|
@@ -271,12 +271,13 @@ Vehicle::Vehicle()
|
|
|
{
|
|
|
this->type = VEH_INVALID;
|
|
|
this->left_coord = INVALID_COORD;
|
|
|
this->group_id = DEFAULT_GROUP;
|
|
|
this->fill_percent_te_id = INVALID_TE_ID;
|
|
|
this->first = this;
|
|
|
this->colormap = PAL_NONE;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get a value for a vehicle's random_bits.
|
|
|
* @return A random value from 0 to 255.
|
|
|
*/
|
|
@@ -454,12 +455,18 @@ void ResetVehiclePosHash()
|
|
|
Vehicle *v;
|
|
|
FOR_ALL_VEHICLES(v) { v->old_new_hash = NULL; }
|
|
|
memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash));
|
|
|
memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_hash));
|
|
|
}
|
|
|
|
|
|
void ResetVehicleColorMap()
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
FOR_ALL_VEHICLES(v) { v->colormap = PAL_NONE; }
|
|
|
}
|
|
|
|
|
|
void InitializeVehicles()
|
|
|
{
|
|
|
_Vehicle_pool.CleanPool();
|
|
|
_Vehicle_pool.AddBlockToPool();
|
|
|
|
|
|
ResetVehiclePosHash();
|
|
@@ -2604,36 +2611,45 @@ const Livery *GetEngineLivery(EngineID e
|
|
|
return &p->livery[scheme];
|
|
|
}
|
|
|
|
|
|
|
|
|
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
|
|
|
{
|
|
|
SpriteID map = PAL_NONE;
|
|
|
SpriteID map = (v != NULL) ? v->colormap : PAL_NONE;
|
|
|
|
|
|
/* Return cached value if any */
|
|
|
if (map != PAL_NONE) return map;
|
|
|
|
|
|
/* Check if we should use the colour map callback */
|
|
|
if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_COLOUR_REMAP)) {
|
|
|
uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v);
|
|
|
/* A return value of 0xC000 is stated to "use the default two-color
|
|
|
* maps" which happens to be the failure action too... */
|
|
|
if (callback != CALLBACK_FAILED && callback != 0xC000) {
|
|
|
map = GB(callback, 0, 14);
|
|
|
/* If bit 14 is set, then the company colours are applied to the
|
|
|
* map else it's returned as-is. */
|
|
|
if (!HASBIT(callback, 14)) return map;
|
|
|
if (!HASBIT(callback, 14)) {
|
|
|
/* Update cache */
|
|
|
if (v != NULL) ((Vehicle*)v)->colormap = map;
|
|
|
return map;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool twocc = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC);
|
|
|
|
|
|
if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOR_START;
|
|
|
|
|
|
const Livery *livery = GetEngineLivery(engine_type, player, parent_engine_type, v);
|
|
|
|
|
|
map += livery->colour1;
|
|
|
if (twocc) map += livery->colour2 * 16;
|
|
|
|
|
|
/* Update cache */
|
|
|
if (v != NULL) ((Vehicle*)v)->colormap = map;
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
|
|
|
{
|
|
|
return GetEngineColourMap(engine_type, player, INVALID_ENGINE, NULL);
|