From 4e4a3363115b1ec692b87ed4109623937d76e326 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Fri, 10 Nov 2017 14:09:29 +0300 Subject: [PATCH] Added ITEM_FLAG_OVERKILL. --- qcsrc/common/items/item.qh | 3 +- qcsrc/common/items/item/armor.qh | 4 ++ qcsrc/common/items/item/health.qh | 1 + .../common/mutators/mutator/instagib/items.qh | 8 +-- .../mutators/mutator/overkill/sv_overkill.qc | 30 +++++++--- .../mutator/random_items/sv_random_items.qc | 57 ++++--------------- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 1d2c8d671..01bf81a9d 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -59,7 +59,8 @@ const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FU enum { ITEM_FLAG_INSTAGIB = BIT(0), ///< Item is usable in instagib. - ITEM_FLAG_MUTATORBLOCKED = BIT(1) + ITEM_FLAG_OVERKILL = BIT(1), ///< Item is usable in overkill. + ITEM_FLAG_MUTATORBLOCKED = BIT(2) }; #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__) diff --git a/qcsrc/common/items/item/armor.qh b/qcsrc/common/items/item/armor.qh index 9a9326c43..53255f9f1 100644 --- a/qcsrc/common/items/item/armor.qh +++ b/qcsrc/common/items/item/armor.qh @@ -34,6 +34,7 @@ void item_armorsmall_init(entity item) REGISTER_ITEM(ArmorSmall, Armor) { this.m_canonical_spawnfunc = "item_armor_small"; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_OVERKILL; this.m_model = MDL_ArmorSmall_ITEM; this.m_sound = SND_ArmorSmall; #endif @@ -71,6 +72,7 @@ void item_armormedium_init(entity item) REGISTER_ITEM(ArmorMedium, Armor) { this.m_canonical_spawnfunc = "item_armor_medium"; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_OVERKILL; this.m_model = MDL_ArmorMedium_ITEM; this.m_sound = SND_ArmorMedium; #endif @@ -108,6 +110,7 @@ void item_armorbig_init(entity item) REGISTER_ITEM(ArmorBig, Armor) { this.m_canonical_spawnfunc = "item_armor_big"; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_OVERKILL; this.m_model = MDL_ArmorBig_ITEM; this.m_sound = SND_ArmorBig; #endif @@ -147,6 +150,7 @@ void item_armormega_init(entity item) REGISTER_ITEM(ArmorMega, Armor) { this.m_canonical_spawnfunc = "item_armor_mega"; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_OVERKILL; this.m_model = MDL_ArmorMega_ITEM; this.m_sound = SND_ArmorMega; #endif diff --git a/qcsrc/common/items/item/health.qh b/qcsrc/common/items/item/health.qh index 3ffb5728b..a64a37701 100644 --- a/qcsrc/common/items/item/health.qh +++ b/qcsrc/common/items/item/health.qh @@ -147,6 +147,7 @@ void item_healthmega_init(entity item) REGISTER_ITEM(HealthMega, Health) { this.m_canonical_spawnfunc = "item_health_mega"; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_OVERKILL; this.m_model = MDL_HealthMega_ITEM; this.m_sound = SND_HealthMega; #endif diff --git a/qcsrc/common/mutators/mutator/instagib/items.qh b/qcsrc/common/mutators/mutator/instagib/items.qh index e6354c936..ab6843ed5 100644 --- a/qcsrc/common/mutators/mutator/instagib/items.qh +++ b/qcsrc/common/mutators/mutator/instagib/items.qh @@ -24,8 +24,8 @@ void ammo_vaporizercells_init(entity item) #endif REGISTER_ITEM(VaporizerCells, Ammo) { this.m_canonical_spawnfunc = "item_vaporizer_cells"; - this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED; this.m_model = MDL_VaporizerCells_ITEM; this.m_sound = SND_VaporizerCells; #endif @@ -51,8 +51,8 @@ SOUND(ExtraLife, Item_Sound("megahealth")); REGISTER_ITEM(ExtraLife, Powerup) { this.m_canonical_spawnfunc = "item_extralife"; - this.spawnflags = ITEM_FLAG_INSTAGIB; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_INSTAGIB; this.m_model = MDL_ExtraLife_ITEM; this.m_sound = SND_ExtraLife; #endif @@ -81,8 +81,8 @@ void powerup_invisibility_init(entity item); REGISTER_ITEM(Invisibility, Powerup) { this.m_canonical_spawnfunc = "item_invisibility"; - this.spawnflags = ITEM_FLAG_INSTAGIB; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_INSTAGIB; this.m_model = MDL_Invisibility_ITEM; this.m_sound = SND_Invisibility; this.m_glow = true; @@ -116,8 +116,8 @@ void powerup_speed_init(entity item); REGISTER_ITEM(Speed, Powerup) { this.m_canonical_spawnfunc = "item_speed"; - this.spawnflags = ITEM_FLAG_INSTAGIB; #ifdef GAMEQC + this.spawnflags = ITEM_FLAG_INSTAGIB; this.m_model = MDL_Speed_ITEM; this.m_sound = SND_Speed; this.m_glow = true; diff --git a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc index 120fabe56..7462de81f 100644 --- a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc +++ b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc @@ -17,6 +17,23 @@ REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") & { precache_all_playermodels("models/ok_player/*.dpm"); + if (autocvar_g_overkill_filter_healthmega) + { + ITEM_HealthMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED; + } + if (autocvar_g_overkill_filter_armormedium) + { + ITEM_ArmorMedium.spawnflags |= ITEM_FLAG_MUTATORBLOCKED; + } + if (autocvar_g_overkill_filter_armorbig) + { + ITEM_ArmorBig.spawnflags |= ITEM_FLAG_MUTATORBLOCKED; + } + if (autocvar_g_overkill_filter_armormega) + { + ITEM_ArmorMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED; + } + WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; @@ -27,6 +44,11 @@ REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") & MUTATOR_ONREMOVE { + ITEM_HealthMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED; + ITEM_ArmorMedium.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED; + ITEM_ArmorBig.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED; + ITEM_ArmorMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED; + WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED; WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED; } @@ -247,14 +269,6 @@ MUTATOR_HOOKFUNCTION(ok, FilterItem) if(item.ok_item) return false; - switch(item.itemdef) - { - case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega; - case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium; - case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig; - case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega; - } - return true; } diff --git a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc index 2cf4b0a77..3e11d3af5 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc @@ -60,8 +60,6 @@ bool random_items_is_spawning = false; string RandomItems_GetRandomItemClassNameWithProperty(string prefix, .bool item_property); -string RandomItems_GetItemVarName(string class_name); - //=========================== Public API ====================================== string RandomItems_GetRandomItemClassName(string prefix) @@ -156,55 +154,22 @@ string RandomItems_GetRandomInstagibItemClassName(string prefix) string RandomItems_GetRandomOverkillItemClassName(string prefix) { RandomSelection_Init(); - string varname; - #define X(classname) MACRO_BEGIN \ - if ((varname = RandomItems_GetItemVarName(classname))) \ - { \ - RandomSelection_AddString( \ - classname, \ - cvar(sprintf("g_%s_overkill_%s_probability", prefix, varname)), \ - 1 \ - ); \ - } \ - MACRO_END - X("item_health_mega"); - X("item_armor_small"); - X("item_armor_medium"); - X("item_armor_big"); - X("item_armor_mega"); - X("weapon_hmg"); - X("weapon_rpc"); - #undef X + FOREACH(Items, (it.spawnflags & ITEM_FLAG_OVERKILL) && + !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED), + { + RandomSelection_AddString(it.m_canonical_spawnfunc, + cvar(sprintf("g_%s_overkill_%s_probability", prefix, + it.m_canonical_spawnfunc)), 1); + }); + RandomSelection_AddString("weapon_hmg", + cvar(sprintf("g_%s_overkill_weapon_hmg_probability", prefix)), 1); + RandomSelection_AddString("weapon_rpc", + cvar(sprintf("g_%s_overkill_weapon_rpc_probability", prefix)), 1); return RandomSelection_chosen_string; } //========================= Free functions ==================================== -string RandomItems_GetItemVarName(string class_name) -{ - if (startsWith(class_name, "weapon_")) - { - FOREACH(Weapons, it.m_canonical_spawnfunc == class_name, { - if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) - { - return ""; - } - return class_name; - }); - } - switch (class_name) - { - #define XCOND(classname, expr) case #classname: if (expr) return #classname; else break - XCOND(item_health_mega, !autocvar_g_overkill_filter_healthmega); - case "item_armor_small": return "item_armor_small"; - XCOND(item_armor_medium, !autocvar_g_overkill_filter_armormedium); - XCOND(item_armor_big, !autocvar_g_overkill_filter_armorbig); - XCOND(item_armor_mega, !autocvar_g_overkill_filter_armormega); - #undef XCOND - } - return ""; -} - /// \brief Returns list of classnames to replace a map item with. /// \param[in] item Item to inspect. /// \return List of classnames to replace a map item with. -- 2.39.2