1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Likely fixed duplicated random heroes

This commit is contained in:
Ivan Savenko 2015-12-05 01:40:23 +02:00
parent 8a3feb1e48
commit 89bf3592e3
2 changed files with 16 additions and 12 deletions

View File

@ -1383,7 +1383,8 @@ void CGameState::placeStartingHeroes()
}
int heroTypeId = pickNextHeroType(playerColor);
if(playerSettingPair.second.hero == -1) playerSettingPair.second.hero = heroTypeId;
if(playerSettingPair.second.hero == -1)
playerSettingPair.second.hero = heroTypeId;
placeStartingHero(playerColor, HeroTypeID(heroTypeId), playerInfo.posOfMainTown);
}
@ -2770,7 +2771,7 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
{
for(auto hero : map->heroesOnMap) //heroes instances initialization
{
if(hero->subID == hid.getNum())
if(hero->type && hero->type->ID == hid)
{
return hero;
}
@ -2778,9 +2779,12 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
for(auto obj : map->objects) //prisons
{
if(obj && obj->ID == Obj::PRISON && obj->subID == hid.getNum())
if(obj && obj->ID == Obj::PRISON )
{
return dynamic_cast<CGHeroInstance *>(obj.get());
auto hero = dynamic_cast<CGHeroInstance *>(obj.get());
assert(hero);
if ( hero->type && hero->type->ID == hid )
return hero;
}
}