diff options
author | frosch <frosch@openttd.org> | 2008-11-22 16:04:11 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2008-11-22 16:04:11 +0000 |
commit | 259a073f0c16dccdace6dced05d955e15de080d9 (patch) | |
tree | 3eae77104f99b355105a041898cd4174c1d8031f /src | |
parent | f0286cb1e57a53b5be8565a325fdd7383cf6fc6f (diff) | |
download | openttd-259a073f0c16dccdace6dced05d955e15de080d9.tar.xz |
(svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
-Fix [FS#2419]: The modifiers were not applied in all cases.
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_commons.h | 43 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 30 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 10 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 14 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 18 | ||||
-rw-r--r-- | src/station_cmd.cpp | 15 |
6 files changed, 73 insertions, 57 deletions
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 80432d0fe..66ed32404 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -7,6 +7,10 @@ #ifndef NEWGRF_COMMONS_H #define NEWGRF_COMMONS_H +#include "core/bitmath_func.hpp" + +#include "table/sprites.h" + /** * Maps an entity id stored on the map to a GRF file. * Entities are objects used ingame (houses, industries, industry tiles) for @@ -96,4 +100,43 @@ uint32 GetTerrainType(TileIndex tile); TileIndex GetNearbyTile(byte parameter, TileIndex tile); uint32 GetNearbyTileInformation(TileIndex tile); +/** + * Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR to a palette entry of a sprite layout entry + * @Note for ground sprites use #GroundSpritePaletteTransform + * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set + * when to use the default palette. + * + * @param image The sprite to draw + * @param pal The palette from the sprite layout + * @param default_pal The default recolour sprite to use (typically company color resp. random industry/house color) + * @return The palette to use + */ +static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal) +{ + if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { + return (pal != 0 ? pal : default_pal); + } else { + return PAL_NONE; + } +} + +/** + * Applies PALETTE_MODIFIER_COLOR to a palette entry of a ground sprite + * @Note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set + * when to use the default palette. + * + * @param image The sprite to draw + * @param pal The palette from the sprite layout + * @param default_pal The default recolour sprite to use (typically company color resp. random industry/house color) + * @return The palette to use + */ +static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal) +{ + if (HasBit(image, PALETTE_MODIFIER_COLOR)) { + return (pal != 0 ? pal : default_pal); + } else { + return PAL_NONE; + } +} + #endif /* NEWGRF_COMMONS_H */ diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 79bb20259..f112936f0 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -426,12 +426,24 @@ static void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte st const DrawTileSprites *dts = group->g.layout.dts; const DrawTileSeqStruct *dtss; + const HouseSpec *hs = GetHouseSpecs(house_id); + SpriteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOR_START; + if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) { + uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile); + if (callback != CALLBACK_FAILED) { + /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ + palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback; + } + } + SpriteID image = dts->ground.sprite; SpriteID pal = dts->ground.pal; if (IS_CUSTOM_SPRITE(image)) image += stage; - if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); + if (GB(image, 0, SPRITE_WIDTH) != 0) { + DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette)); + } foreach_draw_tile_seq(dtss, dts->seq) { if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue; @@ -444,21 +456,7 @@ static void DrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte st if (IS_CUSTOM_SPRITE(image)) image += stage; - if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { - if (pal == 0) { - const HouseSpec *hs = GetHouseSpecs(house_id); - pal = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOR_START; - if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) { - uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile); - if (callback != CALLBACK_FAILED) { - /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ - pal = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback; - } - } - } - } else { - pal = PAL_NONE; - } + pal = SpriteLayoutPaletteTransform(image, pal, palette); if ((byte)dtss->delta_z != 0x80) { AddSortableSpriteToDraw( diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index bab9977f7..97706038c 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -183,7 +183,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) { DrawWaterClassGround(ti); } else { - DrawGroundSprite(image, pal); + DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, GENERAL_SPRITE_COLOR(rnd_color))); } } @@ -198,13 +198,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, if (IS_CUSTOM_SPRITE(image)) image += stage; - if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { - if (pal == 0) { - pal = GENERAL_SPRITE_COLOR(rnd_color); - } - } else { - pal = PAL_NONE; - } + pal = SpriteLayoutPaletteTransform(image, pal, GENERAL_SPRITE_COLOR(rnd_color)); if ((byte)dtss->delta_z != 0x80) { AddSortableSpriteToDraw( diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 3438a87ca..3556e2185 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -803,6 +803,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID } image = sprites->ground.sprite; + SpriteID pal = sprites->ground.pal; if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE); image += rti->custom_ground_offset; @@ -810,7 +811,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID image += rti->total_offset; } - DrawSprite(image, PAL_NONE, x, y); + DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y); Point child_offset = {0, 0}; @@ -822,16 +823,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID image += relocation; } - SpriteID pal; - if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { - if (seq->image.pal > 0) { - pal = seq->image.pal; - } else { - pal = palette; - } - } else { - pal = PAL_NONE; - } + pal = SpriteLayoutPaletteTransform(image, seq->image.pal, palette); if ((byte)seq->delta_z != 0x80) { Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index bf5dee271..cbe1e65ef 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -30,6 +30,7 @@ #include "newgrf_engine.h" #include "newgrf_callbacks.h" #include "newgrf_station.h" +#include "newgrf_commons.h" #include "train.h" #include "variables.h" #include "autoslope.h" @@ -1920,6 +1921,7 @@ static void DrawTile_Track(TileInfo *ti) const DrawTileSprites* dts; const DrawTileSeqStruct* dtss; uint32 relocation; + SpriteID pal = PAL_NONE; if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); @@ -1976,6 +1978,8 @@ static void DrawTile_Track(TileInfo *ti) } else { image += rti->total_offset; } + + pal = dts->ground.pal; } else { goto default_waypoint; } @@ -1989,7 +1993,7 @@ default_waypoint: } } - DrawGroundSprite(image, PAL_NONE); + DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, _drawtile_track_palette)); /* PBS debugging, draw reserved tracks darker */ if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && GetDepotWaypointReservation(ti->tile) && @@ -2001,7 +2005,7 @@ default_waypoint: foreach_draw_tile_seq(dtss, dts->seq) { SpriteID image = dtss->image.sprite; - SpriteID pal; + SpriteID pal = dtss->image.pal; /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ if (IsInvisibilitySet(TO_BUILDINGS) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; @@ -2015,15 +2019,7 @@ default_waypoint: image += relocation; } - if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { - if (dtss->image.pal != 0) { - pal = dtss->image.pal; - } else { - pal = _drawtile_track_palette; - } - } else { - pal = PAL_NONE; - } + pal = SpriteLayoutPaletteTransform(image, pal, _drawtile_track_palette); if ((byte)dtss->delta_z != 0x80) { AddSortableSpriteToDraw( diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 13b0bd8a2..b5a33136d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -24,6 +24,7 @@ #include "industry_map.h" #include "newgrf_callbacks.h" #include "newgrf_station.h" +#include "newgrf_commons.h" #include "yapf/yapf.h" #include "road_type.h" #include "road_internal.h" /* For drawing catenary/checking road removal */ @@ -2325,13 +2326,14 @@ static void DrawTile_Station(TileInfo *ti) } } else { SpriteID image = t->ground.sprite; + SpriteID pal = t->ground.pal; if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { image += GetCustomStationGroundRelocation(statspec, st, ti->tile); image += custom_ground_offset; } else { image += total_offset; } - DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE); + DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette)); /* PBS debugging, draw reserved tracks darker */ if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && IsRailwayStation(ti->tile) && GetRailwayStationReservation(ti->tile)) { @@ -2361,16 +2363,7 @@ static void DrawTile_Station(TileInfo *ti) image += relocation; } - SpriteID pal; - if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) { - if (dtss->image.pal > 0) { - pal = dtss->image.pal; - } else { - pal = palette; - } - } else { - pal = PAL_NONE; - } + SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, palette); if ((byte)dtss->delta_z != 0x80) { AddSortableSpriteToDraw( |