* Check whether the given tile is suitable for a waypoint. * @param tile the tile to check for suitability * @param axis the axis of the waypoint * @param waypoint Waypoint the waypoint to check for is already joined to. If we find another waypoint it can join to it will throw an error. */
| 150 | * @param waypoint Waypoint the waypoint to check for is already joined to. If we find another waypoint it can join to it will throw an error. |
| 151 | */ |
| 152 | static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint) |
| 153 | { |
| 154 | /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints. |
| 155 | * so waypoint points to StationID::Invalid() if we can build on any waypoint. |
| 156 | * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */ |
| 157 | if (waypoint != nullptr && IsTileType(tile, MP_STATION)) { |
| 158 | if (!IsRailWaypoint(tile)) { |
| 159 | return ClearTile_Station(tile, DoCommandFlag::Auto); // get error message |
| 160 | } else { |
| 161 | StationID wp = GetStationIndex(tile); |
| 162 | if (*waypoint == StationID::Invalid()) { |
| 163 | *waypoint = wp; |
| 164 | } else if (*waypoint != wp) { |
| 165 | return CommandCost(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if (GetAxisForNewRailWaypoint(tile) != axis) return CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); |
| 171 | |
| 172 | Owner owner = GetTileOwner(tile); |
| 173 | CommandCost ret = CheckOwnership(owner); |
| 174 | if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile); |
| 175 | if (ret.Failed()) return ret; |
| 176 | |
| 177 | Slope tileh = GetTileSlope(tile); |
| 178 | if (tileh != SLOPE_FLAT && |
| 179 | (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) { |
| 180 | return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); |
| 181 | } |
| 182 | |
| 183 | return CommandCost(); |
| 184 | } |
| 185 | |
| 186 | extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp, bool is_road); |
| 187 | extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta); |
no test coverage detected