OpenTTD Source: src/newgrf_generic.cpp File Reference

OpenTTD Source 14.0-beta3

Data Structures | Typedefs | Functions | Variables
newgrf_generic.cpp File Reference
`#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< GenericCallback > | GenericCallbackList

## Functions
void | ResetGenericCallbacks ()
| Reset all generic feature callback sprite groups.
void | AddGenericCallback (uint8_t feature, const GRFFile *file, const SpriteGroup *group)
| Add a generic feature callback sprite group to the appropriate feature list. More...
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. More...
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 More...
void | AmbientSoundEffectCallback (TileIndex tile)
| 'Execute' the ambient sound effect callback. More...

## Variables
static GenericCallbackList | _gcl [GSF_END]

## Detailed Description

Handling of generic feature callbacks.

Definition in file newgrf_generic.cpp.

## Function Documentation

## ◆ AddGenericCallback()

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

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

Parameters

  feature | The feature for the callback.
  file | The GRF of the callback.
  group | The 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

  tile | Tile the sound effect should be generated for.

Definition at line 242 of file newgrf_generic.cpp.

References _settings_client, SoundSettings::ambient, CBID_SOUNDS_AMBIENT_EFFECT, Chance16R(), IsTileType(), MP_CLEAR, MP_TREES, MP_WATER, and ClientSettings::sound.

## ◆ GetAiPurchaseCallbackResult()

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

Parameters

  | feature | GRF Feature to call callback for.
  | cargo_type | Cargotype 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)
  [out] | file | Optionally returns the GRFFile which made the final decision for the callback result. May be nullptr if not required.

Returns
  callback value if successful or CALLBACK_FAILED

Definition at line 206 of file newgrf_generic.cpp.

## ◆ GetGenericCallbackResult()

static uint16_t GetGenericCallbackResult | ( | uint8_t | feature,
|  | ResolverObject & | object,
|  | uint32_t | param1_grfv7,
|  | uint32_t | param1_grfv8,
|  | const GRFFile ** | file
| ) |  |
| static

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

Parameters

  | feature | GRF Feature of callback
  | object | pre-populated resolver object
  | param1_grfv7 | callback_param1 for GRFs up to version 7.
  | param1_grfv8 | callback_param1 for GRFs from version 8 on.
  [out] | file | Optionally returns the GRFFile which made the final decision for the callback result. May be nullptr if not required.

Returns
  callback value if successful or CALLBACK_FAILED

Definition at line 167 of file newgrf_generic.cpp.