Class TCODMap

Class Documentation

class TCODMap

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.

Public Functions

TCODMap(int width, int height)

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

Parameters

width, height – The size of the map (in map cells).

TCODMap(const TCODMap&) = delete
TCODMap &operator=(const TCODMap&) = delete
inline TCODMap(TCODMap &&rhs) noexcept
inline TCODMap &operator=(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).

Parameters
  • map – In the C version, the map handler returned by the TCOD_map_new function.

  • x, y – Coordinate of the cell that we want to update.

  • isTransparent – If true, this cell will let the light pass else it will block the light.

  • isWalkable – If true, creatures can walk true this cell (it is not a wall).

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)

Parameters
  • map – In the C version, the map handler returned by the TCOD_map_new function.

  • walkable – Whether the cells should be walkable.

  • transparent – Whether the cells should be transparent.

void copy(const TCODMap *source)

You can copy an existing map into another.

You have to allocate the destination map first.

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)

Parameters
  • source – The map containing the source data.

  • dest – In C and Python version, the map where data is copied.

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 :

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). Original implementation here. Comparison of the algorithms : Check this.

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) 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))

Parameters
  • map – In the C version, the map handler returned by the TCOD_map_new function.

  • player_x, player_y – Position of the player in the map. 0 <= player_x < map width. 0 <= player_y < map height.

  • maxRadius – If > 0, the fov is only computed up to maxRadius cells away from the player. Else, the range is unlimited.

  • light_walls – Whether the wall cells near ground cells in fov must be in fov too.

  • algo – FOV algorithm to use.

bool isInFov(int x, int y) const

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

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)

Parameters
  • map – In the C version, the map handler returned by the TCOD_map_new function.

  • x, y – Coordinates of the cell we want to check. 0 <= x < map width. 0 <= y < map height.

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) const

bool 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
  • map – In the C version, the map handler returned by the TCOD_map_new function.

  • x, y – Coordinates of the cell we want to check. 0 <= x < map width. 0 <= y < map height.

bool isWalkable(int x, int y) const
int getWidth() const

You can retrieve the map size with :

int TCODMap::getWidth() const int TCODMap::getHeight() const

int 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

map – In the C version, the map handler returned by the TCOD_map_new function.

int getHeight() const
virtual ~TCODMap()
void setInFov(int x, int y, bool fov)
int getNbCells() const

Public Members

TCOD_map_t data

Friends

friend class TCODPath
friend class TCODDijkstra