36 if (group ==
nullptr)
return nullptr;
38 _temp_store.ClearChanges();
43 RealSpriteGroup::~RealSpriteGroup()
49 DeterministicSpriteGroup::~DeterministicSpriteGroup()
55 RandomizedSpriteGroup::~RandomizedSpriteGroup()
60 static inline uint32 GetVariable(
const ResolverObject &
object,
ScopeResolver *scope, byte variable, uint32 parameter,
bool *available)
64 case 0x0C:
return object.callback;
65 case 0x10:
return object.callback_param1;
66 case 0x18:
return object.callback_param2;
67 case 0x1C:
return object.last_value;
71 case 0x7D:
return _temp_store.
GetValue(parameter);
74 if (
object.grffile ==
nullptr)
return 0;
75 return object.grffile->GetParam(parameter);
79 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
81 return scope->
GetVariable(variable, parameter, available);
112 DEBUG(grf, 1,
"Unhandled scope variable 0x%X", variable);
142 return &this->default_scope;
147 template <
typename U,
typename S>
150 value >>= adjust->shift_num;
151 value &= adjust->and_mask;
153 switch (adjust->type) {
154 case DSGA_TYPE_DIV: value = ((S)value + (S)adjust->add_val) / (S)adjust->divmod_val;
break;
155 case DSGA_TYPE_MOD: value = ((S)value + (S)adjust->add_val) % (S)adjust->divmod_val;
break;
156 case DSGA_TYPE_NONE:
break;
159 switch (adjust->operation) {
166 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
167 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
168 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
169 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
177 case DSGA_OP_ROR:
return ROR<uint32>((U)last_value, (U)value & 0x1F);
178 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
179 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
180 case DSGA_OP_SHL:
return (uint32)(U)last_value << ((U)value & 0x1F);
181 case DSGA_OP_SHR:
return (uint32)(U)last_value >> ((U)value & 0x1F);
182 case DSGA_OP_SAR:
return (int32)(S)last_value >> ((U)value & 0x1F);
183 default:
return value;
190 return range.high < value;
195 uint32 last_value = 0;
201 for (i = 0; i < this->num_adjusts; i++) {
205 bool available =
true;
206 if (adjust->variable == 0x7E) {
208 if (subgroup ==
nullptr) {
211 value = subgroup->GetCallbackResult();
215 }
else if (adjust->variable == 0x7B) {
216 value = GetVariable(
object, scope, adjust->
parameter, last_value, &available);
218 value = GetVariable(
object, scope, adjust->variable, adjust->
parameter, &available);
227 switch (this->size) {
228 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, scope, last_value, value);
break;
229 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, scope, last_value, value);
break;
230 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value);
break;
231 default: NOT_REACHED();
236 object.last_value = last_value;
238 if (this->calculated_result) {
242 nvarzero.result = value;
246 if (this->num_ranges > 4) {
248 if (lower != this->ranges + this->num_ranges && lower->low <= value) {
249 assert(lower->low <= value && value <= lower->high);
253 for (i = 0; i < this->num_ranges; i++) {
254 if (this->ranges[i].low <= value && value <= this->ranges[i].high) {
266 ScopeResolver *scope =
object.GetScope(this->var_scope, this->count);
269 byte match = this->triggers &
object.waiting_triggers;
270 bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
273 object.used_triggers |= match;
274 object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
278 uint32 mask = (this->num_groups - 1) << this->lowest_randbit;
287 return object.ResolveReal(
this);
299 if (!this->dts.NeedsPreprocessing()) {
300 if (stage !=
nullptr && this->dts.consistent_max_offset > 0) *stage =
GetConstructionStageOffset(*stage, this->dts.consistent_max_offset);
305 uint8 actual_stage = stage !=
nullptr ? *stage : 0;
306 this->dts.PrepareLayout(0, 0, 0, actual_stage,
false);
307 this->dts.ProcessRegisters(0, 0,
false);
308 result.
seq = this->dts.GetLayout(&result.
ground);
311 if (stage !=
nullptr) *stage = 0;
rotate a b positions to the right
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Functions related to debugging.
virtual const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const
Get the real sprites of the grf.
Class for temporary storage of data.
Interface for SpriteGroup-s to access the gamestate.
(unsigned) comparison (a < b -> 0, a == b = 1, a > b = 2)
Tindex index
Index of this pool item.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
static T max(const T a, const T b)
Returns the maximum of two values.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
Ground palette sprite of a tile, together with its sprite layout.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
store a into temporary storage, indexed by b. return a
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
static T min(const T a, const T b)
Returns the minimum of two values.
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Base class for all pools.
#define DEBUG(name, level,...)
Output a line of debugging information.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
PalSpriteID ground
Palette and sprite for the ground.
bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
virtual void StorePSA(uint reg, int32 value)
Store a value into the persistent storage area (PSA).
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
(signed) comparison (a < b -> 0, a == b = 1, a > b = 2)
store a into persistent storage, indexed by b, return a
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
virtual uint32 GetRandomBits() const
Get a few random bits.
Set when calling a randomizing trigger (almost undocumented).
static uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
TYPE GetValue(uint pos) const
Gets the value from a given position.
byte parameter
Used for variables between 0x60 and 0x7F inclusive.
virtual uint32 GetTriggers() const
Get the triggers.