瀏覽代碼

Fix loading of some user-made maps

Ivan Savenko 2 年之前
父節點
當前提交
402823e3d5
共有 2 個文件被更改,包括 21 次插入13 次删除
  1. 1 1
      lib/mapping/MapFeaturesH3M.cpp
  2. 20 12
      lib/mapping/MapReaderH3M.cpp

+ 1 - 1
lib/mapping/MapFeaturesH3M.cpp

@@ -75,7 +75,7 @@ MapFormatFeaturesH3M MapFormatFeaturesH3M::getFeaturesAB()
 	result.factionsBytes = 2; // + Conflux
 	result.factionsCount = 9;
 
-	result.creaturesCount = 144; // + Conflux and new neutrals
+	result.creaturesCount = 145; // + Conflux and new neutrals
 
 	result.heroesCount = 156; // + Conflux and campaign heroes
 	result.heroesPortraitsCount = 163;

+ 20 - 12
lib/mapping/MapReaderH3M.cpp

@@ -38,8 +38,11 @@ ArtifactID MapReaderH3M::readArtifact()
 	if(result == features.artifactIdentifierInvalid)
 		return ArtifactID::NONE;
 
-	assert(result < features.artifactsCount);
-	return result;
+	if (result < features.artifactsCount)
+		return result;
+
+	logGlobal->warn("Map contains invalid artifact %d. Will be removed!", result.getNum());
+	return ArtifactID::NONE;
 }
 
 ArtifactID MapReaderH3M::readArtifact32()
@@ -49,8 +52,11 @@ ArtifactID MapReaderH3M::readArtifact32()
 	if(result == ArtifactID::NONE)
 		return ArtifactID::NONE;
 
-	assert(result < features.artifactsCount);
-	return result;
+	if (result < features.artifactsCount)
+		return result;
+
+	logGlobal->warn("Map contains invalid artifact %d. Will be removed!", result.getNum());
+	return ArtifactID::NONE;
 }
 
 HeroTypeID MapReaderH3M::readHero()
@@ -76,16 +82,18 @@ CreatureID MapReaderH3M::readCreature()
 	if(result == features.creatureIdentifierInvalid)
 		return CreatureID::NONE;
 
-	if(result > features.creaturesCount)
-	{
-		// this may be random creature in army/town, to be randomized later
-		CreatureID randomIndex(result.getNum() - features.creatureIdentifierInvalid - 1);
-		assert(randomIndex < CreatureID::NONE);
-		assert(randomIndex > -16);
+	if(result < features.creaturesCount)
+		return result;
+
+	// this may be random creature in army/town, to be randomized later
+	CreatureID randomIndex(result.getNum() - features.creatureIdentifierInvalid - 1);
+	assert(randomIndex < CreatureID::NONE);
+
+	if (randomIndex > -16)
 		return randomIndex;
-	}
 
-	return result;
+	logGlobal->warn("Map contains invalid creature %d. Will be removed!", result.getNum());
+	return CreatureID::NONE;
 }
 
 TerrainId MapReaderH3M::readTerrain()