Godot RGMap
godot::RGMap Class Reference

Class for managing maps for roguelike. More...

#include <rgmap.h>

Inheritance diagram for godot::RGMap:

Public Member Functions

Signals

PoolIntArray chunks_load_requested ()
 Signal. Emited when chunks need to be loaded. Emited on calling request_chunks_load function
 
PoolIntArray chunks_free_requested ()
 Signal. Emited when chunks need to be freed. Emited on calling request_chunks_load function
 
PoolIntArray chunks_render_requested ()
 Signal. Emited when chunks need to be rendered. Emited on calling request_chunks_render function
 
PoolIntArray chunks_hide_requested ()
 Signal. Emited when rendered chunks need to be hidden. Emited on calling request_chunks_render function
 
int chunk_loaded ()
 Signal. Emited when is loaded for the first time. Emited on calling load_chunk function
 
int chunk_freed ()
 Signal. Emited when chunk is freed from memory. Emited on calling free_chunk function
 
Tiles

int add_tile (String name, String display_name)
 Add new tile. Returns unique tile index. More...
 
void set_tile_transparency (int index, bool value)
 Set transparency of the tile.
 
void set_tile_passability (int index, bool value)
 Set passability of the tile.
 
void add_tile_property (String property_name, Variant default_value)
 Add custom property field for all tiles. More...
 
void set_tile_z_index (int index, int z_index)
 Set tile's drawing index.
 
void set_tile_texture_offset (int index, Vector2 offset)
 Set tile's texture offset.
 
void set_tile_texture (int index, Ref< Texture > texture)
 Set tile's texture.
 
void set_tile_normal_map (int index, Ref< Texture > texture)
 Set tile's normal map.
 
void set_tile_material (int index, Ref< Material > material)
 Set tile's material.
 
void set_tile_modulate (int index, Color color)
 Set tile's modulation color.
 
void set_tile_property (int index, String property_name, Variant new_value)
 Set value of custom property for specified tile.
 
int get_tiles_count ()
 Get number of tiles.
 
int get_tile_index (String name)
 Get tile index by name.
 
String get_tile_name (int index)
 Get tile name (unique)
 
String get_tile_display_name (int index)
 Get tile display name.
 
bool is_tile_passable (int index)
 Check if tile is passable.
 
bool is_tile_transparent (int index)
 Check if tile is transparent.
 
int get_tile_z_index (int index)
 Get tile's drawing index.
 
Vector2 get_tile_texture_offset (int index)
 Get tile's texture offset.
 
Ref< Texture > get_tile_texture (int index)
 Get tile's texture.
 
Ref< Texture > get_tile_normal_map (int index)
 Get tile's normal map.
 
Ref< Material > get_tile_material (int index)
 Get tile's material.
 
Color get_tile_modulate (int index)
 Get tile's modulation color.
 
Variant get_tile_property (int index, String property_name)
 Get value of custom tile property.
 
Ref< TileSet > generate_tileset ()
 Generate Tileset for using with 2d Tilemap.
 
Chunks

int get_chunk_index (Vector2 position)
 Get index of chunk which contains a given position.
 
Vector2 chunk_index_int_to_v2 (int index)
 Convert index of chunk from int to Vector2 format.
 
int chunk_index_v2_to_int (Vector2 index)
 Convert index of chunk from Vector2 to int format.
 
bool is_chunk_in_bounds (int index)
 Check if chunk is in bounds.
 
bool is_chunk_loaded (int index)
 Check if chunk is loaded.
 
void load_chunk (int index, PoolIntArray data=PoolIntArray())
 Load saved chunk to memory or generate a new chunk. "data" argument is optional.
 
PoolIntArray dump_chunk_data (int index)
 Returns all cell data for chunk as PoolIntArray.
 
void free_chunk (int index)
 Free chunk from memory.
 
void reset_chunk (int index)
 Clear all cell data in chunk.
 
bool is_chunk_rendered (int index)
 Check if chunk is rendered.
 
void set_chunk_rendered (int index, bool value)
 Set rendering status of chunk.
 
PoolIntArray get_loaded_chunks ()
 Get ids of loaded chunks.
 
PoolIntArray get_chunks_in_distance (Vector2 point, int distance)
 Get indexes of chunks forming a square grid with a given point in its center.
 
PoolIntArray get_chunks_to_load (Vector2 player_position)
 Get ids of chunks around player that needs to be loaded. More...
 
PoolIntArray get_chunks_to_free (Vector2 player_position)
 Get ids of chunks that are loaded, but not needed anymore because player is too far. More...
 
void request_chunks_load (Vector2 player_position)
 Request chunk load/unload depending on player_position and load_distance. More...
 
PoolIntArray get_rendered_chunks ()
 Get ids of rendered chunks.
 
PoolIntArray get_chunks_to_render (Vector2 player_position)
 Get ids of chunks around player that needs to be rendered. More...
 
PoolIntArray get_chunks_to_hide (Vector2 player_position)
 Get ids of chunks that are rendered, but not needed anymore because player is too far. More...
 
void request_chunks_render (Vector2 player_position)
 Request chunk render/hide depending on player_position and render_distance. More...
 
Cells

int get_local_index (Vector2 position)
 Get local index of cell within a chunk.
 
int get_value (Vector2 position)
 Get value of cell.
 
String get_name (Vector2 position)
 Get name of cell.
 
String get_display_name (Vector2 position)
 Get display name of cell.
 
Variant get_property (Vector2 position, String property_name)
 Get custom property value of cell's tile.
 
bool is_in_bounds (Vector2 position)
 Check if cell is in bounds.
 
bool is_transparent (Vector2 position)
 Check if cell is transparent.
 
bool is_passable (Vector2 position)
 Check if cell is passable.
 
bool is_visible (Vector2 position)
 Check if cell is visible.
 
bool is_discovered (Vector2 position)
 Check if cell is discovered.
 
void set_value (Vector2 position, int value)
 Set value of cell.
 
void set_visibility (Vector2 position, bool value)
 Set visibility of cell.
 
void set_discovered (Vector2 position, bool value)
 Set cell discovered/undiscovered.
 
View and pathfinding

PoolVector2Array rpas_calc_visible_cells_from (Vector2 center, int radius)
 Get list of cells visible from position within radius using RPAS algorithm.
 
void calculate_fov (Vector2 view_position)
 Calculate visibility from given position.
 
void add_pathfinding_exception (Vector2 position, bool value)
 Allow/disallow patfinding for this cell ignoring passability.
 
void remove_pathfinding_exception (Vector2 position)
 Remove all pathfinding exceptions for this cell if they exist.
 
PoolVector2Array show_pathfinding_exceptions (bool exception_type)
 Show all pathfinding exceptions of a type. More...
 
bool is_pathfinding_allowed (Vector2 position)
 Check if pathfinding on this cell is allowed.
 
PoolVector2Array find_path (Vector2 start, Vector2 end, Rect2 pathfinding_zone)
 Find path from start to end using A* algorithm. More...
 
PoolVector2Array find_discovered_path (Vector2 start, Vector2 end, Rect2 pathfinding_zone)
 Find path from start to end using A* algorithm including only discovered cells. More...
 
PoolVector2Array get_line (Vector2 start, Vector2 end)
 Get a set of points in Bresenham's line. More...
 
PoolVector2Array get_line_orthogonal (Vector2 start, Vector2 end)
 Get a set of points in Bresenham's line (No diagonals allowed)
 
Vector2 raycast_vision (Vector2 start, Vector2 end)
 Cast ray from start to end and return position where vision is blocked by an obstacle.
 
Vector2 raycast_path (Vector2 start, Vector2 end)
 Cast ray from start to end and return position where path is blocked by an obstacle.
 
bool visibility_between (Vector2 start, Vector2 end, int max_distance)
 Check if end point is visisble from start point. More...
 
Editing

void clean_map ()
 Free all chunks and forget pathfinding exceptions.
 
void resize_map (Vector2 new_size, Vector2 new_chunk_size)
 Change size and chunk size of the map.
 
void place_map (RGMap *another_map, Vector2 start)
 Place another map inside this map.
 
void draw_line (Vector2 start, Vector2 end, int value)
 Draw straight line using Bresenham's line algorithm.
 
void draw_line_orthogonal (Vector2 start, Vector2 end, int value)
 Draw orthogonal straight line (No diagonals allowed)
 
void draw_rect (Rect2 rect, int value)
 Draw rect borders.
 
void fill_rect (Rect2 rect, int value)
 Fill rect.
 
void draw_ellipse (Vector2 center, Vector2 radius, float start_angle, float end_angle, int value)
 Draw ellipse using Bresenham's midpoint algorithm. More...
 
void draw_ellipse_orthogonal (Vector2 center, Vector2 radius, float start_angle, float end_angle, int value)
 Draw orthogonal ellipse (No diagonals allowed)
 
void fill_ellipse (Vector2 center, Vector2 radius, float start_angle, float end_angle, int value)
 Fill ellipse.
 
void draw_circle (Vector2 center, float radius, int value)
 Draw circle.
 
void draw_circle_orthogonal (Vector2 center, float radius, int value)
 Draw circle (No diagonals allowed)
 
void fill_circle (Vector2 center, float radius, int value)
 Fill circle.
 
void draw_arc (Vector2 center, float radius, float start_angle, float end_angle, int value)
 Draw arc.
 
void draw_arc_orthogonal (Vector2 center, float radius, float start_angle, float end_angle, int value)
 Draw orthogonal arc (No diagonals allowed)
 
void fill_arc (Vector2 center, float radius, float start_angle, float end_angle, int value)
 Fill arc.
 
Entities

int add_entity (Vector2 position, bool passability, bool transparency)
 Add new entity to the map. Returns id given to a new entity.
 
void remove_entity (int id)
 Remove entity from memory. The id of this entity will also be given to a new entity.
 
void move_entity (int id, Vector2 position)
 Move entity to a new position.
 
void set_entity_transparency (int id, bool value)
 Change entity transparency.
 
void set_entity_passability (int id, bool value)
 Change entity passability.
 
void set_entity_discovered (int id, bool value)
 Change memory status of entity.
 
bool is_entity_visible (int id)
 Check if entity is visible.
 
bool is_entity_transparent (int id)
 Check if entity is transparent;.
 
bool is_entity_passable (int id)
 Check if entity is passable.
 
bool is_entity_discovered (int id)
 Check if entity is discovered.
 
bool is_entity_chunk_loaded (int id)
 Check if entity is on loaded chunk.
 
bool is_entity_chunk_rendered (int id)
 Check if entity is on rendered chunk.
 
Vector2 get_entity_position (int id)
 Get position of the entity.
 
PoolIntArray get_entities_in_position (Vector2 position)
 Find ids of all entities in position.
 
PoolIntArray get_entities_in_rect (Rect2 rect)
 Find ids of all entities in rect.
 
PoolIntArray get_entities_in_radius (Vector2 position, int radius)
 Find ids of all entities in radius.
 
PoolIntArray get_entities_in_chunk (int chunk_index)
 Find ids of all entities in chunk.
 
Saving and Loading

PoolIntArray dump_map_data ()
 Save map data.
 
void load_map_data (PoolIntArray map_data)
 Load map data.
 

Public Attributes

Map Properties

Vector2 chunk_size = Vector2(50,50)
 Size of one chunk (Default: 50x50)
 
Vector2 size = Vector2(3,3)
 Size of the whole map in chunks (Default: 3x3)
 
int load_distance = 1
 Number of chunks loaded around the player. More...
 
int render_distance = 1
 Number of chunks rendered around the player. More...
 
bool allow_diagonal_pathfinding = true
 Allow/Disallow diagonal pathfinding.
 
FOV Properties

int fov_radius = 15
 Radius in which cells are visible for player.
 
float RPAS_RADIUS_FUDGE = 1.0 / 3.0
 How smooth the edges of the vision bubble are. Between 0 and 1.
 
bool RPAS_NOT_VISIBLE_BLOCKS_VISION = true
 If this is false, some cells will unexpectedly be visible.
 
int RPAS_RESTRICTIVENESS = 1
 Determines how restrictive the algorithm is. More...
 
bool RPAS_VISIBLE_ON_EQUAL = true
 If false, an obstruction will obstruct its endpoints.
 

Standard methods

 RGMap ()
 
 ~RGMap ()
 
void _init ()
 
void _ready ()
 
static void _register_methods ()
 

Detailed Description

Class for managing maps for roguelike.

Member Function Documentation

◆ add_tile()

int RGMap::add_tile ( String  name,
String  display_name 
)

Add new tile. Returns unique tile index.

Parameters
nameUnique name of the tile. Needed for searching tiles by name
display_nameName that will be shown to the player. Can be a duplicate

◆ add_tile_property()

void RGMap::add_tile_property ( String  property_name,
Variant  default_value 
)

Add custom property field for all tiles.

Parameters
property_nameName of new property field that will be added to all tiles
default_valueDefault value for that property. Can be any type

◆ draw_ellipse()

void RGMap::draw_ellipse ( Vector2  center,
Vector2  radius,
float  start_angle,
float  end_angle,
int  value 
)

Draw ellipse using Bresenham's midpoint algorithm.

Tweaked version of code from here: https://www.geeksforgeeks.org/midpoint-ellipse-drawing-algorithm/

◆ find_discovered_path()

PoolVector2Array RGMap::find_discovered_path ( Vector2  start,
Vector2  end,
Rect2  pathfinding_zone 
)

Find path from start to end using A* algorithm including only discovered cells.

Returns PoolVector2Array

Parameters
startStart point
endTarget point
pathfinding_zoneRect2 zone where pathfinding is calculated

◆ find_path()

PoolVector2Array RGMap::find_path ( Vector2  start,
Vector2  end,
Rect2  pathfinding_zone 
)

Find path from start to end using A* algorithm.

Returns PoolVector2Array

Parameters
startStart point
endTarget point
pathfinding_zoneRect2 zone where pathfinding is calculated

◆ get_chunks_to_free()

PoolIntArray RGMap::get_chunks_to_free ( Vector2  player_position)

Get ids of chunks that are loaded, but not needed anymore because player is too far.

Parameters
player_positionVector2 position of the player Uses load_distance parameter to define the radius

◆ get_chunks_to_hide()

PoolIntArray RGMap::get_chunks_to_hide ( Vector2  player_position)

Get ids of chunks that are rendered, but not needed anymore because player is too far.

Parameters
player_positionVector2 position of the player Uses render_distance parameter to define the radius

◆ get_chunks_to_load()

PoolIntArray RGMap::get_chunks_to_load ( Vector2  player_position)

Get ids of chunks around player that needs to be loaded.

Parameters
player_positionVector2 position of the player Uses load_distance parameter to define the radius Skips chunks that were already loaded

◆ get_chunks_to_render()

PoolIntArray RGMap::get_chunks_to_render ( Vector2  player_position)

Get ids of chunks around player that needs to be rendered.

Parameters
player_positionVector2 position of the player Uses render_distance parameter to define the radius Skips chunks that were already rendered

◆ get_line()

PoolVector2Array RGMap::get_line ( Vector2  start,
Vector2  end 
)

Get a set of points in Bresenham's line.

Based on Python implementation from here: http://www.roguebasin.com/index.php/Bresenham%27s_Line_Algorithm

◆ request_chunks_load()

void RGMap::request_chunks_load ( Vector2  player_position)

Request chunk load/unload depending on player_position and load_distance.

Emits "chunks_load_requested" and "chunks_free_requested" signals Will produce the same result until chunks will be loaded/freed from other script Does nothing if all needed chunks are loaded and all unneeded chunks are freed

Parameters
player_positionVector2 position of the player Uses load_distance parameter to define the radius

◆ request_chunks_render()

void RGMap::request_chunks_render ( Vector2  player_position)

Request chunk render/hide depending on player_position and render_distance.

Emits "chunks_render_requested" and "chunks_hide_requested" signals Will produce the same result until chunks will be rendered/hidden from other script Does nothing if all needed chunks are rendered and all unneeded chunks are hidden

Parameters
player_positionVector2 position of the player Uses render_distance parameter to define the radius

◆ show_pathfinding_exceptions()

PoolVector2Array RGMap::show_pathfinding_exceptions ( bool  exception_type)

Show all pathfinding exceptions of a type.

Parameters
exception_typetrue for allowed cells, false for disallowed cells

◆ visibility_between()

bool RGMap::visibility_between ( Vector2  start,
Vector2  end,
int  max_distance 
)

Check if end point is visisble from start point.

Parameters
startStart point
endTarget point
max_distanceMaximum distance at which points are visible

Member Data Documentation

◆ load_distance

int godot::RGMap::load_distance = 1

Number of chunks loaded around the player.

Excluding the chunk where player stands Default: 1 (3x3 grid)

◆ render_distance

int godot::RGMap::render_distance = 1

Number of chunks rendered around the player.

Excluding the chunk where player stands Default: 1 (3x3 grid)

◆ RPAS_RESTRICTIVENESS

int godot::RGMap::RPAS_RESTRICTIVENESS = 1

Determines how restrictive the algorithm is.

0 - if you have a line to the near, center, or far, it will return as visible
1 - if you have a line to the center and at least one other corner it will return as visible
2 - if you have a line to all the near, center, and far, it will return as visible


The documentation for this class was generated from the following files: