]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/instagib/instagib.qc
fa8ce973477430f05415cc5e750a2293fa810232
[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         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 {
178         entity player = M_ARGV(0, entity);
179
180         player.effects |= EF_FULLBRIGHT;
181 }
182
183 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
184 {SELFPARAM();
185         instagib_ammocheck(self);
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         entity frag_attacker = M_ARGV(1, entity);
272         entity frag_target = M_ARGV(2, entity);
273         float frag_deathtype = M_ARGV(3, float);
274         float frag_damage = M_ARGV(4, float);
275         float frag_mirrordamage = M_ARGV(5, float);
276         vector frag_force = M_ARGV(6, vector);
277
278         if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
279                 frag_damage = 0;
280
281         if(IS_PLAYER(frag_target))
282         {
283                 if(frag_deathtype == DEATH_FALL.m_id)
284                         frag_damage = 0; // never count fall damage
285
286                 if(!autocvar_g_instagib_damagedbycontents)
287                 switch(DEATH_ENT(frag_deathtype))
288                 {
289                         case DEATH_DROWN:
290                         case DEATH_SLIME:
291                         case DEATH_LAVA:
292                                 frag_damage = 0;
293                                 break;
294                 }
295
296                 if(IS_PLAYER(frag_attacker))
297                 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
298                 {
299                         if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
300                                 frag_force = '0 0 0';
301
302                         if(frag_target.armorvalue)
303                         {
304                                 frag_target.armorvalue -= 1;
305                                 frag_damage = 0;
306                                 frag_target.damage_dealt += 1;
307                                 frag_attacker.damage_dealt += 1;
308                                 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
309                         }
310                 }
311
312                 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
313                 {
314                         if(frag_deathtype & HITTYPE_SECONDARY)
315                         {
316                                 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
317                                 {
318                                         frag_damage = 0;
319                                         if(!autocvar_g_instagib_mirrordamage)
320                                                 frag_mirrordamage = 0; // never do mirror damage on enemies
321                                 }
322
323                                 if(frag_target != frag_attacker)
324                                 {
325                                         if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
326                                         if(!autocvar_g_instagib_blaster_keepforce)
327                                                 frag_force = '0 0 0';
328                                 }
329                         }
330                 }
331         }
332
333         if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
334         if(IS_PLAYER(frag_attacker))
335         if(frag_mirrordamage > 0)
336         {
337                 // just lose extra LIVES, don't kill the player for mirror damage
338                 if(frag_attacker.armorvalue > 0)
339                 {
340                         frag_attacker.armorvalue -= 1;
341                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
342                         frag_attacker.damage_dealt += frag_mirrordamage;
343                 }
344                 frag_mirrordamage = 0;
345         }
346
347         if(frag_target.alpha && frag_target.alpha < 1)
348         if(IS_PLAYER(frag_target))
349                 yoda = 1;
350
351         M_ARGV(4, float) = frag_damage;
352         M_ARGV(5, float) = frag_mirrordamage;
353         M_ARGV(6, vector) = frag_force;
354
355         return false;
356 }
357
358 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
359 {
360         start_health       = warmup_start_health       = 100;
361         start_armorvalue   = warmup_start_armorvalue   = 0;
362
363         start_ammo_shells  = warmup_start_ammo_shells  = 0;
364         start_ammo_nails   = warmup_start_ammo_nails   = 0;
365         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_instagib_ammo_start");
366         start_ammo_plasma  = warmup_start_ammo_plasma  = 0;
367         start_ammo_rockets = warmup_start_ammo_rockets = 0;
368         start_ammo_fuel    = warmup_start_ammo_fuel    = 0;
369
370         start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
371         start_items |= IT_UNLIMITED_SUPERWEAPONS;
372
373         return false;
374 }
375
376 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
377 {SELFPARAM();
378         if(self.classname == "item_cells")
379                 return true; // no normal cells?
380
381         if(self.weapon == WEP_VAPORIZER.m_id && self.classname == "droppedweapon")
382         {
383                 self.ammo_cells = autocvar_g_instagib_ammo_drop;
384                 return false;
385         }
386
387         if(self.weapon == WEP_DEVASTATOR.m_id || self.weapon == WEP_VORTEX.m_id)
388         {
389                 entity e = spawn();
390                 setorigin(e, self.origin);
391                 e.noalign = self.noalign;
392         e.cnt = self.cnt;
393         e.team = self.team;
394         e.spawnfunc_checked = true;
395                 WITHSELF(e, spawnfunc_item_minst_cells(e));
396                 return true;
397         }
398
399         if(self.flags & FL_POWERUP)
400                 return false;
401
402         if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
403                 self.ammo_cells = autocvar_g_instagib_ammo_drop;
404
405         if(self.ammo_cells && !self.weapon)
406                 return false;
407
408         return true;
409 }
410
411 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
412 {SELFPARAM();
413         entity e = WaypointSprite_getviewentity(other);
414
415         // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
416         // but only apply this to real players, not to spectators
417         if((self.owner.flags & FL_CLIENT) && (self.owner.items & ITEM_Invisibility.m_itemid) && (e == other))
418         if(DIFF_TEAM(self.owner, e))
419                 return true;
420
421         return false;
422 }
423
424 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
425 {
426         if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
427                 frag_damage = 1000; // always gib if it was a vaporizer death
428
429         return false;
430 }
431
432 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
433 {SELFPARAM();
434         if(self.ammo_cells)
435         {
436                 // play some cool sounds ;)
437                 if (IS_CLIENT(other))
438                 {
439                         if(other.health <= 5)
440                                 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
441                         else if(other.health < 50)
442                                 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
443                 }
444
445                 if(other.health < 100)
446                         other.health = 100;
447
448                 return MUT_ITEMTOUCH_CONTINUE;
449         }
450
451         if(self.itemdef == ITEM_ExtraLife)
452         {
453                 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_instagib_extralives);
454                 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
455                 return MUT_ITEMTOUCH_PICKUP;
456         }
457
458         return MUT_ITEMTOUCH_CONTINUE;
459 }
460
461 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
462 {SELFPARAM();
463         if (!autocvar_g_powerups) { return false; }
464         // Can't use .itemdef here
465         if (!(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega"))
466                 return false;
467
468         entity e = spawn();
469
470         float r = random();
471         if (r < 0.3)
472                 setthink(e, instagib_invisibility);
473         else if (r < 0.6)
474                 setthink(e, instagib_extralife);
475         else
476                 setthink(e, instagib_speed);
477
478         e.nextthink = time + 0.1;
479         e.spawnflags = self.spawnflags;
480         e.noalign = self.noalign;
481         setorigin(e, self.origin);
482
483         return true;
484 }
485
486 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
487 {
488         ret_string = strcat(ret_string, ":instagib");
489         return false;
490 }
491
492 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
493 {
494         ret_string = strcat(ret_string, ", instagib");
495         return false;
496 }
497
498 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
499 {
500         modname = "InstaGib";
501         return true;
502 }
503
504 #endif
505 #endif