瀏覽代碼

Move CTownHandler::loadStructures inside CTownHandler::loadNames and rename the latter with the former.

Frank Zago 14 年之前
父節點
當前提交
1a2323996e
共有 3 個文件被更改,包括 88 次插入97 次删除
  1. 87 95
      lib/CTownHandler.cpp
  2. 0 1
      lib/CTownHandler.h
  3. 1 1
      lib/VCMI_Lib.cpp

+ 87 - 95
lib/CTownHandler.cpp

@@ -31,120 +31,33 @@ CTownHandler::~CTownHandler()
 		for( std::map<int, Structure*>::iterator j = i->begin(); j!=i->end(); j++)
 			delete j->second;
 }
-void CTownHandler::loadNames()
+void CTownHandler::loadStructures()
 {
 	int si, itr;
 	char bufname[75];
-	for (si=0; si<F_NUMBER; si++)
+	int townID;
+
+	for (townID=0; townID<F_NUMBER; townID++)
 	{
 		CTown town;
-		town.typeID=si;
+		town.typeID=townID;
 		town.bonus=towns.size();
 		if (town.bonus==8) town.bonus=3;
 		towns.push_back(town);
 	}
 
-	loadStructures();
-
-
-	std::ifstream of;
-	for(int x=0;x<towns.size();x++)
-		towns[x].basicCreatures.resize(7);
-
-	of.open(DATA_DIR "/config/basicCres.txt");
-	while(!of.eof())
-	{
-		int tid, lid, cid; //town,level,creature
-		of >> tid >> lid >> cid;
-		if(lid < towns[tid].basicCreatures.size())
-			towns[tid].basicCreatures[lid]=cid;
-	}
-	of.close();
-	of.clear();
-
-	for(int x=0;x<towns.size();x++)
-		towns[x].upgradedCreatures.resize(7);
-
-	of.open(DATA_DIR "/config/creatures_upgr.txt");
-	while(!of.eof())
-	{
-		int tid, lid, cid; //town,level,creature
-		of >> tid >> lid >> cid;
-		if(lid < towns[tid].upgradedCreatures.size())
-			towns[tid].upgradedCreatures[lid]=cid;
-	}
-	of.close();
-	of.clear();
-
-	of.open(DATA_DIR "/config/building_horde.txt");
-	while(!of.eof())
-	{
-		int tid, lid, cid; //town,horde serial,creature level
-		of >> tid >> lid >> cid;
-		towns[tid].hordeLvl[--lid] = cid;
-	}
-	of.close();
-	of.clear();
-
-	of.open(DATA_DIR "/config/mageLevel.txt");
-	of >> si;
-	for(itr=0; itr<si; itr++)
-	{
-		of >> towns[itr].mageLevel >> towns[itr].primaryRes >> towns[itr].warMachine;
-	}
-	of.close();
-	of.clear();
-
-	of.open(DATA_DIR "/config/requirements.txt");
-	requirements.resize(F_NUMBER);
-	while(!of.eof())
-	{
-		int ile, town, build, pom;
-		of >> ile;
-		for(int i=0;i<ile;i++)
-		{
-			of >> town;
-			while(true)
-			{
-				of.getline(bufname,75);
-				if(!bufname[0] || bufname[0] == '\n' || bufname[0] == '\r')
-					of.getline(bufname,75);
-				std::istringstream ifs(bufname);
-				ifs >> build;
-				if(build<0)
-					break;
-				while(!ifs.eof())
-				{
-					ifs >> pom;
-					requirements[town][build].insert(pom);
-				}
-			}
-		}
-	}
-	of.close();
-	of.clear();
-}
-
-void CTownHandler::loadStructures()
-{
-	std::ifstream of;
-
 	structures.resize(F_NUMBER);
 
 	// read city properties
 	const JsonNode config(DATA_DIR "/config/buildings.json");
-	const JsonVector &town_type_vec = config["town_type"].Vector();
-	int townID=0;
 
 	// Iterate for each city type
-	for (JsonVector::const_iterator it = town_type_vec.begin(); it!=town_type_vec.end(); ++it, ++townID) {
+	townID = 0;
+	BOOST_FOREACH(const JsonNode &town_node, config["town_type"].Vector()) {
 		std::map<int, Structure*> &town = structures[townID];
-		const JsonNode &town_node = *it;
-		const JsonVector &defnames_vec = town_node["defnames"].Vector();
 
 		// Read buildings coordinates for that city
-		for (JsonVector::const_iterator it2 = defnames_vec.begin(); it2!=defnames_vec.end(); ++it2) {
-			const JsonNode &node = *it2;
+		BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) {
 			Structure *vinya = new Structure;
 			const JsonNode *value;
 
@@ -183,6 +96,8 @@ void CTownHandler::loadStructures()
 			else
 				tlog3 << "Warning1: No building " << buildingID << " in the castle " << townID << std::endl;
 		}
+
+		townID ++;
 	}
 
 	int group_num=0;
@@ -226,6 +141,83 @@ void CTownHandler::loadStructures()
 			}
 		}
 	}
+
+	std::ifstream of;
+	for(int x=0;x<towns.size();x++)
+		towns[x].basicCreatures.resize(7);
+
+	of.open(DATA_DIR "/config/basicCres.txt");
+	while(!of.eof())
+	{
+		int tid, lid, cid; //town,level,creature
+		of >> tid >> lid >> cid;
+		if(lid < towns[tid].basicCreatures.size())
+			towns[tid].basicCreatures[lid]=cid;
+	}
+	of.close();
+	of.clear();
+
+	for(int x=0;x<towns.size();x++)
+		towns[x].upgradedCreatures.resize(7);
+
+	of.open(DATA_DIR "/config/creatures_upgr.txt");
+	while(!of.eof())
+	{
+		int tid, lid, cid; //town,level,creature
+		of >> tid >> lid >> cid;
+		if(lid < towns[tid].upgradedCreatures.size())
+			towns[tid].upgradedCreatures[lid]=cid;
+	}
+	of.close();
+	of.clear();
+
+	of.open(DATA_DIR "/config/building_horde.txt");
+	while(!of.eof())
+	{
+		int tid, lid, cid; //town,horde serial,creature level
+		of >> tid >> lid >> cid;
+		towns[tid].hordeLvl[--lid] = cid;
+	}
+	of.close();
+	of.clear();
+
+	of.open(DATA_DIR "/config/mageLevel.txt");
+	of >> si;
+	for(itr=0; itr<si; itr++)
+	{
+		of >> towns[itr].mageLevel >> towns[itr].primaryRes >> towns[itr].warMachine;
+	}
+	of.close();
+	of.clear();
+
+	of.open(DATA_DIR "/config/requirements.txt");
+	requirements.resize(F_NUMBER);
+	while(!of.eof())
+	{
+		int ile, town, build, pom;
+		of >> ile;
+		for(int i=0;i<ile;i++)
+		{
+			of >> town;
+			while(true)
+			{
+				of.getline(bufname,75);
+				if(!bufname[0] || bufname[0] == '\n' || bufname[0] == '\r')
+					of.getline(bufname,75);
+				std::istringstream ifs(bufname);
+				ifs >> build;
+				if(build<0)
+					break;
+				while(!ifs.eof())
+				{
+					ifs >> pom;
+					requirements[town][build].insert(pom);
+				}
+			}
+		}
+	}
+	of.close();
+	of.clear();
 }
 
 const std::string & CTown::Name() const

+ 0 - 1
lib/CTownHandler.h

@@ -69,7 +69,6 @@ public:
 
 	CTownHandler(); //c-tor
 	~CTownHandler(); //d-tor
-	void loadNames();
 	void loadStructures();
 
 	template <typename Handler> void serialize(Handler &h, const int version)

+ 1 - 1
lib/VCMI_Lib.cpp

@@ -190,7 +190,7 @@ void LibClasses::init()
 	tlog0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
 
 	townh = new CTownHandler;
-	townh->loadNames();
+	townh->loadStructures();
 	tlog0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
 
 	objh = new CObjectHandler;