1 #include "sv_instagib.qh"
3 #include <server/client.qh>
4 #include <common/items/_mod.qh>
5 #include "../random_items/sv_random_items.qh"
7 bool autocvar_g_instagib_damagedbycontents = true;
8 bool autocvar_g_instagib_blaster_keepdamage = false;
9 bool autocvar_g_instagib_blaster_keepforce = false;
10 bool autocvar_g_instagib_mirrordamage;
11 bool autocvar_g_instagib_friendlypush = true;
12 //int autocvar_g_instagib_ammo_drop;
13 bool autocvar_g_instagib_ammo_convert_cells;
14 bool autocvar_g_instagib_ammo_convert_rockets;
15 bool autocvar_g_instagib_ammo_convert_shells;
16 bool autocvar_g_instagib_ammo_convert_bullets;
17 float autocvar_g_instagib_speed_highspeed;
19 IntrusiveList g_instagib_items;
22 g_instagib_items = IL_NEW();
23 IL_PUSH(g_instagib_items, ITEM_VaporizerCells);
24 IL_PUSH(g_instagib_items, ITEM_ExtraLife);
25 IL_PUSH(g_instagib_items, ITEM_Invisibility);
26 IL_PUSH(g_instagib_items, ITEM_Speed);
29 void instagib_invisibility(entity this)
31 this.strength_finished = autocvar_g_instagib_invisibility_time;
32 StartItem(this, ITEM_Invisibility);
35 void instagib_extralife(entity this)
37 StartItem(this, ITEM_ExtraLife);
40 void instagib_speed(entity this)
42 this.invincible_finished = autocvar_g_instagib_speed_time;
43 StartItem(this, ITEM_Speed);
46 /// \brief Returns a random classname of the instagib item.
47 /// \param[in] prefix Prefix of the cvars that hold probabilities.
48 /// \return Random classname of the instagib item.
49 string RandomItems_GetRandomInstagibItemClassName(string prefix)
51 RandomSelection_Init();
52 IL_EACH(g_instagib_items, Item_IsDefinitionAllowed(it),
54 string cvar_name = sprintf("g_%s_%s_probability", prefix,
55 it.m_canonical_spawnfunc);
56 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
58 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
61 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
63 return RandomSelection_chosen_string;
66 .float instagib_nextthink;
67 .float instagib_needammo;
68 void instagib_stop_countdown(entity e)
70 if (!e.instagib_needammo)
72 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
73 e.instagib_needammo = false;
75 void instagib_ammocheck(entity this)
77 if(time < this.instagib_nextthink)
80 return; // not a player
82 if(IS_DEAD(this) || game_stopped)
83 instagib_stop_countdown(this);
84 else if (GetResource(this, RES_CELLS) > 0 || (this.items & IT_UNLIMITED_AMMO) || (this.flags & FL_GODMODE))
85 instagib_stop_countdown(this);
86 else if(autocvar_g_rm && autocvar_g_rm_laser)
88 if(!this.instagib_needammo)
90 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
91 this.instagib_needammo = true;
96 float hp = GetResource(this, RES_HEALTH);
97 this.instagib_needammo = true;
100 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
101 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
105 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
106 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
110 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
111 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
115 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
116 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
120 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
121 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
125 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
126 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
130 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
131 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
135 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
136 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
140 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
141 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
145 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
146 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
147 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
151 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
152 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
155 this.instagib_nextthink = time + 1;
158 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
160 FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
163 MUTATOR_HOOKFUNCTION(mutator_instagib, RandomItems_GetRandomItemClassName)
165 M_ARGV(1, string) = RandomItems_GetRandomInstagibItemClassName(
170 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
172 entity item = M_ARGV(1, entity);
174 item.monster_loot = ITEM_VaporizerCells;
177 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
179 entity mon = M_ARGV(0, entity);
181 // always refill ammo
182 if(mon.monsterid == MON_MAGE.monsterid)
186 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
188 entity targ = M_ARGV(1, entity);
190 if (targ.items & ITEM_Invisibility.m_itemid)
194 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
196 entity player = M_ARGV(0, entity);
198 instagib_stop_countdown(player);
201 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidRandomStartWeapons)
206 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
208 entity player = M_ARGV(0, entity);
210 player.effects |= EF_FULLBRIGHT;
213 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
215 entity player = M_ARGV(0, entity);
217 instagib_ammocheck(player);
220 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
222 // no regeneration in instagib
226 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
228 entity player = M_ARGV(0, entity);
230 if (!(player.effects & EF_FULLBRIGHT))
231 player.effects |= EF_FULLBRIGHT;
233 if (player.items & ITEM_Invisibility.m_itemid)
235 play_countdown(player, player.strength_finished, SND_POWEROFF);
236 if (time > player.strength_finished)
238 player.alpha = default_player_alpha;
239 player.exteriorweaponentity.alpha = default_weapon_alpha;
240 player.items &= ~ITEM_Invisibility.m_itemid;
241 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
246 if (time < player.strength_finished)
248 player.alpha = autocvar_g_instagib_invis_alpha;
249 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
250 player.items |= ITEM_Invisibility.m_itemid;
251 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
252 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
256 if (player.items & ITEM_Speed.m_itemid)
258 play_countdown(player, player.invincible_finished, SND_POWEROFF);
259 if (time > player.invincible_finished)
261 player.items &= ~ITEM_Speed.m_itemid;
262 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
267 if (time < player.invincible_finished)
269 player.items |= ITEM_Speed.m_itemid;
270 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
271 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
276 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics_UpdateStats)
278 entity player = M_ARGV(0, entity);
279 // these automatically reset, no need to worry
281 if(player.items & ITEM_Speed.m_itemid)
282 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_instagib_speed_highspeed;
285 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
287 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
288 M_ARGV(5, float) = 0; // save
291 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
293 // weapon dropping on death handled by FilterItem
297 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
299 entity frag_attacker = M_ARGV(1, entity);
300 entity frag_target = M_ARGV(2, entity);
301 float frag_deathtype = M_ARGV(3, float);
302 float frag_damage = M_ARGV(4, float);
303 float frag_mirrordamage = M_ARGV(5, float);
304 vector frag_force = M_ARGV(6, vector);
306 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
309 if(IS_PLAYER(frag_target))
311 if(frag_deathtype == DEATH_FALL.m_id)
312 frag_damage = 0; // never count fall damage
314 if(!autocvar_g_instagib_damagedbycontents)
315 switch(DEATH_ENT(frag_deathtype))
324 if(IS_PLAYER(frag_attacker))
325 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
327 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
328 frag_force = '0 0 0';
330 float armor = GetResource(frag_target, RES_ARMOR);
334 SetResource(frag_target, RES_ARMOR, armor);
336 frag_target.damage_dealt += 1;
337 frag_attacker.damage_dealt += 1;
338 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
342 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
344 if(frag_deathtype & HITTYPE_SECONDARY)
346 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
349 if(!autocvar_g_instagib_mirrordamage)
350 frag_mirrordamage = 0; // never do mirror damage on enemies
353 if(frag_target != frag_attacker)
355 if(!autocvar_g_instagib_blaster_keepforce)
356 frag_force = '0 0 0';
362 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
363 if(IS_PLAYER(frag_attacker))
364 if(frag_mirrordamage > 0)
366 // just lose extra LIVES, don't kill the player for mirror damage
367 float armor = GetResource(frag_attacker, RES_ARMOR);
371 SetResource(frag_attacker, RES_ARMOR, armor);
372 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
373 frag_attacker.damage_dealt += frag_mirrordamage;
375 frag_mirrordamage = 0;
378 if(frag_target.alpha && frag_target.alpha < 1)
379 if(IS_PLAYER(frag_target))
382 M_ARGV(4, float) = frag_damage;
383 M_ARGV(5, float) = frag_mirrordamage;
384 M_ARGV(6, vector) = frag_force;
387 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems, CBC_ORDER_LAST)
389 start_health = warmup_start_health = 100;
390 start_armorvalue = warmup_start_armorvalue = 0;
392 start_ammo_shells = warmup_start_ammo_shells = 0;
393 start_ammo_nails = warmup_start_ammo_nails = 0;
394 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
395 start_ammo_plasma = warmup_start_ammo_plasma = 0;
396 start_ammo_rockets = warmup_start_ammo_rockets = 0;
397 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
399 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
400 start_items |= IT_UNLIMITED_SUPERWEAPONS;
403 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
405 // turn weapon arena off
406 M_ARGV(0, string) = "off";
409 void replace_with_insta_cells(entity item)
411 entity e = new(item_vaporizer_cells);
412 setorigin(e, item.origin);
413 e.noalign = Item_ShouldKeepPosition(item);
416 e.spawnfunc_checked = true;
417 spawnfunc_item_vaporizer_cells(e);
420 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
422 entity item = M_ARGV(0, entity);
424 if(item.classname == "item_cells")
426 if(autocvar_g_instagib_ammo_convert_cells)
428 replace_with_insta_cells(item);
432 else if(item.classname == "item_rockets")
434 if(autocvar_g_instagib_ammo_convert_rockets)
436 replace_with_insta_cells(item);
440 else if(item.classname == "item_shells")
442 if(autocvar_g_instagib_ammo_convert_shells)
444 replace_with_insta_cells(item);
448 else if(item.classname == "item_bullets")
450 if(autocvar_g_instagib_ammo_convert_bullets)
452 replace_with_insta_cells(item);
457 if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
459 SetResource(item, RES_CELLS, autocvar_g_instagib_ammo_drop);
463 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
465 replace_with_insta_cells(item);
469 if(item.flags & FL_POWERUP)
472 float cells = GetResource(item, RES_CELLS);
473 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
474 SetResource(item, RES_CELLS, autocvar_g_instagib_ammo_drop);
476 if(cells && !item.weapon)
482 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
484 entity wp = M_ARGV(0, entity);
485 entity player = M_ARGV(1, entity);
487 entity e = WaypointSprite_getviewentity(player);
489 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
490 // but only apply this to real players, not to spectators
491 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
492 if(DIFF_TEAM(wp.owner, e))
496 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
498 float frag_deathtype = M_ARGV(3, float);
500 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
501 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
504 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
506 entity item = M_ARGV(0, entity);
507 entity toucher = M_ARGV(1, entity);
509 if(GetResource(item, RES_CELLS))
511 // play some cool sounds ;)
512 float hp = GetResource(toucher, RES_HEALTH);
513 if (IS_CLIENT(toucher))
516 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
518 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
522 SetResource(toucher, RES_HEALTH, 100);
524 return MUT_ITEMTOUCH_CONTINUE;
527 if(item.itemdef == ITEM_ExtraLife)
529 GiveResource(toucher, RES_ARMOR, autocvar_g_instagib_extralives);
530 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_instagib_extralives);
531 return MUT_ITEMTOUCH_PICKUP;
534 return MUT_ITEMTOUCH_CONTINUE;
537 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
539 if (!autocvar_g_powerups) { return; }
540 entity ent = M_ARGV(0, entity);
541 // Can't use .itemdef here
542 if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
550 e.classname = "item_invisibility";
551 setthink(e, instagib_invisibility);
555 e.classname = "item_extralife";
556 setthink(e, instagib_extralife);
560 e.classname = "item_speed";
561 setthink(e, instagib_speed);
564 e.nextthink = time + 0.1;
565 e.spawnflags = ent.spawnflags;
566 e.noalign = ent.noalign;
567 setorigin(e, ent.origin);
572 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
574 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
577 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
579 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
582 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
584 M_ARGV(0, string) = "InstaGib";