mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
CGCreature: add reward granting. Fix issue 2372
This commit is contained in:
@ -392,6 +392,7 @@ void CGCreature::joinDecision(const CGHeroInstance *h, int cost, ui32 accept) co
|
|||||||
if(cost)
|
if(cost)
|
||||||
cb->giveResource(h->tempOwner,Res::GOLD,-cost);
|
cb->giveResource(h->tempOwner,Res::GOLD,-cost);
|
||||||
|
|
||||||
|
giveReward(h);
|
||||||
cb->tryJoiningArmy(this, h, true, true);
|
cb->tryJoiningArmy(this, h, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -455,6 +456,7 @@ void CGCreature::battleFinished(const CGHeroInstance *hero, const BattleResult &
|
|||||||
|
|
||||||
if(result.winner==0)
|
if(result.winner==0)
|
||||||
{
|
{
|
||||||
|
giveReward(hero);
|
||||||
cb->removeObject(this);
|
cb->removeObject(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -557,6 +559,35 @@ int CGCreature::getNumberOfStacks(const CGHeroInstance *hero) const
|
|||||||
return split;
|
return split;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGCreature::giveReward(const CGHeroInstance * h) const
|
||||||
|
{
|
||||||
|
InfoWindow iw;
|
||||||
|
iw.player = h->tempOwner;
|
||||||
|
|
||||||
|
if(resources.size())
|
||||||
|
{
|
||||||
|
cb->giveResources(h->tempOwner, resources);
|
||||||
|
for(int i = 0; i < resources.size(); i++)
|
||||||
|
{
|
||||||
|
if(resources[i] > 0)
|
||||||
|
iw.components.push_back(Component(Component::RESOURCE, i, resources[i], 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gainedArtifact != ArtifactID::NONE)
|
||||||
|
{
|
||||||
|
cb->giveHeroNewArtifact(h, VLC->arth->artifacts[gainedArtifact], ArtifactPosition::FIRST_AVAILABLE);
|
||||||
|
iw.components.push_back(Component(Component::ARTIFACT, gainedArtifact, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(iw.components.size())
|
||||||
|
{
|
||||||
|
iw.text.addTxt(MetaString::ADVOB_TXT, 183); // % has found treasure
|
||||||
|
iw.text.addReplacement(h->name);
|
||||||
|
cb->showInfoDialog(&iw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CGMine::onHeroVisit( const CGHeroInstance * h ) const
|
void CGMine::onHeroVisit( const CGHeroInstance * h ) const
|
||||||
{
|
{
|
||||||
int relations = cb->gameState()->getPlayerRelations(h->tempOwner, tempOwner);
|
int relations = cb->gameState()->getPlayerRelations(h->tempOwner, tempOwner);
|
||||||
|
@ -90,6 +90,7 @@ private:
|
|||||||
void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
|
void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
|
||||||
|
|
||||||
int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
|
int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
|
||||||
|
void giveReward(const CGHeroInstance * h) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user