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

C++ : void TCODMap::computeFov(int player_x, int player_y, int maxRadius=0)
C   : void TCOD_map_compute_fov(TCOD_map_t map, int player_x, int player_y, int max_radius)

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.

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 (unlimited range)
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);