Explorar o código

Changed logic for zone placement.

Now every zone can be surface, underground, or both. This is separate from water <-> land distinction.

Iand type is now a combination of flags and can take multiple values: "type": ["LAND", "WATER", "SURFACE", "SUB", "ROCK"]. In nothing is specified, terrains get LAND | SURFACE flags by default.

Non-surface zones will default to DIRT, and non-underground zones will default to SUBTERRA.
Tomasz Zieliński %!s(int64=3) %!d(string=hai) anos
pai
achega
6aaf77812b

+ 0 - 5
config/randomMap.json

@@ -1,9 +1,4 @@
 {
 {
-  "terrain" :
-  {
-    "undergroundAllow" : ["lava"], //others to be replaced by subterranena
-    "groundProhibit" : ["subterra"] //to be replaced by dirt
-  },
   "waterZone" :
   "waterZone" :
   {
   {
     "treasure" :
     "treasure" :

+ 1 - 1
config/terrains.json

@@ -103,7 +103,7 @@
 		"minimapBlocked"   : [ 41, 40, 41 ],
 		"minimapBlocked"   : [ 41, 40, 41 ],
 		"music" : "Lava.mp3",
 		"music" : "Lava.mp3",
 		"tiles" : "LAVATL",
 		"tiles" : "LAVATL",
-		"type" : "SUB",
+		"type" : ["SUB", "SURFACE"],
 		"code" : "lv",
 		"code" : "lv",
 		"river" : "rl",
 		"river" : "rl",
 		"battleFields" : ["lava"],
 		"battleFields" : ["lava"],

+ 29 - 10
lib/Terrain.cpp

@@ -57,15 +57,29 @@ TerrainTypeHandler::TerrainTypeHandler()
 			
 			
 			if(terr.second["type"].isNull())
 			if(terr.second["type"].isNull())
 			{
 			{
-				info->passabilityType = TerrainType::PassabilityType::LAND;
+				info->passabilityType = TerrainType::PassabilityType::LAND | TerrainType::PassabilityType::SURFACE;
 			}
 			}
-			else
+			else if (terr.second["type"].getType() == JsonNode::JsonType::DATA_VECTOR)
+			{
+				for (const auto& node : terr.second["type"].Vector())
+				{
+					//Set bits
+					auto s = node.String();
+					if (s == "LAND") info->passabilityType |= TerrainType::PassabilityType::LAND;
+					if (s == "WATER") info->passabilityType |= TerrainType::PassabilityType::WATER;
+					if (s == "ROCK") info->passabilityType |= TerrainType::PassabilityType::ROCK;
+					if (s == "SURFACE") info->passabilityType |= TerrainType::PassabilityType::SURFACE;
+					if (s == "SUB") info->passabilityType |= TerrainType::PassabilityType::SUBTERRANEAN;
+				}
+			}
+			else  //should be string - one option only
 			{
 			{
 				auto s = terr.second["type"].String();
 				auto s = terr.second["type"].String();
-				if(s == "LAND") info->passabilityType = TerrainType::PassabilityType::LAND;
-				if(s == "WATER") info->passabilityType = TerrainType::PassabilityType::WATER;
-				if(s == "ROCK") info->passabilityType = TerrainType::PassabilityType::ROCK;
-				if(s == "SUB") info->passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
+				if (s == "LAND") info->passabilityType = TerrainType::PassabilityType::LAND;
+				if (s == "WATER") info->passabilityType = TerrainType::PassabilityType::WATER;
+				if (s == "ROCK") info->passabilityType = TerrainType::PassabilityType::ROCK;
+				if (s == "SURFACE") info->passabilityType = TerrainType::PassabilityType::SURFACE;
+				if (s == "SUB") info->passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
 			}
 			}
 			
 			
 			if(terr.second["rockTerrain"].isNull())
 			if(terr.second["rockTerrain"].isNull())
@@ -223,7 +237,7 @@ TerrainType::TerrainType(const std::string& _name):
 	rockTerrain(Terrain::ROCK),
 	rockTerrain(Terrain::ROCK),
 	moveCost(100),
 	moveCost(100),
 	horseSoundId(0),
 	horseSoundId(0),
-	passabilityType(PassabilityType::LAND),
+	passabilityType(0),
 	transitionRequired(false)
 	transitionRequired(false)
 {
 {
 }
 }
@@ -257,17 +271,22 @@ bool TerrainType::isLand() const
 
 
 bool TerrainType::isWater() const
 bool TerrainType::isWater() const
 {
 {
-	return passabilityType == PassabilityType::WATER;
+	return passabilityType & PassabilityType::WATER;
 }
 }
 
 
 bool TerrainType::isPassable() const
 bool TerrainType::isPassable() const
 {
 {
-	return passabilityType != PassabilityType::ROCK;
+	return !(passabilityType & PassabilityType::ROCK);
+}
+
+bool TerrainType::isSurface() const
+{
+	return passabilityType & PassabilityType::SURFACE;
 }
 }
 
 
 bool TerrainType::isUnderground() const
 bool TerrainType::isUnderground() const
 {
 {
-	return passabilityType == PassabilityType::SUBTERRANEAN;
+	return passabilityType & PassabilityType::SUBTERRANEAN;
 }
 }
 
 
 bool TerrainType::isTransitionRequired() const
 bool TerrainType::isTransitionRequired() const

+ 9 - 7
lib/Terrain.h

@@ -19,12 +19,13 @@ class DLL_LINKAGE TerrainType
 {
 {
 public:
 public:
 	
 	
-	enum class PassabilityType
+	enum PassabilityType : ui8
 	{
 	{
-		LAND,
-		WATER,
-		SUBTERRANEAN,
-		ROCK
+		LAND = 1,
+		WATER = 2,
+		SURFACE = 4,
+		SUBTERRANEAN = 8,
+		ROCK = 16
 	};
 	};
 	
 	
 	std::vector<std::string> battleFields;
 	std::vector<std::string> battleFields;
@@ -43,7 +44,7 @@ public:
 	TTerrain rockTerrain;
 	TTerrain rockTerrain;
 	int moveCost;
 	int moveCost;
 	int horseSoundId;
 	int horseSoundId;
-	PassabilityType passabilityType;
+	ui8 passabilityType;
 	bool transitionRequired;
 	bool transitionRequired;
 	
 	
 	TerrainType(const std::string & name = "");
 	TerrainType(const std::string & name = "");
@@ -56,7 +57,8 @@ public:
 	
 	
 	bool isLand() const;
 	bool isLand() const;
 	bool isWater() const;
 	bool isWater() const;
-	bool isPassable() const; //ROCK
+	bool isPassable() const;
+	bool isSurface() const;
 	bool isUnderground() const;
 	bool isUnderground() const;
 	bool isTransitionRequired() const;
 	bool isTransitionRequired() const;
 		
 		

+ 1 - 10
lib/rmg/CMapGenerator.cpp

@@ -46,16 +46,7 @@ void CMapGenerator::loadConfig()
 {
 {
 	static const ResourceID path("config/randomMap.json");
 	static const ResourceID path("config/randomMap.json");
 	JsonNode randomMapJson(path);
 	JsonNode randomMapJson(path);
-	for(auto& s : randomMapJson["terrain"]["undergroundAllow"].Vector())
-	{
-		if(!s.isNull())
-			config.terrainUndergroundAllowed.emplace_back(VLC->terrainTypeHandler->getInfoByName(s.String())->id);
-	}
-	for(auto& s : randomMapJson["terrain"]["groundProhibit"].Vector())
-	{
-		if(!s.isNull())
-			config.terrainGroundProhibit.emplace_back(VLC->terrainTypeHandler->getInfoByName(s.String())->id);
-	}
+
 	config.shipyardGuard = randomMapJson["waterZone"]["shipyard"]["value"].Integer();
 	config.shipyardGuard = randomMapJson["waterZone"]["shipyard"]["value"].Integer();
 	for(auto & treasure : randomMapJson["waterZone"]["treasure"].Vector())
 	for(auto & treasure : randomMapJson["waterZone"]["treasure"].Vector())
 	{
 	{

+ 0 - 2
lib/rmg/CMapGenerator.h

@@ -32,8 +32,6 @@ class DLL_LINKAGE CMapGenerator: public Load::Progress
 public:
 public:
 	struct Config
 	struct Config
 	{
 	{
-		std::vector<TTerrain> terrainUndergroundAllowed;
-		std::vector<TTerrain> terrainGroundProhibit;
 		std::vector<CTreasureInfo> waterTreasure;
 		std::vector<CTreasureInfo> waterTreasure;
 		int shipyardGuard;
 		int shipyardGuard;
 		int mineExtraResources;
 		int mineExtraResources;

+ 3 - 2
lib/rmg/CZonePlacer.cpp

@@ -198,9 +198,10 @@ void CZonePlacer::prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const
 					}
 					}
 					else
 					else
 					{
 					{
-						if(VLC->terrainTypeHandler->terrains()[tt]->isUnderground())
+						const auto * terrainType = VLC->terrainTypeHandler->terrains()[tt];
+						if(terrainType->isUnderground() && !terrainType->isSurface())
 						{
 						{
-							//underground
+							//underground only
 							zonesOnLevel[1]++;
 							zonesOnLevel[1]++;
 							levels[zone.first] = 1;
 							levels[zone.first] = 1;
 						}
 						}

+ 11 - 15
lib/rmg/Functions.cpp

@@ -134,26 +134,22 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
 			zone.setTerrainType(*RandomGeneratorUtil::nextItem(zone.getTerrainTypes(), gen.rand));
 			zone.setTerrainType(*RandomGeneratorUtil::nextItem(zone.getTerrainTypes(), gen.rand));
 		}
 		}
 		
 		
+		//Now, replace disallowed terrains on surface and in the underground
 		//TODO: allow new types of terrain?
 		//TODO: allow new types of terrain?
+		const auto* terrainType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()];
+
+		if(zone.isUnderground())
 		{
 		{
-			if(zone.isUnderground())
+			if(!terrainType->isUnderground())
 			{
 			{
-				if(!vstd::contains(gen.getConfig().terrainUndergroundAllowed, zone.getTerrainType()))
-				{
-					//collect all underground terrain types
-					std::vector<TTerrain> undegroundTerrains;
-					for(const auto * terrain : VLC->terrainTypeHandler->terrains())
-						if(terrain->isUnderground())
-							undegroundTerrains.push_back(terrain->id);
-					
-					zone.setTerrainType(*RandomGeneratorUtil::nextItem(undegroundTerrains, gen.rand));
-				}
+				zone.setTerrainType(Terrain::SUBTERRANEAN);
 			}
 			}
-			else
+		}
+		else
+		{
+			if (!terrainType->isSurface())
 			{
 			{
-				const auto* terrainType = VLC->terrainTypeHandler->terrains()[zone.getTerrainType()];
-				if(vstd::contains(gen.getConfig().terrainGroundProhibit, zone.getTerrainType()) || terrainType->isUnderground())
-					zone.setTerrainType(Terrain::DIRT);
+				zone.setTerrainType(Terrain::DIRT);
 			}
 			}
 		}
 		}
 	}
 	}