30 template <
typename Tbase,
typename Tspec,
typename Tobj,
typename Textra, u
int16 (*GetCallback)(CallbackID callback, u
int32 param1, u
int32 param2, const Tspec *statspec, Tobj *st, TileIndex tile, Textra extra_data)>
41 static void AnimateTile(
const Tspec *spec, Tobj *obj,
TileIndex tile,
bool random_animation, Textra extra_data = 0)
46 uint8 animation_speed = spec->animation.speed;
47 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) {
48 uint16 callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data);
50 if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8)
ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, Tbase::cb_animation_speed, callback);
51 animation_speed =
Clamp(callback & 0xFF, 0, 16);
62 uint8 num_frames = spec->animation.frames;
64 bool frame_set_by_callback =
false;
66 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_next_frame)) {
67 uint16 callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile, extra_data);
70 frame_set_by_callback =
true;
72 switch (callback & 0xFF) {
78 frame_set_by_callback =
false;
82 frame = callback & 0xFF;
92 if (!frame_set_by_callback) {
93 if (frame < num_frames) {
122 uint16 callback = GetCallback(cb, random_bits, trigger, spec, obj, tile, extra_data);
125 switch (callback & 0xFF) {
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet)...
Functions related to dates.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definitions related to NewGRF animation.
bool ambient
Play ambient, industry and town sounds.
static void ChangeAnimationFrame(CallbackID cb, const Tspec *spec, Tobj *obj, TileIndex tile, uint32 random_bits, uint32 trigger, Textra extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
Callbacks that NewGRFs could implement.
static void AnimateTile(const Tspec *spec, Tobj *obj, TileIndex tile, bool random_animation, Textra extra_data=0)
Animate a single tile.
Functions related to (drawing on) viewports.
Pseudo random number generator.
SoundSettings sound
sound effect settings
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
ClientSettings _settings_client
The current settings for this game.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
uint32 TileIndex
The index/ID of a Tile.
Helper class for a unified approach to NewGRF animation.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
CallbackID
List of implemented NewGRF callbacks.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Map writing/reading functions for tiles.
static const uint8 ANIM_STATUS_LOOPING
Animation is looping.