From bc0292133d30cdb20f0e162ac23e190c5b06f07c Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sun, 10 Jun 2018 00:41:06 +0300 Subject: [PATCH] Better random items. --- qcsrc/common/items/item.qh | 4 +- qcsrc/common/items/item/armor.qh | 8 +-- qcsrc/common/items/item/health.qh | 2 +- .../common/mutators/mutator/instagib/items.qh | 9 ++- .../mutators/mutator/instagib/sv_instagib.qc | 43 ++++++++++++- .../mutators/mutator/overkill/sv_overkill.qc | 58 +++++++++++++++++ .../mutator/random_items/sv_random_items.qc | 63 +------------------ .../mutator/random_items/sv_random_items.qh | 16 +++-- randomitems-overkill.cfg | 21 +++++++ randomitems-xonotic.cfg | 14 ----- ruleset-overkill.cfg | 1 + 11 files changed, 139 insertions(+), 100 deletions(-) create mode 100644 randomitems-overkill.cfg diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index e59152076..31b8f43cb 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -72,9 +72,7 @@ const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FU enum { ITEM_FLAG_NORMAL = BIT(0), ///< Item is usable during normal gameplay. - ITEM_FLAG_INSTAGIB = BIT(1), ///< Item is usable in instagib. - ITEM_FLAG_OVERKILL = BIT(2), ///< Item is usable in overkill. - ITEM_FLAG_MUTATORBLOCKED = BIT(3) + ITEM_FLAG_MUTATORBLOCKED = BIT(1) }; #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 7f37c75ae..b00ccc0f2 100644 --- a/qcsrc/common/items/item/armor.qh +++ b/qcsrc/common/items/item/armor.qh @@ -34,7 +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_NORMAL | ITEM_FLAG_OVERKILL; + this.spawnflags = ITEM_FLAG_NORMAL; this.m_model = MDL_ArmorSmall_ITEM; this.m_sound = SND_ArmorSmall; #endif @@ -72,7 +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_NORMAL | ITEM_FLAG_OVERKILL; + this.spawnflags = ITEM_FLAG_NORMAL; this.m_model = MDL_ArmorMedium_ITEM; this.m_sound = SND_ArmorMedium; #endif @@ -110,7 +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_NORMAL | ITEM_FLAG_OVERKILL; + this.spawnflags = ITEM_FLAG_NORMAL; this.m_model = MDL_ArmorBig_ITEM; this.m_sound = SND_ArmorBig; #endif @@ -150,7 +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_NORMAL | ITEM_FLAG_OVERKILL; + this.spawnflags = ITEM_FLAG_NORMAL; 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 da431086e..879ee5101 100644 --- a/qcsrc/common/items/item/health.qh +++ b/qcsrc/common/items/item/health.qh @@ -150,7 +150,7 @@ void item_healthmega_init(entity item) REGISTER_ITEM(HealthMega, Health) { this.m_canonical_spawnfunc = "item_health_mega"; #ifdef GAMEQC - this.spawnflags = ITEM_FLAG_NORMAL | ITEM_FLAG_OVERKILL; + this.spawnflags = ITEM_FLAG_NORMAL; 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 fe0070afc..ad7ba6ba4 100644 --- a/qcsrc/common/mutators/mutator/instagib/items.qh +++ b/qcsrc/common/mutators/mutator/instagib/items.qh @@ -25,7 +25,7 @@ void ammo_vaporizercells_init(entity item) REGISTER_ITEM(VaporizerCells, Ammo) { this.m_canonical_spawnfunc = "item_vaporizer_cells"; #ifdef GAMEQC - this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED; + this.spawnflags = ITEM_FLAG_MUTATORBLOCKED; this.m_model = MDL_VaporizerCells_ITEM; this.m_sound = SND_VaporizerCells; #endif @@ -52,8 +52,7 @@ SOUND(ExtraLife, Item_Sound("megahealth")); REGISTER_ITEM(ExtraLife, Powerup) { this.m_canonical_spawnfunc = "item_extralife"; #ifdef GAMEQC - this.spawnflags = ITEM_FLAG_INSTAGIB; - this.m_model = MDL_ExtraLife_ITEM; + this.m_model = MDL_ExtraLife_ITEM; this.m_sound = SND_ExtraLife; #endif this.netname = "extralife"; @@ -82,7 +81,7 @@ void powerup_invisibility_init(entity item); REGISTER_ITEM(Invisibility, Powerup) { this.m_canonical_spawnfunc = "item_invisibility"; #ifdef GAMEQC - this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED; + this.spawnflags = ITEM_FLAG_MUTATORBLOCKED; this.m_model = MDL_Invisibility_ITEM; this.m_sound = SND_Invisibility; this.m_glow = true; @@ -117,7 +116,7 @@ void powerup_speed_init(entity item); REGISTER_ITEM(Speed, Powerup) { this.m_canonical_spawnfunc = "item_speed"; #ifdef GAMEQC - this.spawnflags = ITEM_FLAG_INSTAGIB | ITEM_FLAG_MUTATORBLOCKED; + this.spawnflags = ITEM_FLAG_MUTATORBLOCKED; this.m_model = MDL_Speed_ITEM; this.m_sound = SND_Speed; this.m_glow = true; diff --git a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc index f93b69235..3cda4485f 100644 --- a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc +++ b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc @@ -1,5 +1,9 @@ #include "sv_instagib.qh" +#include +#include +#include "../random_items/sv_random_items.qh" + bool autocvar_g_instagib_damagedbycontents = true; bool autocvar_g_instagib_blaster_keepdamage = false; bool autocvar_g_instagib_blaster_keepforce = false; @@ -13,9 +17,15 @@ bool autocvar_g_instagib_ammo_convert_bullets; int autocvar_g_instagib_extralives; float autocvar_g_instagib_speed_highspeed; -#include - -#include +IntrusiveList g_instagib_items; +STATIC_INIT() +{ + g_instagib_items = IL_NEW(); + IL_PUSH(g_instagib_items, ITEM_VaporizerCells); + IL_PUSH(g_instagib_items, ITEM_ExtraLife); + IL_PUSH(g_instagib_items, ITEM_Invisibility); + IL_PUSH(g_instagib_items, ITEM_Speed); +} void instagib_invisibility(entity this) { @@ -34,6 +44,26 @@ void instagib_speed(entity this) StartItem(this, ITEM_Speed); } +/// \brief Returns a random classname of the instagib item. +/// \param[in] prefix Prefix of the cvars that hold probabilities. +/// \return Random classname of the instagib item. +string RandomItems_GetRandomInstagibItemClassName(string prefix) +{ + RandomSelection_Init(); + IL_EACH(g_instagib_items, Item_IsDefinitionAllowed(it), + { + string cvar_name = sprintf("g_%s_%s_probability", prefix, + it.m_canonical_spawnfunc); + if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) + { + LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); + continue; + } + RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1); + }); + return RandomSelection_chosen_string; +} + .float instagib_nextthink; .float instagib_needammo; void instagib_stop_countdown(entity e) @@ -131,6 +161,13 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd) FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); }); } +MUTATOR_HOOKFUNCTION(mutator_instagib, RandomItems_GetRandomItemClassName) +{ + M_ARGV(1, string) = RandomItems_GetRandomInstagibItemClassName( + M_ARGV(0, string)); + return true; +} + MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem) { entity item = M_ARGV(1, entity); diff --git a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc index f4432a9cb..b6ff5e14d 100644 --- a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc +++ b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc @@ -6,6 +6,64 @@ bool autocvar_g_overkill_itemwaypoints = true; .Weapon ok_lastwep[MAX_WEAPONSLOTS]; +IntrusiveList g_overkill_items; +STATIC_INIT() +{ + g_overkill_items = IL_NEW(); + IL_PUSH(g_overkill_items, ITEM_HealthMega); + IL_PUSH(g_overkill_items, ITEM_ArmorSmall); + IL_PUSH(g_overkill_items, ITEM_ArmorMedium); + IL_PUSH(g_overkill_items, ITEM_ArmorBig); + IL_PUSH(g_overkill_items, ITEM_ArmorMega); +} + +/// \brief Returns a random classname of the overkill item. +/// \param[in] prefix Prefix of the cvars that hold probabilities. +/// \return Random classname of the overkill item. +string RandomItems_GetRandomOverkillItemClassName(string prefix) +{ + RandomSelection_Init(); + IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) && + Item_IsDefinitionAllowed(it), + { + string cvar_name = sprintf("g_%s_%s_probability", prefix, + it.m_canonical_spawnfunc); + if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) + { + LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); + continue; + } + RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1); + }); + string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix); + if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) + { + LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); + } + else + { + RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1); + } + cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix); + if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) + { + LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); + } + else + { + RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1); + } + return RandomSelection_chosen_string; +} + + +MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName) +{ + M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName( + M_ARGV(0, string)); + return true; +} + MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST) { entity frag_attacker = M_ARGV(1, entity); 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 251e57b87..183808021 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc @@ -53,13 +53,9 @@ string RandomItems_GetRandomItemClassNameWithProperty(string prefix, string RandomItems_GetRandomItemClassName(string prefix) { - if (MUTATOR_IS_ENABLED(mutator_instagib)) + if (MUTATOR_CALLHOOK(RandomItems_GetRandomItemClassName, prefix)) { - return RandomItems_GetRandomInstagibItemClassName(prefix); - } - if (MUTATOR_IS_ENABLED(ok)) - { - return RandomItems_GetRandomOverkillItemClassName(prefix); + return M_ARGV(1, string); } return RandomItems_GetRandomVanillaItemClassName(prefix, RANDOM_ITEM_TYPE_ALL); @@ -196,61 +192,6 @@ string RandomItems_GetRandomVanillaItemClassName(string prefix, int types) return ""; } -string RandomItems_GetRandomInstagibItemClassName(string prefix) -{ - RandomSelection_Init(); - FOREACH(Items, it.spawnflags & ITEM_FLAG_INSTAGIB && - Item_IsDefinitionAllowed(it), - { - string cvar_name = sprintf("g_%s_%s_probability", prefix, - it.m_canonical_spawnfunc); - if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) - { - LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); - continue; - } - RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1); - }); - return RandomSelection_chosen_string; -} - -string RandomItems_GetRandomOverkillItemClassName(string prefix) -{ - RandomSelection_Init(); - FOREACH(Items, (it.spawnflags & ITEM_FLAG_OVERKILL) && - !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) && - Item_IsDefinitionAllowed(it), - { - string cvar_name = sprintf("g_%s_overkill_%s_probability", prefix, - it.m_canonical_spawnfunc); - if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) - { - LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); - continue; - } - RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1); - }); - string cvar_name = sprintf("g_%s_overkill_weapon_okhmg_probability", prefix); - if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) - { - LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); - } - else - { - RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1); - } - cvar_name = sprintf("g_%s_overkill_weapon_okrpc_probability", prefix); - if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS)) - { - LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name); - } - else - { - RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1); - } - return RandomSelection_chosen_string; -} - //========================= Free functions ==================================== /// \brief Returns list of classnames to replace a map item with. diff --git a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qh b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qh index d49e3effa..c94375cea 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qh +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qh @@ -33,15 +33,13 @@ string RandomItems_GetRandomItemClassName(string prefix); /// jetpack and new toys. string RandomItems_GetRandomVanillaItemClassName(string prefix, int types); -/// \brief Returns a random classname of the instagib item. -/// \param[in] prefix Prefix of the cvars that hold probabilities. -/// \return Random classname of the instagib item. -string RandomItems_GetRandomInstagibItemClassName(string prefix); - -/// \brief Returns a random classname of the overkill item. -/// \param[in] prefix Prefix of the cvars that hold probabilities. -/// \return Random classname of the overkill item. -string RandomItems_GetRandomOverkillItemClassName(string prefix); +/// \brief Called when random item classname is requested. +#define EV_RandomItems_GetRandomItemClassName(i, o) \ + /** prefix */ i(string, MUTATOR_ARGV_0_string) \ + /** classname */ o(string, MUTATOR_ARGV_1_string) \ + /**/ +MUTATOR_HOOKABLE(RandomItems_GetRandomItemClassName, + EV_RandomItems_GetRandomItemClassName); REGISTER_MUTATOR(random_items, (autocvar_g_random_items || autocvar_g_random_loot)); diff --git a/randomitems-overkill.cfg b/randomitems-overkill.cfg new file mode 100644 index 000000000..e2a2617e5 --- /dev/null +++ b/randomitems-overkill.cfg @@ -0,0 +1,21 @@ +// Random items mutator config for Overkill ruleset + +// Map items + +set g_random_items_item_health_mega_probability 1 "Probability of random mega health spawning in the map during overkill." +set g_random_items_item_armor_small_probability 10 "Probability of random small armor spawning in the map during overkill." +set g_random_items_item_armor_medium_probability 4 "Probability of random medium armor spawning in the map during overkill." +set g_random_items_item_armor_big_probability 2 "Probability of random big armor spawning in the map during overkill." +set g_random_items_item_armor_mega_probability 1 "Probability of random mega armor spawning in the map during overkill." +set g_random_items_weapon_okhmg_probability 0.5 "Probability of random overkill HMG spawning in the map during overkill." +set g_random_items_weapon_okrpc_probability 0.5 "Probability of random overkill RPC spawning in the map during overkill." + +// Loot + +set g_random_loot_item_health_mega_probability 1 "Probability of random mega health spawning as loot during overkill." +set g_random_loot_item_armor_small_probability 10 "Probability of random small armor spawning as loot during overkill." +set g_random_loot_item_armor_medium_probability 4 "Probability of random medium armor spawning as loot during overkill." +set g_random_loot_item_armor_big_probability 2 "Probability of random big armor spawning as loot during overkill." +set g_random_loot_item_armor_mega_probability 1 "Probability of random mega armor spawning as loot during overkill." +set g_random_loot_weapon_okhmg_probability 1 "Probability of random overkill HMG spawning as loot during overkill." +set g_random_loot_weapon_okrpc_probability 1 "Probability of random overkill RPC spawning as loot during overkill." diff --git a/randomitems-xonotic.cfg b/randomitems-xonotic.cfg index 1491ffd0c..bffa2b1ac 100644 --- a/randomitems-xonotic.cfg +++ b/randomitems-xonotic.cfg @@ -99,13 +99,6 @@ set g_random_items_item_vaporizer_cells_probability 20 "Probability of random va set g_random_items_item_invisibility_probability 1 "Probability of random invisibility spawning in the map." set g_random_items_item_extralife_probability 1 "Probability of random extra life spawning in the map." set g_random_items_item_speed_probability 1 "Probability of random speed spawning in the map." -set g_random_items_overkill_item_health_mega_probability 1 "Probability of random mega health spawning in the map during overkill." -set g_random_items_overkill_item_armor_small_probability 10 "Probability of random small armor spawning in the map during overkill." -set g_random_items_overkill_item_armor_medium_probability 4 "Probability of random medium armor spawning in the map during overkill." -set g_random_items_overkill_item_armor_big_probability 2 "Probability of random big armor spawning in the map during overkill." -set g_random_items_overkill_item_armor_mega_probability 1 "Probability of random mega armor spawning in the map during overkill." -set g_random_items_overkill_weapon_okhmg_probability 0.5 "Probability of random overkill HMG spawning in the map during overkill." -set g_random_items_overkill_weapon_okrpc_probability 0.5 "Probability of random overkill RPC spawning in the map during overkill." // Loot @@ -163,10 +156,3 @@ set g_random_loot_item_vaporizer_cells_probability 20 "Probability of random vap set g_random_loot_item_invisibility_probability 1 "Probability of random invisibility spawning as loot." set g_random_loot_item_extralife_probability 1 "Probability of random extra life spawning as loot." set g_random_loot_item_speed_probability 1 "Probability of random speed spawning as loot." -set g_random_loot_overkill_item_health_mega_probability 1 "Probability of random mega health spawning as loot during overkill." -set g_random_loot_overkill_item_armor_small_probability 10 "Probability of random small armor spawning as loot during overkill." -set g_random_loot_overkill_item_armor_medium_probability 4 "Probability of random medium armor spawning as loot during overkill." -set g_random_loot_overkill_item_armor_big_probability 2 "Probability of random big armor spawning as loot during overkill." -set g_random_loot_overkill_item_armor_mega_probability 1 "Probability of random mega armor spawning as loot during overkill." -set g_random_loot_overkill_weapon_okhmg_probability 1 "Probability of random overkill HMG spawning as loot during overkill." -set g_random_loot_overkill_weapon_okrpc_probability 1 "Probability of random overkill RPC spawning as loot during overkill." diff --git a/ruleset-overkill.cfg b/ruleset-overkill.cfg index 49eb730c9..cc512e0c4 100644 --- a/ruleset-overkill.cfg +++ b/ruleset-overkill.cfg @@ -5,6 +5,7 @@ exec xonotic-server.cfg exec balance-overkill.cfg exec physicsOverkill.cfg +exec randomitems-overkill.cfg // general gameplay set g_overkill 1 -- 2.39.2