23 uint8_t default_selection;
44 uint32_t
GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter,
bool &available)
const override;
86 typedef std::list<GenericCallback> GenericCallbackList;
88 static GenericCallbackList _gcl[GSF_END];
96 for (
auto &gcl : _gcl) {
111 GrfMsg(5,
"AddGenericCallback: Unsupported feature 0x{:02X}", feature);
127 case 0x80:
return this->cargo_type;
129 case 0x82:
return this->default_selection;
132 case 0x85:
return this->distance;
133 case 0x86:
return this->event;
134 case 0x87:
return this->count;
135 case 0x88:
return this->station_size;
141 Debug(grf, 1,
"Unhandled generic feature variable 0x{:02X}", variable);
172 for (
const auto &it : _gcl[feature]) {
173 object.grffile = it.file;
174 object.root_spritegroup = it.group;
176 object.callback_param1 = it.file->grf_version >= 8 ? param1_grfv8 : param1_grfv7;
177 uint16_t result =
object.ResolveCallback();
181 if (file !=
nullptr) *file = it.file;
222 object.generic_scope.cargo_type = cargo_type;
223 object.generic_scope.default_selection = default_selection;
224 object.generic_scope.src_industry = src_industry;
225 object.generic_scope.dst_industry = dst_industry;
226 object.generic_scope.distance = distance;
227 object.generic_scope.event = event;
228 object.generic_scope.count = count;
229 object.generic_scope.station_size = station_size;
230 object.generic_scope.feature = feature;
252 object.generic_scope.feature = GSF_SOUNDFX;
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
@ GSF_INVALID
An invalid spec feature.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_SOUNDS_AMBIENT_EFFECT
Select an ambient sound to play for a given type of tile.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
@ CBID_GENERIC_AI_PURCHASE_SELECTION
AI construction/purchase selection.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
void AddGenericCallback(uint8_t feature, const GRFFile *file, const SpriteGroup *group)
Add a generic feature callback sprite group to the appropriate feature list.
static uint16_t GetGenericCallbackResult(uint8_t feature, ResolverObject &object, uint32_t param1_grfv7, uint32_t param1_grfv8, const GRFFile **file)
Follow a generic feature callback list and return the first successful answer.
void AmbientSoundEffectCallback(TileIndex tile)
'Execute' the ambient sound effect callback.
uint16_t GetAiPurchaseCallbackResult(uint8_t feature, CargoID cargo_type, uint8_t default_selection, IndustryType src_industry, IndustryType dst_industry, uint8_t distance, AIConstructionEvent event, uint8_t count, uint8_t station_size, const GRFFile **file)
'Execute' an AI purchase selection callback
void ResetGenericCallbacks()
Reset all generic feature callback sprite groups.
static const IndustryType IT_AI_UNKNOWN
The AI has no specific industry in mind.
AIConstructionEvent
AI events for asking the NewGRF for information.
static const IndustryType IT_AI_TOWN
The AI actually wants to transport to/from a town, not an industry.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
Functions related to NewGRF provided sounds.
@ VSG_SCOPE_SELF
Resolved object itself.
Pseudo random number generator.
bool Chance16R(const uint32_t a, const uint32_t b, uint32_t &r, const std::source_location location=std::source_location::current())
Flips a coin with a given probability and saves the randomize-number in a variable.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
uint8_t bitnum
Cargo bit number, is INVALID_CARGO_BITNUM for a non-used spec.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
SoundSettings sound
sound effect settings
Dynamic data of a loaded NewGRF.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
Resolver object for generic objects/properties.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
GenericResolverObject(bool ai_callback, CallbackID callback=CBID_NO_CALLBACK)
Generic resolver.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Scope resolver for generic objects and properties.
uint8_t dst_industry
Destination industry substitute type. 0xFF for "town", 0xFE for "unknown".
bool ai_callback
Callback comes from the AI.
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override
Get a variable value.
GenericScopeResolver(ResolverObject &ro, bool ai_callback)
Generic scope resolver.
uint8_t src_industry
Source industry substitute type. 0xFF for "town", 0xFE for "unknown".
Defines the data structure for constructing industry.
GRFFileProps grf_prop
properties related to the grf file
Interface for SpriteGroup-s to access the gamestate.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
CallbackID callback
Callback being resolved.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
bool ambient
Play ambient, industry and town sounds.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
@ MP_TREES
Tile got trees.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Map accessors for water tiles.
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.