Changeset - r2182:c25721cf181e
[Not reviewed]
master
0 3 0
tron - 19 years ago 2005-07-23 19:48:24
tron@openttd.org
(svn r2696) Remove stray semicolons
3 files changed with 17 insertions and 17 deletions:
npf.c
2
2
pbs.c
14
14
0 comments (0 inline, 0 general)
npf.c
Show inline comments
 
@@ -61,25 +61,25 @@ bool IsEndOfLine(TileIndex tile, Trackdi
 
		if (IsTileDepotType(dst_tile, TRANSPORT_RAIL) && (exitdir != ReverseDiagdir(GetDepotDirection(dst_tile, TRANSPORT_RAIL))))
 
			return true;
 

	
 
		/* Check for oneway signal against us */
 
		if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TYPE_SIGNALS) {
 
			if (HasSignalOnTrackdir(dst_tile, ReverseTrackdir(FindFirstBit2x64(ts))) && !HasSignalOnTrackdir(dst_tile, FindFirstBit2x64(ts)))
 
				// if one way signal not pointing towards us, stop going in this direction.
 
				return true;
 
		}
 

	
 
		return false;
 
	}
 
};
 
}
 

	
 
#if 0
 
static uint NTPHash(uint key1, uint key2)
 
{
 
	/* This function uses the old hash, which is fixed on 10 bits (1024 buckets) */
 
	return PATHFIND_HASH_TILE(key1);
 
}
 
#endif
 

	
 
/**
 
 * Calculates a hash value for use in the NPF.
 
 * @param key1	The TileIndex of the tile to hash
 
@@ -118,25 +118,25 @@ static TileIndex CalcClosestStationTile(
 
	uint x;
 
	uint y;
 

	
 
	// we are going the aim for the x coordinate of the closest corner
 
	// but if we are between those coordinates, we will aim for our own x coordinate
 
	x = clamp(TileX(tile), minx, maxx);
 

	
 
	// same for y coordinate, see above comment
 
	y = clamp(TileY(tile), miny, maxy);
 

	
 
	// return the tile of our target coordinates
 
	return TileXY(x, y);
 
};
 
}
 

	
 
/* On PBS pathfinding runs, this is called before pathfinding ends (BeforeExit aystar callback), and will
 
 * reserve the appropriate tracks, if needed. */
 
void NPFReservePBSPath(AyStar *as)
 
{
 
	NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path;
 
	bool eol_end = false;
 

	
 
	if (ftd->best_trackdir == 0xFF)
 
		return;
 

	
 
	if (!NPFGetFlag(&ftd->node, NPF_FLAG_PBS_EXIT) && IsEndOfLine(ftd->node.tile, ftd->node.direction, as->user_data[NPF_RAILTYPE]) && !NPFGetFlag(&ftd->node, NPF_FLAG_SEEN_SIGNAL)) {
pbs.c
Show inline comments
 
@@ -31,25 +31,25 @@
 
 * 0xFF are invalid entries and should never be accessed.
 
 */
 
static const byte encrt_to_reserved[16] = {
 
	0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0xFF,
 
	0xFF, 0xFF, 0xFF, 0x0C, 0x0C, 0x30, 0x30, 0xFF
 
};
 

	
 
/**
 
 * maps an encoded reserved track (from map3lo bits 4..7)
 
 * to the track(dir)s that are unavailable due to reservations.
 
 * 0xFFFF are invalid entries and should never be accessed.
 
 */
 
static const int16 encrt_to_unavail[16] = {
 
static const uint16 encrt_to_unavail[16] = {
 
	0x0000, 0x3F3F, 0x3F3F, 0x3737, 0x3B3B, 0x1F1F, 0x2F2F, 0xFFFF,
 
	0xFFFF, 0xFFFF, 0xFFFF, 0x3F3F, 0x3F3F, 0x3F3F, 0x3F3F, 0xFFFF
 
};
 

	
 
void PBSReserveTrack(TileIndex tile, Track track) {
 
	assert(IsValidTile(tile));
 
	assert(track <= 5);
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				SETBIT(_m[tile].m3, 6);
 
@@ -70,91 +70,91 @@ void PBSReserveTrack(TileIndex tile, Tra
 
			_m[tile].m4 |= (1 << track) & 3;
 
			break;
 
		case MP_STATION:
 
			SETBIT(_m[tile].m3, 6);
 
			break;
 
		case MP_STREET:
 
			// make sure it is a railroad crossing
 
			if (!IsLevelCrossing(tile)) return;
 
			SETBIT(_m[tile].m5, 0);
 
			break;
 
		default:
 
			return;
 
	};
 
	}
 
	// if debugging, mark tile dirty to show reserved status
 
	if (_debug_pbs_level >= 1)
 
		MarkTileDirtyByTile(tile);
 
}
 

	
 
byte PBSTileReserved(TileIndex tile) {
 
	assert(IsValidTile(tile));
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				// check if its reserved
 
				if (!HASBIT(_m[tile].m3, 6)) return 0;
 
				// return the track for the correct direction
 
				return HASBIT(_m[tile].m5, 0) ? 2 : 1;
 
			} else {
 
				// normal track
 
				byte res = encrt_to_reserved[(_m[tile].m4 & 0xF0) >> 4];
 
				assert(res != 0xFF);
 
				return res;
 
			};
 
			}
 
		case MP_TUNNELBRIDGE:
 
			return (_m[tile].m4 & 3);
 
		case MP_STATION:
 
			// check if its reserved
 
			if (!HASBIT(_m[tile].m3, 6)) return 0;
 
			// return the track for the correct direction
 
			return HASBIT(_m[tile].m5, 0) ? 2 : 1;
 
		case MP_STREET:
 
			// make sure its a railroad crossing
 
			if (!IsLevelCrossing(tile)) return 0;
 
			// check if its reserved
 
			if (!HASBIT(_m[tile].m5, 0)) return 0;
 
			// return the track for the correct direction
 
			return HASBIT(_m[tile].m5, 3) ? 1 : 2;
 
		default:
 
			return 0;
 
	};
 
};
 
	}
 
}
 

	
 
uint16 PBSTileUnavail(TileIndex tile) {
 
	assert(IsValidTile(tile));
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
 
			} else {
 
				// normal track
 
				uint16 res = encrt_to_unavail[(_m[tile].m4 & 0xF0) >> 4];
 
				assert(res != 0xFFFF);
 
				return res;
 
			};
 
			}
 
		case MP_TUNNELBRIDGE:
 
			return (_m[tile].m4 & 3) | ((_m[tile].m4 & 3) << 8);
 
		case MP_STATION:
 
			return HASBIT(_m[tile].m3, 6) ? TRACKDIR_BIT_MASK : 0;
 
		case MP_STREET:
 
			// make sure its a railroad crossing
 
			if (!IsLevelCrossing(tile)) return 0;
 
			// check if its reserved
 
			return (HASBIT(_m[tile].m5, 0)) ? TRACKDIR_BIT_MASK : 0;
 
		default:
 
			return 0;
 
	};
 
};
 
	}
 
}
 

	
 
void PBSClearTrack(TileIndex tile, Track track) {
 
	assert(IsValidTile(tile));
 
	assert(track <= 5);
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
			if ((_m[tile].m5 & ~1) == 0xC4) {
 
				// waypoint
 
				CLRBIT(_m[tile].m3, 6);
 
			} else {
 
				// normal rail track
 
				byte encrt = (_m[tile].m4 & 0xF0) >> 4;
 
@@ -174,82 +174,82 @@ void PBSClearTrack(TileIndex tile, Track
 
			_m[tile].m4 &= ~((1 << track) & 3);
 
			break;
 
		case MP_STATION:
 
			CLRBIT(_m[tile].m3, 6);
 
			break;
 
		case MP_STREET:
 
			// make sure it is a railroad crossing
 
			if (!IsLevelCrossing(tile)) return;
 
			CLRBIT(_m[tile].m5, 0);
 
			break;
 
		default:
 
			return;
 
	};
 
	}
 
	// if debugging, mark tile dirty to show reserved status
 
	if (_debug_pbs_level >= 1)
 
		MarkTileDirtyByTile(tile);
 
};
 
}
 

	
 
void PBSClearPath(TileIndex tile, Trackdir trackdir, TileIndex end_tile, Trackdir end_trackdir) {
 
	uint16 res;
 
	FindLengthOfTunnelResult flotr;
 
	assert(IsValidTile(tile));
 
	assert(IsValidTrackdir(trackdir));
 

	
 
	do {
 
		PBSClearTrack(tile, TrackdirToTrack(trackdir));
 

	
 
		if (tile == end_tile && TrackdirToTrack(trackdir) == TrackdirToTrack(end_trackdir))
 
			return;
 

	
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (unsigned)(_m[tile].m5 & 3) == TrackdirToExitdir(trackdir)) {
 
			// this is a tunnel
 
			flotr = FindLengthOfTunnel(tile, TrackdirToExitdir(trackdir));
 

	
 
			tile = flotr.tile;
 
		} else {
 
			byte exitdir = TrackdirToExitdir(trackdir);
 
			tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(exitdir));
 
		};
 
		}
 

	
 
		res = PBSTileReserved(tile);
 
		res |= res << 8;
 
		res &= TrackdirReachesTrackdirs(trackdir);
 
		trackdir = FindFirstBit2x64(res);
 

	
 
	} while (res != 0);
 
};
 
}
 

	
 
bool PBSIsPbsSignal(TileIndex tile, Trackdir trackdir)
 
{
 
	assert(IsValidTile(tile));
 
	assert(IsValidTrackdir(trackdir));
 

	
 
	if (!_patches.new_pathfinding_all)
 
		return false;
 

	
 
	if (!IsTileType(tile, MP_RAILWAY))
 
		return false;
 

	
 
	if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS)
 
		return false;
 

	
 
	if (!HasSignalOnTrackdir(tile, trackdir))
 
		return false;
 

	
 
	if (GetSignalType(tile, TrackdirToTrack(trackdir)) == 4)
 
		return true;
 
	else
 
		return false;
 
};
 
}
 

	
 
typedef struct SetSignalsDataPbs {
 
	int cur;
 

	
 
	// these are used to keep track of the signals.
 
	byte bit[NUM_SSD_ENTRY];
 
	TileIndex tile[NUM_SSD_ENTRY];
 
} SetSignalsDataPbs;
 

	
 
// This function stores the signals inside the SetSignalsDataPbs struct, passed as callback to FollowTrack() in the PBSIsPbsSegment() function below
 
static bool SetSignalsEnumProcPBS(uint tile, SetSignalsDataPbs *ssd, int trackdir, uint length, byte *state)
 
{
 
@@ -276,16 +276,16 @@ bool PBSIsPbsSegment(uint tile, Trackdir
 
	DiagDirection direction = TrackdirToExitdir(trackdir);//GetDepotDirection(tile,TRANSPORT_RAIL);
 
	int i;
 

	
 
	ssd.cur = 0;
 

	
 
	FollowTrack(tile, 0xC000 | TRANSPORT_RAIL, direction, (TPFEnumProc*)SetSignalsEnumProcPBS, NULL, &ssd);
 
	for(i=0; i!=ssd.cur; i++) {
 
		uint tile = ssd.tile[i];
 
		byte bit = ssd.bit[i];
 
		if (!PBSIsPbsSignal(tile, bit) && !PBSIsPbsSignal(tile, bit | 8))
 
			return false;
 
		result = true;
 
	};
 
	}
 

	
 
	return result;
 
}
train_cmd.c
Show inline comments
 
@@ -1301,25 +1301,25 @@ TileIndex GetVehicleTileOutOfTunnel(cons
 
	byte direction = (!reverse) ? DirToDiagdir(v->direction) : ReverseDiagdir(v->direction >> 1);
 
	TileIndexDiff delta = TileOffsByDir(direction);
 

	
 
	if (v->u.rail.track != 0x40)
 
		return v->tile;
 

	
 
	for (tile = v->tile;; tile += delta) {
 
		if (IsTunnelTile(tile) && (_m[tile].m5 & 0x3) != (direction) && GetTileZ(tile) == v->z_pos)
 
 			break;
 
 	}
 
 	return tile;
 

	
 
};
 
}
 

	
 
static void ReverseTrainDirection(Vehicle *v)
 
{
 
	int l = 0, r = -1;
 
	Vehicle *u;
 
	TileIndex tile;
 
	Trackdir trackdir;
 
	TileIndex pbs_end_tile = v->u.rail.pbs_end_tile; // these may be changed, and we may need
 
	Trackdir pbs_end_trackdir = v->u.rail.pbs_end_trackdir; // the old values, so cache them
 

	
 
	u = GetLastVehicleInChain(v);
 
	tile = GetVehicleTileOutOfTunnel(u, false);
0 comments (0 inline, 0 general)