From 7095e9d8f915606762b816fd82e73869330edd28 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 5 Feb 2023 00:36:51 +0100 Subject: [PATCH] Allow heroes to start with empty armies if configured properly --- AI/Nullkiller/Analyzers/ArmyManager.cpp | 2 +- config/defaultMods.json | 3 ++- lib/mapObjects/CGHeroInstance.cpp | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/AI/Nullkiller/Analyzers/ArmyManager.cpp b/AI/Nullkiller/Analyzers/ArmyManager.cpp index e5356d368..d1c39980d 100644 --- a/AI/Nullkiller/Analyzers/ArmyManager.cpp +++ b/AI/Nullkiller/Analyzers/ArmyManager.cpp @@ -182,7 +182,7 @@ std::vector ArmyManager::getBestArmy(const IBonusBearer * armyCarrier, { auto weakest = getWeakestCreature(resultingArmy); - if(weakest->count == 1) + if(weakest != resultingArmy.end() && weakest->count == 1) //we check iterator validity for playing with settings that allow 0 stacks armies { resultingArmy.erase(weakest); } diff --git a/config/defaultMods.json b/config/defaultMods.json index 3bfd04fee..60448d347 100644 --- a/config/defaultMods.json +++ b/config/defaultMods.json @@ -34,7 +34,8 @@ "ATTACK_POINTS_DMG_MULTIPLIER_CAP": 4.0, //limit of damage increase that can be achieved by overpowering attack points "DEFENSE_POINT_DMG_MULTIPLIER": 0.025, //every 1 defense point damage influence in battle when defense points > attack points during creature attack "DEFENSE_POINTS_DMG_MULTIPLIER_CAP": 0.7, //limit of damage reduction that can be achieved by overpowering defense points - "HERO_STARTING_ARMY_STACKS_COUNT_CHANCES": [10, 80], //chances for new hero units count - technically random number 1-100, first element in list below generated number sets count, if none then result is number of elements + 1 + //chances for new hero units count - technically random number 1-100, first element in list below generated number sets count, if none then result is number of elements + 1 + "HERO_STARTING_ARMY_STACKS_COUNT_CHANCES": [10, 80], //example: [10,80] gives 10% chance for 1 stack, 70% for 2, 20% for 3. Additionally you can add -1 as last special value to start counting from 0 and allowing empty armies "DEFAULT_BUILDING_SET_DWELLING_CHANCES": [100, 50] //percent chance for dwellings to appear - for example [30,10,0,100] means 30% chance for 1st level dwelling, 10% for 2nd, 0% for 3rd, and guaranteed 4th level, no 5th, no 6th, no 7th }, "modules": diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index e0415c840..3f7553566 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -353,15 +353,20 @@ void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst) std::vector stacksCountChances = VLC->modh->settings.HERO_STARTING_ARMY_STACKS_COUNT_CHANCES; + const int zeroStacksAllowingValue = -1; + bool allowZeroStacksArmy = !stacksCountChances.empty() && stacksCountChances.back() == zeroStacksAllowingValue; + if(allowZeroStacksArmy) + stacksCountChances.pop_back(); + int stacksCountInitRandomNumber = rand.nextInt(1, 100); auto stacksCountElementIndex = vstd::find_pos_if(stacksCountChances, [stacksCountInitRandomNumber](int element){ return stacksCountInitRandomNumber < element; }); if(stacksCountElementIndex == -1) - { stacksCountElementIndex = stacksCountChances.size(); - } - howManyStacks = stacksCountElementIndex + 1; + howManyStacks = stacksCountElementIndex; + if(!allowZeroStacksArmy) + howManyStacks++; vstd::amin(howManyStacks, type->initialArmy.size());