1 #include "sv_overkill.qh"
3 #include "okshotgun.qh"
7 bool autocvar_g_overkill_powerups_replace;
9 bool autocvar_g_overkill_itemwaypoints = true;
11 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
13 IntrusiveList g_overkill_items;
16 g_overkill_items = IL_NEW();
17 IL_PUSH(g_overkill_items, ITEM_HealthMega);
18 IL_PUSH(g_overkill_items, ITEM_ArmorSmall);
19 IL_PUSH(g_overkill_items, ITEM_ArmorMedium);
20 IL_PUSH(g_overkill_items, ITEM_ArmorBig);
21 IL_PUSH(g_overkill_items, ITEM_ArmorMega);
24 /// \brief Returns a random classname of the overkill item.
25 /// \param[in] prefix Prefix of the cvars that hold probabilities.
26 /// \return Random classname of the overkill item.
27 string RandomItems_GetRandomOverkillItemClassName(string prefix)
29 RandomSelection_Init();
30 IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
31 Item_IsDefinitionAllowed(it),
33 string cvar_name = sprintf("g_%s_%s_probability", prefix,
34 it.m_canonical_spawnfunc);
35 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
37 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
40 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
42 string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
43 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
45 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
49 RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
51 cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
52 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
54 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
58 RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
60 return RandomSelection_chosen_string;
64 MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
66 M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
71 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
73 entity frag_attacker = M_ARGV(1, entity);
74 entity frag_target = M_ARGV(2, entity);
75 float frag_deathtype = M_ARGV(3, float);
77 if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
78 if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
80 if(frag_attacker != frag_target)
81 if(!STAT(FROZEN, frag_target))
82 if(!IS_DEAD(frag_target))
84 M_ARGV(6, vector) = '0 0 0'; // force
87 M_ARGV(4, float) = 0; // damage
91 void ok_DropItem(entity this, entity targ)
95 Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
96 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
99 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
101 entity frag_attacker = M_ARGV(1, entity);
102 entity frag_target = M_ARGV(2, entity);
104 entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
106 ok_DropItem(frag_target, targ);
108 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
110 .entity weaponentity = weaponentities[slot];
112 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
116 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
118 entity mon = M_ARGV(0, entity);
119 entity olditem = M_ARGV(1, entity);
120 entity frag_attacker = M_ARGV(2, entity);
124 M_ARGV(1, entity) = NULL;
126 ok_DropItem(mon, frag_attacker);
129 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
134 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
140 entity player = M_ARGV(0, entity);
141 if (!IS_PLAYER(player) || IS_DEAD(player) || STAT(FROZEN, player))
145 if (!PHYS_INPUT_BUTTON_ATCK2(player) || weaponLocked(player) ||
146 !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
150 // Allow secondary blaster during countdown.
151 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
153 .entity weaponentity = weaponentities[slot];
154 Weapon weapon = player.(weaponentity).m_weapon;
155 if (weapon == WEP_Null && slot != 0)
159 weapon.wr_think(weapon, player, weaponentity, 2);
161 PHYS_INPUT_BUTTON_ATCK2(player) = false;
164 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
169 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
171 entity player = M_ARGV(0, entity);
173 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
175 .entity weaponentity = weaponentities[slot];
176 entity thiswep = player.(weaponentity);
178 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
180 Weapon newwep = player.ok_lastwep[slot];
181 if(player.ok_lastwep[slot] == WEP_OVERKILL_HMG)
182 newwep = WEP_OVERKILL_MACHINEGUN;
183 if(player.ok_lastwep[slot] == WEP_OVERKILL_RPC)
184 newwep = WEP_OVERKILL_NEX;
185 thiswep.m_switchweapon = newwep;
186 player.ok_lastwep[slot] = WEP_Null;
191 bool ok_HandleItemWaypoints(entity e)
193 if(!autocvar_g_overkill_itemwaypoints)
194 return false; // don't handle it
198 case ITEM_HealthMega: return true;
199 case ITEM_ArmorMedium: return true;
200 case ITEM_ArmorBig: return true;
201 case ITEM_ArmorMega: return true;
207 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
209 entity item = M_ARGV(0, entity);
210 return ok_HandleItemWaypoints(item);
213 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
215 entity item = M_ARGV(0, entity);
216 return ok_HandleItemWaypoints(item);
219 MUTATOR_HOOKFUNCTION(ok, FilterItem)
221 entity item = M_ARGV(0, entity);
229 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
230 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
231 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
232 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
234 if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
238 if (item.classname == "item_strength")
240 entity wep = new(weapon_okhmg);
241 setorigin(wep, item.origin);
243 wep.noalign = Item_ShouldKeepPosition(item);
245 wep.team = item.team;
246 wep.respawntime = g_pickup_respawntime_superweapon;
247 wep.pickup_anyway = true;
248 wep.spawnfunc_checked = true;
249 Item_Initialize(wep, "weapon_okhmg"); // doesn't actually use spawnfunc
252 else if (item.classname == "item_shield")
254 entity wep = new(weapon_okrpc);
255 setorigin(wep, item.origin);
257 wep.noalign = Item_ShouldKeepPosition(item);
259 wep.team = item.team;
260 wep.respawntime = g_pickup_respawntime_superweapon;
261 wep.pickup_anyway = true;
262 wep.spawnfunc_checked = true;
263 Item_Initialize(wep, "weapon_okrpc"); // doesn't actually use spawnfunc
269 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
271 WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_NEX) | WEPSET(OVERKILL_SHOTGUN));
273 if(WEP_OVERKILL_RPC.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_RPC); }
274 if(WEP_OVERKILL_HMG.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_HMG); }
276 // this gives unlimited ammo (the 4 types) but not fuel
277 // using `g_use_ammunition` instead gives also fuel which is unnecessary and distracting in the HUD
278 start_items |= IT_UNLIMITED_AMMO;
280 start_weapons = warmup_start_weapons = ok_start_items;
283 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
285 // turn weapon arena off
286 M_ARGV(0, string) = "off";
289 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
291 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
294 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
296 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
299 MUTATOR_HOOKFUNCTION(ok, SetModname)
301 M_ARGV(0, string) = "Overkill";