MCPcopy Create free account
hub / github.com/SimHacker/micropolis / doPowerScan

Method doPowerScan

MicropolisCore/src/MicropolisEngine/src/power.cpp:115–156  ·  view source on GitHub ↗

* Scan the map for powered tiles, and copy them to the Micropolis::powerGridMap * array. * Also warns the user about using too much power ('buy another power plant'). */

Source from the content-addressed store, hash-verified

113 * Also warns the user about using too much power ('buy another power plant').
114 */
115void Micropolis::doPowerScan()
116{
117 Direction2 anyDir,dir;
118 int conNum;
119
120 // Clear power map.
121 powerGridMap.clear();
122
123 // Power that the combined coal and nuclear power plants can deliver.
124 Quad maxPower = coalPowerPop * COAL_POWER_STRENGTH +
125 nuclearPowerPop * NUCLEAR_POWER_STRENGTH;
126
127 Quad numPower = 0; // Amount of power used.
128
129 while (powerStackPointer > 0) {
130 Position pos = pullPowerStack();
131 anyDir = DIR2_INVALID;
132 do {
133 numPower++;
134 if (numPower > maxPower) {
135 sendMessage(MESSAGE_NOT_ENOUGH_POWER);
136 return;
137 }
138 if (anyDir != DIR2_INVALID) {
139 pos.move(anyDir);
140 }
141 powerGridMap.worldSet(pos.posX, pos.posY, 1);
142 conNum = 0;
143 dir = DIR2_BEGIN;
144 while (dir < DIR2_END && conNum < 2) {
145 if (testForConductive(pos, dir)) {
146 conNum++;
147 anyDir = dir;
148 }
149 dir = increment90(dir);
150 }
151 if (conNum > 1) {
152 pushPowerStack(pos);
153 }
154 } while (conNum);
155 }
156}
157
158
159/**

Callers

nothing calls this directly

Calls 4

increment90Function · 0.85
worldSetMethod · 0.80
clearMethod · 0.45
moveMethod · 0.45

Tested by

no test coverage detected