Added CMap::Field(x,y), changed some #defines to inline functions
This commit is contained in:
parent
cd09df73a8
commit
cc0472bc02
13 changed files with 72 additions and 63 deletions
action
ai
editor
include
map
pathfinder
unit
|
@ -164,7 +164,7 @@ int DoActionMove(CUnit *unit)
|
|||
}
|
||||
|
||||
move = UnitShowAnimationScaled(unit, unit->Type->Animations->Move,
|
||||
Map.Fields[unit->X + unit->Y*Map.Info.MapWidth].Cost);
|
||||
Map.Field(unit->X, unit->Y)->Cost);
|
||||
|
||||
unit->IX += xd * move;
|
||||
unit->IY += yd * move;
|
||||
|
|
|
@ -1010,6 +1010,7 @@ void CommandSharedVision(int player, bool state, int opponent)
|
|||
int x;
|
||||
int y;
|
||||
int i;
|
||||
CMapField *mf;
|
||||
|
||||
//
|
||||
// Do a real hardcore seen recount. First we unmark EVERYTHING.
|
||||
|
@ -1037,15 +1038,15 @@ void CommandSharedVision(int player, bool state, int opponent)
|
|||
//
|
||||
for (x = 0; x < Map.Info.MapWidth; ++x) {
|
||||
for (y = 0; y < Map.Info.MapHeight; ++y) {
|
||||
i = x + y * Map.Info.MapWidth;
|
||||
if (Map.Fields[i].Visible[player] && !Map.Fields[i].Visible[opponent]) {
|
||||
Map.Fields[i].Visible[opponent] = 1;
|
||||
mf = Map.Field(x, y);
|
||||
if (mf->Visible[player] && !mf->Visible[opponent]) {
|
||||
mf->Visible[opponent] = 1;
|
||||
if (opponent == ThisPlayer->Index) {
|
||||
Map.MarkSeenTile(x, y);
|
||||
}
|
||||
}
|
||||
if (Map.Fields[i].Visible[opponent] && !Map.Fields[i].Visible[player]) {
|
||||
Map.Fields[i].Visible[player] = 1;
|
||||
if (mf->Visible[opponent] && !mf->Visible[player]) {
|
||||
mf->Visible[player] = 1;
|
||||
if (player == ThisPlayer->Index) {
|
||||
Map.MarkSeenTile(x, y);
|
||||
}
|
||||
|
|
|
@ -92,12 +92,11 @@ static int AiCheckSurrounding(const CUnit *worker, const CUnitType *type, int x,
|
|||
if ((unsigned)x < (unsigned)Map.Info.MapWidth && (unsigned)y < (unsigned)Map.Info.MapHeight) {
|
||||
if (worker && x == worker->X && y == worker->Y) {
|
||||
surrounding[surroundingnb++] = 1;
|
||||
} else if (Map.Fields[x + y * Map.Info.MapWidth].Flags &
|
||||
(MapFieldUnpassable | MapFieldBuilding)) {
|
||||
} else if (Map.Field(x, y)->Flags & (MapFieldUnpassable | MapFieldBuilding)) {
|
||||
surrounding[surroundingnb++] = 0;
|
||||
} else{
|
||||
// Can pass there
|
||||
surrounding[surroundingnb++] = (Map.Fields[x + y * Map.Info.MapWidth].Flags &
|
||||
surrounding[surroundingnb++] = (Map.Field(x, y)->Flags &
|
||||
(MapFieldWaterAllowed + MapFieldCoastAllowed + MapFieldLandAllowed)) != 0;;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -199,7 +199,7 @@ void EditTile(int x, int y, int tile)
|
|||
//
|
||||
// Change the flags
|
||||
//
|
||||
mf = &Map.Fields[y * Map.Info.MapWidth + x];
|
||||
mf = Map.Field(x, y);
|
||||
mf->Flags &= ~(MapFieldLandAllowed | MapFieldCoastAllowed |
|
||||
MapFieldWaterAllowed | MapFieldNoBuilding | MapFieldUnpassable);
|
||||
|
||||
|
@ -1043,9 +1043,9 @@ static void DrawEditorInfo(void)
|
|||
//
|
||||
// Flags info
|
||||
//
|
||||
flags = Map.Fields[x + y * Map.Info.MapWidth].Flags;
|
||||
flags = Map.Field(x, y)->Flags;
|
||||
sprintf(buf, "%02X|%04X|%c%c%c%c%c%c%c%c%c%c%c%c%c",
|
||||
Map.Fields[x + y * Map.Info.MapWidth].Value, flags,
|
||||
Map.Field(x, y)->Value, flags,
|
||||
flags & MapFieldUnpassable ? 'u' : '-',
|
||||
flags & MapFieldNoBuilding ? 'n' : '-',
|
||||
flags & MapFieldLandAllowed ? 'L' : '-',
|
||||
|
@ -1060,7 +1060,7 @@ static void DrawEditorInfo(void)
|
|||
//
|
||||
// Tile info
|
||||
//
|
||||
tile = Map.Fields[x + y * Map.Info.MapWidth].Tile;
|
||||
tile = Map.Field(x, y)->Tile;
|
||||
|
||||
for (i = 0; i < Map.Tileset.NumTiles; ++i) {
|
||||
if (tile == Map.Tileset.Table[i]) {
|
||||
|
|
|
@ -99,7 +99,7 @@ static unsigned QuadFromTile(int x, int y)
|
|||
//
|
||||
// find the abstact tile number
|
||||
//
|
||||
tile = Map.Fields[y * Map.Info.MapWidth + x].Tile;
|
||||
tile = Map.Field(x, y)->Tile;
|
||||
for (i = 0; i < Map.Tileset.NumTiles; ++i) {
|
||||
if (tile == Map.Tileset.Table[i]) {
|
||||
break;
|
||||
|
@ -420,7 +420,7 @@ void ChangeTile(int x, int y, int tile)
|
|||
Assert(x >= 0 && y >= 0 && x < Map.Info.MapWidth && y < Map.Info.MapHeight);
|
||||
Assert(tile >= 0 && tile < Map.Tileset.NumTiles);
|
||||
|
||||
mf = &Map.Fields[y * Map.Info.MapWidth + x];
|
||||
mf = Map.Field(x, y);
|
||||
mf->Tile = mf->SeenTile = Map.Tileset.Table[tile];
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ static void EditorChangeTile(int x, int y, int tile, int d)
|
|||
//
|
||||
// Change the flags
|
||||
//
|
||||
mf = &Map.Fields[y * Map.Info.MapWidth + x];
|
||||
mf = Map.Field(x, y);
|
||||
mf->Flags &= ~(MapFieldLandAllowed | MapFieldCoastAllowed |
|
||||
MapFieldWaterAllowed | MapFieldNoBuilding | MapFieldUnpassable);
|
||||
|
||||
|
|
|
@ -271,6 +271,10 @@ public:
|
|||
/// Save the map.
|
||||
void Save(CFile *file) const;
|
||||
|
||||
/// Get the MapField at location x,y
|
||||
inline CMapField *Field(int x, int y) {
|
||||
return &this->Fields[x + y * this->Info.MapWidth];
|
||||
}
|
||||
//
|
||||
// Tile type.
|
||||
//
|
||||
|
@ -323,7 +327,7 @@ extern int ReplayRevealMap;
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
//
|
||||
// in map_fog.c
|
||||
// in map_fog.cpp
|
||||
//
|
||||
/// Function to (un)mark the vision table.
|
||||
typedef void MapMarkerFunc(const CPlayer *player, int x, int y);
|
||||
|
@ -349,7 +353,7 @@ extern void InitVisionTable(void);
|
|||
extern void FreeVisionTable(void);
|
||||
|
||||
//
|
||||
// in map_radar.c
|
||||
// in map_radar.cpp
|
||||
//
|
||||
|
||||
/// Check if a unit is visible on radar
|
||||
|
@ -366,7 +370,7 @@ extern void MapMarkTileRadarJammer(const CPlayer *player, int x, int y);
|
|||
extern void MapUnmarkTileRadarJammer(const CPlayer *player, int x, int y);
|
||||
|
||||
//
|
||||
// in script_map.c
|
||||
// in script_map.cpp
|
||||
//
|
||||
/// Set a tile
|
||||
extern void SetTile(int tile, int w, int h, int value = 0);
|
||||
|
@ -395,7 +399,7 @@ extern int UnitCanBeAt(const CUnit *unit, int x, int y);
|
|||
/// Preprocess map, for internal use.
|
||||
extern void PreprocessMap(void);
|
||||
|
||||
// in unit.c
|
||||
// in unit.cpp
|
||||
|
||||
/// Mark on vision table the Sight of the unit.
|
||||
void MapMarkUnitSight(CUnit *unit);
|
||||
|
@ -407,24 +411,31 @@ void MapUnmarkUnitSight(CUnit *unit);
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// Can a unit with 'mask' enter the field
|
||||
#define CanMoveToMask(x, y, mask) \
|
||||
!(Map.Fields[(x) + (y) * Map.Info.MapWidth].Flags & (mask))
|
||||
inline bool CanMoveToMask(int x, int y, int mask) {
|
||||
return !(Map.Field(x, y)->Flags & mask);
|
||||
}
|
||||
|
||||
#define MapMarkSight(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapMarkTileSight)
|
||||
#define MapUnmarkSight(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapUnmarkTileSight)
|
||||
inline void MapMarkSight(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapMarkTileSight);
|
||||
}
|
||||
inline void MapUnmarkSight(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapUnmarkTileSight);
|
||||
}
|
||||
|
||||
/// Handle Marking and Unmarking of radar vision
|
||||
#define MapMarkRadar(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapMarkTileRadar)
|
||||
#define MapUnmarkRadar(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapUnmarkTileRadar)
|
||||
inline void MapMarkRadar(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapMarkTileRadar);
|
||||
}
|
||||
inline void MapUnmarkRadar(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapUnmarkTileRadar);
|
||||
}
|
||||
/// Handle Marking and Unmarking of radar vision
|
||||
#define MapMarkRadarJammer(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapMarkTileRadarJammer)
|
||||
#define MapUnmarkRadarJammer(player, x, y, w, h, range) \
|
||||
MapSight((player), (x), (y), (w), (h), (range), MapUnmarkTileRadarJammer)
|
||||
inline void MapMarkRadarJammer(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapMarkTileRadarJammer);
|
||||
}
|
||||
inline void MapUnmarkRadarJammer(const CPlayer *player, int x, int y, int w, int h, int range) {
|
||||
MapSight(player, x, y, w, h, range, MapUnmarkTileRadarJammer);
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ int CheckedCanMoveToMask(int x, int y, int mask)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return !(Map.Fields[x + y * Map.Info.MapWidth].Flags & mask);
|
||||
return !(Map.Field(x, y)->Flags & mask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +233,7 @@ void PreprocessMap(void)
|
|||
|
||||
for (ix = 0; ix < Map.Info.MapWidth; ++ix) {
|
||||
for (iy = 0; iy < Map.Info.MapHeight; ++iy) {
|
||||
mf = Map.Fields + ix + iy * Map.Info.MapWidth;
|
||||
mf = Map.Field(ix, iy);
|
||||
mf->SeenTile = mf->Tile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ void MapMarkTileSight(const CPlayer *player, int x, int y)
|
|||
|
||||
unsigned short *v;
|
||||
|
||||
v = &Map.Fields[x + y * Map.Info.MapWidth].Visible[player->Index];
|
||||
v = &Map.Field(x, y)->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) {
|
||||
|
@ -203,7 +203,7 @@ void MapUnmarkTileSight(const CPlayer *player, int x, int y)
|
|||
|
||||
unsigned short *v;
|
||||
|
||||
v = &Map.Fields[x + y * Map.Info.MapWidth].Visible[player->Index];
|
||||
v = &Map.Field(x, y)->Visible[player->Index];
|
||||
switch (*v) {
|
||||
case 0: // Unexplored
|
||||
case 1:
|
||||
|
|
|
@ -89,12 +89,12 @@ unsigned char IsTileRadarVisible(const CPlayer *pradar, const CPlayer *punit, in
|
|||
unsigned char *radar;
|
||||
unsigned char *jamming;
|
||||
|
||||
jamming = Map.Fields[y * Map.Info.MapWidth + x].RadarJammer;
|
||||
jamming = Map.Field(x, y)->RadarJammer;
|
||||
if (jamming[punit->Index]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
radar = Map.Fields[y * Map.Info.MapWidth + x].Radar;
|
||||
radar = Map.Field(x, y)->Radar;
|
||||
radarvision = radar[pradar->Index];
|
||||
|
||||
if (!pradar->SharedVision) {
|
||||
|
@ -129,9 +129,9 @@ void MapMarkTileRadar(const CPlayer *player, int x, int y)
|
|||
{
|
||||
Assert(0 <= x && x < Map.Info.MapWidth);
|
||||
Assert(0 <= y && y < Map.Info.MapHeight);
|
||||
Assert(Map.Fields[x + y * Map.Info.MapWidth].Radar[player->Index] != 255);
|
||||
Assert(Map.Field(x, y)->Radar[player->Index] != 255);
|
||||
|
||||
Map.Fields[x + y * Map.Info.MapWidth].Radar[player->Index]++;
|
||||
Map.Field(x, y)->Radar[player->Index]++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ void MapUnmarkTileRadar(const CPlayer *player, int x, int y)
|
|||
Assert(0 <= y && y < Map.Info.MapHeight);
|
||||
|
||||
// Reduce radar coverage if it exists.
|
||||
v = &Map.Fields[x + y * Map.Info.MapWidth].Radar[player->Index];
|
||||
v = &Map.Field(x, y)->Radar[player->Index];
|
||||
if (*v) {
|
||||
--*v;
|
||||
}
|
||||
|
@ -166,9 +166,9 @@ void MapMarkTileRadarJammer(const CPlayer *player, int x, int y)
|
|||
{
|
||||
Assert(0 <= x && x < Map.Info.MapWidth);
|
||||
Assert(0 <= y && y < Map.Info.MapHeight);
|
||||
Assert(Map.Fields[x + y * Map.Info.MapWidth].RadarJammer[player->Index] != 255);
|
||||
Assert(Map.Field(x, y)->RadarJammer[player->Index] != 255);
|
||||
|
||||
Map.Fields[x + y * Map.Info.MapWidth].RadarJammer[player->Index]++;
|
||||
Map.Field(x, y)->RadarJammer[player->Index]++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +186,7 @@ void MapUnmarkTileRadarJammer(const CPlayer *player, int x, int y)
|
|||
Assert(0 <= y && y < Map.Info.MapHeight);
|
||||
|
||||
// Reduce radar coverage if it exists.
|
||||
v = &Map.Fields[x + y * Map.Info.MapWidth].RadarJammer[player->Index];
|
||||
v = &Map.Field(x, y)->RadarJammer[player->Index];
|
||||
if (*v) {
|
||||
--*v;
|
||||
}
|
||||
|
|
|
@ -401,9 +401,9 @@ void SetTile(int tile, int w, int h, int value)
|
|||
}
|
||||
|
||||
if (Map.Fields) {
|
||||
Map.Fields[w + h * Map.Info.MapWidth].Tile = Map.Tileset.Table[tile];
|
||||
Map.Fields[w + h * Map.Info.MapWidth].Flags = Map.Tileset.FlagsTable[tile];
|
||||
Map.Fields[w + h * Map.Info.MapWidth].Cost =
|
||||
Map.Field(w, h)->Tile = Map.Tileset.Table[tile];
|
||||
Map.Field(w, h)->Flags = Map.Tileset.FlagsTable[tile];
|
||||
Map.Field(w, h)->Cost =
|
||||
1 << (Map.Tileset.FlagsTable[tile] & MapFieldSpeedMask);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ static int CostMoveTo(const CUnit *unit, int ex, int ey, int mask) {
|
|||
// verify each tile of the unit.
|
||||
for (i = ex; i < ex + unit->Type->TileWidth; i++) {
|
||||
for (j = ey; j < ey + unit->Type->TileHeight; j++) {
|
||||
flag = Map.Fields[i + j * Map.Info.MapWidth].Flags & mask;
|
||||
flag = Map.Field(i, j)->Flags & mask;
|
||||
if (flag && (AStarKnowUnknown || Map.IsFieldExplored(unit->Player, i, j)) ) {
|
||||
if (flag & ~(MapFieldLandUnit | MapFieldAirUnit | MapFieldSeaUnit)) {
|
||||
// we can't cross fixed units and other unpassable things
|
||||
|
@ -321,7 +321,7 @@ static int CostMoveTo(const CUnit *unit, int ex, int ey, int mask) {
|
|||
cost += AStarUnknownTerrainCost;
|
||||
}
|
||||
// Add tile movement cost
|
||||
cost += Map.Fields[i + j * Map.Info.MapWidth].Cost;
|
||||
cost += Map.Field(i, j)->Cost;
|
||||
}
|
||||
}
|
||||
return cost;
|
||||
|
|
|
@ -571,7 +571,7 @@ void MarkUnitFieldFlags(const CUnit *unit)
|
|||
flags = type->FieldFlags;
|
||||
for (h = type->TileHeight; h--;) {
|
||||
for (w = type->TileWidth; w--;) {
|
||||
Map.Fields[x + w + (y + h) * Map.Info.MapWidth].Flags |= flags;
|
||||
Map.Field(x + w, y + h)->Flags |= flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -598,13 +598,12 @@ void UnmarkUnitFieldFlags(const CUnit *unit)
|
|||
flags = type->FieldFlags;
|
||||
for (h = type->TileHeight; h--;) {
|
||||
for (w = type->TileWidth; w--;) {
|
||||
Map.Fields[x + w + (y + h) * Map.Info.MapWidth].Flags &= ~flags;
|
||||
Map.Field(x + w, y + h)->Flags &= ~flags;
|
||||
|
||||
int n = UnitCacheOnTile(x + w, y + h, table);
|
||||
while (n--) {
|
||||
if (table[n] != unit && table[n]->Orders[0]->Action != UnitActionDie) {
|
||||
Map.Fields[x + w + (y + h) * Map.Info.MapWidth].Flags |=
|
||||
table[n]->Type->FieldFlags;
|
||||
Map.Field(x + w, y + h)->Flags |= table[n]->Type->FieldFlags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1208,7 +1207,7 @@ void UnitCountSeen(CUnit *unit)
|
|||
for (x = 0; x < unit->Type->TileWidth; ++x) {
|
||||
for (y = 0; y < unit->Type->TileHeight; ++y) {
|
||||
// Icky ugly code trick. With NoFogOfWar we have to be > 0;
|
||||
if (Map.Fields[(unit->Y + y) * Map.Info.MapWidth + unit->X + x].Visible[p] >
|
||||
if (Map.Field(unit->X + x, unit->Y + y)->Visible[p] >
|
||||
1 - (Map.NoFogOfWar ? 1 : 0)) {
|
||||
newv++;
|
||||
}
|
||||
|
@ -2097,8 +2096,7 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType *type, int x, int y)
|
|||
// Need at least one coast tile
|
||||
for (h = type->TileHeight; h--;) {
|
||||
for (w = type->TileWidth; w--;) {
|
||||
if (Map.Fields[x + w + (y + h) * Map.Info.MapWidth].Flags &
|
||||
MapFieldCoastAllowed) {
|
||||
if (Map.Field(x + w, y + h)->Flags & MapFieldCoastAllowed) {
|
||||
h = w = 0;
|
||||
success = 1;
|
||||
}
|
||||
|
@ -2144,7 +2142,7 @@ bool CanBuildOn(int x, int y, int mask)
|
|||
if (x < 0 || y < 0 || x >= Map.Info.MapWidth || y >= Map.Info.MapHeight) {
|
||||
return false;
|
||||
}
|
||||
return (Map.Fields[x + y * Map.Info.MapWidth].Flags & mask) ? false : true;
|
||||
return (Map.Field(x, y)->Flags & mask) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,7 +56,7 @@ void UnitCacheInsert(CUnit *unit)
|
|||
Assert(!unit->Removed);
|
||||
|
||||
for (int i = 0; i < unit->Type->TileHeight; ++i) {
|
||||
CMapField *mf = Map.Fields + (i + unit->Y) * Map.Info.MapWidth + unit->X;
|
||||
CMapField *mf = Map.Field(unit->X, unit->Y + i);
|
||||
for (int j = 0; j < unit->Type->TileWidth; ++j) {
|
||||
mf[j].UnitCache.push_back(unit);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ void UnitCacheRemove(CUnit *unit)
|
|||
Assert(!unit->Removed);
|
||||
|
||||
for (int i = 0; i < unit->Type->TileHeight; ++i) {
|
||||
CMapField *mf = Map.Fields + (i + unit->Y) * Map.Info.MapWidth + unit->X;
|
||||
CMapField *mf = Map.Field(unit->X, unit->Y + i);
|
||||
for (int j = 0; j < unit->Type->TileWidth; ++j) {
|
||||
for (std::vector<CUnit *>::iterator k = mf[j].UnitCache.begin(); k != mf[j].UnitCache.end(); ++k) {
|
||||
if (*k == unit) {
|
||||
|
@ -127,7 +127,7 @@ int UnitCacheSelect(int x1, int y1, int x2, int y2, CUnit **table)
|
|||
|
||||
n = 0;
|
||||
for (i = y1; i < y2; ++i) {
|
||||
mf = &Map.Fields[i * Map.Info.MapWidth + x1];
|
||||
mf = Map.Field(x1, i);
|
||||
for (j = x1; j < x2; ++j) {
|
||||
for (size_t k = 0, end = mf->UnitCache.size(); k < end; ++k) {
|
||||
//
|
||||
|
@ -172,7 +172,7 @@ int UnitCacheOnTile(int x, int y, CUnit **table)
|
|||
// so there is no need for Cache Locks.
|
||||
//
|
||||
int n = 0;
|
||||
CMapField *mf = &Map.Fields[y * Map.Info.MapWidth + x];
|
||||
CMapField *mf = Map.Field(x, y);
|
||||
std::vector<CUnit *>::iterator i, end;
|
||||
|
||||
for (i = mf->UnitCache.begin(), end = mf->UnitCache.end(); i != end; ++i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue