1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

CRewardableObject::onHeroVisit: avoid crash on pickable objects

Missed this problem when tested #214
This commit is contained in:
Arseniy Shestakov 2016-09-23 11:47:07 +03:00
parent 50b271393c
commit bb05db90e5

View File

@ -125,6 +125,13 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
if(!wasVisited(h))
{
auto rewards = getAvailableRewards(h);
bool objectRemovalPossible = false;
for(auto index : rewards)
{
if(getVisitInfo(index, h).reward.removeObject)
objectRemovalPossible = true;
}
logGlobal->debugStream() << "Visiting object with " << rewards.size() << " possible rewards";
switch (rewards.size())
{
@ -165,7 +172,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
}
}
if (getAvailableRewards(h).size() == 0)
if(!objectRemovalPossible && getAvailableRewards(h).size() == 0)
{
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
cb->sendAndApply(&cov);