Changeset - r3326:d3b33ffce47d
[Not reviewed]
master
0 8 0
belugas - 18 years ago 2006-03-24 18:16:39
belugas@openttd.org
(svn r4092) CodeChange : Named sprites instead of magic numbers plus create/use helper macro/enum for recoloring scheme
8 files changed with 22 insertions and 14 deletions:
0 comments (0 inline, 0 general)
industry_cmd.c
Show inline comments
 
@@ -349,13 +349,13 @@ static void DrawTile_Industry(TileInfo *
 
	const DrawIndustryTileStruct *dits;
 
	byte z;
 
	uint32 image, ormod;
 

	
 
	/* Pointer to industry */
 
	ind = GetIndustryByTile(ti->tile);
 
	ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START;
 
	ormod = GENERAL_SPRITE_COLOR(ind->color_map);
 

	
 
	/* Retrieve pointer to the draw industry tile struct */
 
	dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
 

	
 
	image = dits->sprite_1;
 
	if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
macros.h
Show inline comments
 
@@ -64,13 +64,14 @@ static inline int64 BIGMULS(int32 a, int
 

	
 
// checking more bits. Maybe unneccessary, but easy to use
 
#define HASBITS(x,y) ((x) & (y))
 
#define SETBITS(x,y) ((x) |= (y))
 
#define CLRBITS(x,y) ((x) &= ~(y))
 

	
 
#define PLAYER_SPRITE_COLOR(owner) ( (_player_colors[owner] + 0x307) << PALETTE_SPRITE_START)
 
#define GENERAL_SPRITE_COLOR(color) ( (color + PALETTE_RECOLOR_START) << PALETTE_SPRITE_START)
 
#define PLAYER_SPRITE_COLOR(owner) ( GENERAL_SPRITE_COLOR(_player_colors[owner]))
 
#define SPRITE_PALETTE(x) ((x) | PALETTE_MODIFIER_COLOR)
 

	
 
extern const byte _ffb_64[128];
 
/* Returns the position of the first bit that is not zero, counted from the
 
 * left. Ie, 10110100 returns 2, 00000001 returns 0, etc. When x == 0 returns
 
 * 0.
main_gui.c
Show inline comments
 
@@ -2401,13 +2401,13 @@ void SetupColorsAndInitialWindow(void)
 
{
 
	uint i;
 
	Window *w;
 
	int width,height;
 

	
 
	for (i = 0; i != 16; i++) {
 
		const byte* b = GetNonSprite(0x307 + i);
 
		const byte* b = GetNonSprite(PALETTE_RECOLOR_START + i);
 

	
 
		assert(b);
 
		_color_list[i] = *(const ColorList*)(b + 0xC6);
 
	}
 

	
 
	width = _screen.width;
player_gui.c
Show inline comments
 
@@ -268,13 +268,13 @@ static void SelectPlayerColorWndProc(Win
 
		y = 17;
 
		pos = w->vscroll.pos;
 

	
 
		for (i = 0; i != 16; i++) {
 
			if (!(used_colors & 1) && --pos < 0 && pos >= -8) {
 
				DrawString(x + 30, y, STR_00D1_DARK_BLUE + i, 2);
 
				DrawSprite((i << 16) + 0x3078C1A, x + 14, y + 4);
 
				DrawSprite(((GENERAL_SPRITE_COLOR(i) | PALETTE_MODIFIER_COLOR) | SPR_VEH_BUS_SIDE_VIEW), x + 14, y + 4);
 
				y += 14;
 
			}
 
			used_colors >>= 1;
 
		}
 
	} break;
 

	
 
@@ -538,14 +538,14 @@ static void PlayerCompanyWndProc(Window 
 
		SetDParam(0, p->inaugurated_year + 1920);
 
		DrawString(110, 25, STR_7038_INAUGURATED, 0);
 

	
 
		DrawPlayerVehiclesAmount(w->window_number);
 

	
 
		DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
 
		// Draw company-colour bus (0xC19)
 
		DrawSprite(PLAYER_SPRITE_COLOR(p->index) + (0xC19 | PALETTE_MODIFIER_COLOR), 215, 49);
 
		// Draw company-colour bus
 
		DrawSprite(PLAYER_SPRITE_COLOR(p->index) + SPRITE_PALETTE(SPR_VEH_BUS_SW_VIEW), 215, 49);
 

	
 
		DrawPlayerFace(p->face, p->player_color, 2, 16);
 

	
 
		SetDParam(0, p->president_name_1);
 
		SetDParam(1, p->president_name_2);
 
		DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94);
players.c
Show inline comments
 
@@ -42,13 +42,13 @@ void DrawPlayerFace(uint32 face, int col
 
	if ( (int32)face < 0)
 
		flag |= 1;
 
	if ((((((face >> 7) ^ face) >> 7) ^ face) & 0x8080000) == 0x8000000)
 
		flag |= 2;
 

	
 
	/* draw the gradient */
 
	DrawSprite((color + 0x307) << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR | SPR_GRADIENT, x, y);
 
	DrawSprite(GENERAL_SPRITE_COLOR(color) | PALETTE_MODIFIER_COLOR | SPR_GRADIENT, x, y);
 

	
 
	/* draw the cheeks */
 
	DrawSprite(cheeks_table[flag&3], x, y);
 

	
 
	/* draw the chin */
 
	/* FIXME: real code uses -2 in zoomlevel 1 */
 
@@ -71,21 +71,21 @@ void DrawPlayerFace(uint32 face, int col
 
			if (val2 != 6)
 
				high = 0x30D << PALETTE_SPRITE_START;
 
		}
 

	
 
		if (!(flag & 2)) {
 
			if (!(flag & 1)) {
 
				DrawSprite(high+((val1 * 12 >> 4) + (0x32B | PALETTE_MODIFIER_COLOR)), x, y);
 
				DrawSprite(high+((val1 * 12 >> 4) + SPRITE_PALETTE(0x32B)), x, y);
 
			} else {
 
				DrawSprite(high+(val1 + (0x337 | PALETTE_MODIFIER_COLOR)), x, y);
 
			}
 
		} else {
 
			if (!(flag & 1)) {
 
				DrawSprite(high+((val1 * 11 >> 4) + (0x39A | PALETTE_MODIFIER_COLOR)), x, y);
 
				DrawSprite(high+(val1 + SPRITE_PALETTE(0x337)), x, y);
 
			} else {
 
				DrawSprite(high+(val1 + (0x3B8 | PALETTE_MODIFIER_COLOR)), x, y);
 
				DrawSprite(high+(val1 + SPRITE_PALETTE(0x3B8)), x, y);
 
			}
 
		}
 
	}
 

	
 
	/* draw the mouth */
 
	{
smallmap_gui.c
Show inline comments
 
@@ -612,13 +612,13 @@ static void DrawSmallMap(DrawPixelInfo *
 
		_owner_colors[OWNER_SPECTATOR] = MKCOLOR(0x20202020); /* industry */
 

	
 
		/* now fill with the player colors */
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active) {
 
				_owner_colors[p->index] =
 
					dup_byte32(GetNonSprite(775 + p->player_color)[0xCB]); // XXX - magic pixel
 
					dup_byte32(GetNonSprite(PALETTE_RECOLOR_START + p->player_color)[0xCB]); // XXX - magic pixel
 
			}
 
		}
 
	}
 

	
 
	tile_x = WP(w,smallmap_d).scroll_x / 16;
 
	tile_y = WP(w,smallmap_d).scroll_y / 16;
table/sprites.h
Show inline comments
 
@@ -697,12 +697,15 @@ enum Sprites {
 

	
 

	
 
	/* Vehicle sprite-flags (red/green) */
 
	SPR_FLAG_VEH_STOPPED  = 3090,
 
	SPR_FLAG_VEH_RUNNING  = 3091,
 

	
 
	SPR_VEH_BUS_SW_VIEW   = 3097,
 
	SPR_VEH_BUS_SIDE_VIEW = 3098,
 

	
 
	/* Rotor sprite numbers */
 
	SPR_ROTOR_STOPPED   = 3901,
 
	SPR_ROTOR_MOVING_1  = 3902,
 
	SPR_ROTOR_MOVING_3  = 3904,
 

	
 
	/* Town/house sprites */
 
@@ -1130,12 +1133,16 @@ assert_compile( (1 << RECOLOR_BIT & SPRI
 
assert_compile( TRANSPARENT_BIT != RECOLOR_BIT );
 
assert_compile( (1 << TRANSPARENT_BIT & PALETTE_SPRITE_MASK) == 0);
 
assert_compile( (1 << RECOLOR_BIT & PALETTE_SPRITE_MASK) == 0 );
 
assert_compile( (PALETTE_SPRITE_MASK & SPRITE_MASK) == 0 );
 
assert_compile( SPRITE_WIDTH + PALETTE_SPRITE_WIDTH <= 30 );
 

	
 
enum Recoloring {
 
	PALETTE_RECOLOR_START       = 0x307,
 
};
 

	
 
#define PALETTE_RECOLOR_SPRITE(a) (a << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR)
 
enum PaletteSprites {
 
	//note: these numbers are already the modified once the renderer needs.
 
	//the actual sprite number is the upper 16 bits of the number
 

	
 
	///Here a puslating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible
 
@@ -1146,14 +1153,14 @@ enum PaletteSprites {
 
	PALETTE_SEL_TILE_BLUE       = PALETTE_RECOLOR_SPRITE(0x305),
 
	//0x306 is a real sprite (the little dot you get when you try to raise/lower a corner of the map
 
	//here the color switches begin
 
	//use this if you add stuff to the value, so that the resulting color
 
	//is not a fixed value.
 
	//NOTE THAT THE SWITCH 0x8000 is NOT present in _TO_COLORS yet!
 
	PALETTE_TO_COLORS           = 0x307 << PALETTE_SPRITE_START,
 
	PALETTE_TO_DARK_BLUE        = PALETTE_RECOLOR_SPRITE(0x307),
 
	PALETTE_TO_COLORS           = PALETTE_RECOLOR_START << PALETTE_SPRITE_START,
 
	PALETTE_TO_DARK_BLUE        = PALETTE_RECOLOR_SPRITE(PALETTE_RECOLOR_START),
 
	PALETTE_TO_PALE_GREEN       = PALETTE_RECOLOR_SPRITE(0x308),
 
	PALETTE_TO_PINK             = PALETTE_RECOLOR_SPRITE(0x309),
 
	PALETTE_TO_YELLOW           = PALETTE_RECOLOR_SPRITE(0x30A),
 
	PALETTE_TO_RED              = PALETTE_RECOLOR_SPRITE(0x30B),
 
	PALETTE_TO_LIGHT_BLUE       = PALETTE_RECOLOR_SPRITE(0x30C),
 
	PALETTE_TO_GREEN            = PALETTE_RECOLOR_SPRITE(0x30D),
vehicle.c
Show inline comments
 
@@ -2049,13 +2049,13 @@ static PalSpriteID GetEngineColourMap(En
 
{
 
	SpriteID map;
 
	byte colour = _player_colors[player];
 

	
 
	/* XXX Magic 0x307 is the first company colour remap sprite */
 
	map = HASBIT(_engine_info[engine_type].misc_flags, EF_USES_2CC) ?
 
		(SPR_2CCMAP_BASE + colour + colour * 16) : (0x307 + colour);
 
		(SPR_2CCMAP_BASE + colour + colour * 16) : (PALETTE_RECOLOR_START + colour);
 

	
 
	return SPRITE_PALETTE(map << PALETTE_SPRITE_START);
 
}
 

	
 
PalSpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
 
{
0 comments (0 inline, 0 general)