浏览代码

Integrate buildings4.txt into buildings.json. It's ligthly tested because I can't find what this file is supposed to define.

Frank Zago 14 年之前
父节点
当前提交
b114047738
共有 3 个文件被更改,包括 122 次插入188 次删除
  1. 85 2
      config/buildings.json
  2. 0 111
      config/buildings4.txt
  3. 37 75
      lib/CTownHandler.cpp

+ 85 - 2
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 ]
+				],
+			}
+		]
+}	

+ 0 - 111
config/buildings4.txt

@@ -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

+ 37 - 75
lib/CTownHandler.cpp

@@ -6,6 +6,7 @@
 #include "../lib/VCMI_Lib.h"
 #include "CGeneralTextHandler.h"
 #include "../lib/JsonNode.h"
+#include <boost/foreach.hpp>
 
 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<std::map<int, Structure*> >::iterator i;
-			std::map<int, Structure*>::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 "<<buildingID<<" in the castle "<<castleID<<std::endl;
-							else
-								tlog3 << "Warning3: Castle "<<castleID<<" not defined."<<std::endl;
-						}
-						else //set group for selected building in ALL castles
-						{
-							for(i=structures.begin();i!=structures.end();i++)
-							{
-								for(i2=i->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<std::map<int, Structure*> >::iterator i;
+				std::map<int, Structure*>::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 "<<buildingID<<" in the castle "<<townID<<std::endl;
+					} 
+					else
+						tlog3 << "Warning3: Castle "<<townID<<" not defined."<<std::endl;
+				} else {
+					// Set group for selected building in ALL castles
+					for (i=structures.begin();i!=structures.end();i++) {
+						for(i2=i->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())