/** * Callback to start placing a bridge. * @param tile Start tile of the bridge. */ static void PlaceRoad_Bridge(TileIndex tile, Window *w) { if (IsBridgeTile(tile)) { TileIndex other_tile = GetOtherTunnelBridgeEnd(tile); Point pt = {0, 0}; w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile); } else { VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE); } }
static typename TileIndexT<Tgeneric>::T GetBridgeEnd(typename TileIndexT<Tgeneric>::T tile, DiagDirection dir) { TileIndexDiff delta = TileOffsByDiagDir<Tgeneric>(dir, MapOf(tile)); dir = ReverseDiagDir(dir); do { tile += delta; } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir); return tile; }
/** * Finds the end of a bridge in the specified direction starting at a middle tile * @param tile the bridge tile to find the bridge ramp for * @param dir the direction to search in */ static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir) { TileIndexDiff delta = TileOffsByDiagDir(dir); dir = ReverseDiagDir(dir); do { tile += delta; } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir); return tile; }
/** * Does the given track direction on the given tile yeild an uphill penalty? * @param tile The tile to check. * @param td The track direction to check. * @return True if there's a slope, otherwise false. */ FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td) { if (IsDiagonalTrackdir(td)) { if (IsBridgeTile(tile)) { /* it is bridge ramp, check if we are entering the bridge */ if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty /* we are entering the bridge */ Slope tile_slope = GetTileSlope(tile, NULL); Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile)); return !HasBridgeFlatRamp(tile_slope, axis); } else { /* not bridge ramp */ if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope Slope tile_slope = GetTileSlope(tile, NULL); return IsUphillTrackdir(tile_slope, td); // slopes uphill => apply penalty } } return false; }
typename TileIndexT<Tgeneric>::T GetOtherBridgeEnd(typename TileIndexT<Tgeneric>::T tile) { assert(IsBridgeTile(tile)); return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile)); }
/** * Starting at one bridge end finds the other bridge end * @param t the bridge ramp tile to find the other bridge ramp for */ TileIndex GetOtherBridgeEnd(TileIndex tile) { assert(IsBridgeTile(tile)); return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile)); }