Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapFunctions.hxx
Go to the documentation of this file.
1 #ifndef MAPFUNCTIONS_HXX_
2 #define MAPFUNCTIONS_HXX_
3 
4 // #include "WindowManager.hxx"
5 // #include "basics/Point.hxx"
6 #include <vector>
7 #include "../Map.hxx"
8 // #include "../../util/Singleton.hxx"
9 #include <Singleton.hxx>
10 #include <Point.hxx>
11 
12 class MapFunctions : public Singleton<MapFunctions>
13 {
14 public:
15  MapFunctions();
16  Map *getMap() { return m_map; };
17 
22  void changeHeight(const Point &isoCoordinates, const bool elevate);
23 
29  bool updateHeight(Point coordinate, const bool elevate);
30 
35  void levelHeight(const Point &startCoordinate, const std::vector<Point> levelArea);
36 
40  inline MapNode &getMapNode(Point isoCoords)
41  {
42  uint32_t index = isoCoords.toIndex();
43  return m_map->mapNodes[index < m_map->mapNodes.size() ? index : 0];
44  };
45 
48  const std::vector<MapNode> &getMapNodes() { return m_map->mapNodes; };
49 
55  std::vector<NeighborNode> getNeighborNodes(const Point &isoCoordinates, const bool includeCentralNode);
56 
61  unsigned char getElevatedNeighborBitmask(Point centerCoordinates);
62 
67  bool isPlacementOnNodeAllowed(const Point &isoCoordinates, const std::string &tileID) const;
68 
73  bool isPlacementOnAreaAllowed(const std::vector<Point> &targetCoordinates, const std::string &tileID) const;
74 
82  bool setTileID(const std::string &tileID, Point coordinate);
83 
91  bool setTileID(const std::string &tileID, const std::vector<Point> &coordinates);
92 
101  void demolishNode(const std::vector<Point> &isoCoordinates, bool updateNeighboringTiles = false, Layer layer = Layer::NONE);
102 
109  Point getNodeOrigCornerPoint(const Point &isoCoordinates, Layer layer = Layer::NONE);
110 
116  void getNodeInformation(const Point &isoCoordinates) const;
117 
124  void highlightNode(const Point &isoCoordinates, const SpriteRGBColor &rgbColor);
125 
131  void unHighlightNode(const Point &isoCoordinates);
132 
139  Point findNodeInMap(const SDL_Point &screenCoordinates, const Layer &layer = Layer::NONE);
140 
145  std::string getTileID(const Point &isoCoordinates, Layer layer);
146 
151  void refreshVisibleMap();
152 
157  void newMap(bool generateTerrain = true);
158 
165  void loadMapFromFile(const std::string &fileName);
166 
167 private:
169 
173  void updateNodeNeighbors(const std::vector<Point> &nodes);
174 
179  void updateAllNodes();
180 
189  bool isClickWithinTile(const SDL_Point &screenCoordinates, Point isoCoordinate, const Layer &layer) const;
190 
195  void saveMapToFile(const std::string &fileName);
196 
204  std::vector<uint8_t> calculateAutotileBitmask(Point coordinate);
205 };
206 
207 #endif
MapFunctions::loadMapFromFile
void loadMapFromFile(const std::string &fileName)
Load Map from file.
Definition: MapFunctions.cxx:684
MapFunctions::getNodeInformation
void getNodeInformation(const Point &isoCoordinates) const
Debug MapNodeData to Console.
Definition: MapFunctions.cxx:518
MapFunctions::getElevatedNeighborBitmask
unsigned char getElevatedNeighborBitmask(Point centerCoordinates)
Get elevated bit mask of the map node.
Definition: MapFunctions.cxx:310
Map::mapNodes
std::vector< MapNode > mapNodes
Definition: Map.hxx:66
MapFunctions::m_map
Map * m_map
Definition: MapFunctions.hxx:168
Point::toIndex
int toIndex() const
calculates the index (stride) that can be used to access in Map to access mapNodes vector.
Definition: Point.hxx:80
MapFunctions::updateHeight
bool updateHeight(Point coordinate, const bool elevate)
Change map node height.
Definition: MapFunctions.cxx:18
MapFunctions::demolishNode
void demolishNode(const std::vector< Point > &isoCoordinates, bool updateNeighboringTiles=false, Layer layer=Layer::NONE)
Demolish a node.
Definition: MapFunctions.cxx:465
MapFunctions::getNodeOrigCornerPoint
Point getNodeOrigCornerPoint(const Point &isoCoordinates, Layer layer=Layer::NONE)
Get original corner point of given point within building borders.
Definition: MapFunctions.cxx:326
MapFunctions::updateAllNodes
void updateAllNodes()
Update all mapNodes.
Definition: MapFunctions.cxx:244
NONE
@ NONE
0- this must be FIRST !!!
Definition: enums.hxx:11
MapFunctions::getMap
Map * getMap()
Definition: MapFunctions.hxx:16
MapFunctions::updateNodeNeighbors
void updateNodeNeighbors(const std::vector< Point > &nodes)
Update the nodes and all affected node with the change.
Definition: MapFunctions.cxx:134
MapFunctions::refreshVisibleMap
void refreshVisibleMap()
Refresh the visible part of the map.
Definition: MapFunctions.cxx:764
MapFunctions::highlightNode
void highlightNode(const Point &isoCoordinates, const SpriteRGBColor &rgbColor)
Sets a node to be highlighted.
Definition: MapFunctions.cxx:535
MapFunctions::levelHeight
void levelHeight(const Point &startCoordinate, const std::vector< Point > levelArea)
level area of map nodes.
Definition: MapFunctions.cxx:63
MapFunctions::isPlacementOnNodeAllowed
bool isPlacementOnNodeAllowed(const Point &isoCoordinates, const std::string &tileID) const
check if Tile is occupied
Definition: MapFunctions.cxx:265
MapFunctions::MapFunctions
MapFunctions()
Definition: MapFunctions.cxx:16
MapFunctions::isPlacementOnAreaAllowed
bool isPlacementOnAreaAllowed(const std::vector< Point > &targetCoordinates, const std::string &tileID) const
check if Tile can be placed in an area
Definition: MapFunctions.cxx:270
MapFunctions::getNeighborNodes
std::vector< NeighborNode > getNeighborNodes(const Point &isoCoordinates, const bool includeCentralNode)
Get all neighbor nodes from provided map node.
Definition: MapFunctions.cxx:253
Singleton.hxx
MapNode
Class that holds map nodes.
Definition: MapNode.hxx:30
MapFunctions::getTileID
std::string getTileID(const Point &isoCoordinates, Layer layer)
get Tile ID of specific layer of specific iso coordinates
Definition: MapFunctions.cxx:545
MapFunctions
Definition: MapFunctions.hxx:12
MapFunctions::unHighlightNode
void unHighlightNode(const Point &isoCoordinates)
Sets a node to be unhighlighred.
Definition: MapFunctions.cxx:550
MapFunctions::getMapNodes
const std::vector< MapNode > & getMapNodes()
Get all mapnodes as a vector.
Definition: MapFunctions.hxx:48
MapFunctions::newMap
void newMap(bool generateTerrain=true)
Creates a new map object with terrain gen.
Definition: MapFunctions.cxx:671
SpriteRGBColor
Definition: Sprite.hxx:18
Singleton
Abstract Singleton implementation.
Definition: Singleton.hxx:8
MapFunctions::findNodeInMap
Point findNodeInMap(const SDL_Point &screenCoordinates, const Layer &layer=Layer::NONE)
Returns the node at given screen coordinates.
Definition: MapFunctions.cxx:558
MapFunctions::calculateAutotileBitmask
std::vector< uint8_t > calculateAutotileBitmask(Point coordinate)
Get a bitmask that represents same-tile neighbors.
Definition: MapFunctions.cxx:336
MapFunctions::saveMapToFile
void saveMapToFile(const std::string &fileName)
Save Map to file.
Definition: MapFunctions.cxx:745
MapFunctions::getMapNode
MapNode & getMapNode(Point isoCoords)
Get pointer to a single mapNode at specific iso coordinates.
Definition: MapFunctions.hxx:40
Map
Definition: Map.hxx:23
Point
Definition: Point.hxx:7
MapFunctions::isClickWithinTile
bool isClickWithinTile(const SDL_Point &screenCoordinates, Point isoCoordinate, const Layer &layer) const
Check if a click is within a non transparent part of a sprite.
Definition: MapFunctions.cxx:608
MapFunctions::setTileID
bool setTileID(const std::string &tileID, Point coordinate)
Set the Tile ID Of Node object.
Definition: MapFunctions.cxx:378
Layer
Layer
All Layers we have.
Definition: enums.hxx:9
string
std::string string
Definition: AudioConfig.hxx:14
MapFunctions::changeHeight
void changeHeight(const Point &isoCoordinates, const bool elevate)
Change map node height.
Definition: MapFunctions.cxx:36
Point.hxx