1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

change config format

This commit is contained in:
kdmcser
2025-03-23 01:12:12 +08:00
parent 32e945c116
commit 5c1adc7df5
8 changed files with 56 additions and 64 deletions

View File

@ -232,18 +232,19 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
auto morale = slot.second->moraleVal();
auto multiplier = 1.0f;
const auto & badMoraleDice = cb->getSettings().getDiceVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
const auto & highMoraleDice = cb->getSettings().getDiceVector(EGameSettings::COMBAT_GOOD_MORALE_DICE);
const auto & badMoraleChance = cb->getSettings().getVector(EGameSettings::COMBAT_BAD_MORALE_CHANCE);
const auto & highMoraleChance = cb->getSettings().getVector(EGameSettings::COMBAT_GOOD_MORALE_CHANCE);
int moraleDiceSize = cb->getSettings().getInteger(EGameSettings::COMBAT_MORALE_DICE_SIZE);
if(morale < 0 && !badMoraleDice.empty())
if(morale < 0 && !badMoraleChance.empty())
{
size_t diceIndex = std::min<size_t>(badMoraleDice.size(), -morale) - 1;
multiplier -= 1.0 / badMoraleDice.at(diceIndex).second * badMoraleDice.at(diceIndex).first;
size_t chanceIndex = std::min<size_t>(badMoraleChance.size(), -morale) - 1;
multiplier -= 1.0 / moraleDiceSize * badMoraleChance.at(chanceIndex);
}
else if(morale > 0 && !highMoraleDice.empty())
else if(morale > 0 && !highMoraleChance.empty())
{
size_t diceIndex = std::min<size_t>(highMoraleDice.size(), morale) - 1;
multiplier += 1.0 / highMoraleDice.at(diceIndex).second * highMoraleDice.at(diceIndex).first;
size_t chanceIndex = std::min<size_t>(highMoraleChance.size(), morale) - 1;
multiplier += 1.0 / moraleDiceSize * highMoraleChance.at(chanceIndex);
}
newValue += multiplier * slot.second->getPower();

View File

@ -340,14 +340,16 @@
"combat":
{
// defines dice size of a morale roll, based on creature's morale.
// Resulting chance is 1/(value). If list contains 0 values, option will be disabled
"goodMoraleDice" : [ 24, 12, 8 ],
"badMoraleDice" : [ 12, 6, 4],
// defines dice chance and dice size of a morale roll, based on creature's morale.
// Resulting chance is chanceValue / diceSize. If list contains 0 values, option will be disabled
"goodMoraleChance" : [ 1, 2, 3 ],
"badMoraleChance" : [ 2, 4, 6],
"moraleDiceSize" : 24,
// defines dice size of a luck roll, based on creature's luck
"goodLuckDice" : [ 24, 12, 8 ],
"badLuckDice" : [],
// defines dice chance and dice size of a luck roll, based on creature's luck
"goodLuckChance" : [ 1, 2, 3 ],
"badLuckChance" : [],
"luckDiceSize" : 24,
// every 1 attack point damage influence in battle when attack points > defense points during creature attack
"attackPointDamageFactor": 0.05,

View File

@ -66,10 +66,12 @@
"type" : "object",
"additionalProperties" : false,
"properties" : {
"goodMoraleDice" : { "type" : "array" },
"badMoraleDice" : { "type" : "array" },
"goodLuckDice" : { "type" : "array" },
"badLuckDice" : { "type" : "array" },
"goodMoraleChance" : { "type" : "array" },
"badMoraleChance" : { "type" : "array" },
"moraleDiceSize" : { "type" : "number" },
"goodLuckChance" : { "type" : "array" },
"badLuckChance" : { "type" : "array" },
"luckDiceSize" : { "type" : "number" },
"backpackSize" : { "type" : "number" },
"attackPointDamageFactor" : { "type" : "number" },
"attackPointDamageFactorCap" : { "type" : "number" },

View File

@ -71,8 +71,8 @@ int AFactionMember::getMaxDamage(bool ranged) const
int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
{
int32_t maxGoodMorale = LIBRARY->engineSettings()->getDiceVector(EGameSettings::COMBAT_GOOD_MORALE_DICE).size();
int32_t maxBadMorale = - (int32_t) LIBRARY->engineSettings()->getDiceVector(EGameSettings::COMBAT_BAD_MORALE_DICE).size();
int32_t maxGoodMorale = LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_GOOD_MORALE_CHANCE).size();
int32_t maxBadMorale = - (int32_t) LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_BAD_MORALE_CHANCE).size();
if(getBonusBearer()->hasBonusOfType(BonusType::MAX_MORALE))
{
@ -100,8 +100,8 @@ int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
int AFactionMember::luckValAndBonusList(TConstBonusListPtr & bonusList) const
{
int32_t maxGoodLuck = LIBRARY->engineSettings()->getDiceVector(EGameSettings::COMBAT_GOOD_LUCK_DICE).size();
int32_t maxBadLuck = - (int32_t) LIBRARY->engineSettings()->getDiceVector(EGameSettings::COMBAT_BAD_LUCK_DICE).size();
int32_t maxGoodLuck = LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_GOOD_LUCK_CHANCE).size();
int32_t maxBadLuck = - (int32_t) LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_BAD_LUCK_CHANCE).size();
if(getBonusBearer()->hasBonusOfType(BonusType::MAX_LUCK))
{

View File

@ -33,26 +33,6 @@ std::vector<int> IGameSettings::getVector(EGameSettings option) const
return getValue(option).convertTo<std::vector<int>>();
}
std::vector<std::pair<int, int> > IGameSettings::getDiceVector(EGameSettings option) const
{
const JsonVector & diceVector = getValue(option).Vector();
std::vector<std::pair<int, int> > result;
for (auto& jsonNode : diceVector)
{
if (jsonNode.isVector())
{
std::vector<int> oneDice = jsonNode.convertTo<std::vector<int>>();
result.push_back(std::make_pair(oneDice[0], oneDice[1]));
}
else
{
int denominator = jsonNode.Integer();
result.push_back(std::make_pair(1, denominator));
}
}
return result;
}
int IGameSettings::getVectorValue(EGameSettings option, size_t index) const
{
return getValue(option)[index].Integer();
@ -68,12 +48,14 @@ const std::vector<GameSettings::SettingOption> GameSettings::settingProperties =
{EGameSettings::COMBAT_AREA_SHOT_CAN_TARGET_EMPTY_HEX, "combat", "areaShotCanTargetEmptyHex" },
{EGameSettings::COMBAT_ATTACK_POINT_DAMAGE_FACTOR, "combat", "attackPointDamageFactor" },
{EGameSettings::COMBAT_ATTACK_POINT_DAMAGE_FACTOR_CAP, "combat", "attackPointDamageFactorCap" },
{EGameSettings::COMBAT_BAD_LUCK_DICE, "combat", "badLuckDice" },
{EGameSettings::COMBAT_BAD_MORALE_DICE, "combat", "badMoraleDice" },
{EGameSettings::COMBAT_DEFENSE_POINT_DAMAGE_FACTOR, "combat", "defensePointDamageFactor" },
{EGameSettings::COMBAT_DEFENSE_POINT_DAMAGE_FACTOR_CAP, "combat", "defensePointDamageFactorCap" },
{EGameSettings::COMBAT_GOOD_LUCK_DICE, "combat", "goodLuckDice" },
{EGameSettings::COMBAT_GOOD_MORALE_DICE, "combat", "goodMoraleDice" },
{EGameSettings::COMBAT_GOOD_MORALE_CHANCE, "combat", "goodMoraleChance" },
{EGameSettings::COMBAT_BAD_MORALE_CHANCE, "combat", "badMoraleChance" },
{EGameSettings::COMBAT_MORALE_DICE_SIZE, "combat", "moraleDiceSize" },
{EGameSettings::COMBAT_GOOD_LUCK_CHANCE, "combat", "goodLuckChance" },
{EGameSettings::COMBAT_BAD_LUCK_CHANCE, "combat", "badLuckChance" },
{EGameSettings::COMBAT_LUCK_DICE_SIZE, "combat", "luckDiceSize" },
{EGameSettings::COMBAT_LAYOUTS, "combat", "layouts" },
{EGameSettings::COMBAT_ONE_HEX_TRIGGERS_OBSTACLES, "combat", "oneHexTriggersObstacles" },
{EGameSettings::CREATURES_ALLOW_ALL_FOR_DOUBLE_MONTH, "creatures", "allowAllForDoubleMonth" },

View File

@ -21,12 +21,14 @@ enum class EGameSettings
COMBAT_AREA_SHOT_CAN_TARGET_EMPTY_HEX,
COMBAT_ATTACK_POINT_DAMAGE_FACTOR,
COMBAT_ATTACK_POINT_DAMAGE_FACTOR_CAP,
COMBAT_BAD_LUCK_DICE,
COMBAT_BAD_MORALE_DICE,
COMBAT_DEFENSE_POINT_DAMAGE_FACTOR,
COMBAT_DEFENSE_POINT_DAMAGE_FACTOR_CAP,
COMBAT_GOOD_LUCK_DICE,
COMBAT_GOOD_MORALE_DICE,
COMBAT_GOOD_MORALE_CHANCE,
COMBAT_BAD_MORALE_CHANCE,
COMBAT_MORALE_DICE_SIZE,
COMBAT_GOOD_LUCK_CHANCE,
COMBAT_BAD_LUCK_CHANCE,
COMBAT_LUCK_DICE_SIZE,
COMBAT_LAYOUTS,
COMBAT_ONE_HEX_TRIGGERS_OBSTACLES,
CREATURES_ALLOW_ALL_FOR_DOUBLE_MONTH,
@ -106,7 +108,6 @@ public:
int64_t getInteger(EGameSettings option) const;
double getDouble(EGameSettings option) const;
std::vector<int> getVector(EGameSettings option) const;
std::vector<std::pair<int, int> > getDiceVector(EGameSettings option) const;
int getVectorValue(EGameSettings option, size_t index) const;
};

View File

@ -940,19 +940,21 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
if(attackerLuck > 0)
{
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_GOOD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), attackerLuck) - 1; // array index, so 0-indexed
auto goodLuckChanceVector = gameHandler->getSettings().getVector(EGameSettings::COMBAT_GOOD_LUCK_CHANCE);
int luckDiceSize = gameHandler->getSettings().getInteger(EGameSettings::COMBAT_LUCK_DICE_SIZE);
size_t chanceIndex = std::min<size_t>(goodLuckChanceVector.size(), attackerLuck) - 1; // array index, so 0-indexed
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
if(goodLuckChanceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, luckDiceSize) <= goodLuckChanceVector[chanceIndex])
bat.flags |= BattleAttack::LUCKY;
}
if(attackerLuck < 0)
{
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_BAD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), -attackerLuck) - 1; // array index, so 0-indexed
auto badLuckChanceVector = gameHandler->getSettings().getVector(EGameSettings::COMBAT_BAD_LUCK_CHANCE);
int luckDiceSize = gameHandler->getSettings().getInteger(EGameSettings::COMBAT_LUCK_DICE_SIZE);
size_t chanceIndex = std::min<size_t>(badLuckChanceVector.size(), -attackerLuck) - 1; // array index, so 0-indexed
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
if(badLuckChanceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, luckDiceSize) <= badLuckChanceVector[chanceIndex])
bat.flags |= BattleAttack::UNLUCKY;
}

View File

@ -347,10 +347,11 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
int nextStackMorale = next->moraleVal();
if(!next->hadMorale && !next->waited() && nextStackMorale < 0)
{
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), -nextStackMorale) - 1; // array index, so 0-indexed
auto badMoraleChanceVector = gameHandler->getSettings().getVector(EGameSettings::COMBAT_BAD_MORALE_CHANCE);
int moraleDiceSize = gameHandler->getSettings().getInteger(EGameSettings::COMBAT_MORALE_DICE_SIZE);
size_t chanceIndex = std::min<size_t>(badMoraleChanceVector.size(), -nextStackMorale) - 1; // array index, so 0-indexed
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
if(badMoraleChanceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, moraleDiceSize) <= badMoraleChanceVector[chanceIndex])
{
//unit loses its turn - empty freeze action
BattleAction ba;
@ -526,10 +527,11 @@ bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, con
&& next->canMove()
&& nextStackMorale > 0)
{
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_GOOD_MORALE_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), nextStackMorale) - 1; // array index, so 0-indexed
auto goodMoraleChanceVector = gameHandler->getSettings().getVector(EGameSettings::COMBAT_GOOD_MORALE_CHANCE);
int moraleDiceSize = gameHandler->getSettings().getInteger(EGameSettings::COMBAT_MORALE_DICE_SIZE);
size_t chanceIndex = std::min<size_t>(goodMoraleChanceVector.size(), nextStackMorale) - 1; // array index, so 0-indexed
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
if(goodMoraleChanceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, moraleDiceSize) <= goodMoraleChanceVector[chanceIndex])
{
BattleTriggerEffect bte;
bte.battleID = battle.getBattle()->getBattleID();