mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
- Fixed mantis #1643
This commit is contained in:
parent
5971ceaa7f
commit
aff704d1ca
@ -2742,11 +2742,18 @@ std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > CGameState::generateC
|
|||||||
{
|
{
|
||||||
std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > campaignHeroReplacements;
|
std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > campaignHeroReplacements;
|
||||||
|
|
||||||
|
auto removeHeroPlaceholder = [this](CGHeroPlaceholder * heroPlaceholder)
|
||||||
|
{
|
||||||
|
map->removeBlockVisTiles(heroPlaceholder, true);
|
||||||
|
map->objects[heroPlaceholder->id.getNum()] = nullptr;
|
||||||
|
delete heroPlaceholder;
|
||||||
|
};
|
||||||
|
|
||||||
//selecting heroes by type
|
//selecting heroes by type
|
||||||
for(int g = 0; g < map->objects.size(); ++g)
|
for(int g = 0; g < map->objects.size(); ++g)
|
||||||
{
|
{
|
||||||
CGObjectInstance * obj = map->objects[g];
|
CGObjectInstance * obj = map->objects[g];
|
||||||
if (obj->ID == Obj::HERO_PLACEHOLDER)
|
if (obj && obj->ID == Obj::HERO_PLACEHOLDER)
|
||||||
{
|
{
|
||||||
CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
|
CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
|
||||||
|
|
||||||
@ -2766,10 +2773,7 @@ std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > CGameState::generateC
|
|||||||
}
|
}
|
||||||
if(!found)
|
if(!found)
|
||||||
{
|
{
|
||||||
auto nh = new CGHeroInstance();
|
removeHeroPlaceholder(hp);
|
||||||
nh->subID = hp->subID;
|
|
||||||
nh->initHeroDefInfo();
|
|
||||||
campaignHeroReplacements.push_back(std::make_pair(nh, gid));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2786,7 +2790,7 @@ std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > CGameState::generateC
|
|||||||
for(int g = 0; g < map->objects.size(); ++g)
|
for(int g = 0; g < map->objects.size(); ++g)
|
||||||
{
|
{
|
||||||
CGObjectInstance * obj = map->objects[g];
|
CGObjectInstance * obj = map->objects[g];
|
||||||
if(obj->ID == Obj::HERO_PLACEHOLDER)
|
if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
|
||||||
{
|
{
|
||||||
CGHeroPlaceholder * hp = dynamic_cast<CGHeroPlaceholder*>(obj);
|
CGHeroPlaceholder * hp = dynamic_cast<CGHeroPlaceholder*>(obj);
|
||||||
if(hp->subID == 0xFF) //select by power
|
if(hp->subID == 0xFF) //select by power
|
||||||
@ -2809,9 +2813,7 @@ std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > CGameState::generateC
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
map->removeBlockVisTiles(heroPlaceholder, true);
|
removeHeroPlaceholder(heroPlaceholder);
|
||||||
delete heroPlaceholder;
|
|
||||||
map->objects[heroPlaceholder->id.getNum()] = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2828,7 +2830,7 @@ void CGameState::replaceHeroesPlaceholders(const std::vector<std::pair<CGHeroIns
|
|||||||
heroToPlace->id = obj.second;
|
heroToPlace->id = obj.second;
|
||||||
heroToPlace->tempOwner = placeholder->tempOwner;
|
heroToPlace->tempOwner = placeholder->tempOwner;
|
||||||
heroToPlace->pos = placeholder->pos;
|
heroToPlace->pos = placeholder->pos;
|
||||||
heroToPlace->type = VLC->heroh->heroes[heroToPlace->type->ID.getNum()]; //TODO is this reasonable? either old type can be still used or it can be deleted?
|
heroToPlace->type = VLC->heroh->heroes[heroToPlace->subID];
|
||||||
|
|
||||||
for(auto &&i : heroToPlace->stacks)
|
for(auto &&i : heroToPlace->stacks)
|
||||||
i.second->type = VLC->creh->creatures[i.second->getCreatureID()];
|
i.second->type = VLC->creh->creatures[i.second->getCreatureID()];
|
||||||
|
Loading…
Reference in New Issue
Block a user