CMap::MarkSeenTile take CMapField parameter instead of index or pos.

This commit is contained in:
Joris 2012-09-13 19:14:55 +02:00
parent 37e537eae4
commit 64314d4902
5 changed files with 58 additions and 69 deletions

View file

@ -851,22 +851,21 @@ void CommandSharedVision(int player, bool state, int opponent)
if (before && !after) {
// Don't share vision anymore. Give each other explored terrain for good-bye.
Vec2i pos;
for (pos.x = 0; pos.x < Map.Info.MapWidth; ++pos.x) {
for (pos.y = 0; pos.y < Map.Info.MapHeight; ++pos.y) {
CMapFieldPlayerInfo &mfp = Map.Field(pos)->playerInfo;
if (mfp.Visible[player] && !mfp.Visible[opponent]) {
mfp.Visible[opponent] = 1;
if (opponent == ThisPlayer->Index) {
Map.MarkSeenTile(pos);
}
for (int i = 0; i != this->Info.MapWidth * this->Info.MapHeight; ++i) {
CMapField &mf = *this->Field(i);
CMapFieldPlayerInfo &mfp = mf.playerInfo;
if (mfp.Visible[player] && !mfp.Visible[opponent]) {
mfp.Visible[opponent] = 1;
if (opponent == ThisPlayer->Index) {
Map.MarkSeenTile(mf);
}
if (mfp.Visible[opponent] && !mfp.Visible[player]) {
mfp.Visible[player] = 1;
if (player == ThisPlayer->Index) {
Map.MarkSeenTile(pos);
}
}
if (mfp.Visible[opponent] && !mfp.Visible[player]) {
mfp.Visible[player] = 1;
if (player == ThisPlayer->Index) {
Map.MarkSeenTile(mf);
}
}
}

View file

@ -187,13 +187,7 @@ public:
PixelPos TilePosToMapPixelPos_Center(const Vec2i &tilePos) const;
/// Mark a tile as seen by the player.
void MarkSeenTile(const unsigned int index);
/// Mark a tile as seen by the player.
void MarkSeenTile(const Vec2i &pos) {
Assert(Info.IsPointOnMap(pos));
MarkSeenTile(getIndex(pos));
}
void MarkSeenTile(CMapField &mf);
/// Regenerate the forest.
void RegenerateForest();

View file

@ -64,9 +64,8 @@ char CurrentMapPath[1024]; /// Path of the current map
** @param x Map X tile-position.
** @param y Map Y tile-position.
*/
void CMap::MarkSeenTile(const unsigned int index)
void CMap::MarkSeenTile(CMapField &mf)
{
CMapField &mf = *this->Field(index);
const int tile = mf.Tile;
const int seentile = mf.playerInfo.SeenTile;
@ -80,6 +79,7 @@ void CMap::MarkSeenTile(const unsigned int index)
#ifdef MINIMAP_UPDATE
//rb - GRRRRRRRRRRRR
const unsigned int index = &mf - Map.Fields;
const int y = index / Info.MapWidth;
const int x = index - (y * Info.MapWidth);
const Vec2i pos = {x, y}
@ -88,6 +88,7 @@ void CMap::MarkSeenTile(const unsigned int index)
if (this->Tileset.TileTypeTable) {
#ifndef MINIMAP_UPDATE
//rb - GRRRRRRRRRRRR
const unsigned int index = &mf - Map.Fields;
const int y = index / Info.MapWidth;
const int x = index - (y * Info.MapWidth);
const Vec2i pos(x, y);
@ -132,15 +133,13 @@ void CMap::MarkSeenTile(const unsigned int index)
void CMap::Reveal()
{
// Mark every explored tile as visible. 1 turns into 2.
Vec2i pos;
for (pos.x = 0; pos.x < this->Info.MapWidth; ++pos.x) {
for (pos.y = 0; pos.y < this->Info.MapHeight; ++pos.y) {
CMapFieldPlayerInfo &playerInfo = this->Field(pos)->playerInfo;
for (int p = 0; p < PlayerMax; ++p) {
playerInfo.Visible[p] = std::max<unsigned short>(1, playerInfo.Visible[p]);
}
MarkSeenTile(pos);
for (int i = 0; i != this->Info.MapWidth * this->Info.MapHeight; ++i) {
CMapField &mf = *this->Field(i);
CMapFieldPlayerInfo &playerInfo = mf.playerInfo;
for (int p = 0; p < PlayerMax; ++p) {
playerInfo.Visible[p] = std::max<unsigned short>(1, playerInfo.Visible[p]);
}
MarkSeenTile(mf);
}
// Global seen recount. Simple and effective.
for (CUnitManager::Iterator it = UnitManager.begin(); it != UnitManager.end(); ++it) {
@ -428,11 +427,11 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
return;
}
unsigned int index = getIndex(pos);
CMapField *mf = this->Field(index);
CMapField &mf = *this->Field(index);
if (seen && !Tileset.IsSeenTile(type, mf->playerInfo.SeenTile)) {
if (seen && !Tileset.IsSeenTile(type, mf.playerInfo.SeenTile)) {
return;
} else if (!seen && !(mf->Flags & type)) {
} else if (!seen && !(mf.Flags & type)) {
return;
}
@ -468,41 +467,41 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
if (pos.y - 1 < 0) {
ttup = 15; //Assign trees in all directions
} else {
CMapField *new_mf = (mf - this->Info.MapWidth);
CMapField &new_mf = *(&mf - this->Info.MapWidth);
if (seen) {
ttup = this->Tileset.MixedLookupTable[new_mf->playerInfo.SeenTile];
ttup = this->Tileset.MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttup = this->Tileset.MixedLookupTable[new_mf->Tile];
ttup = this->Tileset.MixedLookupTable[new_mf.Tile];
}
}
if (pos.x + 1 >= this->Info.MapWidth) {
ttright = 15; //Assign trees in all directions
} else {
CMapField *new_mf = (mf + 1);
CMapField &new_mf = *(&mf + 1);
if (seen) {
ttright = this->Tileset.MixedLookupTable[new_mf->playerInfo.SeenTile];
ttright = this->Tileset.MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttright = this->Tileset.MixedLookupTable[new_mf->Tile];
ttright = this->Tileset.MixedLookupTable[new_mf.Tile];
}
}
if (pos.y + 1 >= this->Info.MapHeight) {
ttdown = 15; //Assign trees in all directions
} else {
CMapField *new_mf = (mf + this->Info.MapWidth);
CMapField &new_mf = *(&mf + this->Info.MapWidth);
if (seen) {
ttdown = this->Tileset.MixedLookupTable[new_mf->playerInfo.SeenTile];
ttdown = this->Tileset.MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttdown = this->Tileset.MixedLookupTable[new_mf->Tile];
ttdown = this->Tileset.MixedLookupTable[new_mf.Tile];
}
}
if (pos.x - 1 < 0) {
ttleft = 15; //Assign trees in all directions
} else {
CMapField *new_mf = (mf - 1);
CMapField &new_mf = *(&mf - 1);
if (seen) {
ttleft = this->Tileset.MixedLookupTable[new_mf->playerInfo.SeenTile];
ttleft = this->Tileset.MixedLookupTable[new_mf.playerInfo.SeenTile];
} else {
ttleft = this->Tileset.MixedLookupTable[new_mf->Tile];
ttleft = this->Tileset.MixedLookupTable[new_mf.Tile];
}
}
@ -545,30 +544,30 @@ void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
//Update seen tile.
if (tile == -1) { // No valid wood remove it.
if (seen) {
mf->playerInfo.SeenTile = removedtile;
mf.playerInfo.SeenTile = removedtile;
this->FixNeighbors(type, seen, pos);
} else {
mf->Tile = removedtile;
mf->Flags &= ~flags;
mf->Value = 0;
mf.Tile = removedtile;
mf.Flags &= ~flags;
mf.Value = 0;
UI.Minimap.UpdateXY(pos);
}
} else if (seen && this->Tileset.MixedLookupTable[mf->playerInfo.SeenTile] ==
} else if (seen && this->Tileset.MixedLookupTable[mf.playerInfo.SeenTile] ==
this->Tileset.MixedLookupTable[tile]) { //Same Type
return;
} else {
if (seen) {
mf->playerInfo.SeenTile = tile;
mf.playerInfo.SeenTile = tile;
} else {
mf->Tile = tile;
mf.Tile = tile;
}
}
//maybe isExplored
if (mf->playerInfo.IsExplored(*ThisPlayer)) {
if (mf.playerInfo.IsExplored(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
if (!seen) {
MarkSeenTile(pos);
MarkSeenTile(mf);
}
}
}
@ -627,7 +626,7 @@ void CMap::ClearTile(unsigned short type, const Vec2i &pos)
//maybe isExplored
if (mf.playerInfo.IsExplored(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
MarkSeenTile(pos);
MarkSeenTile(mf);
}
}
@ -672,11 +671,11 @@ void CMap::RegenerateForestTile(const Vec2i &pos)
mf.Value = 0;
mf.Flags |= MapFieldForest | MapFieldUnpassable;
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
MarkSeenTile(pos);
MarkSeenTile(mf);
}
const Vec2i offset(0, -1);
if (Map.Field(pos + offset)->playerInfo.IsTeamVisible(*ThisPlayer)) {
MarkSeenTile(pos);
MarkSeenTile(mf);
}
}
}

View file

@ -229,7 +229,7 @@ void MapMarkTileSight(const CPlayer &player, const unsigned int index)
}
*v = 2;
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
Map.MarkSeenTile(index);
Map.MarkSeenTile(mf);
}
return;
}
@ -267,7 +267,7 @@ void MapUnmarkTileSight(const CPlayer &player, const unsigned int index)
}
// Check visible Tile, then deduct...
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
Map.MarkSeenTile(index);
Map.MarkSeenTile(mf);
}
default: // seen -> seen
--*v;
@ -407,20 +407,17 @@ void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range,
void UpdateFogOfWarChange()
{
DebugPrint("::UpdateFogOfWarChange\n");
//
// Mark all explored fields as visible again.
//
if (Map.NoFogOfWar) {
const unsigned int w = Map.Info.MapHeight * Map.Info.MapWidth;
for (unsigned int index = 0; index != w; ++index) {
if (Map.Field(index)->playerInfo.IsExplored(*ThisPlayer)) {
Map.MarkSeenTile(index);
CMapField &mf = *Map.Field(index);
if (mf.playerInfo.IsExplored(*ThisPlayer)) {
Map.MarkSeenTile(mf);
}
}
}
//
// Global seen recount.
//
for (CUnitManager::Iterator it = UnitManager.begin(); it != UnitManager.end(); ++it) {
CUnit &unit = **it;
UnitCountSeen(unit);

View file

@ -249,7 +249,7 @@ void MapFixWallTile(const Vec2i &pos)
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
Map.MarkSeenTile(pos);
Map.MarkSeenTile(mf);
}
}
}
@ -287,7 +287,7 @@ void CMap::RemoveWall(const Vec2i &pos)
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
this->MarkSeenTile(pos);
this->MarkSeenTile(mf);
}
}
@ -322,7 +322,7 @@ void CMap::SetWall(const Vec2i &pos, int humanwall)
if (mf.playerInfo.IsTeamVisible(*ThisPlayer)) {
UI.Minimap.UpdateSeenXY(pos);
this->MarkSeenTile(pos);
this->MarkSeenTile(mf);
}
}