Просмотр исходного кода

Fixed duplicated hero check - was used too early, before hero type is
loaded

Ivan Savenko 1 год назад
Родитель
Сommit
9e09fe08e1
2 измененных файлов с 15 добавлено и 22 удалено
  1. 0 22
      lib/mapObjects/CGHeroInstance.cpp
  2. 15 0
      lib/mapping/MapFormatJson.cpp

+ 0 - 22
lib/mapObjects/CGHeroInstance.cpp

@@ -1524,28 +1524,6 @@ std::string CGHeroInstance::getHeroTypeName() const
 
 void CGHeroInstance::afterAddToMap(CMap * map)
 {
-	if(ID != Obj::RANDOM_HERO)
-	{
-		auto existingHero = std::find_if(map->objects.begin(), map->objects.end(), [&](const CGObjectInstance * o) ->bool
-			{
-				return o && (o->ID == Obj::HERO || o->ID == Obj::PRISON) && o->subID == subID && o != this;
-			});
-
-		if(existingHero != map->objects.end())
-		{
-			if(settings["session"]["editor"].Bool())
-			{
-				logGlobal->warn("Hero is already on the map at %s", (*existingHero)->visitablePos().toString());
-			}
-			else
-			{
-				logGlobal->error("Hero is already on the map at %s", (*existingHero)->visitablePos().toString());
-
-				throw std::runtime_error("Hero is already on the map");
-			}
-		}
-	}
-
 	if(ID != Obj::PRISON)
 	{		
 		map->heroesOnMap.emplace_back(this);

+ 15 - 0
lib/mapping/MapFormatJson.cpp

@@ -1156,6 +1156,21 @@ void CMapLoaderJson::readObjects()
 	{
 		return a->getObjTypeIndex() < b->getObjTypeIndex();
 	});
+
+
+	std::set<HeroTypeID> debugHeroesOnMap;
+	for (auto const & object : map->objects)
+	{
+		if(object->ID != Obj::HERO && object->ID != Obj::PRISON)
+			continue;
+
+		auto * hero = dynamic_cast<const CGHeroInstance *>(object.get());
+
+		if (debugHeroesOnMap.count(hero->getHeroType()))
+			logGlobal->error("Hero is already on the map at %s", hero->visitablePos().toString());
+
+		debugHeroesOnMap.insert(hero->getHeroType());
+	}
 }
 
 void CMapLoaderJson::readTranslations()