Gamedev Framework (gf)  0.11.0 A C++14 framework for 2D games
gf::SquareMap Class Reference

A square map. More...

#include <gf/Map.h>

## Public Member Functions

SquareMap (Vector2i size)
Constructor. More...

Vector2i getSize () const
Get the size of the map. More...

PositionRange< int > getRange () const
Get a range of the positions of the map. More...

Cell properties
void setCell (Vector2i pos, CellFlags flags)
Set the properties of a cell. More...

void reset (CellFlags flags)
Initialize the cells with some properties. More...

void setTransparent (Vector2i pos)
Make a cell transparent. More...

bool isTransparent (Vector2i pos) const
Check if a cell is transparent. More...

void setWalkable (Vector2i pos)
Make a cell walkable. More...

bool isWalkable (Vector2i pos) const
Check if a cell is walkable. More...

void setEmpty (Vector2i pos)
Make a cell empty. More...

Field of Vision
void clearFieldOfVision ()
Make the whole map not visible. More...

void clearExplored ()
Make the whole map not explored. More...

void computeFieldOfVision (Vector2i pos, int maxRadius=0, FieldOfVisionLimit limit=FieldOfVisionLimit::Included, FieldOfVision algorithm=FieldOfVision::Basic)
Compute a field of vision. More...

void computeLocalFieldOfVision (Vector2i pos, int maxRadius=0, FieldOfVisionLimit limit=FieldOfVisionLimit::Included, FieldOfVision algorithm=FieldOfVision::Basic)
Compute a local field of vision. More...

bool isInFieldOfVision (Vector2i pos) const
Check if a cell is visible. More...

bool isExplored (Vector2i pos) const
Check if a cell is explored. More...

Route
std::vector< Vector2icomputeRoute (Vector2i origin, Vector2i target, float diagonalCost=Sqrt2, Route algorithm=Route::AStar)
Compute a route between two points. More...

## Detailed Description

A square map.

A square map is a model of map where cells are organized in a square grid. This type of map is quite common in games. gf provides some useful algorithms related to square maps: field of vision, route finding.

A cell can be transparent and/or walkable. By default, all cells are neither transparent nor walkable i.e. they are walls. The transparent property of a cell is used to compute the field of vision. The walkable property of a cell is used to compute routes. A cell can be transparent and not walkable (e.g. lava or water), it can be walkable and not transparent (e.g. a secret passage).

gf::CellProperty

## ◆ SquareMap()

 gf::SquareMap::SquareMap ( Vector2i size )

Constructor.

Parameters
 size The size of the map

## ◆ clearExplored()

 void gf::SquareMap::clearExplored ( )

Make the whole map not explored.

You should call this function before exploring a new map.

computeFieldOfVision()

## ◆ clearFieldOfVision()

 void gf::SquareMap::clearFieldOfVision ( )

Make the whole map not visible.

You should call this function before computing a new field of vision.

computeFieldOfVision()

## ◆ computeFieldOfVision()

 void gf::SquareMap::computeFieldOfVision ( Vector2i pos, int maxRadius = 0, FieldOfVisionLimit limit = FieldOfVisionLimit::Included, FieldOfVision algorithm = FieldOfVision::Basic )

Compute a field of vision.

The map is not cleared before computing the field of vision. The algorithm use the transparent property of the cells. After calling this function, some cells are marked visible.

This algorithm marks visible cells as explored.

Parameters
 pos The position of the entity maxRadius The maximum radius that the entity can see limit Is the limit included in the field of vision? algorithm The algorithm to use for computing the field of vision
clearFieldOfVision(), isInFieldOfVision()

## ◆ computeLocalFieldOfVision()

 void gf::SquareMap::computeLocalFieldOfVision ( Vector2i pos, int maxRadius = 0, FieldOfVisionLimit limit = FieldOfVisionLimit::Included, FieldOfVision algorithm = FieldOfVision::Basic )

Compute a local field of vision.

The map is not cleared before computing the field of vision. The algorithm use the transparent property of the cells. After calling this function, some cells are marked visible.

This algorithm does not mark visible cells as explored. It can be used for computing an ennemy field of view without modifying the explored area of the hero.

Parameters
 pos The position of the entity maxRadius The maximum radius that the entity can see limit Is the limit included in the field of vision? algorithm The algorithm to use for computing the field of vision
clearFieldOfVision(), isInFieldOfVision()

## ◆ computeRoute()

 std::vector gf::SquareMap::computeRoute ( Vector2i origin, Vector2i target, float diagonalCost = Sqrt2, Route algorithm = Route::AStar )

Compute a route between two points.

The algorithm use the walkable property of the cells. Diagonal movement can be allowed and its cost can be adjusted (defaults to $$\sqrt{2}$$).

Parameters
 origin The origin of the route target The target of the route diagonalCost The cost of going diagonal between two cells (0 means no diagonal movement) algorithm The algorithm to use for computing the route
Returns
The route between the two points (included)

## ◆ getRange()

 PositionRange gf::SquareMap::getRange ( ) const

Get a range of the positions of the map.

Returns
A 2D range of all the positions
Array2D::getPositionRange()

## ◆ getSize()

 Vector2i gf::SquareMap::getSize ( ) const

Get the size of the map.

Returns
The size of the map

## ◆ isExplored()

 bool gf::SquareMap::isExplored ( Vector2i pos ) const

Check if a cell is explored.

Cells are explored if they have been in the field of vision after a call to clearExplored().

computeFieldOfVision(), isInFieldOfVision()

## ◆ isInFieldOfVision()

 bool gf::SquareMap::isInFieldOfVision ( Vector2i pos ) const

Check if a cell is visible.

Cells can be made visible by computing a field of vision.

Returns
True if the cell is visible
computeFieldOfVision()

## ◆ isTransparent()

 bool gf::SquareMap::isTransparent ( Vector2i pos ) const

Check if a cell is transparent.

Returns
True if the cell is transparent
setTransparent()

## ◆ isWalkable()

 bool gf::SquareMap::isWalkable ( Vector2i pos ) const

Check if a cell is walkable.

setWalkable()

## ◆ reset()

 void gf::SquareMap::reset ( CellFlags flags )

Initialize the cells with some properties.

Parameters
 flags The properties to set

## ◆ setCell()

 void gf::SquareMap::setCell ( Vector2i pos, CellFlags flags )

Set the properties of a cell.

This function directly set all the properties of a cell. You should use the other functions that set a particular property.

Parameters
 pos The position of the cell flags The properties of the cell
setTransparent(), setWalkable(), setEmpty()

## ◆ setEmpty()

 void gf::SquareMap::setEmpty ( Vector2i pos )

Make a cell empty.

An empty cell is walkable and transparent

Parameters
 pos The position of the cell

## ◆ setTransparent()

 void gf::SquareMap::setTransparent ( Vector2i pos )

Make a cell transparent.

Parameters
 pos The position of the cell