1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

NetPacks: change GiveBonus enum to enum class.

This commit is contained in:
Konstantin 2023-03-28 14:46:53 +03:00
parent b2f5042942
commit 5716925b47
6 changed files with 19 additions and 19 deletions

View File

@ -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);

View File

@ -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

View File

@ -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));

View File

@ -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);

View File

@ -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();

View File

@ -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;