From 11068ce5963e21815c02ffb775d49d5aaea96312 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sat, 30 Sep 2017 10:12:35 +0300 Subject: [PATCH] Random items: new replacement algorithm. --- mutators.cfg | 78 +++--- .../mutator/random_items/sv_random_items.qc | 229 ++++++++++-------- 2 files changed, 161 insertions(+), 146 deletions(-) diff --git a/mutators.cfg b/mutators.cfg index c70c2d0b4..7b1218e18 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -478,49 +478,49 @@ set g_dynamic_handicap_max 0 "The maximum value of the handicap." // random items // ============== set g_random_items 0 "Whether to enable random items." -set g_random_items_replace_health_small 1 "Whether to randomly replace small health." -set g_random_items_replace_health_medium 1 "Whether to randomly replace medium health." -set g_random_items_replace_health_big 1 "Whether to randomly replace big health." -set g_random_items_replace_health_mega 1 "Whether to randomly replace mega health." -set g_random_items_replace_armor_small 1 "Whether to randomly replace small armor." -set g_random_items_replace_armor_medium 1 "Whether to randomly replace medium armor." -set g_random_items_replace_armor_big 1 "Whether to randomly replace big armor." -set g_random_items_replace_armor_mega 1 "Whether to randomly replace mega armor." -set g_random_items_replace_item_shells 1 "Whether to randomly replace shells." -set g_random_items_replace_item_bullets 1 "Whether to randomly replace bullets." -set g_random_items_replace_item_rockets 1 "Whether to randomly replace rockets." -set g_random_items_replace_item_cells 1 "Whether to randomly replace cells." -set g_random_items_replace_item_plasma 1 "Whether to randomly replace plasma." -set g_random_items_replace_item_fuel 1 "Whether to randomly replace fuel." -set g_random_items_replace_weapon_blaster 1 "Whether to randomly replace blaster." -set g_random_items_replace_weapon_shotgun 1 "Whether to randomly replace shotgun." -set g_random_items_replace_weapon_machinegun 1 "Whether to randomly replace machinegun." -set g_random_items_replace_weapon_mortar 1 "Whether to randomly replace mortar." -set g_random_items_replace_weapon_electro 1 "Whether to randomly replace electro." -set g_random_items_replace_weapon_crylink 1 "Whether to randomly replace crylink." -set g_random_items_replace_weapon_vortex 1 "Whether to randomly replace vortex." -set g_random_items_replace_weapon_hagar 1 "Whether to randomly replace hagar." -set g_random_items_replace_weapon_devastator 1 "Whether to randomly replace devastator." -set g_random_items_replace_weapon_shockwave 1 "Whether to randomly replace shockwave." -set g_random_items_replace_weapon_arc 1 "Whether to randomly replace arc." -set g_random_items_replace_weapon_hook 1 "Whether to randomly replace hook." -set g_random_items_replace_weapon_tuba 1 "Whether to randomly replace tuba." -set g_random_items_replace_weapon_porto 1 "Whether to randomly replace port-o-launch." -set g_random_items_replace_weapon_fireball 1 "Whether to randomly replace fireball." -set g_random_items_replace_weapon_minelayer 1 "Whether to randomly replace mine layer." -set g_random_items_replace_weapon_hlac 1 "Whether to randomly replace HLAC." -set g_random_items_replace_weapon_rifle 1 "Whether to randomly replace rifle." -set g_random_items_replace_weapon_seeker 1 "Whether to randomly replace TAG seeker." -set g_random_items_replace_weapon_vaporizer 1 "Whether to randomly replace vaporizer." -set g_random_items_replace_item_strength 1 "Whether to randomly replace strength." -set g_random_items_replace_item_shield 1 "Whether to randomly replace shield." -set g_random_items_replace_item_fuel_regen 1 "Whether to randomly replace fuel regeneration." -set g_random_items_replace_item_jetpack 1 "Whether to randomly replace jetpack." +set g_random_items_replace_health_small "random" "Classnames to replace small health with." +set g_random_items_replace_health_medium "random" "Classnames to replace medium health with." +set g_random_items_replace_health_big "random" "Classnames to replace big health with." +set g_random_items_replace_health_mega "random" "Classnames to replace mega health with." +set g_random_items_replace_armor_small "random" "Classnames to replace small armor with." +set g_random_items_replace_armor_medium "random" "Classnames to replace medium armor with." +set g_random_items_replace_armor_big "random" "Classnames to replace big armor with." +set g_random_items_replace_armor_mega "random" "Classnames to replace mega armor with." +set g_random_items_replace_item_shells "random" "Classnames to replace shells with." +set g_random_items_replace_item_bullets "random" "Classnames to replace bullets with." +set g_random_items_replace_item_rockets "random" "Classnames to replace rockets with." +set g_random_items_replace_item_cells "random" "Classnames to replace cells with." +set g_random_items_replace_item_plasma "random" "Classnames to replace plasma with." +set g_random_items_replace_item_fuel "random" "Classnames to replace fuel with." +set g_random_items_replace_weapon_blaster "random" "Classnames to replace blaster with." +set g_random_items_replace_weapon_shotgun "random" "Classnames to replace shotgun with." +set g_random_items_replace_weapon_machinegun "random" "Classnames to replace machinegun with." +set g_random_items_replace_weapon_mortar "random" "Classnames to replace mortar with." +set g_random_items_replace_weapon_electro "random" "Classnames to replace electro with." +set g_random_items_replace_weapon_crylink "random" "Classnames to replace crylink with." +set g_random_items_replace_weapon_vortex "random" "Classnames to replace vortex with." +set g_random_items_replace_weapon_hagar "random" "Classnames to replace hagar with." +set g_random_items_replace_weapon_devastator "random" "Classnames to replace devastator with." +set g_random_items_replace_weapon_shockwave "random" "Classnames to replace shockwave with." +set g_random_items_replace_weapon_arc "random" "Classnames to replace arc with." +set g_random_items_replace_weapon_hook "random" "Classnames to replace hook with." +set g_random_items_replace_weapon_tuba "random" "Classnames to replace tuba with." +set g_random_items_replace_weapon_porto "random" "Classnames to replace port-o-launch with." +set g_random_items_replace_weapon_fireball "random" "Classnames to replace fireball with." +set g_random_items_replace_weapon_minelayer "random" "Classnames to replace mine layer with." +set g_random_items_replace_weapon_hlac "random" "Classnames to replace HLAC with." +set g_random_items_replace_weapon_rifle "random" "Classnames to replace rifle with." +set g_random_items_replace_weapon_seeker "random" "Classnames to replace TAG seeker with." +set g_random_items_replace_weapon_vaporizer "random" "Classnames to replace vaporizer with." +set g_random_items_replace_item_strength "random" "Classnames to replace strength with." +set g_random_items_replace_item_shield "random" "Classnames to replace shield with." +set g_random_items_replace_item_fuel_regen "random" "Classnames to replace fuel regeneration with." +set g_random_items_replace_item_jetpack "random" "Classnames to replace jetpack with." set g_random_items_health_probability 1 "Probability of random health items spawning in the map." set g_random_items_armor_probability 1 "Probability of random armor items spawning in the map." set g_random_items_resource_probability 1 "Probability of random ammo items spawning in the map." set g_random_items_weapon_probability 1 "Probability of random weapons spawning in the map." -set g_random_items_powerup_probability 0.2 "Probability of random powerups spawning in the map." +set g_random_items_powerup_probability 0.175 "Probability of random powerups spawning in the map." set g_random_items_health_small_probability 10 "Probability of random small health spawning in the map." set g_random_items_health_medium_probability 4 "Probability of random medium health spawning in the map." set g_random_items_health_big_probability 2 "Probability of random big health spawning in the map." 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 38958cdaf..c374d3446 100644 --- a/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc +++ b/qcsrc/common/mutators/mutator/random_items/sv_random_items.qc @@ -78,91 +78,91 @@ bool autocvar_g_random_items; ///< Whether to enable random items. // Replace cvars -/// \brief Whether to randomly replace small health. -bool autocvar_g_random_items_replace_health_small; -/// \brief Whether to randomly replace medium health. -bool autocvar_g_random_items_replace_health_medium; -/// \brief Whether to randomly replace big health. -bool autocvar_g_random_items_replace_health_big; -/// \brief Whether to randomly replace mega health. -bool autocvar_g_random_items_replace_health_mega; +/// \brief Classnames to replace small health with. +string autocvar_g_random_items_replace_health_small; +/// \brief Classnames to replace medium health with. +string autocvar_g_random_items_replace_health_medium; +/// \brief Classnames to replace big health with. +string autocvar_g_random_items_replace_health_big; +/// \brief Classnames to replace mega health with. +string autocvar_g_random_items_replace_health_mega; -/// \brief Whether to randomly replace small armor. -bool autocvar_g_random_items_replace_armor_small; -/// \brief Whether to randomly replace medium armor. -bool autocvar_g_random_items_replace_armor_medium; -/// \brief Whether to randomly replace big armor. -bool autocvar_g_random_items_replace_armor_big; -/// \brief Whether to randomly replace mega armor. -bool autocvar_g_random_items_replace_armor_mega; +/// \brief Classnames to replace small armor with. +string autocvar_g_random_items_replace_armor_small; +/// \brief Classnames to replace medium armor with. +string autocvar_g_random_items_replace_armor_medium; +/// \brief Classnames to replace big armor with. +string autocvar_g_random_items_replace_armor_big; +/// \brief Classnames to replace mega armor with. +string autocvar_g_random_items_replace_armor_mega; -/// \brief Whether to randomly replace shells. -bool autocvar_g_random_items_replace_item_shells; -/// \brief Whether to randomly replace bullets. -bool autocvar_g_random_items_replace_item_bullets; -/// \brief Whether to randomly replace rockets. -bool autocvar_g_random_items_replace_item_rockets; -/// \brief Whether to randomly replace cells. -bool autocvar_g_random_items_replace_item_cells; -/// \brief Whether to randomly replace plasma. -bool autocvar_g_random_items_replace_item_plasma; -/// \brief Whether to randomly replace fuel. -bool autocvar_g_random_items_replace_item_fuel; +/// \brief Classnames to replace shells with. +string autocvar_g_random_items_replace_item_shells; +/// \brief Classnames to replace bullets with. +string autocvar_g_random_items_replace_item_bullets; +/// \brief Classnames to replace rockets with. +string autocvar_g_random_items_replace_item_rockets; +/// \brief Classnames to replace cells with. +string autocvar_g_random_items_replace_item_cells; +/// \brief Classnames to replace plasma with. +string autocvar_g_random_items_replace_item_plasma; +/// \brief Classnames to replace fuel with. +string autocvar_g_random_items_replace_item_fuel; -/// \brief Whether to randomly replace blaster. -bool autocvar_g_random_items_replace_weapon_blaster; -/// \brief Whether to randomly replace shotgun. -bool autocvar_g_random_items_replace_weapon_shotgun; -/// \brief Whether to randomly replace machinegun. -bool autocvar_g_random_items_replace_weapon_machinegun; -/// \brief Whether to randomly replace mortar. -bool autocvar_g_random_items_replace_weapon_mortar; -/// \brief Whether to randomly replace electro. -bool autocvar_g_random_items_replace_weapon_electro; -/// \brief Whether to randomly replace crylink. -bool autocvar_g_random_items_replace_weapon_crylink; -/// \brief Whether to randomly replace vortex. -bool autocvar_g_random_items_replace_weapon_vortex; -/// \brief Whether to randomly replace hagar. -bool autocvar_g_random_items_replace_weapon_hagar; -/// \brief Whether to randomly replace devastator. -bool autocvar_g_random_items_replace_weapon_devastator; -/// \brief Whether to randomly replace shockwave. -bool autocvar_g_random_items_replace_weapon_shockwave; -/// \brief Whether to randomly replace arc. -bool autocvar_g_random_items_replace_weapon_arc; -/// \brief Whether to randomly replace hook. -bool autocvar_g_random_items_replace_weapon_hook; -/// \brief Whether to randomly replace tuba. -bool autocvar_g_random_items_replace_weapon_tuba; -/// \brief Whether to randomly replace port-o-launch. -bool autocvar_g_random_items_replace_weapon_porto; -/// \brief Whether to randomly replace fireball. -bool autocvar_g_random_items_replace_weapon_fireball; -/// \brief Whether to randomly replace mine layer. -bool autocvar_g_random_items_replace_weapon_minelayer; -/// \brief Whether to randomly replace HLAC. -bool autocvar_g_random_items_replace_weapon_hlac; -/// \brief Whether to randomly replace rifle. -bool autocvar_g_random_items_replace_weapon_rifle; -/// \brief Whether to randomly replace TAG seeker. -bool autocvar_g_random_items_replace_weapon_seeker; -/// \brief Whether to randomly replace vaporizer. -bool autocvar_g_random_items_replace_weapon_vaporizer; +/// \brief Classnames to replace blaster with. +string autocvar_g_random_items_replace_weapon_blaster; +/// \brief Classnames to replace shotgun with. +string autocvar_g_random_items_replace_weapon_shotgun; +/// \brief Classnames to replace machinegun with. +string autocvar_g_random_items_replace_weapon_machinegun; +/// \brief Classnames to replace mortar with. +string autocvar_g_random_items_replace_weapon_mortar; +/// \brief Classnames to replace electro with. +string autocvar_g_random_items_replace_weapon_electro; +/// \brief Classnames to replace crylink with. +string autocvar_g_random_items_replace_weapon_crylink; +/// \brief Classnames to replace vortex with. +string autocvar_g_random_items_replace_weapon_vortex; +/// \brief Classnames to replace hagar with. +string autocvar_g_random_items_replace_weapon_hagar; +/// \brief Classnames to replace devastator with. +string autocvar_g_random_items_replace_weapon_devastator; +/// \brief Classnames to replace shockwave with. +string autocvar_g_random_items_replace_weapon_shockwave; +/// \brief Classnames to replace arc with. +string autocvar_g_random_items_replace_weapon_arc; +/// \brief Classnames to replace hook with. +string autocvar_g_random_items_replace_weapon_hook; +/// \brief Classnames to replace tuba with. +string autocvar_g_random_items_replace_weapon_tuba; +/// \brief Classnames to replace port-o-launch with. +string autocvar_g_random_items_replace_weapon_porto; +/// \brief Classnames to replace fireball with. +string autocvar_g_random_items_replace_weapon_fireball; +/// \brief Classnames to replace mine layer with. +string autocvar_g_random_items_replace_weapon_minelayer; +/// \brief Classnames to replace HLAC with. +string autocvar_g_random_items_replace_weapon_hlac; +/// \brief Classnames to replace rifle with. +string autocvar_g_random_items_replace_weapon_rifle; +/// \brief Classnames to replace TAG seeker with. +string autocvar_g_random_items_replace_weapon_seeker; +/// \brief Classnames to replace vaporizer with. +string autocvar_g_random_items_replace_weapon_vaporizer; -/// \brief Whether to randomly replace strength. -bool autocvar_g_random_items_replace_item_strength; -/// \brief Whether to randomly replace shield. -bool autocvar_g_random_items_replace_item_shield; -/// \brief Whether to randomly replace fuel regeneration. -bool autocvar_g_random_items_replace_item_fuel_regen; -/// \brief Whether to randomly replace jetpack. -bool autocvar_g_random_items_replace_item_jetpack; +/// \brief Classnames to replace strength with. +string autocvar_g_random_items_replace_item_strength; +/// \brief Classnames to replace shield with. +string autocvar_g_random_items_replace_item_shield; +/// \brief Classnames to replace fuel regeneration with. +string autocvar_g_random_items_replace_item_fuel_regen; +/// \brief Classnames to replace jetpack with. +string autocvar_g_random_items_replace_item_jetpack; -bool autocvar_g_random_items_replace_item_minst_cells; -bool autocvar_g_random_items_replace_item_invisibility; -bool autocvar_g_random_items_replace_item_extralife; -bool autocvar_g_random_items_replace_item_speed; +string autocvar_g_random_items_replace_item_minst_cells; +string autocvar_g_random_items_replace_item_invisibility; +string autocvar_g_random_items_replace_item_extralife; +string autocvar_g_random_items_replace_item_speed; // Map probability cvars @@ -372,10 +372,10 @@ bool random_items_is_spawning = false; //========================= Free functions ==================================== -/// \brief Returns whether a map item should be replaced. +/// \brief Returns list of classnames to replace a map item with. /// \param[in] item Item to inspect. -/// \return True if the item should be replaced, false otherwise. -bool RandomItems_ShouldReplaceItem(entity item) +/// \return List of classnames to replace a map item with. +string RandomItems_GetItemReplacementClassNames(entity item) { switch (item.classname) { @@ -579,13 +579,13 @@ bool RandomItems_ShouldReplaceItem(entity item) } default: { - return false; + return string_null; } } } default: { - return false; + return string_null; } } } @@ -885,27 +885,50 @@ string RandomItems_GetRandomMapItemClassName() return string_null; } -/// \brief Spawns a random map item. -/// \param[in] position Position of the item. +/// \brief Replaces a map item. +/// \param[in] item Item to replace. /// \return Spawned item on success, NULL otherwise. -entity RandomItems_SpawnMapItem(vector position) +entity RandomItems_ReplaceMapItem(entity item) { - string class_name = RandomItems_GetRandomMapItemClassName(); - if (!class_name) + string classnames = RandomItems_GetItemReplacementClassNames(item); + if (!classnames) { return NULL; } + string class_name; + if (classnames == "random") + { + class_name = RandomItems_GetRandomMapItemClassName(); + if (!class_name) + { + return NULL; + } + } + else + { + int num_classnames = tokenize_console(classnames); + if (num_classnames == 1) + { + class_name = classnames; + } + else + { + int classname_index = floor(random() * num_classnames); + class_name = argv(classname_index); + } + } random_items_is_spawning = true; - entity item = spawn(); - item.classname = class_name; - Item_Initialize(item, class_name); + entity new_item = spawn(); + new_item.classname = strzone(class_name); + new_item.spawnfunc_checked = true; + Item_Initialize(new_item, class_name); random_items_is_spawning = false; - if (wasfreed(item)) + if (wasfreed(new_item)) { return NULL; } - setorigin(item, position); - return item; + setorigin(new_item, item.origin); + return new_item; } /// \brief Returns a random classname of the loot item. @@ -1253,11 +1276,7 @@ MUTATOR_HOOKFUNCTION(random_items, FilterItem, CBC_ORDER_LAST) { return false; } - if (!RandomItems_ShouldReplaceItem(item)) - { - return false; - } - if (RandomItems_SpawnMapItem(item.origin) == NULL) + if (RandomItems_ReplaceMapItem(item) == NULL) { return false; } @@ -1277,14 +1296,10 @@ MUTATOR_HOOKFUNCTION(random_items, ItemTouched, CBC_ORDER_LAST) { return; } - if (!RandomItems_ShouldReplaceItem(item)) - { - return; - } - entity new_item = RandomItems_SpawnMapItem(item.origin); + entity new_item = RandomItems_ReplaceMapItem(item); if (new_item == NULL) { - return; + return false; } Item_ScheduleRespawn(new_item); delete(item); -- 2.39.2