浏览代码

* much better callback function declaration (previous version inspired me to write a new coding guideline)

mateuszb 13 年之前
父节点
当前提交
100dad889a
共有 4 个文件被更改,包括 11 次插入6 次删除
  1. 1 1
      lib/CGameState.cpp
  2. 1 1
      lib/CGameState.h
  3. 8 3
      lib/IGameCallback.cpp
  4. 1 1
      lib/IGameCallback.h

+ 1 - 1
lib/CGameState.cpp

@@ -1889,7 +1889,7 @@ void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int
  * @return int3(-1, -1, -1) if the tile is unguarded, or the position of
  * the monster guarding the tile.
  */
-const std::vector<CGObjectInstance*> CGameState::guardingCreatures (int3 pos) const
+std::vector<CGObjectInstance*> CGameState::guardingCreatures (int3 pos) const
 {
 	std::vector<CGObjectInstance*> guards;
 	const int3 originalPos = pos;

+ 1 - 1
lib/CGameState.h

@@ -423,7 +423,7 @@ public:
 	bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists
 	void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or NULL if path does not exists
 	int3 guardingCreaturePosition (int3 pos) const;
-	const std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
+	std::vector<CGObjectInstance*> guardingCreatures (int3 pos) const;
 	int victoryCheck(ui8 player) const; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
 	int lossCheck(ui8 player) const; //checks if given player is loser;  -1 if std loss, 1 if special, 0 else
 	ui8 checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 if no winner

+ 8 - 3
lib/IGameCallback.cpp

@@ -386,10 +386,15 @@ int3 CGameInfoCallback::guardingCreaturePosition (int3 pos) const
 	return gs->guardingCreaturePosition(pos);
 }
 
-const std::vector<CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (int3 pos) const
+std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (int3 pos) const
 {
-	ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", std::vector<CGObjectInstance*>());
-	return gs->guardingCreatures (pos);
+	ERROR_RET_VAL_IF(!isVisible(pos), "Tile is not visible!", std::vector<const CGObjectInstance*>());
+	std::vector<const CGObjectInstance*> ret;
+	BOOST_FOREACH(auto cr, gs->guardingCreatures(pos))
+	{
+		ret.push_back(cr);
+	}
+	return ret;
 }
 
 bool CGameInfoCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero &dest ) const

+ 1 - 1
lib/IGameCallback.h

@@ -116,7 +116,7 @@ public:
 
 	//map
 	int3 guardingCreaturePosition (int3 pos) const;
-	const std::vector<CGObjectInstance*> getGuardingCreatures (int3 pos) const;
+	std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
 	const CMapHeader * getMapHeader()const;
 	int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
 	const TerrainTile * getTile(int3 tile, bool verbose = true) const;