(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642

This commit is contained in:
smatz 2007-12-16 19:30:42 +00:00
parent 0730b9afc1
commit 145517fb8e
15 changed files with 84 additions and 190 deletions

View File

@ -45,10 +45,7 @@ static bool IsRoad(TileIndex tile)
return return
// MP_ROAD, but not a road depot? // MP_ROAD, but not a road depot?
(IsTileType(tile, MP_ROAD) && !IsTileDepotType(tile, TRANSPORT_ROAD)) || (IsTileType(tile, MP_ROAD) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
(IsTileType(tile, MP_TUNNELBRIDGE) && ( (IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD);
(IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) ||
(IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD)
));
} }
@ -236,11 +233,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// If the next step is a bridge, we have to enter it the right way // If the next step is a bridge, we have to enter it the right way
if (!PathFinderInfo->rail_or_road && IsRoad(atile)) { if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
if (IsTileType(atile, MP_TUNNELBRIDGE)) { if (IsTileType(atile, MP_TUNNELBRIDGE)) {
if (IsTunnel(atile)) { if (GetTunnelBridgeDirection(atile) != i) continue;
if (GetTunnelBridgeDirection(atile) != i) continue;
} else {
if (GetTunnelBridgeDirection(atile) != i) continue;
}
} }
} }

View File

@ -93,17 +93,11 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (IsTunnel(t)) { if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; if (override != NULL && (IsTunnel(t) || DistanceMax(t, GetOtherBridgeEnd(t)) > 1)) {
if (override != NULL) *override = 1 << GetTunnelBridgeDirection(t); *override = 1 << GetTunnelBridgeDirection(t);
return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
} else {
if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
*override = 1 << GetTunnelBridgeDirection(t);
}
return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
} }
return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
case MP_ROAD: case MP_ROAD:
if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE; if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;

View File

@ -481,8 +481,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if ((IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) || if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
(IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL)) {
return IsTileOwner(tile, owner); return IsTileOwner(tile, owner);
} }
break; break;
@ -534,14 +533,11 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
DEBUG(npf, 4, "Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile); DEBUG(npf, 4, "Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
/* Find dest tile */ /* Find dest tile */
if (IsTunnelTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) { if (IsTileType(src_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(src_tile) == src_exitdir) {
/* This is a tunnel. We know this tunnel is our type, /* This is a tunnel/bridge. We know this tunnel/bridge is our type,
* otherwise we wouldn't have got here. It is also facing us, * otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */ * so we should skip it's body */
dst_tile = GetOtherTunnelEnd(src_tile); dst_tile = IsTunnel(src_tile) ? GetOtherTunnelEnd(src_tile) : GetOtherBridgeEnd(src_tile);
override_dst_check = true;
} else if (IsBridgeTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) {
dst_tile = GetOtherBridgeEnd(src_tile);
override_dst_check = true; override_dst_check = true;
} else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) { } else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) {
/* This is a road station (non drive-through) or a train or road depot. We can enter and exit /* This is a road station (non drive-through) or a train or road depot. We can enter and exit
@ -590,14 +586,9 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note /* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note
* that I can enter the tunnel from a tile below the tunnel entrance. This * that I can enter the tunnel from a tile below the tunnel entrance. This
* solves the problem of vehicles wanting to drive off a tunnel entrance */ * solves the problem of vehicles wanting to drive off a tunnel entrance */
if (!override_dst_check) { if (!override_dst_check && IsTileType(dst_tile, MP_TUNNELBRIDGE) &&
if (IsTileType(dst_tile, MP_TUNNELBRIDGE)) { GetTunnelBridgeDirection(dst_tile) != src_exitdir) {
if (IsTunnel(dst_tile)) { return;
if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return;
} else {
if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return;
}
}
} }
/* check correct rail type (mono, maglev, etc) */ /* check correct rail type (mono, maglev, etc) */

View File

@ -1759,14 +1759,8 @@ bool AfterLoadGame()
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (IsTunnel(t)) { if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) { SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
}
} else {
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
}
} }
break; break;

View File

@ -260,16 +260,9 @@ static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, Til
/* Check if the new tile is a tunnel or bridge head and that the direction /* Check if the new tile is a tunnel or bridge head and that the direction
* and transport type match */ * and transport type match */
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(tile)) { if (GetTunnelBridgeDirection(tile) != direction ||
if (GetTunnelBridgeDirection(tile) != direction || GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
GetTunnelBridgeTransportType(tile) != tpf->tracktype) { return;
return;
}
} else if (IsBridge(tile)) {
if (GetTunnelBridgeDirection(tile) != direction ||
GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
return;
}
} }
} }

View File

@ -132,11 +132,7 @@ RailType GetTileRailType(TileIndex tile)
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) { if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
} else {
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
}
break; break;
default: default:

View File

@ -926,17 +926,15 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
return true; return true;
case MP_TUNNELBRIDGE: { case MP_TUNNELBRIDGE: {
TileIndex orig_tile = tile; TileIndex orig_tile = tile; // backup old value
/* Skip to end of tunnel or bridge */
if (IsBridge(tile)) { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false; if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
tile = GetOtherBridgeEnd(tile); /* Skip to end of tunnel or bridge
} else { * note that tile is a parameter by reference, so it must be updated */
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false; tile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
tile = GetOtherTunnelEnd(tile);
}
signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2; signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
return true; return true;
} }

View File

@ -1522,12 +1522,8 @@ void SetDefaultRailGui()
RailType count[RAILTYPE_END]; RailType count[RAILTYPE_END];
memset(count, 0, sizeof(count)); memset(count, 0, sizeof(count));
for (TileIndex t = 0; t < MapSize(); t++) { for (TileIndex t = 0; t < MapSize(); t++) {
if (IsTileType(t, MP_RAILWAY) || if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || IsRailwayStationTile(t) ||
IsLevelCrossingTile(t) || (IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) {
IsRailwayStationTile(t) ||
(IsTunnelTile(t) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) ||
(IsBridgeTile(t) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)
) {
count[GetRailType(t)]++; count[GetRailType(t)]++;
} }
} }

View File

@ -133,15 +133,8 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
{ {
TileIndex endtile; if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
if (IsTunnel(tile)) { TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherTunnelEnd(tile);
} else {
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherBridgeEnd(tile);
}
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR; if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
} break; } break;
@ -514,15 +507,11 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
{ {
TileIndex endtile; if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
if (IsTunnel(tile)) {
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherTunnelEnd(tile);
} else {
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherBridgeEnd(tile);
}
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT); if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */ /* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR; if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
} break; } break;

View File

@ -34,13 +34,8 @@ RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt)
return DiagDirToRoadBits(GetRoadStopDir(tile)); return DiagDirToRoadBits(GetRoadStopDir(tile));
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE; return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
} else {
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
}
default: return ROAD_NONE; default: return ROAD_NONE;
} }

View File

@ -551,8 +551,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (IsTileType(v->tile, MP_ROAD) && GetRoadTileType(v->tile) == ROAD_TILE_NORMAL && GetDisallowedRoadDirections(v->tile) != DRD_NONE) return CMD_ERROR; if (IsTileType(v->tile, MP_ROAD) && GetRoadTileType(v->tile) == ROAD_TILE_NORMAL && GetDisallowedRoadDirections(v->tile) != DRD_NONE) return CMD_ERROR;
if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR; if (IsTileType(v->tile, MP_TUNNELBRIDGE) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180; if (flags & DC_EXEC) v->u.road.reverse_ctr = 180;
@ -1407,9 +1406,7 @@ static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev,
if (prev_state == RVSB_WORMHOLE || prev_state == RVSB_IN_DEPOT) { if (prev_state == RVSB_WORMHOLE || prev_state == RVSB_IN_DEPOT) {
DiagDirection diag_dir = INVALID_DIAGDIR; DiagDirection diag_dir = INVALID_DIAGDIR;
if (IsTunnelTile(tile)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
diag_dir = GetTunnelBridgeDirection(tile);
} else if (IsBridgeTile(tile)) {
diag_dir = GetTunnelBridgeDirection(tile); diag_dir = GetTunnelBridgeDirection(tile);
} else if (IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT) { } else if (IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
diag_dir = ReverseDiagDir(GetRoadDepotDirection(tile)); diag_dir = ReverseDiagDir(GetRoadDepotDirection(tile));

View File

@ -339,13 +339,8 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
TileType t = GetTileType(tile); TileType t = GetTileType(tile);
if (t == MP_TUNNELBRIDGE) { if (t == MP_TUNNELBRIDGE) {
TransportType tt; TransportType tt = GetTunnelBridgeTransportType(tile);
if (IsTunnel(tile)) {
tt = GetTunnelBridgeTransportType(tile);
} else {
tt = GetTunnelBridgeTransportType(tile);
}
switch (tt) { switch (tt) {
case TRANSPORT_RAIL: t = MP_RAILWAY; break; case TRANSPORT_RAIL: t = MP_RAILWAY; break;
case TRANSPORT_ROAD: t = MP_ROAD; break; case TRANSPORT_ROAD: t = MP_ROAD; break;

View File

@ -1064,10 +1064,8 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
/* Reached a tunnel/bridge? Then continue at the other side of it. */ /* Reached a tunnel/bridge? Then continue at the other side of it. */
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) { if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
*tile_ptr = GetOtherTunnelEnd(tile); *tile_ptr = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
} else if (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
*tile_ptr = GetOtherBridgeEnd(tile);
} }
return; return;
} }

View File

@ -3059,7 +3059,7 @@ static void DeleteLastWagon(Vehicle *v)
if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy
DiagDirection dir = IsTunnel(v->tile) ? GetTunnelBridgeDirection(v->tile) : GetTunnelBridgeDirection(v->tile); DiagDirection dir = GetTunnelBridgeDirection(v->tile);
/* v->direction is "random", so it cannot be used to determine the direction of the track */ /* v->direction is "random", so it cannot be used to determine the direction of the track */
UpdateSignalsOnSegment(v->tile, dir); UpdateSignalsOnSegment(v->tile, dir);
@ -3176,7 +3176,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
TileIndex tile = v->tile; TileIndex tile = v->tile;
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
DiagDirection dir = IsTunnel(tile) ? GetTunnelBridgeDirection(tile) : GetTunnelBridgeDirection(tile); DiagDirection dir = GetTunnelBridgeDirection(tile);
if (DiagDirToDir(dir) == v->direction) return true; if (DiagDirToDir(dir) == v->direction) return true;
} }

View File

@ -702,63 +702,39 @@ static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
*/ */
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec) CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
{ {
if (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) { if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return CMD_ERROR;
TileIndex endtile = GetOtherTunnelEnd(tile);
/* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel */ TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
if (!IsCompatibleRail(GetRailType(tile), totype) &&
GetVehicleTunnelBridge(tile, endtile) != NULL) {
return CMD_ERROR;
}
if (exec) { /* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
SetRailType(tile, totype); if (!IsCompatibleRail(GetRailType(tile), totype) &&
SetRailType(endtile, totype); GetVehicleTunnelBridge(tile, endtile) != NULL) {
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
}
return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
} else if (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
TileIndex endtile = GetOtherBridgeEnd(tile);
if (!IsCompatibleRail(GetRailType(tile), totype) &&
GetVehicleTunnelBridge(tile, endtile) != NULL) {
return CMD_ERROR;
}
if (exec) {
SetRailType(tile, totype);
SetRailType(endtile, totype);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
for (tile += delta; tile != endtile; tile += delta) {
MarkTileDirtyByTile(tile); // TODO encapsulate this into a function
}
}
return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
} else {
return CMD_ERROR; return CMD_ERROR;
} }
if (exec) {
SetRailType(tile, totype);
SetRailType(endtile, totype);
Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
if (IsBridge(tile)) {
TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
TileIndex t = tile + delta;
for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function
}
}
return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
} }
@ -1261,29 +1237,24 @@ static void AnimateTile_TunnelBridge(TileIndex tile)
static void TileLoop_TunnelBridge(TileIndex tile) static void TileLoop_TunnelBridge(TileIndex tile)
{ {
bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelBridgeSnowOrDesert(tile) : HasTunnelBridgeSnowOrDesert(tile); bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile);
switch (_opt.landscape) { switch (_opt.landscape) {
case LT_ARCTIC: case LT_ARCTIC:
if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) { if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
if (IsTunnelTile(tile)) { SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
} else {
SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
}
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
break; break;
case LT_TROPIC: case LT_TROPIC:
if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) { if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
if (IsTunnelTile(tile)) { SetTunnelBridgeSnowOrDesert(tile, true);
SetTunnelBridgeSnowOrDesert(tile, true);
} else {
SetTunnelBridgeSnowOrDesert(tile, true);
}
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
break; break;
default:
break;
} }
} }
@ -1295,15 +1266,9 @@ static void ClickTile_TunnelBridge(TileIndex tile)
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode) static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode)
{ {
if (IsTunnel(tile)) { if (GetTunnelBridgeTransportType(tile) != mode) return 0;
if (GetTunnelBridgeTransportType(tile) != mode) return 0; if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0; return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
} else {
if (GetTunnelBridgeTransportType(tile) != mode) return 0;
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
}
} }
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
@ -1318,7 +1283,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, Pl
* the bridge/tunnel. As all *our* vehicles are already removed, they * the bridge/tunnel. As all *our* vehicles are already removed, they
* must be of another owner. Therefor this must be a road bridge/tunnel. * must be of another owner. Therefor this must be a road bridge/tunnel.
* In that case we can safely reassign the ownership to OWNER_NONE. */ * In that case we can safely reassign the ownership to OWNER_NONE. */
assert((IsTunnel(tile) ? GetTunnelBridgeTransportType(tile) : GetTunnelBridgeTransportType(tile)) == TRANSPORT_ROAD); assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD);
SetTileOwner(tile, OWNER_NONE); SetTileOwner(tile, OWNER_NONE);
} }
} }