diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index a05aa2d3c..d897b109a 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -324,13 +324,13 @@ void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack) cl.invalidatePaths(); switch(pack.who) { - case GiveBonus::HERO: + case GiveBonus::ETarget::HERO: { const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id)); callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, *h->getBonusList().back(), true); } break; - case GiveBonus::PLAYER: + case GiveBonus::ETarget::PLAYER: { const PlayerState *p = gs.getPlayerState(PlayerColor(pack.id)); callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, *p->getBonusList().back(), true); @@ -399,13 +399,13 @@ void ApplyClientNetPackVisitor::visitRemoveBonus(RemoveBonus & pack) cl.invalidatePaths(); switch(pack.who) { - case RemoveBonus::HERO: + case GiveBonus::ETarget::HERO: { const CGHeroInstance *h = gs.getHero(ObjectInstanceID(pack.id)); callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, pack.bonus, false); } break; - case RemoveBonus::PLAYER: + case GiveBonus::ETarget::PLAYER: { //const PlayerState *p = gs.getPlayerState(pack.id); callInterfaceIfPresent(cl, PlayerColor(pack.id), &IGameEventsReceiver::playerBonusChanged, pack.bonus, false); diff --git a/lib/NetPacks.h b/lib/NetPacks.h index ce078e20a..0ff30acfe 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -349,15 +349,16 @@ struct DLL_LINKAGE SetAvailableHeroes : public CPackForClient struct DLL_LINKAGE GiveBonus : public CPackForClient { - GiveBonus(ui8 Who = 0) + enum class ETarget : ui8 { HERO, PLAYER, TOWN }; + + GiveBonus(ETarget Who = ETarget::HERO) :who(Who) { } void applyGs(CGameState * gs); - enum { HERO, PLAYER, TOWN }; - ui8 who = 0; //who receives bonus, uses enum above + ETarget who = ETarget::HERO; //who receives bonus si32 id = 0; //hero. town or player id - whoever receives it Bonus bonus; MetaString bdescr; @@ -424,15 +425,14 @@ struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient struct DLL_LINKAGE RemoveBonus : public CPackForClient { - RemoveBonus(ui8 Who = 0) + RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::HERO) :who(Who) { } void applyGs(CGameState * gs); - enum { HERO, PLAYER, TOWN }; - ui8 who; //who receives bonus, uses enum above + GiveBonus::ETarget who; //who receives bonus ui32 whoID = 0; //hero, town or player id - whoever loses bonus //vars to identify bonus: its source diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index b814fda18..460a984dc 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -952,13 +952,13 @@ void GiveBonus::applyGs(CGameState *gs) CBonusSystemNode *cbsn = nullptr; switch(who) { - case HERO: + case ETarget::HERO: cbsn = gs->getHero(ObjectInstanceID(id)); break; - case PLAYER: + case ETarget::PLAYER: cbsn = gs->getPlayerState(PlayerColor(id)); break; - case TOWN: + case ETarget::TOWN: cbsn = gs->getTown(ObjectInstanceID(id)); break; } @@ -1106,7 +1106,7 @@ void PlayerReinitInterface::applyGs(CGameState *gs) void RemoveBonus::applyGs(CGameState *gs) { CBonusSystemNode * node = nullptr; - if (who == HERO) + if (who == GiveBonus::ETarget::HERO) node = gs->getHero(ObjectInstanceID(whoID)); else node = gs->getPlayerState(PlayerColor(whoID)); diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 1d3138582..1cade310f 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -318,7 +318,7 @@ void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, c assert(bonus.source == Bonus::OBJECT); assert(bonus.sid == ID); GiveBonus gb; - gb.who = GiveBonus::HERO; + gb.who = GiveBonus::ETarget::HERO; gb.bonus = bonus; gb.id = hero->id.getNum(); cb->giveHeroBonus(&gb); diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 4c2b59856..da7b13ca8 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -2142,7 +2142,7 @@ void CGLighthouse::onHeroVisit( const CGHeroInstance * h ) const if(oldOwner < PlayerColor::PLAYER_LIMIT) //remove bonus from old owner { - RemoveBonus rb(RemoveBonus::PLAYER); + RemoveBonus rb(GiveBonus::ETarget::PLAYER); rb.whoID = oldOwner.getNum(); rb.source = Bonus::OBJECT; rb.id = id.getNum(); @@ -2162,7 +2162,7 @@ void CGLighthouse::initObj(CRandomGenerator & rand) void CGLighthouse::giveBonusTo(const PlayerColor & player, bool onInit) const { - GiveBonus gb(GiveBonus::PLAYER); + GiveBonus gb(GiveBonus::ETarget::PLAYER); gb.bonus.type = Bonus::MOVEMENT; gb.bonus.val = 500; gb.id = player.getNum(); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 9ad62dcc6..21fb3b73a 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -6943,7 +6943,7 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK); ///Give all spells with bonus (to allow banned spells) - GiveBonus giveBonus(GiveBonus::HERO); + GiveBonus giveBonus(GiveBonus::ETarget::HERO); giveBonus.id = hero->id.getNum(); giveBonus.bonus = Bonus(Bonus::PERMANENT, Bonus::SPELLS_OF_LEVEL, Bonus::OTHER, 0, 0); //start with level 0 to skip abilities @@ -7089,7 +7089,7 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons smp.val = 1000000; sendAndApply(&smp); - GiveBonus gb(GiveBonus::HERO); + GiveBonus gb(GiveBonus::ETarget::HERO); gb.bonus.type = Bonus::FREE_SHIP_BOARDING; gb.bonus.duration = Bonus::ONE_DAY; gb.bonus.source = Bonus::OTHER;