]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_minstagib.qc
f8c833144c831657bee30197925fecf86efdbc96
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_minstagib.qc
1 void spawnfunc_item_minst_cells (void) 
2 {
3         if not(g_minstagib) { remove(self); return; }
4         if not(self.ammo_cells)
5                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
6                 
7         StartItem ("models/items/a_cells.md3",
8                            "misc/itempickup.wav", 45, 0,
9                            "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
10 }
11
12 void minstagib_health_mega()
13 {
14         self.max_health = 1;
15         StartItem ("models/items/g_h100.md3",
16                            "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
17                            "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
18 }
19
20 .float minstagib_nextthink;
21 .float minstagib_needammo;
22 void minstagib_stop_countdown(entity e)
23 {
24         if (!e.minstagib_needammo)
25                 return;
26         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_MINSTA_FINDAMMO);
27         e.minstagib_needammo = FALSE;
28 }
29 void minstagib_ammocheck(void)
30 {
31         if (time < self.minstagib_nextthink)
32                 return;
33
34         if (self.deadflag || gameover)
35                 minstagib_stop_countdown(self);
36         else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO))
37                 minstagib_stop_countdown(self);
38         else
39         {
40                 self.minstagib_needammo = TRUE;
41                 if (self.health == 5)
42                 {
43                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
44                         AnnounceTo(self, "terminated");
45                 }
46                 else if (self.health == 10)
47                 {
48                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
49                         AnnounceTo(self, "1");
50                 }
51                 else if (self.health == 20)
52                 {
53                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
54                         AnnounceTo(self, "2");
55                 }
56                 else if (self.health == 30)
57                 {
58                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
59                         AnnounceTo(self, "3");
60                 }
61                 else if (self.health == 40)
62                 {
63                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
64                         AnnounceTo(self, "4");
65                 }
66                 else if (self.health == 50)
67                 {
68                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
69                         AnnounceTo(self, "5");
70                 }
71                 else if (self.health == 60)
72                 {
73                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
74                         AnnounceTo(self, "6");
75                 }
76                 else if (self.health == 70)
77                 {
78                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
79                         AnnounceTo(self, "7");
80                 }
81                 else if (self.health == 80)
82                 {
83                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
84                         AnnounceTo(self, "8");
85                 }
86                 else if (self.health == 90)
87                 {
88                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MINSTA_FINDAMMO);
89                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
90                         AnnounceTo(self, "9");
91                 }
92                 else if (self.health == 100)
93                 {
94                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MINSTA_FINDAMMO_FIRST);
95                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
96                         if not(self.flags & FL_GODMODE)
97                                 AnnounceTo(self, "10");
98                 }
99         }
100         self.minstagib_nextthink = time + 1;
101 }
102
103 MUTATOR_HOOKFUNCTION(minstagib_BotShouldAttack)
104 {
105         if(checkentity.items & IT_STRENGTH)
106                 return TRUE;
107                 
108         return FALSE;
109 }
110
111 MUTATOR_HOOKFUNCTION(minstagib_MakePlayerObserver)
112 {
113         minstagib_stop_countdown(self);
114         return FALSE;
115 }
116
117 MUTATOR_HOOKFUNCTION(minstagib_PlayerSpawn)
118 {
119         self.effects |= EF_FULLBRIGHT;
120         return FALSE;
121 }
122
123 MUTATOR_HOOKFUNCTION(minstagib_PlayerPreThink)
124 {
125         minstagib_ammocheck();
126         return FALSE;
127 }
128
129 MUTATOR_HOOKFUNCTION(minstagib_PlayerPowerups)
130 {
131         if not(self.effects & EF_FULLBRIGHT)
132                 self.effects |= EF_FULLBRIGHT;
133
134         if (self.items & IT_STRENGTH)
135         {
136                 play_countdown(self.strength_finished, "misc/poweroff.wav");
137                 if (time > self.strength_finished)
138                 {
139                         self.alpha = default_player_alpha;
140                         self.exteriorweaponentity.alpha = default_weapon_alpha;
141                         self.items &~= IT_STRENGTH;
142                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
143                 }
144         }
145         else
146         {
147                 if (time < self.strength_finished)
148                 {
149                         self.alpha = g_minstagib_invis_alpha;
150                         self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
151                         self.items |= IT_STRENGTH;
152                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_INVISIBILITY, self.netname);
153                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
154                 }
155         }
156
157         if (self.items & IT_INVINCIBLE)
158         {
159                 play_countdown(self.invincible_finished, "misc/poweroff.wav");
160                 if (time > self.invincible_finished)
161                 {
162                         self.items &~= IT_INVINCIBLE;
163                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
164                 }
165         }
166         else
167         {
168                 if (time < self.invincible_finished)
169                 {
170                         self.items |= IT_INVINCIBLE;
171                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SPEED, self.netname);
172                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SPEED);
173                 }
174         }
175         return FALSE;
176 }
177
178 MUTATOR_HOOKFUNCTION(minstagib_PlayerPhysics)
179 {
180         if(self.items & IT_INVINCIBLE)
181                 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_minstagib_speed_highspeed;
182                 
183         return FALSE;
184 }
185
186 MUTATOR_HOOKFUNCTION(minstagib_SplitHealthArmor)
187 {
188         damage_save = 0;
189         //damage_take = frag_damage; // frag_damage isn't even set here?!
190         
191         return FALSE;
192 }
193
194 MUTATOR_HOOKFUNCTION(minstagib_ForbidThrowing)
195 {
196         if (self.health < 1)
197                 return FALSE;
198                 
199         return TRUE;
200 }
201
202 MUTATOR_HOOKFUNCTION(minstagib_PlayerDamage)
203 {
204         if(autocvar_g_friendlyfire == 0 && !IsDifferentTeam(frag_target, frag_attacker) && IS_PLAYER(frag_target))
205                 frag_damage = 0;
206                 
207         if(IS_PLAYER(frag_target))
208         {
209                 if ((frag_deathtype == DEATH_FALL)  ||
210                         (frag_deathtype == DEATH_DROWN) ||
211                         (frag_deathtype == DEATH_SLIME) ||
212                         (frag_deathtype == DEATH_LAVA))
213                 {
214                         frag_damage = 0;
215                 }
216                 
217                 if (frag_target.armorvalue && (frag_deathtype == WEP_MINSTANEX) && frag_damage)
218                 {
219                         frag_target.armorvalue -= 1;
220                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_target.armorvalue);
221                         frag_damage = 0;
222                         frag_target.hitsound += 1;
223                         frag_attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
224                 }
225                 if (DEATH_ISWEAPON(frag_deathtype, WEP_LASER))
226                 {
227                         frag_damage = 0;
228                         frag_mirrordamage = 0;
229                         if (frag_target != frag_attacker)
230                         {
231                                 if ((frag_target.health >= 1) && IS_PLAYER(frag_target))
232                                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_SECONDARY);
233                                 frag_force = '0 0 0';
234                                 // keep mirrorfrag_force
235                                 frag_attacker = frag_target;
236                         }
237                 }
238         }
239         
240         if(frag_mirrordamage > 0)
241         {
242                 // just lose extra LIVES, don't kill the player for mirror damage
243                 if(frag_attacker.armorvalue > 0)
244                 {
245                         frag_attacker.armorvalue = frag_attacker.armorvalue - 1;
246                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_attacker.armorvalue);
247                         frag_attacker.hitsound += 1;
248                 }
249                 frag_mirrordamage = 0;
250         }
251         
252         if(frag_target.items & IT_STRENGTH)
253                 yoda = 1;
254                 
255         return FALSE;
256 }
257
258 MUTATOR_HOOKFUNCTION(minstagib_SetStartItems)
259 {
260         start_ammo_cells = cvar("g_minstagib_ammo_start");
261         
262         g_pinata = 0; // incompatible
263         g_weapon_stay = 0; // incompatible
264         g_bloodloss = 0; // incompatible
265         start_health = 100;
266         start_armorvalue = 0;
267         WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
268         g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
269         start_items |= IT_UNLIMITED_SUPERWEAPONS;
270
271         if (g_minstagib_invis_alpha <= 0)
272                 g_minstagib_invis_alpha = -1;
273                 
274         return FALSE;
275 }
276
277 MUTATOR_HOOKFUNCTION(minstagib_FilterItem)
278 {
279         if(self.classname == "item_cells")
280                 return TRUE; // no normal cells?
281                 
282         if(self.weapon == WEP_MINSTANEX && self.classname == "droppedweapon")
283         {
284                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
285                 return FALSE;
286         }
287         
288         if(self.weapon == WEP_ROCKET_LAUNCHER || self.weapon == WEP_NEX)
289         {
290                 entity e = spawn();
291                 setorigin(e, self.origin);
292                 entity oldself;
293                 oldself = self;
294                 self = e;
295                 spawnfunc_item_minst_cells();
296                 self = oldself;
297                 return TRUE;
298         }
299                 
300         if(self.flags & FL_POWERUP)
301                 return FALSE;
302                 
303         if(self.ammo_cells > autocvar_g_minstagib_ammo_drop && self.classname != "item_minst_cells")
304                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
305                 
306         if(self.ammo_cells && !self.weapon)
307                 return FALSE;
308                 
309         return TRUE;
310 }
311
312 MUTATOR_HOOKFUNCTION(minstagib_ItemCountdown)
313 {
314         switch(self.items)
315         {
316                 case IT_STRENGTH:   item_name = "item-invis"; item_color = '0 0 1'; break;
317                 case IT_NAILS:      item_name = "item-extralife"; item_color = '1 0 0'; break;
318                 case IT_INVINCIBLE: item_name = "item-speed"; item_color = '1 0 1'; break;
319         }
320         return FALSE;
321 }
322
323 MUTATOR_HOOKFUNCTION(minstagib_GiveItem)
324 {
325         if(giveitem.ammo_cells)
326         {
327                 // play some cool sounds ;)
328                 if (IS_CLIENT(other))
329                 {
330                         if(other.health <= 5)
331                                 AnnounceTo(other, "lastsecond");
332                         else if(other.health < 50)
333                                 AnnounceTo(other, "narrowly");
334                 }
335
336                 if(other.health < 100)
337                         other.health = 100;
338                         
339                 player_pickedup = TRUE;
340         }
341         
342         if(giveitem.max_health)
343         {
344                 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_minstagib_extralives);
345                 sprint(other, "^3You picked up some extra lives\n");
346                 player_pickedup = TRUE;
347         }
348                 
349         return TRUE;
350 }
351
352 MUTATOR_HOOKFUNCTION(minstagib_OnEntityPreSpawn)
353 {
354         if not(autocvar_g_powerups) { return FALSE; }
355         if not(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega")
356                 return FALSE;
357         
358         entity e = spawn();
359         
360         if(random() < 0.3)
361                 e.think = spawnfunc_item_strength;
362         else if(random() < 0.6)
363                 e.think = minstagib_health_mega;
364         else
365                 e.think = spawnfunc_item_invincible;
366                 
367         e.nextthink = time + 0.1;
368         e.spawnflags = self.spawnflags;
369         e.noalign = self.noalign;
370         setorigin(e, self.origin);
371         
372         return TRUE;
373 }
374
375 MUTATOR_HOOKFUNCTION(minstagib_BuildMutatorsString)
376 {
377         ret_string = strcat(ret_string, ":MinstaGib");
378         return FALSE;
379 }
380
381 MUTATOR_HOOKFUNCTION(minstagib_BuildMutatorsPrettyString)
382 {
383         ret_string = strcat(ret_string, ", MinstaGib");
384         return FALSE;
385 }
386
387 MUTATOR_DEFINITION(mutator_minstagib)
388 {
389         MUTATOR_HOOK(BotShouldAttack, minstagib_BotShouldAttack, CBC_ORDER_ANY);
390         MUTATOR_HOOK(PlayerPhysics, minstagib_PlayerPhysics, CBC_ORDER_ANY);
391         MUTATOR_HOOK(PlayerSpawn, minstagib_PlayerSpawn, CBC_ORDER_ANY);
392         MUTATOR_HOOK(PlayerDamage_Calculate, minstagib_PlayerDamage, CBC_ORDER_ANY);
393         MUTATOR_HOOK(MakePlayerObserver, minstagib_MakePlayerObserver, CBC_ORDER_ANY);
394         MUTATOR_HOOK(SetStartItems, minstagib_SetStartItems, CBC_ORDER_ANY);
395         MUTATOR_HOOK(Item_GiveTo, minstagib_GiveItem, CBC_ORDER_ANY);
396         MUTATOR_HOOK(FilterItem, minstagib_FilterItem, CBC_ORDER_ANY);
397         MUTATOR_HOOK(Item_RespawnCountdown, minstagib_ItemCountdown, CBC_ORDER_ANY);
398         MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, minstagib_SplitHealthArmor, CBC_ORDER_ANY);
399         MUTATOR_HOOK(PlayerPowerups, minstagib_PlayerPowerups, CBC_ORDER_ANY);
400         MUTATOR_HOOK(ForbidThrowCurrentWeapon, minstagib_ForbidThrowing, CBC_ORDER_ANY);
401         MUTATOR_HOOK(PlayerPreThink, minstagib_PlayerPreThink, CBC_ORDER_ANY);
402         MUTATOR_HOOK(OnEntityPreSpawn, minstagib_OnEntityPreSpawn, CBC_ORDER_ANY);
403         MUTATOR_HOOK(BuildMutatorsString, minstagib_BuildMutatorsString, CBC_ORDER_ANY);
404         MUTATOR_HOOK(BuildMutatorsPrettyString, minstagib_BuildMutatorsPrettyString, CBC_ORDER_ANY);
405
406         return FALSE;
407 }