diff --git a/config/battleStartpos.json b/config/battleStartpos.json index 91cd9358f..c193c8f71 100644 --- a/config/battleStartpos.json +++ b/config/battleStartpos.json @@ -1,5 +1,6 @@ { - "battle_positions": [ + "battle_positions": + [ { "name" : "attackerLoose", // loose formation, attacker "levels": [ @@ -77,5 +78,10 @@ [ 15, 185, 171, 1, 100, 86, 8 ] ] } - ] + ], + "commanderPositions": + { + "field" : [88, 98], //attacker/defender + "creBank" : [95, 8] //not expecting defendig hero at bank, but hell knows + } } diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index e5835ef4b..d4a1c4714 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -1616,7 +1616,9 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const } //reading battleStartpos + //TODO: parse once to some structure std::vector< std::vector > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank; + std::vector commanderField, commanderBank; const JsonNode config(GameConstants::DATA_DIR + "/config/battleStartpos.json"); const JsonVector &positions = config["battle_positions"].Vector(); @@ -1626,6 +1628,15 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const CGH::readBattlePositions(positions[3]["levels"], defenderTight); CGH::readBattlePositions(positions[4]["levels"], attackerCreBank); CGH::readBattlePositions(positions[5]["levels"], defenderCreBank); + + BOOST_FOREACH (auto position, config["commanderPositions"]["field"].Vector()) + { + commanderField.push_back (position.Float()); + } + BOOST_FOREACH (auto position, config["commanderPositions"]["creBank"].Vector()) + { + commanderBank.push_back (position.Float()); + } //battleStartpos read int k = 0; //stack serial @@ -1721,6 +1732,18 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const } //war machines added + //adding commanders + for (int i = 0; i < 2; ++i) + { + if (heroes[i] && heroes[i]->commander) + { + CStack * stack = curB->generateNewStack (*heroes[i]->commander, !i, 255, + creatureBank ? commanderBank[i] : commanderField[i]); + stacks.push_back(stack); + } + + } + if (curB->siege == 2 || curB->siege == 3) { // keep tower diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index d60b7f375..7cfc9de2b 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -36,7 +36,7 @@ namespace ArtBearer { enum { - HERO, CREATURE//, COMMANDER + HERO, CREATURE, COMMANDER }; } diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index c2ea7144c..914f17937 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -949,20 +949,21 @@ ui8 CStackInstance::bearerType() const CCommanderInstance::CCommanderInstance() { init(); + name = "Unnamed"; } CCommanderInstance::CCommanderInstance (TCreature id) { init(); - CStackInstance (id, 1); //init with single unit + setType(id); name = "Commando"; //TODO - parse them } -void CCommanderInstance::init() +void CCommanderInstance::init() //called only after CStackInstance::init was executed { alive = true; experience = 0; - count = 0; + count = 1; type = NULL; idRand = -1; _armyObj = NULL; diff --git a/lib/CCreatureSet.h b/lib/CCreatureSet.h index 3ccf91282..ca889ad6f 100644 --- a/lib/CCreatureSet.h +++ b/lib/CCreatureSet.h @@ -83,13 +83,14 @@ public: std::string name; // each Commander has different name std::vector > secondarySkills; //ID, level //std::vector arts; - void init(); + void init() OVERRIDE; CCommanderInstance(); CCommanderInstance (TCreature id); ~CCommanderInstance(); ui64 getPower() const {return 0;}; int getExpRank() const {return 0;}; + ui8 bearerType() const OVERRIDE {return ArtBearer::COMMANDER;}; //from CArtifactSet template void serialize(Handler &h, const int version) { diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 50b375e49..f9b0d3f32 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -777,6 +777,7 @@ void CGHeroInstance::initHero() if (GameConstants::COMMANDERS) { commander = new CCommanderInstance (VLC->creh->factionCommanders[type->heroType / 2]); //hopefully it returns town type + commander->setArmyObj (castToArmyObj()); //TODO: separate function for setting commanders } hoverName = VLC->generaltexth->allTexts[15]; diff --git a/lib/GameConstants.h b/lib/GameConstants.h index fdce5e403..d77091a2e 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -92,7 +92,7 @@ namespace GameConstants //game modules const bool STACK_EXP = true; const bool STACK_ARTIFACT = true; //now toggle for testing - const bool COMMANDERS = false; + const bool COMMANDERS = true; const bool MITHRIL = false; }