Changeset - r2839:c302b8fc0717
[Not reviewed]
master
0 1 0
tron - 19 years ago 2006-01-07 16:30:49
tron@openttd.org
(svn r3387) Restructure the code, which places fences along railroad tracks.
This includes no functional changes, just some cleanup before some bugfix
1 file changed with 58 insertions and 29 deletions:
rail_cmd.c
58
29
0 comments (0 inline, 0 general)
rail_cmd.c
Show inline comments
 
@@ -1906,162 +1906,191 @@ static uint GetSlopeZ_Track(const TileIn
 
				// inclined foundation
 
				th = _inclined_tileh[f - 15];
 
			}
 
		} else if ((ti->map5 & 0xC0) == 0xC0) {
 
			// depot or waypoint
 
			return z + 8;
 
		}
 
		return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
 
	}
 
	return z;
 
}
 

	
 
static uint GetSlopeTileh_Track(const TileInfo *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 (f != 0) {
 
				if (f < 15) {
 
					// leveled foundation
 
					return 0;
 
				}
 
				// inclined foundation
 
				return _inclined_tileh[f - 15];
 
			}
 
		} else if ((ti->map5 & 0xC0) == 0xC0) {
 
			// depot or waypoint
 
			return 0;
 
		}
 
	}
 
	return ti->tileh;
 
}
 

	
 
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void AnimateTile_Track(TileIndex tile)
 
{
 
	/* not used */
 
}
 

	
 
static void TileLoop_Track(TileIndex tile)
 
{
 
	byte old_ground;
 
	byte new_ground;
 
	TrackBits rail;
 

	
 
	old_ground = _m[tile].m5 & RAIL_TYPE_SPECIAL ? GB(_m[tile].m4, 0, 4) : GB(_m[tile].m2, 0, 4);
 

	
 
	switch (_opt.landscape) {
 
		case LT_HILLY:
 
			if (GetTileZ(tile) > _opt.snow_line) { /* convert into snow? */
 
				new_ground = RAIL_GROUND_ICE_DESERT;
 
				goto modify_me;
 
			}
 
			break;
 

	
 
		case LT_DESERT:
 
			if (GetMapExtraBits(tile) == 1) { /* convert into desert? */
 
				new_ground = RAIL_GROUND_ICE_DESERT;
 
				goto modify_me;
 
			}
 
			break;
 
	}
 

	
 
	// Don't continue tile loop for depots
 
	if (_m[tile].m5 & RAIL_TYPE_SPECIAL) return;
 

	
 
	new_ground = RAIL_GROUND_GREEN;
 

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

	
 
		if (rail == TRACK_BIT_UPPER) {
 
			new_ground = RAIL_GROUND_FENCE_HORIZ1;
 
		} else if (rail == TRACK_BIT_LOWER) {
 
			new_ground = RAIL_GROUND_FENCE_HORIZ2;
 
		} else if (rail == TRACK_BIT_LEFT) {
 
			new_ground = RAIL_GROUND_FENCE_VERT1;
 
		} else if (rail == TRACK_BIT_RIGHT) {
 
			new_ground = RAIL_GROUND_FENCE_VERT2;
 
		} else {
 
		switch (rail) {
 
			case TRACK_BIT_UPPER: new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
 
			case TRACK_BIT_LOWER: new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
 
			case TRACK_BIT_LEFT:  new_ground = RAIL_GROUND_FENCE_VERT1;  break;
 
			case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2;  break;
 

	
 
			default: {
 
			PlayerID owner = GetTileOwner(tile);
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TileDiffXY(0, -1), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(0, -1), owner) ||
 
						(_m[tile + TileDiffXY(0, -1)].m5 == TRACK_BIT_UPPER || _m[tile + TileDiffXY(0, -1)].m5 == TRACK_BIT_LEFT))
 
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
 
							!(rail & (TRACK_BIT_DIAG2 | TRACK_BIT_UPPER | TRACK_BIT_LEFT)) &&
 
							(rail & TRACK_BIT_DIAG1)
 
						)) {
 
					TileIndex n = tile + TileDiffXY(0, -1);
 

	
 
					if (!IsTileType(n, MP_RAILWAY) ||
 
							!IsTileOwner(n, owner) ||
 
							_m[n].m5 == TRACK_BIT_UPPER ||
 
							_m[n].m5 == TRACK_BIT_LEFT) {
 
							new_ground = RAIL_GROUND_FENCE_NW;
 
			}
 
				}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_LEFT)) {
 
				if (!IsTileType(tile + TileDiffXY(0, 1), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(0, 1), owner) ||
 
						(_m[tile + TileDiffXY(0, 1)].m5 == TRACK_BIT_LOWER || _m[tile + TileDiffXY(0, 1)].m5 == TRACK_BIT_RIGHT))
 
							new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ? RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
 
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_LEFT) || (
 
							!(rail & (TRACK_BIT_DIAG2 | TRACK_BIT_LOWER | TRACK_BIT_RIGHT)) &&
 
							(rail & TRACK_BIT_DIAG1)
 
						)) {
 
					TileIndex n = tile + TileDiffXY(0, 1);
 

	
 
					if (!IsTileType(n, MP_RAILWAY) ||
 
							!IsTileOwner(n, owner) ||
 
							_m[n].m5 == TRACK_BIT_LOWER ||
 
							_m[n].m5 == TRACK_BIT_RIGHT) {
 
						new_ground = (new_ground == RAIL_GROUND_FENCE_NW) ?
 
							RAIL_GROUND_FENCE_SENW : RAIL_GROUND_FENCE_SE;
 
					}
 
			}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_LEFT)) {
 
				if (!IsTileType(tile + TileDiffXY(-1, 0), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(-1, 0), owner) ||
 
						(_m[tile + TileDiffXY(-1, 0)].m5 == TRACK_BIT_UPPER || _m[tile + TileDiffXY(-1, 0)].m5 == TRACK_BIT_RIGHT))
 
				if (rail == (TRACK_BIT_LOWER | TRACK_BIT_LEFT) || (
 
							!(rail & (TRACK_BIT_DIAG1 | TRACK_BIT_UPPER | TRACK_BIT_RIGHT)) &&
 
							(rail & TRACK_BIT_DIAG2)
 
						)) {
 
					TileIndex n = tile + TileDiffXY(-1, 0);
 

	
 
					if (!IsTileType(n, MP_RAILWAY) ||
 
							!IsTileOwner(n, owner) ||
 
							_m[n].m5 == TRACK_BIT_UPPER ||
 
							_m[n].m5 == TRACK_BIT_RIGHT) {
 
							new_ground = RAIL_GROUND_FENCE_NE;
 
			}
 
				}
 

	
 
			if ( (!(rail&(TRACK_BIT_DIAG1|TRACK_BIT_LOWER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG2)) || rail==(TRACK_BIT_UPPER|TRACK_BIT_RIGHT)) {
 
				if (!IsTileType(tile + TileDiffXY(1, 0), MP_RAILWAY) ||
 
						!IsTileOwner(tile + TileDiffXY(1, 0), owner) ||
 
						(_m[tile + TileDiffXY(1, 0)].m5 == TRACK_BIT_LOWER || _m[tile + TileDiffXY(1, 0)].m5 == TRACK_BIT_LEFT))
 
							new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ? RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
 
				if (rail == (TRACK_BIT_UPPER | TRACK_BIT_RIGHT) || (
 
							!(rail & (TRACK_BIT_DIAG1 | TRACK_BIT_LOWER | TRACK_BIT_LEFT)) &&
 
							(rail & TRACK_BIT_DIAG2)
 
						)) {
 
					TileIndex n = tile + TileDiffXY(1, 0);
 

	
 
					if (!IsTileType(n, MP_RAILWAY) ||
 
							!IsTileOwner(n, owner) ||
 
							_m[n].m5 == TRACK_BIT_LOWER ||
 
							_m[n].m5 == TRACK_BIT_LEFT) {
 
						new_ground = (new_ground == RAIL_GROUND_FENCE_NE) ?
 
							RAIL_GROUND_FENCE_NESW : RAIL_GROUND_FENCE_SW;
 
					}
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
modify_me:;
 
	/* tile changed? */
 
	if (old_ground != new_ground) {
 
		if (_m[tile].m5 & RAIL_TYPE_SPECIAL) {
 
			SB(_m[tile].m4, 0, 4, new_ground);
 
		} else {
 
			SB(_m[tile].m2, 0, 4, new_ground);
 
		}
 
		MarkTileDirtyByTile(tile);
 
	}
 
}
 

	
 

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

	
 
	if (mode != TRANSPORT_RAIL) return 0;
 

	
 
	m5 = _m[tile].m5;
 

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

	
 
			a = _m[tile].m3;
 
			b = _m[tile].m2;
 

	
 
			b &= a;
 

	
 
			/* When signals are not present (in neither
 
			 * direction), we pretend them to be green. (So if
 
			 * signals are only one way, the other way will
 
			 * implicitely become `red' */
 
			if ((a & 0xC0) == 0) b |= 0xC0;
 
			if ((a & 0x30) == 0) b |= 0x30;
 

	
0 comments (0 inline, 0 general)