Browse Source

Fixed game startup

Ivan Savenko 2 năm trước cách đây
mục cha
commit
2de3178158

+ 3 - 0
config/defaultMods.json

@@ -10,6 +10,9 @@
 		"hero"       : 156,
 		"spell"      : 81,
 		"object"     : 256,
+		"terrain"    : 10,
+		"river"      : 5,
+		"road"       : 4,
 		"mapVersion" : 28 // max supported version, SoD
 	},
 

+ 5 - 5
config/rivers.json

@@ -1,30 +1,30 @@
 {
     "waterRiver":
     {
-        "originalRiverId": 1,
+        "index": 1,
         "code": "rw", //must be 2 characters
         "animation": "clrrvr",
         "delta": "clrdelt"
     },
     "iceRiver":
     {
-        "originalRiverId": 2,
+        "index": 2,
         "code": "ri",
         "animation": "icyrvr",
         "delta": "icedelt"
     },
     "mudRiver":
     {
-        "originalRiverId": 3,
+        "index": 3,
         "code": "rm",
         "animation": "mudrvr",
         "delta": "muddelt"
     },
     "lavaRiver":
     {
-        "originalRiverId": 4,
+        "index": 4,
         "code": "rl",
         "animation": "lavrvr",
         "delta": "lavdelt"
     }
-}
+}

+ 4 - 4
config/roads.json

@@ -1,23 +1,23 @@
 {
     "dirtRoad":
     {
-        "originalRoadId": 1,
+        "index": 1,
         "code": "pd", //must be 2 characters
         "animation": "dirtrd",
         "moveCost": 75
     },
     "gravelRoad":
     {
-        "originalRoadId": 2,
+        "index": 2,
         "code": "pg",
         "animation": "gravrd",
         "moveCost": 65
     },
     "cobblestoneRoad":
     {
-        "originalRoadId": 3,
+        "index": 3,
         "code": "pc",
         "animation": "cobbrd",
         "moveCost": 50
     }
-}
+}

+ 3 - 3
config/terrains.json

@@ -88,7 +88,7 @@
 		"minimapBlocked"   : [  90,  8, 0 ],
 		"music" : "Underground.mp3",
 		"tiles" : "SUBBTL",
-		"type" : "SUB",
+		"type" : [ "SUB" ],
 		"code" : "sb",
 		"river" : "rw",
 		"battleFields" : ["subterranean"],
@@ -118,7 +118,7 @@
 		"minimapBlocked"   : [ 8, 81, 148 ],
 		"music" : "Water.mp3",
 		"tiles" : "WATRTL",
-		"type" : "WATER",
+		"type" : [ "WATER" ],
 		"code" : "wt",
 		"battleFields" : ["ship"],
 		"transitionRequired" : true,
@@ -136,7 +136,7 @@
 		"minimapBlocked"   : [ 0, 0, 0 ],
 		"music" : "Underground.mp3", // Impossible in H3
 		"tiles" : "ROCKTL",
-		"type" : "ROCK",
+		"type" : [ "ROCK" ],
 		"code" : "rc",
 		"battleFields" : ["rocklands"],
 		"transitionRequired" : true,

+ 1 - 1
lib/GameConstants.h

@@ -1226,7 +1226,7 @@ enum class ETerrainId {
 	WRONG = -2,
 	BORDER = -1,
 	FIRST_REGULAR_TERRAIN = 0,
-	DIRT,
+	DIRT = 0,
 	SAND,
 	GRASS,
 	SNOW,

+ 16 - 3
lib/Terrain.cpp

@@ -12,6 +12,7 @@
 #include "Terrain.h"
 #include "VCMI_Lib.h"
 #include "CModHandler.h"
+#include "CGeneralTextHandler.h"
 
 VCMI_LIB_NAMESPACE_BEGIN
 
@@ -99,8 +100,7 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
 
 	if(!json["rockTerrain"].isNull())
 	{
-		auto rockTerrainName = json["rockTerrain"].String();
-		VLC->modh->identifiers.requestIdentifier("terrain", rockTerrainName, [info](int32_t identifier)
+		VLC->modh->identifiers.requestIdentifier("terrain", json["rockTerrain"], [info](int32_t identifier)
 		{
 			info->rockTerrain = TerrainId(identifier);
 		});
@@ -117,7 +117,20 @@ const std::vector<std::string> & TerrainTypeHandler::getTypeNames() const
 
 std::vector<JsonNode> TerrainTypeHandler::loadLegacyData(size_t dataSize)
 {
-	return {};
+	objects.resize(dataSize);
+
+	CLegacyConfigParser terrainParser("DATA/TERRNAME.TXT");
+
+	std::vector<JsonNode> result;
+	do
+	{
+		JsonNode terrain;
+		terrain["text"].String() = terrainParser.readString();
+		result.push_back(terrain);
+	}
+	while (terrainParser.endLine());
+
+	return result;
 }
 
 std::vector<bool> TerrainTypeHandler::getDefaultAllowed() const

+ 11 - 24
lib/mapObjects/ObjectTemplate.cpp

@@ -165,14 +165,7 @@ void ObjectTemplate::readTxt(CLegacyConfigParser & parser)
 	}
 	
 	//assuming that object can be placed on other land terrains
-	if(allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER))
-	{
-		for(const auto & terrain : VLC->terrainTypeHandler->objects)
-		{
-			if(terrain->isLand() && terrain->isPassable())
-				allowedTerrains.insert(terrain->id);
-		}
-	}
+	anyTerrain = allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER);
 
 	id    = Obj(boost::lexical_cast<int>(strings[5]));
 	subid = boost::lexical_cast<int>(strings[6]);
@@ -238,14 +231,7 @@ void ObjectTemplate::readMap(CBinaryReader & reader)
 	}
 	
 	//assuming that object can be placed on other land terrains
-	if(allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER))
-	{
-		for(const auto & terrain : VLC->terrainTypeHandler->objects)
-		{
-			if(terrain->isLand() && terrain->isPassable())
-				allowedTerrains.insert(terrain->id);
-		}
-	}
+	anyTerrain = allowedTerrains.size() >= 8 && !allowedTerrains.count(ETerrainId::WATER);
 
 	id = Obj(reader.readUInt32());
 	subid = reader.readUInt32();
@@ -292,15 +278,11 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain)
 				allowedTerrains.insert(TerrainId(identifier));
 			});
 		}
+		anyTerrain = false;
 	}
 	else
 	{
-		for(const auto & terrain : VLC->terrainTypeHandler->objects)
-		{
-			if(!terrain->isPassable() || terrain->isWater())
-				continue;
-			allowedTerrains.insert(terrain->id);
-		}
+		anyTerrain = true;
 	}
 
 	if(withTerrain && allowedTerrains.empty())
@@ -561,9 +543,14 @@ void ObjectTemplate::calculateVisitableOffset()
 	visitableOffset = int3(0, 0, 0);
 }
 
-bool ObjectTemplate::canBePlacedAt(TerrainId terrain) const
+bool ObjectTemplate::canBePlacedAt(TerrainId terrainID) const
 {
-	return vstd::contains(allowedTerrains, terrain);
+	if (anyTerrain)
+	{
+		auto const & terrain = VLC->terrainTypeHandler->getById(terrainID);
+		return terrain->isLand() && terrain->isPassable();
+	}
+	return vstd::contains(allowedTerrains, terrainID);
 }
 
 void ObjectTemplate::recalculate()

+ 3 - 0
lib/mapObjects/ObjectTemplate.h

@@ -35,6 +35,9 @@ class DLL_LINKAGE ObjectTemplate
 	/// list of terrains on which this object can be placed
 	std::set<TerrainId> allowedTerrains;
 
+	/// or, allow placing object on any terrain
+	bool anyTerrain;
+
 	void afterLoadFixup();
 
 public:

+ 4 - 2
lib/rmg/CRmgTemplate.cpp

@@ -377,8 +377,10 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
 				terrainTypes.clear();
 				for(auto ttype : node.Vector())
 				{
-					auto identifier = VLC->modh->identifiers.getIdentifier("terrain", ttype);
-					terrainTypes.emplace(*identifier);
+					VLC->modh->identifiers.requestIdentifier("terrain", ttype, [this](int32_t identifier)
+					{
+						terrainTypes.emplace(identifier);
+					});
 				}
 			}
 		}