libtcod
Loading...
Searching...
No Matches
TCODMap Class Reference

#include <fov.hpp>

Public Member Functions

 TCODMap (int width, int height)
 First, you have to allocate a map of the same size as your dungeon.
 TCODMap (const TCODMap &)=delete
TCODMapoperator= (const TCODMap &)=delete
 TCODMap (TCODMap &&rhs) noexcept
TCODMapoperator= (TCODMap &&rhs) noexcept
void setProperties (int x, int y, bool isTransparent, bool isWalkable)
 Then, build your dungeon by defining which cells let the light pass (by default, all cells block the light) and which cells are walkable (by default, all cells are not-walkable).
void clear (bool transparent=false, bool walkable=false)
 You can clear an existing map (setting all cells to the chosen walkable/transparent values) with:void TCODMap::clear() void TCODMap::clear(bool transparent) void TCODMap::clear(bool transparent, bool walkable).
void copy (const TCODMap *source)
 You can copy an existing map into another.
void computeFov (int playerX, int playerY, int maxRadius=0, bool light_walls=true, TCOD_fov_algorithm_t algo=FOV_BASIC)
 Once your map is allocated and empty cells have been defined, you can calculate the field of view with :
bool isInFov (int x, int y) const
 Once your computed the field of view, you can know if a cell is visible with :
bool isTransparent (int x, int y) const
 You can also retrieve transparent/walkable information with :bool TCODMap::isTransparent(int x, int y) const bool TCODMap::isWalkable(int x, int y) constbool TCOD_map_is_transparent(TCOD_map_t map, int x, int y) bool TCOD_map_is_walkable(TCOD_map_t map, int x, int y)map_is_transparent(map, x, y) map_is_walkable(map, x, y)bool TCODMap::isTransparent(int x, int y) bool TCODMap::isWalkable(int x, int y).
bool isWalkable (int x, int y) const
int getWidth () const
 You can retrieve the map size with :int TCODMap::getWidth() const int TCODMap::getHeight() constint TCOD_map_get_width(TCOD_map_t map) int TCOD_map_get_height(TCOD_map_t map)map_get_width(map) map_get_height(map)int TCODMap::getWidth() int TCODMap::getHeight().
int getHeight () const
void setInFov (int x, int y, bool fov)
int getNbCells () const

Public Attributes

TCOD_map_t data {}

Friends

class TCODPath
class TCODDijkstra

Detailed Description

This toolkit allows one to easily calculate the potential visible set of map cells from the player position. A cell is potentially visible if the line of sight from the player to the cell in unobstructed.

Constructor & Destructor Documentation

◆ TCODMap()

TCODMap::TCODMap ( int width,
int height )

First, you have to allocate a map of the same size as your dungeon.

Parameters
width,heightThe size of the map (in map cells).

Member Function Documentation

◆ clear()

void TCODMap::clear ( bool transparent = false,
bool walkable = false )

You can clear an existing map (setting all cells to the chosen walkable/transparent values) with:void TCODMap::clear() void TCODMap::clear(bool transparent) void TCODMap::clear(bool transparent, bool walkable).

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.
walkableWhether the cells should be walkable.
transparentWhether the cells should be transparent.

◆ computeFov()

void TCODMap::computeFov ( int playerX,
int playerY,
int maxRadius = 0,
bool light_walls = true,
TCOD_fov_algorithm_t algo = FOV_BASIC )

Once your map is allocated and empty cells have been defined, you can calculate the field of view with :

typedef enum { FOV_BASIC,
           FOV_DIAMOND,
           FOV_SHADOW,
           FOV_PERMISSIVE_0,FOV_PERMISSIVE_1,FOV_PERMISSIVE_2,FOV_PERMISSIVE_3,
           FOV_PERMISSIVE_4,FOV_PERMISSIVE_5,FOV_PERMISSIVE_6,FOV_PERMISSIVE_7,FOV_PERMISSIVE_8,
           FOV_RESTRICTIVE,
           NB_FOV_ALGORITHMS } TCOD_fov_algorithm_t;
        

FOV_BASIC : classic libtcod fov algorithm (ray casted from the player to all the cells on the submap perimeter) FOV_DIAMOND : based on this algorithm FOV_SHADOW : based on this algorithm FOV_PERMISSIVE_x : based on this algorithm Permissive has a variable permissiveness parameter. You can either use the constants FOV_PERMISSIVE_x, x between 0 (the less permissive) and 8 (the more permissive), or using the macro FOV_PERMISSIVE(x). FOV_RESTRICTIVE : Mingos' Restrictive Precise Angle Shadowcasting (MRPAS).

void TCODMap::computeFov(int playerX, int playerY) void TCODMap::computeFov(int playerX, int playerY, int maxRadius) void TCODMap::computeFov(int playerX, int playerY, int maxRadius,bool light_walls) void TCODMap::computeFov(int playerX, int playerY, int maxRadius,bool light_walls, TCODFOVTypes algo)

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.
player_x,player_yPosition of the player in the map. 0 <= player_x < map width. 0 <= player_y < map height.
maxRadiusIf > 0, the fov is only computed up to maxRadius cells away from the player. Else, the range is unlimited.
light_wallsWhether the wall cells near ground cells in fov must be in fov too.
algoFOV algorithm to use.

TCODMap *map = new TCODMap(50,50); // allocate the map map->setProperties(10,10,true,true); // set a cell as 'empty' map->computeFov(10,10); // calculate fov from the cell 10x10 (basic raycasting, unlimited range, walls lighting on)

TCOD_map_t map = TCOD_map_new(50,50); TCOD_map_set_properties(map,10,10,true,true); TCOD_map_compute_fov(map,10,10,0,true,FOV_SHADOW); // using shadow casting

map = libtcod.map_new(50,50) libtcod.map_set_properties(map,10,10,True,True) libtcod.map_compute_fov(map,10,10,0,True,libtcod.FOV_PERMISSIVE(2))

◆ copy()

void TCODMap::copy ( const TCODMap * source)

You can copy an existing map into another.

You have to allocate the destination map first.

Parameters
sourceThe map containing the source data.
destIn C and Python version, the map where data is copied.

TCODMap * map = new TCODMap(50,50); // allocate the map map->setProperties(10,10,true,true); // set a cell as 'empty' TCODMap * map2 = new TCODMap(10,10); // allocate another map map2->copy(map); // copy map data into map2, reallocating it to 50x50

TCOD_map_t map = TCOD_map_new(50,50); TCOD_map_t map2 = TCOD_map_new(10,10); TCOD_map_set_properties(map,10,10,true,true); TCOD_map_copy(map,map2);

map = libtcod.map_new(50,50) map2 = libtcod.map_new(10,10) libtcod.map_set_properties(map,10,10,True,True) libtcod.map_copy(map,map2)

◆ getWidth()

int TCODMap::getWidth ( ) const

You can retrieve the map size with :int TCODMap::getWidth() const int TCODMap::getHeight() constint TCOD_map_get_width(TCOD_map_t map) int TCOD_map_get_height(TCOD_map_t map)map_get_width(map) map_get_height(map)int TCODMap::getWidth() int TCODMap::getHeight().

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.

◆ isInFov()

bool TCODMap::isInFov ( int x,
int y ) const

Once your computed the field of view, you can know if a cell is visible with :

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.
x,yCoordinates of the cell we want to check. 0 <= x < map width. 0 <= y < map height.

TCODMap *map = new TCODMap(50,50); // allocate the map map->setProperties(10,10,true,true); // set a cell as 'empty' map->computeFov(10,10); // calculate fov from the cell 10x10 bool visible=map->isInFov(10,10); // is the cell 10x10 visible ?

TCOD_map_t map = TCOD_map_new(50,50); TCOD_map_set_properties(map,10,10,true,true); TCOD_map_compute_fov(map,10,10); bool visible = TCOD_map_is_in_fov(map,10,10);

map = libtcod.map_new(50,50) libtcod.map_set_properties(map,10,10,True,True) libtcod.map_compute_fov(map,10,10) visible = libtcod.map_is_in_fov(map,10,10)

◆ isTransparent()

bool TCODMap::isTransparent ( int x,
int y ) const

You can also retrieve transparent/walkable information with :bool TCODMap::isTransparent(int x, int y) const bool TCODMap::isWalkable(int x, int y) constbool TCOD_map_is_transparent(TCOD_map_t map, int x, int y) bool TCOD_map_is_walkable(TCOD_map_t map, int x, int y)map_is_transparent(map, x, y) map_is_walkable(map, x, y)bool TCODMap::isTransparent(int x, int y) bool TCODMap::isWalkable(int x, int y).

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.
x,yCoordinates of the cell we want to check. 0 <= x < map width. 0 <= y < map height.

◆ setProperties()

void TCODMap::setProperties ( int x,
int y,
bool isTransparent,
bool isWalkable )

Then, build your dungeon by defining which cells let the light pass (by default, all cells block the light) and which cells are walkable (by default, all cells are not-walkable).

Parameters
mapIn the C version, the map handler returned by the TCOD_map_new function.
x,yCoordinate of the cell that we want to update.
isTransparentIf true, this cell will let the light pass else it will block the light.
isWalkableIf true, creatures can walk true this cell (it is not a wall).

The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/fov.hpp