Browse Source

* last revision reverted, mysterious bug

mateuszb 13 years ago
parent
commit
59fcc15254
8 changed files with 55 additions and 55 deletions
  1. 1 1
      lib/CGameState.h
  2. 4 4
      lib/CObjectHandler.cpp
  3. 5 5
      lib/CObjectHandler.h
  4. 1 1
      lib/HeroBonus.cpp
  5. 2 2
      lib/HeroBonus.h
  6. 20 20
      lib/IGameCallback.cpp
  7. 21 21
      lib/IGameCallback.h
  8. 1 1
      lib/ResourceSet.h

+ 1 - 1
lib/CGameState.h

@@ -80,7 +80,7 @@ struct ArmyDescriptor : public std::map<TSlot, CStackBasicDescriptor>
 
 struct DLL_LINKAGE InfoAboutArmy
 {
-	TPlayerColor owner;
+	ui8 owner;
 	std::string name;
 
 	ArmyDescriptor army;

+ 4 - 4
lib/CObjectHandler.cpp

@@ -212,7 +212,7 @@ int CObjectHandler::bankObjToIndex (const CGObjectInstance * obj)
 		return 0;
 	}
 }
-TPlayerColor CGObjectInstance::getOwner() const
+int CGObjectInstance::getOwner() const
 {
 	//if (state)
 	//	return state->owner;
@@ -242,7 +242,7 @@ const std::string & CGObjectInstance::getHoverText() const
 {
 	return hoverName;
 }
-void CGObjectInstance::setOwner(TPlayerColor ow)
+void CGObjectInstance::setOwner(int ow)
 {
 	//if (state)
 	//	state->owner = ow;
@@ -2198,12 +2198,12 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
 	}
 }
 
-void CGTownInstance::removeCapitols (TPlayerColor owner) const
+void CGTownInstance::removeCapitols (ui8 owner) const
 {
 	if (hasCapitol()) // search if there's an older capitol
 	{
 		PlayerState* state = cb->gameState()->getPlayer (owner); //get all towns owned by player
-		for (auto i = state->towns.cbegin(); i < state->towns.cend(); ++i)
+		for (std::vector<ConstTransitivePtr<CGTownInstance> >::const_iterator i = state->towns.begin(); i < state->towns.end(); ++i)
 		{
 			if (*i != this && (*i)->hasCapitol())
 			{

+ 5 - 5
lib/CObjectHandler.h

@@ -167,15 +167,15 @@ public:
 	CGDefInfo * defInfo;
 	ui8 animPhaseShift;
 
-	TPlayerColor tempOwner;
+	ui8 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<int3, ShashInt3> &tiles) const; //returns reference to the set
-	TPlayerColor getOwner() const;
-	void setOwner(TPlayerColor ow);
+	int getOwner() const;
+	void setOwner(int 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(){};
-	TPlayerColor player; //owner
+	ui8 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 (TPlayerColor owner) const;
+	void removeCapitols (ui8 owner) const;
 	bool armedGarrison() const; //true if town has creatures in garrison or garrisoned hero
 
 	CGTownInstance();

+ 1 - 1
lib/HeroBonus.cpp

@@ -1475,7 +1475,7 @@ StackOwnerLimiter::StackOwnerLimiter()
 {
 }
 
-StackOwnerLimiter::StackOwnerLimiter(TPlayerColor Owner)
+StackOwnerLimiter::StackOwnerLimiter(ui8 Owner)
 	: owner(Owner)
 {
 }

+ 2 - 2
lib/HeroBonus.h

@@ -828,9 +828,9 @@ public:
 class DLL_LINKAGE StackOwnerLimiter : public ILimiter //applies only to creatures of given alignment
 {
 public:
-	TPlayerColor owner;
+	ui8 owner;
 	StackOwnerLimiter();
-	StackOwnerLimiter(TPlayerColor Owner);
+	StackOwnerLimiter(ui8 Owner);
 
 	int limit(const BonusLimitationContext &context) const OVERRIDE;
 

+ 20 - 20
lib/IGameCallback.cpp

@@ -41,14 +41,14 @@ CGameState * CPrivilagedInfoCallback::gameState ()
 	return gs;
 }
 
-TPlayerColor CGameInfoCallback::getOwner(int heroID) const
+int 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;
 }
 
-TResource CGameInfoCallback::getResource(TPlayerColor Player, int which) const
+int CGameInfoCallback::getResource(int Player, int which) const
 {
 	const PlayerState *p = getPlayer(Player);
 	ERROR_RET_VAL_IF(!p, "No player info!", -1);
@@ -56,7 +56,7 @@ TResource CGameInfoCallback::getResource(TPlayerColor Player, int which) const
 	return p->resources[which];
 }
 
-const CGHeroInstance* CGameInfoCallback::getSelectedHero( TPlayerColor Player ) const
+const CGHeroInstance* CGameInfoCallback::getSelectedHero( int 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(TPlayerColor color) const
+const PlayerSettings * CGameInfoCallback::getPlayerSettings(int color) const
 {
 	return &gs->scenarioOps->getIthPlayersSettings(color);
 }
 
-void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, TPlayerColor player/*=-1*/, int mode/*=0*/ ) const
+void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ ) const
 {
 	if(player >= GameConstants::PLAYER_LIMIT)
 	{
@@ -103,7 +103,7 @@ void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set<int3, ShashI
 	}
 }
 
-void CPrivilagedInfoCallback::getAllTiles (boost::unordered_set<int3, ShashInt3> &tiles, TPlayerColor Player/*=-1*/, int level, int surface ) const
+void CPrivilagedInfoCallback::getAllTiles (boost::unordered_set<int3, ShashInt3> &tiles, int 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(TPlayerColor color, bool verbose) const
+const PlayerState * CGameInfoCallback::getPlayer(int 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(TPlayerColor color) const
+const CTown * CGameInfoCallback::getNativeTown(int 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, TPlayerColor Player) const
+bool CGameInfoCallback::isVisible(int3 pos, int Player) const
 {
 	//boost::shared_lock<boost::shared_mutex> 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, TPlayerColor Player ) const
+bool CGameInfoCallback::isVisible( const CGObjectInstance *obj, int Player ) const
 {
 	return gs->isVisible(obj, Player);
 }
@@ -640,12 +640,12 @@ const CMapHeader * CGameInfoCallback::getMapHeader() const
 	return gs->map;
 }
 
-bool CGameInfoCallback::hasAccess(TPlayerColor playerId) const
+bool CGameInfoCallback::hasAccess(int playerId) const
 {
 	return player < 0 || gs->getPlayerRelations( playerId, player );
 }
 
-int CGameInfoCallback::getPlayerStatus(TPlayerColor player) const
+int CGameInfoCallback::getPlayerStatus(int 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( TPlayerColor color1, TPlayerColor color2 ) const
+int CGameInfoCallback::getPlayerRelations( ui8 color1, ui8 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( TPlayerColor player, bool includeGarrisoned ) const
+int CGameInfoCallback::getHeroCount( int player, bool includeGarrisoned ) const
 {
 	int ret = 0;
 	const PlayerState *p = gs->getPlayer(player);
@@ -702,7 +702,7 @@ CGameInfoCallback::CGameInfoCallback()
 {
 }
 
-CGameInfoCallback::CGameInfoCallback(CGameState *GS, TPlayerColor Player)
+CGameInfoCallback::CGameInfoCallback(CGameState *GS, int Player)
 {
 	gs = GS;
 	player = Player;
@@ -851,7 +851,7 @@ const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId)
 	return p->towns[serialId];
 }
 
-TResource CPlayerSpecificInfoCallback::getResourceAmount(int type) const
+int CPlayerSpecificInfoCallback::getResourceAmount(int type) const
 {
 	//boost::shared_lock<boost::shared_mutex> 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<TeamState*>(CGameInfoCallback::getTeam(teamID));
 }
 
-TeamState *CNonConstInfoCallback::getPlayerTeam(TPlayerColor color)
+TeamState *CNonConstInfoCallback::getPlayerTeam(ui8 color)
 {
 	return const_cast<TeamState*>(CGameInfoCallback::getPlayerTeam(color));
 }
 
-PlayerState * CNonConstInfoCallback::getPlayer( TPlayerColor color, bool verbose )
+PlayerState * CNonConstInfoCallback::getPlayer( ui8 color, bool verbose )
 {
 	return const_cast<PlayerState*>(CGameInfoCallback::getPlayer(color, verbose));
 }
@@ -899,9 +899,9 @@ const TeamState * CGameInfoCallback::getTeam( ui8 teamID ) const
 	return ret;
 }
 
-const TeamState * CGameInfoCallback::getPlayerTeam( TPlayerColor color ) const
+const TeamState * CGameInfoCallback::getPlayerTeam( ui8 teamID ) const
 {
-	const PlayerState * ps = getPlayer(color);
+	const PlayerState * ps = getPlayer(teamID);
 	if (ps)
 		return getTeam(ps->team);
 	return NULL;

+ 21 - 21
lib/IGameCallback.h

@@ -64,10 +64,10 @@ class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
 {
 protected:
 	CGameInfoCallback();
-	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;
+	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;
 	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(TPlayerColor color, bool verbose = true) const;
-	TResource getResource(TPlayerColor Player, int which) const;
+	const PlayerState * getPlayer(int color, bool verbose = true) const;
+	int getResource(int Player, int which) const;
 	bool isVisible(int3 pos) const;
-	int getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const;// 0 = enemy, 1 = ally, 2 = same player 
+	int getPlayerRelations(ui8 color1, ui8 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(TPlayerColor player) const; //-1 if no such player
+	int getPlayerStatus(int 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(TPlayerColor color) const;
+	const PlayerSettings * getPlayerSettings(int color) const;
 
 
 	//armed object
@@ -97,12 +97,12 @@ public:
 	//hero
 	const CGHeroInstance* getHero(int objid) const;
 	const CGHeroInstance* getHeroWithSubid(int subid) const;
-	int getHeroCount(TPlayerColor player, bool includeGarrisoned) const;
+	int getHeroCount(int 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(TPlayerColor player) const; //NULL if no hero is selected
+	const CGHeroInstance* getSelectedHero(int player) const; //NULL if no hero is selected
 	const CGHeroInstance* getSelectedHero() const; //of current (active) player
 
 	//objects
@@ -111,7 +111,7 @@ public:
 	std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true)const;
 	std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
 	std::vector <std::string > getObjDescriptions(int3 pos)const; //returns descriptions of objects at pos in order from the lowest to the highest
-	TPlayerColor getOwner(int heroID) const;
+	int 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<int> getBuildingRequiments(const CGTownInstance *t, int ID);
 	virtual bool getTownInfo(const CGObjectInstance *town, InfoAboutTown &dest) const;
-	const CTown *getNativeTown(TPlayerColor color) const;
+	const CTown *getNativeTown(int color) const;
 
 	//from gs
 	const TeamState *getTeam(ui8 teamID) const;
-	const TeamState *getPlayerTeam(TPlayerColor color) const;
+	const TeamState *getPlayerTeam(ui8 color) const;
 	std::set<int> 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 <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
 	std::vector <QuestInfo> getMyQuests() const;
 
-	TResource getResourceAmount(int type)const;
+	int getResourceAmount(int type)const;
 	TResources getResourceAmount() const;
 	const std::vector< std::vector< std::vector<ui8> > > & getVisibilityMap()const; //returns visibility map 
-	const PlayerSettings * getPlayerSettings(TPlayerColor color) const;
+	const PlayerSettings * getPlayerSettings(int 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<int3> &tiles) const; //used for random spawns
-	void getTilesInRange(boost::unordered_set<int3, ShashInt3> &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<int3, ShashInt3> &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
+	void getTilesInRange(boost::unordered_set<int3, ShashInt3> &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<int3, ShashInt3> &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
 	ui16 getRandomArt (int flags);
 	ui16 getArtSync (ui32 rand, int flags); //synchronous
 	void pickAllowedArtsSet(std::vector<const CArtifact*> &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(TPlayerColor color, bool verbose = true);
+	PlayerState *getPlayer(ui8 color, bool verbose = true);
 	TeamState *getTeam(ui8 teamID);//get team by team ID
-	TeamState *getPlayerTeam(TPlayerColor color);// get team by player color
+	TeamState *getPlayerTeam(ui8 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(TPlayerColor player, QuestInfo & quest){};
+	virtual void addQuest(int player, QuestInfo & quest){};
 };
 
 /// Interface class for handling general game logic and actions

+ 1 - 1
lib/ResourceSet.h

@@ -16,7 +16,7 @@ namespace Res
 	};
 
 	//class to be representing a vector of resource
-	class ResourceSet : public std::vector<TResource>
+	class ResourceSet : public std::vector<int>
 	{
 	public:
 		DLL_LINKAGE ResourceSet();