summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2006-03-24 18:16:39 +0000
committerbelugas <belugas@openttd.org>2006-03-24 18:16:39 +0000
commit26a5b628656eb0fb134553d14c6c884bc53eacf4 (patch)
tree0b28a6b60c9227ace9353683266a32927594287b
parent74853e619a34f481d141b586a5b2c94fe474b5a0 (diff)
downloadopenttd-26a5b628656eb0fb134553d14c6c884bc53eacf4.tar.xz
(svn r4092) CodeChange : Named sprites instead of magic numbers plus create/use helper macro/enum for recoloring scheme
-rw-r--r--industry_cmd.c2
-rw-r--r--macros.h3
-rw-r--r--main_gui.c2
-rw-r--r--player_gui.c16
-rw-r--r--players.c8
-rw-r--r--smallmap_gui.c2
-rw-r--r--table/sprites.h11
-rw-r--r--vehicle.c2
8 files changed, 27 insertions, 19 deletions
diff --git a/industry_cmd.c b/industry_cmd.c
index 36aa24332..59c230104 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -352,7 +352,7 @@ static void DrawTile_Industry(TileInfo *ti)
/* 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)];
diff --git a/macros.h b/macros.h
index 7371d13fa..8f1064a0d 100644
--- a/macros.h
+++ b/macros.h
@@ -67,7 +67,8 @@ static inline int64 BIGMULS(int32 a, int32 b) {
#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];
diff --git a/main_gui.c b/main_gui.c
index afdbbff7d..2c554d507 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -2404,7 +2404,7 @@ void SetupColorsAndInitialWindow(void)
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);
diff --git a/player_gui.c b/player_gui.c
index d86e4871f..8a7aa7121 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -271,7 +271,7 @@ static void SelectPlayerColorWndProc(Window *w, WindowEvent *e)
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;
@@ -541,8 +541,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
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);
@@ -726,11 +726,11 @@ static void BuyCompanyWndProc(Window *w, WindowEvent *e)
}
static const Widget _buy_company_widgets[] = {
-{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 5, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 333, 14, 136, 0x0, STR_NULL},
-{ WWT_TEXTBTN, RESIZE_NONE, 5, 148, 207, 117, 128, STR_00C9_NO, STR_NULL},
-{ WWT_TEXTBTN, RESIZE_NONE, 5, 218, 277, 117, 128, STR_00C8_YES, STR_NULL},
+{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, RESIZE_NONE, 5, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 333, 14, 136, 0x0, STR_NULL},
+{ WWT_TEXTBTN, RESIZE_NONE, 5, 148, 207, 117, 128, STR_00C9_NO, STR_NULL},
+{ WWT_TEXTBTN, RESIZE_NONE, 5, 218, 277, 117, 128, STR_00C8_YES, STR_NULL},
{ WIDGETS_END},
};
diff --git a/players.c b/players.c
index 2a39ed685..45d27f82d 100644
--- a/players.c
+++ b/players.c
@@ -45,7 +45,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
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);
@@ -74,15 +74,15 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
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);
}
}
}
diff --git a/smallmap_gui.c b/smallmap_gui.c
index baa393d7b..4f8ae49a3 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -615,7 +615,7 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
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
}
}
}
diff --git a/table/sprites.h b/table/sprites.h
index 1de54ba40..34fda3f64 100644
--- a/table/sprites.h
+++ b/table/sprites.h
@@ -700,6 +700,9 @@ enum Sprites {
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,
@@ -1133,6 +1136,10 @@ 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.
@@ -1149,8 +1156,8 @@ enum PaletteSprites {
//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),
diff --git a/vehicle.c b/vehicle.c
index 2c7c7aae6..6f8558823 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -2052,7 +2052,7 @@ static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID 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);
}