Loading [MathJax]/extensions/MathMenu.js
 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file.
3 #include "../services/GameClock.hxx"
4 #include "../services/Randomizer.hxx"
35 if (zoneArea.isMemberOf(nodeToVacate))
37 zoneArea.setVacancy(nodeToVacate,
true);
52 if (zoneArea.isMemberOf(nodeToOccupy))
54 zoneArea.setVacancy(nodeToOccupy,
false);
88 if (zoneArea.isVacant() && zoneArea.hasPowerSupply())
92 for (
auto node : zoneArea)
101 zoneArea.spawnBuildings();
108 std::vector<int> neighborZones;
111 for (
auto &zoneArea : zoneAreas)
113 if (zoneArea.getZone() == zoneNode.
zoneType && (zoneArea.getZoneDensity() == zoneNode.
zoneDensity) &&
116 neighborZones.push_back(i);
121 return neighborZones;
128 if (zoneNeighbour.empty())
131 zoneAreas.emplace_back(zoneNode);
133 else if (zoneNeighbour.size() == 1)
136 zoneAreas[zoneNeighbour[0]].addNode(zoneNode);
141 ZoneArea &mergedZone = zoneAreas[zoneNeighbour[0]];
144 for (
int idx = 1; idx < zoneNeighbour.size(); ++idx)
149 for (
int idx = zoneNeighbour.size() - 1; idx > 0; --idx)
151 zoneAreas.erase(zoneAreas.begin() + zoneNeighbour[idx]);
158 std::vector<ZoneArea> newZoneAreas;
172 if (zoneIt->isMemberOf(coordinate))
174 zoneIt->removeZoneNode(coordinate);
176 if (zoneIt->size() == 0)
183 assert(zoneAreas.size() > 0);
186 if (zoneAreas.size() > 1)
200 for (
const auto &grid : powerGrid)
204 if (
bool isGridConnected =
206 std::find_if(area.begin(), area.end(), [grid](
const ZoneNode &node) { return grid.isNeighbor(node.coordinate); });
209 if (grid.getPowerLevel() > 0)
211 area.setPowerSupply(
true);
215 area.setPowerSupply(
false);
268 ZoneNode nodeToAdd = {mapNode.getCoordinates(), mapNode.getTileData(
Layer::ZONE)->zoneTypes[0],
void updatePlacedNodes(const MapNode &mapNode)
@ DE_ZONE
Remove only zones.
std::vector< ZoneArea > m_zoneAreas
void spawnBuildings()
Spawn Buildings on the gathered tileMap.
void updatePower(const std::vector< PowerGrid > &powerGrid)
std::vector< Point > m_nodesToVacate
All zoneAreas.
void mergeZoneAreas(ZoneArea &mainZone, ZoneArea &toBeMerged)
void removeZoneNode(Point coordinate)
Removes a zonenode.
const Point & getCoordinates() const
get iso coordinates of this node
void update()
Process previously cached nodes to update.
const TileData * getTileData(Layer layer) const
Class that holds map nodes.
@ ZONE
4- Optional layer, zones(Industrial/Residential/Commercial).
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
void addZoneNodeToArea(ZoneNode &zoneNode, std::vector< ZoneArea > &zoneAreas)
Adds a zoneNode to a given area.
std::vector< Point > m_nodesToRemove
All zoneAreas.
void updateRemovedNodes(const MapNode *mapNode)
std::vector< ZoneType > zoneTypes
Restrict this building to a zone type.
@ DEFAULT
Demolish everything, but not.
std::vector< ZoneNode > m_nodesToAdd
All zoneAreas.
std::vector< ZoneArea > rebuildZoneArea(ZoneArea &zoneArea)
rebuild a certain zone area
std::function< R(Args...)> slot(instance &object, R(Class::*method)(Args...))
This function creates a std::function by binding object to the member function pointer method.
std::vector< ZoneDensity > zoneDensity
Restrict this building to a certain zone density. See enum ZoneDensity.
static SignalMediator & instance(void)
Get an instance of the singleton.
std::vector< int > getAdjacentZoneAreas(const ZoneNode &zoneNode, std::vector< ZoneArea > &zoneAreas)
get a list of neighboring zoneareas for a zoneNode
GameClock::ClockTaskHndl addRealTimeClockTask(ClockCbk cbk, DelayType delay, PeriodType period=TimePointZero)
Add new real time clock task.
void addNode(ZoneNode zoneNode) override
Add a zoneNode to this zoneArea.
std::vector< Point > m_nodesToOccupy
All zoneAreas.