Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapNode Class Reference

Class that holds map nodes. More...

#include <MapNode.hxx>

+ Collaboration diagram for MapNode:

Public Member Functions

 MapNode (Point isoCoordinates, const std::string &terrainID, const std::string &newTileID="")
 
 MapNode (MapNode &&mn) noexcept
 Move constructor. More...
 
 ~MapNode ()=default
 Destroys the MapNode object. More...
 
SpritegetSprite () const
 get Sprite More...
 
const PointgetCoordinates () const
 get iso coordinates of this node More...
 
void setCoordinates (const Point &newIsoCoordinates)
 sets the iso coordinates of this node More...
 
bool changeHeight (const bool higher)
 Change Height. More...
 
void render () const
 Render MapNode. More...
 
void setBitmask (unsigned char elevationBitmask, std::vector< uint8_t > tileTypeBitmask)
 
unsigned char getElevationBitmask () const
 
const TileDatagetTileData (Layer layer) const
 
const std::stringgetTileID (Layer layer) const
 get TileID of specific layer inside NodeData. More...
 
bool isPlacementAllowed (const std::string &newTileID) const
 
void setMapNodeData (std::vector< MapNodeData > &&mapNodeData)
 Overwrite m_mapData with the one loaded from a savegame. This function to be used only by loadGame. More...
 
const std::vector< MapNodeData > & getMapNodeData () const
 
const MapNodeDatagetMapNodeDataForLayer (Layer layer) const
 
const MapNodeDatagetActiveMapNodeData () const
 
bool isPlacableOnSlope (const std::string &tileID) const
 check if tileID placeable on slope tile. More...
 
bool isSlopeNode (void) const
 check if current Node Terrain is Slope Terrain. More...
 
const bool isConductive () const
 check the conductivity of the node More...
 
void demolishNode (const Layer &layer=Layer::NONE)
 Demolish a node. More...
 
void demolishLayer (const Layer &layer)
 demolish specific layer of a Node. More...
 
void setTileID (const std::string &tileType, const Point &origPoint)
 
const PointgetOrigCornerPoint (Layer layer) const
 Get the Origin Corner Point of a multitile building. More...
 
bool isOriginNode (Layer layer=Layer::BUILDINGS) const
 If this is the origin node of a multitile building. More...
 
Layer getTopMostActiveLayer () const
 return topmost active layer. More...
 
bool isLayerOccupied (const Layer &layer) const
 
void setElevationBitMask (const unsigned char bitMask)
 Set elevation bit mask. More...
 
void setAutotileBitMask (std::vector< unsigned char > &&bitMask)
 Set autotile bit mask. More...
 
void updateTexture (const Layer &layer=Layer::NONE)
 Update texture. More...
 
void setNodeTransparency (const float transparencyFactor, const Layer &layer) const
 Sets a node to be Transparent. More...
 
void setZIndex (int zIndex)
 Update the Z-Index of this mapNode. More...
 

Static Public Attributes

static const int maxHeight = 32
 Maximum height of the node. More...
 

Private Attributes

Point m_isoCoordinates
 
std::unique_ptr< Spritem_sprite
 
std::string m_previousTileID = "terrain"
 
std::vector< TileOrientationm_autotileOrientation
 
size_t m_elevationOrientation = TileSlopes::DEFAULT_ORIENTATION
 
int m_clippingWidth = 0
 
std::vector< MapNodeDatam_mapNodeData
 
std::vector< unsigned char > m_autotileBitmask
 
unsigned char m_elevationBitmask = 0
 

Detailed Description

Class that holds map nodes.

Each tile is represented by the map nodes class.

Definition at line 30 of file MapNode.hxx.

Constructor & Destructor Documentation

◆ MapNode() [1/2]

MapNode::MapNode ( Point  isoCoordinates,
const std::string terrainID,
const std::string newTileID = "" 
)

Definition at line 9 of file MapNode.cxx.

10  : m_isoCoordinates(std::move(isoCoordinates)), m_sprite{std::make_unique<Sprite>(m_isoCoordinates)},
14 {
15  setTileID(terrainID, isoCoordinates);
16  if (!tileID.empty()) // in case tileID is not supplied skip it
17  {
18  setTileID(tileID, isoCoordinates);
19  }
20  // always add blueprint tiles too when creating the node
21  setTileID("terrain_blueprint", isoCoordinates);
22  const Layer layer = TileManager::instance().getTileLayer(tileID);
23  updateTexture(layer);
24 }

◆ MapNode() [2/2]

MapNode::MapNode ( MapNode &&  mn)
inlinenoexcept

Move constructor.

Definition at line 37 of file MapNode.hxx.

◆ ~MapNode()

MapNode::~MapNode ( )
default

Destroys the MapNode object.

Member Function Documentation

◆ changeHeight()

bool MapNode::changeHeight ( const bool  higher)

Change Height.

Increases or decrease the height of the node and its sprite. This function should not be called directly, but only from where the neighboring nodes slopes are determined.

Parameters
higherpass true in case that height should be increased or false in case that height should be decreased.
Returns
true in case that height is changed, otherwise false.

Definition at line 26 of file MapNode.cxx.

27 {
28  constexpr int minHeight = 0;
29  auto &height = m_isoCoordinates.height;
30 
31  if ((higher && (height < maxHeight)) || (!higher && (height > minHeight)))
32  {
33  higher ? ++height : --height;
34  m_sprite->isoCoordinates = m_isoCoordinates;
35  return true;
36  }
37 
38  return false;
39 }
+ Here is the caller graph for this function:

◆ demolishLayer()

void MapNode::demolishLayer ( const Layer layer)

demolish specific layer of a Node.

Parameters
layerwhat layer should be demolished.

Definition at line 454 of file MapNode.cxx.

455 {
456  m_mapNodeData[layer].tileData = nullptr;
457  m_mapNodeData[layer].tileID = "";
458  m_autotileOrientation[layer] =
459  TileOrientation::TILE_DEFAULT_ORIENTATION; // We need to reset TileOrientation, in case it's set (demolishing autotiles)
460  m_mapNodeData[layer].origCornerPoint = this->getCoordinates();
461  m_sprite->setRenderFlag(Layer::ZONE, true);
462  m_sprite->clearSprite(layer);
463 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ demolishNode()

void MapNode::demolishNode ( const Layer layer = Layer::NONE)

Demolish a node.

Removes all tiles on a node. This effects all layers where something to demolish is placed (BUILDINGS, GROUND_DECORATION, UNDERGROUND) per default, but can be restricted to a single Layer.

Parameters
layerrestrict demolish to a single layer
See also
MapNode::demolishNode

Definition at line 465 of file MapNode.cxx.

466 {
467  // allow to delete a single layer only
468  std::vector<Layer> layersToDemolish;
469  if (demolishLayer == Layer::NONE)
470  {
473  }
474  else
475  {
476  layersToDemolish.push_back(demolishLayer);
477  }
478 
479  for (auto &layer : layersToDemolish)
480  {
481  if (MapLayers::isLayerActive(layer) && m_mapNodeData[layer].tileData)
482  {
484  m_mapNodeData[layer].tileData->tileType == +TileType::ZONE) ||
486  m_mapNodeData[layer].tileData->tileType != +TileType::ZONE) ||
488  m_mapNodeData[layer].tileData->tileType != +TileType::GROUNDDECORATION))
489  {
490  continue;
491  }
492  this->demolishLayer(layer);
493  if (layer == Layer::BUILDINGS)
494  {
496  }
498  }
499  }
500 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getActiveMapNodeData()

const MapNodeData & MapNode::getActiveMapNodeData ( ) const

Definition at line 438 of file MapNode.cxx.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCoordinates()

const Point& MapNode::getCoordinates ( ) const
inline

get iso coordinates of this node

Returns
a pointer to the node's iso coordinates

Definition at line 59 of file MapNode.hxx.

59 { return m_isoCoordinates; };
+ Here is the caller graph for this function:

◆ getElevationBitmask()

unsigned char MapNode::getElevationBitmask ( ) const
inline

Definition at line 82 of file MapNode.hxx.

82 { return m_elevationBitmask; };
+ Here is the caller graph for this function:

◆ getMapNodeData()

const std::vector<MapNodeData>& MapNode::getMapNodeData ( ) const
inline

Definition at line 96 of file MapNode.hxx.

96 { return m_mapNodeData; };
+ Here is the caller graph for this function:

◆ getMapNodeDataForLayer()

const MapNodeData& MapNode::getMapNodeDataForLayer ( Layer  layer) const
inline

Definition at line 97 of file MapNode.hxx.

97 { return m_mapNodeData[layer]; };
+ Here is the caller graph for this function:

◆ getOrigCornerPoint()

const Point& MapNode::getOrigCornerPoint ( Layer  layer) const
inline

Get the Origin Corner Point of a multitile building.

Parameters
layerthe layer that should be checked
Returns
const Point&

Definition at line 136 of file MapNode.hxx.

136 { return getMapNodeDataForLayer(layer).origCornerPoint; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSprite()

Sprite* MapNode::getSprite ( ) const
inline

get Sprite

get the Sprite* object for this nodes

Returns
the Sprite of this node.
See also
Sprite

Definition at line 54 of file MapNode.hxx.

54 { return m_sprite.get(); };
+ Here is the caller graph for this function:

◆ getTileData()

const TileData* MapNode::getTileData ( Layer  layer) const
inline

Definition at line 84 of file MapNode.hxx.

84 { return m_mapNodeData[layer].tileData; };
+ Here is the caller graph for this function:

◆ getTileID()

const std::string& MapNode::getTileID ( Layer  layer) const
inline

get TileID of specific layer inside NodeData.

Parameters
layerwhat layer should be checked on.

Definition at line 89 of file MapNode.hxx.

89 { return m_mapNodeData[layer].tileID; };
+ Here is the caller graph for this function:

◆ getTopMostActiveLayer()

Layer MapNode::getTopMostActiveLayer ( ) const

return topmost active layer.

check layers in order of significance for the topmost active layer that has an active tile on that layer

Returns
Layer enum of the topmost active layer

Definition at line 105 of file MapNode.cxx.

106 {
107  for (auto currentLayer : layersInActiveOrder)
108  {
109  if (MapLayers::isLayerActive(currentLayer) && m_mapNodeData[currentLayer].tileData)
110  {
111  return currentLayer;
112  }
113  }
114  return Layer::NONE;
115 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isConductive()

const bool MapNode::isConductive ( ) const

check the conductivity of the node

Returns
true if the node conducts electricity/power, false if not

Definition at line 502 of file MapNode.cxx.

503 {
505  {
506  return true;
507  }
508  else
509  {
510  return false;
511  }
512 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLayerOccupied()

bool MapNode::isLayerOccupied ( const Layer layer) const
inline

Definition at line 155 of file MapNode.hxx.

155 { return m_mapNodeData[layer].tileData != nullptr; }
+ Here is the caller graph for this function:

◆ isOriginNode()

bool MapNode::isOriginNode ( Layer  layer = Layer::BUILDINGS) const
inline

If this is the origin node of a multitile building.

Parameters
layerthe layer that should be checked, defaults to the BUILDINGS layer
Returns
wheter or not this is the origin node of a multitile building

Definition at line 144 of file MapNode.hxx.

145  {
146  return (m_isoCoordinates == getMapNodeDataForLayer(layer).origCornerPoint);
147  }
+ Here is the call graph for this function:

◆ isPlacableOnSlope()

bool MapNode::isPlacableOnSlope ( const std::string tileID) const

check if tileID placeable on slope tile.

Parameters
tileIDthe tileID which need to be checked whether allowing placement on slope or not.

Definition at line 124 of file MapNode.cxx.

125 {
126  TileData *tileData = TileManager::instance().getTileData(tileID);
127  if (tileData && tileData->tileType == +TileType::ZONE)
128  {
129  // zones are allowed to pass slopes.
130  return true;
131  }
133  {
134  // we need to check the terrain layer for it's orientation so we can calculate the resulting x offset in the spritesheet.
135  const int clipRectX = tileData->slopeTiles.clippingWidth * static_cast<int>(m_autotileOrientation[Layer::TERRAIN]);
136  // while loading game, m_previousTileID will be equal to "terrain" for terrin tiles while it's empty "" when starting new game.
137  // so the check here on m_previousTileID is needed both (temporary), empty and "terrain", this will be fixed in new PR.
138  if (clipRectX >= static_cast<int>(tileData->slopeTiles.count) * tileData->slopeTiles.clippingWidth &&
139  (m_previousTileID.empty() || m_previousTileID == "terrain"))
140  {
141  return false;
142  }
143  }
144  return true;
145 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPlacementAllowed()

bool MapNode::isPlacementAllowed ( const std::string newTileID) const

Definition at line 147 of file MapNode.cxx.

148 {
149  TileData *tileData = TileManager::instance().getTileData(newTileID);
150 
151  if (tileData)
152  {
153  const Layer layer = TileManager::instance().getTileLayer(newTileID);
154  // layer specific checks:
155  switch (layer)
156  {
157  case Layer::ZONE:
159  {
160  return tileData->placeOnWater;
161  }
162  return true;
163  case Layer::POWERLINES:
165  std::any_of(layersPowerlinesCanCross.begin(), layersPowerlinesCanCross.end(),
166  [this](const Layer &_layer) { return this->isLayerOccupied(_layer); }))
167  { // powerlines can be placed over each other and over other low terrains
168  return true;
169  }
170  case Layer::ROAD:
171  if ((isLayerOccupied(Layer::BUILDINGS) && (m_mapNodeData[Layer::BUILDINGS].tileData->category != "Flora")) ||
173  { // roads cannot be placed:
174  // - on buildings that are not category flora.
175  // - on water
176  // - on slopetiles that don't have a tileID
177  return false;
178  }
179  return true;
182  { // allow placement of ground decoration on existing ground decoration and on buildings.
183  return true;
184  }
185  break;
186  case Layer::FLORA:
187  if (m_mapNodeData[Layer::FLORA].tileData && m_mapNodeData[Layer::FLORA].tileData->isOverPlacable)
188  { // flora with overplacable flag
189  return true;
190  }
192  { // don't allow placement of flora on buildings or roads
193  return false;
194  }
195  break;
196  case Layer::BUILDINGS:
197  {
198  TileData *tileDataBuildings = m_mapNodeData[Layer::BUILDINGS].tileData;
199  if (tileDataBuildings && tileDataBuildings->isOverPlacable)
200  { // buildings with overplacable flag
201  return true;
202  }
204  { // buildings cannot be placed on roads
205  return false;
206  }
207  break;
208  }
209  default:
210  break;
211  }
212 
213  // checks for all layers:
215  {
216  if (tileData->tileType != +TileType::WATER && !tileData->placeOnWater)
217  // Disallow placement on water for tiles that are:
218  // not of tiletype water
219  // not flag placeOnWater enabled
220  {
221  return false;
222  }
223  }
224  else // not water
225  {
226  if (!tileData->placeOnGround)
227  // Disallow placement on ground (meaning a tile that is not water) for tiles that have:
228  // not flag placeOnGround enabled
229  {
230  return false;
231  }
232  }
233 
234  if (!isPlacableOnSlope(newTileID))
235  { // Check if a tile has slope frames and therefore can be placed on a node with a slope
236  return false;
237  }
238 
239  if (tileData->tileType == +TileType::UNDERGROUND)
240  { // Underground tiletype (pipes, metro tunnels, ... ) can overplace each other
241  return true;
242  }
243 
244  if (m_mapNodeData[layer].tileID.empty())
245  { // of course allow placement on empty tiles
246  return true;
247  }
248  }
249  // every case that is not handled is false
250  return false;
251 }
+ Here is the call graph for this function:

◆ isSlopeNode()

bool MapNode::isSlopeNode ( void  ) const

check if current Node Terrain is Slope Terrain.

Definition at line 430 of file MapNode.cxx.

430 { return m_mapNodeData[Layer::TERRAIN].tileMap == TileMap::SLOPES; }
+ Here is the caller graph for this function:

◆ render()

void MapNode::render ( ) const

Render MapNode.

Renders the sprite object(s) of the node

Definition at line 41 of file MapNode.cxx.

41 { m_sprite->render(); }

◆ setAutotileBitMask()

void MapNode::setAutotileBitMask ( std::vector< unsigned char > &&  bitMask)
inline

Set autotile bit mask.

Parameters
bitMask

Definition at line 165 of file MapNode.hxx.

165 { m_autotileBitmask = std::move(bitMask); }
+ Here is the caller graph for this function:

◆ setBitmask()

void MapNode::setBitmask ( unsigned char  elevationBitmask,
std::vector< uint8_t >  tileTypeBitmask 
)

Definition at line 43 of file MapNode.cxx.

44 {
45  m_elevationBitmask = elevationBitmask;
46  m_autotileBitmask = autotileBitmask;
47  updateTexture();
48 }
+ Here is the call graph for this function:

◆ setCoordinates()

void MapNode::setCoordinates ( const Point newIsoCoordinates)

sets the iso coordinates of this node

Parameters
newIsoCoordinatesthe new iso coordinates for the node

Definition at line 432 of file MapNode.cxx.

433 {
434  m_isoCoordinates = newIsoCoordinates;
435  m_sprite->isoCoordinates = m_isoCoordinates;
436 }
+ Here is the caller graph for this function:

◆ setElevationBitMask()

void MapNode::setElevationBitMask ( const unsigned char  bitMask)
inline

Set elevation bit mask.

Parameters
bitMask

Definition at line 160 of file MapNode.hxx.

160 { m_elevationBitmask = bitMask; }
+ Here is the caller graph for this function:

◆ setMapNodeData()

void MapNode::setMapNodeData ( std::vector< MapNodeData > &&  mapNodeData)

Overwrite m_mapData with the one loaded from a savegame. This function to be used only by loadGame.

Definition at line 440 of file MapNode.cxx.

441 {
442  m_mapNodeData.swap(mapNodeData);
443  this->setNodeTransparency(Settings::instance().zoneLayerTransparency, Layer::ZONE);
444 
445  // updates the pointers to the tiles, after loading tileIDs from json
446  for (auto &it : m_mapNodeData)
447  {
448  delete it.tileData;
449 
450  it.tileData = TileManager::instance().getTileData(it.tileID);
451  }
452 }
+ Here is the call graph for this function:

◆ setNodeTransparency()

void MapNode::setNodeTransparency ( const float  transparencyFactor,
const Layer layer 
) const

Sets a node to be Transparent.

Parameters
transparencyFactor(0-1.0) - The percentage of node transparency. 1 -> invisible, 0 -> opaque.
layerwhat layer in Sprite should it's transparency altered.

Definition at line 117 of file MapNode.cxx.

118 {
119  // TODO refactoring: Consider replacing magic number (255) with constexpr.
120  unsigned char alpha = (1 - transparencyFactor) * 255;
121  m_sprite->setSpriteTranparencyFactor(layer, alpha);
122 }
+ Here is the caller graph for this function:

◆ setTileID()

void MapNode::setTileID ( const std::string tileType,
const Point origPoint 
)

set tileIndex to a rand between 1 and count, this will be the displayed image of the entire tileset if this tile has ordered frames, like roads then pickRandomTile must be set to 0.

must be reset to 0 otherwise overwritting tiles would keep the old tile's tileIndex which creates problems if it's supposed to be 0

Definition at line 50 of file MapNode.cxx.

51 {
52  TileData *tileData = TileManager::instance().getTileData(tileID);
53  if (tileData && !tileID.empty())
54  {
55  const Layer layer = TileManager::instance().getTileLayer(tileID);
56  switch (layer)
57  {
58  case Layer::ZONE:
59  this->setNodeTransparency(Settings::instance().zoneLayerTransparency, Layer::ZONE);
60  break;
61  case Layer::WATER:
63  //TODO: we need to modify neighbors TileTypes to Shore.
64  // no break on purpose.
65  case Layer::ROAD:
66  // in case it's allowed then maybe a Tree Tile already exist, so we remove it.
68  case Layer::POWERLINES:
69  break;
70  case Layer::BUILDINGS:
71  if (tileData->tileType != +TileType::FLORA)
72  {
74  }
75  m_sprite->setRenderFlag(Layer::ZONE, false);
76  break;
77  default:
78  break;
79  }
80 
81  m_mapNodeData[layer].origCornerPoint = origCornerPoint;
82  m_previousTileID = m_mapNodeData[layer].tileID;
83  m_mapNodeData[layer].tileData = tileData;
84  m_mapNodeData[layer].tileID = tileID;
85 
86  // Determine if the tile should have a random rotation or not.
87  if (m_mapNodeData[layer].tileData->tiles.pickRandomTile && m_mapNodeData[layer].tileData->tiles.count > 1)
88  {
92  m_mapNodeData[layer].tileIndex = rand() % m_mapNodeData[layer].tileData->tiles.count;
93  }
94  else
95  {
99  m_mapNodeData[layer].tileIndex = 0;
100  }
101  updateTexture(layer);
102  }
103 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setZIndex()

void MapNode::setZIndex ( int  zIndex)
inline

Update the Z-Index of this mapNode.

Parameters
thenew Z-Index

Definition at line 183 of file MapNode.hxx.

183 { m_isoCoordinates.z = zIndex; };

◆ updateTexture()

void MapNode::updateTexture ( const Layer layer = Layer::NONE)

Update texture.

Parameters
layer

Definition at line 253 of file MapNode.cxx.

254 {
255  SDL_Rect clipRect{0, 0, 0, 0};
256  //TODO: Refactor this
258  std::vector<Layer> layersToGoOver;
259  if (layer != Layer::NONE)
260  {
261  // in case this is not the default value (which is NONE), we need to update only 1 layer.
262  layersToGoOver.push_back(layer);
263  }
264  else
265  {
266  layersToGoOver.insert(layersToGoOver.begin(), std::begin(allLayersOrdered), std::end(allLayersOrdered));
267  }
268 
269  for (auto currentLayer : layersToGoOver)
270  {
271  if (m_mapNodeData[currentLayer].tileData)
272  {
273  size_t spriteCount = 1;
274  m_mapNodeData[currentLayer].tileMap = TileMap::DEFAULT;
276  {
277  if (m_mapNodeData[currentLayer].tileData->tileType == +TileType::WATER ||
278  m_mapNodeData[currentLayer].tileData->tileType == +TileType::TERRAIN ||
279  m_mapNodeData[currentLayer].tileData->tileType == +TileType::BLUEPRINT)
280  {
282  m_mapNodeData[currentLayer].tileMap = TileMap::DEFAULT;
284  {
286  // for shore tiles, we need to reset the tileIndex to 0, else a random tile would be picked. This is a little bit hacky.
287  m_mapNodeData[Layer::TERRAIN].tileIndex = 0;
288  }
289  }
290  // if the node can autotile, calculate it's tile orientation
291  else if (TileManager::instance().isTileIDAutoTile(getTileID(currentLayer)))
292  {
294  }
295  }
297  {
298  if (m_mapNodeData[currentLayer].tileData->slopeTiles.fileName.empty())
299  {
300  m_mapNodeData[currentLayer].tileMap = TileMap::DEFAULT;
302  }
303  else
304  {
305  m_mapNodeData[currentLayer].tileMap = TileMap::SLOPES; // TileSlopes [N,E,w,S]
306  m_autotileOrientation[currentLayer] = static_cast<TileOrientation>(m_elevationOrientation);
307  }
308  }
309 
310  switch (m_mapNodeData[currentLayer].tileMap)
311  {
312  case TileMap::DEFAULT:
313  m_clippingWidth = m_mapNodeData[currentLayer].tileData->tiles.clippingWidth;
314  if (m_mapNodeData[currentLayer].tileIndex != 0)
315  {
316  clipRect.x = m_clippingWidth * m_mapNodeData[currentLayer].tileIndex;
317  }
318  else
319  {
320  if (m_mapNodeData[currentLayer].tileData->tileType == +TileType::POWERLINE &&
321  std::any_of(layersPowerlinesCanCross.begin(), layersPowerlinesCanCross.end(),
322  [this](const Layer &_layer) { return this->m_mapNodeData[_layer].tileData; }))
323  { // if we place a power line cross low terrain (eg, roads, water, flora)
324  switch (m_autotileOrientation[currentLayer])
325  {
328  break;
331  break;
332  default:
333  break;
334  }
335  }
336  // only check for rectangular roads when there are frames for it. Spritesheets with rect-roads have 20 items
337  if (GameStates::instance().rectangularRoads && m_mapNodeData[currentLayer].tileData->tiles.count == 20)
338  {
339  switch (m_autotileOrientation[currentLayer])
340  {
343  break;
346  break;
349  break;
352  break;
353 
354  default:
355  break;
356  }
357  }
358  clipRect.x = m_clippingWidth * static_cast<int>(m_autotileOrientation[currentLayer]);
359  }
360 
361  if (!m_mapNodeData[currentLayer].tileID.empty())
362  {
363  m_sprite->setClipRect({clipRect.x + m_clippingWidth * m_mapNodeData[currentLayer].tileData->tiles.offset, 0,
364  m_clippingWidth, m_mapNodeData[currentLayer].tileData->tiles.clippingHeight},
365  static_cast<Layer>(currentLayer));
366  m_sprite->setTexture(TileManager::instance().getTexture(m_mapNodeData[currentLayer].tileID),
367  static_cast<Layer>(currentLayer));
368  }
369 
370  spriteCount = m_mapNodeData[currentLayer].tileData->tiles.count;
371  break;
372  case TileMap::SHORE:
373  m_clippingWidth = m_mapNodeData[currentLayer].tileData->shoreTiles.clippingWidth;
374  if (m_mapNodeData[currentLayer].tileIndex != 0)
375  {
376  clipRect.x = m_clippingWidth * m_mapNodeData[currentLayer].tileIndex;
377  }
378  else
379  {
380  clipRect.x = m_clippingWidth * static_cast<int>(m_autotileOrientation[currentLayer]);
381  }
382 
383  if (!m_mapNodeData[currentLayer].tileID.empty())
384  {
385  m_sprite->setClipRect({clipRect.x + m_clippingWidth * m_mapNodeData[currentLayer].tileData->shoreTiles.offset, 0,
386  m_clippingWidth, m_mapNodeData[currentLayer].tileData->shoreTiles.clippingHeight},
387  static_cast<Layer>(currentLayer));
388  m_sprite->setTexture(TileManager::instance().getTexture(m_mapNodeData[currentLayer].tileID + "_shore"),
389  static_cast<Layer>(currentLayer));
390  }
391 
392  spriteCount = m_mapNodeData[currentLayer].tileData->shoreTiles.count;
393  break;
394  case TileMap::SLOPES:
395  if (m_mapNodeData[currentLayer].tileData->slopeTiles.fileName.empty())
396  {
397  break;
398  }
399  m_clippingWidth = m_mapNodeData[currentLayer].tileData->slopeTiles.clippingWidth;
400  clipRect.x = m_mapNodeData[currentLayer].tileData->slopeTiles.clippingWidth *
401  static_cast<int>(m_autotileOrientation[currentLayer]);
402  spriteCount = m_mapNodeData[currentLayer].tileData->slopeTiles.count;
403  if (clipRect.x <= static_cast<int>(spriteCount) * m_clippingWidth)
404  {
405  m_sprite->setClipRect({clipRect.x + m_mapNodeData[currentLayer].tileData->slopeTiles.offset * m_clippingWidth, 0,
406  m_clippingWidth, m_mapNodeData[currentLayer].tileData->slopeTiles.clippingHeight},
407  static_cast<Layer>(currentLayer));
408  m_sprite->setTexture(TileManager::instance().getTexture(m_mapNodeData[currentLayer].tileID),
409  static_cast<Layer>(currentLayer));
410  }
411  break;
412  default:
413  break;
414  }
415 
416  if (clipRect.x >= static_cast<int>(spriteCount) * m_clippingWidth)
417  {
418  m_mapNodeData[currentLayer].tileID = m_previousTileID;
419  if (m_previousTileID.empty())
420  {
421  m_mapNodeData[currentLayer].tileData = nullptr;
422  }
423  updateTexture(currentLayer);
424  }
425  m_sprite->spriteCount = spriteCount;
426  }
427  }
428 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_autotileBitmask

std::vector<unsigned char> MapNode::m_autotileBitmask
private

Definition at line 196 of file MapNode.hxx.

◆ m_autotileOrientation

std::vector<TileOrientation> MapNode::m_autotileOrientation
private

Definition at line 192 of file MapNode.hxx.

◆ m_clippingWidth

int MapNode::m_clippingWidth = 0
private

Definition at line 194 of file MapNode.hxx.

◆ m_elevationBitmask

unsigned char MapNode::m_elevationBitmask = 0
private

Definition at line 197 of file MapNode.hxx.

◆ m_elevationOrientation

size_t MapNode::m_elevationOrientation = TileSlopes::DEFAULT_ORIENTATION
private

Definition at line 193 of file MapNode.hxx.

◆ m_isoCoordinates

Point MapNode::m_isoCoordinates
private

Definition at line 189 of file MapNode.hxx.

◆ m_mapNodeData

std::vector<MapNodeData> MapNode::m_mapNodeData
private

Definition at line 195 of file MapNode.hxx.

◆ m_previousTileID

std::string MapNode::m_previousTileID = "terrain"
private

Definition at line 191 of file MapNode.hxx.

◆ m_sprite

std::unique_ptr<Sprite> MapNode::m_sprite
private

Definition at line 190 of file MapNode.hxx.

◆ maxHeight

const int MapNode::maxHeight = 32
static

Maximum height of the node.

Definition at line 186 of file MapNode.hxx.


The documentation for this class was generated from the following files:
demolishMode
bool demolishMode
Definition: mapEdit.cxx:5
DemolishMode::DE_ZONE
@ DE_ZONE
Remove only zones.
TileData::placeOnWater
bool placeOnWater
whether or not this building is placeable on water
Definition: tileData.hxx:162
TileManager::calculateTileOrientation
TileOrientation calculateTileOrientation(unsigned char bitMaskElevation)
Calculates the TileOrientation for elevated tiles to pick the correct Sprite.
Definition: TileManager.cxx:257
WATER
@ WATER
6- Water tiles
Definition: enums.hxx:17
TileData::tileType
TileType tileType
Definition: tileData.hxx:149
DEFAULT
@ DEFAULT
Definition: TileManager.hxx:18
MapNode::getMapNodeDataForLayer
const MapNodeData & getMapNodeDataForLayer(Layer layer) const
Definition: MapNode.hxx:97
TILE_N_AND_W
@ TILE_N_AND_W
Definition: TileManager.hxx:49
TILE_S_AND_E_RECT
@ TILE_S_AND_E_RECT
Definition: TileManager.hxx:61
MapNode::getCoordinates
const Point & getCoordinates() const
get iso coordinates of this node
Definition: MapNode.hxx:59
TileData::category
std::string category
The category this item resides in. Categories are used for the building menu in-game and for sorting ...
Definition: tileData.hxx:140
POWERLINES
@ POWERLINES
9- Powerlines
Definition: enums.hxx:20
BETWEEN
@ BETWEEN
Definition: TileManager.hxx:37
MapNode::getTopMostActiveLayer
Layer getTopMostActiveLayer() const
return topmost active layer.
Definition: MapNode.cxx:105
NONE
@ NONE
0- this must be FIRST !!!
Definition: enums.hxx:11
Point::z
int z
The z coordinate.
Definition: Point.hxx:23
MapNode::maxHeight
static const int maxHeight
Maximum height of the node.
Definition: MapNode.hxx:186
TILE_N_AND_S_CROSS
@ TILE_N_AND_S_CROSS
Definition: TileManager.hxx:64
TileManager::calculateSlopeOrientation
size_t calculateSlopeOrientation(unsigned char bitMaskElevation)
Calculates the slope orientation for elevated tiles to pick the correct slope Sprite.
Definition: TileManager.cxx:147
DemolishMode::GROUND_DECORATION
@ GROUND_DECORATION
Remove only ground decoration.
MapNode::getTileData
const TileData * getTileData(Layer layer) const
Definition: MapNode.hxx:84
MapNodeData::origCornerPoint
Point origCornerPoint
Definition: MapNode.hxx:22
MapNode::m_autotileOrientation
std::vector< TileOrientation > m_autotileOrientation
Definition: MapNode.hxx:192
MapNode::m_elevationBitmask
unsigned char m_elevationBitmask
Definition: MapNode.hxx:197
TILE_N_AND_E
@ TILE_N_AND_E
Definition: TileManager.hxx:46
MapNode::m_sprite
std::unique_ptr< Sprite > m_sprite
Definition: MapNode.hxx:190
TILE_N_AND_W_RECT
@ TILE_N_AND_W_RECT
Definition: TileManager.hxx:62
TILE_E_AND_W
@ TILE_E_AND_W
Definition: TileManager.hxx:48
MapNode::demolishLayer
void demolishLayer(const Layer &layer)
demolish specific layer of a Node.
Definition: MapNode.cxx:454
MapNode::updateTexture
void updateTexture(const Layer &layer=Layer::NONE)
Update texture.
Definition: MapNode.cxx:253
TileData::tiles
TileSetData tiles
Tile Spritesheet information.
Definition: tileData.hxx:148
TILE_E_AND_W_CROSS
@ TILE_E_AND_W_CROSS
Definition: TileManager.hxx:63
ZONE
@ ZONE
4- Optional layer, zones(Industrial/Residential/Commercial).
Definition: enums.hxx:15
BLUEPRINT
@ BLUEPRINT
1- Optional layer - Map Blueprint
Definition: enums.hxx:12
SHORE
@ SHORE
Definition: TileManager.hxx:20
BUILDINGS
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
Definition: enums.hxx:19
TileManager::getTileLayer
Layer getTileLayer(const std::string &tileID) const
Get the Layer that is associated with a tileID. The Tile will be placed on this layer.
Definition: TileManager.cxx:104
TILE_S_AND_E
@ TILE_S_AND_E
Definition: TileManager.hxx:52
MapNode::m_elevationOrientation
size_t m_elevationOrientation
Definition: MapNode.hxx:193
DEFAULT_ORIENTATION
@ DEFAULT_ORIENTATION
Definition: TileManager.hxx:38
TileManager::getTexture
SDL_Texture * getTexture(const std::string &tileID) const
Get the Texture for the tileID.
Definition: TileManager.cxx:17
GameStatesData::rectangularRoads
bool rectangularRoads
place rectangular road tiles instead of diagonal tiles
Definition: GameStates.hxx:15
TILE_S_AND_W_RECT
@ TILE_S_AND_W_RECT
Definition: TileManager.hxx:60
GameStatesData::demolishMode
DemolishMode demolishMode
Definition: GameStates.hxx:19
TileData::isOverPlacable
bool isOverPlacable
Determines if other tiles can be placed over this one tile.
Definition: tileData.hxx:163
MapNode::m_mapNodeData
std::vector< MapNodeData > m_mapNodeData
Definition: MapNode.hxx:195
FLORA
@ FLORA
10- Trees and other flora/Fauna tiles
Definition: enums.hxx:21
TileManager::getTileData
TileData * getTileData(const std::string &id) noexcept
Get the TileData struct for this tileID and all information associated with it.
Definition: TileManager.cxx:22
DemolishMode::DEFAULT
@ DEFAULT
Demolish everything, but not.
MapLayers::isLayerActive
static bool isLayerActive(unsigned int layer)
Check if given Layer is being drawn.
Definition: MapLayers.hxx:34
TileData::slopeTiles
TileSetData slopeTiles
Slope Tile Spritesheet information.
Definition: tileData.hxx:151
TERRAIN
@ TERRAIN
3- Terrain tiles, decorations, ... - must always be a "full" tile
Definition: enums.hxx:14
TileOrientation
TileOrientation
Definition: TileManager.hxx:41
MapNode::setNodeTransparency
void setNodeTransparency(const float transparencyFactor, const Layer &layer) const
Sets a node to be Transparent.
Definition: MapNode.cxx:117
TILE_S_AND_W
@ TILE_S_AND_W
Definition: TileManager.hxx:55
layersInActiveOrder
static Layer layersInActiveOrder[]
This is a ordered list of all relevant layers from the most active to the least active.
Definition: enums.hxx:34
Point::height
int height
The height level.
Definition: Point.hxx:26
MapNode::m_clippingWidth
int m_clippingWidth
Definition: MapNode.hxx:194
ROAD
@ ROAD
5- Optional layer, roads.
Definition: enums.hxx:16
MapNode::getTileID
const std::string & getTileID(Layer layer) const
get TileID of specific layer inside NodeData.
Definition: MapNode.hxx:89
MapNode::m_autotileBitmask
std::vector< unsigned char > m_autotileBitmask
Definition: MapNode.hxx:196
TILE_N_AND_S
@ TILE_N_AND_S
Definition: TileManager.hxx:53
layersPowerlinesCanCross
const static std::vector< Layer > layersPowerlinesCanCross
Definition: enums.hxx:38
MapNode::m_previousTileID
std::string m_previousTileID
Definition: MapNode.hxx:191
MapNode::m_isoCoordinates
Point m_isoCoordinates
Definition: MapNode.hxx:189
allLayersOrdered
static Layer allLayersOrdered[]
This is a ordered list of all relevant layers we need to interact with.
Definition: enums.hxx:29
GROUND_DECORATION
@ GROUND_DECORATION
13- Decoration to place beneath buildings. Like concrete or grass
Definition: enums.hxx:24
Singleton< TileManager >::instance
static TileManager & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
LAYERS_COUNT
@ LAYERS_COUNT
this must be LAST !!!
Definition: enums.hxx:25
N
@ N
Definition: TileManager.hxx:25
TILE_N_AND_E_RECT
@ TILE_N_AND_E_RECT
Definition: TileManager.hxx:59
MapNode::isPlacableOnSlope
bool isPlacableOnSlope(const std::string &tileID) const
check if tileID placeable on slope tile.
Definition: MapNode.cxx:124
Layer
Layer
All Layers we have.
Definition: enums.hxx:9
UNDERGROUND
@ UNDERGROUND
2- Optional layer - Pipes, Subway-pipes and so onn
Definition: enums.hxx:13
MapNode::isLayerOccupied
bool isLayerOccupied(const Layer &layer) const
Definition: MapNode.hxx:155
TILE_DEFAULT_ORIENTATION
@ TILE_DEFAULT_ORIENTATION
Definition: TileManager.hxx:43
MapNodeData
Definition: MapNode.hxx:17
TileData
Holds all releavted information to this specific tile.
Definition: tileData.hxx:135
MapNode::setTileID
void setTileID(const std::string &tileType, const Point &origPoint)
Definition: MapNode.cxx:50
SLOPES
@ SLOPES
Definition: TileManager.hxx:19