Changeset - r18557:96a9c31d64d1
[Not reviewed]
master
0 5 0
michi_cc - 12 years ago 2011-12-03 23:40:18
michi_cc@openttd.org
(svn r23412) -Add: Company infrastructure counts for road.
5 files changed with 195 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -451,13 +451,21 @@ CommandCost CmdBuildSingleRail(TileIndex
 
				RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
 
				RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
 
				switch (roadtypes) {
 
					default: break;
 
					case ROADTYPES_TRAM:
 
						/* Tram crossings must always have road. */
 
						if (flags & DC_EXEC) SetRoadOwner(tile, ROADTYPE_ROAD, _current_company);
 
						if (flags & DC_EXEC) {
 
							SetRoadOwner(tile, ROADTYPE_ROAD, _current_company);
 
							Company *c = Company::GetIfValid(_current_company);
 
							if (c != NULL) {
 
								/* A full diagonal tile has two road bits. */
 
								c->infrastructure.road[ROADTYPE_ROAD] += 2;
 
								DirtyCompanyInfrastructureWindows(c->index);
 
							}
 
						}
 
						roadtypes |= ROADTYPES_ROAD;
 
						break;
 

	
 
					case ROADTYPES_ALL:
 
						if (road != tram) return CMD_ERROR;
 
						break;
src/road_cmd.cpp
Show inline comments
 
@@ -32,12 +32,13 @@
 
#include "town.h"
 
#include "company_base.h"
 
#include "core/random_func.hpp"
 
#include "newgrf_railtype.h"
 
#include "date_func.h"
 
#include "genworld.h"
 
#include "company_gui.h"
 

	
 
#include "table/strings.h"
 

	
 
/**
 
 * Verify whether a road vehicle is available.
 
 * @return \c true if at least one road vehicle is available, \c false if not
 
@@ -215,14 +216,22 @@ static CommandCost RemoveRoad(TileIndex 
 
		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 

	
 
		CommandCost cost(EXPENSES_CONSTRUCTION);
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
 
			/* Pay for *every* tile of the bridge or tunnel */
 
			cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price[PR_CLEAR_ROAD]);
 
			uint len = GetTunnelBridgeLength(other_end, tile) + 2;
 
			cost.AddCost(len * _price[PR_CLEAR_ROAD]);
 
			if (flags & DC_EXEC) {
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					/* A full diagonal road tile has two road bits. */
 
					c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 

	
 
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
 
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
 

	
 
				/* If the owner of the bridge sells all its road, also move the ownership
 
				 * to the owner of the other roadtype. */
 
				RoadType other_rt = (rt == ROADTYPE_ROAD) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
 
@@ -242,12 +251,18 @@ static CommandCost RemoveRoad(TileIndex 
 
				}
 
			}
 
		} else {
 
			assert(IsDriveThroughStopTile(tile));
 
			cost.AddCost(_price[PR_CLEAR_ROAD] * 2);
 
			if (flags & DC_EXEC) {
 
				Company *c = Company::GetIfValid(GetTileOwner(tile));
 
				if (c != NULL) {
 
					/* A full diagonal road tile has two road bits. */
 
					c->infrastructure.road[rt] -= 2;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
 
				MarkTileDirtyByTile(tile);
 
			}
 
		}
 
		return cost;
 
	}
 
@@ -296,12 +311,19 @@ static CommandCost RemoveRoad(TileIndex 
 
					FOR_ALL_EFFECTVEHICLES(v) {
 
						if (TileVirtXY(v->x_pos, v->y_pos) == tile) {
 
							delete v;
 
						}
 
					}
 
				}
 

	
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					c->infrastructure.road[rt] -= CountBits(pieces);
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 

	
 
				if (present == ROAD_NONE) {
 
					RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
 
					if (rts == ROADTYPES_NONE) {
 
						/* Includes MarkTileDirtyByTile() */
 
						DoClearSquare(tile);
 
					} else {
 
@@ -338,12 +360,19 @@ static CommandCost RemoveRoad(TileIndex 
 

	
 
			/* Don't allow road to be removed from the crossing when there is tram;
 
			 * we can't draw the crossing without roadbits ;) */
 
			if (rt == ROADTYPE_ROAD && HasTileRoadType(tile, ROADTYPE_TRAM) && (flags & DC_EXEC || crossing_check)) return CMD_ERROR;
 

	
 
			if (flags & DC_EXEC) {
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					/* A full diagonal road tile has two road bits. */
 
					c->infrastructure.road[rt] -= 2;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 

	
 
				Track railtrack = GetCrossingRailTrack(tile);
 
				RoadTypes rts = GetRoadTypes(tile) & ComplementRoadTypes(RoadTypeToRoadTypes(rt));
 
				if (rts == ROADTYPES_NONE) {
 
					TrackBits tracks = GetCrossingRailBits(tile);
 
					bool reserved = HasCrossingReservation(tile);
 
					MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile));
 
@@ -570,12 +599,19 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			if (ret.Failed()) return ret;
 

	
 
			if (flags & DC_EXEC) {
 
				Track railtrack = AxisToTrack(OtherAxis(roaddir));
 
				YapfNotifyTrackLayoutChange(tile, railtrack);
 
				/* Update company infrastructure counts. A level crossing has two road bits. */
 
				Company *c = Company::GetIfValid(_current_company);
 
				if (c != NULL) {
 
					c->infrastructure.road[rt] += 2;
 
					if (rt != ROADTYPE_ROAD) c->infrastructure.road[ROADTYPE_ROAD] += 2;
 
					DirtyCompanyInfrastructureWindows(_current_company);
 
				}
 
				/* Always add road to the roadtypes (can't draw without it) */
 
				bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
 
				MakeRoadCrossing(tile, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
 
				SetCrossingReservation(tile, reserved);
 
				UpdateLevelCrossing(tile, false);
 
				MarkTileDirtyByTile(tile);
 
@@ -705,12 +741,20 @@ do_clear:;
 

	
 
			default:
 
				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_company, _current_company);
 
				break;
 
		}
 

	
 
		/* Update company infrastructure count. */
 
		Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
		if (c != NULL) {
 
			if (IsTileType(tile, MP_TUNNELBRIDGE)) num_pieces *= TUNNELBRIDGE_TRACKBIT_FACTOR;
 
			c->infrastructure.road[rt] += num_pieces;
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 

	
 
		if (rt != ROADTYPE_TRAM && IsNormalRoadTile(tile)) {
 
			existing |= pieces;
 
			SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ?
 
					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
 
		}
 

	
 
@@ -925,12 +969,16 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *dep = new Depot(tile);
 
		dep->build_date = _date;
 

	
 
		/* A road depot has two road bits. */
 
		Company::Get(_current_company)->infrastructure.road[rt] += 2;
 
		DirtyCompanyInfrastructureWindows(_current_company);
 

	
 
		MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
 
		MarkTileDirtyByTile(tile);
 
		MakeDefaultName(dep);
 
	}
 
	cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
 
	return cost;
 
@@ -944,12 +992,19 @@ static CommandCost RemoveRoadDepot(TileI
 
	}
 

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

	
 
	if (flags & DC_EXEC) {
 
		Company *c = Company::GetIfValid(GetTileOwner(tile));
 
		if (c != NULL) {
 
			/* A road depot has two road bits. */
 
			c->infrastructure.road[FIND_FIRST_BIT(GetRoadTypes(tile))] -= 2;
 
			DirtyCompanyInfrastructureWindows(c->index);
 
		}
 

	
 
		delete Depot::GetByTile(tile);
 
		DoClearSquare(tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
 
}
 
@@ -1650,21 +1705,33 @@ static void ChangeTileOwner_Road(TileInd
 
{
 
	if (IsRoadDepot(tile)) {
 
		if (GetTileOwner(tile) == old_owner) {
 
			if (new_owner == INVALID_OWNER) {
 
				DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
			} else {
 
				/* A road depot has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
 
				RoadType rt = (RoadType)FIND_FIRST_BIT(GetRoadTypes(tile));
 
				Company::Get(old_owner)->infrastructure.road[rt] -= 2;
 
				Company::Get(new_owner)->infrastructure.road[rt] += 2;
 

	
 
				SetTileOwner(tile, new_owner);
 
			}
 
		}
 
		return;
 
	}
 

	
 
	for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
		/* Update all roadtypes, no matter if they are present */
 
		if (GetRoadOwner(tile, rt) == old_owner) {
 
			if (HasTileRoadType(tile, rt)) {
 
				/* A level crossing has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
 
				uint num_bits = IsLevelCrossing(tile) ? 2 : CountBits(GetRoadBits(tile, rt));
 
				Company::Get(old_owner)->infrastructure.road[rt] -= num_bits;
 
				if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_bits;
 
			}
 

	
 
			SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
 
		}
 
	}
 

	
 
	if (IsLevelCrossing(tile)) {
 
		if (GetTileOwner(tile) == old_owner) {
src/saveload/company_sl.cpp
Show inline comments
 
@@ -112,28 +112,48 @@ void AfterLoadCompanyStats()
 
					c->infrastructure.rail[GetRailType(tile)] += pieces;
 

	
 
					if (HasSignals(tile)) c->infrastructure.signal += CountBits(GetPresentSignals(tile));
 
				}
 
				break;
 

	
 
			case MP_ROAD:
 
			case MP_ROAD: {
 
				if (IsLevelCrossing(tile)) {
 
					c = Company::GetIfValid(GetTileOwner(tile));
 
					if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
 
				}
 

	
 
				/* Iterate all present road types as each can have a different owner. */
 
				RoadType rt;
 
				FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
					c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rt));
 
					/* A level crossings and depots have two road bits. */
 
					if (c != NULL) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rt)) : 2;
 
				}
 
				break;
 
			}
 

	
 
			case MP_STATION:
 
				c = Company::GetIfValid(GetTileOwner(tile));
 

	
 
				switch (GetStationType(tile)) {
 
					case STATION_RAIL:
 
					case STATION_WAYPOINT:
 
						if (c != NULL && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
 
						break;
 

	
 
					case STATION_BUS:
 
					case STATION_TRUCK: {
 
						/* Iterate all present road types as each can have a different owner. */
 
						RoadType rt;
 
						FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
							c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
							if (c != NULL) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
 
						}
 
						break;
 
					}
 

	
 
					default:
 
						break;
 
				}
 
				break;
 

	
 
			case MP_TUNNELBRIDGE: {
 
@@ -147,12 +167,22 @@ void AfterLoadCompanyStats()
 
					switch (GetTunnelBridgeTransportType(tile)) {
 
						case TRANSPORT_RAIL:
 
							c = Company::GetIfValid(GetTileOwner(tile));
 
							if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += len;
 
							break;
 

	
 
						case TRANSPORT_ROAD: {
 
							/* Iterate all present road types as each can have a different owner. */
 
							RoadType rt;
 
							FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
								c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
								if (c != NULL) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
 
							}
 
							break;
 
						}
 

	
 
						default:
 
							break;
 
					}
 
				}
 
				break;
 
			}
src/station_cmd.cpp
Show inline comments
 
@@ -1788,15 +1788,29 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
			st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, cur_tile);
 

	
 
			st->rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
 

	
 
			RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
 
			if (is_drive_through) {
 
				/* Update company infrastructure counts. If the current tile is a normal
 
				 * road tile, count only the new road bits needed to get a full diagonal road. */
 
				RoadType rt;
 
				FOR_EACH_SET_ROADTYPE(rt, cur_rts | rts) {
 
					Company *c = Company::GetIfValid(IsNormalRoadTile(cur_tile) && HasBit(cur_rts, rt) ? GetRoadOwner(cur_tile, rt) : _current_company);
 
					if (c != NULL) {
 
						c->infrastructure.road[rt] += 2 - (IsNormalRoadTile(cur_tile) ? CountBits(GetRoadBits(cur_tile, rt)) : 0);
 
						DirtyCompanyInfrastructureWindows(c->index);
 
					}
 
				}
 

	
 
				MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts | cur_rts, DiagDirToAxis(ddir));
 
				road_stop->MakeDriveThrough();
 
			} else {
 
				/* Non-drive-through stop never overbuild and always count as two road bits. */
 
				Company::Get(st->owner)->infrastructure.road[FIND_FIRST_BIT(rts)] += 2;
 
				DirtyCompanyInfrastructureWindows(st->owner);
 
				MakeRoadStop(cur_tile, st->owner, st->index, rs_type, rts, ddir);
 
			}
 

	
 
			MarkTileDirtyByTile(cur_tile);
 
		}
 
	}
 
@@ -1880,12 +1894,22 @@ static CommandCost RemoveRoadStop(TileIn
 
			/* tell the predecessor in the list to skip this stop */
 
			RoadStop *pred = *primary_stop;
 
			while (pred->next != cur_stop) pred = pred->next;
 
			pred->next = cur_stop->next;
 
		}
 

	
 
		/* Update company infrastructure counts. */
 
		RoadType rt;
 
		FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
			Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
			if (c != NULL) {
 
				c->infrastructure.road[rt] -= 2;
 
				DirtyCompanyInfrastructureWindows(c->index);
 
			}
 
		}
 

	
 
		if (IsDriveThroughStopTile(tile)) {
 
			/* Clears the tile for us */
 
			cur_stop->ClearDriveThrough();
 
		} else {
 
			DoClearSquare(tile);
 
		}
 
@@ -1964,12 +1988,22 @@ CommandCost CmdRemoveRoadStop(TileIndex 
 

	
 
		quantity++;
 
		/* If the stop was a drive-through stop replace the road */
 
		if ((flags & DC_EXEC) && is_drive_through) {
 
			MakeRoadNormal(cur_tile, road_bits, rts, ClosestTownFromTile(cur_tile, UINT_MAX)->index,
 
					road_owner, tram_owner);
 

	
 
			/* Update company infrastructure counts. */
 
			RoadType rt;
 
			FOR_EACH_SET_ROADTYPE(rt, rts) {
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					c->infrastructure.road[rt] += CountBits(road_bits);
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 
			}
 
		}
 
	}
 

	
 
	if (quantity == 0) return_cmd_error(STR_ERROR_THERE_IS_NO_STATION);
 

	
 
	return cost;
 
@@ -3501,12 +3535,17 @@ void DeleteOilRig(TileIndex tile)
 
static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	if (IsDriveThroughStopTile(tile)) {
 
		for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
			/* Update all roadtypes, no matter if they are present */
 
			if (GetRoadOwner(tile, rt) == old_owner) {
 
				if (HasTileRoadType(tile, rt)) {
 
					/* A drive-through road-stop has always two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
 
					Company::Get(old_owner)->infrastructure.road[rt] -= 2;
 
					if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += 2;
 
				}
 
				SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
 
			}
 
		}
 
	}
 

	
 
	if (!IsTileOwner(tile, old_owner)) return;
 
@@ -3520,12 +3559,19 @@ static void ChangeTileOwner_Station(Tile
 
		Company *new_company = Company::Get(new_owner);
 

	
 
		if ((IsRailWaypoint(tile) || IsRailStation(tile)) && !IsStationTileBlocked(tile)) {
 
			old_company->infrastructure.rail[GetRailType(tile)]--;
 
			new_company->infrastructure.rail[GetRailType(tile)]++;
 
		}
 
		if (IsRoadStop(tile) && !IsDriveThroughStopTile(tile)) {
 
			RoadType rt;
 
			FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
				old_company->infrastructure.road[rt] -= 2;
 
				new_company->infrastructure.road[rt] += 2;
 
			}
 
		}
 

	
 
		/* for buoys, owner of tile is owner of water, st->owner == OWNER_NONE */
 
		SetTileOwner(tile, new_owner);
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
 
	} else {
 
		if (IsDriveThroughStopTile(tile)) {
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -440,12 +440,20 @@ CommandCost CmdBuildBridge(TileIndex end
 
				MakeRailBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), railtype);
 
				SetTunnelBridgeReservation(tile_start, pbs_reservation);
 
				SetTunnelBridgeReservation(tile_end,   pbs_reservation);
 
				break;
 

	
 
			case TRANSPORT_ROAD:
 
				if (c != NULL) {
 
					/* Add all new road types to the company infrastructure counter. */
 
					RoadType new_rt;
 
					FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ (IsBridgeTile(tile_start) ? GetRoadTypes(tile_start) : ROADTYPES_NONE)) {
 
						/* A full diagonal road tile has two road bits. */
 
						Company::Get(owner)->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
					}
 
				}
 
				MakeRoadBridgeRamp(tile_start, owner, bridge_type, dir,                 roadtypes);
 
				MakeRoadBridgeRamp(tile_end,   owner, bridge_type, ReverseDiagDir(dir), roadtypes);
 
				break;
 

	
 
			case TRANSPORT_WATER:
 
				MakeAqueductBridgeRamp(tile_start, owner, dir);
 
@@ -637,12 +645,18 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
			if (!IsTunnelTile(start_tile) && c != NULL) c->infrastructure.rail[railtype] += num_pieces;
 
			MakeRailTunnel(start_tile, _current_company, direction,                 railtype);
 
			MakeRailTunnel(end_tile,   _current_company, ReverseDiagDir(direction), railtype);
 
			AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_company);
 
			YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
 
		} else {
 
			if (c != NULL) {
 
				RoadType rt;
 
				FOR_EACH_SET_ROADTYPE(rt, rts ^ (IsTunnelTile(start_tile) ? GetRoadTypes(start_tile) : ROADTYPES_NONE)) {
 
					c->infrastructure.road[rt] += num_pieces * 2; // A full diagonal road has two road bits.
 
				}
 
			}
 
			MakeRoadTunnel(start_tile, _current_company, direction,                 rts);
 
			MakeRoadTunnel(end_tile,   _current_company, ReverseDiagDir(direction), rts);
 
		}
 
		DirtyCompanyInfrastructureWindows(_current_company);
 
	}
 

	
 
@@ -758,12 +772,22 @@ static CommandCost DoClearTunnel(TileInd
 

	
 
			YapfNotifyTrackLayoutChange(tile,    track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 

	
 
			if (v != NULL) TryPathReserve(v);
 
		} else {
 
			RoadType rt;
 
			FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
				/* A full diagonal road tile has two road bits. */
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 
			}
 

	
 
			DoClearSquare(tile);
 
			DoClearSquare(endtile);
 
		}
 
	}
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_TUNNEL] * len);
 
}
 
@@ -819,12 +843,22 @@ static CommandCost DoClearBridge(TileInd
 
			if (v != NULL) FreeTrainTrackReservation(v);
 
		}
 

	
 
		/* Update company infrastructure counts. */
 
		if (rail) {
 
			if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
		} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
 
			RoadType rt;
 
			FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
 
				Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
 
				if (c != NULL) {
 
					/* A full diagonal road tile has two road bits. */
 
					c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
					DirtyCompanyInfrastructureWindows(c->index);
 
				}
 
			}
 
		}
 
		DirtyCompanyInfrastructureWindows(owner);
 

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		for (TileIndex c = tile + delta; c != endtile; c += delta) {
 
@@ -1517,12 +1551,19 @@ static void ChangeTileOwner_TunnelBridge
 
	 * don't want to update the infrastructure counts twice. */
 
	uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0;
 

	
 
	for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
		/* Update all roadtypes, no matter if they are present */
 
		if (GetRoadOwner(tile, rt) == old_owner) {
 
			if (HasBit(GetRoadTypes(tile), rt)) {
 
				/* Update company infrastructure counts. A full diagonal road tile has two road bits.
 
				 * No need to dirty windows here, we'll redraw the whole screen anyway. */
 
				Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2;
 
				if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2;
 
			}
 

	
 
			SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
 
		}
 
	}
 

	
 
	if (!IsTileOwner(tile, old_owner)) return;
 

	
0 comments (0 inline, 0 general)