Changeset - r8300:4cfeeb3725a9
[Not reviewed]
master
0 9 0
smatz - 17 years ago 2008-01-15 15:00:01
smatz@openttd.org
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
9 files changed with 72 insertions and 56 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -437,13 +437,13 @@ void ChangeOwnershipOfPlayerItems(Player
 

	
 
			do {
 
				if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_player) && HasSignals(tile)) {
 
					TrackBits tracks = GetTrackBits(tile);
 
					do { // there may be two tracks with signals for TRACK_BIT_HORZ and TRACK_BIT_VERT
 
						Track track = RemoveFirstTrack(&tracks);
 
						if (HasSignalOnTrack(tile, track)) SetSignalsOnBothDir(tile, track);
 
						if (HasSignalOnTrack(tile, track)) SetSignalsOnBothDir(tile, track, new_player);
 
					} while (tracks != TRACK_BIT_NONE);
 
				}
 
			} while (++tile != MapSize());
 
		}
 
	}
 

	
src/rail_cmd.cpp
Show inline comments
 
@@ -415,13 +415,13 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			}
 
			break;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		MarkTileDirtyByTile(tile);
 
		SetSignalsOnBothDir(tile, track);
 
		SetSignalsOnBothDir(tile, track, _current_player);
 
		YapfNotifyTrackLayoutChange(tile, track);
 
	}
 

	
 
	return cost.AddCost(RailBuildCost(railtype));
 
}
 

	
 
@@ -438,12 +438,16 @@ CommandCost CmdRemoveSingleRail(TileInde
 
	CommandCost cost(EXPENSES_CONSTRUCTION, _price.remove_rail );
 
	bool crossing = false;
 

	
 
	if (!ValParamTrackOrientation((Track)p2)) return CMD_ERROR;
 
	trackbit = TrackToTrackBits(track);
 

	
 
	/* Need to read tile owner now because it may change when the rail is removed.
 
	 * Also, in case of floods, _current_player != owner */
 
	Owner owner = GetTileOwner(tile);
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD: {
 
			if (!IsLevelCrossing(tile) ||
 
					GetCrossingRailBits(tile) != trackbit ||
 
					(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
 
					!EnsureNoVehicleOnGround(tile)) {
 
@@ -495,18 +499,18 @@ CommandCost CmdRemoveSingleRail(TileInde
 
		MarkTileDirtyByTile(tile);
 
		if (crossing) {
 
			/* crossing is set when only TRACK_BIT_X and TRACK_BIT_Y are set. As we
 
			 * are removing one of these pieces, we'll need to update signals for
 
			 * both directions explicitly, as after the track is removed it won't
 
			 * 'connect' with the other piece. */
 
			SetSignalsOnBothDir(tile, TRACK_X);
 
			SetSignalsOnBothDir(tile, TRACK_Y);
 
			SetSignalsOnBothDir(tile, TRACK_X, owner);
 
			SetSignalsOnBothDir(tile, TRACK_Y, owner);
 
			YapfNotifyTrackLayoutChange(tile, TRACK_X);
 
			YapfNotifyTrackLayoutChange(tile, TRACK_Y);
 
		} else {
 
			SetSignalsOnBothDir(tile, track);
 
			SetSignalsOnBothDir(tile, track, owner);
 
			YapfNotifyTrackLayoutChange(tile, track);
 
		}
 
	}
 

	
 
	return cost;
 
}
 
@@ -738,13 +742,13 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
	if (flags & DC_EXEC) {
 
		MakeRailDepot(tile, _current_player, dir, (RailType)p1);
 
		MarkTileDirtyByTile(tile);
 

	
 
		d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
 

	
 
		UpdateSignalsOnSegment(tile, INVALID_DIAGDIR);
 
		UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, _current_player);
 
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 
		d_auto_delete.Detach();
 
	}
 

	
 
	return cost.AddCost(_price.build_train_depot);
 
}
 
@@ -864,13 +868,13 @@ CommandCost CmdBuildSingleSignal(TileInd
 
			 * direction of the first signal given as parameter by CmdBuildManySignals */
 
			SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | (p2 & SignalOnTrack(track)));
 
			SetSignalVariant(tile, track, sigvar);
 
		}
 

	
 
		MarkTileDirtyByTile(tile);
 
		SetSignalsOnBothDir(tile, track);
 
		SetSignalsOnBothDir(tile, track, _current_player);
 
		YapfNotifyTrackLayoutChange(tile, track);
 
	}
 

	
 
	return cost;
 
}
 

	
 
@@ -1095,13 +1099,13 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
		if (GetPresentSignals(tile) == 0) {
 
			SetSignalStates(tile, 0);
 
			SetHasSignals(tile, false);
 
			SetSignalVariant(tile, INVALID_TRACK, SIG_ELECTRIC); // remove any possible semaphores
 
		}
 

	
 
		SetSignalsOnBothDir(tile, track);
 
		SetSignalsOnBothDir(tile, track, GetTileOwner(tile));
 
		YapfNotifyTrackLayoutChange(tile, track);
 

	
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_signals);
 
@@ -1301,17 +1305,19 @@ static CommandCost RemoveTrainDepot(Tile
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicleOnGround(tile))
 
		return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		/* read variables before the depot is removed */
 
		DiagDirection dir = GetRailDepotDirection(tile);
 
		Owner owner = GetTileOwner(tile);
 

	
 
		DoClearSquare(tile);
 
		delete GetDepotByTile(tile);
 
		UpdateSignalsOnSegment(tile, dir);
 
		UpdateSignalsOnSegment(tile, dir, owner);
 
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
}
 

	
src/signal.cpp
Show inline comments
 
@@ -254,18 +254,16 @@ DECLARE_ENUM_AS_BIT_SET(SigFlags)
 
 * @return SigFlags
 
 */
 
static SigFlags ExploreSegment(Owner owner)
 
{
 
	SigFlags flags = SF_NONE;
 

	
 
	while (!_tbdset.IsEmpty()) {
 
		TileIndex tile;
 
		DiagDirection enterdir;
 
	TileIndex tile;
 
	DiagDirection enterdir;
 

	
 
		_tbdset.Get(&tile, &enterdir);
 

	
 
	while (_tbdset.Get(&tile, &enterdir)) {
 
		TileIndex oldtile = tile; // tile we are leaving
 
		DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
 

	
 
		switch (GetTileType(tile)) {
 
			case MP_RAILWAY: {
 
				if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
 
@@ -393,17 +391,16 @@ static SigFlags ExploreSegment(Owner own
 
 * Update signals around segment in _tbuset
 
 *
 
 * @param flags info about segment
 
 */
 
static void UpdateSignalsAroundSegment(SigFlags flags)
 
{
 
	while (!_tbuset.IsEmpty()) {
 
		TileIndex tile;
 
		Trackdir trackdir;
 
		_tbuset.Get(&tile, &trackdir);
 
	TileIndex tile;
 
	Trackdir trackdir;
 

	
 
	while (_tbuset.Get(&tile, &trackdir)) {
 
		assert(HasSignalOnTrackdir(tile, trackdir));
 

	
 
		SignalType sig = GetSignalType(tile, TrackdirToTrack(trackdir));
 
		SignalState newstate = SIGNAL_STATE_GREEN;
 

	
 
		/* determine whether the new state is red */
 
@@ -450,21 +447,23 @@ static inline void ResetSets()
 
}
 

	
 

	
 
/**
 
 * Updates blocks in _globset buffer
 
 *
 
 * @param owner player whose signals we are updating
 
 * @return false iff presignal entry would be green (needed for trains leaving depot)
 
 * @pre IsValidPlayer(owner)
 
 */
 
static bool UpdateSignalsInBuffer()
 
static bool UpdateSignalsInBuffer(Owner owner)
 
{
 
	assert(IsValidPlayer(owner));
 

	
 
	bool first = true;  // first block?
 
	bool state = false; // value to return
 

	
 
	Owner owner = OWNER_NONE; // owner whose signals we are updating
 

	
 
	TileIndex tile;
 
	DiagDirection dir;
 

	
 
	while (_globset.Get(&tile, &dir)) {
 
		assert(_tbuset.IsEmpty());
 
		assert(_tbdset.IsEmpty());
 
@@ -476,50 +475,45 @@ static bool UpdateSignalsInBuffer()
 
		 */
 
		switch (GetTileType(tile)) {
 
			case MP_TUNNELBRIDGE:
 
				/* 'optimization assert' - do not try to update signals when it is not needed */
 
				assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL);
 
				assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
 
				if (first) owner = GetTileOwner(tile);
 
				_tbdset.Add(tile, INVALID_DIAGDIR);  // we can safely start from wormhole centre
 
				_tbdset.Add(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR);
 
				break;
 

	
 
			case MP_RAILWAY:
 
				if (IsRailDepot(tile)) {
 
					/* 'optimization assert' do not try to update signals in other cases */
 
					assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
 
					if (first) owner = GetTileOwner(tile);
 
					_tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
 
					break;
 
				}
 
				/* FALLTHROUGH */
 
			case MP_STATION:
 
			case MP_ROAD:
 
				if ((TrackBits)(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
 
 					/* only add to set when there is some 'interesting' track */
 
					if (first) owner = GetTileOwner(tile);
 
					_tbdset.Add(tile, dir);
 
					_tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
 
					break;
 
				}
 
				/* FALLTHROUGH */
 
			default:
 
				/* jump to next tile */
 
				tile = tile + TileOffsByDiagDir(dir);
 
				dir = ReverseDiagDir(dir);
 
				if ((TrackBits)(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
 
					if (first) owner = GetTileOwner(tile);
 
					_tbdset.Add(tile, dir);
 
					break;
 
				}
 
				/* happens when removing a rail that wasn't connected at one or both sides */
 
				continue; // continue the while() loop
 
		}
 

	
 
		assert(IsValidPlayer(owner));
 
		assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
 
		assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
 

	
 
		SigFlags flags = ExploreSegment(owner);
 

	
 
		if (first) {
 
@@ -544,40 +538,42 @@ static bool UpdateSignalsInBuffer()
 
 * Update signals, starting at one side of a tile
 
 * Will check tile next to this at opposite side too
 
 *
 
 * @see UpdateSignalsInBuffer()
 
 * @param tile tile where we start
 
 * @param side side of tile
 
 * @param owner owner whose signals we will update
 
 * @return false iff train can leave depot
 
 */
 
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection side)
 
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
 
{
 
	assert(_globset.IsEmpty());
 
	_globset.Add(tile, side);
 

	
 
	return UpdateSignalsInBuffer();
 
	return UpdateSignalsInBuffer(owner);
 
}
 

	
 

	
 
/**
 
 * Update signals at segments that are at both ends of
 
 * given (existent or non-existent) track
 
 *
 
 * @see UpdateSignalsInBuffer()
 
 * @param tile tile where we start
 
 * @param track track at which ends we will update signals
 
 * @param owner owner whose signals we will update
 
 */
 
void SetSignalsOnBothDir(TileIndex tile, Track track)
 
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
 
{
 
	static const DiagDirection _search_dir_1[] = {
 
		DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE
 
	};
 
	static const DiagDirection _search_dir_2[] = {
 
		DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE
 
	};
 

	
 
	assert(_globset.IsEmpty());
 

	
 
	_globset.Add(tile, _search_dir_1[track]);
 
	_globset.Add(tile, _search_dir_2[track]);
 
	UpdateSignalsInBuffer();
 
	UpdateSignalsInBuffer(owner);
 
}
src/signal_func.h
Show inline comments
 
@@ -6,12 +6,13 @@
 
#define SIGNAL_FUNC_H
 

	
 
#include "track_type.h"
 
#include "tile_type.h"
 
#include "direction_type.h"
 
#include "track_type.h"
 
#include "player_type.h"
 

	
 
/**
 
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
 
 * direction along with the trackdir.
 
 */
 
static inline byte SignalAlongTrackdir(Trackdir trackdir)
 
@@ -37,10 +38,10 @@ static inline byte SignalAgainstTrackdir
 
static inline byte SignalOnTrack(Track track)
 
{
 
	extern const byte _signal_on_track[TRACK_END];
 
	return _signal_on_track[track];
 
}
 

	
 
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection side);
 
void SetSignalsOnBothDir(TileIndex tile, Track track);
 
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner);
 
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner);
 

	
 
#endif /* SIGNAL_FUNC_H */
src/station_cmd.cpp
Show inline comments
 
@@ -1070,13 +1070,13 @@ CommandCost CmdBuildRailroadStation(Tile
 
					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
 
					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
 
				}
 

	
 
				tile += tile_delta;
 
			} while (--w);
 
			SetSignalsOnBothDir(tile_org, track);
 
			SetSignalsOnBothDir(tile_org, track, _current_player);
 
			YapfNotifyTrackLayoutChange(tile_org, track);
 
			tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
 
		} while (--numtracks);
 

	
 
		st->MarkTilesDirty(false);
 
		UpdateStationVirtCoordDirty(st);
 
@@ -1199,17 +1199,20 @@ CommandCost CmdRemoveFromRailroadStation
 
		if (!_patches.nonuniform_stations) return_cmd_error(STR_306D_NONUNIFORM_STATIONS_DISALLOWED);
 

	
 
		/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
 
		quantity++;
 

	
 
		if (flags & DC_EXEC) {
 
			/* read variables before the station tile is removed */
 
			uint specindex = GetCustomStationSpecIndex(tile2);
 
			Track track = GetRailStationTrack(tile2);
 
			Owner owner = GetTileOwner(tile2);
 

	
 
			DoClearSquare(tile2);
 
			st->rect.AfterRemoveTile(st, tile2);
 
			SetSignalsOnBothDir(tile2, track);
 
			SetSignalsOnBothDir(tile2, track, owner);
 
			YapfNotifyTrackLayoutChange(tile2, track);
 

	
 
			DeallocateSpecFromStation(st, specindex);
 

	
 
			/* now we need to make the "spanned" area of the railway station smaller
 
			 * if we deleted something at the edges.
 
@@ -1254,21 +1257,23 @@ static CommandCost RemoveRailroadStation
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	/* clear all areas of the station */
 
	do {
 
		int w_bak = w;
 
		do {
 
			// for nonuniform stations, only remove tiles that are actually train station tiles
 
			/* for nonuniform stations, only remove tiles that are actually train station tiles */
 
			if (st->TileBelongsToRailStation(tile)) {
 
				if (!EnsureNoVehicleOnGround(tile))
 
					return CMD_ERROR;
 
				cost.AddCost(_price.remove_rail_station);
 
				if (flags & DC_EXEC) {
 
					/* read variables before the station tile is removed */
 
					Track track = GetRailStationTrack(tile);
 
					Owner owner = GetTileOwner(tile); // _current_player can be OWNER_WATER
 
					DoClearSquare(tile);
 
					SetSignalsOnBothDir(tile, track);
 
					SetSignalsOnBothDir(tile, track, owner);
 
					YapfNotifyTrackLayoutChange(tile, track);
 
				}
 
			}
 
			tile += TileDiffXY(1, 0);
 
		} while (--w);
 
		w = w_bak;
src/train_cmd.cpp
Show inline comments
 
@@ -2165,13 +2165,13 @@ static bool CheckTrainStayInDepot(Vehicl
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			return true;
 
		}
 

	
 
		v->load_unload_time_rem = 0;
 

	
 
		if (UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR)) {
 
		if (UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner)) {
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			return true;
 
		}
 
	}
 

	
 
	VehicleServiceInDepot(v);
 
@@ -2184,13 +2184,13 @@ static bool CheckTrainStayInDepot(Vehicl
 
	v->vehstatus &= ~VS_HIDDEN;
 
	v->cur_speed = 0;
 

	
 
	v->UpdateDeltaXY(v->direction);
 
	v->cur_image = v->GetImage(v->direction);
 
	VehiclePositionChanged(v);
 
	UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR);
 
	UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
 
	UpdateTrainAcceleration(v);
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	return false;
 
}
 

	
 
@@ -2765,13 +2765,13 @@ static const DiagDirection _otherside_si
 

	
 
static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
 
{
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			GetRailTileType(tile) == RAIL_TILE_SIGNALS) {
 
		uint i = FindFirstBit2x64(GetTrackBits(tile) * 0x101 & _reachable_tracks[dir]);
 
		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
 
		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i], GetTileOwner(tile));
 
	}
 
}
 

	
 

	
 
static void SetVehicleCrashed(Vehicle *v)
 
{
 
@@ -3138,24 +3138,26 @@ static void DeleteLastWagon(Vehicle *v)
 
	BeginVehicleMove(v);
 
	EndVehicleMove(v);
 

	
 
	/* 'v' shouldn't be accessed after it has been deleted */
 
	TrackBits track = v->u.rail.track;
 
	TileIndex tile = v->tile;
 
	Owner owner = v->owner;
 

	
 
	delete v;
 
	v = NULL; // make sure nobody will won't try to read 'v' anymore
 

	
 
	/* Check if the wagon was on a road/rail-crossing and disable it if no
 
	 * others are on it */
 
	DisableTrainCrossing(tile);
 

	
 
	/* Update signals */
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) || IsTileDepotType(tile, TRANSPORT_RAIL)) {
 
		UpdateSignalsOnSegment(tile, INVALID_DIAGDIR);
 
		UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner);
 
	} else {
 
		SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)));
 
		SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)), owner);
 
	}
 
}
 

	
 
static void ChangeTrainDirRandomly(Vehicle *v)
 
{
 
	static const DirDiff delta[] = {
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -416,13 +416,13 @@ not_valid_below:;
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC && railtype != INVALID_RAILTYPE) {
 
		Track track = AxisToTrack(direction);
 
		UpdateSignalsOnSegment(tile_start, INVALID_DIAGDIR);
 
		UpdateSignalsOnSegment(tile_start, INVALID_DIAGDIR, _current_player);
 
		YapfNotifyTrackLayoutChange(tile_start, track);
 
	}
 

	
 
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
 
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
 
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
 
@@ -546,13 +546,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	cost.AddCost(ret);
 

	
 
	if (flags & DC_EXEC) {
 
		if (GB(p1, 9, 1) == TRANSPORT_RAIL) {
 
			MakeRailTunnel(start_tile, _current_player, direction,                 (RailType)GB(p1, 0, 4));
 
			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
 
			UpdateSignalsOnSegment(start_tile, INVALID_DIAGDIR);
 
			UpdateSignalsOnSegment(start_tile, INVALID_DIAGDIR, _current_player);
 
			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
 
		} else {
 
			MakeRoadTunnel(start_tile, _current_player, direction,                 (RoadTypes)GB(p1, 0, 3));
 
			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 3));
 
		}
 
	}
 
@@ -600,27 +600,30 @@ static CommandCost DoClearTunnel(TileInd
 
	 * 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);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* We first need to request the direction before calling DoClearSquare
 
		 *  else the direction is always 0.. dah!! ;) */
 
		DiagDirection dir = GetTunnelBridgeDirection(tile);
 
		bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
 
		if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
			/* We first need to request values before calling DoClearSquare */
 
			DiagDirection dir = GetTunnelBridgeDirection(tile);
 
			Owner owner = GetTileOwner(tile);
 

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
			DoClearSquare(tile);
 
			DoClearSquare(endtile);
 

	
 
		if (rail) {
 
			UpdateSignalsOnSegment(tile, ReverseDiagDir(dir));
 
			UpdateSignalsOnSegment(endtile, dir);
 
			/* cannot use INVALID_DIAGDIR for signal update because the tunnel doesn't exist anymore */
 
			UpdateSignalsOnSegment(tile, ReverseDiagDir(dir), owner);
 
			UpdateSignalsOnSegment(endtile, dir, owner);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(dir));
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		} else {
 
			DoClearSquare(tile);
 
			DoClearSquare(endtile);
 
		}
 
	}
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
 
}
 

	
 

	
 
@@ -657,23 +660,25 @@ static CommandCost DoClearBridge(TileInd
 
		ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 
	}
 

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

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		for (TileIndex c = tile + delta; c != endtile; c += delta) {
 
			ClearBridgeMiddle(c);
 
			MarkTileDirtyByTile(c);
 
		}
 

	
 
		if (rail) {
 
			UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
 
			UpdateSignalsOnSegment(endtile, direction);
 
			/* cannot use INVALID_DIAGDIR for signal update because the bridge doesn't exist anymore */
 
			UpdateSignalsOnSegment(tile, ReverseDiagDir(direction), owner);
 
			UpdateSignalsOnSegment(endtile, direction, owner);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(direction));
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		}
 
	}
src/vehicle.cpp
Show inline comments
 
@@ -2175,13 +2175,13 @@ uint8 CalcPercentVehicleFilled(Vehicle *
 
void VehicleEnterDepot(Vehicle *v)
 
{
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			if (!IsFrontEngine(v)) v = v->First();
 
			UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR);
 
			UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
 
			v->load_unload_time_rem = 0;
 
			break;
 

	
 
		case VEH_ROAD:
 
			InvalidateWindowClasses(WC_ROADVEH_LIST);
 
			if (!IsRoadVehFront(v)) v = v->First();
src/waypoint.cpp
Show inline comments
 
@@ -283,23 +283,24 @@ CommandCost RemoveTrainWaypoint(TileInde
 
			!EnsureNoVehicleOnGround(tile)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		Track track = GetRailWaypointTrack(tile);
 
		Owner owner = GetTileOwner(tile); // cannot use _current_player because of possible floods
 
		wp = GetWaypointByTile(tile);
 

	
 
		wp->deleted = 30; // let it live for this many days before we do the actual deletion.
 
		RedrawWaypointSign(wp);
 

	
 
		if (justremove) {
 
			MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile));
 
			MarkTileDirtyByTile(tile);
 
		} else {
 
			DoClearSquare(tile);
 
			SetSignalsOnBothDir(tile, track);
 
			SetSignalsOnBothDir(tile, track, owner);
 
		}
 
		YapfNotifyTrackLayoutChange(tile, track);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
}
0 comments (0 inline, 0 general)