Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_instagib.qc
1 void spawnfunc_item_minst_cells (void)
2 {
3         if (!g_instagib) { remove(self); return; }
4         if (!self.ammo_cells)
5                 self.ammo_cells = autocvar_g_instagib_ammo_drop;
6
7         StartItem ("models/items/a_cells.md3",
8                            "misc/itempickup.wav", 45, 0,
9                            "Vaporizer Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
10 }
11
12 void instagib_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 instagib_nextthink;
21 .float instagib_needammo;
22 void instagib_stop_countdown(entity e)
23 {
24         if (!e.instagib_needammo)
25                 return;
26         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_INSTAGIB_FINDAMMO);
27         e.instagib_needammo = false;
28 }
29 void instagib_ammocheck()
30 {
31         if(time < self.instagib_nextthink)
32                 return;
33         if(!IS_PLAYER(self))
34                 return; // not a player
35
36         if(self.deadflag || gameover)
37                 instagib_stop_countdown(self);
38         else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO) || (self.flags & FL_GODMODE))
39                 instagib_stop_countdown(self);
40         else
41         {
42                 self.instagib_needammo = true;
43                 if (self.health <= 5)
44                 {
45                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
46                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
47                 }
48                 else if (self.health <= 10)
49                 {
50                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
51                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_1);
52                 }
53                 else if (self.health <= 20)
54                 {
55                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
56                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_2);
57                 }
58                 else if (self.health <= 30)
59                 {
60                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
61                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_3);
62                 }
63                 else if (self.health <= 40)
64                 {
65                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
66                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_4);
67                 }
68                 else if (self.health <= 50)
69                 {
70                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
71                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_5);
72                 }
73                 else if (self.health <= 60)
74                 {
75                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
76                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_6);
77                 }
78                 else if (self.health <= 70)
79                 {
80                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
81                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_7);
82                 }
83                 else if (self.health <= 80)
84                 {
85                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
86                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_8);
87                 }
88                 else if (self.health <= 90)
89                 {
90                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
91                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
92                         Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_9);
93                 }
94                 else
95                 {
96                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
97                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
98                 }
99         }
100         self.instagib_nextthink = time + 1;
101 }
102
103 MUTATOR_HOOKFUNCTION(instagib_MatchEnd)
104 {
105         entity head;
106         FOR_EACH_PLAYER(head)
107                 instagib_stop_countdown(head);
108
109         return false;
110 }
111
112 MUTATOR_HOOKFUNCTION(instagib_MonsterLoot)
113 {
114         other.monster_loot = spawnfunc_item_minst_cells;
115
116         return false;
117 }
118
119 MUTATOR_HOOKFUNCTION(instagib_MonsterSpawn)
120 {
121         // always refill ammo
122         if(self.monsterid == MON_MAGE)
123                 self.skin = 1;
124
125         return false;
126 }
127
128 MUTATOR_HOOKFUNCTION(instagib_BotShouldAttack)
129 {
130         if(checkentity.items & IT_STRENGTH)
131                 return true;
132
133         return false;
134 }
135
136 MUTATOR_HOOKFUNCTION(instagib_MakePlayerObserver)
137 {
138         instagib_stop_countdown(self);
139         return false;
140 }
141
142 MUTATOR_HOOKFUNCTION(instagib_PlayerSpawn)
143 {
144         self.effects |= EF_FULLBRIGHT;
145         return false;
146 }
147
148 MUTATOR_HOOKFUNCTION(instagib_PlayerPreThink)
149 {
150         instagib_ammocheck();
151         return false;
152 }
153
154 MUTATOR_HOOKFUNCTION(instagib_PlayerRegen)
155 {
156         // no regeneration in instagib
157         return true;
158 }
159
160 MUTATOR_HOOKFUNCTION(instagib_PlayerPowerups)
161 {
162         if (!(self.effects & EF_FULLBRIGHT))
163                 self.effects |= EF_FULLBRIGHT;
164
165         if (self.items & IT_STRENGTH)
166         {
167                 play_countdown(self.strength_finished, "misc/poweroff.wav");
168                 if (time > self.strength_finished)
169                 {
170                         self.alpha = default_player_alpha;
171                         self.exteriorweaponentity.alpha = default_weapon_alpha;
172                         self.items &= ~IT_STRENGTH;
173                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
174                 }
175         }
176         else
177         {
178                 if (time < self.strength_finished)
179                 {
180                         self.alpha = autocvar_g_instagib_invis_alpha;
181                         self.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
182                         self.items |= IT_STRENGTH;
183                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_INVISIBILITY, self.netname);
184                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
185                 }
186         }
187
188         if (self.items & IT_INVINCIBLE)
189         {
190                 play_countdown(self.invincible_finished, "misc/poweroff.wav");
191                 if (time > self.invincible_finished)
192                 {
193                         self.items &= ~IT_INVINCIBLE;
194                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
195                 }
196         }
197         else
198         {
199                 if (time < self.invincible_finished)
200                 {
201                         self.items |= IT_INVINCIBLE;
202                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SPEED, self.netname);
203                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SPEED);
204                 }
205         }
206         return false;
207 }
208
209 MUTATOR_HOOKFUNCTION(instagib_PlayerPhysics)
210 {
211         if(self.items & IT_INVINCIBLE)
212                 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
213
214         return false;
215 }
216
217 MUTATOR_HOOKFUNCTION(instagib_SplitHealthArmor)
218 {
219         damage_save = 0;
220         damage_take = frag_damage;
221
222         return false;
223 }
224
225 MUTATOR_HOOKFUNCTION(instagib_ForbidThrowing)
226 {
227         // weapon dropping on death handled by FilterItem
228
229         return true;
230 }
231
232 MUTATOR_HOOKFUNCTION(instagib_PlayerDamage)
233 {
234         if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
235                 frag_damage = 0;
236
237         if(IS_PLAYER(frag_target))
238         {
239                 if ((frag_deathtype == DEATH_FALL)  ||
240                         (frag_deathtype == DEATH_DROWN) ||
241                         (frag_deathtype == DEATH_SLIME) ||
242                         (frag_deathtype == DEATH_LAVA))
243                 {
244                         frag_damage = 0;
245                 }
246
247                 if(IS_PLAYER(frag_attacker))
248                 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
249                 {
250                         if(frag_target.armorvalue)
251                         {
252                                 frag_target.armorvalue -= 1;
253                                 frag_damage = 0;
254                                 frag_target.damage_dealt += 1;
255                                 frag_attacker.damage_dealt += 1; // TODO: change this to a specific hitsound for armor hit
256                                 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
257                         }
258                 }
259
260                 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
261                 {
262                         if(frag_deathtype & HITTYPE_SECONDARY)
263                         {
264                                 frag_damage = frag_mirrordamage = 0;
265
266                                 if(frag_target != frag_attacker)
267                                 {
268                                         if(frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
269                                         frag_force = '0 0 0';
270                                 }
271                         }
272                 }
273         }
274
275         if(IS_PLAYER(frag_attacker))
276         if(frag_mirrordamage > 0)
277         {
278                 // just lose extra LIVES, don't kill the player for mirror damage
279                 if(frag_attacker.armorvalue > 0)
280                 {
281                         frag_attacker.armorvalue -= 1;
282                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
283                         frag_attacker.damage_dealt += 1;
284                 }
285                 frag_mirrordamage = 0;
286         }
287
288         if((frag_target.buffs & BUFF_INVISIBLE) || (frag_target.items & IT_STRENGTH))
289                 yoda = 1;
290
291         return false;
292 }
293
294 MUTATOR_HOOKFUNCTION(instagib_SetStartItems)
295 {
296         start_health       = warmup_start_health       = 100;
297         start_armorvalue   = warmup_start_armorvalue   = 0;
298
299         start_ammo_shells  = warmup_start_ammo_shells  = 0;
300         start_ammo_nails   = warmup_start_ammo_nails   = 0;
301         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_instagib_ammo_start");
302         start_ammo_plasma  = warmup_start_ammo_plasma  = 0;
303         start_ammo_rockets = warmup_start_ammo_rockets = 0;
304         start_ammo_fuel    = warmup_start_ammo_fuel    = 0;
305
306         start_weapons = warmup_start_weapons = WEPSET_VAPORIZER;
307         start_items |= IT_UNLIMITED_SUPERWEAPONS;
308
309         return false;
310 }
311
312 MUTATOR_HOOKFUNCTION(instagib_FilterItem)
313 {
314         if(self.classname == "item_cells")
315                 return true; // no normal cells?
316
317         if(self.weapon == WEP_VAPORIZER && self.classname == "droppedweapon")
318         {
319                 self.ammo_cells = autocvar_g_instagib_ammo_drop;
320                 return false;
321         }
322
323         if(self.weapon == WEP_DEVASTATOR || self.weapon == WEP_VORTEX)
324         {
325                 entity e = spawn();
326                 setorigin(e, self.origin);
327                 entity oldself;
328                 oldself = self;
329                 self = e;
330                 spawnfunc_item_minst_cells();
331                 self = oldself;
332                 return true;
333         }
334
335         if(self.flags & FL_POWERUP)
336                 return false;
337
338         if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
339                 self.ammo_cells = autocvar_g_instagib_ammo_drop;
340
341         if(self.ammo_cells && !self.weapon)
342                 return false;
343
344         return true;
345 }
346
347 MUTATOR_HOOKFUNCTION(instagib_CustomizeWaypoint)
348 {
349         entity e = WaypointSprite_getviewentity(other);
350
351         // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
352         // but only apply this to real players, not to spectators
353         if((self.owner.flags & FL_CLIENT) && (self.owner.items & IT_STRENGTH) && (e == other))
354         if(DIFF_TEAM(self.owner, e))
355                 return true;
356
357         return false;
358 }
359
360 MUTATOR_HOOKFUNCTION(instagib_ItemCountdown)
361 {
362         switch(self.items)
363         {
364                 case IT_STRENGTH:   item_name = "item-invis"; item_color = '0 0 1'; break;
365                 case IT_NAILS:      item_name = "item-extralife"; item_color = '1 0 0'; break;
366                 case IT_INVINCIBLE: item_name = "item-speed"; item_color = '1 0 1'; break;
367         }
368         return false;
369 }
370
371 MUTATOR_HOOKFUNCTION(instagib_PlayerDies)
372 {       
373         if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
374                 frag_damage = 1000; // always gib if it was a vaporizer death
375
376         return FALSE;
377 }
378
379 MUTATOR_HOOKFUNCTION(instagib_ItemTouch)
380 {
381         if(self.ammo_cells)
382         {
383                 // play some cool sounds ;)
384                 if (IS_CLIENT(other))
385                 {
386                         if(other.health <= 5)
387                                 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
388                         else if(other.health < 50)
389                                 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
390                 }
391
392                 if(other.health < 100)
393                         other.health = 100;
394
395                 return MUT_ITEMTOUCH_CONTINUE;
396         }
397
398         if(self.max_health)
399         {
400                 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_instagib_extralives);
401                 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
402                 return MUT_ITEMTOUCH_PICKUP;
403         }
404
405         return MUT_ITEMTOUCH_CONTINUE;
406 }
407
408 MUTATOR_HOOKFUNCTION(instagib_OnEntityPreSpawn)
409 {
410         if (!autocvar_g_powerups) { return false; }
411         if (!(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega"))
412                 return false;
413
414         entity e = spawn();
415
416         if(random() < 0.3)
417                 e.think = spawnfunc_item_strength;
418         else if(random() < 0.6)
419                 e.think = instagib_health_mega;
420         else
421                 e.think = spawnfunc_item_invincible;
422
423         e.nextthink = time + 0.1;
424         e.spawnflags = self.spawnflags;
425         e.noalign = self.noalign;
426         setorigin(e, self.origin);
427
428         return true;
429 }
430
431 MUTATOR_HOOKFUNCTION(instagib_BuildMutatorsString)
432 {
433         ret_string = strcat(ret_string, ":instagib");
434         return false;
435 }
436
437 MUTATOR_HOOKFUNCTION(instagib_BuildMutatorsPrettyString)
438 {
439         ret_string = strcat(ret_string, ", instagib");
440         return false;
441 }
442
443 MUTATOR_HOOKFUNCTION(instagib_SetModname)
444 {
445         modname = "instagib";
446         return true;
447 }
448
449 MUTATOR_DEFINITION(mutator_instagib)
450 {
451         MUTATOR_HOOK(MatchEnd, instagib_MatchEnd, CBC_ORDER_ANY);
452         MUTATOR_HOOK(MonsterDropItem, instagib_MonsterLoot, CBC_ORDER_ANY);
453         MUTATOR_HOOK(MonsterSpawn, instagib_MonsterSpawn, CBC_ORDER_ANY);
454         MUTATOR_HOOK(BotShouldAttack, instagib_BotShouldAttack, CBC_ORDER_ANY);
455         MUTATOR_HOOK(PlayerPhysics, instagib_PlayerPhysics, CBC_ORDER_ANY);
456         MUTATOR_HOOK(PlayerSpawn, instagib_PlayerSpawn, CBC_ORDER_ANY);
457         MUTATOR_HOOK(PlayerDamage_Calculate, instagib_PlayerDamage, CBC_ORDER_ANY);
458         MUTATOR_HOOK(MakePlayerObserver, instagib_MakePlayerObserver, CBC_ORDER_ANY);
459         MUTATOR_HOOK(SetStartItems, instagib_SetStartItems, CBC_ORDER_ANY);
460         MUTATOR_HOOK(ItemTouch, instagib_ItemTouch, CBC_ORDER_ANY);
461         MUTATOR_HOOK(FilterItem, instagib_FilterItem, CBC_ORDER_ANY);
462         MUTATOR_HOOK(CustomizeWaypoint, instagib_CustomizeWaypoint, CBC_ORDER_ANY);
463         MUTATOR_HOOK(Item_RespawnCountdown, instagib_ItemCountdown, CBC_ORDER_ANY);
464         MUTATOR_HOOK(PlayerDies, instagib_PlayerDies, CBC_ORDER_ANY);
465         MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, instagib_SplitHealthArmor, CBC_ORDER_ANY);
466         MUTATOR_HOOK(PlayerPowerups, instagib_PlayerPowerups, CBC_ORDER_ANY);
467         MUTATOR_HOOK(ForbidThrowCurrentWeapon, instagib_ForbidThrowing, CBC_ORDER_ANY);
468         MUTATOR_HOOK(PlayerPreThink, instagib_PlayerPreThink, CBC_ORDER_ANY);
469         MUTATOR_HOOK(PlayerRegen, instagib_PlayerRegen, CBC_ORDER_ANY);
470         MUTATOR_HOOK(OnEntityPreSpawn, instagib_OnEntityPreSpawn, CBC_ORDER_ANY);
471         MUTATOR_HOOK(BuildMutatorsString, instagib_BuildMutatorsString, CBC_ORDER_ANY);
472         MUTATOR_HOOK(BuildMutatorsPrettyString, instagib_BuildMutatorsPrettyString, CBC_ORDER_ANY);
473         MUTATOR_HOOK(SetModname, instagib_SetModname, CBC_ORDER_ANY);
474
475         return false;
476 }