1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

#3173 - fix trap crash on random hero

This commit is contained in:
Andrii Danylchenko
2023-11-12 16:14:06 +02:00
parent 07472d3b05
commit 142d0083d5
2 changed files with 18 additions and 16 deletions

View File

@@ -121,8 +121,7 @@ HeroTypeID CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
return *notAllowedHeroesButStillBetterThanCrash.begin();
logGlobal->error("No free heroes at all!");
assert(0); //current code can't handle this situation
return HeroTypeID::NONE; // no available heroes at all
throw std::runtime_error("Can not allocate hero. All heroes are already used.");
}
int CGameState::getDate(Date mode) const

View File

@@ -1531,6 +1531,8 @@ 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;
@@ -1549,6 +1551,7 @@ void CGHeroInstance::afterAddToMap(CMap * map)
throw std::runtime_error("Hero is already on the map");
}
}
}
if(ID != Obj::PRISON)
{