changeset 8519:0e4b2a37af1f draft

(svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
author smatz <smatz@openttd.org>
date Sat, 09 Feb 2008 15:07:31 +0000
parents 60d7ff4383fb
children c777304e2098
files src/command.cpp src/command_type.h src/rail_cmd.cpp src/road_cmd.cpp src/station_cmd.cpp src/tunnelbridge_cmd.cpp src/water_cmd.cpp
diffstat 7 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -422,6 +422,7 @@
 
 		if (_docommand_recursive == 1 &&
 				!(flags & DC_QUERY_COST) &&
+				!(flags & DC_BANKRUPT) &&
 				res.GetCost() != 0 &&
 				!CheckPlayerHasMoney(res)) {
 			goto error;
@@ -446,7 +447,7 @@
 	}
 
 	/* if toplevel, subtract the money. */
-	if (--_docommand_recursive == 0) {
+	if (--_docommand_recursive == 0 && !(flags & DC_BANKRUPT)) {
 		SubtractMoneyFromPlayer(res);
 		/* XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of player */
 		if (tile != 0 && IsValidPlayer(_current_player)) {
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -271,6 +271,7 @@
 	DC_NO_RAIL_OVERLAP = 0x10, ///< don't allow overlap of rails (used in buildrail)
 	DC_AI_BUILDING     = 0x20, ///< special building rules for AI
 	DC_NO_TOWN_RATING  = 0x40, ///< town rating does not disallow you from building
+	DC_BANKRUPT        = 0x80, ///< company bankrupts, skip money check, skip vehicle on tile check in some cases
 };
 
 /**
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -455,7 +455,7 @@
 			if (!IsLevelCrossing(tile) ||
 					GetCrossingRailBits(tile) != trackbit ||
 					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
-					!EnsureNoVehicleOnGround(tile)) {
+					(!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
 				return CMD_ERROR;
 			}
 
@@ -2146,7 +2146,7 @@
 	if (new_player != PLAYER_SPECTATOR) {
 		SetTileOwner(tile, new_player);
 	} else {
-		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+		DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 	}
 }
 
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1404,7 +1404,7 @@
 	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
 		if (GetTileOwner(tile) == old_player) {
 			if (new_player == PLAYER_SPECTATOR) {
-				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+				DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 			} else {
 				SetTileOwner(tile, new_player);
 			}
@@ -1423,7 +1423,7 @@
 	if (IsLevelCrossing(tile)) {
 		if (GetTileOwner(tile) == old_player) {
 			if (new_player == PLAYER_SPECTATOR) {
-				MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY));
+				DoCommand(tile, 0, AxisToTrack(OtherAxis(GetCrossingRoadAxis(tile))), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
 			} else {
 				SetTileOwner(tile, new_player);
 			}
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2893,9 +2893,9 @@
 	} else {
 		if (IsDriveThroughStopTile(tile) && GetStopBuiltOnTownRoad(tile)) {
 			/* For a drive-through stop on a town-owned road remove the stop and replace the road */
-			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC, CMD_REMOVE_ROAD_STOP);
+			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
 		} else {
-			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+			DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 		}
 	}
 }
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -1181,7 +1181,7 @@
 	if (new_player != PLAYER_SPECTATOR) {
 		SetTileOwner(tile, new_player);
 	} else {
-		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR))) {
 			/* When clearing the bridge/tunnel failed there are still vehicles on/in
 			 * the bridge/tunnel. As all *our* vehicles are already removed, they
 			 * must be of another owner. Therefor this must be a road bridge/tunnel.
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -1140,7 +1140,7 @@
 	if (new_player != PLAYER_SPECTATOR) {
 		SetTileOwner(tile, new_player);
 	} else if (IsShipDepot(tile)) {
-		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+		DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 	} else {
 		SetTileOwner(tile, OWNER_NONE);
 	}