* 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'). */
| 113 | * Also warns the user about using too much power ('buy another power plant'). |
| 114 | */ |
| 115 | void 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 | /** |
nothing calls this directly
no test coverage detected