Files @ r8104:df12a5e083b5
Branch filter:

Location: cpp/openttd-patchpack/source/src/newgrf_spritegroup.h - annotation

belugas
(svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
Fix directly inspired by Csaboka
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6332:7393965b5322
r6835:9051f7024392
r7609:2e734c4aad38
r5475:3f5cd13d1b63
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7616:d6611d4fd004
r7609:2e734c4aad38
r7168:156fd244b919
r7168:156fd244b919
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r6521:f9fb7d189c75
r6521:f9fb7d189c75
r7610:6031d09c03ef
r7612:58e7a3f2232d
r7612:58e7a3f2232d
r7612:58e7a3f2232d
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5617:94e7517dc4e8
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r6348:a905c3e6d8fa
r5475:3f5cd13d1b63
r6348:a905c3e6d8fa
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r6332:7393965b5322
r6348:a905c3e6d8fa
r6332:7393965b5322
r6332:7393965b5322
r6332:7393965b5322
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r7168:156fd244b919
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6332:7393965b5322
r7168:156fd244b919
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6332:7393965b5322
r7168:156fd244b919
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6247:96e840dbefcc
r6247:96e840dbefcc
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r7327:28855024ff6c
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r7610:6031d09c03ef
r7610:6031d09c03ef
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6583:63b4cb964287
r6583:63b4cb964287
r6583:63b4cb964287
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6332:7393965b5322
r6332:7393965b5322
r6332:7393965b5322
r6332:7393965b5322
r6332:7393965b5322
r6365:410001496130
r6835:9051f7024392
r6835:9051f7024392
r6884:06c993c360e4
r6835:9051f7024392
r6835:9051f7024392
r6365:410001496130
r6365:410001496130
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6248:b940b09d7ab8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r7609:2e734c4aad38
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
/* $Id$ */

/** @file newgrf_spritegroup.h */

#ifndef NEWGRF_SPRITEGROUP_H
#define NEWGRF_SPRITEGROUP_H

#include "town.h"
#include "industry.h"
#include "newgrf_storage.h"

/**
 * Gets the value of a so-called newgrf "register".
 * @param i index of the register
 * @pre i < 0x110
 * @return the value of the register
 */
static inline uint32 GetRegister(uint i)
{
	extern TemporaryStorageArray<uint32, 0x110> _temp_store;
	return _temp_store.Get(i);
}

struct SpriteGroup;


/* 'Real' sprite groups contain a list of other result or callback sprite
 * groups. */
struct RealSpriteGroup {
	/* Loaded = in motion, loading = not moving
	 * Each group contains several spritesets, for various loading stages */

	/* XXX: For stations the meaning is different - loaded is for stations
	 * with small amount of cargo whilst loading is for stations with a lot
	 * of da stuff. */

	byte num_loaded;       ///< Number of loaded groups
	byte num_loading;      ///< Number of loading groups
	const SpriteGroup **loaded;  ///< List of loaded groups (can be SpriteIDs or Callback results)
	const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
};

/* Shared by deterministic and random groups. */
enum VarSpriteGroupScope {
	VSG_SCOPE_SELF,
	/* Engine of consists for vehicles, city for stations. */
	VSG_SCOPE_PARENT,
};

enum DeterministicSpriteGroupSize {
	DSG_SIZE_BYTE,
	DSG_SIZE_WORD,
	DSG_SIZE_DWORD,
};

enum DeterministicSpriteGroupAdjustType {
	DSGA_TYPE_NONE,
	DSGA_TYPE_DIV,
	DSGA_TYPE_MOD,
};

enum DeterministicSpriteGroupAdjustOperation {
	DSGA_OP_ADD,  ///< a + b
	DSGA_OP_SUB,  ///< a - b
	DSGA_OP_SMIN, ///< (signed) min(a, b)
	DSGA_OP_SMAX, ///< (signed) max(a, b)
	DSGA_OP_UMIN, ///< (unsigned) min(a, b)
	DSGA_OP_UMAX, ///< (unsigned) max(a, b)
	DSGA_OP_SDIV, ///< (signed) a / b
	DSGA_OP_SMOD, ///< (signed) a % b
	DSGA_OP_UDIV, ///< (unsigned) a / b
	DSGA_OP_UMOD, ///< (unsigned) a & b
	DSGA_OP_MUL,  ///< a * b
	DSGA_OP_AND,  ///< a & b
	DSGA_OP_OR,   ///< a | b
	DSGA_OP_XOR,  ///< a ^ b
	DSGA_OP_STO,  ///< store a into temporary storage, indexed by b. return a
	DSGA_OP_RST,  ///< return b
	DSGA_OP_STOP, ///< store a into persistent storage, indexed by b, return a
	DSGA_OP_ROR,  ///< rotate a b positions to the right
	DSGA_OP_SCMP, ///< (signed) comparision (a < b -> 0, a == b = 1, a > b = 2)
	DSGA_OP_UCMP, ///< (unsigned) comparision (a < b -> 0, a == b = 1, a > b = 2)
};


struct DeterministicSpriteGroupAdjust {
	DeterministicSpriteGroupAdjustOperation operation;
	DeterministicSpriteGroupAdjustType type;
	byte variable;
	byte parameter; ///< Used for variables between 0x60 and 0x7F inclusive.
	byte shift_num;
	uint32 and_mask;
	uint32 add_val;
	uint32 divmod_val;
	const SpriteGroup *subroutine;
};


struct DeterministicSpriteGroupRange {
	const SpriteGroup *group;
	uint32 low;
	uint32 high;
};


struct DeterministicSpriteGroup {
	VarSpriteGroupScope var_scope;
	DeterministicSpriteGroupSize size;
	byte num_adjusts;
	byte num_ranges;
	DeterministicSpriteGroupAdjust *adjusts;
	DeterministicSpriteGroupRange *ranges; // Dynamically allocated

	/* Dynamically allocated, this is the sole owner */
	const SpriteGroup *default_group;
};

enum RandomizedSpriteGroupCompareMode {
	RSG_CMP_ANY,
	RSG_CMP_ALL,
};

struct RandomizedSpriteGroup {
	VarSpriteGroupScope var_scope;  ///< Take this object:

	RandomizedSpriteGroupCompareMode cmp_mode; ///< Check for these triggers:
	byte triggers;

	byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
	byte num_groups; ///< must be power of 2

	const SpriteGroup **groups; ///< Take the group with appropriate index:
};


/* This contains a callback result. A failed callback has a value of
 * CALLBACK_FAILED */
struct CallbackResultSpriteGroup {
	uint16 result;
};


/* A result sprite group returns the first SpriteID and the number of
 * sprites in the set */
struct ResultSpriteGroup {
	SpriteID sprite;
	byte num_sprites;
};

struct TileLayoutSpriteGroup {
	byte num_sprites; ///< Number of sprites in the spriteset, used for loading stages
	struct DrawTileSprites *dts;
};

struct IndustryProductionSpriteGroup {
	uint8 version;
	uint16 substract_input[3];
	uint16 add_output[2];
	uint8 again;
};

/* List of different sprite group types */
enum SpriteGroupType {
	SGT_INVALID,
	SGT_REAL,
	SGT_DETERMINISTIC,
	SGT_RANDOMIZED,
	SGT_CALLBACK,
	SGT_RESULT,
	SGT_TILELAYOUT,
	SGT_INDUSTRY_PRODUCTION,
};

/* Common wrapper for all the different sprite group types */
struct SpriteGroup {
	SpriteGroupType type;

	union {
		RealSpriteGroup real;
		DeterministicSpriteGroup determ;
		RandomizedSpriteGroup random;
		CallbackResultSpriteGroup callback;
		ResultSpriteGroup result;
		TileLayoutSpriteGroup layout;
		IndustryProductionSpriteGroup indprod;
	} g;
};


SpriteGroup *AllocateSpriteGroup();
void InitializeSpriteGroupPool();


struct ResolverObject {
	CallbackID callback;
	uint32 callback_param1;
	uint32 callback_param2;

	byte trigger;
	uint32 last_value;
	uint32 reseed;
	VarSpriteGroupScope scope;

	bool info_view; ///< Indicates if the item is being drawn in an info window

	BaseStorageArray *psa; ///< The persistent storage array of this resolved object.

	union {
		struct {
			const struct Vehicle *self;
			const struct Vehicle *parent;
			EngineID self_type;
		} vehicle;
		struct {
			TileIndex tile;
		} canal;
		struct {
			TileIndex tile;
			const struct Station *st;
			const struct StationSpec *statspec;
			CargoID cargo_type;
		} station;
		struct {
			TileIndex tile;
			Town *town;
			HouseID house_id;
		} house;
		struct {
			TileIndex tile;
			Industry *ind;
			IndustryGfx gfx;
		} industry;
		struct {
			const struct CargoSpec *cs;
		} cargo;
	} u;

	uint32 (*GetRandomBits)(const struct ResolverObject*);
	uint32 (*GetTriggers)(const struct ResolverObject*);
	void (*SetTriggers)(const struct ResolverObject*, int);
	uint32 (*GetVariable)(const struct ResolverObject*, byte, byte, bool*);
	const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const SpriteGroup*);
};


/* Base sprite group resolver */
const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object);


#endif /* NEWGRF_SPRITEGROUP_H */