Changeset - r24602:d0d308decaa4
[Not reviewed]
master
0 2 0
Patric Stout - 3 years ago 2021-01-06 20:12:32
truebrain@openttd.org
Fix #7656: destroying a tunnel/bridge now first removes the tracks for cost calculation

This means that for rail tunnel/bridges, the rail is first sold,
and the tunnel/bridge is destroyed after. This means destroying
tunnels/ bridges now often makes you money, instead of costing.

Similar, with road/tram tracks. Destroying a road+tram
tunnel/bridge now costs the same amount of money as first
removing the tram tracks and than destroying the road
tunnel/bridge. Especially as tram tracks generate money when
removing, this is a noticeable difference.
2 files changed with 41 insertions and 6 deletions:
0 comments (0 inline, 0 general)
regression/regression/result.txt
Show inline comments
 
@@ -7311,26 +7311,26 @@ ERROR: IsEnd() is invalid as Begin() is 
 
--AIMarine--
 
  IsWaterDepotTile():   false
 
  IsDockTile():         false
 
  IsBuoyTile():         false
 
  IsLockTile():         false
 
  IsCanalTile():        false
 
  GetBankBalance():     1999979664
 
  GetBankBalance():     1999979304
 
  BuildWaterDepot():    true
 
  BuildDock():          true
 
  BuildBuoy():          true
 
  BuildLock():          true
 
  HasTransportType():   false
 
  BuildCanal():         true
 
  HasTransportType():   true
 
  IsWaterDepotTile():   true
 
  IsDockTile():         true
 
  IsBuoyTile():         true
 
  IsLockTile():         true
 
  IsCanalTile():        true
 
  GetBankBalance():     1999965040
 
  GetBankBalance():     1999964680
 

	
 
--AIWaypointList(BUOY)--
 
  Count():             1
 
  Location ListDump:
 
    28481
 
  HasWaypointType:
 
@@ -7343,13 +7343,13 @@ ERROR: IsEnd() is invalid as Begin() is 
 
  RemoveCanal():        true
 
  IsWaterDepotTile():   false
 
  IsDockTile():         false
 
  IsBuoyTile():         false
 
  IsLockTile():         false
 
  IsCanalTile():        false
 
  GetBankBalance():     1999959645
 
  GetBankBalance():     1999959285
 
  BuildWaterDepot():    true
 
  BuildDock():          true
 

	
 
--Prices--
 
 -Rail-
 
  0,BT_TRACK:    75
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -211,12 +211,44 @@ CommandCost CheckBridgeAvailability(Brid
 
	if (b->min_length > bridge_len) return CMD_ERROR;
 
	if (bridge_len <= max) return CommandCost();
 
	return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
 
}
 

	
 
/**
 
 * Calculate the base cost of clearing a tunnel/bridge per tile.
 
 * @param tile Start tile of the tunnel/bridge.
 
 * @return How much clearing this tunnel/bridge costs per tile.
 
 */
 
static Money TunnelBridgeClearCost(TileIndex tile, Price base_price)
 
{
 
	Money base_cost = _price[base_price];
 

	
 
	/* Add the cost of the transport that is on the tunnel/bridge. */
 
	switch (GetTunnelBridgeTransportType(tile)) {
 
		case TRANSPORT_ROAD: {
 
			RoadType road_rt = GetRoadTypeRoad(tile);
 
			RoadType tram_rt = GetRoadTypeTram(tile);
 

	
 
			if (road_rt != INVALID_ROADTYPE) {
 
				base_cost += 2 * RoadClearCost(road_rt);
 
			}
 
			if (tram_rt != INVALID_ROADTYPE) {
 
				base_cost += 2 * RoadClearCost(tram_rt);
 
			}
 
		} break;
 

	
 
		case TRANSPORT_RAIL: base_cost += RailClearCost(GetRailType(tile)); break;
 
		/* Aquaducts have their own clear price. */
 
		case TRANSPORT_WATER: base_cost = _price[PR_CLEAR_AQUEDUCT]; break;
 
		default: break;
 
	}
 

	
 
	return base_cost;
 
}
 

	
 
/**
 
 * Build a Bridge
 
 * @param end_tile end tile
 
 * @param flags type of operation
 
 * @param p1 packed start tile coords (~ dx)
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit  0- 7) - bridge type (hi bh)
 
@@ -370,13 +402,14 @@ CommandCost CmdBuildBridge(TileIndex end
 

	
 
		/* Do not allow replacing another company's bridges. */
 
		if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN) && !IsTileOwner(tile_start, OWNER_NONE)) {
 
			return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
 
		}
 

	
 
		cost.AddCost(bridge_len * _price[PR_CLEAR_BRIDGE]); // The cost of clearing the current bridge.
 
		/* The cost of clearing the current bridge. */
 
		cost.AddCost(bridge_len * TunnelBridgeClearCost(tile_start, PR_CLEAR_BRIDGE));
 
		owner = GetTileOwner(tile_start);
 

	
 
		/* If bridge belonged to bankrupt company, it has a new owner now */
 
		is_new_owner = (owner == OWNER_NONE);
 
		if (is_new_owner) owner = company;
 
	} else {
 
@@ -846,12 +879,13 @@ static CommandCost DoClearTunnel(TileInd
 
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
	 * you have a "Poor" (0) town rating */
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
 
	}
 

	
 
	Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_TUNNEL);
 
	uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
 

	
 
	if (flags & DC_EXEC) {
 
		if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
			/* We first need to request values before calling DoClearSquare */
 
			DiagDirection dir = GetTunnelBridgeDirection(tile);
 
@@ -886,13 +920,14 @@ static CommandCost DoClearTunnel(TileInd
 
			UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
 

	
 
			DoClearSquare(tile);
 
			DoClearSquare(endtile);
 
		}
 
	}
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_TUNNEL] * len);
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, len * base_cost);
 
}
 

	
 

	
 
/**
 
 * Remove a bridge from the game, update town rating, etc.
 
 * @param tile Tile containing one of the endpoints of the bridge.
 
@@ -925,13 +960,13 @@ static CommandCost DoClearBridge(TileInd
 
	/* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
	 * you have a "Poor" (0) town rating */
 
	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
 
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags);
 
	}
 

	
 
	Money base_cost = (GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) ? _price[PR_CLEAR_BRIDGE] : _price[PR_CLEAR_AQUEDUCT];
 
	Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_BRIDGE);
 
	uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles.
 

	
 
	if (flags & DC_EXEC) {
 
		/* read this value before actual removal of bridge */
 
		bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
 
		Owner owner = GetTileOwner(tile);
0 comments (0 inline, 0 general)