38 if (group == NULL)
return NULL;
40 _temp_store.ClearChanges();
45 RealSpriteGroup::~RealSpriteGroup()
51 DeterministicSpriteGroup::~DeterministicSpriteGroup()
57 RandomizedSpriteGroup::~RandomizedSpriteGroup()
62 static inline uint32 GetVariable(
const ResolverObject &
object,
ScopeResolver *scope, byte variable, uint32 parameter,
bool *available)
66 case 0x0C:
return object.callback;
67 case 0x10:
return object.callback_param1;
68 case 0x18:
return object.callback_param2;
69 case 0x1C:
return object.last_value;
73 case 0x7D:
return _temp_store.
GetValue(parameter);
76 if (
object.grffile == NULL)
return 0;
77 return object.grffile->GetParam(parameter);
81 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
83 return scope->
GetVariable(variable, parameter, available);
114 DEBUG(grf, 1,
"Unhandled scope variable 0x%X", variable);
144 return &this->default_scope;
158 return (val >> rot) | (val << (32 - rot));
164 template <
typename U,
typename S>
167 value >>= adjust->shift_num;
168 value &= adjust->and_mask;
170 switch (adjust->type) {
171 case DSGA_TYPE_DIV: value = ((S)value + (S)adjust->add_val) / (S)adjust->divmod_val;
break;
172 case DSGA_TYPE_MOD: value = ((S)value + (S)adjust->add_val) % (S)adjust->divmod_val;
break;
173 case DSGA_TYPE_NONE:
break;
176 switch (adjust->operation) {
183 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
184 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
185 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
186 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
195 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
196 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
197 case DSGA_OP_SHL:
return (uint32)(U)last_value << ((U)value & 0x1F);
198 case DSGA_OP_SHR:
return (uint32)(U)last_value >> ((U)value & 0x1F);
199 case DSGA_OP_SAR:
return (int32)(S)last_value >> ((U)value & 0x1F);
200 default:
return value;
207 return range.high < value;
212 uint32 last_value = 0;
218 for (i = 0; i < this->num_adjusts; i++) {
222 bool available =
true;
223 if (adjust->variable == 0x7E) {
225 if (subgroup == NULL) {
228 value = subgroup->GetCallbackResult();
232 }
else if (adjust->variable == 0x7B) {
233 value = GetVariable(
object, scope, adjust->
parameter, last_value, &available);
235 value = GetVariable(
object, scope, adjust->variable, adjust->
parameter, &available);
244 switch (this->size) {
245 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, scope, last_value, value);
break;
246 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, scope, last_value, value);
break;
247 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value);
break;
248 default: NOT_REACHED();
253 object.last_value = last_value;
255 if (this->calculated_result) {
259 nvarzero.result = value;
263 if (this->num_ranges > 4) {
265 if (lower != this->ranges + this->num_ranges && lower->low <= value) {
266 assert(lower->low <= value && value <= lower->high);
270 for (i = 0; i < this->num_ranges; i++) {
271 if (this->ranges[i].low <= value && value <= this->ranges[i].high) {
283 ScopeResolver *scope =
object.GetScope(this->var_scope, this->count);
286 byte match = this->triggers &
object.waiting_triggers;
287 bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
290 object.used_triggers |= match;
291 object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
295 uint32 mask = (this->num_groups - 1) << this->lowest_randbit;
304 return object.ResolveReal(
this);
316 if (!this->dts.NeedsPreprocessing()) {
317 if (stage != NULL && this->dts.consistent_max_offset > 0) *stage =
GetConstructionStageOffset(*stage, this->dts.consistent_max_offset);
322 uint8 actual_stage = stage != NULL ? *stage : 0;
323 this->dts.PrepareLayout(0, 0, 0, actual_stage,
false);
324 this->dts.ProcessRegisters(0, 0,
false);
325 result.
seq = this->dts.GetLayout(&result.
ground);
328 if (stage != NULL) *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.
static uint32 RotateRight(uint32 val, uint32 rot)
Rotate val rot times to the right.
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.