2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file sprite.h Base for drawing complex sprites. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2004-11-14 16:45:38 +00:00
|
|
|
#ifndef SPRITE_H
|
|
|
|
#define SPRITE_H
|
|
|
|
|
2010-01-16 22:25:44 +00:00
|
|
|
#include "transparency.h"
|
|
|
|
|
|
|
|
#include "table/sprites.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
#define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
|
|
|
|
#define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
|
2007-12-21 19:21:21 +00:00
|
|
|
|
2004-11-14 16:45:38 +00:00
|
|
|
/* The following describes bunch of sprites to be drawn together in a single 3D
|
|
|
|
* bounding box. Used especially for various multi-sprite buildings (like
|
|
|
|
* depots or stations): */
|
|
|
|
|
2008-10-13 03:26:48 +00:00
|
|
|
/** A tile child sprite and palette to draw for stations etc, with 3D bounding box */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawTileSeqStruct {
|
2024-01-07 16:41:53 +00:00
|
|
|
int8_t delta_x; ///< \c 0x80 is sequence terminator
|
|
|
|
int8_t delta_y;
|
|
|
|
int8_t delta_z; ///< \c 0x80 identifies child sprites
|
2006-08-06 08:23:19 +00:00
|
|
|
byte size_x;
|
|
|
|
byte size_y;
|
|
|
|
byte size_z;
|
2008-02-15 18:34:26 +00:00
|
|
|
PalSpriteID image;
|
2011-02-19 13:16:34 +00:00
|
|
|
|
|
|
|
/** Make this struct a sequence terminator. */
|
|
|
|
void MakeTerminator()
|
|
|
|
{
|
2024-01-07 16:41:53 +00:00
|
|
|
this->delta_x = (int8_t)0x80;
|
2011-02-19 13:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Check whether this is a sequence terminator. */
|
|
|
|
bool IsTerminator() const
|
|
|
|
{
|
|
|
|
return (byte)this->delta_x == 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check whether this is a parent sprite with a boundingbox. */
|
|
|
|
bool IsParentSprite() const
|
|
|
|
{
|
|
|
|
return (byte)this->delta_z != 0x80;
|
|
|
|
}
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-11-14 16:45:38 +00:00
|
|
|
|
2011-05-14 17:25:45 +00:00
|
|
|
/**
|
|
|
|
* Ground palette sprite of a tile, together with its sprite layout.
|
|
|
|
* This struct is used for static sprite layouts in the code.
|
|
|
|
* For allocated ones from NewGRF see #NewGRFSpriteLayout.
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawTileSprites {
|
2008-10-13 03:26:48 +00:00
|
|
|
PalSpriteID ground; ///< Palette and sprite for the ground
|
|
|
|
const DrawTileSeqStruct *seq; ///< Array of child sprites. Terminated with a terminator entry
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-11-14 16:45:38 +00:00
|
|
|
|
2006-04-24 21:10:56 +00:00
|
|
|
/**
|
|
|
|
* This structure is the same for both Industries and Houses.
|
|
|
|
* Buildings here reference a general type of construction
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DrawBuildingsTileStruct {
|
2007-01-14 19:57:49 +00:00
|
|
|
PalSpriteID ground;
|
|
|
|
PalSpriteID building;
|
2007-09-20 19:21:01 +00:00
|
|
|
byte subtile_x;
|
|
|
|
byte subtile_y;
|
|
|
|
byte width;
|
|
|
|
byte height;
|
2006-04-24 21:10:56 +00:00
|
|
|
byte dz;
|
2009-03-15 00:32:18 +00:00
|
|
|
byte draw_proc; // this allows to specify a special drawing procedure.
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-24 21:10:56 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/** Iterate through all DrawTileSeqStructs in DrawTileSprites. */
|
2011-02-19 13:16:34 +00:00
|
|
|
#define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
|
2004-11-14 16:45:38 +00:00
|
|
|
|
2024-01-07 16:41:53 +00:00
|
|
|
void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
|
|
|
|
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
|
2010-01-16 22:25:44 +00:00
|
|
|
|
2010-01-17 15:05:25 +00:00
|
|
|
/**
|
|
|
|
* Draw tile sprite sequence on tile with railroad specifics.
|
|
|
|
* @param total_offset Spriteoffset from normal rail to current railtype.
|
|
|
|
* @param newgrf_offset Startsprite of the Action1 to use.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
|
2010-01-17 15:05:25 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw tile sprite sequence in GUI with railroad specifics.
|
|
|
|
* @param total_offset Spriteoffset from normal rail to current railtype.
|
|
|
|
* @param newgrf_offset Startsprite of the Action1 to use.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
|
2010-01-17 15:05:25 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw TTD sprite sequence on tile.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
|
2010-01-17 15:05:25 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw TTD sprite sequence in GUI.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
|
2010-01-17 15:05:25 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw NewGRF industrytile or house sprite layout
|
|
|
|
* @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
|
2010-01-17 15:05:25 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
|
|
|
|
}
|
2004-11-14 16:45:38 +00:00
|
|
|
|
2010-08-28 18:23:58 +00:00
|
|
|
/**
|
|
|
|
* Draw NewGRF object in GUI
|
|
|
|
* @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage.
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
|
2010-08-28 18:23:58 +00:00
|
|
|
{
|
|
|
|
DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
|
|
|
|
}
|
|
|
|
|
2010-01-16 22:25:44 +00:00
|
|
|
/**
|
|
|
|
* Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry
|
2012-01-01 17:36:19 +00:00
|
|
|
* @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
|
2010-01-16 22:25:44 +00:00
|
|
|
* 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 colour resp. random industry/house colour)
|
|
|
|
* @return The palette to use
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
|
2010-01-16 22:25:44 +00:00
|
|
|
{
|
|
|
|
if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
|
|
|
|
return (pal != 0 ? pal : default_pal);
|
|
|
|
} else {
|
|
|
|
return PAL_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite
|
2012-01-01 17:36:19 +00:00
|
|
|
* @note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
|
2010-01-16 22:25:44 +00:00
|
|
|
* 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 colour resp. random industry/house colour)
|
|
|
|
* @return The palette to use
|
|
|
|
*/
|
2024-01-06 11:19:27 +00:00
|
|
|
inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
|
2010-01-16 22:25:44 +00:00
|
|
|
{
|
|
|
|
if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
|
|
|
|
return (pal != 0 ? pal : default_pal);
|
|
|
|
} else {
|
|
|
|
return PAL_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* SPRITE_H */
|