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

Fixed initialization of move points and mana for dismissed heroes

This commit is contained in:
Ivan Savenko 2024-01-15 22:25:52 +02:00
parent 03675e1c48
commit c21913f661
10 changed files with 29 additions and 8 deletions

View File

@ -202,6 +202,7 @@ public:
bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, bool transit = false, PlayerColor asker = PlayerColor::NEUTRAL) override {return false;};
void giveHeroBonus(GiveBonus * bonus) override {};
void setMovePoints(SetMovePoints * smp) override {};
void setMovePoints(ObjectInstanceID hid, int val, bool absolute) override {};
void setManaPoints(ObjectInstanceID hid, int val) override {};
void giveHero(ObjectInstanceID id, PlayerColor player, ObjectInstanceID boatId = ObjectInstanceID()) override {};
void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator) override {};

View File

@ -122,6 +122,7 @@ public:
virtual bool swapGarrisonOnSiege(ObjectInstanceID tid)=0;
virtual void giveHeroBonus(GiveBonus * bonus)=0;
virtual void setMovePoints(SetMovePoints * smp)=0;
virtual void setMovePoints(ObjectInstanceID hid, int val, bool absolute)=0;
virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
virtual void giveHero(ObjectInstanceID id, PlayerColor player, ObjectInstanceID boatId = ObjectInstanceID()) = 0;
virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator)=0;

View File

@ -40,7 +40,7 @@ TavernSlotRole TavernHeroesPool::getSlotRole(HeroTypeID hero) const
return TavernSlotRole::NONE;
}
void TavernHeroesPool::setHeroForPlayer(PlayerColor player, TavernHeroSlot slot, HeroTypeID hero, CSimpleArmy & army, TavernSlotRole role)
void TavernHeroesPool::setHeroForPlayer(PlayerColor player, TavernHeroSlot slot, HeroTypeID hero, CSimpleArmy & army, TavernSlotRole role, bool replenishPoints)
{
vstd::erase_if(currentTavern, [&](const TavernSlot & entry){
return entry.player == player && entry.slot == slot;
@ -54,6 +54,12 @@ void TavernHeroesPool::setHeroForPlayer(PlayerColor player, TavernHeroSlot slot,
if (h && army)
h->setToArmy(army);
if (h && replenishPoints)
{
h->setMovementPoints(h->movementPointsLimit(true));
h->mana = h->manaLimit();
}
TavernSlot newSlot;
newSlot.hero = h;
newSlot.player = player;

View File

@ -74,7 +74,7 @@ public:
void setAvailability(HeroTypeID hero, std::set<PlayerColor> mask);
/// Makes hero available in tavern of specified player
void setHeroForPlayer(PlayerColor player, TavernHeroSlot slot, HeroTypeID hero, CSimpleArmy & army, TavernSlotRole role);
void setHeroForPlayer(PlayerColor player, TavernHeroSlot slot, HeroTypeID hero, CSimpleArmy & army, TavernSlotRole role, bool replenishPoints);
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -151,11 +151,7 @@ void COPWBonus::onHeroVisit (const CGHeroInstance * h) const
gb.id = heroID;
cb->giveHeroBonus(&gb);
SetMovePoints mp;
mp.val = 600;
mp.absolute = false;
mp.hid = heroID;
cb->setMovePoints(&mp);
cb->setMovePoints(heroID, 600, false);
iw.text.appendRawString(VLC->generaltexth->allTexts[580]);
cb->showInfoDialog(&iw);

View File

@ -959,7 +959,7 @@ void FoWChange::applyGs(CGameState *gs)
void SetAvailableHero::applyGs(CGameState *gs)
{
gs->heroesPool->setHeroForPlayer(player, slotID, hid, army, roleID);
gs->heroesPool->setHeroForPlayer(player, slotID, hid, army, roleID, replenishPoints);
}
void GiveBonus::applyGs(CGameState *gs)

View File

@ -352,6 +352,7 @@ struct DLL_LINKAGE SetAvailableHero : public CPackForClient
PlayerColor player;
HeroTypeID hid; //HeroTypeID::NONE if no hero
CSimpleArmy army;
bool replenishPoints;
void visitTyped(ICPackVisitor & visitor) override;
@ -362,6 +363,7 @@ struct DLL_LINKAGE SetAvailableHero : public CPackForClient
h & player;
h & hid;
h & army;
h & replenishPoints;
}
};

View File

@ -1510,6 +1510,15 @@ void CGameHandler::setMovePoints(SetMovePoints * smp)
sendAndApply(smp);
}
void CGameHandler::setMovePoints(ObjectInstanceID hid, int val, bool absolute)
{
SetMovePoints smp;
smp.hid = hid;
smp.val = val;
smp.absolute = absolute;
sendAndApply(&smp);
}
void CGameHandler::setManaPoints(ObjectInstanceID hid, int val)
{
SetMana sm;

View File

@ -142,6 +142,7 @@ public:
bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, bool transit = false, PlayerColor asker = PlayerColor::NEUTRAL) override;
void giveHeroBonus(GiveBonus * bonus) override;
void setMovePoints(SetMovePoints * smp) override;
void setMovePoints(ObjectInstanceID hid, int val, bool absolute) override;
void setManaPoints(ObjectInstanceID hid, int val) override;
void giveHero(ObjectInstanceID id, PlayerColor player, ObjectInstanceID boatId = ObjectInstanceID()) override;
void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator) override;

View File

@ -74,6 +74,7 @@ void HeroPoolProcessor::onHeroSurrendered(const PlayerColor & color, const CGHer
sah.slotID = selectSlotForRole(color, sah.roleID);
sah.player = color;
sah.hid = hero->getHeroType();
sah.replenishPoints = false;
gameHandler->sendAndApply(&sah);
}
@ -87,6 +88,7 @@ void HeroPoolProcessor::onHeroEscaped(const PlayerColor & color, const CGHeroIns
sah.hid = hero->getHeroType();
sah.army.clearSlots();
sah.army.setCreature(SlotID(0), hero->type->initialArmy.at(0).creature, 1);
sah.replenishPoints = false;
gameHandler->sendAndApply(&sah);
}
@ -98,6 +100,7 @@ void HeroPoolProcessor::clearHeroFromSlot(const PlayerColor & color, TavernHeroS
sah.roleID = TavernSlotRole::NONE;
sah.slotID = slot;
sah.hid = HeroTypeID::NONE;
sah.replenishPoints = false;
gameHandler->sendAndApply(&sah);
}
@ -106,6 +109,7 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
SetAvailableHero sah;
sah.player = color;
sah.slotID = slot;
sah.replenishPoints = true;
CGHeroInstance *newHero = pickHeroFor(needNativeHero, color);
@ -129,6 +133,7 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
{
sah.hid = HeroTypeID::NONE;
}
gameHandler->sendAndApply(&sah);
}