mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Fixed duplicated hero check - was used too early, before hero type is
loaded
This commit is contained in:
parent
87059be67b
commit
9e09fe08e1
@ -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);
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user