diff --git a/config/hall.json b/config/hall.json new file mode 100644 index 000000000..db15de54e --- /dev/null +++ b/config/hall.json @@ -0,0 +1,114 @@ +{ + // for each castle: + // id: town ID + // boxes: row buildings containing sets of ids for each box + "town": [ + { + "id": 0, + "image": "TPTHBKCS.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5, 22 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3 ], [ 6, 17 ] ], + [ [ 21 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 1, + "image": "TPTHBKRM.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 17, 21 ] ], + [ [ 22 ], [ 24, 25 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 2, + "image": "TPTHBKTW.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 22 ], [ 23 ] ], + [ [ 17 ], [ 21 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 3, + "image": "TPTHBKIN.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 23 ], [ 21 ] ], + [ [ 22 ], [ 18, 19 ], [ 24, 25 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 4, + "image": "TPTHBKNC.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 21 ], [ 6 ] ], + [ [ 17 ], [ 22 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 5, + "image": "TPTHBKDG.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 21 ], [ 22 ] ], + [ [ 17 ], [ 23 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 6, + "image": "TPTHBKTW.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2 ], [ 23 ], [ 17 ] ], + [ [ 21 ], [ 22 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 7, + "image": "TPTHBKFR.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2 ], [ 6 ] ], + [ [ 17 ], [ 21, 22 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + }, + + { + "id": 8, + "image": "TPTHBKFR.BMP", + "boxes": [ + [ [ 10, 11, 12, 13 ], [ 7, 8, 9 ], [ 5 ], [ 16 ] ], + [ [ 14, 15 ], [ 0, 1, 2, 3, 4 ], [ 6 ] ], + [ [ 21 ], [ 17 ], [ 18, 19 ] ], + [ [ 30, 37 ], [ 31, 38 ], [ 32, 39 ], [ 33, 40 ] ], + [ [ 34, 41 ], [ 35, 42 ], [ 36, 43 ] ] + ] + } + ] +} diff --git a/config/hall.txt b/config/hall.txt deleted file mode 100644 index 1c4fba00a..000000000 --- a/config/hall.txt +++ /dev/null @@ -1,75 +0,0 @@ -9 -0 -TPTHBKCS.BMP -10 11 12 13 | 7 8 9 | 5 22 | 16 -14 15 | 0 1 2 3 | 6 17 -21 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -1 -TPTHBKRM.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 17 21 -22 | 24 25 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -2 -TPTHBKTW.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 22 | 23 -17 | 21 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -3 -TPTHBKIN.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 23 | 21 -22 | 18 19 | 24 25 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -4 -TPTHBKNC.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 21 | 6 -17 | 22 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -5 -TPTHBKDG.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 21 | 22 -17 | 23 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -6 -TPTHBKTW.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 | 23 | 17 -21 | 22 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -7 -TPTHBKFR.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 | 6 -17 | 21 22 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 -8 -TPTHBKFR.BMP -10 11 12 13 | 7 8 9 | 5 | 16 -14 15 | 0 1 2 3 4 | 6 -21 | 17 | 18 19 -30 37 | 31 38 | 32 39 | 33 40 -34 41 | 35 42 | 36 43 - - -file format: -numberof castles -* for each castle: - castle ID - first row buildings (ids for each box, boxes are separated with '|') - sencond row buildings - etc... - - Warning: file is whitespace sensitive, don't add any spaces at end of the lines, or remove spaces between numbers and separators \ No newline at end of file diff --git a/lib/CBuildingHandler.cpp b/lib/CBuildingHandler.cpp index 88c8bf0f8..8fc5a10e6 100644 --- a/lib/CBuildingHandler.cpp +++ b/lib/CBuildingHandler.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include "../lib/JsonNode.h" extern CLodHandler * bitmaph; @@ -99,50 +101,33 @@ void CBuildingHandler::loadBuildings() } } /////done reading BUILDING.TXT***************************** + const JsonNode config(DATA_DIR "/config/hall.json"); - char line[100]; //bufor - std::ifstream ofs(DATA_DIR "/config/hall.txt"); - int castles; - ofs>>castles; - for(int i=0;i> tid >> pom; - hall[tid].first = pom; - (hall[tid].second).resize(5); //rows - for(int j=0;j<5;j++) - { - box = it = 0; - ofs.getline(line,100); - if(!line[0] || line[0] == '\n' || line[0] == '\r') - ofs.getline(line,100); - std::string linia(line); - bool areboxes=true; - while(areboxes) //read all boxes - { - (hall[tid].second)[j].push_back(std::vector()); //push new box - int seppos = linia.find_first_of('|',it); //position of end of this box data - if(seppos<0) - seppos = linia.length(); - while(it> last; - (hall[tid].second)[j][box].push_back(last); - areboxes = it; //wyzeruje jak nie znajdzie kolejnej spacji = koniec linii - if(!it) - it = seppos+1; - } - box++; - it+=2; - } - } - } + int tid = town["id"].Float(); + hall[tid].first = town["image"].String(); + (hall[tid].second).resize(5); //rows + + int row_num = 0; + BOOST_FOREACH(const JsonNode &row, town["boxes"].Vector()) + { + BOOST_FOREACH(const JsonNode &box, row.Vector()) + { + (hall[tid].second)[row_num].push_back(std::vector()); //push new box + std::vector &box_vec = (hall[tid].second)[row_num].back(); + + BOOST_FOREACH(const JsonNode &value, box.Vector()) + { + box_vec.push_back(value.Float()); + } + } + row_num ++; + } + + assert (row_num == 5); + } } CBuildingHandler::~CBuildingHandler()