diff options
author | rubidium <rubidium@openttd.org> | 2007-09-26 16:12:43 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-09-26 16:12:43 +0000 |
commit | 01edaeec578bddb73b4513baf9d8bfe5f9a886b0 (patch) | |
tree | 226af8de8514a96ed474dc9590f68e2c517a31d9 /src/road.cpp | |
parent | a85e18c92200590c84a6c3d3f60dd41f394cc0fe (diff) | |
download | openttd-01edaeec578bddb73b4513baf9d8bfe5f9a886b0.tar.xz |
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
Diffstat (limited to 'src/road.cpp')
-rw-r--r-- | src/road.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/road.cpp b/src/road.cpp new file mode 100644 index 000000000..ae806647f --- /dev/null +++ b/src/road.cpp @@ -0,0 +1,69 @@ +#include "stdafx.h" +#include "openttd.h" +#include "functions.h" +#include "rail_map.h" +#include "road.h" +#include "road_map.h" +#include "water_map.h" +#include "macros.h" + +bool IsPossibleCrossing(const TileIndex tile, Axis ax) +{ + return (IsTileType(tile, MP_RAILWAY) && + !HasSignals(tile) && + GetTrackBits(tile) == (ax == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) && + GetTileSlope(tile, NULL) == SLOPE_FLAT); +} + +RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb) +{ + for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { + const TileIndex neighbor_tile = TileAddByDiagDir(tile, dir); + + /* Get the Roadbit pointing to the neighbor_tile */ + const RoadBits target_rb = DiagDirToRoadBits(dir); + + /* If the roadbit is in the current plan */ + if (org_rb & target_rb) { + bool connective = false; + const RoadBits mirrored_rb = MirrorRoadBits(target_rb); + + switch (GetTileType(neighbor_tile)) { + /* Allways connective ones */ + case MP_CLEAR: case MP_TREES: + connective = true; + break; + + /* The conditionaly connective ones */ + case MP_TUNNELBRIDGE: + case MP_STATION: + case MP_ROAD: { + const RoadBits neighbor_rb = GetAnyRoadBits(neighbor_tile, ROADTYPE_ROAD) | GetAnyRoadBits(neighbor_tile, ROADTYPE_TRAM); + + /* Accept only connective tiles */ + connective = (neighbor_rb & mirrored_rb) || // Neighbor has got the fitting RoadBit + COUNTBITS(neighbor_rb) == 1; // Neighbor has got only one Roadbit + + } break; + + case MP_RAILWAY: + connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir)); + break; + + case MP_WATER: + /* Check for real water tile */ + connective = !IsWater(neighbor_tile); + break; + + /* The defentetly not connective ones */ + default: break; + } + + /* If the neighbor tile is inconnective remove the planed road connection to it */ + if (!connective) org_rb ^= target_rb; + + } + } + + return org_rb; +} |