diff options
author | peter1138 <peter1138@openttd.org> | 2007-04-20 21:21:47 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-04-20 21:21:47 +0000 |
commit | 15bfaba2594484536b8843edd9c2d1dbb3d30283 (patch) | |
tree | 774cf9c0bc8edefa4aa277e6b907603dbea345f6 /src/vehicle.cpp | |
parent | a4b3066433f2128e27d85d8df54f28a727287c21 (diff) | |
download | openttd-15bfaba2594484536b8843edd9c2d1dbb3d30283.tar.xz |
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index d4cdcd083..384590e64 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2467,26 +2467,13 @@ UnitID GetFreeUnitNumber(byte type) return unit; } -static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) + +const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) { - SpriteID map = PAL_NONE; const Player *p = GetPlayer(player); LiveryScheme scheme = LS_DEFAULT; CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; - /* Check if we should use the colour map callback */ - if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_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; - } - } - /* The default livery is always available for use, but its in_use flag determines * whether any _other_ liveries are in use. */ if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) { @@ -2563,12 +2550,35 @@ static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, Engine if (!p->livery[scheme].in_use) scheme = LS_DEFAULT; } + return &p->livery[scheme]; +} + + +static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) +{ + SpriteID map = PAL_NONE; + + /* Check if we should use the colour map callback */ + if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_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; + } + } + 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; - map += p->livery[scheme].colour1; - if (twocc) map += p->livery[scheme].colour2 * 16; + const Livery *livery = GetEngineLivery(engine_type, player, parent_engine_type, v); + + map += livery->colour1; + if (twocc) map += livery->colour2 * 16; return map; } |