Move some methods from CMap into CMapField.
This commit is contained in:
parent
fee897b0a7
commit
f3697901e2
9 changed files with 59 additions and 107 deletions
|
@ -175,8 +175,8 @@ int DoActionMove(CUnit &unit)
|
|||
//
|
||||
// FIXME: This is an ugly hack
|
||||
if (unit.Type->CanTransport()
|
||||
&& ((Map.WaterOnMap(off) && Map.CoastOnMap(pos + posd))
|
||||
|| (Map.CoastOnMap(off) && Map.WaterOnMap(pos + posd)))) {
|
||||
&& ((Map.Field(off)->WaterOnMap() && Map.Field(pos + posd)->CoastOnMap())
|
||||
|| (Map.Field(off)->CoastOnMap() && Map.Field(pos + posd)->WaterOnMap()))) {
|
||||
PlayUnitSound(unit, VoiceDocking);
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ VisitResult NearReachableTerrainFinder::Visit(TerrainTraversal &terrainTraversal
|
|||
}
|
||||
return VisitResult_Finished;
|
||||
}
|
||||
if (Map.CheckMask(pos, resmask)) { // reachable
|
||||
if (Map.Field(pos)->CheckMask(resmask)) { // reachable
|
||||
if (terrainTraversal.Get(pos) <= maxDist) {
|
||||
return VisitResult_Ok;
|
||||
} else {
|
||||
|
@ -114,7 +114,7 @@ static bool FindNearestReachableTerrainType(int movemask, int resmask, int range
|
|||
terrainTraversal.SetSize(Map.Info.MapWidth, Map.Info.MapHeight);
|
||||
terrainTraversal.Init();
|
||||
|
||||
Assert(Map.CheckMask(startPos, resmask));
|
||||
Assert(Map.Field(startPos)->CheckMask(resmask));
|
||||
terrainTraversal.PushPos(startPos);
|
||||
|
||||
NearReachableTerrainFinder nearReachableTerrainFinder(player, range, movemask, resmask, terrainPos);
|
||||
|
|
|
@ -143,7 +143,7 @@ VisitResult WallFinder::Visit(TerrainTraversal &terrainTraversal, const Vec2i &p
|
|||
}
|
||||
return VisitResult_Finished;
|
||||
}
|
||||
if (Map.CheckMask(pos, movemask)) { // reachable
|
||||
if (Map.Field(pos)->CheckMask(movemask)) { // reachable
|
||||
if (terrainTraversal.Get(pos) <= maxDist) {
|
||||
return VisitResult_Ok;
|
||||
} else {
|
||||
|
|
|
@ -112,24 +112,6 @@ class CUnitType;
|
|||
#define MaxMapWidth 256 /// max map width supported
|
||||
#define MaxMapHeight 256 /// max map height supported
|
||||
|
||||
// Not used until now:
|
||||
#define MapFieldSpeedMask 0x0007 /// Move faster on this tile
|
||||
|
||||
#define MapFieldHuman 0x0008 /// Human is owner of the field (walls)
|
||||
|
||||
#define MapFieldLandAllowed 0x0010 /// Land units allowed
|
||||
#define MapFieldCoastAllowed 0x0020 /// Coast (transporter) units allowed
|
||||
#define MapFieldWaterAllowed 0x0040 /// Water units allowed
|
||||
#define MapFieldNoBuilding 0x0080 /// No buildings allowed
|
||||
|
||||
#define MapFieldUnpassable 0x0100 /// Field is movement blocked
|
||||
//#define MapFieldWall 0x0200 /// defined in tileset.h
|
||||
|
||||
#define MapFieldLandUnit 0x1000 /// Land unit on field
|
||||
#define MapFieldAirUnit 0x2000 /// Air unit on field
|
||||
#define MapFieldSeaUnit 0x4000 /// Water unit on field
|
||||
#define MapFieldBuilding 0x8000 /// Building on field
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Map info structure
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -208,15 +190,6 @@ public:
|
|||
*/
|
||||
unsigned short IsTileVisible(const CPlayer &player, const unsigned int index) const;
|
||||
|
||||
/// Check if a field flags.
|
||||
bool CheckMask(const unsigned int index, const int mask) const {
|
||||
return (this->Fields[index].Flags & mask) != 0;
|
||||
}
|
||||
|
||||
bool CheckMask(const Vec2i &pos, int mask) const {
|
||||
return CheckMask(getIndex(pos), mask);
|
||||
}
|
||||
|
||||
/// Check if a field for the user is explored.
|
||||
bool IsFieldExplored(const CPlayer &player, const unsigned int index) const;
|
||||
|
||||
|
@ -285,45 +258,6 @@ public:
|
|||
/// Returns true, if orc wall on the map tile field
|
||||
bool OrcWallOnMap(const Vec2i &pos) const;
|
||||
|
||||
|
||||
//
|
||||
// Tile type.
|
||||
//
|
||||
|
||||
/// Returns true, if water on the map tile field
|
||||
bool WaterOnMap(const unsigned int index) const {
|
||||
return CheckMask(index, MapFieldWaterAllowed);
|
||||
};
|
||||
|
||||
/**
|
||||
** Water on map tile.
|
||||
**
|
||||
** @param pos map tile position.
|
||||
**
|
||||
** @return True if water, false otherwise.
|
||||
*/
|
||||
bool WaterOnMap(const Vec2i &pos) const {
|
||||
Assert(Info.IsPointOnMap(pos));
|
||||
return WaterOnMap(getIndex(pos));
|
||||
}
|
||||
|
||||
/// Returns true, if coast on the map tile field
|
||||
bool CoastOnMap(const unsigned int index) const {
|
||||
return CheckMask(index, MapFieldCoastAllowed);
|
||||
};
|
||||
|
||||
/**
|
||||
** Coast on map tile.
|
||||
**
|
||||
** @param pos map tile position.
|
||||
**
|
||||
** @return True if coast, false otherwise.
|
||||
*/
|
||||
bool CoastOnMap(const Vec2i &pos) const {
|
||||
Assert(Info.IsPointOnMap(pos));
|
||||
return CoastOnMap(getIndex(pos));
|
||||
}
|
||||
|
||||
//UnitCache
|
||||
|
||||
/// Insert new unit into cache
|
||||
|
@ -495,7 +429,7 @@ void MapUnmarkUnitSight(CUnit &unit);
|
|||
/// Can a unit with 'mask' enter the field
|
||||
inline bool CanMoveToMask(const Vec2i &pos, int mask)
|
||||
{
|
||||
return !Map.CheckMask(pos, mask);
|
||||
return !Map.Field(pos)->CheckMask(mask);
|
||||
}
|
||||
|
||||
/// Handle Marking and Unmarking of radar vision
|
||||
|
|
|
@ -142,6 +142,25 @@ class CFile;
|
|||
-- Map - field
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
// Not used until now:
|
||||
#define MapFieldSpeedMask 0x0007 /// Move faster on this tile
|
||||
|
||||
#define MapFieldHuman 0x0008 /// Human is owner of the field (walls)
|
||||
|
||||
#define MapFieldLandAllowed 0x0010 /// Land units allowed
|
||||
#define MapFieldCoastAllowed 0x0020 /// Coast (transporter) units allowed
|
||||
#define MapFieldWaterAllowed 0x0040 /// Water units allowed
|
||||
#define MapFieldNoBuilding 0x0080 /// No buildings allowed
|
||||
|
||||
#define MapFieldUnpassable 0x0100 /// Field is movement blocked
|
||||
//#define MapFieldWall 0x0200 /// defined in tileset.h
|
||||
|
||||
#define MapFieldLandUnit 0x1000 /// Land unit on field
|
||||
#define MapFieldAirUnit 0x2000 /// Air unit on field
|
||||
#define MapFieldSeaUnit 0x4000 /// Water unit on field
|
||||
#define MapFieldBuilding 0x8000 /// Building on field
|
||||
|
||||
|
||||
class CMapFieldPlayerInfo
|
||||
{
|
||||
public:
|
||||
|
@ -179,6 +198,31 @@ public:
|
|||
|
||||
void Save(CFile &file) const;
|
||||
|
||||
/// Check if a field flags.
|
||||
bool CheckMask(int mask) const {
|
||||
return (this->Flags & mask) != 0;
|
||||
}
|
||||
|
||||
/// Returns true, if water on the map tile field
|
||||
bool WaterOnMap() const {
|
||||
return CheckMask(MapFieldWaterAllowed);
|
||||
}
|
||||
|
||||
/// Returns true, if coast on the map tile field
|
||||
bool CoastOnMap() const {
|
||||
return CheckMask(MapFieldCoastAllowed);
|
||||
}
|
||||
|
||||
/// Returns true, if water on the map tile field
|
||||
bool ForestOnMap() const {
|
||||
return CheckMask(MapFieldForest);
|
||||
}
|
||||
|
||||
/// Returns true, if coast on the map tile field
|
||||
bool RockOnMap() const {
|
||||
return CheckMask(MapFieldRocks);
|
||||
}
|
||||
|
||||
public:
|
||||
unsigned short Tile; /// graphic tile number
|
||||
unsigned short Flags; /// field flags
|
||||
|
|
|
@ -58,31 +58,6 @@ char CurrentMapPath[1024]; /// Path of the current map
|
|||
-- Visible and explored handling
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// Returns true, if forest on the map tile field
|
||||
static bool ForestOnMap(const unsigned int index)
|
||||
{
|
||||
return Map.CheckMask(index, MapFieldForest);
|
||||
}
|
||||
|
||||
static bool ForestOnMap(const Vec2i &pos)
|
||||
{
|
||||
Assert(Map.Info.IsPointOnMap(pos));
|
||||
return ForestOnMap(Map.getIndex(pos));
|
||||
}
|
||||
|
||||
/// Returns true, if rock on the map tile field
|
||||
static bool RockOnMap(const unsigned int index)
|
||||
{
|
||||
return Map.CheckMask(index, MapFieldRocks);
|
||||
}
|
||||
#if 0
|
||||
static bool RockOnMap(const Vec2i &pos)
|
||||
{
|
||||
Assert(Map.Info.IsPointOnMap(pos));
|
||||
return RockOnMap(Map.getIndex(pos));
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Marks seen tile -- used mainly for the Fog Of War
|
||||
**
|
||||
|
@ -123,7 +98,7 @@ void CMap::MarkSeenTile(const unsigned int index)
|
|||
FixNeighbors(MapFieldForest, 1, pos);
|
||||
} else if (seentile == this->Tileset.RemovedTree && tile != this->Tileset.RemovedTree) {
|
||||
FixTile(MapFieldForest, 1, pos);
|
||||
} else if (ForestOnMap(index)) {
|
||||
} else if (mf.ForestOnMap()) {
|
||||
FixTile(MapFieldForest, 1, pos);
|
||||
FixNeighbors(MapFieldForest, 1, pos);
|
||||
|
||||
|
@ -132,7 +107,7 @@ void CMap::MarkSeenTile(const unsigned int index)
|
|||
FixNeighbors(MapFieldRocks, 1, pos);
|
||||
} else if (seentile == this->Tileset.RemovedRock && tile != Map.Tileset.RemovedRock) {
|
||||
FixTile(MapFieldRocks, 1, pos);
|
||||
} else if (RockOnMap(index)) {
|
||||
} else if (mf.RockOnMap()) {
|
||||
FixTile(MapFieldRocks, 1, pos);
|
||||
FixNeighbors(MapFieldRocks, 1, pos);
|
||||
|
||||
|
@ -210,7 +185,7 @@ bool CMap::IsTerrainResourceOnMap(const Vec2i &pos, int resource) const
|
|||
{
|
||||
// TODO: Hard coded stuff.
|
||||
if (resource == WoodCost) {
|
||||
return ForestOnMap(pos);
|
||||
return Field(pos)->ForestOnMap();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -266,7 +241,6 @@ bool CMap::WallOnMap(const Vec2i &pos) const
|
|||
{
|
||||
Assert(Map.Info.IsPointOnMap(pos));
|
||||
return (Field(pos)->Flags & MapFieldWall) != 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,7 +279,7 @@ bool CMap::OrcWallOnMap(const Vec2i &pos) const
|
|||
*/
|
||||
bool CheckedCanMoveToMask(const Vec2i &pos, int mask)
|
||||
{
|
||||
return Map.Info.IsPointOnMap(pos) && !Map.CheckMask(pos, mask);
|
||||
return Map.Info.IsPointOnMap(pos) && CanMoveToMask(pos, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -324,7 +298,7 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
|
|||
for (int addy = 0; addy < type.TileHeight; ++addy) {
|
||||
for (int addx = 0; addx < type.TileWidth; ++addx) {
|
||||
if (Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) == false
|
||||
|| Map.CheckMask(pos.x + addx + index, mask) == true) {
|
||||
|| Map.Field(pos.x + addx + index)->CheckMask(mask) == true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1304,7 +1304,7 @@ void CButtonPanel::DoClicked(int button)
|
|||
// That or a bunker.
|
||||
//
|
||||
if ((NumSelected == 1 && Selected[0]->CurrentAction() == UnitActionStill
|
||||
&& Map.CoastOnMap(Selected[0]->tilePos))
|
||||
&& Map.Field(Selected[0]->tilePos)->CoastOnMap())
|
||||
|| !Selected[0]->CanMove()) {
|
||||
SendCommandUnload(*Selected[0], Selected[0]->tilePos, NoUnitP, flush);
|
||||
break;
|
||||
|
|
|
@ -340,7 +340,7 @@ CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos)
|
|||
*/
|
||||
bool CanBuildOn(const Vec2i &pos, int mask)
|
||||
{
|
||||
return (Map.Info.IsPointOnMap(pos) && !Map.CheckMask(pos, mask));
|
||||
return (Map.Info.IsPointOnMap(pos) && !Map.Field(pos)->CheckMask(mask));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,7 +393,7 @@ CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &p
|
|||
testmask = type.MovementMask;
|
||||
}
|
||||
/*secound part of if (!CanBuildOn(x + w, y + h, testmask)) */
|
||||
if (Map.CheckMask(index + pos.x + w, testmask)) {
|
||||
if (Map.Field(index + pos.x + w)->CheckMask(testmask)) {
|
||||
h = type.TileHeight;
|
||||
ontop = NULL;
|
||||
break;
|
||||
|
|
|
@ -130,7 +130,7 @@ VisitResult TerrainFinder::Visit(TerrainTraversal &terrainTraversal, const Vec2i
|
|||
return VisitResult_DeadEnd;
|
||||
}
|
||||
// Look if found what was required.
|
||||
if (Map.CheckMask(pos, resmask)) {
|
||||
if (Map.Field(pos)->CheckMask(resmask)) {
|
||||
if (resPos) {
|
||||
*resPos = pos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue