diff --git a/src/include/unit.h b/src/include/unit.h index 88176714b..c9b6205bb 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -57,6 +57,7 @@ class CBuildRestrictionOnTop; class CConstructionFrame; class CFile; class Missile; +class CMapField; class COrder; class CPlayer; class CUnit; @@ -489,12 +490,10 @@ extern void UnitGoesUnderFog(CUnit &unit, const CPlayer &player); /// Call when an Unit goes out of fog. extern void UnitGoesOutOfFog(CUnit &unit, const CPlayer &player); /// Marks a unit as seen -extern void UnitsOnTileMarkSeen(const CPlayer &player, int x, int y, int p); -extern void UnitsOnTileMarkSeen(const CPlayer &player, unsigned int index, int p); +extern void UnitsOnTileMarkSeen(const CPlayer &player, CMapField &mf, int p); /// Unmarks a unit as seen -extern void UnitsOnTileUnmarkSeen(const CPlayer &player, int x, int y, int p); -extern void UnitsOnTileUnmarkSeen(const CPlayer &player, unsigned int index, int p); +extern void UnitsOnTileUnmarkSeen(const CPlayer &player, CMapField &mf, int p); /// Does a recount for VisCount extern void UnitCountSeen(CUnit &unit); diff --git a/src/map/map_fog.cpp b/src/map/map_fog.cpp index c364df56e..e7acc55ae 100644 --- a/src/map/map_fog.cpp +++ b/src/map/map_fog.cpp @@ -132,15 +132,15 @@ int MapFogFilterFlags(CPlayer &player, const Vec2i &pos, int mask) */ void MapMarkTileSight(const CPlayer &player, const unsigned int index) { - //v = &Map.Field(x, y)->Visible[player.Index]; - unsigned short *v = &(Map.Field(index)->playerInfo.Visible[player.Index]); + CMapField &mf = *Map.Field(index); + unsigned short *v = &(mf.playerInfo.Visible[player.Index]); if (*v == 0 || *v == 1) { // Unexplored or unseen // When there is no fog only unexplored tiles are marked. if (!Map.NoFogOfWar || *v == 0) { - UnitsOnTileMarkSeen(player, index, 0); + UnitsOnTileMarkSeen(player, mf, 0); } *v = 2; - if (Map.Field(index)->playerInfo.IsTeamVisible(*ThisPlayer)) { + if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) { Map.MarkSeenTile(index); } return; @@ -165,7 +165,8 @@ void MapMarkTileSight(const CPlayer &player, const Vec2i &pos) */ void MapUnmarkTileSight(const CPlayer &player, const unsigned int index) { - unsigned short *v = &(Map.Field(index)->playerInfo.Visible[player.Index]); + CMapField &mf = *Map.Field(index); + unsigned short *v = &mf.playerInfo.Visible[player.Index]; switch (*v) { case 0: // Unexplored case 1: @@ -174,10 +175,10 @@ void MapUnmarkTileSight(const CPlayer &player, const unsigned int index) case 2: // When there is NoFogOfWar units never get unmarked. if (!Map.NoFogOfWar) { - UnitsOnTileUnmarkSeen(player, index, 0); + UnitsOnTileUnmarkSeen(player, mf, 0); } // Check visible Tile, then deduct... - if (Map.Field(index)->playerInfo.IsTeamVisible(*ThisPlayer)) { + if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) { Map.MarkSeenTile(index); } default: // seen -> seen @@ -202,9 +203,10 @@ void MapUnmarkTileSight(const CPlayer &player, const Vec2i &pos) */ void MapMarkTileDetectCloak(const CPlayer &player, const unsigned int index) { - unsigned char *v = &(Map.Field(index)->playerInfo.VisCloak[player.Index]); + CMapField &mf = *Map.Field(index); + unsigned char *v = &mf.playerInfo.VisCloak[player.Index]; if (*v == 0) { - UnitsOnTileMarkSeen(player, index, 1); + UnitsOnTileMarkSeen(player, mf, 1); } Assert(*v != 255); ++*v; @@ -223,13 +225,13 @@ void MapMarkTileDetectCloak(const CPlayer &player, const Vec2i &pos) ** @param x X tile to mark. ** @param y Y tile to mark. */ -void -MapUnmarkTileDetectCloak(const CPlayer &player, const unsigned int index) +void MapUnmarkTileDetectCloak(const CPlayer &player, const unsigned int index) { - unsigned char *v = &(Map.Field(index)->playerInfo.VisCloak[player.Index]); + CMapField &mf = *Map.Field(index); + unsigned char *v = &mf.playerInfo.VisCloak[player.Index]; Assert(*v != 0); if (*v == 1) { - UnitsOnTileUnmarkSeen(player, index, 1); + UnitsOnTileUnmarkSeen(player, mf, 1); } --*v; } diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index dc1a382a2..46b35520a 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -1543,43 +1543,28 @@ private: ** Mark all units on a tile as now visible. ** ** @param player The player this is for. -** @param x x location to check -** @param y y location to check +** @param mf field location to check ** @param cloak If we mark cloaked units too. */ -void UnitsOnTileMarkSeen(const CPlayer &player, const unsigned int index, int cloak) +void UnitsOnTileMarkSeen(const CPlayer &player, CMapField &mf, int cloak) { _TileSeen seen(player, cloak); - Map.Field(index)->UnitCache.for_each(seen); + mf.UnitCache.for_each(seen); } -void UnitsOnTileMarkSeen(const CPlayer &player, int x, int y, int cloak) -{ - UnitsOnTileMarkSeen(player, Map.getIndex(x, y), cloak); -} - - /** ** This function unmarks units on x, y as seen. It uses a reference count. ** ** @param player The player to mark for. -** @param x x location to check if building is on, and mark as seen -** @param y y location to check if building is on, and mark as seen +** @param mf field to check if building is on, and mark as seen ** @param cloak If this is for cloaked units. */ -void UnitsOnTileUnmarkSeen(const CPlayer &player, - const unsigned int index, int cloak) +void UnitsOnTileUnmarkSeen(const CPlayer &player, CMapField &mf, int cloak) { _TileSeen seen(player, cloak); - Map.Field(index)->UnitCache.for_each(seen); + mf.UnitCache.for_each(seen); } -void UnitsOnTileUnmarkSeen(const CPlayer &player, int x, int y, int cloak) -{ - UnitsOnTileUnmarkSeen(player, Map.getIndex(x, y), cloak); -} - - /** ** Recalculates a units visiblity count. This happens really often, ** Like every time a unit moves. It's really fast though, since we