1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Restructured difficulty config

This commit is contained in:
nordsoft
2023-09-20 16:12:26 +02:00
parent 0de912e67b
commit cb3bbc6680
4 changed files with 79 additions and 109 deletions

View File

@@ -1,89 +1,70 @@
// Starting resources, ordered by difficulty level (0 to 4) //Configured difficulty
{ {
"startres": "human":
[
{ {
"human": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 }, "pawn":
"ai": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 } {
"resources": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 },
"globalBonuses": [],
"battleBonuses": []
}, },
"knight":
{ {
"human": { "wood" : 20, "mercury": 10, "ore": 20, "sulfur": 10, "crystal": 10, "gems": 10, "gold": 20000, "mithril": 0 }, "resources": { "wood" : 20, "mercury": 10, "ore": 20, "sulfur": 10, "crystal": 10, "gems": 10, "gold": 20000, "mithril": 0 },
"ai": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 7500, "mithril": 0 } "globalBonuses": [],
"battleBonuses": []
}, },
"rook":
{ {
"human": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 15000, "mithril": 0 }, "resources": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 15000, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } "globalBonuses": [],
"battleBonuses": []
}, },
"queen":
{ {
"human": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 10000, "mithril": 0 }, "resources": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 10000, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } "globalBonuses": [],
"battleBonuses": []
}, },
"king":
{ {
"human": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 }, "resources": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } "globalBonuses": [],
"battleBonuses": []
} }
],
"battleBonus":
[
{
}, },
{
"ai": "ai":
[
{ {
"type" : "STACK_HEALTH", "pawn":
"val" : 50, {
"valueType" : "PERCENT_TO_ALL", "resources": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 },
"duration" : "ONE_BATTLE", "globalBonuses": [],
"sourceType" : "OTHER" "battleBonuses": []
},
"knight":
{
"resources": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 7500, "mithril": 0 },
"globalBonuses": [],
"battleBonuses": []
},
"rook":
{
"resources": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 },
"globalBonuses": [],
"battleBonuses": []
},
"queen":
{
"resources": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 },
"globalBonuses": [],
"battleBonuses": []
},
"king":
{
"resources": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 },
"globalBonuses": [],
"battleBonuses": []
} }
],
}, },
{
"ai":
[
{
"type" : "STACK_HEALTH",
"val" : 100,
"valueType" : "PERCENT_TO_ALL",
"duration" : "ONE_BATTLE",
"sourceType" : "OTHER"
}
],
},
{
"ai":
[
{
"type" : "STACK_HEALTH",
"val" : 150,
"valueType" : "PERCENT_TO_ALL",
"duration" : "ONE_BATTLE",
"sourceType" : "OTHER"
},
],
},
{
"ai":
[
{
"type" : "STACK_HEALTH",
"val" : 200,
"valueType" : "PERCENT_TO_ALL",
"duration" : "ONE_BATTLE",
"sourceType" : "OTHER"
},
],
},
]
} }

View File

@@ -27,6 +27,8 @@ namespace GameConstants
}; };
const std::string ALIGNMENT_NAMES [3] = {"good", "evil", "neutral"}; const std::string ALIGNMENT_NAMES [3] = {"good", "evil", "neutral"};
const std::string DIFFICULTY_NAMES [5] = {"pawn", "knight", "rook", "queen", "king"};
} }
namespace NPrimarySkill namespace NPrimarySkill

View File

@@ -29,6 +29,7 @@
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include "../battle/BattleInfo.h" #include "../battle/BattleInfo.h"
#include "../campaign/CampaignState.h" #include "../campaign/CampaignState.h"
#include "../constants/StringConstants.h"
#include "../filesystem/ResourcePath.h" #include "../filesystem/ResourcePath.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h" #include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h"
@@ -450,13 +451,12 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
initPlayerStates(); initPlayerStates();
if (campaign) if (campaign)
campaign->placeCampaignHeroes(); campaign->placeCampaignHeroes();
initBattleBonuses();
removeHeroPlaceholders(); removeHeroPlaceholders();
initGrailPosition(); initGrailPosition();
initRandomFactionsForPlayers(); initRandomFactionsForPlayers();
randomizeMapObjects(); randomizeMapObjects();
placeStartingHeroes(); placeStartingHeroes();
initStartingResources(); initDifficulty();
initHeroes(); initHeroes();
initStartingBonus(); initStartingBonus();
initTowns(); initTowns();
@@ -658,29 +658,41 @@ void CGameState::initGlobalBonuses()
VLC->creh->loadCrExpBon(globalEffects); VLC->creh->loadCrExpBon(globalEffects);
} }
void CGameState::initBattleBonuses() void CGameState::initDifficulty()
{ {
logGlobal->debug("\tLoading battle bonuses up resources"); logGlobal->debug("\tLoading difficulty settings");
const JsonNode config(JsonPath::builtin("config/difficulty.json")); const JsonNode config(JsonPath::builtin("config/difficulty.json"));
const JsonVector &vector = config["battleBonus"].Vector(); const JsonVector &vector = config["battleBonus"].Vector();
const JsonNode &level = vector[scenarioOps->difficulty]; const JsonNode &level = vector[scenarioOps->difficulty];
const JsonNode & bonusesAI(level["ai"]); const JsonNode & difficultyAI(level["ai"][GameConstants::DIFFICULTY_NAMES[scenarioOps->difficulty]]);
const JsonNode & bonusesHuman(level["human"]); const JsonNode & difficultyHuman(level["human"][GameConstants::DIFFICULTY_NAMES[scenarioOps->difficulty]]);
auto setDifficulty = [](PlayerState & state, const JsonNode & json)
{
//set starting resources
state.resources = TResources(json["resources"]);
//set global bonuses
for(auto & jsonBonus : json["globalBonuses"].Vector())
if(auto bonus = JsonUtils::parseBonus(jsonBonus))
state.addNewBonus(bonus);
//set battle bonuses
for(auto & jsonBonus : json["battleBonuses"].Vector())
if(auto bonus = JsonUtils::parseBonus(jsonBonus))
state.battleBonuses.push_back(*bonus);
};
for (auto & elem : players) for (auto & elem : players)
{ {
PlayerState &p = elem.second; PlayerState &p = elem.second;
if(p.human) setDifficulty(p, p.human ? difficultyHuman : difficultyAI);
{
for(auto & jsonBonus : bonusesHuman.Vector())
p.battleBonuses.push_back(*JsonUtils::parseBonus(jsonBonus));
}
else
{
for(auto & jsonBonus : bonusesAI.Vector())
p.battleBonuses.push_back(*JsonUtils::parseBonus(jsonBonus));
}
} }
if (campaign)
campaign->initStartingResources();
} }
void CGameState::initGrailPosition() void CGameState::initGrailPosition()
@@ -839,30 +851,6 @@ void CGameState::removeHeroPlaceholders()
} }
} }
void CGameState::initStartingResources()
{
logGlobal->debug("\tSetting up resources");
const JsonNode config(JsonPath::builtin("config/difficulty.json"));
const JsonVector &vector = config["startres"].Vector();
const JsonNode &level = vector[scenarioOps->difficulty];
TResources startresAI(level["ai"]);
TResources startresHuman(level["human"]);
for (auto & elem : players)
{
PlayerState &p = elem.second;
if (p.human)
p.resources = startresHuman;
else
p.resources = startresAI;
}
if (campaign)
campaign->initStartingResources();
}
void CGameState::initHeroes() void CGameState::initHeroes()
{ {
for(auto hero : map->heroesOnMap) //heroes instances initialization for(auto hero : map->heroesOnMap) //heroes instances initialization

View File

@@ -184,7 +184,6 @@ private:
void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking); void initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking);
void checkMapChecksum(); void checkMapChecksum();
void initGlobalBonuses(); void initGlobalBonuses();
void initBattleBonuses();
void initGrailPosition(); void initGrailPosition();
void initRandomFactionsForPlayers(); void initRandomFactionsForPlayers();
void randomizeMapObjects(); void randomizeMapObjects();
@@ -193,7 +192,7 @@ private:
void placeStartingHeroes(); void placeStartingHeroes();
void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos); void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos);
void removeHeroPlaceholders(); void removeHeroPlaceholders();
void initStartingResources(); void initDifficulty();
void initHeroes(); void initHeroes();
void placeHeroesInTowns(); void placeHeroesInTowns();
void initFogOfWar(); void initFogOfWar();