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

CGCreature: fix crash on draw

Also according to H3 behaviour if there artifact monster guarded it's will be lost on draw.
This commit is contained in:
Arseniy Shestakov 2016-01-26 08:41:09 +03:00
parent 10f5029fff
commit 97a8874ed7
2 changed files with 16 additions and 12 deletions

View File

@ -295,10 +295,10 @@ void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int val, int nega
void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
{ {
if(result.winner) if(result.winner == 0)
return; {
giveContentsUpToExp(hero);
giveContentsUpToExp(hero); }
} }
void CGPandoraBox::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const void CGPandoraBox::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const

View File

@ -453,22 +453,26 @@ void CGCreature::flee( const CGHeroInstance * h ) const
void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
{ {
if(result.winner == 0)
if(result.winner==0)
{ {
giveReward(hero); giveReward(hero);
cb->removeObject(this); cb->removeObject(this);
} }
else if(result.winner > 1) // draw
{
// guarded reward is lost forever on draw
cb->removeObject(this);
}
else else
{ {
//merge stacks into one //merge stacks into one
TSlots::const_iterator i; TSlots::const_iterator i;
CCreature * cre = VLC->creh->creatures[formation.basicType]; CCreature * cre = VLC->creh->creatures[formation.basicType];
for (i = stacks.begin(); i != stacks.end(); i++) for(i = stacks.begin(); i != stacks.end(); i++)
{ {
if (cre->isMyUpgrade(i->second->type)) if(cre->isMyUpgrade(i->second->type))
{ {
cb->changeStackType (StackLocation(this, i->first), cre); //un-upgrade creatures cb->changeStackType(StackLocation(this, i->first), cre); //un-upgrade creatures
} }
} }
@ -476,16 +480,16 @@ void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &
if(!hasStackAtSlot(SlotID(0))) if(!hasStackAtSlot(SlotID(0)))
cb->moveStack(StackLocation(this, stacks.begin()->first), StackLocation(this, SlotID(0)), stacks.begin()->second->count); cb->moveStack(StackLocation(this, stacks.begin()->first), StackLocation(this, SlotID(0)), stacks.begin()->second->count);
while (stacks.size() > 1) //hopefully that's enough while(stacks.size() > 1) //hopefully that's enough
{ {
// TODO it's either overcomplicated (if we assume there'll be only one stack) or buggy (if we allow multiple stacks... but that'll also cause troubles elsewhere) // TODO it's either overcomplicated (if we assume there'll be only one stack) or buggy (if we allow multiple stacks... but that'll also cause troubles elsewhere)
i = stacks.end(); i = stacks.end();
i--; i--;
SlotID slot = getSlotFor(i->second->type); SlotID slot = getSlotFor(i->second->type);
if (slot == i->first) //no reason to move stack to its own slot if(slot == i->first) //no reason to move stack to its own slot
break; break;
else else
cb->moveStack (StackLocation(this, i->first), StackLocation(this, slot), i->second->count); cb->moveStack(StackLocation(this, i->first), StackLocation(this, slot), i->second->count);
} }
cb->setObjProperty(id, ObjProperty::MONSTER_POWER, stacks.begin()->second->count * 1000); //remember casualties cb->setObjProperty(id, ObjProperty::MONSTER_POWER, stacks.begin()->second->count * 1000); //remember casualties