Changeset - r3267:f0ddcd9d96b3
[Not reviewed]
master
0 10 0
tron - 19 years ago 2006-03-19 12:06:12
tron@openttd.org
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
10 files changed with 66 insertions and 63 deletions:
0 comments (0 inline, 0 general)
clear_cmd.c
Show inline comments
 
@@ -96,7 +96,7 @@ static int TerraformProc(TerraformerStat
 
		return r;
 

	
 
	if (IsTileType(tile, MP_RAILWAY)) {
 
		static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
 
		static const TrackBits _railway_modes[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT };
 
		static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
 
		static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4};
 

	
 
@@ -113,7 +113,7 @@ static int TerraformProc(TerraformerStat
 

	
 
		// If we have a single diagonal track there, the other side of
 
		// tile can be terraformed.
 
		if ((_m[tile].m5 & ~0x40) == _railway_modes[mode]) {
 
		if (IsPlainRailTile(tile) && GetTrackBits(tile) == _railway_modes[mode]) {
 
			if (ts->direction == 1) return 0;
 
			skip_clear = true;
 
		}
pathfind.c
Show inline comments
 
@@ -782,7 +782,7 @@ start_at:
 
			}
 

	
 
			/* Regular rail tile, determine which tracks exist. */
 
			allbits = _m[tile].m5 & TRACK_BIT_MASK;
 
			allbits = GetTrackBits(tile);
 
			/* Which tracks are reachable? */
 
			bits = allbits & DiagdirReachesTracks(direction);
 

	
rail.h
Show inline comments
 
@@ -213,14 +213,6 @@ static inline bool IsPlainRailTile(TileI
 
	return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS;
 
}
 

	
 
/**
 
 * Returns the tracks present on the given plain rail tile (IsPlainRailTile())
 
 */
 
static inline TrackBits GetTrackBits(TileIndex tile)
 
{
 
	assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
 
	return (TrackBits)(_m[tile].m5 & TRACK_BIT_MASK);
 
}
 

	
 
/**
 
 * Returns whether the given track is present on the given tile. Tile must be
rail_cmd.c
Show inline comments
 
@@ -130,7 +130,7 @@ static bool CheckTrackCombination(TileIn
 
}
 

	
 

	
 
static const byte _valid_tileh_slopes[][15] = {
 
static const TrackBits _valid_tileh_slopes[][15] = {
 

	
 
// set of normal ones
 
{
 
@@ -199,7 +199,7 @@ static const byte _valid_tileh_slopes[][
 
	},
 
};
 

	
 
uint GetRailFoundation(uint tileh, uint bits)
 
uint GetRailFoundation(uint tileh, TrackBits bits)
 
{
 
	int i;
 

	
 
@@ -350,8 +350,9 @@ int32 CmdBuildSingleRail(int x, int y, u
 
				break;
 
			}
 

	
 
			if (IsLevelCrossing(tile) && (m5 & 0x08 ? TRACK_X : TRACK_Y) == track)
 
			if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
 
				return_cmd_error(STR_1007_ALREADY_BUILT);
 
			}
 
			/* FALLTHROUGH */
 

	
 
		default:
 
@@ -1341,18 +1342,17 @@ static void DrawTrackBits(TileInfo* ti, 
 

	
 
static void DrawTile_Track(TileInfo *ti)
 
{
 
	byte m5;
 
	const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
 
	PalSpriteID image;
 

	
 
	_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
 

	
 
	m5 = (byte)ti->map5;
 
	if (GetRailTileType(ti->tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
 
		TrackBits rails = GetTrackBits(ti->tile);
 
		bool earth = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_BROWN;
 
		bool snow = (_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT;
 

	
 
		DrawTrackBits(ti, m5 & TRACK_BIT_MASK, earth, snow, false);
 
		DrawTrackBits(ti, rails, earth, snow, false);
 

	
 
		if (_display_opt & DO_FULL_DETAIL) {
 
			_detailed_track_proc[_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK](ti);
 
@@ -1370,21 +1370,21 @@ static void DrawTile_Track(TileInfo *ti)
 
#define ISON_SIGNAL(x) (m23 & (byte)(0x10 << (x)))
 
#define MAYBE_DRAW_SIGNAL(x,y,z) if (HAS_SIGNAL(x)) DrawSignalHelper(ti, ISON_SIGNAL(x), ((y-0x4FB) << 4)|(z))
 

	
 
		if (!(m5 & TRACK_BIT_Y)) {
 
			if (!(m5 & TRACK_BIT_X)) {
 
				if (m5 & TRACK_BIT_LEFT) {
 
		if (!(rails & TRACK_BIT_Y)) {
 
			if (!(rails & TRACK_BIT_X)) {
 
				if (rails & TRACK_BIT_LEFT) {
 
					MAYBE_DRAW_SIGNAL(2, 0x509, 0);
 
					MAYBE_DRAW_SIGNAL(3, 0x507, 1);
 
				}
 
				if (m5 & TRACK_BIT_RIGHT) {
 
				if (rails & TRACK_BIT_RIGHT) {
 
					MAYBE_DRAW_SIGNAL(0, 0x509, 2);
 
					MAYBE_DRAW_SIGNAL(1, 0x507, 3);
 
				}
 
				if (m5 & TRACK_BIT_UPPER) {
 
				if (rails & TRACK_BIT_UPPER) {
 
					MAYBE_DRAW_SIGNAL(3, 0x505, 4);
 
					MAYBE_DRAW_SIGNAL(2, 0x503, 5);
 
				}
 
				if (m5 & TRACK_BIT_LOWER) {
 
				if (rails & TRACK_BIT_LOWER) {
 
					MAYBE_DRAW_SIGNAL(1, 0x505, 6);
 
					MAYBE_DRAW_SIGNAL(0, 0x503, 7);
 
				}
 
@@ -1400,7 +1400,7 @@ static void DrawTile_Track(TileInfo *ti)
 
	} else {
 
		/* draw depots / waypoints */
 
		const DrawTrackSeqStruct *drss;
 
		byte type = m5 & 0x3F; // 0-3: depots, 4-5: waypoints
 
		byte type = ti->map5 & 0x3F; // 0-3: depots, 4-5: waypoints
 

	
 
		if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
 

	
 
@@ -1412,7 +1412,7 @@ static void DrawTile_Track(TileInfo *ti)
 
			if (stat != NULL) {
 
				DrawTileSeqStruct const *seq;
 
				// emulate station tile - open with building
 
				const DrawTileSprites *cust = &stat->renderdata[2 + (m5 & 0x1)];
 
				const DrawTileSprites *cust = &stat->renderdata[2 + (ti->map5 & 0x1)];
 
				uint32 relocation = GetCustomStationRelocation(stat, ComposeWaypointStation(ti->tile), 0);
 

	
 
				/* We don't touch the 0x8000 bit. In all this
 
@@ -1790,8 +1790,10 @@ static uint GetSlopeZ_Track(const TileIn
 

	
 
	// check if it's a foundation
 
	if (ti->tileh != 0) {
 
		if ((ti->map5 & 0x80) == 0) {
 
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
 
		if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
 
			return z + 8;
 
		} else {
 
			uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
 

	
 
			if (f != 0) {
 
				if (f < 15) {
 
@@ -1801,9 +1803,6 @@ static uint GetSlopeZ_Track(const TileIn
 
				// inclined foundation
 
				th = _inclined_tileh[f - 15];
 
			}
 
		} else if ((ti->map5 & RAIL_TILE_TYPE_MASK) == RAIL_TYPE_DEPOT_WAYPOINT) {
 
			// depot or waypoint
 
			return z + 8;
 
		}
 
		return GetPartialZ(ti->x & 0xF, ti->y & 0xF, th) + z;
 
	}
 
@@ -1814,8 +1813,10 @@ static uint GetSlopeTileh_Track(const Ti
 
{
 
	// check if it's a foundation
 
	if (ti->tileh != 0) {
 
		if ((ti->map5 & 0x80) == 0) {
 
			uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
 
		if (GetRailTileType(ti->tile) == RAIL_TYPE_DEPOT_WAYPOINT) {
 
			return 0;
 
		} else {
 
			uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
 
			if (f != 0) {
 
				if (f < 15) {
 
					// leveled foundation
 
@@ -1824,9 +1825,6 @@ static uint GetSlopeTileh_Track(const Ti
 
				// inclined foundation
 
				return _inclined_tileh[f - 15];
 
			}
 
		} else if ((ti->map5 & 0xC0) == 0xC0) {
 
			// depot or waypoint
 
			return 0;
 
		}
 
	}
 
	return ti->tileh;
 
@@ -1876,7 +1874,7 @@ static void TileLoop_Track(TileIndex til
 

	
 
	if (old_ground != RAIL_GROUND_BROWN) { /* wait until bottom is green */
 
		/* determine direction of fence */
 
		TrackBits rail = _m[tile].m5 & TRACK_BIT_MASK;
 
		TrackBits rail = GetTrackBits(tile);
 

	
 
		switch (rail) {
 
			case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
 
@@ -1964,20 +1962,17 @@ modify_me:;
 

	
 
static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
 
{
 
	byte m5, a;
 
	byte a;
 
	uint16 b;
 
	uint32 ret;
 

	
 
	if (mode != TRANSPORT_RAIL) return 0;
 

	
 
	m5 = _m[tile].m5;
 
	if (GetRailTileType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
 
		TrackBits rails = GetTrackBits(tile);
 
		uint32 ret = rails * 0x101;
 

	
 
	if (GetRailTileType(tile) != RAIL_TYPE_DEPOT_WAYPOINT) {
 
		ret = (m5 | (m5 << 8)) & 0x3F3F;
 
		if (GetRailTileType(tile) != RAIL_TYPE_SIGNALS) {
 
			if ( (ret & 0xFF) == 3)
 
			/* Diagonal crossing? */
 
				ret |= 0x40;
 
			if (rails == TRACK_BIT_CROSS) ret |= 0x40;
 
		} else {
 
			/* has_signals */
 

	
 
@@ -1998,13 +1993,14 @@ static uint32 GetTileTrackStatus_Track(T
 
			if ((b & 0x20) == 0) ret |= 0x20080000;
 
			if ((b & 0x10) == 0) ret |= 0x08200000;
 
		}
 
	} else if (m5 & 0x40) {
 
		static const byte _train_spec_tracks[6] = {1,2,1,2,1,2};
 
		m5 = _train_spec_tracks[m5 & 0x3F];
 
		ret = (m5 << 8) + m5;
 
	} else
 
		return 0;
 
	return ret;
 
		return ret;
 
	} else {
 
		if (_m[tile].m5 & 0x40) {
 
			return GetRailWaypointBits(tile) * 0x101;
 
		} else {
 
			return 0;
 
		}
 
	}
 
}
 

	
 
static void ClickTile_Track(TileIndex tile)
rail_map.h
Show inline comments
 
@@ -105,6 +105,11 @@ typedef enum TrackBits {
 
	TRACK_BIT_MASK  = 0x3FU
 
} TrackBits;
 

	
 
static inline TrackBits GetTrackBits(TileIndex tile)
 
{
 
	return (TrackBits)GB(_m[tile].m5, 0, 6);
 
}
 

	
 

	
 
static inline DiagDirection GetRailDepotDirection(TileIndex t)
 
{
road_cmd.c
Show inline comments
 
@@ -1034,7 +1034,7 @@ static uint32 GetTileTrackStatus_Road(Ti
 
	switch (mode) {
 
		case TRANSPORT_RAIL:
 
			if (!IsLevelCrossing(tile)) return 0;
 
			return _m[tile].m5 & 8 ? 0x101 : 0x202;
 
			return GetCrossingRailBits(tile) * 0x101;
 

	
 
		case TRANSPORT_ROAD:
 
			switch (GetRoadType(tile)) {
train_cmd.c
Show inline comments
 
@@ -2652,7 +2652,8 @@ static const DiagDirection _otherside_si
 

	
 
static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
 
{
 
	if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) {
 
	if (IsTileType(tile, MP_RAILWAY) &&
 
			GetRailTileType(tile) == RAIL_TYPE_SIGNALS) {
 
		uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]);
 
		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
 
	}
tunnelbridge_cmd.c
Show inline comments
 
@@ -328,7 +328,8 @@ int32 CmdBuildBridge(int x, int y, uint3
 
				break;
 

	
 
			case MP_RAILWAY:
 
				if (_m[tile].m5 != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
 
				if (GetRailTileType(tile) != RAIL_TYPE_NORMAL ||
 
						GetTrackBits(tile) != (direction == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X)) {
 
					goto not_valid_below;
 
				}
 
				transport_under = TRANSPORT_RAIL;
water_cmd.c
Show inline comments
 
@@ -519,14 +519,21 @@ static void TileLoopWaterHelper(TileInde
 
		// make coast..
 
		switch (GetTileType(target)) {
 
			case MP_RAILWAY: {
 
				uint slope = GetTileSlope(target, NULL);
 
				byte tracks = GB(_m[target].m5, 0, 6);
 
				TrackBits tracks;
 
				uint slope;
 

	
 
				if (!IsPlainRailTile(tile)) break;
 

	
 
				tracks = GetTrackBits(target);
 
				slope = GetTileSlope(target, NULL);
 
				if (!(
 
						(slope == 1 && tracks == 0x20) ||
 
						(slope == 2 && tracks == 0x04) ||
 
						(slope == 4 && tracks == 0x10) ||
 
						(slope == 8 && tracks == 0x08)))
 
							(slope == 1 && tracks == TRACK_BIT_RIGHT) &&
 
							(slope == 2 && tracks == TRACK_BIT_UPPER) &&
 
							(slope == 4 && tracks == TRACK_BIT_LEFT)  &&
 
							(slope == 8 && tracks == TRACK_BIT_LOWER)
 
						)) {
 
					break;
 
				}
 
			}
 
			/* FALLTHROUGH */
 

	
waypoint.c
Show inline comments
 
@@ -182,9 +182,10 @@ int32 CmdBuildTrainWaypoint(int x, int y
 
	/* if custom gfx are used, make sure it is within bounds */
 
	if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR;
 

	
 
	if (!IsTileType(tile, MP_RAILWAY) || (
 
				(axis = AXIS_X, _m[tile].m5 != TRACK_BIT_X) &&
 
				(axis = AXIS_Y, _m[tile].m5 != TRACK_BIT_Y)
 
	if (!IsTileType(tile, MP_RAILWAY) ||
 
			GetRailTileType(tile) != RAIL_TYPE_NORMAL || (
 
				(axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) &&
 
				(axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y)
 
			)) {
 
		return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
 
	}
0 comments (0 inline, 0 general)