From 19e785b842494c4d8698510868e2de8fe58753f5 Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Sat, 29 Mar 2025 14:59:09 -0500 Subject: [PATCH] [Bots] Fix Rule ZonesWithSpawnLimits/ZonesWithForcedSpawnLimits errors (#4791) * [Bots] Fix error copy/paste Oops * Eliminate false errors on empty rules and add more sanity checks - `Bots:ZonesWithSpawnLimits` - This is to be used when zones will only allow up to x amount of bots. Example: A player can normally spawn 5 bots but a zone in this rule has a lower limit of up to 3, this rule would override their normal limit if their normal limit is above the listed zone's max in `Bots:ZoneSpawnLimits`. - `Bots:ZonesWithForcedSpawnLimits` - Zones in this rule will override any spawn limits high or low and force it. If one player can normally spawn 2 and another player can spawn 10 but a zone listed forces a limit of 5, all players will be able to spawn 5. Follows the limits set in `Bots:ZoneForcedSpawnLimits` --- zone/client_bot.cpp | 62 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/zone/client_bot.cpp b/zone/client_bot.cpp index d5e9080cb..1a420b216 100644 --- a/zone/client_bot.cpp +++ b/zone/client_bot.cpp @@ -120,48 +120,46 @@ int Client::GetBotSpawnLimit(uint8 class_id) { } const auto& zones_list = Strings::Split(RuleS(Bots, ZonesWithSpawnLimits), ","); - const auto& zones_limits_list = Strings::Split(RuleS(Bots, ZoneSpawnLimits), ","); - int i = 0; - for (const auto& result : zones_list) { - try { - if ( - std::stoul(result) == zone->GetZoneID() && - std::stoul(zones_limits_list[i]) < bot_spawn_limit - ) { - bot_spawn_limit = std::stoul(zones_limits_list[i]); + if (!zones_list.empty()) { + auto it = std::find(zones_list.begin(), zones_list.end(), std::to_string(zone->GetZoneID())); - break; + if (it != zones_list.end()) { + const auto& zones_limits_list = Strings::Split(RuleS(Bots, ZoneSpawnLimits), ","); + + if (zones_list.size() == zones_limits_list.size()) { + try { + auto new_limit = std::stoul(zones_limits_list[std::distance(zones_list.begin(), it)]); + + if (new_limit < bot_spawn_limit) { + bot_spawn_limit = new_limit; + } + } catch (const std::exception& e) { + LogInfo("Invalid entry in Rule Bots:ZoneSpawnLimits: [{}]", e.what()); + } } - - ++i; - } - - catch (const std::exception& e) { - LogInfo("Invalid entry in Rule VegasScaling:SpecialScalingZones or SpecialScalingZonesVersions: [{}]", e.what()); } } const auto& zones_forced_list = Strings::Split(RuleS(Bots, ZonesWithForcedSpawnLimits), ","); - const auto& zones_forced_limits_list = Strings::Split(RuleS(Bots, ZoneForcedSpawnLimits), ","); - i = 0; - for (const auto& result : zones_forced_list) { - try { - if ( - std::stoul(result) == zone->GetZoneID() && - std::stoul(zones_forced_limits_list[i]) != bot_spawn_limit - ) { - bot_spawn_limit = std::stoul(zones_forced_limits_list[i]); + if (!zones_forced_list.empty()) { + auto it = std::find(zones_forced_list.begin(), zones_forced_list.end(), std::to_string(zone->GetZoneID())); - break; + if (it != zones_forced_list.end()) { + const auto& zones_forced_limits_list = Strings::Split(RuleS(Bots, ZoneForcedSpawnLimits), ","); + + if (zones_forced_list.size() == zones_forced_limits_list.size()) { + try { + auto new_limit = std::stoul(zones_forced_limits_list[std::distance(zones_forced_list.begin(), it)]); + + if (new_limit != bot_spawn_limit) { + bot_spawn_limit = new_limit; + } + } catch (const std::exception& e) { + LogInfo("Invalid entry in Rule Bots:ZoneForcedSpawnLimits: [{}]", e.what()); + } } - - ++i; - } - - catch (const std::exception& e) { - LogInfo("Invalid entry in Rule VegasScaling:SpecialScalingZones or SpecialScalingZonesVersions: [{}]", e.what()); } }