(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
authorpeter1138
Wed, 01 Mar 2006 23:14:03 +0000
changeset 3113 c0f312f22238
parent 3112 05a599216d83
child 3114 b5576f77693d
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
data/2ccmap.grf
engine.h
gfxinit.c
table/sprites.h
vehicle.c
Binary file data/2ccmap.grf has changed
--- a/engine.h	Wed Mar 01 21:15:25 2006 +0000
+++ b/engine.h	Wed Mar 01 23:14:03 2006 +0000
@@ -98,6 +98,15 @@
 	byte type;				// type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h
 } Engine;
 
+/**
+ * EngineInfo.misc_flags is a bitmask, with the following values
+ */
+enum {
+	EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves (unsupported)
+	EF_ROAD_TRAM  = 0, ///< Road vehicle is a tram/light rail vehicle (unsup)
+	EF_USES_2CC   = 1, ///< Vehicle uses two company colours
+	EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
+};
 
 enum {
 	RVI_MULTIHEAD = 1,
--- a/gfxinit.c	Wed Mar 01 21:15:25 2006 +0000
+++ b/gfxinit.c	Wed Mar 01 23:14:03 2006 +0000
@@ -352,6 +352,9 @@
 	load_index = SPR_AUTORAIL_BASE;
 	load_index += LoadGrfFile("autorail.grf", load_index, i++);
 
+	assert(load_index == SPR_2CCMAP_BASE);
+	load_index += LoadGrfFile("2ccmap.grf", load_index, i++);
+
 	assert(load_index == SPR_OPENTTD_BASE);
 	LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
 	load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT;
--- a/table/sprites.h	Wed Mar 01 21:15:25 2006 +0000
+++ b/table/sprites.h	Wed Mar 01 23:14:03 2006 +0000
@@ -51,7 +51,8 @@
 	SPR_CANALS_BASE   = 5382,
 	SPR_SLOPES_BASE   = SPR_CANALS_BASE + 70,
 	SPR_AUTORAIL_BASE = SPR_SLOPES_BASE + 78,
-	SPR_OPENTTD_BASE  = SPR_AUTORAIL_BASE + 55,
+	SPR_2CCMAP_BASE   = SPR_AUTORAIL_BASE + 55,
+	SPR_OPENTTD_BASE  = SPR_2CCMAP_BASE + 256,
 
 	SPR_BLOT = SPR_OPENTTD_BASE + 29, // colored circle (mainly used as vehicle profit marker and for sever compatibility)
 
@@ -1071,7 +1072,7 @@
 	TRANSPARENT_BIT = 31,       ///< toggles transparency in the sprite
 	RECOLOR_BIT = 15,           ///< toggles recoloring in the sprite
 	PALETTE_SPRITE_START = 16,  ///< number of the first bit of the sprite containing the recolor palette
-	PALETTE_SPRITE_WIDTH = 11,  ///< number of bits of the sprite containing the recolor palette
+	PALETTE_SPRITE_WIDTH = 14,  ///< number of bits of the sprite containing the recolor palette
 	SPRITE_WIDTH = 14,          ///< number of bits for the sprite number
 };
 
--- a/vehicle.c	Wed Mar 01 21:15:25 2006 +0000
+++ b/vehicle.c	Wed Mar 01 23:14:03 2006 +0000
@@ -2040,20 +2040,26 @@
 	return unit;
 }
 
-// XXX Temporary stub -- will be expanded
-static PalSpriteID GetEngineColourMap(PlayerID player)
+static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player)
 {
-	return SPRITE_PALETTE(PLAYER_SPRITE_COLOR(player));
+	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);
+
+	return SPRITE_PALETTE(map << PALETTE_SPRITE_START);
 }
 
 PalSpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
 {
-	return GetEngineColourMap(player);
+	return GetEngineColourMap(engine_type, player);
 }
 
 PalSpriteID GetVehiclePalette(const Vehicle *v)
 {
-	return GetEngineColourMap(v->owner);
+	return GetEngineColourMap(v->engine_type, v->owner);
 }
 
 // Save and load of vehicles