1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

Moved weekly income bonus for AI to game settings

This commit is contained in:
Ivan Savenko
2024-11-26 18:43:25 +00:00
parent 087de6637c
commit f74cd32147
5 changed files with 38 additions and 37 deletions

View File

@@ -489,6 +489,20 @@
"originalFlyRules" : true "originalFlyRules" : true
}, },
"resources" : {
// H3 mechanics - AI receives bonus (or malus, on easy) to his resource income
// AI will receive specified values as percentage of his weekly income
// So, "gems" : 200 will give AI player 200% of his daily income of gems over week, or, in other words,
// giving AI player 2 additional gems per week for every owned Gem Pond
"weeklyBonusesAI" : {
"pawn" : { "gold" : -175 },
"knight": {},
"rook" : {},
"queen" : { "wood" : 275 , "mercury" : 100, "ore" : 275, "sulfur" : 100, "crystal" : 100, "gems" : 100, "gold" : 175},
"king" : { "wood" : 375 , "mercury" : 200, "ore" : 375, "sulfur" : 200, "crystal" : 200, "gems" : 200, "gold" : 350}
}
}
"spells": "spells":
{ {
// if enabled, dimension work doesn't work into tiles under Fog of War // if enabled, dimension work doesn't work into tiles under Fog of War

View File

@@ -133,6 +133,14 @@
"originalFlyRules" : { "type" : "boolean" } "originalFlyRules" : { "type" : "boolean" }
} }
}, },
"resources": {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"weeklyBonusesAI" : { "type" : "object" }
}
},
"spells": { "spells": {
"type" : "object", "type" : "object",
"additionalProperties" : false, "additionalProperties" : false,

View File

@@ -89,6 +89,7 @@ const std::vector<GameSettings::SettingOption> GameSettings::settingProperties =
{EGameSettings::PATHFINDER_USE_MONOLITH_ONE_WAY_UNIQUE, "pathfinder", "useMonolithOneWayUnique" }, {EGameSettings::PATHFINDER_USE_MONOLITH_ONE_WAY_UNIQUE, "pathfinder", "useMonolithOneWayUnique" },
{EGameSettings::PATHFINDER_USE_MONOLITH_TWO_WAY, "pathfinder", "useMonolithTwoWay" }, {EGameSettings::PATHFINDER_USE_MONOLITH_TWO_WAY, "pathfinder", "useMonolithTwoWay" },
{EGameSettings::PATHFINDER_USE_WHIRLPOOL, "pathfinder", "useWhirlpool" }, {EGameSettings::PATHFINDER_USE_WHIRLPOOL, "pathfinder", "useWhirlpool" },
{EGameSettings::RESOURCES_WEEKLY_BONUSES_AI, "resources", "weeklyBonusesAI" },
{EGameSettings::TEXTS_ARTIFACT, "textData", "artifact" }, {EGameSettings::TEXTS_ARTIFACT, "textData", "artifact" },
{EGameSettings::TEXTS_CREATURE, "textData", "creature" }, {EGameSettings::TEXTS_CREATURE, "textData", "creature" },
{EGameSettings::TEXTS_FACTION, "textData", "faction" }, {EGameSettings::TEXTS_FACTION, "textData", "faction" },

View File

@@ -67,6 +67,7 @@ enum class EGameSettings
PATHFINDER_USE_MONOLITH_ONE_WAY_UNIQUE, PATHFINDER_USE_MONOLITH_ONE_WAY_UNIQUE,
PATHFINDER_USE_MONOLITH_TWO_WAY, PATHFINDER_USE_MONOLITH_TWO_WAY,
PATHFINDER_USE_WHIRLPOOL, PATHFINDER_USE_WHIRLPOOL,
RESOURCES_WEEKLY_BONUSES_AI,
TEXTS_ARTIFACT, TEXTS_ARTIFACT,
TEXTS_CREATURE, TEXTS_CREATURE,
TEXTS_FACTION, TEXTS_FACTION,

View File

@@ -18,6 +18,7 @@
#include "../../lib/IGameSettings.h" #include "../../lib/IGameSettings.h"
#include "../../lib/StartInfo.h" #include "../../lib/StartInfo.h"
#include "../../lib/TerrainHandler.h" #include "../../lib/TerrainHandler.h"
#include "../../lib/constants/StringConstants.h"
#include "../../lib/entities/building/CBuilding.h" #include "../../lib/entities/building/CBuilding.h"
#include "../../lib/entities/faction/CTownHandler.h" #include "../../lib/entities/faction/CTownHandler.h"
#include "../../lib/gameState/CGameState.h" #include "../../lib/gameState/CGameState.h"
@@ -240,46 +241,22 @@ ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool ne
if (!state.isHuman()) if (!state.isHuman())
{ {
// Initialize bonuses for different resources // Initialize bonuses for different resources
std::array<int, GameResID::COUNT> weeklyBonuses = {}; int difficultyIndex = gameHandler->gameState()->getStartInfo()->difficulty;
const std::string & difficultyName = GameConstants::DIFFICULTY_NAMES[difficultyIndex];
// Calculate weekly bonuses based on difficulty const JsonNode & weeklyBonusesConfig = gameHandler->gameState()->getSettings().getValue(EGameSettings::RESOURCES_WEEKLY_BONUSES_AI);
if (gameHandler->gameState()->getStartInfo()->difficulty == 0) const JsonNode & difficultyConfig = weeklyBonusesConfig[difficultyName];
{
weeklyBonuses[EGameResID::GOLD] = static_cast<int>(std::round(incomeHandicapped[EGameResID::GOLD] * (0.75 - 1) * 7));
}
else if (gameHandler->gameState()->getStartInfo()->difficulty == 3)
{
weeklyBonuses[EGameResID::GOLD] = static_cast<int>(std::round(incomeHandicapped[EGameResID::GOLD] * 0.25 * 7));
weeklyBonuses[EGameResID::WOOD] = static_cast<int>(std::round(incomeHandicapped[EGameResID::WOOD] * 0.39 * 7));
weeklyBonuses[EGameResID::ORE] = static_cast<int>(std::round(incomeHandicapped[EGameResID::ORE] * 0.39 * 7));
weeklyBonuses[EGameResID::MERCURY] = static_cast<int>(std::round(incomeHandicapped[EGameResID::MERCURY] * 0.14 * 7));
weeklyBonuses[EGameResID::CRYSTAL] = static_cast<int>(std::round(incomeHandicapped[EGameResID::CRYSTAL] * 0.14 * 7));
weeklyBonuses[EGameResID::SULFUR] = static_cast<int>(std::round(incomeHandicapped[EGameResID::SULFUR] * 0.14 * 7));
weeklyBonuses[EGameResID::GEMS] = static_cast<int>(std::round(incomeHandicapped[EGameResID::GEMS] * 0.14 * 7));
}
else if (gameHandler->gameState()->getStartInfo()->difficulty == 4)
{
weeklyBonuses[EGameResID::GOLD] = static_cast<int>(std::round(incomeHandicapped[EGameResID::GOLD] * 0.5 * 7));
weeklyBonuses[EGameResID::WOOD] = static_cast<int>(std::round(incomeHandicapped[EGameResID::WOOD] * 0.53 * 7));
weeklyBonuses[EGameResID::ORE] = static_cast<int>(std::round(incomeHandicapped[EGameResID::ORE] * 0.53 * 7));
weeklyBonuses[EGameResID::MERCURY] = static_cast<int>(std::round(incomeHandicapped[EGameResID::MERCURY] * 0.28 * 7));
weeklyBonuses[EGameResID::CRYSTAL] = static_cast<int>(std::round(incomeHandicapped[EGameResID::CRYSTAL] * 0.28 * 7));
weeklyBonuses[EGameResID::SULFUR] = static_cast<int>(std::round(incomeHandicapped[EGameResID::SULFUR] * 0.28 * 7));
weeklyBonuses[EGameResID::GEMS] = static_cast<int>(std::round(incomeHandicapped[EGameResID::GEMS] * 0.28 * 7));
}
// Distribute weekly bonuses over 7 days, depending on the current day of the week // Distribute weekly bonuses over 7 days, depending on the current day of the week
for (int i = 0; i < GameResID::COUNT; ++i) for (GameResID i : GameResID::ALL_RESOURCES())
{ {
int dailyBonus = weeklyBonuses[i] / 7; const std::string & name = GameConstants::RESOURCE_NAMES[i];
int remainderBonus = weeklyBonuses[i] % 7; int weeklyBonus = difficultyConfig[name].Integer();
int dayOfWeek = gameHandler->gameState()->getDate(Date::DAY_OF_WEEK);
// Apply the daily bonus for each day, and distribute the remainder accordingly int dailyIncome = incomeHandicapped[i];
incomeHandicapped[static_cast<GameResID>(i)] += dailyBonus; int amountTillToday = dailyIncome * weeklyBonus * (dayOfWeek-1) / 7 / 100;
if (gameHandler->gameState()->getDate(Date::DAY_OF_WEEK) - 1 < remainderBonus) int amountAfterToday = dailyIncome * weeklyBonus * dayOfWeek / 7 / 100;
{ int dailyBonusToday = amountAfterToday - amountTillToday;
incomeHandicapped[static_cast<GameResID>(i)] += 1; incomeHandicapped[static_cast<GameResID>(i)] += dailyBonusToday;
}
} }
} }