mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-28 03:57:02 +02:00
CRewardableObject::onHeroVisit: avoid crash on pickable objects
Missed this problem when tested #214
This commit is contained in:
parent
50b271393c
commit
bb05db90e5
@ -125,6 +125,13 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
|
|||||||
if(!wasVisited(h))
|
if(!wasVisited(h))
|
||||||
{
|
{
|
||||||
auto rewards = getAvailableRewards(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";
|
logGlobal->debugStream() << "Visiting object with " << rewards.size() << " possible rewards";
|
||||||
switch (rewards.size())
|
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);
|
ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id);
|
||||||
cb->sendAndApply(&cov);
|
cb->sendAndApply(&cov);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user