00001
00002
00005 #ifndef NEWGRF_SPRITEGROUP_H
00006 #define NEWGRF_SPRITEGROUP_H
00007
00008 #include "town_type.h"
00009 #include "industry_type.h"
00010 #include "core/bitmath_func.hpp"
00011 #include "gfx_type.h"
00012 #include "engine_type.h"
00013 #include "tile_type.h"
00014
00015 #include "newgrf_cargo.h"
00016 #include "newgrf_callbacks.h"
00017 #include "newgrf_generic.h"
00018 #include "newgrf_storage.h"
00019
00026 static inline uint32 GetRegister(uint i)
00027 {
00028 extern TemporaryStorageArray<uint32, 0x110> _temp_store;
00029 return _temp_store.Get(i);
00030 }
00031
00032 struct SpriteGroup;
00033
00034
00035
00036
00037 struct RealSpriteGroup {
00038
00039
00040
00041
00042
00043
00044
00045 byte num_loaded;
00046 byte num_loading;
00047 const SpriteGroup **loaded;
00048 const SpriteGroup **loading;
00049 };
00050
00051
00052 enum VarSpriteGroupScope {
00053 VSG_SCOPE_SELF,
00054
00055 VSG_SCOPE_PARENT,
00056
00057 VSG_SCOPE_RELATIVE,
00058 };
00059
00060 enum DeterministicSpriteGroupSize {
00061 DSG_SIZE_BYTE,
00062 DSG_SIZE_WORD,
00063 DSG_SIZE_DWORD,
00064 };
00065
00066 enum DeterministicSpriteGroupAdjustType {
00067 DSGA_TYPE_NONE,
00068 DSGA_TYPE_DIV,
00069 DSGA_TYPE_MOD,
00070 };
00071
00072 enum DeterministicSpriteGroupAdjustOperation {
00073 DSGA_OP_ADD,
00074 DSGA_OP_SUB,
00075 DSGA_OP_SMIN,
00076 DSGA_OP_SMAX,
00077 DSGA_OP_UMIN,
00078 DSGA_OP_UMAX,
00079 DSGA_OP_SDIV,
00080 DSGA_OP_SMOD,
00081 DSGA_OP_UDIV,
00082 DSGA_OP_UMOD,
00083 DSGA_OP_MUL,
00084 DSGA_OP_AND,
00085 DSGA_OP_OR,
00086 DSGA_OP_XOR,
00087 DSGA_OP_STO,
00088 DSGA_OP_RST,
00089 DSGA_OP_STOP,
00090 DSGA_OP_ROR,
00091 DSGA_OP_SCMP,
00092 DSGA_OP_UCMP,
00093 };
00094
00095
00096 struct DeterministicSpriteGroupAdjust {
00097 DeterministicSpriteGroupAdjustOperation operation;
00098 DeterministicSpriteGroupAdjustType type;
00099 byte variable;
00100 byte parameter;
00101 byte shift_num;
00102 uint32 and_mask;
00103 uint32 add_val;
00104 uint32 divmod_val;
00105 const SpriteGroup *subroutine;
00106 };
00107
00108
00109 struct DeterministicSpriteGroupRange {
00110 const SpriteGroup *group;
00111 uint32 low;
00112 uint32 high;
00113 };
00114
00115
00116 struct DeterministicSpriteGroup {
00117 VarSpriteGroupScope var_scope;
00118 DeterministicSpriteGroupSize size;
00119 byte num_adjusts;
00120 byte num_ranges;
00121 DeterministicSpriteGroupAdjust *adjusts;
00122 DeterministicSpriteGroupRange *ranges;
00123
00124
00125 const SpriteGroup *default_group;
00126 };
00127
00128 enum RandomizedSpriteGroupCompareMode {
00129 RSG_CMP_ANY,
00130 RSG_CMP_ALL,
00131 };
00132
00133 struct RandomizedSpriteGroup {
00134 VarSpriteGroupScope var_scope;
00135
00136 RandomizedSpriteGroupCompareMode cmp_mode;
00137 byte triggers;
00138 byte count;
00139
00140 byte lowest_randbit;
00141 byte num_groups;
00142
00143 const SpriteGroup **groups;
00144 };
00145
00146
00147
00148
00149 struct CallbackResultSpriteGroup {
00150 uint16 result;
00151 };
00152
00153
00154
00155
00156 struct ResultSpriteGroup {
00157 SpriteID sprite;
00158 byte num_sprites;
00159 };
00160
00161 struct TileLayoutSpriteGroup {
00162 byte num_sprites;
00163 struct DrawTileSprites *dts;
00164 };
00165
00166 struct IndustryProductionSpriteGroup {
00167 uint8 version;
00168 int16 substract_input[3];
00169 uint16 add_output[2];
00170 uint8 again;
00171 };
00172
00173
00174 enum SpriteGroupType {
00175 SGT_INVALID,
00176 SGT_REAL,
00177 SGT_DETERMINISTIC,
00178 SGT_RANDOMIZED,
00179 SGT_CALLBACK,
00180 SGT_RESULT,
00181 SGT_TILELAYOUT,
00182 SGT_INDUSTRY_PRODUCTION,
00183 };
00184
00185
00186 struct SpriteGroup {
00187 SpriteGroupType type;
00188
00189 union {
00190 RealSpriteGroup real;
00191 DeterministicSpriteGroup determ;
00192 RandomizedSpriteGroup random;
00193 CallbackResultSpriteGroup callback;
00194 ResultSpriteGroup result;
00195 TileLayoutSpriteGroup layout;
00196 IndustryProductionSpriteGroup indprod;
00197 } g;
00198 };
00199
00200
00201 SpriteGroup *AllocateSpriteGroup();
00202 void InitializeSpriteGroupPool();
00203
00204
00205 struct ResolverObject {
00206 CallbackID callback;
00207 uint32 callback_param1;
00208 uint32 callback_param2;
00209
00210 byte trigger;
00211 byte count;
00212 uint32 last_value;
00213 uint32 reseed;
00214 VarSpriteGroupScope scope;
00215
00216 bool info_view;
00217
00218 BaseStorageArray *psa;
00219
00220 const GRFFile *grffile;
00221
00222 union {
00223 struct {
00224 const struct Vehicle *self;
00225 const struct Vehicle *parent;
00226 EngineID self_type;
00227 } vehicle;
00228 struct {
00229 TileIndex tile;
00230 } canal;
00231 struct {
00232 TileIndex tile;
00233 const struct Station *st;
00234 const struct StationSpec *statspec;
00235 CargoID cargo_type;
00236 } station;
00237 struct {
00238 TileIndex tile;
00239 Town *town;
00240 HouseID house_id;
00241 } house;
00242 struct {
00243 TileIndex tile;
00244 Industry *ind;
00245 IndustryGfx gfx;
00246 IndustryType type;
00247 } industry;
00248 struct {
00249 const struct CargoSpec *cs;
00250 } cargo;
00251 struct {
00252 CargoID cargo_type;
00253 uint8 default_selection;
00254 IndustryType src_industry;
00255 IndustryType dst_industry;
00256 uint8 distance;
00257 AIConstructionEvent event;
00258 uint8 count;
00259 uint8 station_size;
00260 } generic;
00261 } u;
00262
00263 uint32 (*GetRandomBits)(const struct ResolverObject*);
00264 uint32 (*GetTriggers)(const struct ResolverObject*);
00265 void (*SetTriggers)(const struct ResolverObject*, int);
00266 uint32 (*GetVariable)(const struct ResolverObject*, byte, byte, bool*);
00267 const SpriteGroup *(*ResolveReal)(const struct ResolverObject*, const SpriteGroup*);
00268 };
00269
00270
00271
00272 const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object);
00273
00274
00275 #endif