|
libtcod
|
#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 | |
| TCODMap & | operator= (const TCODMap &)=delete |
| TCODMap (TCODMap &&rhs) noexcept | |
| 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). | |
| 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 |
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.
| TCODMap::TCODMap | ( | int | width, |
| int | height ) |
First, you have to allocate a map of the same size as your dungeon.
| width,height | The size of the map (in map cells). |
| 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).
| 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 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)
| 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. |
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))
| void TCODMap::copy | ( | const TCODMap * | source | ) |
You can copy an existing map into another.
You have to allocate the destination map first.
| source | The map containing the source data. |
| dest | In 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)
| 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().
| map | In the C version, the map handler returned by the TCOD_map_new function. |
| bool TCODMap::isInFov | ( | int | x, |
| int | y ) const |
Once your computed the field of view, you can know if a cell is visible with :
| 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. |
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)
| 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).
| 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. |
| 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).
| 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). |