1 #ifndef MUTATOR_INSTAGIB_H
2 #define MUTATOR_INSTAGIB_H
11 int autocvar_g_instagib_ammo_drop;
12 int autocvar_g_instagib_extralives;
13 float autocvar_g_instagib_speed_highspeed;
15 #include "../../../../server/cl_client.qh"
16 #include "../../../buffs/all.qh"
18 #include "../../../items/all.qc"
20 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
22 spawnfunc(item_minst_cells)
24 if (!g_instagib) { remove(self); return; }
25 if (!self.ammo_cells) self.ammo_cells = autocvar_g_instagib_ammo_drop;
26 StartItem(this, ITEM_VaporizerCells);
29 void instagib_invisibility()
31 self.strength_finished = autocvar_g_balance_powerup_strength_time;
32 StartItem(this, ITEM_Invisibility);
35 void instagib_extralife()
38 StartItem(this, ITEM_ExtraLife);
43 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
44 StartItem(this, ITEM_Speed);
47 .float instagib_nextthink;
48 .float instagib_needammo;
49 void instagib_stop_countdown(entity e)
51 if (!e.instagib_needammo)
53 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_INSTAGIB_FINDAMMO);
54 e.instagib_needammo = false;
56 void instagib_ammocheck()
58 if(time < self.instagib_nextthink)
61 return; // not a player
63 if(self.deadflag || gameover)
64 instagib_stop_countdown(self);
65 else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO) || (self.flags & FL_GODMODE))
66 instagib_stop_countdown(self);
67 else if(autocvar_g_rm && autocvar_g_rm_laser)
69 if(!self.instagib_needammo)
71 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
72 self.instagib_needammo = true;
77 self.instagib_needammo = true;
80 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
81 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
83 else if (self.health <= 10)
85 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
86 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_1);
88 else if (self.health <= 20)
90 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
91 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_2);
93 else if (self.health <= 30)
95 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
96 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_3);
98 else if (self.health <= 40)
100 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
101 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_4);
103 else if (self.health <= 50)
105 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
106 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_5);
108 else if (self.health <= 60)
110 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
111 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_6);
113 else if (self.health <= 70)
115 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
116 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_7);
118 else if (self.health <= 80)
120 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
121 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_8);
123 else if (self.health <= 90)
125 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
126 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
127 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_9);
131 Send_Notification(NOTIF_ONE_ONLY, self, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
132 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
135 self.instagib_nextthink = time + 1;
138 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
141 FOR_EACH_PLAYER(head)
142 instagib_stop_countdown(head);
147 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
149 other.monster_loot = spawnfunc_item_minst_cells;
154 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
156 // always refill ammo
157 if(self.monsterid == MON_MAGE.monsterid)
163 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
165 if (checkentity.items & ITEM_Invisibility.m_itemid)
171 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
173 instagib_stop_countdown(self);
177 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
179 self.effects |= EF_FULLBRIGHT;
183 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
185 instagib_ammocheck();
189 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
191 // no regeneration in instagib
195 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
197 if (!(self.effects & EF_FULLBRIGHT))
198 self.effects |= EF_FULLBRIGHT;
200 if (self.items & ITEM_Invisibility.m_itemid)
202 play_countdown(self.strength_finished, SND(POWEROFF));
203 if (time > self.strength_finished)
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);
213 if (time < self.strength_finished)
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);
223 if (self.items & ITEM_Speed.m_itemid)
225 play_countdown(self.invincible_finished, SND(POWEROFF));
226 if (time > self.invincible_finished)
228 self.items &= ~ITEM_Speed.m_itemid;
229 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
234 if (time < self.invincible_finished)
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);
244 .float stat_sv_maxspeed;
246 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
248 if(self.items & ITEM_Speed.m_itemid)
249 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
254 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
257 damage_take = frag_damage;
262 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
264 // weapon dropping on death handled by FilterItem
269 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
271 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
274 if(IS_PLAYER(frag_target))
276 if(frag_deathtype == DEATH_FALL.m_id)
277 frag_damage = 0; // never count fall damage
279 if(!autocvar_g_instagib_damagedbycontents)
280 switch(DEATH_ENT(frag_deathtype))
289 if(IS_PLAYER(frag_attacker))
290 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
292 if(frag_target.armorvalue)
294 frag_target.armorvalue -= 1;
296 frag_target.damage_dealt += 1;
297 frag_attacker.damage_dealt += 1; // TODO: change this to a specific hitsound for armor hit
298 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
302 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
304 if(frag_deathtype & HITTYPE_SECONDARY)
306 if(!autocvar_g_instagib_blaster_keepdamage)
307 frag_damage = frag_mirrordamage = 0;
309 if(frag_target != frag_attacker)
311 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
312 if(!autocvar_g_instagib_blaster_keepforce)
313 frag_force = '0 0 0';
319 if(IS_PLAYER(frag_attacker))
320 if(frag_mirrordamage > 0)
322 // just lose extra LIVES, don't kill the player for mirror damage
323 if(frag_attacker.armorvalue > 0)
325 frag_attacker.armorvalue -= 1;
326 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
327 frag_attacker.damage_dealt += frag_mirrordamage;
329 frag_mirrordamage = 0;
332 if((frag_target.buffs & BUFF_INVISIBLE.m_itemid) || (frag_target.items & ITEM_Invisibility.m_itemid))
338 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
340 start_health = warmup_start_health = 100;
341 start_armorvalue = warmup_start_armorvalue = 0;
343 start_ammo_shells = warmup_start_ammo_shells = 0;
344 start_ammo_nails = warmup_start_ammo_nails = 0;
345 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
346 start_ammo_plasma = warmup_start_ammo_plasma = 0;
347 start_ammo_rockets = warmup_start_ammo_rockets = 0;
348 start_ammo_fuel = warmup_start_ammo_fuel = 0;
350 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
351 start_items |= IT_UNLIMITED_SUPERWEAPONS;
356 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
358 if(self.classname == "item_cells")
359 return true; // no normal cells?
361 if(self.weapon == WEP_VAPORIZER.m_id && self.classname == "droppedweapon")
363 self.ammo_cells = autocvar_g_instagib_ammo_drop;
367 if(self.weapon == WEP_DEVASTATOR.m_id || self.weapon == WEP_VORTEX.m_id)
370 setorigin(e, self.origin);
371 e.noalign = self.noalign;
374 e.spawnfunc_checked = true;
375 WITH(entity, self, e, spawnfunc_item_minst_cells(e));
379 if(self.flags & FL_POWERUP)
382 if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
383 self.ammo_cells = autocvar_g_instagib_ammo_drop;
385 if(self.ammo_cells && !self.weapon)
391 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
393 entity e = WaypointSprite_getviewentity(other);
395 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
396 // but only apply this to real players, not to spectators
397 if((self.owner.flags & FL_CLIENT) && (self.owner.items & ITEM_Invisibility.m_itemid) && (e == other))
398 if(DIFF_TEAM(self.owner, e))
404 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
406 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
407 frag_damage = 1000; // always gib if it was a vaporizer death
412 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
416 // play some cool sounds ;)
417 if (IS_CLIENT(other))
419 if(other.health <= 5)
420 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
421 else if(other.health < 50)
422 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
425 if(other.health < 100)
428 return MUT_ITEMTOUCH_CONTINUE;
433 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_instagib_extralives);
434 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
435 return MUT_ITEMTOUCH_PICKUP;
438 return MUT_ITEMTOUCH_CONTINUE;
441 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
443 if (!autocvar_g_powerups) { return false; }
444 // Can't use .itemdef here
445 if (!(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega"))
452 e.think = instagib_invisibility;
454 e.think = instagib_extralife;
456 e.think = instagib_speed;
458 e.nextthink = time + 0.1;
459 e.spawnflags = self.spawnflags;
460 e.noalign = self.noalign;
461 setorigin(e, self.origin);
466 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
468 ret_string = strcat(ret_string, ":instagib");
472 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
474 ret_string = strcat(ret_string, ", instagib");
478 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
480 modname = "InstaGib";