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"
21 #include "../../../items/all.qc"
23 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
25 spawnfunc(item_minst_cells)
27 if (!g_instagib) { remove(self); return; }
28 if (!self.ammo_cells) self.ammo_cells = autocvar_g_instagib_ammo_drop;
29 StartItem(this, ITEM_VaporizerCells);
32 void instagib_invisibility()
34 self.strength_finished = autocvar_g_balance_powerup_strength_time;
35 StartItem(this, ITEM_Invisibility);
38 void instagib_extralife()
41 StartItem(this, ITEM_ExtraLife);
46 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
47 StartItem(this, ITEM_Speed);
50 .float instagib_nextthink;
51 .float instagib_needammo;
52 void instagib_stop_countdown(entity e)
54 if (!e.instagib_needammo)
56 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_INSTAGIB_FINDAMMO);
57 e.instagib_needammo = false;
59 void instagib_ammocheck()
61 if(time < self.instagib_nextthink)
64 return; // not a player
66 if(self.deadflag || gameover)
67 instagib_stop_countdown(self);
68 else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO) || (self.flags & FL_GODMODE))
69 instagib_stop_countdown(self);
70 else if(autocvar_g_rm && autocvar_g_rm_laser)
72 if(!self.instagib_needammo)
74 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
75 self.instagib_needammo = true;
80 self.instagib_needammo = true;
83 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
84 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
86 else if (self.health <= 10)
88 Damage(self, self, self, 5, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
89 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_1);
91 else if (self.health <= 20)
93 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
94 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_2);
96 else if (self.health <= 30)
98 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
99 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_3);
101 else if (self.health <= 40)
103 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
104 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_4);
106 else if (self.health <= 50)
108 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
109 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_5);
111 else if (self.health <= 60)
113 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
114 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_6);
116 else if (self.health <= 70)
118 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
119 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_7);
121 else if (self.health <= 80)
123 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
124 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_8);
126 else if (self.health <= 90)
128 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
129 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
130 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, ANNCE_NUM_9);
134 Send_Notification(NOTIF_ONE_ONLY, self, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
135 Damage(self, self, self, 10, DEATH_NOAMMO.m_id, self.origin, '0 0 0');
138 self.instagib_nextthink = time + 1;
141 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
144 FOR_EACH_PLAYER(head)
145 instagib_stop_countdown(head);
150 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
152 other.monster_loot = spawnfunc_item_minst_cells;
157 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
159 // always refill ammo
160 if(self.monsterid == MON_MAGE.monsterid)
166 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
168 if (checkentity.items & ITEM_Invisibility.m_itemid)
174 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
176 instagib_stop_countdown(self);
180 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
182 self.effects |= EF_FULLBRIGHT;
186 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
188 instagib_ammocheck();
192 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
194 // no regeneration in instagib
198 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
200 if (!(self.effects & EF_FULLBRIGHT))
201 self.effects |= EF_FULLBRIGHT;
203 if (self.items & ITEM_Invisibility.m_itemid)
205 play_countdown(self.strength_finished, SND(POWEROFF));
206 if (time > self.strength_finished)
208 self.alpha = default_player_alpha;
209 self.exteriorweaponentity.alpha = default_weapon_alpha;
210 self.items &= ~ITEM_Invisibility.m_itemid;
211 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
216 if (time < self.strength_finished)
218 self.alpha = autocvar_g_instagib_invis_alpha;
219 self.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
220 self.items |= ITEM_Invisibility.m_itemid;
221 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_INVISIBILITY, self.netname);
222 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
226 if (self.items & ITEM_Speed.m_itemid)
228 play_countdown(self.invincible_finished, SND(POWEROFF));
229 if (time > self.invincible_finished)
231 self.items &= ~ITEM_Speed.m_itemid;
232 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
237 if (time < self.invincible_finished)
239 self.items |= ITEM_Speed.m_itemid;
240 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SPEED, self.netname);
241 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SPEED);
247 .float stat_sv_maxspeed;
249 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
251 if(self.items & ITEM_Speed.m_itemid)
252 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
257 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
260 damage_take = frag_damage;
265 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
267 // weapon dropping on death handled by FilterItem
272 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
274 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
277 if(IS_PLAYER(frag_target))
279 if(frag_deathtype == DEATH_FALL.m_id)
280 frag_damage = 0; // never count fall damage
282 if(!autocvar_g_instagib_damagedbycontents)
283 switch(DEATH_ENT(frag_deathtype))
292 if(IS_PLAYER(frag_attacker))
293 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
295 if(frag_target.armorvalue)
297 frag_target.armorvalue -= 1;
299 frag_target.damage_dealt += 1;
300 frag_attacker.damage_dealt += 1; // TODO: change this to a specific hitsound for armor hit
301 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
305 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
307 if(frag_deathtype & HITTYPE_SECONDARY)
309 if(!autocvar_g_instagib_blaster_keepdamage)
310 frag_damage = frag_mirrordamage = 0;
312 if(frag_target != frag_attacker)
314 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
315 if(!autocvar_g_instagib_blaster_keepforce)
316 frag_force = '0 0 0';
322 if(IS_PLAYER(frag_attacker))
323 if(frag_mirrordamage > 0)
325 // just lose extra LIVES, don't kill the player for mirror damage
326 if(frag_attacker.armorvalue > 0)
328 frag_attacker.armorvalue -= 1;
329 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
330 frag_attacker.damage_dealt += frag_mirrordamage;
332 frag_mirrordamage = 0;
335 if(frag_target.alpha && frag_target.alpha < 1)
341 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
343 start_health = warmup_start_health = 100;
344 start_armorvalue = warmup_start_armorvalue = 0;
346 start_ammo_shells = warmup_start_ammo_shells = 0;
347 start_ammo_nails = warmup_start_ammo_nails = 0;
348 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
349 start_ammo_plasma = warmup_start_ammo_plasma = 0;
350 start_ammo_rockets = warmup_start_ammo_rockets = 0;
351 start_ammo_fuel = warmup_start_ammo_fuel = 0;
353 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
354 start_items |= IT_UNLIMITED_SUPERWEAPONS;
359 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
361 if(self.classname == "item_cells")
362 return true; // no normal cells?
364 if(self.weapon == WEP_VAPORIZER.m_id && self.classname == "droppedweapon")
366 self.ammo_cells = autocvar_g_instagib_ammo_drop;
370 if(self.weapon == WEP_DEVASTATOR.m_id || self.weapon == WEP_VORTEX.m_id)
373 setorigin(e, self.origin);
374 e.noalign = self.noalign;
377 e.spawnfunc_checked = true;
378 WITH(entity, self, e, spawnfunc_item_minst_cells(e));
382 if(self.flags & FL_POWERUP)
385 if(self.ammo_cells > autocvar_g_instagib_ammo_drop && self.classname != "item_minst_cells")
386 self.ammo_cells = autocvar_g_instagib_ammo_drop;
388 if(self.ammo_cells && !self.weapon)
394 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
396 entity e = WaypointSprite_getviewentity(other);
398 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
399 // but only apply this to real players, not to spectators
400 if((self.owner.flags & FL_CLIENT) && (self.owner.items & ITEM_Invisibility.m_itemid) && (e == other))
401 if(DIFF_TEAM(self.owner, e))
407 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
409 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
410 frag_damage = 1000; // always gib if it was a vaporizer death
415 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
419 // play some cool sounds ;)
420 if (IS_CLIENT(other))
422 if(other.health <= 5)
423 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
424 else if(other.health < 50)
425 Send_Notification(NOTIF_ONE, other, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
428 if(other.health < 100)
431 return MUT_ITEMTOUCH_CONTINUE;
436 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_instagib_extralives);
437 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES);
438 return MUT_ITEMTOUCH_PICKUP;
441 return MUT_ITEMTOUCH_CONTINUE;
444 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
446 if (!autocvar_g_powerups) { return false; }
447 // Can't use .itemdef here
448 if (!(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega"))
455 e.think = instagib_invisibility;
457 e.think = instagib_extralife;
459 e.think = instagib_speed;
461 e.nextthink = time + 0.1;
462 e.spawnflags = self.spawnflags;
463 e.noalign = self.noalign;
464 setorigin(e, self.origin);
469 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
471 ret_string = strcat(ret_string, ":instagib");
475 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
477 ret_string = strcat(ret_string, ", instagib");
481 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
483 modname = "InstaGib";