Changeset - r9224:0340c9af9930
[Not reviewed]
master
0 12 0
smatz - 17 years ago 2008-05-14 18:31:21
smatz@openttd.org
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
12 files changed with 64 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -2198,7 +2198,7 @@ static void AiBuildRailConstruct(Player 
 
		int32 bridge_len = GetTunnelBridgeLength(t1, t2);
 

	
 
		DiagDirection dir = (TileX(t1) == TileX(t2) ? DIAGDIR_SE : DIAGDIR_SW);
 
		Track track = AxisToTrack(DiagDirToAxis(dir));
 
		Track track = DiagDirToDiagTrack(dir);
 

	
 
		if (t2 < t1) dir = ReverseDiagDir(dir);
 

	
src/elrail.cpp
Show inline comments
 
@@ -104,7 +104,7 @@ static TrackBits GetRailTrackBitsUnivers
 
			if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
 
				*override = 1 << GetTunnelBridgeDirection(t);
 
			}
 
			return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
 
			return DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t));
 

	
 
		case MP_ROAD:
 
			if (!IsLevelCrossing(t)) return TRACK_BIT_NONE;
src/rail_cmd.cpp
Show inline comments
 
@@ -778,7 +778,7 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
		d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
 

	
 
		AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player);
 
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
	}
 

	
 
	return cost.AddCost(_price.build_train_depot);
 
@@ -1247,7 +1247,7 @@ CommandCost CmdConvertRail(TileIndex til
 
						case RAIL_TILE_WAYPOINT:
 
							if (flags & DC_EXEC) {
 
								/* notify YAPF about the track layout change */
 
								YapfNotifyTrackLayoutChange(tile, AxisToTrack(GetWaypointAxis(tile)));
 
								YapfNotifyTrackLayoutChange(tile, GetRailWaypointTrack(tile));
 
							}
 
							cost.AddCost(RailConvertCost(type, totype));
 
							break;
 
@@ -1255,7 +1255,7 @@ CommandCost CmdConvertRail(TileIndex til
 
						case RAIL_TILE_DEPOT:
 
							if (flags & DC_EXEC) {
 
								/* notify YAPF about the track layout change */
 
								YapfNotifyTrackLayoutChange(tile, AxisToTrack(DiagDirToAxis(GetRailDepotDirection(tile))));
 
								YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
 

	
 
								/* Update build vehicle window related to this depot */
 
								InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
 
@@ -1296,7 +1296,7 @@ CommandCost CmdConvertRail(TileIndex til
 
						VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
 
						VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc);
 

	
 
						Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
 
						Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
 

	
 
						YapfNotifyTrackLayoutChange(tile, track);
 
						YapfNotifyTrackLayoutChange(endtile, track);
 
@@ -1345,7 +1345,7 @@ static CommandCost RemoveTrainDepot(Tile
 
		DoClearSquare(tile);
 
		delete GetDepotByTile(tile);
 
		AddSideToSignalBuffer(tile, dir, owner);
 
		YapfNotifyTrackLayoutChange(tile, TrackdirToTrack(DiagdirToDiagTrackdir(dir)));
 
		YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
@@ -2150,7 +2150,7 @@ static TrackStatus GetTileTrackStatus_Tr
 

	
 
			if (side != INVALID_DIAGDIR && side != dir) break;
 

	
 
			trackbits = AxisToTrackBits(DiagDirToAxis(dir));
 
			trackbits = DiagDirToDiagTrackBits(dir);
 
			break;
 
		}
 

	
src/rail_map.h
Show inline comments
 
@@ -168,6 +168,17 @@ static inline DiagDirection GetRailDepot
 
	return (DiagDirection)GB(_m[t].m5, 0, 2);
 
}
 

	
 
/**
 
 * Returns the track of a depot, ignoring direction
 
 * @pre IsRailDepotTile(t)
 
 * @param t the tile to get the depot track from
 
 * @return the track of the depot
 
 */
 
static inline Track GetRailDepotTrack(TileIndex t)
 
{
 
	return DiagDirToDiagTrack(GetRailDepotDirection(t));
 
}
 

	
 

	
 
/**
 
 * Returns the axis of the waypoint
src/road_cmd.cpp
Show inline comments
 
@@ -1391,7 +1391,7 @@ static TrackStatus GetTileTrackStatus_Ro
 

	
 
					if (side != INVALID_DIAGDIR && side != dir) break;
 

	
 
					trackdirbits = TrackBitsToTrackdirBits(AxisToTrackBits(DiagDirToAxis(dir)));
 
					trackdirbits = TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir));
 
					break;
 
				}
 
			}
src/roadveh_cmd.cpp
Show inline comments
 
@@ -970,7 +970,7 @@ static void RoadVehCheckOvertake(Vehicle
 
	/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */
 
	if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return;
 

	
 
	od.trackdir = DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
 
	od.trackdir = DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
 

	
 
	/* Are the current and the next tile suitable for overtaking?
 
	 *  - Does the track continue along od.trackdir
 
@@ -1135,7 +1135,7 @@ static Trackdir RoadFindPathToDest(Vehic
 
			NPFFindStationOrTileData fstd;
 

	
 
			NPFFillWithOrderData(&fstd, v);
 
			Trackdir trackdir = DiagdirToDiagTrackdir(enterdir);
 
			Trackdir trackdir = DiagDirToDiagTrackdir(enterdir);
 
			//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
 

	
 
			NPFFoundTargetData ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, v->owner, INVALID_RAILTYPES);
 
@@ -1325,7 +1325,7 @@ static Trackdir FollowPreviousRoadVehicl
 
		}
 

	
 
		if (diag_dir == INVALID_DIAGDIR) return INVALID_TRACKDIR;
 
		dir = DiagdirToDiagTrackdir(diag_dir);
 
		dir = DiagDirToDiagTrackdir(diag_dir);
 
	} else {
 
		if (already_reversed && prev->tile != tile) {
 
			/*
src/track_func.h
Show inline comments
 
@@ -24,8 +24,6 @@ static inline Track AxisToTrack(Axis a)
 
	return (Track)a;
 
}
 

	
 

	
 

	
 
/**
 
 * Maps a Track to the corresponding TrackBits value
 
 * @param track the track to convert
 
@@ -277,7 +275,7 @@ static inline TrackBits TrackdirBitsToTr
 
 * Converts TrackBits to TrackdirBits while allowing both directions.
 
 *
 
 * @param bits The TrackBits
 
 * @return The TrackDirBits containing of bits in both directions.
 
 * @return The TrackdirBits containing of bits in both directions.
 
 */
 
static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
 
{
 
@@ -436,13 +434,35 @@ static inline Trackdir TrackDirectionToT
 
}
 

	
 
/**
 
 * Maps a (4-way) direction to the diagonal track incidating with that diagdir
 
 *
 
 * @param diagdir The direction
 
 * @return The resulting Track
 
 */
 
static inline Track DiagDirToDiagTrack(DiagDirection diagdir)
 
{
 
	return (Track)(diagdir & 1);
 
}
 

	
 
/**
 
 * Maps a (4-way) direction to the diagonal track bits incidating with that diagdir
 
 *
 
 * @param diagdir The direction
 
 * @return The resulting TrackBits
 
 */
 
static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
 
{
 
	return TrackToTrackBits(DiagDirToDiagTrack(diagdir));
 
}
 

	
 
/**
 
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
 
 * direction.
 
 *
 
 * @param diagdir The direction
 
 * @return The resulting Trackdir direction
 
 */
 
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
 
static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
 
{
 
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
 
	return _dir_to_diag_trackdir[diagdir];
src/train_cmd.cpp
Show inline comments
 
@@ -1764,7 +1764,7 @@ static void AdvanceWagonsAfterSwap(Vehic
 

	
 
		if (d <= 0) {
 
			leave->vehstatus &= ~VS_HIDDEN; // move it out of the depot
 
			leave->u.rail.track = AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(leave->tile)));
 
			leave->u.rail.track = TrackToTrackBits(GetRailDepotTrack(leave->tile));
 
			for (int i = 0; i >= d; i--) TrainController(leave, NULL, false); // maybe move it, and maybe let another wagon leave
 
		}
 
	} else {
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -494,7 +494,7 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
	delta = TileOffsByDiagDir(direction);
 
	DiagDirection tunnel_in_way_dir;
 
	if (OtherAxis(DiagDirToAxis(direction)) == AXIS_X) {
 
	if (DiagDirToAxis(direction) == AXIS_Y) {
 
		tunnel_in_way_dir = (TileX(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SW : DIAGDIR_NE;
 
	} else {
 
		tunnel_in_way_dir = (TileY(start_tile) < (MapMaxX() / 2)) ? DIAGDIR_SE : DIAGDIR_NW;
 
@@ -558,7 +558,7 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
			MakeRailTunnel(start_tile, _current_player, direction,                 (RailType)GB(p1, 0, 4));
 
			MakeRailTunnel(end_tile,   _current_player, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4));
 
			AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_player);
 
			YapfNotifyTrackLayoutChange(start_tile, AxisToTrack(DiagDirToAxis(direction)));
 
			YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(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));
 
@@ -623,7 +623,7 @@ static CommandCost DoClearTunnel(TileInd
 
			AddSideToSignalBuffer(tile,    ReverseDiagDir(dir), owner);
 
			AddSideToSignalBuffer(endtile, dir,                 owner);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(dir));
 
			Track track = DiagDirToDiagTrack(dir);
 
			YapfNotifyTrackLayoutChange(tile,    track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		} else {
 
@@ -691,7 +691,7 @@ static CommandCost DoClearBridge(TileInd
 
			AddSideToSignalBuffer(tile,    ReverseDiagDir(direction), owner);
 
			AddSideToSignalBuffer(endtile, direction,                 owner);
 

	
 
			Track track = AxisToTrack(DiagDirToAxis(direction));
 
			Track track = DiagDirToDiagTrack(direction);
 
			YapfNotifyTrackLayoutChange(tile,    track);
 
			YapfNotifyTrackLayoutChange(endtile, track);
 
		}
 
@@ -1233,7 +1233,7 @@ static TrackStatus GetTileTrackStatus_Tu
 

	
 
	DiagDirection dir = GetTunnelBridgeDirection(tile);
 
	if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
 
	return CombineTrackStatus(TrackBitsToTrackdirBits(AxisToTrackBits(DiagDirToAxis(dir))), TRACKDIR_BIT_NONE);
 
	return CombineTrackStatus(TrackBitsToTrackdirBits(DiagDirToDiagTrackBits(dir)), TRACKDIR_BIT_NONE);
 
}
 

	
 
static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player)
src/vehicle.cpp
Show inline comments
 
@@ -1867,34 +1867,34 @@ Trackdir GetVehicleTrackdir(const Vehicl
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards
 
				return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot
 
				return DiagDirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot
 

	
 
			if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel, so just use his direction and assume a diagonal track
 
				return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
 
				return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
 

	
 
			return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction);
 

	
 
		case VEH_SHIP:
 
			if (v->IsInDepot())
 
				// We'll assume the ship is facing outwards
 
				return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile));
 
				return DiagDirToDiagTrackdir(GetShipDepotDirection(v->tile));
 

	
 
			return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction);
 

	
 
		case VEH_ROAD:
 
			if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards
 
				return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile));
 
				return DiagDirToDiagTrackdir(GetRoadDepotDirection(v->tile));
 

	
 
			if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards
 
				return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station
 

	
 
			if (IsDriveThroughStopTile(v->tile)) return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
 
				return DiagDirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station
 

	
 
			if (IsDriveThroughStopTile(v->tile)) return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
 

	
 
			/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */
 
			if (!IsReversingRoadTrackdir((Trackdir)v->u.road.state)) return (Trackdir)v->u.road.state;
 

	
 
			/* Vehicle is turning around, get the direction from vehicle's direction */
 
			return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));
 
			return DiagDirToDiagTrackdir(DirToDiagDir(v->direction));
 

	
 
		/* case VEH_AIRCRAFT: case VEH_EFFECT: case VEH_DISASTER: */
 
		default: return INVALID_TRACKDIR;
src/water_cmd.cpp
Show inline comments
 
@@ -1123,7 +1123,7 @@ static TrackStatus GetTileTrackStatus_Wa
 
	switch (GetWaterTileType(tile)) {
 
		case WATER_TILE_CLEAR: ts = (GetTileSlope(tile, NULL) == SLOPE_FLAT) ? TRACK_BIT_ALL : TRACK_BIT_NONE; break;
 
		case WATER_TILE_COAST: ts = (TrackBits)coast_tracks[GetTileSlope(tile, NULL) & 0xF]; break;
 
		case WATER_TILE_LOCK:  ts = AxisToTrackBits(DiagDirToAxis(GetLockDirection(tile))); break;
 
		case WATER_TILE_LOCK:  ts = DiagDirToDiagTrackBits(GetLockDirection(tile)); break;
 
		case WATER_TILE_DEPOT: ts = AxisToTrackBits(GetShipDepotAxis(tile)); break;
 
		default: return 0;
 
	}
src/yapf/yapf_road.cpp
Show inline comments
 
@@ -88,7 +88,7 @@ public:
 
			if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break;
 

	
 
			// stop if we have just entered the depot
 
			if (IsRoadDepotTile(tile) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
 
			if (IsRoadDepotTile(tile) && trackdir == DiagDirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
 
				// next time we will reverse and leave the depot
 
				break;
 
			}
 
@@ -264,7 +264,7 @@ public:
 
		// handle special case - when next tile is destination tile
 
		if (tile == v->dest_tile) {
 
			// choose diagonal trackdir reachable from enterdir
 
			return (Trackdir)DiagdirToDiagTrackdir(enterdir);
 
			return DiagDirToDiagTrackdir(enterdir);
 
		}
 
		// our source tile will be the next vehicle tile (should be the given one)
 
		TileIndex src_tile = tile;
0 comments (0 inline, 0 general)