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