From b114047738aac664c71010392ef1de6f86880d50 Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Fri, 26 Aug 2011 02:39:58 +0000 Subject: [PATCH] Integrate buildings4.txt into buildings.json. It's ligthly tested because I can't find what this file is supposed to define. --- config/buildings.json | 87 +++++++++++++++++++++++++++++++- config/buildings4.txt | 111 ----------------------------------------- lib/CTownHandler.cpp | 112 ++++++++++++++---------------------------- 3 files changed, 122 insertions(+), 188 deletions(-) delete mode 100644 config/buildings4.txt diff --git a/config/buildings.json b/config/buildings.json index 223698efc..49d53be88 100644 --- a/config/buildings.json +++ b/config/buildings.json @@ -421,5 +421,88 @@ ], "blit_order": [ -1, 27, 28, 16, 34, 41, 6, 20, 33, 40, 36, 43, 21, 0, 1, 2, 3, 4, 5, 15, 14, 17, 35, 42, 30, 18, 37, 19, 10, 11, 12, 13, 29 ] } - ] -} + ], + + "town_groups": // Not sure what that is. + [ + { + // Applies to all castles + "id": -1, + "groups" : [ + [ 0, 1, 2, 3, 4 ], + [ 6, 20 ], + [ 7, 8, 9 ], + [ 10, 11, 12, 13 ], + [ 30, 37 ], + [ 31, 38 ], + [ 32, 39 ], + [ 33, 40 ], + [ 34, 41 ], + [ 35, 42 ], + [ 36, 43 ], + [ 24, 25 ], + [ 18, 19 ] + ], + }, + + { + "id": 1, + "groups" : [ + [ 24, 25, 34, 41 ], + [ 17, 21 ], + [ 31, 18, 38, 19 ] + ], + }, + + { + "id": 2, + "groups" : [ + [ 18, 19, 31, 38 ] + ], + }, + + { + "id": 3, + "groups" : [ + [ 18, 19, 30, 37 ], + [ 32, 39, 24, 25 ] + ], + }, + + { + "id": 4, + "groups" : [ + [ 30, 37, 18, 19 ] + ], + }, + + { + "id": 5, + "groups" : [ + [ 30, 37, 18, 19 ] + ], + }, + + { + "id": 6, + "groups" : [ + [ 21 ], + [ 30, 37, 18, 19 ] + ], + }, + + { + "id": 7, + "groups" : [ + [ 30, 37, 18, 19 ] + ], + }, + + { + "id": 8, + "groups" : [ + [ 30, 37, 18, 19 ] + ], + } + ] +} diff --git a/config/buildings4.txt b/config/buildings4.txt deleted file mode 100644 index a1dce940d..000000000 --- a/config/buildings4.txt +++ /dev/null @@ -1,111 +0,0 @@ -1 -ALL -GROUP -0 -1 -2 -3 -4 -GROUP -6 -20 -GROUP -7 -8 -9 -GROUP -10 -11 -12 -13 -GROUP -30 -37 -GROUP -31 -38 -GROUP -32 -39 -GROUP -33 -40 -GROUP -34 -41 -GROUP -35 -42 -GROUP -36 -43 -GROUP -24 -25 -GROUP -18 -19 -CASTLE 1 -GROUP -24 -25 -34 -41 -GROUP -17 -21 -GROUP -31 -18 -38 -19 -CASTLE 2 -GROUP -18 -19 -31 -38 -CASTLE 3 -GROUP -18 -19 -30 -37 -GROUP -32 -39 -24 -25 -CASTLE 4 -GROUP -30 -37 -18 -19 -CASTLE 5 -GROUP -30 -37 -18 -19 -CASTLE 6 -GROUP -21 -GROUP -30 -37 -18 -19 -CASTLE 7 -GROUP -30 -37 -18 -19 -CASTLE 8 -GROUP -30 -37 -18 -19 -EOD \ No newline at end of file diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index ba277051c..23c9f38e1 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -6,6 +6,7 @@ #include "../lib/VCMI_Lib.h" #include "CGeneralTextHandler.h" #include "../lib/JsonNode.h" +#include extern CLodHandler * bitmaph; void loadToIt(std::string &dest, const std::string &src, int &iter, int mode); @@ -183,89 +184,50 @@ void CTownHandler::loadStructures() tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl; } } - - //read borders and areas names - int format; - std::string s; - //read groups - of.open(DATA_DIR "/config/buildings4.txt"); - of >> format; - if(format!=1) - { - tlog1 << "Unhandled format of buildings4.txt \n"; - } - else - { - of >> s; - int itr=1; - while(!of.eof()) - { - std::vector >::iterator i; - std::map::iterator i2; - int buildingID; - int castleID; - itr++; - if (s == "CASTLE") - { - of >> castleID; - } - else if(s == "ALL") - { - castleID = -1; - } - else - { - break; - } - of >> s; - while(1) //read groups for castle - { - if (s == "GROUP") - { - while(1) - { - of >> s; - if((s == "GROUP") || (s == "EOD") || (s == "CASTLE")) // - break; - buildingID = atoi(s.c_str()); - if(castleID>=0) - { - if((i = structures.begin() + castleID) != structures.end()) - if((i2=(i->find(buildingID)))!=(i->end())) - i2->second->group = itr; - else - tlog3 << "Warning3: No building "<begin(); i2!=i->end(); i2++) - { - if(i2->first == buildingID) - { - i2->second->group = itr; - break; - } - } + int group_num=0; + + // Iterate for each city + BOOST_FOREACH(const JsonNode &town_node, config["town_groups"].Vector()) { + townID = town_node["id"].Float(); + + // Iterate for each group for that city + BOOST_FOREACH(const JsonNode &group, town_node["groups"].Vector()) { + + group_num ++; + + // Iterate for each bulding value in the group + BOOST_FOREACH(const JsonNode &value, group.Vector()) { + int buildingID = value.Float(); + + std::vector >::iterator i; + std::map::iterator i2; + + if (townID >= 0) { + if ((i = structures.begin() + townID) != structures.end()) { + if ((i2=(i->find(buildingID)))!=(i->end())) + i2->second->group = group_num; + else + tlog3 << "Warning3: No building "<begin(); i2!=i->end(); i2++) { + if(i2->first == buildingID) { + i2->second->group = group_num; + break; } } } - if(s == "CASTLE") - break; - itr++; - }//if (s == "GROUP") - else if(s == "EOD") - break; + } } } - of.close(); - of.clear(); } } + const std::string & CTown::Name() const { if(name.length())