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 <common/items/all.qc>
23 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
25 spawnfunc(item_minst_cells)
27 if (!g_instagib) { delete(this); return; }
28 if (!this.ammo_cells) this.ammo_cells = autocvar_g_instagib_ammo_drop;
29 StartItem(this, ITEM_VaporizerCells);
32 void instagib_invisibility(entity this)
34 this.strength_finished = autocvar_g_balance_powerup_strength_time;
35 StartItem(this, ITEM_Invisibility);
38 void instagib_extralife(entity this)
40 StartItem(this, ITEM_ExtraLife);
43 void instagib_speed(entity this)
45 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
46 StartItem(this, ITEM_Speed);
49 .float instagib_nextthink;
50 .float instagib_needammo;
51 void instagib_stop_countdown(entity e)
53 if (!e.instagib_needammo)
55 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
56 e.instagib_needammo = false;
58 void instagib_ammocheck(entity this)
60 if(time < this.instagib_nextthink)
63 return; // not a player
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)
71 if(!this.instagib_needammo)
73 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
74 this.instagib_needammo = true;
79 this.instagib_needammo = true;
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);
85 else if (this.health <= 10)
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);
90 else if (this.health <= 20)
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);
95 else if (this.health <= 30)
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);
100 else if (this.health <= 40)
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);
105 else if (this.health <= 50)
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);
110 else if (this.health <= 60)
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);
115 else if (this.health <= 70)
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);
120 else if (this.health <= 80)
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);
125 else if (this.health <= 90)
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);
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');
137 this.instagib_nextthink = time + 1;
140 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
142 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(instagib_stop_countdown(it)));
145 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
147 entity item = M_ARGV(1, entity);
149 item.monster_loot = spawnfunc_item_minst_cells;
152 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
154 entity mon = M_ARGV(0, entity);
156 // always refill ammo
157 if(mon.monsterid == MON_MAGE.monsterid)
161 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
163 entity targ = M_ARGV(1, entity);
165 if (targ.items & ITEM_Invisibility.m_itemid)
169 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
171 entity player = M_ARGV(0, entity);
173 instagib_stop_countdown(player);
176 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
178 entity player = M_ARGV(0, entity);
180 player.effects |= EF_FULLBRIGHT;
183 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
185 entity player = M_ARGV(0, entity);
187 instagib_ammocheck(player);
190 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
192 // no regeneration in instagib
196 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
198 entity player = M_ARGV(0, entity);
200 if (!(player.effects & EF_FULLBRIGHT))
201 player.effects |= EF_FULLBRIGHT;
203 if (player.items & ITEM_Invisibility.m_itemid)
205 play_countdown(player, player.strength_finished, SND_POWEROFF);
206 if (time > player.strength_finished)
208 player.alpha = default_player_alpha;
209 player.exteriorweaponentity.alpha = default_weapon_alpha;
210 player.items &= ~ITEM_Invisibility.m_itemid;
211 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
216 if (time < player.strength_finished)
218 player.alpha = autocvar_g_instagib_invis_alpha;
219 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
220 player.items |= ITEM_Invisibility.m_itemid;
221 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
222 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
226 if (player.items & ITEM_Speed.m_itemid)
228 play_countdown(player, player.invincible_finished, SND_POWEROFF);
229 if (time > player.invincible_finished)
231 player.items &= ~ITEM_Speed.m_itemid;
232 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
237 if (time < player.invincible_finished)
239 player.items |= ITEM_Speed.m_itemid;
240 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
241 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
246 .float stat_sv_maxspeed;
248 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
250 entity player = M_ARGV(0, entity);
252 if(player.items & ITEM_Speed.m_itemid)
253 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
256 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
258 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
259 M_ARGV(5, float) = 0; // save
262 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
264 // weapon dropping on death handled by FilterItem
268 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
270 entity frag_attacker = M_ARGV(1, entity);
271 entity frag_target = M_ARGV(2, entity);
272 float frag_deathtype = M_ARGV(3, float);
273 float frag_damage = M_ARGV(4, float);
274 float frag_mirrordamage = M_ARGV(5, float);
275 vector frag_force = M_ARGV(6, vector);
277 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
280 if(IS_PLAYER(frag_target))
282 if(frag_deathtype == DEATH_FALL.m_id)
283 frag_damage = 0; // never count fall damage
285 if(!autocvar_g_instagib_damagedbycontents)
286 switch(DEATH_ENT(frag_deathtype))
295 if(IS_PLAYER(frag_attacker))
296 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
298 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
299 frag_force = '0 0 0';
301 if(frag_target.armorvalue)
303 frag_target.armorvalue -= 1;
305 frag_target.damage_dealt += 1;
306 frag_attacker.damage_dealt += 1;
307 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
311 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
313 if(frag_deathtype & HITTYPE_SECONDARY)
315 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
318 if(!autocvar_g_instagib_mirrordamage)
319 frag_mirrordamage = 0; // never do mirror damage on enemies
322 if(frag_target != frag_attacker)
324 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
325 if(!autocvar_g_instagib_blaster_keepforce)
326 frag_force = '0 0 0';
332 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
333 if(IS_PLAYER(frag_attacker))
334 if(frag_mirrordamage > 0)
336 // just lose extra LIVES, don't kill the player for mirror damage
337 if(frag_attacker.armorvalue > 0)
339 frag_attacker.armorvalue -= 1;
340 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
341 frag_attacker.damage_dealt += frag_mirrordamage;
343 frag_mirrordamage = 0;
346 if(frag_target.alpha && frag_target.alpha < 1)
347 if(IS_PLAYER(frag_target))
350 M_ARGV(4, float) = frag_damage;
351 M_ARGV(5, float) = frag_mirrordamage;
352 M_ARGV(6, vector) = frag_force;
355 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
357 start_health = warmup_start_health = 100;
358 start_armorvalue = warmup_start_armorvalue = 0;
360 start_ammo_shells = warmup_start_ammo_shells = 0;
361 start_ammo_nails = warmup_start_ammo_nails = 0;
362 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
363 start_ammo_plasma = warmup_start_ammo_plasma = 0;
364 start_ammo_rockets = warmup_start_ammo_rockets = 0;
365 start_ammo_fuel = warmup_start_ammo_fuel = 0;
367 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
368 start_items |= IT_UNLIMITED_SUPERWEAPONS;
371 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
373 entity item = M_ARGV(0, entity);
375 if(item.classname == "item_cells")
376 return true; // no normal cells?
378 if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
380 item.ammo_cells = autocvar_g_instagib_ammo_drop;
384 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
387 setorigin(e, item.origin);
388 e.noalign = item.noalign;
391 e.spawnfunc_checked = true;
392 spawnfunc_item_minst_cells(e);
396 if(item.flags & FL_POWERUP)
399 if(item.ammo_cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
400 item.ammo_cells = autocvar_g_instagib_ammo_drop;
402 if(item.ammo_cells && !item.weapon)
408 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
410 entity wp = M_ARGV(0, entity);
411 entity player = M_ARGV(1, entity);
413 entity e = WaypointSprite_getviewentity(player);
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((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
418 if(DIFF_TEAM(wp.owner, e))
422 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
424 float frag_deathtype = M_ARGV(3, float);
426 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
427 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
430 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
432 entity item = M_ARGV(0, entity);
433 entity toucher = M_ARGV(1, entity);
437 // play some cool sounds ;)
438 if (IS_CLIENT(toucher))
440 if(toucher.health <= 5)
441 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
442 else if(toucher.health < 50)
443 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
446 if(toucher.health < 100)
447 toucher.health = 100;
449 return MUT_ITEMTOUCH_CONTINUE;
452 if(item.itemdef == ITEM_ExtraLife)
454 toucher.armorvalue = bound(toucher.armorvalue, 999, toucher.armorvalue + autocvar_g_instagib_extralives);
455 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
456 return MUT_ITEMTOUCH_PICKUP;
459 return MUT_ITEMTOUCH_CONTINUE;
462 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
464 if (!autocvar_g_powerups) { return; }
465 entity ent = M_ARGV(0, entity);
466 // Can't use .itemdef here
467 if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
474 setthink(e, instagib_invisibility);
476 setthink(e, instagib_extralife);
478 setthink(e, instagib_speed);
480 e.nextthink = time + 0.1;
481 e.spawnflags = ent.spawnflags;
482 e.noalign = ent.noalign;
483 setorigin(e, ent.origin);
488 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
490 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
493 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
495 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
498 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
500 M_ARGV(0, string) = "InstaGib";