1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Add building blit priorities in the json building file. Reorganized building coordinates processing code a little.

This commit is contained in:
Frank Zago 2011-08-20 06:08:48 +00:00
parent 6bbccaa76d
commit 8fa540b4da
3 changed files with 64 additions and 319 deletions

View File

@ -1,4 +1,9 @@
// Buildings coordinates inside a city, ordered by city type (0 to 8)
// Town properties, ordered by city type (0 to 8)
// defnames: Buildings coordinates inside a city
// blit_order: Buildings not mentioned in the file will be blitted first.
// Then buildings in the list will be drawn in that order.
{
"town_type":
[
@ -41,7 +46,10 @@
{ "id": 42, "defname": "TBCSUP_5.def", "x": 160, "y": 190 },
{ "id": 43, "defname": "TBCSUP_6.def", "x": 303, "y": 0 },
{ "id": 20, "defname": "TBCSBOAT.def", "x": 478, "y": 134 },
] },
],
"blit_order": [ 1, 2, 3, 10, 11, 12, 13, 5, 22, 30, 37, 16, 6, 20, 18, 19, 34, 41 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBRMBLAK.def", "x": 558, "y": 105 },
@ -86,7 +94,10 @@
{ "id": 13, "defname": "TBRMHAL4.def", "x": 534, "y": 187 },
{ "id": 12, "defname": "TBRMHAL3.def", "x": 538, "y": 187 },
{ "id": 11, "defname": "TBRMHAL2.def", "x": 538, "y": 187 },
], },
],
"blit_order": [ 33, 40, 35, 42, 16, 32, 39, 0, 1, 2, 3, 4, 31, 18, 38, 19, 34, 24, 41, 25, 5, 30, 37, 14, 10, 11, 12, 13, 17, 21, 22, -1, 27, 28, 29, 15 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBTWBLAK.def", "x": 478, "y": 211 },
@ -126,7 +137,9 @@
{ "id": 42, "defname": "TBTWUP_5.def", "x": 681, "y": 157 },
{ "id": 43, "defname": "TBTWUP_6.def", "x": 75, "y": 91 },
{ "id": 8, "defname": "TBTWCAS2.def", "x": 301, "y": 0 },
], },
],
"blit_order": [ 36, 43, 32, 39, 10, 11, 12, 13, 32, 35, 42, 15, 5, 18, 19 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBINBLAK.def", "x": 684, "y": 253 },
@ -167,7 +180,9 @@
{ "id": 42, "defname": "TBINUP_5.def", "x": 220, "y": 282 },
{ "id": 43, "defname": "TBINUP_6.def", "x": 420, "y": 105 },
{ "id": 8, "defname": "TBINCAS2.def", "x": 222, "y": 44 },
], },
],
"blit_order": [ 26, 21, 7, 8, 9, 22, 31, 38, 36, 43, 10, 11, 12, 13, 5, 32, 39, 24, 25, 33, 40, 34, 41, 30, 37, 18, 19, 14, 15, 16, 35, 42 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBNCBLAK.def", "x": 382, "y": 252 },
@ -212,7 +227,9 @@
{ "id": 42, "defname": "TBNCUP_5.def", "x": 0, "y": 30 },
{ "id": 43, "defname": "TBNCUP_6.def", "x": 662, "y": 23 },
{ "id": 20, "defname": "TBNCBOAT.def", "x": 617, "y": 265 },
], },
],
"blit_order": [ 17, 0, 1, 2, 3, 4, 7, 8, 9, 32, 39, 26, 15, 14, 34, 41, 16, 5, 33, 40, 31, 38, 6, 30, 18, 37, 19, 22, 20 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBDNBLAK.def", "x": 544, "y": 248 },
@ -252,7 +269,9 @@
{ "id": 42, "defname": "TBDNUP_5.def", "x": 270, "y": 253 },
{ "id": 43, "defname": "TBDNUP_6.def", "x": 550, "y": 0 },
{ "id": 8, "defname": "TBDNCAS2.def", "x": 363, "y": 87 },
], },
],
"blit_order": [ 0, 1, 2, 3, 4, 21, 35, 42, 5, 30, 18, 37, 19, 32, 39, 26, 7, 8, 9, 23 ]
},
{ "defnames": [
{ "id": 31, "defname": "TBSTDW_1.def", "x": 266, "y": 246 },
@ -291,7 +310,9 @@
{ "id": 41, "defname": "TBSTUP_4.def", "x": 129, "y": 15 },
{ "id": 42, "defname": "TBSTUP_5.def", "x": 616, "y": 93 },
{ "id": 16, "defname": "TBSTBLAK.def", "x": 660, "y": 286 },
], },
],
"blit_order": [ 33, 40, 30, 18, 37, 19, 31, 38, 23, 26, 5, 32, 39, 15, 14, 21, 16, 22 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBFRBLAK.def", "x": 360, "y": 160 },
@ -332,7 +353,9 @@
{ "id": 43, "defname": "TBFRUP_6.def", "x": 587, "y": 263 },
{ "id": 29, "defname": "TBFRWTRW.def", "x": 320, "y": 141 },
{ "id": 20, "defname": "TBFRBOAT.def", "x": 197, "y": 294 },
], },
],
"blit_order": [ 16, 15, 14, 34, 41, 31, 38, 10, 11, 12, 13, 29, 0, 1, 2, 33, 40, 30, 18, 37, 19, 5, 36, 43, 26 ]
},
{ "defnames": [
{ "id": 16, "defname": "TBELBLAK.def", "x": 449, "y": 151 },
@ -377,6 +400,8 @@
{ "id": 42, "defname": "TBELUP_5.def", "x": 394, "y": 283 },
{ "id": 43, "defname": "TBELUP_6.def", "x": 43, "y": 0 },
{ "id": 20, "defname": "TBELBOAT.def", "x": 239, "y": 215 }
] ]
],
"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 ]
}
]
}

View File

@ -1,268 +0,0 @@
0 0
CASTLE 0
0
1
2
3
10
11
12
13
5
22
30
37
16
6
20
18
19
34
41
END
CASTLE 1
33
40
35
42
16
32
39
0
1
2
3
4
31
18
38
19
34
24
41
25
5
30
37
14
10
11
12
13
17
21
22
-1
27
28
29
15
END
CASTLE 2
36
43
32
39
10
11
12
13
32
35
42
15
5
18
19
END
CASTLE 3
26
21
7
8
9
22
31
38
36
43
10
11
12
13
5
32
39
24
25
33
40
34
41
30
37
18
19
14
15
16
35
42
END
CASTLE 4
17
0
1
2
3
4
7
8
9
32
39
26
15
14
34
41
16
5
33
40
31
38
6
30
18
37
19
22
20
END
CASTLE 5
0
1
2
3
4
21
35
42
5
30
18
37
19
32
39
26
7
8
9
23
END
CASTLE 6
33
40
30
18
37
19
31
38
23
26
5
32
39
15
14
21
16
22
END
CASTLE 7
16
15
14
34
41
31
38
10
11
12
13
29
0
1
2
33
40
30
18
37
19
5
36
43
26
END
CASTLE 8
-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
END
EOD
------------------------------------------------------------------
//File format:
0 0 //for further use - format version and ID mode
CASTLE [Castle ID]
[ID] //Building showed on the top (blitted later)
[ID] //Building showed later...
...
[ID] //even later...
END //end of buildings for this castle
[...] //info for more castles
EOD
Buildings not mentioned in the file will be blitted as first. File can contain data for any count of castles.

View File

@ -130,65 +130,53 @@ void CTownHandler::loadStructures()
structures.resize(F_NUMBER);
//read buildings coords
// read city properties
const JsonNode config(DATA_DIR "/config/buildings.json");
const JsonVector &vector1 = config["town_type"].Vector();
int townid=0;
const JsonVector &town_type_vec = config["town_type"].Vector();
int townID=0;
for (JsonVector::const_iterator it = vector1.begin(); it!=vector1.end(); ++it, ++townid) {
// Iterate for each city type
for (JsonVector::const_iterator it = town_type_vec.begin(); it!=town_type_vec.end(); ++it, ++townID) {
std::map<int, Structure*> &town = structures[townID];
const JsonNode &node = *it;
const JsonVector &vector2 = node["defnames"].Vector();
const JsonVector &defnames_vec = node["defnames"].Vector();
for (JsonVector::const_iterator it2 = vector2.begin(); it2!=vector2.end(); ++it2) {
// Read buildings coordinates for that city
for (JsonVector::const_iterator it2 = defnames_vec.begin(); it2!=defnames_vec.end(); ++it2) {
const JsonNode &ai = *it2;
Structure *vinya = new Structure;
vinya->group = -1;
vinya->townID = townid;
vinya->townID = townID;
vinya->ID = ai["id"].Float();
vinya->defName = ai["defname"].String();
vinya->name = vinya->defName; //TODO - use normal names
vinya->pos.x = ai["x"].Float();
vinya->pos.y = ai["y"].Float();
vinya->pos.z = 0;
structures[vinya->townID][vinya->ID] = vinya;
town[vinya->ID] = vinya;
}
// Read buildings blit order for that city
const JsonVector &blit_order_vec = node["blit_order"].Vector();
int itr = 1;
for (JsonVector::const_iterator it2 = blit_order_vec.begin(); it2!=blit_order_vec.end(); ++it2) {
const JsonNode &ai = *it2;
int buildingID = ai.Float();
/* Find the building and set its order. */
std::map<int, Structure*>::iterator i2 = town.find(buildingID);
if (i2 != (town.end()))
i2->second->pos.z = itr++;
else
tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl;
}
}
//read building priorities
of.open(DATA_DIR "/config/buildings2.txt");
int format, idt;
std::string s;
of >> format >> idt;
while(!of.eof())
{
std::vector<std::map<int, Structure*> >::iterator i;
std::map<int, Structure*>::iterator i2;
int itr=1, buildingID;
int castleID;
of >> s;
if (s != "CASTLE")
break;
of >> castleID;
while(1)
{
of >> s;
if (s == "END")
break;
else
if( (i=structures.begin() + castleID) != structures.end() )
if( (i2 = i->find( buildingID = atoi(s.c_str()) )) != (i->end()) )
i2->second->pos.z=itr++;
else
tlog3 << "Warning1: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
else
tlog3 << "Warning1: Castle "<<castleID<<" not defined."<<std::endl;
}
}
of.close();
of.clear();
//read borders and areas names
int format;
std::string s;
of.open(DATA_DIR "/config/buildings3.txt");
while(!of.eof())
{