2
0
Эх сурвалжийг харах

Created terrains.json from native_terrains.txt and TERCOSTS.TXT.

Frank Zago 14 жил өмнө
parent
commit
bcce343b6c

+ 0 - 10
config/TERCOSTS.TXT

@@ -1,10 +0,0 @@
-9
-10 100 150 100 150 175 125 100 100 100 -1
-10 100 150 100 150 175 125 100 100 100 -1
-10 100 150 100 100 175 125 100 100 100 -1
-10 100 150 100 150 175 125 100 100 100 -1
-10 100 150 100 150 175 125 100 100 100 -1
-10 100 150 100 150 175 125 100 100 100 -1
-10 100 150 100 150 175 100 100 100 100 -1
-10 100 150 100 150 100 125 100 100 100 -1
-10 100 150 100 150 175 125 100 100 100 -1

+ 0 - 11
config/native_terrains.txt

@@ -1,11 +0,0 @@
-//list of native terrains of different factions
-//[faction ID] [terrain ID]
-0 2
-1 2
-2 3
-3 7
-4 0
-5 6
-6 5
-7 4
-8 2

+ 52 - 0
config/terrains.json

@@ -0,0 +1,52 @@
+{
+	// Terrains properties related to heroes - ordered by faction (0 to 8)
+	//   cost: ??
+	//   native: native terrain for the faction
+
+	"terrains": [
+		{
+			"costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 2
+		},
+
+		{
+			"costs": [ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 2
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 100, 175, 125, 100, 100, 100, -1 ],
+			"native": 3
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 7
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 0
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 6
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 175, 100, 100, 100, 100, -1 ],
+			"native": 5
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 100, 125, 100, 100, 100, -1 ],
+			"native": 4
+		},
+
+		{
+			"costs": 	[ 100, 150, 100, 150, 175, 125, 100, 100, 100, -1 ],
+			"native": 2
+		}
+	]
+}

+ 16 - 44
lib/CHeroHandler.cpp

@@ -421,8 +421,8 @@ void CHeroHandler::initHeroClasses()
 	{
 		heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
 	}
-	initTerrainCosts();
-	loadNativeTerrains();
+
+	loadTerrains();
 }
 
 unsigned int CHeroHandler::level (ui64 experience) const
@@ -458,56 +458,28 @@ ui64 CHeroHandler::reqExp (unsigned int level) const
 	}
 }
 
-void CHeroHandler::initTerrainCosts()
+void CHeroHandler::loadTerrains()
 {
-	std::ifstream inp;
-	inp.open(DATA_DIR "/config/TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary);
+	int faction = 0;
+	const JsonNode config(DATA_DIR "/config/terrains.json");
 
-	if(!inp.is_open())
-	{
-		tlog1 << "Error while opening config/TERCOSTS.TXT file!" << std::endl;
-	}
+	nativeTerrains.resize(F_NUMBER);
 
-	int tynum;
-	inp>>tynum;
-	for(int i=0; i<2*tynum; i+=2)
-	{
-		int catNum;
-		inp>>catNum;
-		for(int k=0; k<catNum; ++k)
-		{
-			int curCost;
-			inp>>curCost;
-			heroClasses[i]->terrCosts.push_back(curCost);
-			heroClasses[i+1]->terrCosts.push_back(curCost);
+	BOOST_FOREACH(const JsonNode &terrain, config["terrains"].Vector()) {
+
+		BOOST_FOREACH(const JsonNode &cost, terrain["costs"].Vector()) {
+			int curCost = cost.Float();
+
+			heroClasses[2*faction]->terrCosts.push_back(curCost);
+			heroClasses[2*faction+1]->terrCosts.push_back(curCost);
 		}
-	}
-	inp.close();
-}
 
-void CHeroHandler::loadNativeTerrains()
-{
-	std::ifstream inp;
-	inp.open(DATA_DIR "/config/native_terrains.txt", std::ios_base::in|std::ios_base::binary);
+		nativeTerrains[faction] = terrain["native"].Float();
 
-	if(!inp.is_open())
-	{
-		tlog1 << "Error while opening config/native_terrains.txt file!" << std::endl;
+		faction ++;
 	}
-	const int MAX_ELEM = 1000;
-	char buf[MAX_ELEM+1];
-	inp.getline(buf, MAX_ELEM);
-	inp.getline(buf, MAX_ELEM);
 
-	nativeTerrains.resize(F_NUMBER);
-	for(int i=0; i<F_NUMBER; ++i)
-	{
-		int faction, terrain;
-		inp >> faction;
-		inp >> terrain;
-		nativeTerrains[faction] = terrain;
-	}
-	inp.close();
+	assert(faction == F_NUMBER);
 }
 
 CHero::CHero()

+ 1 - 2
lib/CHeroHandler.h

@@ -155,8 +155,7 @@ public:
 	void loadHeroes();
 	void loadHeroClasses();
 	void initHeroClasses();
-	void initTerrainCosts();
-	void loadNativeTerrains();
+	void loadTerrains();
 	CHeroHandler(); //c-tor
 	~CHeroHandler(); //d-tor