< index
< 12. Field of view toolkit
< 12.1 Building the map

=====================================
12.2 Computing the field of view
=====================================

> 12.3 Reading fov information
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, 
               NB_FOV_ALGORITHMS } TCOD_fov_algorithm_t;
C++ : void TCODMap::computeFov(int playerX,int playerY, int maxRadius=0,bool light_walls = true, TCOD_fov_algorithm_t algo = FOV_BASIC)
C   : void TCOD_map_compute_fov(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls, TCOD_fov_algorithm_t algo)
Py  : map_compute_fov(map, player_x, player_y, max_radius=0, light_walls=True, algo=FOV_BASIC )

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). Comparison of the algorithms :
Check this.
ParameterDescription
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_wallsWether the wall cells near ground cells in fov must be in fov too.
algoFOV algorithm to use.

Example :

C++ : 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)
C   : 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
Py  : 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)) 

insert a comment