OpenTTD Source 20260206-master-g4d4e37dbf1
newgrf_generic.cpp File Reference

Handling of generic feature callbacks. More...

#include "stdafx.h"
#include "debug.h"
#include "newgrf_spritegroup.h"
#include "industrytype.h"
#include "core/random_func.hpp"
#include "newgrf_sound.h"
#include "water_map.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  GenericScopeResolver
 Scope resolver for generic objects and properties. More...
struct  GenericResolverObject
 Resolver object for generic objects/properties. More...
struct  GenericCallback

Typedefs

typedef std::list< GenericCallbackGenericCallbackList

Functions

void ResetGenericCallbacks ()
 Reset all generic feature callback sprite groups.
void AddGenericCallback (GrfSpecFeature feature, const GRFFile *file, const SpriteGroup *group)
 Add a generic feature callback sprite group to the appropriate feature list.
static std::pair< const GRFFile *, uint16_t > GetGenericCallbackResult (GrfSpecFeature feature, ResolverObject &object, uint32_t param1_grfv7, uint32_t param1_grfv8, std::span< int32_t > regs100={})
 Follow a generic feature callback list and return the first successful answer.
std::pair< const GRFFile *, uint16_t > GetAiPurchaseCallbackResult (GrfSpecFeature feature, CargoType cargo_type, uint8_t default_selection, IndustryType src_industry, IndustryType dst_industry, uint8_t distance, AIConstructionEvent event, uint8_t count, uint8_t station_size)
 'Execute' an AI purchase selection callback
void AmbientSoundEffectCallback (TileIndex tile)
 'Execute' the ambient sound effect callback.

Variables

static GenericCallbackList _gcl [GSF_END]

Detailed Description

Handling of generic feature callbacks.

Definition in file newgrf_generic.cpp.

Typedef Documentation

◆ GenericCallbackList

typedef std::list<GenericCallback> GenericCallbackList

Definition at line 86 of file newgrf_generic.cpp.

Function Documentation

◆ AddGenericCallback()

void AddGenericCallback ( GrfSpecFeature feature,
const GRFFile * file,
const SpriteGroup * group )

Add a generic feature callback sprite group to the appropriate feature list.

Parameters
featureThe feature for the callback.
fileThe GRF of the callback.
groupThe sprite group of the callback.

Definition at line 108 of file newgrf_generic.cpp.

References lengthof.

◆ AmbientSoundEffectCallback()

void AmbientSoundEffectCallback ( TileIndex tile)

'Execute' the ambient sound effect callback.

Parameters
tileTile the sound effect should be generated for.

Definition at line 238 of file newgrf_generic.cpp.

References _settings_client, CALLBACK_FAILED, CBID_SOUNDS_AMBIENT_EFFECT, Chance16R(), Clamp(), Clear, GB(), GetGenericCallbackResult(), GetTerrainType(), GetTileType(), GetTileZ(), GetWaterClass(), HasTileWaterClass(), IsTileType(), PlayTileSound(), TileHeight(), to_underlying(), Trees, and Water.

Referenced by AmbientSoundEffect().

◆ GetAiPurchaseCallbackResult()

std::pair< const GRFFile *, uint16_t > GetAiPurchaseCallbackResult ( GrfSpecFeature feature,
CargoType cargo_type,
uint8_t default_selection,
IndustryType src_industry,
IndustryType dst_industry,
uint8_t distance,
AIConstructionEvent event,
uint8_t count,
uint8_t station_size )

'Execute' an AI purchase selection callback

Parameters
featureGRF Feature to call callback for.
cargo_typeCargotype to pass to callback. (Variable 80)
default_selection'Default selection' to pass to callback. (Variable 82)
src_industry'Source industry type' to pass to callback. (Variable 83)
dst_industry'Destination industry type' to pass to callback. (Variable 84)
distance'Distance between source and destination' to pass to callback. (Variable 85)
event'AI construction event' to pass to callback. (Variable 86)
count'Construction number' to pass to callback. (Variable 87)
station_size'Station size' to pass to callback. (Variable 88)
Returns
answering GRFFile and callback value if successful, or CALLBACK_FAILED

Definition at line 202 of file newgrf_generic.cpp.

References CALLBACK_FAILED, CBID_GENERIC_AI_PURCHASE_SELECTION, GB(), GetGenericCallbackResult(), GetIndustrySpec(), IndustrySpec::grf_prop, IT_AI_TOWN, and IT_AI_UNKNOWN.

◆ GetGenericCallbackResult()

std::pair< const GRFFile *, uint16_t > GetGenericCallbackResult ( GrfSpecFeature feature,
ResolverObject & object,
uint32_t param1_grfv7,
uint32_t param1_grfv8,
std::span< int32_t > regs100 = {} )
static

Follow a generic feature callback list and return the first successful answer.

Parameters
featureGRF Feature of callback
objectpre-populated resolver object
param1_grfv7callback_param1 for GRFs up to version 7.
param1_grfv8callback_param1 for GRFs from version 8 on.
[out]regs100Additional result values from registers 100+
Returns
answering GRFFile and callback value if successful, or CALLBACK_FAILED

Definition at line 167 of file newgrf_generic.cpp.

Referenced by AmbientSoundEffectCallback(), and GetAiPurchaseCallbackResult().

◆ ResetGenericCallbacks()

void ResetGenericCallbacks ( )

Reset all generic feature callback sprite groups.

Definition at line 94 of file newgrf_generic.cpp.

Referenced by ResetNewGRFData().

Variable Documentation

◆ _gcl

GenericCallbackList _gcl[GSF_END]
static

Definition at line 88 of file newgrf_generic.cpp.