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 /// \brief Returns a random classname of the overkill item.
14 /// \param[in] prefix Prefix of the cvars that hold probabilities.
15 /// \return Random classname of the overkill item.
16 string RandomItems_GetRandomOverkillItemClassName(string prefix)
18 RandomSelection_Init();
19 IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
20 Item_IsDefinitionAllowed(it),
22 string cvar_name = sprintf("g_%s_%s_probability", prefix,
23 it.m_canonical_spawnfunc);
24 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
26 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
29 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
31 string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
32 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
34 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
38 RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
40 cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
41 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
43 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
47 RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
49 return RandomSelection_chosen_string;
53 MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
55 M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
60 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
62 entity frag_attacker = M_ARGV(1, entity);
63 entity frag_target = M_ARGV(2, entity);
64 float frag_deathtype = M_ARGV(3, float);
66 if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
67 if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
69 if(frag_attacker != frag_target)
70 if(!STAT(FROZEN, frag_target))
71 if(!IS_DEAD(frag_target))
73 M_ARGV(6, vector) = '0 0 0'; // force
76 M_ARGV(4, float) = 0; // damage
80 void ok_DropItem(entity this, entity targ)
84 Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
85 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
88 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
90 entity frag_attacker = M_ARGV(1, entity);
91 entity frag_target = M_ARGV(2, entity);
93 entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
95 ok_DropItem(frag_target, targ);
97 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
99 .entity weaponentity = weaponentities[slot];
101 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
105 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
107 entity mon = M_ARGV(0, entity);
108 entity olditem = M_ARGV(1, entity);
109 entity frag_attacker = M_ARGV(2, entity);
113 M_ARGV(1, entity) = NULL;
115 ok_DropItem(mon, frag_attacker);
118 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
123 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
129 entity player = M_ARGV(0, entity);
130 if (!IS_PLAYER(player) || IS_DEAD(player) || STAT(FROZEN, player))
134 if (!PHYS_INPUT_BUTTON_ATCK2(player) || weaponLocked(player) ||
135 !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
139 // Allow secondary blaster during countdown.
140 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
142 .entity weaponentity = weaponentities[slot];
143 Weapon weapon = player.(weaponentity).m_weapon;
144 if (weapon == WEP_Null && slot != 0)
148 weapon.wr_think(weapon, player, weaponentity, 2);
150 PHYS_INPUT_BUTTON_ATCK2(player) = false;
153 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
158 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
160 entity player = M_ARGV(0, entity);
162 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
164 .entity weaponentity = weaponentities[slot];
165 entity thiswep = player.(weaponentity);
167 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
169 Weapon newwep = player.ok_lastwep[slot];
170 if(player.ok_lastwep[slot] == WEP_OVERKILL_HMG)
171 newwep = WEP_OVERKILL_MACHINEGUN;
172 if(player.ok_lastwep[slot] == WEP_OVERKILL_RPC)
173 newwep = WEP_OVERKILL_NEX;
174 thiswep.m_switchweapon = newwep;
175 player.ok_lastwep[slot] = WEP_Null;
180 bool ok_HandleItemWaypoints(entity e)
182 if(!autocvar_g_overkill_itemwaypoints)
183 return false; // don't handle it
187 case ITEM_HealthMega: return true;
188 case ITEM_ArmorMedium: return true;
189 case ITEM_ArmorBig: return true;
190 case ITEM_ArmorMega: return true;
196 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
198 entity item = M_ARGV(0, entity);
199 return ok_HandleItemWaypoints(item);
202 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
204 entity item = M_ARGV(0, entity);
205 return ok_HandleItemWaypoints(item);
208 MUTATOR_HOOKFUNCTION(ok, FilterItem)
210 entity item = M_ARGV(0, entity);
218 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
219 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
220 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
221 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
223 if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
227 if (item.classname == "item_strength")
229 entity wep = new(weapon_okhmg);
230 setorigin(wep, item.origin);
232 wep.noalign = Item_ShouldKeepPosition(item);
234 wep.team = item.team;
235 wep.respawntime = g_pickup_respawntime_superweapon;
236 wep.pickup_anyway = true;
237 wep.spawnfunc_checked = true;
238 Item_Initialize(wep, "weapon_okhmg"); // doesn't actually use spawnfunc
241 else if (item.classname == "item_shield")
243 entity wep = new(weapon_okrpc);
244 setorigin(wep, item.origin);
246 wep.noalign = Item_ShouldKeepPosition(item);
248 wep.team = item.team;
249 wep.respawntime = g_pickup_respawntime_superweapon;
250 wep.pickup_anyway = true;
251 wep.spawnfunc_checked = true;
252 Item_Initialize(wep, "weapon_okrpc"); // doesn't actually use spawnfunc
258 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
260 WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_NEX) | WEPSET(OVERKILL_SHOTGUN));
262 if(WEP_OVERKILL_RPC.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_RPC); }
263 if(WEP_OVERKILL_HMG.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_HMG); }
265 // this gives unlimited ammo (the 4 types) but not fuel
266 // using `g_use_ammunition` instead gives also fuel which is unnecessary and distracting in the HUD
267 start_items |= IT_UNLIMITED_AMMO;
269 start_weapons = warmup_start_weapons = ok_start_items;
272 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
274 // turn weapon arena off
275 M_ARGV(0, string) = "off";
278 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
280 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
283 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
285 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
288 MUTATOR_HOOKFUNCTION(ok, SetModname)
290 M_ARGV(0, string) = "Overkill";