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

#include <PowerGrid.hxx>

+ Inheritance diagram for PowerGrid:
+ Collaboration diagram for PowerGrid:

Public Member Functions

 PowerGrid (PowerNode powerNode)
 
int getPowerLevel () const
 Get the Power Level of this grid. More...
 
void updatePowerLevel ()
 Recalculate the power level of this power grid. More...
 
- Public Member Functions inherited from MapGrid< PowerNode >
 MapGrid (PowerNode node)
 
virtual ~MapGrid ()=0
 
size_t size ()
 
virtual void addNode (PowerNode node)
 Add a T node to this gridnode. More...
 
virtual void removeNode (Point coordinate)
 Remove a node on a given coordinate from this gridnode. More...
 
bool isNeighbor (Point coordinate) const
 If this coordinate is a neighbor of one of the node in the grid. More...
 
bool isMemberOf (Point coordinate) const
 If this coordinate is part of the grid. More...
 
auto begin ()
 
auto end ()
 

Private Attributes

int m_powerLevel = 0
 

Friends

void mergePowerGrids (PowerGrid &mainGrid, PowerGrid &toBeMerged)
 

Additional Inherited Members

- Protected Attributes inherited from MapGrid< PowerNode >
std::vector< PowerNodem_gridNodes
 

Detailed Description

Definition at line 17 of file PowerGrid.hxx.

Constructor & Destructor Documentation

◆ PowerGrid()

PowerGrid::PowerGrid ( PowerNode  powerNode)

Definition at line 5 of file PowerGrid.cxx.

5 : MapGrid(powerNode) {}

Member Function Documentation

◆ getPowerLevel()

int PowerGrid::getPowerLevel ( ) const
inline

Get the Power Level of this grid.

Returns
int power level in MW

Definition at line 27 of file PowerGrid.hxx.

27 { return m_powerLevel; };

◆ updatePowerLevel()

void PowerGrid::updatePowerLevel ( )

Recalculate the power level of this power grid.

Definition at line 12 of file PowerGrid.cxx.

13 {
14  // reset the power level of this grid before recalculating
15  m_powerLevel = 0;
16  for (const auto &node : m_gridNodes)
17  {
18  if (MapFunctions::instance().getMapNode(node.coordinate).getTileData(Layer::BUILDINGS) && node.powerProduction == 0)
19  { // each occupied node consumes one power unit
20  m_powerLevel--;
21  }
22 
23  // For multi-tile buildings, each tile has the same tiledata (including power level).
24  // so make sure we only add it once (if it's the origin node)
25  if (MapFunctions::instance().getMapNode(node.coordinate).isOriginNode())
26  {
27  m_powerLevel += node.powerProduction;
28  }
29  }
30 }
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ mergePowerGrids

void mergePowerGrids ( PowerGrid mainGrid,
PowerGrid toBeMerged 
)
friend

Definition at line 7 of file PowerGrid.cxx.

8 {
9  mainGrid.m_gridNodes.insert(mainGrid.end(), toBeMerged.begin(), toBeMerged.end());
10 }

Member Data Documentation

◆ m_powerLevel

int PowerGrid::m_powerLevel = 0
private

Definition at line 38 of file PowerGrid.hxx.


The documentation for this class was generated from the following files:
MapGrid::begin
auto begin()
Definition: MapGrid.hxx:46
MapGrid::end
auto end()
Definition: MapGrid.hxx:47
MapGrid< PowerNode >::MapGrid
MapGrid(PowerNode node)
Definition: MapGrid.inl.hxx:3
BUILDINGS
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
Definition: enums.hxx:19
MapGrid< PowerNode >::m_gridNodes
std::vector< PowerNode > m_gridNodes
Definition: MapGrid.hxx:50
Singleton< MapFunctions >::instance
static MapFunctions & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
PowerGrid::m_powerLevel
int m_powerLevel
Definition: PowerGrid.hxx:38