mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Merge pull request #3179 from vcmi/fix-3173
#3173 - fix trap crash on random hero
This commit is contained in:
@@ -121,8 +121,7 @@ HeroTypeID CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
|
|||||||
return *notAllowedHeroesButStillBetterThanCrash.begin();
|
return *notAllowedHeroesButStillBetterThanCrash.begin();
|
||||||
|
|
||||||
logGlobal->error("No free heroes at all!");
|
logGlobal->error("No free heroes at all!");
|
||||||
assert(0); //current code can't handle this situation
|
throw std::runtime_error("Can not allocate hero. All heroes are already used.");
|
||||||
return HeroTypeID::NONE; // no available heroes at all
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CGameState::getDate(Date mode) const
|
int CGameState::getDate(Date mode) const
|
||||||
|
|||||||
@@ -1543,22 +1543,25 @@ std::string CGHeroInstance::getHeroTypeName() const
|
|||||||
|
|
||||||
void CGHeroInstance::afterAddToMap(CMap * map)
|
void CGHeroInstance::afterAddToMap(CMap * map)
|
||||||
{
|
{
|
||||||
auto existingHero = std::find_if(map->objects.begin(), map->objects.end(), [&](const CGObjectInstance * o) ->bool
|
if(ID != Obj::RANDOM_HERO)
|
||||||
{
|
|
||||||
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())
|
auto existingHero = std::find_if(map->objects.begin(), map->objects.end(), [&](const CGObjectInstance * o) ->bool
|
||||||
{
|
{
|
||||||
logGlobal->warn("Hero is already on the map at %s", (*existingHero)->visitablePos().toString());
|
return o && (o->ID == Obj::HERO || o->ID == Obj::PRISON) && o->subID == subID && o != this;
|
||||||
}
|
});
|
||||||
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(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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user