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