Changeset - r4158:e34ff2424478
[Not reviewed]
master
0 11 0
tron - 18 years ago 2006-07-22 08:59:52
tron@openttd.org
(svn r5582) Add and use AxisToTrack{Bits,}()
11 files changed with 80 insertions and 51 deletions:
0 comments (0 inline, 0 general)
bridge_map.h
Show inline comments
 
@@ -115,10 +115,15 @@ static inline RoadBits GetRoadBitsUnderB
 
	return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X;
 
}
 

	
 
static inline Track GetRailUnderBridge(TileIndex t)
 
{
 
	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL);
 
	return AxisToTrack(OtherAxis(GetBridgeAxis(t)));
 
}
 

	
 
static inline TrackBits GetRailBitsUnderBridge(TileIndex t)
 
{
 
	assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL);
 
	return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
 
	return TrackToTrackBits(GetRailUnderBridge(t));
 
}
 

	
 

	
direction.h
Show inline comments
 
@@ -98,6 +98,12 @@ typedef enum Axis {
 
} Axis;
 

	
 

	
 
static inline Axis OtherAxis(Axis a)
 
{
 
	return (Axis)(a ^ 1);
 
}
 

	
 

	
 
static inline Axis DiagDirToAxis(DiagDirection d)
 
{
 
	return (Axis)(d & 1);
elrail.c
Show inline comments
 
@@ -89,7 +89,7 @@ static TrackBits GetRailTrackBitsUnivers
 
			if (IsTunnel(t)) {
 
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
 
				if (override != NULL) *override = 1 << GetTunnelDirection(t);
 
				return DiagDirToAxis(GetTunnelDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
 
				return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t)));
 
			} else {
 
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
 
				if (IsBridgeMiddle(t)) {
 
@@ -102,7 +102,7 @@ static TrackBits GetRailTrackBitsUnivers
 
				} else {
 
					if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) *override = 1 << GetBridgeRampDirection(t);
 

	
 
					return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
 
					return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
 
				}
 
			}
 

	
rail.h
Show inline comments
 
@@ -34,6 +34,17 @@ typedef enum Track {
 
} Track;
 

	
 

	
 
/** Convert an Axis to the corresponding Track
 
 * AXIS_X -> TRACK_X
 
 * AXIS_Y -> TRACK_Y
 
 * Uses the fact that they share the same internal encoding
 
 */
 
static inline Track AxisToTrack(Axis a)
 
{
 
	return (Track)a;
 
}
 

	
 

	
 
/** Bitfield corresponding to Track */
 
typedef enum TrackBits {
 
	TRACK_BIT_NONE  = 0U,
 
@@ -55,6 +66,21 @@ typedef enum TrackBits {
 
} TrackBits;
 

	
 

	
 
/**
 
 * Maps a Track to the corresponding TrackBits value
 
 */
 
static inline TrackBits TrackToTrackBits(Track track)
 
{
 
	return (TrackBits)(1 << track);
 
}
 

	
 

	
 
static inline TrackBits AxisToTrackBits(Axis a)
 
{
 
	return TrackToTrackBits(AxisToTrack(a));
 
}
 

	
 

	
 
/** These are a combination of tracks and directions. Values are 0-5 in one
 
direction (corresponding to the Track enum) and 8-13 in the other direction. */
 
typedef enum Trackdirs {
 
@@ -242,11 +268,6 @@ static inline Trackdir ReverseTrackdir(T
 
}
 

	
 
/**
 
 * Maps a Track to the corresponding TrackBits value
 
 */
 
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); }
 

	
 
/**
 
 * Returns the Track that a given Trackdir represents
 
 */
 
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); }
rail_cmd.c
Show inline comments
 
@@ -234,7 +234,7 @@ int32 CmdBuildSingleRail(TileIndex tile,
 
		case MP_TUNNELBRIDGE:
 
			if (!IsBridge(tile) ||
 
					!IsBridgeMiddle(tile) ||
 
					(GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) != trackbit) {
 
					AxisToTrackBits(OtherAxis(GetBridgeAxis(tile))) != trackbit) {
 
				// Get detailed error message
 
				return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			}
 
@@ -1918,7 +1918,7 @@ static uint32 GetTileTrackStatus_Track(T
 
		return ret;
 
	} else {
 
		if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
 
			return (DiagDirToAxis(GetRailDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
			return AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(tile))) * 0x101;
 
		} else {
 
			return GetRailWaypointBits(tile) * 0x101;
 
		}
rail_map.h
Show inline comments
 
@@ -126,20 +126,20 @@ static inline DiagDirection GetRailDepot
 
	return (DiagDirection)GB(_m[t].m5, 0, 2);
 
}
 

	
 

	
 
static inline Axis GetWaypointAxis(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X;
 
}
 

	
 
static inline Track GetRailWaypointTrack(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 0) ? TRACK_Y : TRACK_X;
 
	return AxisToTrack(GetWaypointAxis(t));
 
}
 

	
 
static inline TrackBits GetRailWaypointBits(TileIndex t)
 
{
 
	return _m[t].m5 & 1 ? TRACK_BIT_Y : TRACK_BIT_X;
 
}
 

	
 

	
 
static inline Axis GetWaypointAxis(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X;
 
	return TrackToTrackBits(GetRailWaypointTrack(t));
 
}
 

	
 

	
road_cmd.c
Show inline comments
 
@@ -991,7 +991,7 @@ static uint32 GetTileTrackStatus_Road(Ti
 
					return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile)] * 0x101;
 

	
 
				case ROAD_TILE_CROSSING: {
 
					uint32 r = (GetCrossingRoadAxis(tile) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
					uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101;
 

	
 
					if (IsCrossingBarred(tile)) r *= 0x10001;
 
					return r;
 
@@ -999,7 +999,7 @@ static uint32 GetTileTrackStatus_Road(Ti
 

	
 
				default:
 
				case ROAD_TILE_DEPOT:
 
					return (DiagDirToAxis(GetRoadDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
					return AxisToTrackBits(DiagDirToAxis(GetRoadDepotDirection(tile))) * 0x101;
 
			}
 
			break;
 

	
road_map.h
Show inline comments
 
@@ -57,7 +57,7 @@ static inline RoadBits GetCrossingRoadBi
 

	
 
static inline TrackBits GetCrossingRailBits(TileIndex tile)
 
{
 
	return GetCrossingRoadAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
 
	return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile)));
 
}
 

	
 

	
station_cmd.c
Show inline comments
 
@@ -1087,7 +1087,7 @@ int32 CmdBuildRailroadStation(TileIndex 
 
		st->build_date = _date;
 

	
 
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
		track = (axis == AXIS_X ? TRACK_X : TRACK_Y);
 
		track = AxisToTrack(axis);
 

	
 
		layout_ptr = alloca(numtracks * plat_len);
 
		GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
 
@@ -2216,7 +2216,7 @@ static uint32 GetTileTrackStatus_Station
 

	
 
		case TRANSPORT_ROAD:
 
			if (IsRoadStopTile(tile)) {
 
				return (DiagDirToAxis(GetRoadStopDir(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
				return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101;
 
			}
 
			break;
 

	
station_map.h
Show inline comments
 
@@ -188,7 +188,7 @@ static inline Axis GetRailStationAxis(Ti
 

	
 
static inline Track GetRailStationTrack(TileIndex t)
 
{
 
	return GetRailStationAxis(t) == AXIS_X ? TRACK_X : TRACK_Y;
 
	return AxisToTrack(GetRailStationAxis(t));
 
}
 

	
 
static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
tunnelbridge_cmd.c
Show inline comments
 
@@ -335,7 +335,7 @@ int32 CmdBuildBridge(TileIndex end_tile,
 

	
 
			case MP_RAILWAY:
 
				if (GetRailTileType(tile) != RAIL_TILE_NORMAL ||
 
						GetTrackBits(tile) != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
 
						GetTrackBits(tile) != AxisToTrackBits(OtherAxis(direction))) {
 
					goto not_valid_below;
 
				}
 
				transport_under = TRANSPORT_RAIL;
 
@@ -415,8 +415,8 @@ not_valid_below:;
 
		}
 
	}
 

	
 
	SetSignalsOnBothDir(tile_start, direction == AXIS_X ? TRACK_X : TRACK_Y);
 
	YapfNotifyTrackLayoutChange(tile_start, direction == AXIS_X ? TRACK_X : TRACK_Y);
 
	SetSignalsOnBothDir(tile_start, AxisToTrack(direction));
 
	YapfNotifyTrackLayoutChange(tile_start, AxisToTrack(direction));
 

	
 
	/*	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
 
@@ -507,7 +507,7 @@ int32 CmdBuildTunnel(TileIndex start_til
 
			MakeRailTunnel(start_tile, _current_player, direction,                 GB(p1, 0, 4));
 
			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), GB(p1, 0, 4));
 
			UpdateSignalsOnSegment(start_tile, direction);
 
			YapfNotifyTrackLayoutChange(start_tile, DiagDirToAxis(direction) == AXIS_X ? TRACK_X : TRACK_Y);
 
			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
 
		} else {
 
			MakeRoadTunnel(start_tile, _current_player, direction);
 
			MakeRoadTunnel(end_tile,   _current_player, ReverseDiagDir(direction));
 
@@ -579,6 +579,7 @@ static int32 DoClearTunnel(TileIndex til
 
		// We first need to request the direction before calling DoClearSquare
 
		//  else the direction is always 0.. dah!! ;)
 
		DiagDirection dir = GetTunnelDirection(tile);
 
		Track track;
 

	
 
		// Adjust the town's player rating. Do this before removing the tile owner info.
 
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
 
@@ -588,8 +589,9 @@ static int32 DoClearTunnel(TileIndex til
 
		DoClearSquare(endtile);
 
		UpdateSignalsOnSegment(tile, ReverseDiagDir(dir));
 
		UpdateSignalsOnSegment(endtile, dir);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToAxis(dir) == AXIS_X ? TRACK_X : TRACK_Y);
 
		YapfNotifyTrackLayoutChange(endtile, DiagDirToAxis(dir) == AXIS_X ? TRACK_X : TRACK_Y);
 
		track = AxisToTrack(DiagDirToAxis(dir));
 
		YapfNotifyTrackLayoutChange(tile, track);
 
		YapfNotifyTrackLayoutChange(endtile, track);
 
	}
 
	return _price.clear_tunnel * (length + 1);
 
}
 
@@ -687,6 +689,7 @@ static int32 DoClearBridge(TileIndex til
 

	
 
	if (flags & DC_EXEC) {
 
		TileIndex c;
 
		Track track;
 

	
 
		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
		// you have a "Poor" (0) town rating
 
@@ -724,8 +727,9 @@ static int32 DoClearBridge(TileIndex til
 

	
 
		UpdateSignalsOnSegment(tile, ReverseDiagDir(direction));
 
		UpdateSignalsOnSegment(endtile, direction);
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToAxis(direction) == AXIS_X ? TRACK_X : TRACK_Y);
 
		YapfNotifyTrackLayoutChange(endtile, DiagDirToAxis(direction) == AXIS_X ? TRACK_X : TRACK_Y);
 
		track = AxisToTrack(DiagDirToAxis(direction));
 
		YapfNotifyTrackLayoutChange(tile, track);
 
		YapfNotifyTrackLayoutChange(endtile, track);
 
	}
 

	
 
	return (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge;
 
@@ -759,17 +763,15 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
		if (endtile == INVALID_TILE) return CMD_ERROR;
 

	
 
		if (exec) {
 
			Track track, endtrack;
 
			Track track;
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 

	
 
			// notify YAPF about the track layout change
 
			track = TrackdirToTrack(DiagdirToDiagTrackdir(GetTunnelDirection(tile)));
 
			endtrack = TrackdirToTrack(DiagdirToDiagTrackdir(GetTunnelDirection(endtile)));
 
			track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile)));
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, endtrack);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		}
 
		return (length + 1) * (_price.build_rail >> 1);
 
	} else if (IsBridge(tile) &&
 
@@ -783,13 +785,10 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
		if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
		if (exec) {
 
			TrackBits tracks;
 
			SetRailType(tile, totype);
 
			MarkTileDirtyByTile(tile);
 

	
 
			// notify YAPF about the track layout change
 
			for (tracks = GetRailBitsUnderBridge(tile); tracks != TRACK_BIT_NONE; tracks = KILL_FIRST_BIT(tracks))
 
				YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(tracks));
 
			YapfNotifyTrackLayoutChange(tile, GetRailUnderBridge(tile));
 
		}
 
		return _price.build_rail >> 1;
 
	} else if (IsBridge(tile) && IsBridgeRamp(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
 
@@ -813,17 +812,15 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
		if (GetRailType(tile) == totype) return CMD_ERROR;
 

	
 
		if (exec) {
 
			Track track, endtrack;
 
			Track track;
 
			SetRailType(tile, totype);
 
			SetRailType(endtile, totype);
 
			MarkTileDirtyByTile(tile);
 
			MarkTileDirtyByTile(endtile);
 

	
 
			// notify YAPF about the track layout change
 
			track = TrackdirToTrack(DiagdirToDiagTrackdir(GetBridgeRampDirection(tile)));
 
			endtrack = TrackdirToTrack(DiagdirToDiagTrackdir(GetBridgeRampDirection(endtile)));
 
			track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
 
			YapfNotifyTrackLayoutChange(tile, track);
 
			YapfNotifyTrackLayoutChange(endtile, endtrack);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		}
 
		cost = 2 * (_price.build_rail >> 1);
 
		delta = TileOffsByDir(GetBridgeRampDirection(tile));
 
@@ -1273,20 +1270,20 @@ static uint32 GetTileTrackStatus_TunnelB
 
{
 
	if (IsTunnel(tile)) {
 
		if (GetTunnelTransportType(tile) != mode) return 0;
 
		return (DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
		return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(tile))) * 0x101;
 
	} else {
 
		if (IsBridgeRamp(tile)) {
 
			if (GetBridgeTransportType(tile) != mode) return 0;
 
			return (DiagDirToAxis(GetBridgeRampDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
			return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
 
		} else {
 
			uint32 result = 0;
 

	
 
			if (GetBridgeTransportType(tile) == mode) {
 
				result = (GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
				result = AxisToTrackBits(GetBridgeAxis(tile)) * 0x101;
 
			}
 
			if ((IsTransportUnderBridge(tile) && mode == GetTransportTypeUnderBridge(tile)) ||
 
					(IsWaterUnderBridge(tile)     && mode == TRANSPORT_WATER)) {
 
				result |= (GetBridgeAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X) * 0x101;
 
				result |= AxisToTrackBits(OtherAxis(GetBridgeAxis(tile))) * 0x101;
 
			}
 
			return result;
 
		}
0 comments (0 inline, 0 general)