1 #ifndef MUTATOR_INSTAGIB_H
2 #define MUTATOR_INSTAGIB_H
11 #include "../../../../server/cl_client.qh"
12 #include "../../../buffs/all.qh"
14 #include "../../../items/all.qc"
16 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
18 spawnfunc(item_minst_cells)
20 if (!g_instagib) { remove(self); return; }
21 if (!self.ammo_cells) self.ammo_cells = autocvar_g_instagib_ammo_drop;
22 StartItem(this, ITEM_VaporizerCells);
25 void instagib_invisibility()
27 self.strength_finished = autocvar_g_balance_powerup_strength_time;
28 StartItem(this, ITEM_Invisibility);
31 void instagib_extralife()
34 StartItem(this, ITEM_ExtraLife);
39 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
40 StartItem(this, ITEM_Speed);
43 .float instagib_nextthink;
44 .float instagib_needammo;
45 void instagib_stop_countdown(entity e)
47 if (!e.instagib_needammo)
49 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_INSTAGIB_FINDAMMO);
50 e.instagib_needammo = false;
52 void instagib_ammocheck()
54 if(time < self.instagib_nextthink)
57 return; // not a player
59 if(self.deadflag || gameover)
60 instagib_stop_countdown(self);
61 else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO) || (self.flags & FL_GODMODE))
62 instagib_stop_countdown(self);
63 else if(autocvar_g_rm && autocvar_g_rm_laser)
65 if(!self.instagib_needammo)
67 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
68 self.instagib_needammo = true;
73 self.instagib_needammo = true;
76 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
77 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
79 else if (self.health <= 10)
81 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
82 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_1);
84 else if (self.health <= 20)
86 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
87 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_2);
89 else if (self.health <= 30)
91 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
92 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_3);
94 else if (self.health <= 40)
96 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
97 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_4);
99 else if (self.health <= 50)
101 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
102 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_5);
104 else if (self.health <= 60)
106 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
107 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_6);
109 else if (self.health <= 70)
111 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
112 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_7);
114 else if (self.health <= 80)
116 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
117 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_8);
119 else if (self.health <= 90)
121 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
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_9);
127 Send_Notification(NOTIF_ONE_ONLY, self, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
128 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
131 self.instagib_nextthink = time + 1;
134 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
137 FOR_EACH_PLAYER(head)
138 instagib_stop_countdown(head);
143 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
145 other.monster_loot = spawnfunc_item_minst_cells;
150 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
152 // always refill ammo
153 if(self.monsterid == MON_MAGE.monsterid)
159 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
161 if (checkentity.items & ITEM_Invisibility.m_itemid)
167 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
169 instagib_stop_countdown(self);
173 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
175 self.effects |= EF_FULLBRIGHT;
179 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
181 instagib_ammocheck();
185 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
187 // no regeneration in instagib
191 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
193 if (!(self.effects & EF_FULLBRIGHT))
194 self.effects |= EF_FULLBRIGHT;
196 if (self.items & ITEM_Invisibility.m_itemid)
198 play_countdown(self.strength_finished, SND(POWEROFF));
199 if (time > self.strength_finished)
201 self.alpha = default_player_alpha;
202 self.exteriorweaponentity.alpha = default_weapon_alpha;
203 self.items &= ~ITEM_Invisibility.m_itemid;
204 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
209 if (time < self.strength_finished)
211 self.alpha = autocvar_g_instagib_invis_alpha;
212 self.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
213 self.items |= ITEM_Invisibility.m_itemid;
214 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_INVISIBILITY, self.netname);
215 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
219 if (self.items & ITEM_Speed.m_itemid)
221 play_countdown(self.invincible_finished, SND(POWEROFF));
222 if (time > self.invincible_finished)
224 self.items &= ~ITEM_Speed.m_itemid;
225 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
230 if (time < self.invincible_finished)
232 self.items |= ITEM_Speed.m_itemid;
233 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SPEED, self.netname);
234 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SPEED);
240 .float stat_sv_maxspeed;
242 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
244 if(self.items & ITEM_Speed.m_itemid)
245 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
250 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
253 damage_take = frag_damage;
258 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
260 // weapon dropping on death handled by FilterItem
265 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
267 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
270 if(IS_PLAYER(frag_target))
272 if(frag_deathtype == DEATH_FALL.m_id)
273 frag_damage = 0; // never count fall damage
275 if(!autocvar_g_instagib_damagedbycontents)
276 switch(DEATH_ENT(frag_deathtype))
285 if(IS_PLAYER(frag_attacker))
286 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
288 if(frag_target.armorvalue)
290 frag_target.armorvalue -= 1;
292 frag_target.damage_dealt += 1;
293 frag_attacker.damage_dealt += 1; // TODO: change this to a specific hitsound for armor hit
294 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
298 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
300 if(frag_deathtype & HITTYPE_SECONDARY)
302 if(!autocvar_g_instagib_blaster_keepdamage)
303 frag_damage = frag_mirrordamage = 0;
305 if(frag_target != frag_attacker)
307 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
308 if(!autocvar_g_instagib_blaster_keepforce)
309 frag_force = '0 0 0';
315 if(IS_PLAYER(frag_attacker))
316 if(frag_mirrordamage > 0)
318 // just lose extra LIVES, don't kill the player for mirror damage
319 if(frag_attacker.armorvalue > 0)
321 frag_attacker.armorvalue -= 1;
322 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
323 frag_attacker.damage_dealt += frag_mirrordamage;
325 frag_mirrordamage = 0;
328 if((frag_target.buffs & BUFF_INVISIBLE.m_itemid) || (frag_target.items & ITEM_Invisibility.m_itemid))
334 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
336 start_health = warmup_start_health = 100;
337 start_armorvalue = warmup_start_armorvalue = 0;
339 start_ammo_shells = warmup_start_ammo_shells = 0;
340 start_ammo_nails = warmup_start_ammo_nails = 0;
341 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
342 start_ammo_plasma = warmup_start_ammo_plasma = 0;
343 start_ammo_rockets = warmup_start_ammo_rockets = 0;
344 start_ammo_fuel = warmup_start_ammo_fuel = 0;
346 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
347 start_items |= IT_UNLIMITED_SUPERWEAPONS;
352 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
354 if(self.classname == "item_cells")
355 return true; // no normal cells?
357 if(self.weapon == WEP_VAPORIZER.m_id && self.classname == "droppedweapon")
359 self.ammo_cells = autocvar_g_instagib_ammo_drop;
363 if(self.weapon == WEP_DEVASTATOR.m_id || self.weapon == WEP_VORTEX.m_id)
366 setorigin(e, self.origin);
367 e.noalign = self.noalign;
370 e.spawnfunc_checked = true;
371 WITH(entity, self, e, spawnfunc_item_minst_cells(e));
375 if(self.flags & FL_POWERUP)
378 if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
379 self.ammo_cells = autocvar_g_instagib_ammo_drop;
381 if(self.ammo_cells && !self.weapon)
387 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
389 entity e = WaypointSprite_getviewentity(other);
391 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
392 // but only apply this to real players, not to spectators
393 if((self.owner.flags & FL_CLIENT) && (self.owner.items & ITEM_Invisibility.m_itemid) && (e == other))
394 if(DIFF_TEAM(self.owner, e))
400 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
402 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
403 frag_damage = 1000; // always gib if it was a vaporizer death
408 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
412 // play some cool sounds ;)
413 if (IS_CLIENT(other))
415 if(other.health <= 5)
416 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
417 else if(other.health < 50)
418 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
421 if(other.health < 100)
424 return MUT_ITEMTOUCH_CONTINUE;
429 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_instagib_extralives);
430 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
431 return MUT_ITEMTOUCH_PICKUP;
434 return MUT_ITEMTOUCH_CONTINUE;
437 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
439 if (!autocvar_g_powerups) { return false; }
440 // Can't use .itemdef here
441 if (!(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega"))
448 e.think = instagib_invisibility;
450 e.think = instagib_extralife;
452 e.think = instagib_speed;
454 e.nextthink = time + 0.1;
455 e.spawnflags = self.spawnflags;
456 e.noalign = self.noalign;
457 setorigin(e, self.origin);
462 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
464 ret_string = strcat(ret_string, ":instagib");
468 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
470 ret_string = strcat(ret_string, ", instagib");
474 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
476 modname = "InstaGib";