1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Allow heroes to start with empty armies if configured properly

This commit is contained in:
Dydzio 2023-02-05 00:36:51 +01:00
parent 3f79a9806c
commit 7095e9d8f9
3 changed files with 11 additions and 5 deletions

View File

@ -182,7 +182,7 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
{ {
auto weakest = getWeakestCreature(resultingArmy); 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); resultingArmy.erase(weakest);
} }

View File

@ -34,7 +34,8 @@
"ATTACK_POINTS_DMG_MULTIPLIER_CAP": 4.0, //limit of damage increase that can be achieved by overpowering attack points "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_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 "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 "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": "modules":

View File

@ -353,15 +353,20 @@ void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst)
std::vector<int32_t> stacksCountChances = VLC->modh->settings.HERO_STARTING_ARMY_STACKS_COUNT_CHANCES; std::vector<int32_t> 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); int stacksCountInitRandomNumber = rand.nextInt(1, 100);
auto stacksCountElementIndex = vstd::find_pos_if(stacksCountChances, [stacksCountInitRandomNumber](int element){ return stacksCountInitRandomNumber < element; }); auto stacksCountElementIndex = vstd::find_pos_if(stacksCountChances, [stacksCountInitRandomNumber](int element){ return stacksCountInitRandomNumber < element; });
if(stacksCountElementIndex == -1) if(stacksCountElementIndex == -1)
{
stacksCountElementIndex = stacksCountChances.size(); stacksCountElementIndex = stacksCountChances.size();
}
howManyStacks = stacksCountElementIndex + 1; howManyStacks = stacksCountElementIndex;
if(!allowZeroStacksArmy)
howManyStacks++;
vstd::amin(howManyStacks, type->initialArmy.size()); vstd::amin(howManyStacks, type->initialArmy.size());