(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
authorrubidium
Wed, 14 Feb 2007 20:58:19 +0000
changeset 6018 5d143f68ac94
parent 6017 3d41c97a57fe
child 6019 1422a34ad091
(svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
src/road_gui.cpp
src/station_cmd.cpp
src/table/files.h
--- a/src/road_gui.cpp	Wed Feb 14 20:48:00 2007 +0000
+++ b/src/road_gui.cpp	Wed Feb 14 20:58:19 2007 +0000
@@ -109,8 +109,6 @@
 				!(GetRoadBits(tile) & ((DiagDirection)p1 == DIAGDIR_NE ? ROAD_Y : ROAD_X)))) {
 
 			cmd ^= CMD_AUTO;
-			SETBIT(p2, 2); // We're building over an existing road
-			if (IsTileOwner(tile, OWNER_TOWN)) SETBIT(p2, 3); // It's a town owned road
 		}
 	}
 	DoCommandP(tile, p1, p2, CcRoadDepot, cmd);
--- a/src/station_cmd.cpp	Wed Feb 14 20:48:00 2007 +0000
+++ b/src/station_cmd.cpp	Wed Feb 14 20:58:19 2007 +0000
@@ -1250,8 +1250,6 @@
  * @param p1 entrance direction (DiagDirection)
  * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
  *           bit 1: 0 for normal, 1 for drive-through
- *           bit 2: 0 for normal, 1 for build over road
- *           bit 3: 0 for player owned road, 1 for town owned road
  */
 int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
@@ -1261,27 +1259,28 @@
 	int32 ret;
 	bool type = HASBIT(p2, 0);
 	bool is_drive_through = HASBIT(p2, 1);
+	bool build_over_road  = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL;
 	Owner cur_owner = _current_player;
 
 	/* Saveguard the parameters */
 	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
 	/* If it is a drive-through stop check for valid axis */
 	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
-	/* If overbuilding a road check tile is a valid road tile */
-	if (HASBIT(p2, 2) && !(IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL)) return CMD_ERROR;
-	/* If overbuilding a town road,check tile is town owned and patch setting is enabled */
-	if (HASBIT(p2, 3) && !(_patches.road_stop_on_town_road && IsTileOwner(tile, OWNER_TOWN))) return CMD_ERROR;
+	/* Road bits in the wrong direction */
+	if (build_over_road && (GetRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return CMD_ERROR;
+	/* Not allowed to build over this road */
+	if (build_over_road && !IsTileOwner(tile, _current_player) && !(IsTileOwner(tile, OWNER_TOWN) && _patches.road_stop_on_town_road)) return CMD_ERROR;
 
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
 	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
 		return CMD_ERROR;
 
-	if (is_drive_through & HASBIT(p2, 3)) _current_player = OWNER_TOWN;
+	if (build_over_road && IsTileOwner(tile, OWNER_TOWN)) _current_player = OWNER_TOWN;
 	ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
 	_current_player = cur_owner;
 	if (CmdFailed(ret)) return ret;
-	cost = HASBIT(p2, 2) ? 0 : ret; // Don't add cost of clearing road when overbuilding
+	cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding
 
 	st = GetStationAround(tile, 1, 1, INVALID_STATION);
 	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
--- a/src/table/files.h	Wed Feb 14 20:48:00 2007 +0000
+++ b/src/table/files.h	Wed Feb 14 20:58:19 2007 +0000
@@ -61,4 +61,5 @@
 	{ "elrailsw.grf",  { 0x4f, 0xf9, 0xac, 0x79, 0x50, 0x28, 0x9b, 0xe2, 0x15, 0x30, 0xa8, 0x1e, 0xd5, 0xfd, 0xe1, 0xda } },
 	{ "openttd.grf",   { 0x59, 0x22, 0x19, 0xe0, 0x6e, 0xe7, 0xb6, 0xa3, 0x55, 0x53, 0xcc, 0x9e, 0xbc, 0xaf, 0xcc, 0x83 } },
 	{ "trkfoundw.grf", { 0x12, 0x33, 0x3f, 0xa3, 0xd1, 0x86, 0x8b, 0x04, 0x53, 0x18, 0x9c, 0xee, 0xf9, 0x2d, 0xf5, 0x95 } },
+	{ "roadstops.grf", { 0x8c, 0xd9, 0x45, 0x21, 0x28, 0x82, 0x96, 0x45, 0x33, 0x22, 0x7a, 0xb9, 0x0d, 0xf3, 0x67, 0x4a } },
 };