diff --git a/lib/CGameState.h b/lib/CGameState.h index a6f489ba5..c8bf27706 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -80,7 +80,7 @@ struct ArmyDescriptor : public std::map struct DLL_LINKAGE InfoAboutArmy { - ui8 owner; + TPlayerColor owner; std::string name; ArmyDescriptor army; diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 91ae8c942..a9cc7dda6 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -212,7 +212,7 @@ int CObjectHandler::bankObjToIndex (const CGObjectInstance * obj) return 0; } } -int CGObjectInstance::getOwner() const +TPlayerColor CGObjectInstance::getOwner() const { //if (state) // return state->owner; @@ -242,7 +242,7 @@ const std::string & CGObjectInstance::getHoverText() const { return hoverName; } -void CGObjectInstance::setOwner(int ow) +void CGObjectInstance::setOwner(TPlayerColor ow) { //if (state) // state->owner = ow; @@ -2198,12 +2198,12 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result ) } } -void CGTownInstance::removeCapitols (ui8 owner) const +void CGTownInstance::removeCapitols (TPlayerColor owner) const { if (hasCapitol()) // search if there's an older capitol { PlayerState* state = cb->gameState()->getPlayer (owner); //get all towns owned by player - for (std::vector >::const_iterator i = state->towns.begin(); i < state->towns.end(); ++i) + for (auto i = state->towns.cbegin(); i < state->towns.cend(); ++i) { if (*i != this && (*i)->hasCapitol()) { diff --git a/lib/CObjectHandler.h b/lib/CObjectHandler.h index 63e39606b..d0b60dfa9 100644 --- a/lib/CObjectHandler.h +++ b/lib/CObjectHandler.h @@ -167,15 +167,15 @@ public: CGDefInfo * defInfo; ui8 animPhaseShift; - ui8 tempOwner; + TPlayerColor tempOwner; ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile virtual ui8 getPassableness() const; //bitmap - if the bit is set the corresponding player can pass through the visitable tiles of object, even if it's blockvis; if not set - default properties from definfo are used virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated virtual int getSightRadious() const; //sight distance (should be used if player-owned structure) void getSightTiles(boost::unordered_set &tiles) const; //returns reference to the set - int getOwner() const; - void setOwner(int ow); + TPlayerColor getOwner() const; + void setOwner(TPlayerColor ow); int getWidth() const; //returns width of object graphic in tiles int getHeight() const; //returns height of object graphic in tiles bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles) @@ -424,7 +424,7 @@ class DLL_LINKAGE CSpecObjInfo { public: virtual ~CSpecObjInfo(){}; - ui8 player; //owner + TPlayerColor player; //owner }; class DLL_LINKAGE CCreGenAsCastleInfo : public virtual CSpecObjInfo @@ -637,7 +637,7 @@ public: bool hasBuilt(int buildingID, int townID) const; int dailyIncome() const; //calculates daily income of this town int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5) - void removeCapitols (ui8 owner) const; + void removeCapitols (TPlayerColor owner) const; bool armedGarrison() const; //true if town has creatures in garrison or garrisoned hero CGTownInstance(); diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 1cb901af1..dcc95e3f6 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1475,7 +1475,7 @@ StackOwnerLimiter::StackOwnerLimiter() { } -StackOwnerLimiter::StackOwnerLimiter(ui8 Owner) +StackOwnerLimiter::StackOwnerLimiter(TPlayerColor Owner) : owner(Owner) { } diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 6bb163d95..5199670fd 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -828,9 +828,9 @@ public: class DLL_LINKAGE StackOwnerLimiter : public ILimiter //applies only to creatures of given alignment { public: - ui8 owner; + TPlayerColor owner; StackOwnerLimiter(); - StackOwnerLimiter(ui8 Owner); + StackOwnerLimiter(TPlayerColor Owner); int limit(const BonusLimitationContext &context) const OVERRIDE; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index d031ee61a..15ec8fcd6 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -41,14 +41,14 @@ CGameState * CPrivilagedInfoCallback::gameState () return gs; } -int CGameInfoCallback::getOwner(int heroID) const +TPlayerColor CGameInfoCallback::getOwner(int heroID) const { const CGObjectInstance *obj = getObj(heroID); ERROR_RET_VAL_IF(!obj, "No such object!", -1); return gs->map->objects[heroID]->tempOwner; } -int CGameInfoCallback::getResource(int Player, int which) const +TResource CGameInfoCallback::getResource(TPlayerColor Player, int which) const { const PlayerState *p = getPlayer(Player); ERROR_RET_VAL_IF(!p, "No player info!", -1); @@ -56,7 +56,7 @@ int CGameInfoCallback::getResource(int Player, int which) const return p->resources[which]; } -const CGHeroInstance* CGameInfoCallback::getSelectedHero( int Player ) const +const CGHeroInstance* CGameInfoCallback::getSelectedHero( TPlayerColor Player ) const { const PlayerState *p = getPlayer(Player); ERROR_RET_VAL_IF(!p, "No player info!", NULL); @@ -68,12 +68,12 @@ const CGHeroInstance* CGameInfoCallback::getSelectedHero() const return getSelectedHero(gs->currentPlayer); } -const PlayerSettings * CGameInfoCallback::getPlayerSettings(int color) const +const PlayerSettings * CGameInfoCallback::getPlayerSettings(TPlayerColor color) const { return &gs->scenarioOps->getIthPlayersSettings(color); } -void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ ) const +void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set &tiles, int3 pos, int radious, TPlayerColor player/*=-1*/, int mode/*=0*/ ) const { if(player >= GameConstants::PLAYER_LIMIT) { @@ -103,7 +103,7 @@ void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set &tiles, int Player/*=-1*/, int level, int surface ) const +void CPrivilagedInfoCallback::getAllTiles (boost::unordered_set &tiles, TPlayerColor Player/*=-1*/, int level, int surface ) const { if(Player >= GameConstants::PLAYER_LIMIT) { @@ -226,14 +226,14 @@ inline TerrainTile * CNonConstInfoCallback::getTile( int3 pos ) return &gs->map->getTile(pos); } -const PlayerState * CGameInfoCallback::getPlayer(int color, bool verbose) const +const PlayerState * CGameInfoCallback::getPlayer(TPlayerColor color, bool verbose) const { ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", NULL); ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!vstd::contains(gs->players,color), verbose, "Cannot find player " << color << "info!", NULL); return &gs->players[color]; } -const CTown * CGameInfoCallback::getNativeTown(int color) const +const CTown * CGameInfoCallback::getNativeTown(TPlayerColor color) const { const PlayerSettings *ps = getPlayerSettings(color); ERROR_RET_VAL_IF(!ps, "There is no such player!", NULL); @@ -442,7 +442,7 @@ bool CGameInfoCallback::verifyPath(CPath * path, bool blockSea) const return true; } -bool CGameInfoCallback::isVisible(int3 pos, int Player) const +bool CGameInfoCallback::isVisible(int3 pos, TPlayerColor Player) const { //boost::shared_lock lock(*gs->mx); return gs->map->isInTheMap(pos) && (Player == -1 || gs->isVisible(pos, Player)); @@ -453,7 +453,7 @@ bool CGameInfoCallback::isVisible(int3 pos) const return isVisible(pos,player); } -bool CGameInfoCallback::isVisible( const CGObjectInstance *obj, int Player ) const +bool CGameInfoCallback::isVisible( const CGObjectInstance *obj, TPlayerColor Player ) const { return gs->isVisible(obj, Player); } @@ -640,12 +640,12 @@ const CMapHeader * CGameInfoCallback::getMapHeader() const return gs->map; } -bool CGameInfoCallback::hasAccess(int playerId) const +bool CGameInfoCallback::hasAccess(TPlayerColor playerId) const { return player < 0 || gs->getPlayerRelations( playerId, player ); } -int CGameInfoCallback::getPlayerStatus(int player) const +int CGameInfoCallback::getPlayerStatus(TPlayerColor player) const { const PlayerState *ps = gs->getPlayer(player, false); if(!ps) @@ -658,7 +658,7 @@ std::string CGameInfoCallback::getTavernGossip(const CGObjectInstance * townOrTa return "GOSSIP TEST"; } -int CGameInfoCallback::getPlayerRelations( ui8 color1, ui8 color2 ) const +int CGameInfoCallback::getPlayerRelations( TPlayerColor color1, TPlayerColor color2 ) const { return gs->getPlayerRelations(color1, color2); } @@ -668,7 +668,7 @@ bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const return !obj || hasAccess(obj->tempOwner); } -int CGameInfoCallback::getHeroCount( int player, bool includeGarrisoned ) const +int CGameInfoCallback::getHeroCount( TPlayerColor player, bool includeGarrisoned ) const { int ret = 0; const PlayerState *p = gs->getPlayer(player); @@ -702,7 +702,7 @@ CGameInfoCallback::CGameInfoCallback() { } -CGameInfoCallback::CGameInfoCallback(CGameState *GS, int Player) +CGameInfoCallback::CGameInfoCallback(CGameState *GS, TPlayerColor Player) { gs = GS; player = Player; @@ -851,7 +851,7 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId) return p->towns[serialId]; } -int CPlayerSpecificInfoCallback::getResourceAmount(int type) const +TResource CPlayerSpecificInfoCallback::getResourceAmount(int type) const { //boost::shared_lock lock(*gs->mx); ERROR_RET_VAL_IF(player == -1, "Applicable only for player callbacks", -1); @@ -881,12 +881,12 @@ TeamState *CNonConstInfoCallback::getTeam(ui8 teamID) return const_cast(CGameInfoCallback::getTeam(teamID)); } -TeamState *CNonConstInfoCallback::getPlayerTeam(ui8 color) +TeamState *CNonConstInfoCallback::getPlayerTeam(TPlayerColor color) { return const_cast(CGameInfoCallback::getPlayerTeam(color)); } -PlayerState * CNonConstInfoCallback::getPlayer( ui8 color, bool verbose ) +PlayerState * CNonConstInfoCallback::getPlayer( TPlayerColor color, bool verbose ) { return const_cast(CGameInfoCallback::getPlayer(color, verbose)); } @@ -899,9 +899,9 @@ const TeamState * CGameInfoCallback::getTeam( ui8 teamID ) const return ret; } -const TeamState * CGameInfoCallback::getPlayerTeam( ui8 teamID ) const +const TeamState * CGameInfoCallback::getPlayerTeam( TPlayerColor color ) const { - const PlayerState * ps = getPlayer(teamID); + const PlayerState * ps = getPlayer(color); if (ps) return getTeam(ps->team); return NULL; diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 1627e6873..da6e60b65 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -64,10 +64,10 @@ class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase { protected: CGameInfoCallback(); - CGameInfoCallback(CGameState *GS, int Player); - bool hasAccess(int playerId) const; - bool isVisible(int3 pos, int Player) const; - bool isVisible(const CGObjectInstance *obj, int Player) const; + CGameInfoCallback(CGameState *GS, TPlayerColor Player); + bool hasAccess(TPlayerColor playerId) const; + bool isVisible(int3 pos, TPlayerColor Player) const; + bool isVisible(const CGObjectInstance *obj, TPlayerColor Player) const; bool isVisible(const CGObjectInstance *obj) const; bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode @@ -80,15 +80,15 @@ public: bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill //player - const PlayerState * getPlayer(int color, bool verbose = true) const; - int getResource(int Player, int which) const; + const PlayerState * getPlayer(TPlayerColor color, bool verbose = true) const; + TResource getResource(TPlayerColor Player, int which) const; bool isVisible(int3 pos) const; - int getPlayerRelations(ui8 color1, ui8 color2) const;// 0 = enemy, 1 = ally, 2 = same player + int getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const;// 0 = enemy, 1 = ally, 2 = same player void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object - int getPlayerStatus(int player) const; //-1 if no such player + int getPlayerStatus(TPlayerColor player) const; //-1 if no such player int getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns virtual int getLocalPlayer() const; //player that is currently owning given client (if not a client, then returns current player) - const PlayerSettings * getPlayerSettings(int color) const; + const PlayerSettings * getPlayerSettings(TPlayerColor color) const; //armed object @@ -97,12 +97,12 @@ public: //hero const CGHeroInstance* getHero(int objid) const; const CGHeroInstance* getHeroWithSubid(int subid) const; - int getHeroCount(int player, bool includeGarrisoned) const; + int getHeroCount(TPlayerColor player, bool includeGarrisoned) const; bool getHeroInfo(const CGObjectInstance *hero, InfoAboutHero &dest) const; int getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction int estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg bool verifyPath(CPath * path, bool blockSea)const; - const CGHeroInstance* getSelectedHero(int player) const; //NULL if no hero is selected + const CGHeroInstance* getSelectedHero(TPlayerColor player) const; //NULL if no hero is selected const CGHeroInstance* getSelectedHero() const; //of current (active) player //objects @@ -111,7 +111,7 @@ public: std::vector getVisitableObjs(int3 pos, bool verbose = true)const; std::vector getFlaggableObjects(int3 pos) const; std::vector getObjDescriptions(int3 pos)const; //returns descriptions of objects at pos in order from the lowest to the highest - int getOwner(int heroID) const; + TPlayerColor getOwner(int heroID) const; const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //NULL if object has been removed (eg. killed) //map @@ -130,11 +130,11 @@ public: int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements std::set getBuildingRequiments(const CGTownInstance *t, int ID); virtual bool getTownInfo(const CGObjectInstance *town, InfoAboutTown &dest) const; - const CTown *getNativeTown(int color) const; + const CTown *getNativeTown(TPlayerColor color) const; //from gs const TeamState *getTeam(ui8 teamID) const; - const TeamState *getPlayerTeam(ui8 color) const; + const TeamState *getPlayerTeam(TPlayerColor color) const; std::set getBuildingRequiments(const CGTownInstance *t, int ID) const; int canBuildStructure(const CGTownInstance *t, int ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements }; @@ -157,10 +157,10 @@ public: std::vector getMyObjects() const; //returns all objects flagged by belonging player std::vector getMyQuests() const; - int getResourceAmount(int type)const; + TResource getResourceAmount(int type)const; TResources getResourceAmount() const; const std::vector< std::vector< std::vector > > & getVisibilityMap()const; //returns visibility map - const PlayerSettings * getPlayerSettings(int color) const; + const PlayerSettings * getPlayerSettings(TPlayerColor color) const; }; class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback @@ -168,8 +168,8 @@ class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback public: CGameState * gameState (); void getFreeTiles (std::vector &tiles) const; //used for random spawns - void getTilesInRange(boost::unordered_set &tiles, int3 pos, int radious, int player=-1, int mode=0) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed - void getAllTiles (boost::unordered_set &tiles, int player=-1, int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water + void getTilesInRange(boost::unordered_set &tiles, int3 pos, int radious, TPlayerColor player=-1, int mode=0) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed + void getAllTiles (boost::unordered_set &tiles, TPlayerColor player=-1, int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water ui16 getRandomArt (int flags); ui16 getArtSync (ui32 rand, int flags); //synchronous void pickAllowedArtsSet(std::vector &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant @@ -180,9 +180,9 @@ public: class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback { public: - PlayerState *getPlayer(ui8 color, bool verbose = true); + PlayerState *getPlayer(TPlayerColor color, bool verbose = true); TeamState *getTeam(ui8 teamID);//get team by team ID - TeamState *getPlayerTeam(ui8 color);// get team by player color + TeamState *getPlayerTeam(TPlayerColor color);// get team by player color CGHeroInstance *getHero(int objid); CGTownInstance *getTown(int objid); TerrainTile * getTile(int3 pos); @@ -248,7 +248,7 @@ public: virtual void changeObjPos(int objid, int3 newPos, ui8 flags)=0; virtual void sendAndApply(CPackForClient * info)=0; virtual void heroExchange(si32 hero1, si32 hero2)=0; //when two heroes meet on adventure map - virtual void addQuest(int player, QuestInfo & quest){}; + virtual void addQuest(TPlayerColor player, QuestInfo & quest){}; }; /// Interface class for handling general game logic and actions diff --git a/lib/ResourceSet.h b/lib/ResourceSet.h index 525bf4815..f349c38d4 100644 --- a/lib/ResourceSet.h +++ b/lib/ResourceSet.h @@ -16,7 +16,7 @@ namespace Res }; //class to be representing a vector of resource - class ResourceSet : public std::vector + class ResourceSet : public std::vector { public: DLL_LINKAGE ResourceSet();