Changeset - r1516:acf7eed0d4af
[Not reviewed]
master
0 1 0
tron - 19 years ago 2005-03-17 16:31:18
tron@openttd.org
(svn r2020) Reduce code duplication in the minimap code a bit
1 file changed with 16 insertions and 58 deletions:
0 comments (0 inline, 0 general)
smallmap_gui.c
Show inline comments
 
@@ -302,28 +302,35 @@ static const AndOr _smallmap_vegetation_
 
	{MKCOLOR(0xB5B5B5B5),MKCOLOR(0x00000000)},
 
	{MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)},
 
	{MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)},
 
	{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
 
};
 

	
 
static inline uint32 GetSmallMapContoursPixels(TileIndex tile)
 

	
 
static inline TileType GetEffectiveTileType(TileIndex tile)
 
{
 
	uint t;
 
	TileType t = GetTileType(tile);
 

	
 
	t = GetTileType(tile);
 
	if (t == MP_TUNNELBRIDGE) {
 
		t = _map5[tile];
 
		if ((t & 0x80) == 0) t>>=1;
 
		if ((t & 0x80) == 0) t >>= 1;
 
		if ((t & 6) == 0) {
 
			t = MP_RAILWAY;
 
		} else if ((t & 6) == 2) {
 
			t = MP_STREET;
 
		} else {
 
			t = MP_WATER;
 
		}
 
	}
 
	return t;
 
}
 

	
 

	
 
static inline uint32 GetSmallMapContoursPixels(TileIndex tile)
 
{
 
	TileType t = GetEffectiveTileType(tile);
 

	
 
	return
 
		ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]);
 
}
 

	
 
static void DrawSmallMapContours(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 
@@ -335,26 +342,14 @@ static void DrawSmallMapContours(byte *d
 
	} while (xc++,yc++,dst+=pitch,--reps != 0);
 
}
 

	
 

	
 
static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile)
 
{
 
	uint t;
 
	TileType t = GetEffectiveTileType(tile);
 

	
 
	t = GetTileType(tile);
 
	if (t == MP_TUNNELBRIDGE) {
 
		t = _map5[tile];
 
		if ((t & 0x80) == 0) t>>=1;
 
		if ((t & 6) == 0) {
 
			t = MP_RAILWAY;
 
		} else if ((t & 6) == 2) {
 
			t = MP_STREET;
 
		} else {
 
			t = MP_WATER;
 
		}
 
	}
 
	return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 
}
 

	
 

	
 
static void DrawSmallMapVehicles(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 
{
 
@@ -388,30 +383,18 @@ static const byte _industry_smallmap_col
 
	152,152,152,152,194,194,194, 15,
 
	 15, 15, 15, 15, 15, 15, 15,
 
};
 

	
 
static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile)
 
{
 
	int t;
 
	TileType t = GetEffectiveTileType(tile);
 

	
 
	t = GetTileType(tile);
 
	if (t == MP_INDUSTRY) {
 
		byte color = _industry_smallmap_colors[_map5[tile]];
 
		return color + (color << 8) + (color << 16) + (color << 24);
 
	} else {
 
		if (t == MP_TUNNELBRIDGE) {
 
			t = _map5[tile];
 
			if ((t & 0x80) == 0) t>>=1;
 
			if ((t & 6) == 0) {
 
				t = MP_RAILWAY;
 
			} else if ((t & 6) == 2) {
 
				t = MP_STREET;
 
			} else {
 
				t = MP_WATER;
 
			}
 
		}
 
		return ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 
	}
 
}
 

	
 
static void DrawSmallMapIndustries(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask)
 
{
 
@@ -420,37 +403,25 @@ static void DrawSmallMapIndustries(byte 
 
			WRITE_PIXELS_OR(dst, GetSmallMapIndustriesPixels(TILE_XY(xc,yc)) & mask);
 
	} while (xc++,yc++,dst+=pitch,--reps != 0);
 
}
 

	
 
static inline uint32 GetSmallMapRoutesPixels(TileIndex tile)
 
{
 
	int t;
 
	TileType t = GetEffectiveTileType(tile);
 
	uint32 bits;
 

	
 
	t = GetTileType(tile);
 
	if (t == MP_STATION) {
 
		byte m5 = _map5[tile];
 
		(bits = MKCOLOR(0x56565656), m5 < 8) ||			//   8 - railroad station (green)
 
		(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x43) ||	//  67 - airport (red)
 
		(bits = MKCOLOR(0xC2C2C2C2), m5 < 0x47) ||	//  71 - truck loading bay (orange)
 
		(bits = MKCOLOR(0xBFBFBFBF), m5 < 0x4B) ||	//  75 - bus station (yellow)
 
		(bits = MKCOLOR(0x98989898), m5 < 0x53) ||	//  83 - docks (blue)
 
		(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x73) ||	// 115 - airport (red) (new airports)
 
		(bits = MKCOLOR(0xFFFFFFFF), true);					// all others
 
	} else {
 
		if (t == MP_TUNNELBRIDGE) {
 
			t = _map5[tile];
 
			if ((t & 0x80) == 0) t>>=1;
 
			if ((t & 6) == 0) {
 
				t = MP_RAILWAY;
 
			} else if ((t & 6) == 2) {
 
				t = MP_STREET;
 
			} else {
 
				t = MP_WATER;
 
			}
 
		}
 
		// ground color
 
		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
 
	}
 
	return bits;
 
}
 

	
 
@@ -476,17 +447,16 @@ static const uint32 _vegetation_clear_bi
 
	MKCOLOR(0x54545454),
 
	MKCOLOR(0x54545454),
 
};
 

	
 
static inline uint32 GetSmallMapVegetationPixels(TileIndex tile)
 
{
 
	TileType t = GetEffectiveTileType(tile);
 
	int i;
 
	TileType t;
 
	uint32 bits;
 

	
 
	t = GetTileType(tile);
 
	switch (t) {
 
		case MP_CLEAR:
 
			i = (_map5[tile] & 0x1F) - 4;
 
			if (i >= 0) i >>= 2;
 
			bits = _vegetation_clear_bits[i + 4];
 
			break;
 
@@ -500,23 +470,12 @@ static inline uint32 GetSmallMapVegetati
 
				bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2);
 
			else
 
				bits = MKCOLOR(0x54575754);
 
			break;
 

	
 
		default:
 
			if (t == MP_TUNNELBRIDGE) {
 
				t = _map5[tile];
 
				if ((t & 0x80) == 0) t>>=1;
 
				if ((t & 6) == 0) {
 
					t = MP_RAILWAY;
 
				} else if ((t & 6) == 2) {
 
					t = MP_STREET;
 
				} else {
 
					t = MP_WATER;
 
				}
 
			}
 
			bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_vehicles_andor[t]);
 
			break;
 
	}
 

	
 
	return bits;
 
}
 
@@ -532,15 +491,14 @@ static void DrawSmallMapVegetation(byte 
 

	
 

	
 
static uint32 _owner_colors[256];
 

	
 
static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
 
{
 
	int t;
 
	TileType t = GetTileType(tile);
 

	
 
	t = GetTileType(tile);
 
	if (t == MP_HOUSE || _map_owner[tile] == OWNER_TOWN) {
 
		t = 0x80;
 
	} else if (t == MP_INDUSTRY) {
 
		t = 0xff;
 
	} else {
 
		t = _map_owner[tile];
0 comments (0 inline, 0 general)