Enabled highground check for field of view calculation

This commit is contained in:
alyokhin 2021-10-21 21:53:35 +03:00
parent 498e03b088
commit db2983bce8
3 changed files with 22 additions and 6 deletions

View file

@ -113,10 +113,11 @@ private:
uint16_t OpaqueFields {MapFieldOpaque}; /// Flags for opaque MapFields
} Settings;
Vec2i currTilePos {0, 0}; /// Current work tile pos in global (Map) system coordinates
uint8_t currOctant {0}; /// Current octant
Vec2i Origin {0, 0}; /// Position of the spectator in the global (Map) coordinate system
uint16_t OpaqueFields {0}; /// Flags for opaque MapTiles for current calculation
Vec2i currTilePos {0, 0}; /// Current work tile pos in global (Map) system coordinates
uint8_t currOctant {0}; /// Current octant
Vec2i Origin {0, 0}; /// Position of the spectator in the global (Map) coordinate system
uint8_t Elevation {0}; /// highground elevation level of origin
uint16_t OpaqueFields {0}; /// Flags for opaque MapTiles for current calculation
const CPlayer *Player {nullptr}; /// Pointer to player to set FoV for
const CUnit *Unit {nullptr}; /// Pointer to unit to calculate FoV for
@ -150,8 +151,12 @@ inline bool CFieldOfView::SetCurrentTile(const int16_t col, const int16_t row)
inline bool CFieldOfView::IsTileOpaque() const
{
/// FIXME: add high-/lowground
return (Map.Field(currTilePos.x, currTilePos.y)->Flags & OpaqueFields);
const CMapField &mf = *Map.Field(currTilePos.x, currTilePos.y);
if (this->Elevation > mf.getElevation()) {
return false;
} else if (this->Elevation < mf.getElevation()) {
return true;
} else return (mf.Flags & OpaqueFields);
}
inline void CFieldOfView::MarkTile()

View file

@ -239,6 +239,10 @@ public:
#ifdef DEBUG
int64_t lastAStarCost; /// debugging pathfinder
#endif
uint8_t getElevation() const { return this->ElevationLevel; }
void setElevation(const uint8_t newLevel) { this->ElevationLevel = newLevel; }
private:
#ifdef DEBUG
unsigned int tilesetTile; /// tileset tile number
@ -253,6 +257,10 @@ public:
CUnitCache UnitCache; /// A unit on the map field.
CMapFieldPlayerInfo playerInfo; /// stuff related to player
private:
uint8_t ElevationLevel {0}; /// highground elevation level
};
extern PixelSize PixelTileSize; /// Size of a tile in pixels

View file

@ -413,6 +413,8 @@ void CFieldOfView::PrepareShadowCaster(const CPlayer &player, const CUnit &unit,
{
Player = &player;
Unit = &unit;
/// TODO: maybe should set current level + 1 for units with 'elevated' flag (f.e. towers)
Elevation = Map.Field(pos.x, pos.y)->getElevation();
map_setFoV = marker;
}
@ -420,6 +422,7 @@ void CFieldOfView::ResetShadowCaster()
{
Player = nullptr;
Unit = nullptr;
Elevation = 0;
map_setFoV = nullptr;
currTilePos = { 0, 0 };