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 newgrf_spritegroup.h Action 2 handling. */
|
2007-03-21 03:06:21 +00:00
|
|
|
|
2006-04-20 20:51:57 +00:00
|
|
|
#ifndef NEWGRF_SPRITEGROUP_H
|
|
|
|
#define NEWGRF_SPRITEGROUP_H
|
|
|
|
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town_type.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "engine_type.h"
|
2009-06-26 13:44:14 +00:00
|
|
|
#include "house_type.h"
|
2018-07-26 17:29:54 +00:00
|
|
|
#include "industry_type.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
|
|
|
|
#include "newgrf_callbacks.h"
|
2008-02-12 13:23:57 +00:00
|
|
|
#include "newgrf_generic.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "newgrf_storage.h"
|
2010-08-09 07:10:42 +00:00
|
|
|
#include "newgrf_commons.h"
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-07-05 05:41:56 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2010-03-21 11:05:39 +00:00
|
|
|
extern TemporaryStorageArray<int32, 0x110> _temp_store;
|
2011-06-12 20:40:21 +00:00
|
|
|
return _temp_store.GetValue(i);
|
2007-07-05 05:41:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
/* List of different sprite group types */
|
|
|
|
enum SpriteGroupType {
|
|
|
|
SGT_REAL,
|
|
|
|
SGT_DETERMINISTIC,
|
|
|
|
SGT_RANDOMIZED,
|
|
|
|
SGT_CALLBACK,
|
|
|
|
SGT_RESULT,
|
|
|
|
SGT_TILELAYOUT,
|
|
|
|
SGT_INDUSTRY_PRODUCTION,
|
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct SpriteGroup;
|
2009-05-23 12:13:42 +00:00
|
|
|
typedef uint32 SpriteGroupID;
|
2013-11-24 14:41:19 +00:00
|
|
|
struct ResolverObject;
|
2009-05-23 16:39:55 +00:00
|
|
|
|
|
|
|
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite.
|
|
|
|
* Adding an 'extra' margin would be assuming 64 sprite groups per real
|
|
|
|
* sprite. 64 = 2^6, so 2^30 should be enough (for now) */
|
2022-11-04 07:15:59 +00:00
|
|
|
typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1U << 30, PT_DATA> SpriteGroupPool;
|
2009-05-23 12:13:42 +00:00
|
|
|
extern SpriteGroupPool _spritegroup_pool;
|
|
|
|
|
|
|
|
/* Common wrapper for all the different sprite group types */
|
|
|
|
struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
|
|
|
|
protected:
|
2020-01-26 12:45:51 +00:00
|
|
|
SpriteGroup(SpriteGroupType type) : nfo_line(0), type(type) {}
|
2009-05-23 15:25:52 +00:00
|
|
|
/** Base sprite group resolver */
|
2013-11-24 14:41:19 +00:00
|
|
|
virtual const SpriteGroup *Resolve(ResolverObject &object) const { return this; };
|
2009-05-23 12:13:42 +00:00
|
|
|
|
|
|
|
public:
|
2023-05-14 21:31:03 +00:00
|
|
|
virtual ~SpriteGroup() = default;
|
2009-05-23 12:13:42 +00:00
|
|
|
|
2020-01-26 12:45:51 +00:00
|
|
|
uint32 nfo_line;
|
2009-05-23 12:13:42 +00:00
|
|
|
SpriteGroupType type;
|
|
|
|
|
|
|
|
virtual SpriteID GetResult() const { return 0; }
|
|
|
|
virtual byte GetNumResults() const { return 0; }
|
|
|
|
virtual uint16 GetCallbackResult() const { return CALLBACK_FAILED; }
|
2009-05-23 15:25:52 +00:00
|
|
|
|
2013-12-23 18:08:16 +00:00
|
|
|
static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level = true);
|
2009-05-23 12:13:42 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
/* 'Real' sprite groups contain a list of other result or callback sprite
|
|
|
|
* groups. */
|
2009-05-23 12:13:42 +00:00
|
|
|
struct RealSpriteGroup : SpriteGroup {
|
|
|
|
RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Loaded = in motion, loading = not moving
|
|
|
|
* Each group contains several spritesets, for various loading stages */
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* 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. */
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2021-05-01 22:58:18 +00:00
|
|
|
std::vector<const SpriteGroup *> loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
|
|
|
|
std::vector<const SpriteGroup *> loading; ///< List of loading groups (can be SpriteIDs or Callback results)
|
2009-05-23 15:25:52 +00:00
|
|
|
|
|
|
|
protected:
|
2013-11-24 14:41:19 +00:00
|
|
|
const SpriteGroup *Resolve(ResolverObject &object) const;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
|
|
|
/* Shared by deterministic and random groups. */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum VarSpriteGroupScope {
|
2011-07-04 20:37:20 +00:00
|
|
|
VSG_BEGIN,
|
|
|
|
|
|
|
|
VSG_SCOPE_SELF = VSG_BEGIN, ///< Resolved object itself
|
|
|
|
VSG_SCOPE_PARENT, ///< Related object of the resolved one
|
|
|
|
VSG_SCOPE_RELATIVE, ///< Relative position (vehicles only)
|
|
|
|
|
|
|
|
VSG_END
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2011-07-04 20:37:20 +00:00
|
|
|
DECLARE_POSTFIX_INCREMENT(VarSpriteGroupScope)
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DeterministicSpriteGroupSize {
|
2006-04-26 20:44:28 +00:00
|
|
|
DSG_SIZE_BYTE,
|
|
|
|
DSG_SIZE_WORD,
|
|
|
|
DSG_SIZE_DWORD,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 20:44:28 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DeterministicSpriteGroupAdjustType {
|
2006-04-26 20:44:28 +00:00
|
|
|
DSGA_TYPE_NONE,
|
|
|
|
DSGA_TYPE_DIV,
|
|
|
|
DSGA_TYPE_MOD,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 20:44:28 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DeterministicSpriteGroupAdjustOperation {
|
2007-03-21 03:06:21 +00:00
|
|
|
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
|
2007-04-21 07:27:16 +00:00
|
|
|
DSGA_OP_STO, ///< store a into temporary storage, indexed by b. return a
|
|
|
|
DSGA_OP_RST, ///< return b
|
2007-09-22 13:56:38 +00:00
|
|
|
DSGA_OP_STOP, ///< store a into persistent storage, indexed by b, return a
|
2007-09-22 20:29:17 +00:00
|
|
|
DSGA_OP_ROR, ///< rotate a b positions to the right
|
2013-01-08 22:46:42 +00:00
|
|
|
DSGA_OP_SCMP, ///< (signed) comparison (a < b -> 0, a == b = 1, a > b = 2)
|
|
|
|
DSGA_OP_UCMP, ///< (unsigned) comparison (a < b -> 0, a == b = 1, a > b = 2)
|
2010-08-02 23:12:43 +00:00
|
|
|
DSGA_OP_SHL, ///< a << b
|
|
|
|
DSGA_OP_SHR, ///< (unsigned) a >> b
|
|
|
|
DSGA_OP_SAR, ///< (signed) a >> b
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 20:44:28 +00:00
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DeterministicSpriteGroupAdjust {
|
2006-04-26 20:44:28 +00:00
|
|
|
DeterministicSpriteGroupAdjustOperation operation;
|
|
|
|
DeterministicSpriteGroupAdjustType type;
|
2006-04-26 17:16:57 +00:00
|
|
|
byte variable;
|
|
|
|
byte parameter; ///< Used for variables between 0x60 and 0x7F inclusive.
|
|
|
|
byte shift_num;
|
2006-04-26 20:44:28 +00:00
|
|
|
uint32 and_mask;
|
|
|
|
uint32 add_val;
|
|
|
|
uint32 divmod_val;
|
2007-01-12 11:20:34 +00:00
|
|
|
const SpriteGroup *subroutine;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct DeterministicSpriteGroupRange {
|
2006-10-19 10:20:36 +00:00
|
|
|
const SpriteGroup *group;
|
2006-04-26 20:44:28 +00:00
|
|
|
uint32 low;
|
|
|
|
uint32 high;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 20:44:28 +00:00
|
|
|
|
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
struct DeterministicSpriteGroup : SpriteGroup {
|
|
|
|
DeterministicSpriteGroup() : SpriteGroup(SGT_DETERMINISTIC) {}
|
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
VarSpriteGroupScope var_scope;
|
|
|
|
DeterministicSpriteGroupSize size;
|
2018-03-11 15:08:51 +00:00
|
|
|
bool calculated_result;
|
2021-05-01 23:00:06 +00:00
|
|
|
std::vector<DeterministicSpriteGroupAdjust> adjusts;
|
|
|
|
std::vector<DeterministicSpriteGroupRange> ranges; // Dynamically allocated
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Dynamically allocated, this is the sole owner */
|
2006-10-19 10:20:36 +00:00
|
|
|
const SpriteGroup *default_group;
|
2009-05-23 15:25:52 +00:00
|
|
|
|
2018-03-11 13:21:27 +00:00
|
|
|
const SpriteGroup *error_group; // was first range, before sorting ranges
|
|
|
|
|
2009-05-23 15:25:52 +00:00
|
|
|
protected:
|
2013-11-24 14:41:19 +00:00
|
|
|
const SpriteGroup *Resolve(ResolverObject &object) const;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum RandomizedSpriteGroupCompareMode {
|
2006-04-26 17:16:57 +00:00
|
|
|
RSG_CMP_ANY,
|
|
|
|
RSG_CMP_ALL,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
struct RandomizedSpriteGroup : SpriteGroup {
|
|
|
|
RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
VarSpriteGroupScope var_scope; ///< Take this object:
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
RandomizedSpriteGroupCompareMode cmp_mode; ///< Check for these triggers:
|
2006-04-26 17:16:57 +00:00
|
|
|
byte triggers;
|
2008-03-27 21:36:16 +00:00
|
|
|
byte count;
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2021-05-01 23:00:40 +00:00
|
|
|
std::vector<const SpriteGroup *> groups; ///< Take the group with appropriate index:
|
2009-05-23 15:25:52 +00:00
|
|
|
|
|
|
|
protected:
|
2013-11-24 14:41:19 +00:00
|
|
|
const SpriteGroup *Resolve(ResolverObject &object) const;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
|
|
|
|
/* This contains a callback result. A failed callback has a value of
|
|
|
|
* CALLBACK_FAILED */
|
2009-05-23 12:13:42 +00:00
|
|
|
struct CallbackResultSpriteGroup : SpriteGroup {
|
|
|
|
/**
|
|
|
|
* Creates a spritegroup representing a callback result
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param value The value that was used to represent this callback result
|
2011-11-08 17:22:19 +00:00
|
|
|
* @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
|
2009-05-23 12:13:42 +00:00
|
|
|
*/
|
2011-11-08 17:22:19 +00:00
|
|
|
CallbackResultSpriteGroup(uint16 value, bool grf_version8) :
|
2009-05-23 12:13:42 +00:00
|
|
|
SpriteGroup(SGT_CALLBACK),
|
2009-05-23 12:56:30 +00:00
|
|
|
result(value)
|
2009-05-23 12:13:42 +00:00
|
|
|
{
|
2011-11-08 17:22:19 +00:00
|
|
|
/* Old style callback results (only valid for version < 8) have the highest byte 0xFF so signify it is a callback result.
|
2009-05-23 12:13:42 +00:00
|
|
|
* New style ones only have the highest bit set (allows 15-bit results, instead of just 8) */
|
2011-11-08 17:22:19 +00:00
|
|
|
if (!grf_version8 && (this->result >> 8) == 0xFF) {
|
2009-05-23 12:13:42 +00:00
|
|
|
this->result &= ~0xFF00;
|
|
|
|
} else {
|
|
|
|
this->result &= ~0x8000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-26 17:16:57 +00:00
|
|
|
uint16 result;
|
2009-05-23 12:13:42 +00:00
|
|
|
uint16 GetCallbackResult() const { return this->result; }
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
|
|
|
|
/* A result sprite group returns the first SpriteID and the number of
|
|
|
|
* sprites in the set */
|
2009-05-23 12:13:42 +00:00
|
|
|
struct ResultSpriteGroup : SpriteGroup {
|
|
|
|
/**
|
|
|
|
* Creates a spritegroup representing a sprite number result.
|
|
|
|
* @param sprite The sprite number.
|
|
|
|
* @param num_sprites The number of sprites per set.
|
|
|
|
* @return A spritegroup representing the sprite number result.
|
|
|
|
*/
|
|
|
|
ResultSpriteGroup(SpriteID sprite, byte num_sprites) :
|
|
|
|
SpriteGroup(SGT_RESULT),
|
|
|
|
sprite(sprite),
|
|
|
|
num_sprites(num_sprites)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-26 20:44:28 +00:00
|
|
|
SpriteID sprite;
|
|
|
|
byte num_sprites;
|
2009-05-23 12:13:42 +00:00
|
|
|
SpriteID GetResult() const { return this->sprite; }
|
|
|
|
byte GetNumResults() const { return this->num_sprites; }
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-26 17:16:57 +00:00
|
|
|
|
2011-05-29 16:56:22 +00:00
|
|
|
/**
|
|
|
|
* Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
|
|
|
|
*/
|
2009-05-23 12:13:42 +00:00
|
|
|
struct TileLayoutSpriteGroup : SpriteGroup {
|
|
|
|
TileLayoutSpriteGroup() : SpriteGroup(SGT_TILELAYOUT) {}
|
2011-05-14 17:33:26 +00:00
|
|
|
~TileLayoutSpriteGroup() {}
|
2009-05-23 12:13:42 +00:00
|
|
|
|
2011-05-14 17:33:26 +00:00
|
|
|
NewGRFSpriteLayout dts;
|
2011-05-29 16:56:22 +00:00
|
|
|
|
|
|
|
const DrawTileSprites *ProcessRegisters(uint8 *stage) const;
|
2007-03-19 11:27:30 +00:00
|
|
|
};
|
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
struct IndustryProductionSpriteGroup : SpriteGroup {
|
|
|
|
IndustryProductionSpriteGroup() : SpriteGroup(SGT_INDUSTRY_PRODUCTION) {}
|
|
|
|
|
2019-03-10 17:45:15 +00:00
|
|
|
uint8 version; ///< Production callback version used, or 0xFF if marked invalid
|
2018-07-26 17:29:54 +00:00
|
|
|
uint8 num_input; ///< How many subtract_input values are valid
|
|
|
|
int16 subtract_input[INDUSTRY_NUM_INPUTS]; ///< Take this much of the input cargo (can be negative, is indirect in cb version 1+)
|
|
|
|
CargoID cargo_input[INDUSTRY_NUM_INPUTS]; ///< Which input cargoes to take from (only cb version 2)
|
|
|
|
uint8 num_output; ///< How many add_output values are valid
|
|
|
|
uint16 add_output[INDUSTRY_NUM_OUTPUTS]; ///< Add this much output cargo when successful (unsigned, is indirect in cb version 1+)
|
|
|
|
CargoID cargo_output[INDUSTRY_NUM_OUTPUTS]; ///< Which output cargoes to add to (only cb version 2)
|
2007-07-05 05:41:56 +00:00
|
|
|
uint8 again;
|
2018-07-26 17:29:54 +00:00
|
|
|
|
2007-07-05 05:41:56 +00:00
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/**
|
|
|
|
* Interface to query and set values specific to a single #VarSpriteGroupScope (action 2 scope).
|
|
|
|
*
|
|
|
|
* Multiple of these interfaces are combined into a #ResolverObject to allow access
|
|
|
|
* to different game entities from a #SpriteGroup-chain (action 1-2-3 chain).
|
|
|
|
*/
|
2012-11-10 20:37:31 +00:00
|
|
|
struct ScopeResolver {
|
2013-11-24 14:41:19 +00:00
|
|
|
ResolverObject &ro; ///< Surrounding resolver object.
|
2012-11-10 20:37:31 +00:00
|
|
|
|
2018-03-11 13:19:41 +00:00
|
|
|
ScopeResolver(ResolverObject &ro) : ro(ro) {}
|
2023-05-14 21:31:03 +00:00
|
|
|
virtual ~ScopeResolver() = default;
|
2012-11-10 20:37:31 +00:00
|
|
|
|
|
|
|
virtual uint32 GetRandomBits() const;
|
|
|
|
virtual uint32 GetTriggers() const;
|
|
|
|
|
|
|
|
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
|
|
|
|
virtual void StorePSA(uint reg, int32 value);
|
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/**
|
|
|
|
* Interface for #SpriteGroup-s to access the gamestate.
|
|
|
|
*
|
|
|
|
* Using this interface #SpriteGroup-chains (action 1-2-3 chains) can be resolved,
|
|
|
|
* to get the results of callbacks, rerandomisations or normal sprite lookups.
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct ResolverObject {
|
2018-03-11 13:19:41 +00:00
|
|
|
/**
|
|
|
|
* Resolver constructor.
|
2019-04-10 21:07:06 +00:00
|
|
|
* @param grffile NewGRF file associated with the object (or \c nullptr if none).
|
2018-03-11 13:19:41 +00:00
|
|
|
* @param callback Callback code being resolved (default value is #CBID_NO_CALLBACK).
|
|
|
|
* @param callback_param1 First parameter (var 10) of the callback (only used when \a callback is also set).
|
|
|
|
* @param callback_param2 Second parameter (var 18) of the callback (only used when \a callback is also set).
|
|
|
|
*/
|
|
|
|
ResolverObject(const GRFFile *grffile, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0)
|
2019-04-10 21:07:06 +00:00
|
|
|
: default_scope(*this), callback(callback), callback_param1(callback_param1), callback_param2(callback_param2), grffile(grffile), root_spritegroup(nullptr)
|
2018-03-11 13:19:41 +00:00
|
|
|
{
|
|
|
|
this->ResetState();
|
|
|
|
}
|
|
|
|
|
2023-05-14 21:31:03 +00:00
|
|
|
virtual ~ResolverObject() = default;
|
2012-11-10 20:37:31 +00:00
|
|
|
|
2012-11-10 20:38:46 +00:00
|
|
|
ScopeResolver default_scope; ///< Default implementation of the grf scope.
|
2012-11-10 20:37:31 +00:00
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
CallbackID callback; ///< Callback being resolved.
|
|
|
|
uint32 callback_param1; ///< First parameter (var 10) of the callback.
|
|
|
|
uint32 callback_param2; ///< Second parameter (var 18) of the callback.
|
2006-04-27 19:53:58 +00:00
|
|
|
|
2009-09-30 20:25:59 +00:00
|
|
|
uint32 last_value; ///< Result of most recent DeterministicSpriteGroup (including procedure calls)
|
2017-10-25 15:38:14 +00:00
|
|
|
|
|
|
|
uint32 waiting_triggers; ///< Waiting triggers to be used by any rerandomisation. (scope independent)
|
|
|
|
uint32 used_triggers; ///< Subset of cur_triggers, which actually triggered some rerandomisation. (scope independent)
|
2011-07-04 20:37:20 +00:00
|
|
|
uint32 reseed[VSG_END]; ///< Collects bits to rerandomise while triggering triggers.
|
2009-09-30 20:25:59 +00:00
|
|
|
|
|
|
|
const GRFFile *grffile; ///< GRFFile the resolved SpriteGroup belongs to
|
2014-03-03 20:02:31 +00:00
|
|
|
const SpriteGroup *root_spritegroup; ///< Root SpriteGroup to use for resolving
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve SpriteGroup.
|
|
|
|
* @return Result spritegroup.
|
|
|
|
*/
|
|
|
|
const SpriteGroup *Resolve()
|
|
|
|
{
|
|
|
|
return SpriteGroup::Resolve(this->root_spritegroup, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve callback.
|
|
|
|
* @return Callback result.
|
|
|
|
*/
|
|
|
|
uint16 ResolveCallback()
|
|
|
|
{
|
|
|
|
const SpriteGroup *result = Resolve();
|
2019-04-10 21:07:06 +00:00
|
|
|
return result != nullptr ? result->GetCallbackResult() : CALLBACK_FAILED;
|
2014-03-03 20:02:31 +00:00
|
|
|
}
|
2008-07-30 18:23:12 +00:00
|
|
|
|
2012-11-10 20:37:31 +00:00
|
|
|
virtual const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
|
|
|
|
|
|
|
|
virtual ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
|
|
|
|
|
2017-10-25 15:38:14 +00:00
|
|
|
/**
|
|
|
|
* Returns the waiting triggers that did not trigger any rerandomisation.
|
|
|
|
*/
|
|
|
|
uint32 GetRemainingTriggers() const
|
|
|
|
{
|
|
|
|
return this->waiting_triggers & ~this->used_triggers;
|
|
|
|
}
|
|
|
|
|
2011-07-04 20:37:20 +00:00
|
|
|
/**
|
|
|
|
* Returns the OR-sum of all bits that need reseeding
|
|
|
|
* independent of the scope they were accessed with.
|
|
|
|
* @return OR-sum of the bits.
|
|
|
|
*/
|
|
|
|
uint32 GetReseedSum() const
|
|
|
|
{
|
|
|
|
uint32 sum = 0;
|
|
|
|
for (VarSpriteGroupScope vsg = VSG_BEGIN; vsg < VSG_END; vsg++) {
|
|
|
|
sum |= this->reseed[vsg];
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2011-07-04 20:31:57 +00:00
|
|
|
/**
|
|
|
|
* Resets the dynamic state of the resolver object.
|
|
|
|
* To be called before resolving an Action-1-2-3 chain.
|
|
|
|
*/
|
|
|
|
void ResetState()
|
|
|
|
{
|
|
|
|
this->last_value = 0;
|
2017-10-25 15:38:14 +00:00
|
|
|
this->waiting_triggers = 0;
|
|
|
|
this->used_triggers = 0;
|
2011-07-04 20:37:20 +00:00
|
|
|
memset(this->reseed, 0, sizeof(this->reseed));
|
2011-07-04 20:31:57 +00:00
|
|
|
}
|
2020-01-26 12:45:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the feature number being resolved for.
|
|
|
|
* This function is mainly intended for the callback profiling feature.
|
|
|
|
*/
|
|
|
|
virtual GrfSpecFeature GetFeature() const { return GSF_INVALID; }
|
|
|
|
/**
|
|
|
|
* Get an identifier for the item being resolved.
|
|
|
|
* This function is mainly intended for the callback profiling feature,
|
|
|
|
* and should return an identifier recognisable by the NewGRF developer.
|
|
|
|
*/
|
|
|
|
virtual uint32 GetDebugID() const { return 0; }
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-27 19:53:58 +00:00
|
|
|
|
2006-04-20 20:51:57 +00:00
|
|
|
#endif /* NEWGRF_SPRITEGROUP_H */
|