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

Method driveDone

MicropolisCore/src/MicropolisEngine/src/traffic.cpp:441–483  ·  view source on GitHub ↗

* Has the journey arrived at its destination? * @param pos Current position. * @param destZone Zonetype to drive to. * @return Destination has been reached. */

Source from the content-addressed store, hash-verified

439 * @return Destination has been reached.
440 */
441bool Micropolis::driveDone(const Position &pos, ZoneType destZone)
442{
443 // FIXME: Use macros to determine the zone type: residential, commercial or industrial.
444 /* commercial, industrial, residential destinations */
445 static const MapTile targetLow[3] = {COMBASE, LHTHR, LHTHR};
446 static const MapTile targetHigh[3] = {NUCLEAR, PORT, COMBASE};
447
448 assert(ZT_NUM_DESTINATIONS == LENGTH_OF(targetLow));
449 assert(ZT_NUM_DESTINATIONS == LENGTH_OF(targetHigh));
450
451 MapTile l = targetLow[destZone]; // Lowest acceptable tile value
452 MapTile h = targetHigh[destZone]; // Highest acceptable tile value
453
454 if (pos.posY > 0) {
455 MapTile z = map[pos.posX][pos.posY - 1] & LOMASK;
456 if (z >= l && z <= h) {
457 return true;
458 }
459 }
460
461 if (pos.posX < (WORLD_W - 1)) {
462 MapTile z = map[pos.posX + 1][pos.posY] & LOMASK;
463 if (z >= l && z <= h) {
464 return true;
465 }
466 }
467
468 if (pos.posY < (WORLD_H - 1)) {
469 MapTile z = map[pos.posX][pos.posY + 1] & LOMASK;
470 if (z >= l && z <= h) {
471 return true;
472 }
473 }
474
475 if (pos.posX > 0) {
476 MapTile z = map[pos.posX - 1][pos.posY] & LOMASK;
477 if (z >= l && z <= h) {
478 return true;
479 }
480 }
481
482 return false;
483}
484
485
486/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected