summaryrefslogtreecommitdiff
path: root/src/newgrf_commons.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-11-22 16:04:11 +0000
committerfrosch <frosch@openttd.org>2008-11-22 16:04:11 +0000
commit259a073f0c16dccdace6dced05d955e15de080d9 (patch)
tree3eae77104f99b355105a041898cd4174c1d8031f /src/newgrf_commons.h
parentf0286cb1e57a53b5be8565a325fdd7383cf6fc6f (diff)
downloadopenttd-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/newgrf_commons.h')
-rw-r--r--src/newgrf_commons.h43
1 files changed, 43 insertions, 0 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 */