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