mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-21 00:19:29 +02:00
support setting dice molecule for rolling morale and luck
This commit is contained in:
@ -232,18 +232,18 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
|
||||
auto morale = slot.second->moraleVal();
|
||||
auto multiplier = 1.0f;
|
||||
|
||||
const auto & badMoraleDice = cb->getSettings().getVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
|
||||
const auto & highMoraleDice = cb->getSettings().getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE);
|
||||
const auto & badMoraleDice = cb->getSettings().getDiceVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
|
||||
const auto & highMoraleDice = cb->getSettings().getDiceVector(EGameSettings::COMBAT_GOOD_MORALE_DICE);
|
||||
|
||||
if(morale < 0 && !badMoraleDice.empty())
|
||||
{
|
||||
size_t diceIndex = std::min<size_t>(badMoraleDice.size(), -morale) - 1;
|
||||
multiplier -= 1.0 / badMoraleDice.at(diceIndex);
|
||||
multiplier -= 1.0 / badMoraleDice.at(diceIndex).second * badMoraleDice.at(diceIndex).first;
|
||||
}
|
||||
else if(morale > 0 && !highMoraleDice.empty())
|
||||
{
|
||||
size_t diceIndex = std::min<size_t>(highMoraleDice.size(), morale) - 1;
|
||||
multiplier += 1.0 / highMoraleDice.at(diceIndex);
|
||||
multiplier += 1.0 / highMoraleDice.at(diceIndex).second * highMoraleDice.at(diceIndex).first;
|
||||
}
|
||||
|
||||
newValue += multiplier * slot.second->getPower();
|
||||
|
@ -71,8 +71,8 @@ int AFactionMember::getMaxDamage(bool ranged) const
|
||||
|
||||
int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
|
||||
{
|
||||
int32_t maxGoodMorale = LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE).size();
|
||||
int32_t maxBadMorale = - (int32_t) LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE).size();
|
||||
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();
|
||||
|
||||
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()->getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE).size();
|
||||
int32_t maxBadLuck = - (int32_t) LIBRARY->engineSettings()->getVector(EGameSettings::COMBAT_BAD_LUCK_DICE).size();
|
||||
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();
|
||||
|
||||
if(getBonusBearer()->hasBonusOfType(BonusType::MAX_LUCK))
|
||||
{
|
||||
|
@ -33,6 +33,26 @@ 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();
|
||||
|
@ -106,6 +106,7 @@ 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;
|
||||
};
|
||||
|
||||
|
@ -940,19 +940,19 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
|
||||
|
||||
if(attackerLuck > 0)
|
||||
{
|
||||
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE);
|
||||
size_t diceIndex = std::min<size_t>(diceSize.size(), attackerLuck) - 1; // array index, so 0-indexed
|
||||
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
|
||||
|
||||
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
|
||||
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
|
||||
bat.flags |= BattleAttack::LUCKY;
|
||||
}
|
||||
|
||||
if(attackerLuck < 0)
|
||||
{
|
||||
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_BAD_LUCK_DICE);
|
||||
size_t diceIndex = std::min<size_t>(diceSize.size(), -attackerLuck) - 1; // array index, so 0-indexed
|
||||
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
|
||||
|
||||
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
|
||||
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
|
||||
bat.flags |= BattleAttack::UNLUCKY;
|
||||
}
|
||||
|
||||
|
@ -347,10 +347,10 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
|
||||
int nextStackMorale = next->moraleVal();
|
||||
if(!next->hadMorale && !next->waited() && nextStackMorale < 0)
|
||||
{
|
||||
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
|
||||
size_t diceIndex = std::min<size_t>(diceSize.size(), -nextStackMorale) - 1; // array index, so 0-indexed
|
||||
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
|
||||
|
||||
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
|
||||
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
|
||||
{
|
||||
//unit loses its turn - empty freeze action
|
||||
BattleAction ba;
|
||||
@ -526,10 +526,10 @@ bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, con
|
||||
&& next->canMove()
|
||||
&& nextStackMorale > 0)
|
||||
{
|
||||
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE);
|
||||
size_t diceIndex = std::min<size_t>(diceSize.size(), nextStackMorale) - 1; // array index, so 0-indexed
|
||||
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
|
||||
|
||||
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
|
||||
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
|
||||
{
|
||||
BattleTriggerEffect bte;
|
||||
bte.battleID = battle.getBattle()->getBattleID();
|
||||
|
Reference in New Issue
Block a user