Roguelike
 All Classes Namespaces Functions Variables Typedefs Friends Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
WorldMap Class Reference

#include <world_map.h>

Public Member Functions

 WorldMap ()
 
const std::vector< std::vector
< MapTile > > & 
get_map ()
 

Private Types

typedef std::vector
< std::vector< MapTile > > 
MapTileMatrix
 

Private Member Functions

bool out_of_bounds (int row, int col)
 
int count_in_surrounding_tiles (int row, int col, MapTile tile_type)
 
void starting_noise (int border)
 
void smoothing_pass (MapTile tile_type, int threshold)
 
void generate_land_mass ()
 
void set_land_or_water (int row, int col, int mod, bool more_water)
 
void ocean_borders (int border)
 
void generate_beaches ()
 

Private Attributes

std::vector< std::vector
< MapTile > > 
map
 
int height
 
int width
 

Detailed Description

A representation of the game's world map. The world map is finite and represented by a two-dimensional array, like literally everything else in the game. The map takes care of its own generation in its constructor, then the map is passed to the outside world by a call to get_map().

Member Typedef Documentation

typedef std::vector<std::vector<MapTile> > WorldMap::MapTileMatrix
private

A self-explanatory typedef for the base model for this class.

Constructor & Destructor Documentation

WorldMap::WorldMap ( )

The main constructor, which also generates the world's continents.

Member Function Documentation

int WorldMap::count_in_surrounding_tiles ( int  row,
int  col,
MapTile  tile_type 
)
private

Counts the number of occurences of the given MapTile type in the 8 tiles surrounding the given point.

Parameters
row
col
tile_type- the type of MapTile to query for
Returns
an integer result of the query.
void WorldMap::generate_beaches ( )
private

Generates beaches at the borders of all land and water tiles.

void WorldMap::generate_land_mass ( )
private

Generates the main land mass in the water by calling smoothing_pass in sequence with different parameters on both land and water tiles.

const std::vector< std::vector< MapTile > > & WorldMap::get_map ( )

Returns a reference to the world map.

Returns
a reference to the world map.
void WorldMap::ocean_borders ( int  border)
private

Will generate an ocean border with the given width around the map.

Parameters
border- the desired width of the border.
bool WorldMap::out_of_bounds ( int  row,
int  col 
)
private

Determines whether a given row-column pair is out of bounds on the world map matrix.

Parameters
row
col
Returns
a boolean denoting whether the point is out of bounds.
void WorldMap::set_land_or_water ( int  row,
int  col,
int  mod,
bool  more_water 
)
private

Has a chance of setting a given tile to either a land or water tile. This is for preliminary continent generation in the world.

Parameters
row
col
mod- the inverse of the chance that the given tile will be turned to water/land (for more_water=true/false respectively)
more_water- Should be set to 'true' if the given tile should be more likely to be set to water, and 'false' if the given tile should be more likely to be set to land.
void WorldMap::smoothing_pass ( MapTile  tile_type,
int  threshold 
)
private

Will loop through the world map. On each tile, if the number of surrounding tiles of the given type is greater or equal to the given "threshold", there is a 1/(8 - num_surrounding_tiles) chance that the tile in question will be changed to tile_type. This function is relatively portable, and could be ported to any number of other situations. When applied sequentially with different thresholds (as in generate_land_mass()), will produce a passable world.

Parameters
tile_type- the type of tile that will be changed.
threshold- The number of surrounding tiles must be greater than this value for any change to occur.
void WorldMap::starting_noise ( int  border)
private

Fills the world map (minus the ocean border) with randomly-placed tiles, then performs the following transformation to all tiles on the map:

  ?O?     ?O?
  O?O --> OOO
  ?O?     ?O?
* 
Parameters
border- the width of the ocean border surrounding the map.

Member Data Documentation

int WorldMap::height
private

Height, which is set to WORLD_HEIGHT in the constructor. Essentially just makes the variable less verbose. May be removed.

std::vector<std::vector<MapTile> > WorldMap::map
private

The base model for this class. A two-dimensional matrix storing MapTiles.

See also
MapTile
int WorldMap::width
private

Width, which is set to WORLD_WIDTH in the constructor. Essentially just makes the variable less verbose. May be removed.


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