Преглед изворни кода

support setting dice molecule for rolling morale and luck

kdmcser пре 7 месеци
родитељ
комит
ffb31cc77c

+ 4 - 4
AI/Nullkiller/Analyzers/ArmyManager.cpp

@@ -232,18 +232,18 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
 			auto morale = slot.second->moraleVal();
 			auto morale = slot.second->moraleVal();
 			auto multiplier = 1.0f;
 			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())
 			if(morale < 0 && !badMoraleDice.empty())
 			{
 			{
 				size_t diceIndex = std::min<size_t>(badMoraleDice.size(), -morale) - 1;
 				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())
 			else if(morale > 0 && !highMoraleDice.empty())
 			{
 			{
 				size_t diceIndex = std::min<size_t>(highMoraleDice.size(), morale) - 1;
 				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();
 			newValue += multiplier * slot.second->getPower();

+ 4 - 4
lib/BasicTypes.cpp

@@ -71,8 +71,8 @@ int AFactionMember::getMaxDamage(bool ranged) const
 
 
 int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) 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))
 	if(getBonusBearer()->hasBonusOfType(BonusType::MAX_MORALE))
 	{
 	{
@@ -100,8 +100,8 @@ int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
 
 
 int AFactionMember::luckValAndBonusList(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))
 	if(getBonusBearer()->hasBonusOfType(BonusType::MAX_LUCK))
 	{
 	{

+ 20 - 0
lib/GameSettings.cpp

@@ -33,6 +33,26 @@ std::vector<int> IGameSettings::getVector(EGameSettings option) const
 	return getValue(option).convertTo<std::vector<int>>();
 	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
 int IGameSettings::getVectorValue(EGameSettings option, size_t index) const
 {
 {
 	return getValue(option)[index].Integer();
 	return getValue(option)[index].Integer();

+ 1 - 0
lib/IGameSettings.h

@@ -106,6 +106,7 @@ public:
 	int64_t getInteger(EGameSettings option) const;
 	int64_t getInteger(EGameSettings option) const;
 	double getDouble(EGameSettings option) const;
 	double getDouble(EGameSettings option) const;
 	std::vector<int> getVector(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;
 	int getVectorValue(EGameSettings option, size_t index) const;
 };
 };
 
 

+ 6 - 6
server/battles/BattleActionProcessor.cpp

@@ -940,19 +940,19 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
 
 
 	if(attackerLuck > 0)
 	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;
 			bat.flags |= BattleAttack::LUCKY;
 	}
 	}
 
 
 	if(attackerLuck < 0)
 	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;
 			bat.flags |= BattleAttack::UNLUCKY;
 	}
 	}
 
 

+ 6 - 6
server/battles/BattleFlowProcessor.cpp

@@ -347,10 +347,10 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
 	int nextStackMorale = next->moraleVal();
 	int nextStackMorale = next->moraleVal();
 	if(!next->hadMorale && !next->waited() && nextStackMorale < 0)
 	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
 			//unit loses its turn - empty freeze action
 			BattleAction ba;
 			BattleAction ba;
@@ -526,10 +526,10 @@ bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, con
 		&& next->canMove()
 		&& next->canMove()
 		&& nextStackMorale > 0)
 		&& 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;
 			BattleTriggerEffect bte;
 			bte.battleID = battle.getBattle()->getBattleID();
 			bte.battleID = battle.getBattle()->getBattleID();