1 #include "sv_overkill.qh"
3 bool autocvar_g_overkill_powerups_replace;
5 bool autocvar_g_overkill_itemwaypoints = true;
7 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
9 IntrusiveList g_overkill_items;
12 g_overkill_items = IL_NEW();
13 IL_PUSH(g_overkill_items, ITEM_HealthMega);
14 IL_PUSH(g_overkill_items, ITEM_ArmorSmall);
15 IL_PUSH(g_overkill_items, ITEM_ArmorMedium);
16 IL_PUSH(g_overkill_items, ITEM_ArmorBig);
17 IL_PUSH(g_overkill_items, ITEM_ArmorMega);
20 /// \brief Returns a random classname of the overkill item.
21 /// \param[in] prefix Prefix of the cvars that hold probabilities.
22 /// \return Random classname of the overkill item.
23 string RandomItems_GetRandomOverkillItemClassName(string prefix)
25 RandomSelection_Init();
26 IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
27 Item_IsDefinitionAllowed(it),
29 string cvar_name = sprintf("g_%s_%s_probability", prefix,
30 it.m_canonical_spawnfunc);
31 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
33 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
36 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
38 string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
39 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
41 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
45 RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
47 cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
48 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
50 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
54 RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
56 return RandomSelection_chosen_string;
60 MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
62 M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
67 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
69 entity frag_attacker = M_ARGV(1, entity);
70 entity frag_target = M_ARGV(2, entity);
71 float frag_deathtype = M_ARGV(3, float);
73 if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
74 if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
76 if(frag_attacker != frag_target)
77 if(!STAT(FROZEN, frag_target))
78 if(!IS_DEAD(frag_target))
80 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
81 M_ARGV(6, vector) = '0 0 0'; // force
84 M_ARGV(4, float) = 0; // damage
88 void ok_DropItem(entity this, entity targ)
92 Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
93 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
96 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
98 entity frag_attacker = M_ARGV(1, entity);
99 entity frag_target = M_ARGV(2, entity);
101 entity targ = ((frag_attacker) ? frag_attacker : frag_target);
103 ok_DropItem(frag_target, targ);
105 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
107 .entity weaponentity = weaponentities[slot];
109 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
113 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
115 entity mon = M_ARGV(0, entity);
116 entity olditem = M_ARGV(1, entity);
117 entity frag_attacker = M_ARGV(2, entity);
121 M_ARGV(1, entity) = NULL;
123 ok_DropItem(mon, frag_attacker);
126 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
131 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
137 entity player = M_ARGV(0, entity);
138 if (!IS_PLAYER(player) || IS_DEAD(player) || STAT(FROZEN, player))
142 if (!PHYS_INPUT_BUTTON_ATCK2(player) || forbidWeaponUse(player) ||
143 !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
147 // Allow secondary blaster during countdown.
148 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
150 .entity weaponentity = weaponentities[slot];
151 Weapon weapon = player.(weaponentity).m_weapon;
152 if (weapon == WEP_Null && slot != 0)
156 weapon.wr_think(weapon, player, weaponentity, 2);
158 PHYS_INPUT_BUTTON_ATCK2(player) = false;
161 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
166 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
168 entity player = M_ARGV(0, entity);
170 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
172 .entity weaponentity = weaponentities[slot];
173 entity thiswep = player.(weaponentity);
175 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
177 Weapon newwep = player.ok_lastwep[slot];
178 if(player.ok_lastwep[slot] == WEP_OVERKILL_HMG)
179 newwep = WEP_OVERKILL_MACHINEGUN;
180 if(player.ok_lastwep[slot] == WEP_OVERKILL_RPC)
181 newwep = WEP_OVERKILL_NEX;
182 thiswep.m_switchweapon = newwep;
183 player.ok_lastwep[slot] = WEP_Null;
188 bool ok_HandleItemWaypoints(entity e)
190 if(!autocvar_g_overkill_itemwaypoints)
191 return false; // don't handle it
195 case ITEM_HealthMega: return true;
196 case ITEM_ArmorMedium: return true;
197 case ITEM_ArmorBig: return true;
198 case ITEM_ArmorMega: return true;
204 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
206 entity item = M_ARGV(0, entity);
207 return ok_HandleItemWaypoints(item);
210 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
212 entity item = M_ARGV(0, entity);
213 return ok_HandleItemWaypoints(item);
216 MUTATOR_HOOKFUNCTION(ok, FilterItem)
218 entity item = M_ARGV(0, entity);
226 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
227 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
228 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
229 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
231 if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
235 if (item.classname == "item_strength")
237 entity wep = new(weapon_okhmg);
238 setorigin(wep, item.origin);
240 wep.noalign = Item_ShouldKeepPosition(item);
242 wep.team = item.team;
243 wep.respawntime = g_pickup_respawntime_superweapon;
244 wep.pickup_anyway = true;
245 wep.spawnfunc_checked = true;
246 Item_Initialize(wep, "weapon_okhmg"); // doesn't actually use spawnfunc
249 else if (item.classname == "item_shield")
251 entity wep = new(weapon_okrpc);
252 setorigin(wep, item.origin);
254 wep.noalign = Item_ShouldKeepPosition(item);
256 wep.team = item.team;
257 wep.respawntime = g_pickup_respawntime_superweapon;
258 wep.pickup_anyway = true;
259 wep.spawnfunc_checked = true;
260 Item_Initialize(wep, "weapon_okrpc"); // doesn't actually use spawnfunc
266 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
268 WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_NEX) | WEPSET(OVERKILL_SHOTGUN));
270 if(WEP_OVERKILL_RPC.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_RPC); }
271 if(WEP_OVERKILL_HMG.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_HMG); }
273 start_items |= IT_UNLIMITED_WEAPON_AMMO;
274 start_weapons = warmup_start_weapons = ok_start_items;
277 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
279 // turn weapon arena off
280 M_ARGV(0, string) = "off";
283 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
285 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
288 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
290 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
293 MUTATOR_HOOKFUNCTION(ok, SetModname)
295 M_ARGV(0, string) = "Overkill";