changeset 12367:d929feeb1360 draft

(svn r16791) -Codechange: unify (and document) the Remove[StationType] functions.
author rubidium <rubidium@openttd.org>
date Fri, 10 Jul 2009 22:46:30 +0000
parents 9065de7846a5
children a4189fef49e7
files src/station_cmd.cpp
diffstat 1 files changed, 51 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1234,13 +1234,21 @@
 }
 
 
-static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, DoCommandFlag flags)
+/**
+ * Remove a rail road station
+ * @param tile TileIndex been queried
+ * @param flags operation to perform
+ * @return cost or failure of operation
+ */
+static CommandCost RemoveRailroadStation(TileIndex tile, DoCommandFlag flags)
 {
 	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
 	if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) {
 		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
 	}
 
+	Station *st = Station::GetByTile(tile);
+
 	/* Current company owns the station? */
 	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
 
@@ -1258,8 +1266,9 @@
 		do {
 			/* for nonuniform stations, only remove tiles that are actually train station tiles */
 			if (st->TileBelongsToRailStation(tile)) {
-				if (!EnsureNoVehicleOnGround(tile))
+				if (!EnsureNoVehicleOnGround(tile)) {
 					return CMD_ERROR;
+				}
 				cost.AddCost(_price.remove_rail_station);
 				if (flags & DC_EXEC) {
 					/* read variables before the station tile is removed */
@@ -1480,14 +1489,16 @@
 }
 
 
-/** Remove a bus station
- * @param st Station to remove
+/**
+ * Remove a bus station/truck stop
+ * @param tile TileIndex been queried
  * @param flags operation to perform
- * @param tile TileIndex been queried
  * @return cost or failure of operation
  */
-static CommandCost RemoveRoadStop(Station *st, DoCommandFlag flags, TileIndex tile)
+static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
 {
+	Station *st = Station::GetByTile(tile);
+
 	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
 		return CMD_ERROR;
 	}
@@ -1562,7 +1573,7 @@
 {
 	/* Make sure the specified tile is a road stop of the correct type */
 	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
-	Station *st = Station::GetByTile(tile);
+
 	/* Save the stop info before it is removed */
 	bool is_drive_through = IsDriveThroughStopTile(tile);
 	RoadTypes rts = GetRoadTypes(tile);
@@ -1572,7 +1583,7 @@
 
 	Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
 	Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
-	CommandCost ret = RemoveRoadStop(st, flags, tile);
+	CommandCost ret = RemoveRoadStop(tile, flags);
 
 	/* If the stop was a drive-through stop replace the road */
 	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
@@ -1843,13 +1854,21 @@
 	return cost;
 }
 
-static CommandCost RemoveAirport(Station *st, DoCommandFlag flags)
+/**
+ * Remove an airport
+ * @param tile TileIndex been queried
+ * @param flags operation to perform
+ * @return cost or failure of operation
+ */
+static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
 {
+	Station *st = Station::GetByTile(tile);
+
 	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
 		return CMD_ERROR;
 	}
 
-	TileIndex tile = st->airport_tile;
+	tile = st->airport_tile;
 
 	const AirportFTAClass *afc = st->Airport();
 	int w = afc->size_x;
@@ -1972,12 +1991,18 @@
 	return false;
 }
 
-static CommandCost RemoveBuoy(Station *st, DoCommandFlag flags)
+/**
+ * Remove a buoy
+ * @param tile TileIndex been queried
+ * @param flags operation to perform
+ * @return cost or failure of operation
+ */
+static CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
 {
 	/* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
 	if (!Company::IsValidID(_current_company) && !(flags & DC_BANKRUPT)) return_cmd_error(INVALID_STRING_ID);
 
-	TileIndex tile = st->dock_tile;
+	Station *st = Station::GetByTile(tile);
 
 	if (HasStationInUse(st->index, INVALID_COMPANY)) return_cmd_error(STR_BUOY_IS_IN_USE);
 	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
@@ -2124,8 +2149,15 @@
 	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
 }
 
-static CommandCost RemoveDock(Station *st, DoCommandFlag flags)
+/**
+ * Remove a dock
+ * @param tile TileIndex been queried
+ * @param flags operation to perform
+ * @return cost or failure of operation
+ */
+static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
 {
+	Station *st = Station::GetByTile(tile);
 	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 
 	TileIndex tile1 = st->dock_tile;
@@ -3074,21 +3106,19 @@
 		}
 	}
 
-	Station *st = Station::GetByTile(tile);
-
 	switch (GetStationType(tile)) {
-		case STATION_RAIL:    return RemoveRailroadStation(st, tile, flags);
-		case STATION_AIRPORT: return RemoveAirport(st, flags);
+		case STATION_RAIL:    return RemoveRailroadStation(tile, flags);
+		case STATION_AIRPORT: return RemoveAirport(tile, flags);
 		case STATION_TRUCK:
 			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
 				return_cmd_error(STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST);
-			return RemoveRoadStop(st, flags, tile);
+			return RemoveRoadStop(tile, flags);
 		case STATION_BUS:
 			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
 				return_cmd_error(STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST);
-			return RemoveRoadStop(st, flags, tile);
-		case STATION_BUOY:    return RemoveBuoy(st, flags);
-		case STATION_DOCK:    return RemoveDock(st, flags);
+			return RemoveRoadStop(tile, flags);
+		case STATION_BUOY:    return RemoveBuoy(tile, flags);
+		case STATION_DOCK:    return RemoveDock(tile, flags);
 		default: break;
 	}