Changeset - r13:dd4e824e4f24
[Not reviewed]
master
0 2 0
dominik - 20 years ago 2004-08-10 18:35:43
dominik@openttd.org
(svn r14) Fix: railroad crossings on slopes are now possible
2 files changed with 42 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rail_cmd.c
Show inline comments
 
@@ -115,13 +115,13 @@ static bool CheckTrackCombination(byte m
 
	} else {
 
		return false;
 
	}
 
}
 

	
 

	
 
static const byte _valid_tileh_slopes[3][15] = {
 
static const byte _valid_tileh_slopes[4][15] = {
 

	
 
// set of normal ones
 
{
 
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 
	RAIL_BIT_RIGHT,
 
	RAIL_BIT_UPPER,
 
@@ -181,12 +181,21 @@ static const byte _valid_tileh_slopes[3]
 
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 

	
 
	RAIL_BIT_DIAG2|RAIL_BIT_RIGHT|RAIL_BIT_UPPER,
 
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 
	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 
	},
 

	
 
	// valid railway crossings on slopes
 
	{
 
		1, 0, 0, // 0, 1, 2
 
		0, 0, 1, // 3, 4, 5
 
		0, 1, 0, // 6, 7, 8
 
		0, 1, 1, // 9, 10, 11
 
		0, 1, 1, // 12, 13, 14
 
	}
 
};
 

	
 
static uint GetRailFoundation(uint tileh, uint bits)
 
{
 
	int i;
 
@@ -272,14 +281,18 @@ int32 CmdBuildSingleRail(int x, int y, u
 
			return CMD_ERROR;
 
		} else
 
			goto need_clear;
 
	} else if (ti.type == MP_STREET) {
 
		byte m5;
 
/* BUILD ON STREET CODE */
 
		if (ti.tileh != 0) goto need_clear;
 
		
 
		if (ti.tileh & 0x10) // very steep tile
 
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		if (!_valid_tileh_slopes[3][ti.tileh]) // prevent certain slopes
 
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		if (!(ti.map5 & 0xF0)) {
 
			if ((ti.map5 & 0x0F) == 0xA) {
 
				if (rail_bit != 2) goto need_clear;
 
				m5 = 0x10;
 
			} else if ((ti.map5 & 0x0F) == 0x5) {
 
				if (rail_bit != 1) goto need_clear;
 
@@ -1649,13 +1662,13 @@ void SetSignalsOnBothDir(uint tile, byte
 
}
 

	
 
uint GetSlopeZ_Track(TileInfo *ti) 
 
{
 
	uint z = ti->z;
 
	int th = ti->tileh;
 
	
 

	
 
	// 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) {
road_cmd.c
Show inline comments
 
@@ -250,13 +250,13 @@ enum {
 
	ROAD_SW = 2, // SW road track
 
	ROAD_SE = 4, // SE road track
 
	ROAD_NE = 8, // NE road track
 
	ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE)
 
};
 
 
 
static const byte _valid_tileh_slopes_road[2][15] = {
 
static const byte _valid_tileh_slopes_road[3][15] = {
 
	// set of normal ones
 
	{
 
		ROAD_ALL, 0, 0,
 
		ROAD_SW | ROAD_NE, 0, 0,  // 3, 4, 5
 
		ROAD_NW | ROAD_SE, 0, 0,
 
		ROAD_NW | ROAD_SE, 0, 0,  // 9, 10, 11
 
@@ -279,12 +279,20 @@ static const byte _valid_tileh_slopes_ro
 
		ROAD_ALL,
 
		ROAD_ALL,
 

	
 
		ROAD_NW | ROAD_SE | ROAD_NE, // 12
 
		ROAD_ALL,
 
		ROAD_ALL
 
	},
 
	// valid railway crossings on slopes
 
	{
 
		1, 0, 0, // 0, 1, 2
 
		0, 0, 1, // 3, 4, 5
 
		0, 1, 0, // 6, 7, 8
 
		0, 1, 1, // 9, 10, 11
 
		0, 1, 1, // 12, 13, 14
 
	}
 
};
 

	
 

	
 
static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)	
 
{
 
@@ -344,14 +352,18 @@ int32 CmdBuildRoad(int x, int y, uint32 
 
				return_cmd_error(STR_1007_ALREADY_BUILT);
 
			goto do_clear;
 
		}
 
	} else if (ti.type == MP_RAILWAY) {
 
		byte m5;
 

	
 
		if (ti.tileh != 0) goto do_clear;
 
		
 
		if (ti.tileh & 0x10) // very steep tile
 
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
 
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		if (ti.map5 == 2) {
 
			if (pieces & 5) goto do_clear;
 
			m5 = 0x10;
 
		} else if (ti.map5 == 1) {
 
			if (pieces & 10) goto do_clear;
 
			m5 = 0x18;
 
@@ -368,13 +380,13 @@ int32 CmdBuildRoad(int x, int y, uint32 
 
			);
 
		}
 
		return _price.build_road * 2;
 
	} else if (ti.type == MP_TUNNELBRIDGE) {
 

	
 
		/* check for flat land */
 
		if (ti.tileh & 0x10) //goto do_clear; // very steep tile
 
		if (ti.tileh & 0x10) // very steep tile
 
				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		/* is this middle part of a bridge? */
 
		if ((ti.map5 & 0xC0) != 0xC0)
 
				goto do_clear;
 

	
 
@@ -688,12 +700,16 @@ static uint GetRoadFoundation(uint tileh
 

	
 
	// inclined sloped building
 
	if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) && 
 
		((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE))))
 
		return i + 15;
 

	
 
	// rail crossing
 
	if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh])
 
		return tileh;
 

	
 
	return 0;
 
}
 

	
 
const byte _road_sloped_sprites[14] = {
 
	0,  0,  2,  0,
 
	0,  1,  0,  0,
 
@@ -752,13 +768,16 @@ static void DrawTile_Road(TileInfo *ti)
 
			int y = ti->y | drts->subcoord_y;
 
			byte z = ti->z;
 
			if (ti->tileh != 0)	z = GetSlopeZ(x, y);
 
			AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
 
			drts++;
 
		}
 
	} else if ( (ti->map5 & 0xE0) == 0) {
 
	} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing
 
		int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
 
		if (f) DrawFoundation(ti, f);
 

	
 
		image = 0x55B;
 

	
 
		if ( (ti->map5 & 8) != 0)
 
			image--;
 

	
 
		if ( (ti->map5 & 4) != 0)
 
@@ -833,13 +852,13 @@ uint GetSlopeZ_Road(TileInfo *ti)
 
{
 
	uint z = ti->z;
 
	int th = ti->tileh;
 

	
 
	// check if it's a foundation
 
	if (ti->tileh != 0) {
 
		if ((ti->map5 & 0xF0) == 0) {
 
		if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
 
			uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
 
			if (f != 0) {
 
				if (f < 15) {
 
					// leveled foundation
 
					return z + 8;
 
				}
0 comments (0 inline, 0 general)