mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Add basic system to add more advantages for ai player
This commit is contained in:
89
config/difficulty.json
Normal file
89
config/difficulty.json
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// Starting resources, ordered by difficulty level (0 to 4)
|
||||||
|
{
|
||||||
|
"startres":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"human": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 },
|
||||||
|
"ai": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 }
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"human": { "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 }
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"human": { "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 }
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"human": { "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 }
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"human": { "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 }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"battleBonus":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"ai":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type" : "STACK_HEALTH",
|
||||||
|
"val" : 50,
|
||||||
|
"valueType" : "PERCENT_TO_ALL",
|
||||||
|
"duration" : "ONE_BATTLE",
|
||||||
|
"sourceType" : "OTHER"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
// Starting resources, ordered by difficulty level (0 to 4)
|
|
||||||
{
|
|
||||||
"difficulty":
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"human": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 },
|
|
||||||
"ai": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 }
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"human": { "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 }
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"human": { "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 }
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"human": { "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 }
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"human": { "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 }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -37,6 +37,7 @@ public:
|
|||||||
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
|
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
|
||||||
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
|
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
|
||||||
std::vector<QuestInfo> quests; //store info about all received quests
|
std::vector<QuestInfo> quests; //store info about all received quests
|
||||||
|
std::vector<Bonus> battleBonuses; //additional bonuses to be added during battle with neutrals
|
||||||
|
|
||||||
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
|
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
|
||||||
EPlayerStatus status;
|
EPlayerStatus status;
|
||||||
@ -82,6 +83,7 @@ public:
|
|||||||
h & visitedObjects;
|
h & visitedObjects;
|
||||||
h & status;
|
h & status;
|
||||||
h & daysWithoutCastle;
|
h & daysWithoutCastle;
|
||||||
|
h & battleBonuses;
|
||||||
h & enteredLosingCheatCode;
|
h & enteredLosingCheatCode;
|
||||||
h & enteredWinningCheatCode;
|
h & enteredWinningCheatCode;
|
||||||
h & static_cast<CBonusSystemNode&>(*this);
|
h & static_cast<CBonusSystemNode&>(*this);
|
||||||
|
@ -450,6 +450,7 @@ 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();
|
||||||
@ -657,6 +658,31 @@ void CGameState::initGlobalBonuses()
|
|||||||
VLC->creh->loadCrExpBon(globalEffects);
|
VLC->creh->loadCrExpBon(globalEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGameState::initBattleBonuses()
|
||||||
|
{
|
||||||
|
logGlobal->debug("\tLoading battle bonuses up resources");
|
||||||
|
const JsonNode config(JsonPath::builtin("config/difficulty.json"));
|
||||||
|
const JsonVector &vector = config["battleBonus"].Vector();
|
||||||
|
const JsonNode &level = vector[scenarioOps->difficulty];
|
||||||
|
const JsonNode & bonusesAI(level["ai"]);
|
||||||
|
const JsonNode & bonusesHuman(level["human"]);
|
||||||
|
|
||||||
|
for (auto & elem : players)
|
||||||
|
{
|
||||||
|
PlayerState &p = elem.second;
|
||||||
|
if(p.human)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CGameState::initGrailPosition()
|
void CGameState::initGrailPosition()
|
||||||
{
|
{
|
||||||
logGlobal->debug("\tPicking grail position");
|
logGlobal->debug("\tPicking grail position");
|
||||||
@ -816,8 +842,8 @@ void CGameState::removeHeroPlaceholders()
|
|||||||
void CGameState::initStartingResources()
|
void CGameState::initStartingResources()
|
||||||
{
|
{
|
||||||
logGlobal->debug("\tSetting up resources");
|
logGlobal->debug("\tSetting up resources");
|
||||||
const JsonNode config(JsonPath::builtin("config/startres.json"));
|
const JsonNode config(JsonPath::builtin("config/difficulty.json"));
|
||||||
const JsonVector &vector = config["difficulty"].Vector();
|
const JsonVector &vector = config["startres"].Vector();
|
||||||
const JsonNode &level = vector[scenarioOps->difficulty];
|
const JsonNode &level = vector[scenarioOps->difficulty];
|
||||||
|
|
||||||
TResources startresAI(level["ai"]);
|
TResources startresAI(level["ai"]);
|
||||||
|
@ -184,6 +184,7 @@ 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();
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "../../lib/gameState/CGameState.h"
|
#include "../../lib/gameState/CGameState.h"
|
||||||
#include "../../lib/mapping/CMap.h"
|
#include "../../lib/mapping/CMap.h"
|
||||||
#include "../../lib/modding/IdentifierStorage.h"
|
#include "../../lib/modding/IdentifierStorage.h"
|
||||||
|
#include "../../lib/CPlayerState.h"
|
||||||
|
|
||||||
BattleProcessor::BattleProcessor(CGameHandler * gameHandler)
|
BattleProcessor::BattleProcessor(CGameHandler * gameHandler)
|
||||||
: gameHandler(gameHandler)
|
: gameHandler(gameHandler)
|
||||||
@ -114,6 +115,19 @@ void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArm
|
|||||||
const auto * battle = gameHandler->gameState()->getBattle(battleID);
|
const auto * battle = gameHandler->gameState()->getBattle(battleID);
|
||||||
assert(battle);
|
assert(battle);
|
||||||
|
|
||||||
|
//add battle bonuses based from player state only when attacks neutral creatures
|
||||||
|
const auto * attackerInfo = gameHandler->getPlayerState(army1->getOwner(), false);
|
||||||
|
if(attackerInfo && army2->getOwner() == PlayerColor::NEUTRAL)
|
||||||
|
{
|
||||||
|
for(auto bonus : attackerInfo->battleBonuses)
|
||||||
|
{
|
||||||
|
GiveBonus giveBonus(GiveBonus::ETarget::HERO);
|
||||||
|
giveBonus.id = hero1->id.getNum();
|
||||||
|
giveBonus.bonus = bonus;
|
||||||
|
gameHandler->sendAndApply(&giveBonus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
||||||
|
|
||||||
if (lastBattleQuery)
|
if (lastBattleQuery)
|
||||||
|
Reference in New Issue
Block a user