1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Remove heroes placeholders even in single scenarios

This commit is contained in:
Ivan Savenko 2023-06-25 17:50:04 +03:00
parent 2882e2d248
commit 453d441562
3 changed files with 18 additions and 13 deletions

View File

@ -512,6 +512,7 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, bool allow
initPlayerStates();
if (campaign)
campaign->placeCampaignHeroes();
removeHeroPlaceholders();
initGrailPosition();
initRandomFactionsForPlayers();
randomizeMapObjects();
@ -858,6 +859,22 @@ void CGameState::placeStartingHeroes()
}
}
void CGameState::removeHeroPlaceholders()
{
// remove any hero placeholders that remain on map after (potential) campaign heroes placement
for(auto obj : map->objects)
{
if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
{
auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
map->removeBlockVisTiles(heroPlaceholder, true);
map->instanceNames.erase(obj->instanceName);
map->objects[heroPlaceholder->id.getNum()] = nullptr;
delete heroPlaceholder;
}
}
}
void CGameState::initStartingResources()
{
logGlobal->debug("\tSetting up resources");

View File

@ -220,6 +220,7 @@ private:
void initPlayerStates();
void placeStartingHeroes();
void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos);
void removeHeroPlaceholders();
void initStartingResources();
void initHeroes();
void placeHeroesInTowns();

View File

@ -333,19 +333,6 @@ void CGameStateCampaign::placeCampaignHeroes()
gameState->map->getEditManager()->insertObject(hero);
}
}
// remove hero placeholders on map
for(auto obj : gameState->map->objects)
{
if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
{
auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
gameState->map->removeBlockVisTiles(heroPlaceholder, true);
gameState->map->instanceNames.erase(obj->instanceName);
gameState->map->objects[heroPlaceholder->id.getNum()] = nullptr;
delete heroPlaceholder;
}
}
}
void CGameStateCampaign::giveCampaignBonusToHero(CGHeroInstance * hero)