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