(svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
authorrubidium
Sat, 26 May 2007 14:24:19 +0000
changeset 6703 fdb8d05ce28f
parent 6702 85c63eaaa0de
child 6704 c18d958abfdb
(svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
src/station_cmd.cpp
--- a/src/station_cmd.cpp	Sat May 26 13:00:52 2007 +0000
+++ b/src/station_cmd.cpp	Sat May 26 14:24:19 2007 +0000
@@ -1248,7 +1248,6 @@
 	bool is_drive_through = HASBIT(p2, 1);
 	bool build_over_road  = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL;
 	bool town_owned_road  = build_over_road && IsTileOwner(tile, OWNER_TOWN);
-	Owner cur_owner = _current_player;
 	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
 
 	if (rts == ROADTYPES_NONE || HASBIT(rts, ROADTYPE_HWAY)) return CMD_ERROR;
@@ -1262,32 +1261,29 @@
 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
 	/* Road bits in the wrong direction */
 	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
+
+	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
+
+	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
+
+	int32 cost = 0;
+
 	/* Not allowed to build over this road */
 	if (build_over_road) {
 		if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
 		if (GetRoadTileType(tile) != ROAD_TILE_NORMAL) return CMD_ERROR;
 
 		RoadTypes cur_rts = GetRoadTypes(tile);
-		if (!IsTileOwner(tile, OWNER_TOWN) && (
-				((HASBIT(cur_rts, ROADTYPE_ROAD) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_ROAD)))) ||
-				((HASBIT(cur_rts, ROADTYPE_TRAM) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_TRAM)))))) return CMD_ERROR;
+		if (GetRoadOwner(tile, ROADTYPE_ROAD) != OWNER_TOWN && HASBIT(cur_rts, ROADTYPE_ROAD) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_ROAD))) return CMD_ERROR;
+		if (HASBIT(cur_rts, ROADTYPE_TRAM) && !CheckOwnership(GetRoadOwner(tile, ROADTYPE_TRAM))) return CMD_ERROR;
+
 		/* Do not remove roadtypes! */
-		rts |= GetRoadTypes(tile);
+		rts |= cur_rts;
+	} else {
+		cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
+		if (CmdFailed(cost)) return cost;
 	}
 
-	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
-
-	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
-		return CMD_ERROR;
-
-	if (build_over_road) flags ^= DC_AUTO;
-
-	if (town_owned_road) _current_player = OWNER_TOWN;
-	int32 ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
-	_current_player = cur_owner;
-	if (CmdFailed(ret)) return ret;
-	int32 cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding
-
 	Station *st = NULL;
 
 	if (!_patches.adjacent_stations || !HASBIT(p2, 5)) {