1246 { |
1246 { |
1247 bool type = HASBIT(p2, 0); |
1247 bool type = HASBIT(p2, 0); |
1248 bool is_drive_through = HASBIT(p2, 1); |
1248 bool is_drive_through = HASBIT(p2, 1); |
1249 bool build_over_road = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL; |
1249 bool build_over_road = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL; |
1250 bool town_owned_road = build_over_road && IsTileOwner(tile, OWNER_TOWN); |
1250 bool town_owned_road = build_over_road && IsTileOwner(tile, OWNER_TOWN); |
1251 Owner cur_owner = _current_player; |
|
1252 RoadTypes rts = (RoadTypes)GB(p2, 2, 3); |
1251 RoadTypes rts = (RoadTypes)GB(p2, 2, 3); |
1253 |
1252 |
1254 if (rts == ROADTYPES_NONE || HASBIT(rts, ROADTYPE_HWAY)) return CMD_ERROR; |
1253 if (rts == ROADTYPES_NONE || HASBIT(rts, ROADTYPE_HWAY)) return CMD_ERROR; |
1255 |
1254 |
1256 /* Trams only have drive through stops */ |
1255 /* Trams only have drive through stops */ |
1260 if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR; |
1259 if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR; |
1261 /* If it is a drive-through stop check for valid axis */ |
1260 /* If it is a drive-through stop check for valid axis */ |
1262 if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR; |
1261 if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR; |
1263 /* Road bits in the wrong direction */ |
1262 /* Road bits in the wrong direction */ |
1264 if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION); |
1263 if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION); |
|
1264 |
|
1265 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
|
1266 |
|
1267 if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR; |
|
1268 |
|
1269 int32 cost = 0; |
|
1270 |
1265 /* Not allowed to build over this road */ |
1271 /* Not allowed to build over this road */ |
1266 if (build_over_road) { |
1272 if (build_over_road) { |
1267 if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD); |
1273 if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD); |
1268 if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) return CMD_ERROR; |
1274 if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) return CMD_ERROR; |
1269 |
1275 |
1270 RoadTypes cur_rts = GetRoadTypes(tile); |
1276 RoadTypes cur_rts = GetRoadTypes(tile); |
1271 if (!IsTileOwner(tile, OWNER_TOWN) && ( |
1277 if (GetRoadOwner(tile, ROADTYPE_ROAD) != OWNER_TOWN && HASBIT(cur_rts, ROADTYPE_ROAD) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_ROAD))) return CMD_ERROR; |
1272 ((HASBIT(cur_rts, ROADTYPE_ROAD) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_ROAD)))) || |
1278 if (HASBIT(cur_rts, ROADTYPE_TRAM) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_TRAM))) return CMD_ERROR; |
1273 ((HASBIT(cur_rts, ROADTYPE_TRAM) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_TRAM)))))) return CMD_ERROR; |
1279 |
1274 /* Do not remove roadtypes! */ |
1280 /* Do not remove roadtypes! */ |
1275 rts |= GetRoadTypes(tile); |
1281 rts |= cur_rts; |
1276 } |
1282 } else { |
1277 |
1283 cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL); |
1278 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
1284 if (CmdFailed(cost)) return cost; |
1279 |
1285 } |
1280 if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) |
|
1281 return CMD_ERROR; |
|
1282 |
|
1283 if (build_over_road) flags ^= DC_AUTO; |
|
1284 |
|
1285 if (town_owned_road) _current_player = OWNER_TOWN; |
|
1286 int32 ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL); |
|
1287 _current_player = cur_owner; |
|
1288 if (CmdFailed(ret)) return ret; |
|
1289 int32 cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding |
|
1290 |
1286 |
1291 Station *st = NULL; |
1287 Station *st = NULL; |
1292 |
1288 |
1293 if (!_patches.adjacent_stations || !HASBIT(p2, 5)) { |
1289 if (!_patches.adjacent_stations || !HASBIT(p2, 5)) { |
1294 st = GetStationAround(tile, 1, 1, INVALID_STATION); |
1290 st = GetStationAround(tile, 1, 1, INVALID_STATION); |