Changeset - r14721:f3e02434b6fb
[Not reviewed]
master
0 10 0
alberth - 15 years ago 2010-03-05 21:20:22
alberth@openttd.org
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
10 files changed with 109 insertions and 42 deletions:
0 comments (0 inline, 0 general)
src/disaster_cmd.cpp
Show inline comments
 
@@ -67,7 +67,7 @@ enum DisasterSubType {
 

	
 
static void DisasterClearSquare(TileIndex tile)
 
{
 
	if (!EnsureNoVehicleOnGround(tile)) return;
 
	if (EnsureNoVehicleOnGround(tile).Failed()) return;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
src/industry_cmd.cpp
Show inline comments
 
@@ -1337,7 +1337,9 @@ static CommandCost CheckIfIndustryTilesA
 
				return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
			}
 
		} else {
 
			if (!EnsureNoVehicleOnGround(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
			CommandCost ret = EnsureNoVehicleOnGround(cur_tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 
			if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
			const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
src/rail_cmd.cpp
Show inline comments
 
@@ -416,7 +416,7 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			break;
 
		}
 

	
 
		case MP_ROAD:
 
		case MP_ROAD: {
 
#define M(x) (1 << (x))
 
			/* Level crossings may only be built on these slopes */
 
			if (!HasBit(M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT), tileh)) {
 
@@ -424,7 +424,9 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			}
 
#undef M
 

	
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (IsNormalRoad(tile)) {
 
				if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
 
@@ -463,6 +465,7 @@ CommandCost CmdBuildSingleRail(TileIndex
 
				return_cmd_error(STR_ERROR_ALREADY_BUILT);
 
			}
 
			/* FALLTHROUGH */
 
		}
 

	
 
		default: {
 
			/* Will there be flat water on the lower halftile? */
 
@@ -528,10 +531,14 @@ CommandCost CmdRemoveSingleRail(TileInde
 
		case MP_ROAD: {
 
			if (!IsLevelCrossing(tile) ||
 
					GetCrossingRailBits(tile) != trackbit ||
 
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
 
					(!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
 
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile))) {
 
				return CMD_ERROR;
 
			}
 
			if (!(flags & DC_BANKRUPT)) {
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				ret.SetGlobalErrorMessage();
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				if (HasReservedTracks(tile, trackbit)) {
 
@@ -1408,7 +1415,13 @@ CommandCost CmdConvertRail(TileIndex til
 
			/* Vehicle on the tile when not converting Rail <-> ElRail
 
			 * Tunnels and bridges have special check later */
 
			if (tt != MP_TUNNELBRIDGE) {
 
				if (!IsCompatibleRail(type, totype) && !EnsureNoVehicleOnGround(tile)) continue;
 
				if (!IsCompatibleRail(type, totype)) {
 
					CommandCost ret = EnsureNoVehicleOnGround(tile);
 
					if (ret.Failed()) {
 
						ret.SetGlobalErrorMessage();
 
						continue;
 
					}
 
				}
 
				if (flags & DC_EXEC) { // we can safely convert, too
 
					TrackBits reserved = GetReservedTrackbits(tile);
 
					Track     track;
 
@@ -1524,8 +1537,9 @@ static CommandCost RemoveTrainDepot(Tile
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile))
 
		return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		/* read variables before the depot is removed */
 
@@ -1581,7 +1595,9 @@ static CommandCost ClearTile_Track(TileI
 

	
 
			/* when bankrupting, don't make water dirty, there could be a ship on lower halftile */
 
			if (water_ground && !(flags & DC_BANKRUPT)) {
 
				if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				ret.SetGlobalErrorMessage();
 
				if (ret.Failed()) return ret;
 

	
 
				/* The track was removed, and left a coast tile. Now also clear the water. */
 
				if (flags & DC_EXEC) DoClearSquare(tile);
src/road_cmd.cpp
Show inline comments
 
@@ -183,14 +183,19 @@ static CommandCost RemoveRoad(TileIndex 
 
	if (!HasBit(rts, rt)) return CMD_ERROR;
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD:
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			break;
 
		case MP_ROAD: {
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 
		} break;
 

	
 
		case MP_STATION:
 
		case MP_STATION: {
 
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			break;
 

	
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 
		} break;
 

	
 
		case MP_TUNNELBRIDGE: {
 
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
@@ -493,7 +498,9 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
							Owner owner = GetRoadOwner(tile, ROADTYPE_ROAD);
 
							if (owner != OWNER_NONE && !CheckOwnership(owner, tile)) return CMD_ERROR;
 

	
 
							if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
							CommandCost ret = EnsureNoVehicleOnGround(tile);
 
							ret.SetGlobalErrorMessage();
 
							if (ret.Failed()) return ret;
 

	
 
							/* Ignore half built tiles */
 
							if ((flags & DC_EXEC) && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
 
@@ -549,7 +556,9 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
				default: goto do_clear;
 
			}
 

	
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (flags & DC_EXEC) {
 
				Track railtrack = AxisToTrack(OtherAxis(roaddir));
 
@@ -627,7 +636,11 @@ do_clear:;
 
		}
 
	}
 

	
 
	if (!tile_cleared && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
	if (!tile_cleared) {
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	cost.AddCost(CountBits(pieces) * _price[PR_BUILD_ROAD]);
 
	if (!tile_cleared && IsTileType(tile, MP_TUNNELBRIDGE)) {
 
@@ -900,7 +913,9 @@ static CommandCost RemoveRoadDepot(TileI
 
{
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		delete Depot::GetByTile(tile);
 
@@ -1358,7 +1373,7 @@ static void TileLoop_Road(TileIndex tile
 
			if (t->road_build_months != 0 &&
 
					(DistanceManhattan(t->xy, tile) < 8 || grp != HZB_TOWN_EDGE) &&
 
					IsNormalRoad(tile) && !HasAtMostOneBit(GetAllRoadBits(tile))) {
 
				if (GetFoundationSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && Chance16(1, 40)) {
 
				if (GetFoundationSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile).Succeeded() && Chance16(1, 40)) {
 
					StartRoadWorks(tile);
 

	
 
					SndPlayTileFx(SND_21_JACKHAMMER, tile);
src/station_cmd.cpp
Show inline comments
 
@@ -671,7 +671,9 @@ CommandCost CheckBuildableTile(TileIndex
 
		return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
	}
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 
@@ -1362,7 +1364,11 @@ CommandCost RemoveFromRailBaseStation(Ti
 
		if (!HasStationTileRail(tile)) continue;
 

	
 
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
 
		if (!EnsureNoVehicleOnGround(tile)) continue;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		if (ret.Failed()) {
 
			ret.SetGlobalErrorMessage();
 
			continue;
 
		}
 

	
 
		/* Check ownership of station */
 
		T *st = T::GetByTile(tile);
 
@@ -1526,7 +1532,9 @@ CommandCost RemoveRailStation(T *st, DoC
 
		/* for nonuniform stations, only remove tiles that are actually train station tiles */
 
		if (!st->TileBelongsToRailStation(tile)) continue;
 

	
 
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 

	
 
		cost.AddCost(_price[PR_CLEAR_STATION_RAIL]);
 
		if (flags & DC_EXEC) {
 
@@ -1832,7 +1840,9 @@ static CommandCost RemoveRoadStop(TileIn
 
		/* remove the 'going through road stop' status from all vehicles on that tile */
 
		if (flags & DC_EXEC) FindVehicleOnPos(tile, NULL, &ClearRoadStopStatusEnum);
 
	} else {
 
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -2234,7 +2244,9 @@ static CommandCost RemoveAirport(TileInd
 
	TILE_AREA_LOOP(tile_cur, st->airport) {
 
		if (!st->TileBelongsToAirport(tile_cur)) continue;
 

	
 
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 

	
 
		cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
 

	
 
@@ -2432,8 +2444,10 @@ static CommandCost RemoveDock(TileIndex 
 
	TileIndex tile1 = st->dock_tile;
 
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
 

	
 
	if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
 
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile1);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile1);
src/unmovable_cmd.cpp
Show inline comments
 
@@ -177,7 +177,9 @@ CommandCost CmdSellLandArea(TileIndex ti
 
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) DoClearSquare(tile);
 

	
src/vehicle.cpp
Show inline comments
 
@@ -408,9 +408,9 @@ static Vehicle *EnsureNoVehicleProcZ(Veh
 

	
 
/* Ensure there is no vehicle at the ground at the given position.
 
 * @param tile Position to examine.
 
 * @return A vehicle has been found.
 
 * @return Succeeded command (ground is free) or failed command (a vehicle is found).
 
 */
 
bool EnsureNoVehicleOnGround(TileIndex tile)
 
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
 
{
 
	byte z = GetTileMaxZ(tile);
 

	
 
@@ -419,8 +419,8 @@ bool EnsureNoVehicleOnGround(TileIndex t
 
	 * Such a message does not affect MP synchronisation.
 
	 */
 
	Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true);
 
	if (v != NULL) _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type;
 
	return v == NULL;
 
	if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
 
	return CommandCost();
 
}
 

	
 
/** Procedure called for every vehicle found in tunnel/bridge in the hash map */
src/vehicle_func.h
Show inline comments
 
@@ -156,7 +156,7 @@ static inline uint32 GetCmdSendToDepot(c
 
	return GetCmdSendToDepot(v->type);
 
}
 

	
 
bool EnsureNoVehicleOnGround(TileIndex tile);
 
CommandCost EnsureNoVehicleOnGround(TileIndex tile);
 
void StopAllVehicles();
 

	
 
extern VehicleID _vehicle_id_ctr_day;
src/water_cmd.cpp
Show inline comments
 
@@ -174,7 +174,10 @@ static CommandCost RemoveShipDepot(TileI
 

	
 
	/* do not check for ship on tile when company goes bankrupt */
 
	if (!(flags & DC_BANKRUPT)) {
 
		if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -244,8 +247,11 @@ static CommandCost RemoveShiplift(TileIn
 
	if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
 

	
 
	/* make sure no vehicle is on the tile. */
 
	if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
 
		return CMD_ERROR;
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
 
@@ -341,7 +347,7 @@ CommandCost CmdBuildCanal(TileIndex tile
 
static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags)
 
{
 
	switch (GetWaterTileType(tile)) {
 
		case WATER_TILE_CLEAR:
 
		case WATER_TILE_CLEAR: {
 
			if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
			/* Make sure freeform edges are allowed or it's not an edge tile. */
 
@@ -351,7 +357,9 @@ static CommandCost ClearTile_Water(TileI
 
			}
 

	
 
			/* Make sure no vehicle is on the tile */
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
@@ -360,12 +368,15 @@ static CommandCost ClearTile_Water(TileI
 
				MarkCanalsAndRiversAroundDirty(tile);
 
			}
 
			return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
 
		}
 

	
 
		case WATER_TILE_COAST: {
 
			Slope slope = GetTileSlope(tile, NULL);
 

	
 
			/* Make sure no vehicle is on the tile */
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (flags & DC_EXEC) {
 
				DoClearSquare(tile);
src/waypoint_cmd.cpp
Show inline comments
 
@@ -179,7 +179,10 @@ static CommandCost IsValidTileForWaypoin
 

	
 
	Owner owner = GetTileOwner(tile);
 
	if (!CheckOwnership(owner)) return CMD_ERROR;
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	Slope tileh = GetTileSlope(tile, NULL);
 
	if (tileh != SLOPE_FLAT &&
 
@@ -390,7 +393,11 @@ CommandCost RemoveBuoy(TileIndex tile, D
 

	
 
	if (HasStationInUse(wp->index, INVALID_COMPANY)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
 
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
 
	if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
	if (!(flags & DC_BANKRUPT)) {
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		wp->facilities &= ~FACIL_DOCK;
0 comments (0 inline, 0 general)