1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Allow flexible configuration - starter dwellings and max stacks count

This commit is contained in:
Dydzio 2023-02-04 23:40:02 +01:00
parent 28eed7047c
commit 3f79a9806c
5 changed files with 37 additions and 23 deletions

View File

@ -34,8 +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
"NEW_HERO_ALWAYS_3_CREATURE_STACKS": false,
"DEFAULT_TOWN_ALWAYS_2_DWELLINGS": false
"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
"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":
{

View File

@ -1722,10 +1722,16 @@ void CGameState::initTowns()
if(vti->tempOwner != PlayerColor::NEUTRAL)
vti->builtBuildings.insert(BuildingID::TAVERN);
vti->builtBuildings.insert(BuildingID::DWELL_FIRST);
if((getRandomGenerator().nextInt(1) == 1) || VLC->modh->settings.DEFAULT_TOWN_ALWAYS_2_DWELLINGS)
auto definesBuildingsChances = VLC->modh->settings.DEFAULT_BUILDING_SET_DWELLING_CHANCES;
BuildingID basicDwellings[] = { BuildingID::DWELL_FIRST, BuildingID::DWELL_LVL_2, BuildingID::DWELL_LVL_3, BuildingID::DWELL_LVL_4, BuildingID::DWELL_LVL_5, BuildingID::DWELL_LVL_6, BuildingID::DWELL_LVL_7 };
for(int i = 0; i < definesBuildingsChances.size(); i++)
{
vti->builtBuildings.insert(BuildingID::DWELL_LVL_2);
if((getRandomGenerator().nextInt(1,100) <= definesBuildingsChances[i]))
{
vti->builtBuildings.insert(basicDwellings[i]);
}
}
}

View File

@ -766,10 +766,18 @@ void CModHandler::loadConfigFromFile (std::string name)
logMod->debug("\tDEFENSE_POINT_DMG_MULTIPLIER\t%f", settings.DEFENSE_POINT_DMG_MULTIPLIER);
settings.DEFENSE_POINTS_DMG_MULTIPLIER_CAP = hardcodedFeatures["DEFENSE_POINTS_DMG_MULTIPLIER_CAP"].Float();
logMod->debug("\tDEFENSE_POINTS_DMG_MULTIPLIER_CAP\t%f", settings.DEFENSE_POINTS_DMG_MULTIPLIER_CAP);
settings.NEW_HERO_ALWAYS_3_CREATURE_STACKS = hardcodedFeatures["NEW_HERO_ALWAYS_3_CREATURE_STACKS"].Bool();
logMod->debug("\tNEW_HERO_ALWAYS_3_CREATURE_STACKS\t%f", settings.NEW_HERO_ALWAYS_3_CREATURE_STACKS);
settings.DEFAULT_TOWN_ALWAYS_2_DWELLINGS = hardcodedFeatures["DEFAULT_TOWN_ALWAYS_2_DWELLINGS"].Bool();
logMod->debug("\tDEFAULT_TOWN_ALWAYS_2_DWELLINGS\t%f", settings.DEFAULT_TOWN_ALWAYS_2_DWELLINGS);
JsonVector stacksChancesVector = hardcodedFeatures["HERO_STARTING_ARMY_STACKS_COUNT_CHANCES"].Vector();
boost::range::transform(stacksChancesVector, std::back_inserter(settings.HERO_STARTING_ARMY_STACKS_COUNT_CHANCES), [](JsonNode element) { return element.Integer(); });
std::vector<std::string> stackChangesStringVector;
boost::range::transform(settings.HERO_STARTING_ARMY_STACKS_COUNT_CHANCES, std::back_inserter(stackChangesStringVector), [](int element) { return std::to_string(element); });
logMod->debug("\tHERO_STARTING_ARMY_STACKS_COUNT_CHANCES\t%s", boost::algorithm::join(stackChangesStringVector, ", "));
JsonVector buildingChancesVector = hardcodedFeatures["DEFAULT_BUILDING_SET_DWELLING_CHANCES"].Vector();
boost::range::transform(buildingChancesVector, std::back_inserter(settings.DEFAULT_BUILDING_SET_DWELLING_CHANCES), [](JsonNode element) { return element.Integer(); });
std::vector<std::string> buildingChangesStringVector;
boost::range::transform(settings.DEFAULT_BUILDING_SET_DWELLING_CHANCES, std::back_inserter(buildingChangesStringVector), [](int element) { return std::to_string(element); });
logMod->debug("\tDEFAULT_BUILDING_SET_DWELLING_CHANCES\t%s", boost::algorithm::join(buildingChangesStringVector, ", "));
const JsonNode & gameModules = settings.data["modules"];
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();

View File

@ -363,8 +363,8 @@ public:
double ATTACK_POINTS_DMG_MULTIPLIER_CAP;
double DEFENSE_POINT_DMG_MULTIPLIER;
double DEFENSE_POINTS_DMG_MULTIPLIER_CAP;
bool NEW_HERO_ALWAYS_3_CREATURE_STACKS;
bool DEFAULT_TOWN_ALWAYS_2_DWELLINGS;
std::vector<int32_t> HERO_STARTING_ARMY_STACKS_COUNT_CHANCES;
std::vector<int32_t> DEFAULT_BUILDING_SET_DWELLING_CHANCES;
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -384,8 +384,8 @@ public:
h & ATTACK_POINTS_DMG_MULTIPLIER_CAP;
h & DEFENSE_POINT_DMG_MULTIPLIER;
h & DEFENSE_POINTS_DMG_MULTIPLIER_CAP;
h & NEW_HERO_ALWAYS_3_CREATURE_STACKS;
h & DEFAULT_TOWN_ALWAYS_2_DWELLINGS;
h & HERO_STARTING_ARMY_STACKS_COUNT_CHANCES;
h & DEFAULT_BUILDING_SET_DWELLING_CHANCES;
}
} settings;

View File

@ -348,21 +348,21 @@ void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst)
if(!dst)
dst = this;
int howManyStacks = 3; //how many stacks will hero receives <1 - 3>
int howManyStacks = 7; //how many stacks will hero receives <1 - 7>
int warMachinesGiven = 0;
if(!VLC->modh->settings.NEW_HERO_ALWAYS_3_CREATURE_STACKS)
{
int stacksCountInitRandomNumber = rand.nextInt(99);
std::vector<int32_t> stacksCountChances = VLC->modh->settings.HERO_STARTING_ARMY_STACKS_COUNT_CHANCES;
if(stacksCountInitRandomNumber < 9)
howManyStacks = 1;
else if(stacksCountInitRandomNumber < 79)
howManyStacks = 2;
else
howManyStacks = 3;
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;
vstd::amin(howManyStacks, type->initialArmy.size());
for(int stackNo=0; stackNo < howManyStacks; stackNo++)