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

Method doRail

MicropolisCore/src/MicropolisEngine/src/simulate.cpp:1005–1033  ·  view source on GitHub ↗

* Handle rail track. * Generate a train, and handle road deteriorating effects. * @param pos Position of the rail. */

Source from the content-addressed store, hash-verified

1003 * @param pos Position of the rail.
1004 */
1005void Micropolis::doRail(const Position &pos)
1006{
1007 railTotal++;
1008
1009 generateTrain(pos.posX, pos.posY);
1010
1011 if (roadEffect < (15 * MAX_ROAD_EFFECT / 16)) {
1012
1013 // roadEffect < 15/16 of max road, enable deteriorating rail
1014 if (!(getRandom16() & 511)) {
1015
1016 MapValue curValue = map[pos.posX][pos.posY];
1017 if (!(curValue & CONDBIT)) {
1018
1019 // Otherwise the '(getRandom16() & 31)' makes no sense
1020 assert(MAX_ROAD_EFFECT == 32);
1021 if (roadEffect < (getRandom16() & 31)) {
1022 MapTile tile = curValue & LOMASK;
1023 if (tile < RAILBASE + 2) {
1024 map[pos.posX][pos.posY] = RIVER;
1025 } else {
1026 map[pos.posX][pos.posY] = randomRubble();
1027 }
1028 return;
1029 }
1030 }
1031 }
1032 }
1033}
1034
1035
1036/**

Callers

nothing calls this directly

Calls 1

randomRubbleFunction · 0.85

Tested by

no test coverage detected