1 #ifndef MUTATOR_INSTAGIB_H
2 #define MUTATOR_INSTAGIB_H
7 float autocvar_g_instagib_invis_alpha;
15 int autocvar_g_instagib_ammo_drop;
16 int autocvar_g_instagib_extralives;
17 float autocvar_g_instagib_speed_highspeed;
19 #include "../../../../server/cl_client.qh"
20 #include "../../../buffs/all.qh"
22 #include "../../../items/all.qc"
24 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
26 spawnfunc(item_minst_cells)
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);
33 void instagib_invisibility()
35 self.strength_finished = autocvar_g_balance_powerup_strength_time;
36 StartItem(this, ITEM_Invisibility);
39 void instagib_extralife()
42 StartItem(this, ITEM_ExtraLife);
47 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
48 StartItem(this, ITEM_Speed);
51 .float instagib_nextthink;
52 .float instagib_needammo;
53 void instagib_stop_countdown(entity e)
55 if (!e.instagib_needammo)
57 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_INSTAGIB_FINDAMMO);
58 e.instagib_needammo = false;
60 void instagib_ammocheck()
62 if(time < self.instagib_nextthink)
65 return; // not a player
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)
73 if(!self.instagib_needammo)
75 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
76 self.instagib_needammo = true;
81 self.instagib_needammo = true;
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);
87 else if (self.health <= 10)
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);
92 else if (self.health <= 20)
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);
97 else if (self.health <= 30)
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);
102 else if (self.health <= 40)
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);
107 else if (self.health <= 50)
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);
112 else if (self.health <= 60)
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);
117 else if (self.health <= 70)
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);
122 else if (self.health <= 80)
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);
127 else if (self.health <= 90)
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);
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');
139 self.instagib_nextthink = time + 1;
142 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
145 FOR_EACH_PLAYER(head)
146 instagib_stop_countdown(head);
151 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
153 other.monster_loot = spawnfunc_item_minst_cells;
158 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
160 // always refill ammo
161 if(self.monsterid == MON_MAGE.monsterid)
167 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
169 if (checkentity.items & ITEM_Invisibility.m_itemid)
175 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
177 instagib_stop_countdown(self);
181 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
183 self.effects |= EF_FULLBRIGHT;
187 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
189 instagib_ammocheck();
193 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
195 // no regeneration in instagib
199 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
201 if (!(self.effects & EF_FULLBRIGHT))
202 self.effects |= EF_FULLBRIGHT;
204 if (self.items & ITEM_Invisibility.m_itemid)
206 play_countdown(self.strength_finished, SND(POWEROFF));
207 if (time > self.strength_finished)
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);
217 if (time < self.strength_finished)
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);
227 if (self.items & ITEM_Speed.m_itemid)
229 play_countdown(self.invincible_finished, SND(POWEROFF));
230 if (time > self.invincible_finished)
232 self.items &= ~ITEM_Speed.m_itemid;
233 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
238 if (time < self.invincible_finished)
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);
248 .float stat_sv_maxspeed;
250 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
252 if(self.items & ITEM_Speed.m_itemid)
253 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
258 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
261 damage_take = frag_damage;
266 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
268 // weapon dropping on death handled by FilterItem
273 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
275 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
278 if(IS_PLAYER(frag_target))
280 if(frag_deathtype == DEATH_FALL.m_id)
281 frag_damage = 0; // never count fall damage
283 if(!autocvar_g_instagib_damagedbycontents)
284 switch(DEATH_ENT(frag_deathtype))
293 if(IS_PLAYER(frag_attacker))
294 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
296 if(frag_target.armorvalue)
298 frag_target.armorvalue -= 1;
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);
306 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
308 if(frag_deathtype & HITTYPE_SECONDARY)
310 if(!autocvar_g_instagib_blaster_keepdamage)
311 frag_damage = frag_mirrordamage = 0;
313 if(frag_target != frag_attacker)
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';
323 if(IS_PLAYER(frag_attacker))
324 if(frag_mirrordamage > 0)
326 // just lose extra LIVES, don't kill the player for mirror damage
327 if(frag_attacker.armorvalue > 0)
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;
333 frag_mirrordamage = 0;
336 if((frag_target.buffs & BUFF_INVISIBLE.m_itemid) || (frag_target.items & ITEM_Invisibility.m_itemid))
342 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
344 start_health = warmup_start_health = 100;
345 start_armorvalue = warmup_start_armorvalue = 0;
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;
354 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
355 start_items |= IT_UNLIMITED_SUPERWEAPONS;
360 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
362 if(self.classname == "item_cells")
363 return true; // no normal cells?
365 if(self.weapon == WEP_VAPORIZER.m_id && self.classname == "droppedweapon")
367 self.ammo_cells = autocvar_g_instagib_ammo_drop;
371 if(self.weapon == WEP_DEVASTATOR.m_id || self.weapon == WEP_VORTEX.m_id)
374 setorigin(e, self.origin);
375 e.noalign = self.noalign;
378 e.spawnfunc_checked = true;
379 WITH(entity, self, e, spawnfunc_item_minst_cells(e));
383 if(self.flags & FL_POWERUP)
386 if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
387 self.ammo_cells = autocvar_g_instagib_ammo_drop;
389 if(self.ammo_cells && !self.weapon)
395 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
397 entity e = WaypointSprite_getviewentity(other);
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))
408 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
410 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
411 frag_damage = 1000; // always gib if it was a vaporizer death
416 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
420 // play some cool sounds ;)
421 if (IS_CLIENT(other))
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);
429 if(other.health < 100)
432 return MUT_ITEMTOUCH_CONTINUE;
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;
442 return MUT_ITEMTOUCH_CONTINUE;
445 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
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"))
456 e.think = instagib_invisibility;
458 e.think = instagib_extralife;
460 e.think = instagib_speed;
462 e.nextthink = time + 0.1;
463 e.spawnflags = self.spawnflags;
464 e.noalign = self.noalign;
465 setorigin(e, self.origin);
470 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
472 ret_string = strcat(ret_string, ":instagib");
476 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
478 ret_string = strcat(ret_string, ", instagib");
482 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
484 modname = "InstaGib";