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 64 insertions and 35 deletions:
rail_cmd.c
64
35
0 comments (0 inline, 0 general)
rail_cmd.c
Show inline comments
 
@@ -1942,25 +1942,24 @@ static void GetAcceptedCargo_Track(TileI
 
	/* 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:
 
@@ -1969,63 +1968,93 @@ static void TileLoop_Track(TileIndex til
 
				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;
 

	
 
		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_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 {
 
			PlayerID owner = GetTileOwner(tile);
 
				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 ( (!(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))
 
							new_ground = RAIL_GROUND_FENCE_NW;
 
			}
 
					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_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 ( (!(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 (!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_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 ( (!(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))
 
							new_ground = RAIL_GROUND_FENCE_NE;
 
			}
 
					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);
 
		}
0 comments (0 inline, 0 general)