diff --git a/config/battleStartpos.json b/config/battleStartpos.json new file mode 100644 index 000000000..91cd9358f --- /dev/null +++ b/config/battleStartpos.json @@ -0,0 +1,81 @@ +{ + "battle_positions": [ + { + "name" : "attackerLoose", // loose formation, attacker + "levels": [ + [ 86 ], + [ 35, 137 ], + [ 35, 86, 137 ], + [ 1, 69, 103, 171 ], + [ 1, 35, 86, 137, 171 ], + [ 1, 35, 69, 103, 137, 171 ], + [ 1, 35, 69, 86, 103, 137, 171 ] + ] + }, + + { + "name" : "defenderLoose", // loose formation, defender + "levels": [ + [ 100 ], + [ 49, 151 ], + [ 49, 100, 151 ], + [ 15, 83, 117, 185 ], + [ 15, 49, 100, 151, 185 ], + [ 15, 49, 83, 117, 151, 185 ], + [ 15, 49, 83, 100, 117, 151, 185 ] + ] + }, + + { + "name" : "attackerTight", // tight formation, attacker + "levels": [ + [ 86 ], + [ 69, 103 ], + [ 69, 86, 103 ], + [ 52, 69, 103, 120 ], + [ 52, 69, 86, 103, 120 ], + [ 35, 52, 69, 103, 120, 137 ], + [ 35, 52, 69, 86, 103, 120, 137 ] + ] + }, + + { + "name" : "defenderTight", // tight formation, defender + "levels": [ + [ 100 ], + [ 83, 117 ], + [ 83, 100, 117 ], + [ 66, 83, 117, 134 ], + [ 66, 83, 100, 117, 134 ], + [ 49, 66, 83, 117, 134, 151 ], + [ 49, 66, 83, 100, 117, 134, 151 ] + ] + }, + + { + "name" : "attackerCreBank", // creature bank, attacker + "levels": [ + [ 57 ], + [ 57, 61 ], + [ 57, 61, 90 ], + [ 57, 61, 90, 93 ], + [ 57, 61, 90, 93, 96 ], + [ 57, 61, 90, 93, 96, 125 ], + [ 57, 61, 90, 93, 96, 125, 129 ] + ] + }, + + { + "name" : "defenderCreBank", // creature bank, defender + "levels": [ + [ 15 ], + [ 15, 185 ], + [ 15, 185, 171 ], + [ 15, 185, 171, 1 ], + [ 15, 185, 171, 1, 100 ], + [ 15, 185, 171, 1, 100, 86 ], + [ 15, 185, 171, 1, 100, 86, 8 ] + ] + } + ] +} diff --git a/config/battleStartpos.txt b/config/battleStartpos.txt deleted file mode 100644 index b584ec013..000000000 --- a/config/battleStartpos.txt +++ /dev/null @@ -1,51 +0,0 @@ -//loose_formation -//attacker -86 -35 137 -35 86 137 -1 69 103 171 -1 35 86 137 171 -1 35 69 103 137 171 -1 35 69 86 103 137 171 -//defender -100 -49 151 -49 100 151 -15 83 117 185 -15 49 100 151 185 -15 49 83 117 151 185 -15 49 83 100 117 151 185 -//tight_formation -//atacker -86 -69 103 -69 86 103 -52 69 103 120 -52 69 86 103 120 -35 52 69 103 120 137 -35 52 69 86 103 120 137 -//defender -100 -83 117 -83 100 117 -66 83 117 134 -66 83 100 117 134 -49 66 83 117 134 151 -49 66 83 100 117 134 151 -//creature_bank -//attacker -57 -57 61 -57 61 90 -57 61 90 93 -57 61 90 93 96 -57 61 90 93 96 125 -57 61 90 93 96 125 129 -//defender -15 -15 185 -15 185 171 -15 185 171 1 -15 185 171 1 100 -15 185 171 1 100 86 -15 185 171 1 100 86 8 \ No newline at end of file diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index c3cdaa835..b11d54d94 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -16,6 +16,7 @@ #include "CSpellHandler.h" #include "CTownHandler.h" #include "NetPacks.h" +#include "../lib/JsonNode.h" /* * BattleState.h, part of VCMI engine @@ -1372,16 +1373,17 @@ void BattleInfo::localInit() namespace CGH { using namespace std; - static void readItTo(ifstream & input, vector< vector > & dest) //reads 7 lines, i-th one containing i integers, and puts it to dest + + static void readBattlePositions(const JsonNode &node, vector< vector > & dest) { - for(int j=0; j<7; ++j) + BOOST_FOREACH(const JsonNode &level, node.Vector()) { std::vector pom; - for(int g=0; g>hlp; - pom.push_back(hlp); + pom.push_back(value.Float()); } + dest.push_back(pom); } } @@ -1419,31 +1421,18 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const } //reading battleStartpos - std::ifstream positions; - positions.open(DATA_DIR "/config/battleStartpos.txt", std::ios_base::in|std::ios_base::binary); - if(!positions.is_open()) - { - tlog1<<"Unable to open battleStartpos.txt!"<>dump; positions>>dump; std::vector< std::vector > attackerLoose, defenderLoose, attackerTight, defenderTight, attackerCreBank, defenderCreBank; - CGH::readItTo(positions, attackerLoose); - positions>>dump; - CGH::readItTo(positions, defenderLoose); - positions>>dump; - positions>>dump; - CGH::readItTo(positions, attackerTight); - positions>>dump; - CGH::readItTo(positions, defenderTight); - positions>>dump; - positions>>dump; - CGH::readItTo(positions, attackerCreBank); - positions>>dump; - CGH::readItTo(positions, defenderCreBank); - positions.close(); - //battleStartpos read + const JsonNode config(DATA_DIR "/config/battleStartpos.json"); + const JsonVector &positions = config["battle_positions"].Vector(); + CGH::readBattlePositions(positions[0]["levels"], attackerLoose); + CGH::readBattlePositions(positions[1]["levels"], defenderLoose); + CGH::readBattlePositions(positions[2]["levels"], attackerTight); + CGH::readBattlePositions(positions[3]["levels"], defenderTight); + CGH::readBattlePositions(positions[4]["levels"], attackerCreBank); + CGH::readBattlePositions(positions[5]["levels"], defenderCreBank); + + //battleStartpos read int k = 0; //stack serial for(TSlots::const_iterator i = armies[0]->Slots().begin(); i!=armies[0]->Slots().end(); i++, k++) {