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

Method findPerimeterRoad

MicropolisCore/src/MicropolisEngine/src/traffic.cpp:227–252  ·  view source on GitHub ↗

* Find a connection to a road at the perimeter. * @param pos Starting position. * Gets updated when a perimeter has been found. * @return Indication that a connection has been found. * * @todo We could randomize the search. */

Source from the content-addressed store, hash-verified

225 * @todo We could randomize the search.
226 */
227bool Micropolis::findPerimeterRoad(Position *pos)
228{
229 /* look for road on edges of zone */
230 static const short PerimX[12] = {-1, 0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2};
231 static const short PerimY[12] = {-2,-2,-2,-1, 0, 1, 2, 2, 2, 1, 0,-1};
232 short tx, ty;
233
234 for (short z = 0; z < 12; z++) {
235
236 tx = pos->posX + PerimX[z];
237 ty = pos->posY + PerimY[z];
238
239 if (testBounds(tx, ty)) {
240
241 if (roadTest(map[tx][ty])) {
242
243 pos->posX = tx;
244 pos->posY = ty;
245
246 return true;
247 }
248 }
249 }
250
251 return false;
252}
253
254
255/**

Callers

nothing calls this directly

Calls 1

testBoundsFunction · 0.85

Tested by

no test coverage detected