From bcce343b6c935a771cb697b1b0ec5402e9728279 Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Fri, 2 Sep 2011 03:39:49 +0000 Subject: [PATCH] Created terrains.json from native_terrains.txt and TERCOSTS.TXT. --- config/TERCOSTS.TXT | 10 ------ config/native_terrains.txt | 11 ------ config/terrains.json | 52 +++++++++++++++++++++++++++++ lib/CHeroHandler.cpp | 68 +++++++++++--------------------------- lib/CHeroHandler.h | 3 +- 5 files changed, 73 insertions(+), 71 deletions(-) delete mode 100644 config/TERCOSTS.TXT delete mode 100644 config/native_terrains.txt create mode 100644 config/terrains.json diff --git a/config/TERCOSTS.TXT b/config/TERCOSTS.TXT deleted file mode 100644 index a06c315ac..000000000 --- a/config/TERCOSTS.TXT +++ /dev/null @@ -1,10 +0,0 @@ -9 -10 100 150 100 150 175 125 100 100 100 -1 -10 100 150 100 150 175 125 100 100 100 -1 -10 100 150 100 100 175 125 100 100 100 -1 -10 100 150 100 150 175 125 100 100 100 -1 -10 100 150 100 150 175 125 100 100 100 -1 -10 100 150 100 150 175 125 100 100 100 -1 -10 100 150 100 150 175 100 100 100 100 -1 -10 100 150 100 150 100 125 100 100 100 -1 -10 100 150 100 150 175 125 100 100 100 -1 \ No newline at end of file diff --git a/config/native_terrains.txt b/config/native_terrains.txt deleted file mode 100644 index d90ef9bb7..000000000 --- a/config/native_terrains.txt +++ /dev/null @@ -1,11 +0,0 @@ -//list of native terrains of different factions -//[faction ID] [terrain ID] -0 2 -1 2 -2 3 -3 7 -4 0 -5 6 -6 5 -7 4 -8 2 \ No newline at end of file diff --git a/config/terrains.json b/config/terrains.json new file mode 100644 index 000000000..5fc82be11 --- /dev/null +++ b/config/terrains.json @@ -0,0 +1,52 @@ +{ + // Terrains properties related to heroes - ordered by faction (0 to 8) + // cost: ?? + // native: native terrain for the faction + + "terrains": [ + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 2 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 2 + }, + + { + "costs": [ 100, 150, 100, 100, 175, 125, 100, 100, 100, -1 ], + "native": 3 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 7 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 0 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 6 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 100, 100, 100, 100, -1 ], + "native": 5 + }, + + { + "costs": [ 100, 150, 100, 150, 100, 125, 100, 100, 100, -1 ], + "native": 4 + }, + + { + "costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ], + "native": 2 + } + ] +} diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 3a0aa645c..42d6b8cdb 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -421,8 +421,8 @@ void CHeroHandler::initHeroClasses() { heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType]; } - initTerrainCosts(); - loadNativeTerrains(); + + loadTerrains(); } unsigned int CHeroHandler::level (ui64 experience) const @@ -458,56 +458,28 @@ ui64 CHeroHandler::reqExp (unsigned int level) const } } -void CHeroHandler::initTerrainCosts() +void CHeroHandler::loadTerrains() { - std::ifstream inp; - inp.open(DATA_DIR "/config/TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary); - - if(!inp.is_open()) - { - tlog1 << "Error while opening config/TERCOSTS.TXT file!" << std::endl; - } - - int tynum; - inp>>tynum; - for(int i=0; i<2*tynum; i+=2) - { - int catNum; - inp>>catNum; - for(int k=0; k>curCost; - heroClasses[i]->terrCosts.push_back(curCost); - heroClasses[i+1]->terrCosts.push_back(curCost); - } - } - inp.close(); -} - -void CHeroHandler::loadNativeTerrains() -{ - std::ifstream inp; - inp.open(DATA_DIR "/config/native_terrains.txt", std::ios_base::in|std::ios_base::binary); - - if(!inp.is_open()) - { - tlog1 << "Error while opening config/native_terrains.txt file!" << std::endl; - } - const int MAX_ELEM = 1000; - char buf[MAX_ELEM+1]; - inp.getline(buf, MAX_ELEM); - inp.getline(buf, MAX_ELEM); + int faction = 0; + const JsonNode config(DATA_DIR "/config/terrains.json"); nativeTerrains.resize(F_NUMBER); - for(int i=0; i> faction; - inp >> terrain; - nativeTerrains[faction] = terrain; + + BOOST_FOREACH(const JsonNode &terrain, config["terrains"].Vector()) { + + BOOST_FOREACH(const JsonNode &cost, terrain["costs"].Vector()) { + int curCost = cost.Float(); + + heroClasses[2*faction]->terrCosts.push_back(curCost); + heroClasses[2*faction+1]->terrCosts.push_back(curCost); + } + + nativeTerrains[faction] = terrain["native"].Float(); + + faction ++; } - inp.close(); + + assert(faction == F_NUMBER); } CHero::CHero() diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 8b84aca87..a9acfac59 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -155,8 +155,7 @@ public: void loadHeroes(); void loadHeroClasses(); void initHeroClasses(); - void initTerrainCosts(); - void loadNativeTerrains(); + void loadTerrains(); CHeroHandler(); //c-tor ~CHeroHandler(); //d-tor