OpenTTD Source: src/newgrf_generic.h File Reference

OpenTTD Source 15.3

Enumerations | Functions | Variables
newgrf_generic.h File Reference

Functions related to generic callbacks. More...

`#include "industry_type.h"`
`#include "newgrf.h"`
`#include "tile_type.h"`

Go to the source code of this file.

## Enumerations
enum | AIConstructionEvent : uint8_t { AICE_TRAIN_CHECK_RAIL_ENGINE = 0x00 , AICE_TRAIN_CHECK_ELRAIL_ENGINE = 0x01 , AICE_TRAIN_CHECK_MONORAIL_ENGINE = 0x02 , AICE_TRAIN_CHECK_MAGLEV_ENGINE = 0x03 , AICE_TRAIN_GET_RAIL_WAGON = 0x08 , AICE_TRAIN_GET_ELRAIL_WAGON = 0x09 , AICE_TRAIN_GET_MONORAIL_WAGON = 0x0A , AICE_TRAIN_GET_MAGLEV_WAGON = 0x0B , AICE_TRAIN_GET_RAILTYPE = 0x0F , AICE_ROAD_CHECK_ENGINE = 0x00 , AICE_ROAD_GET_FIRST_ENGINE = 0x01 , AICE_ROAD_GET_NUMBER_ENGINES = 0x02 , AICE_SHIP_CHECK_ENGINE = 0x00 , AICE_SHIP_GET_FIRST_ENGINE = 0x01 , AICE_SHIP_GET_NUMBER_ENGINES = 0x02 , AICE_AIRCRAFT_CHECK_ENGINE = 0x00 , AICE_STATION_GET_STATION_ID = 0x00 }
| AI events for asking the NewGRF for information. More...

## 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.
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.
void | AmbientSoundEffect (TileIndex tile)
| Play an ambient sound effect for an empty tile.

## Variables
static const IndustryType | IT_AI_UNKNOWN = 0xFE
| The AI has no specific industry in mind.
static const IndustryType | IT_AI_TOWN = 0xFF
| The AI actually wants to transport to/from a town, not an industry.

## Detailed Description

Functions related to generic callbacks.

Definition in file newgrf_generic.h.

## Enumeration Type Documentation

## ◆ AIConstructionEvent

enum AIConstructionEvent : uint8_t

AI events for asking the NewGRF for information.

Enumerator
AICE_TRAIN_CHECK_RAIL_ENGINE | Check if we should build an engine.
AICE_TRAIN_CHECK_ELRAIL_ENGINE | Check if we should build an engine.
AICE_TRAIN_CHECK_MONORAIL_ENGINE | Check if we should build an engine.
AICE_TRAIN_CHECK_MAGLEV_ENGINE | Check if we should build an engine.
AICE_TRAIN_GET_RAIL_WAGON | Check if we should build an engine.
AICE_TRAIN_GET_ELRAIL_WAGON | Check if we should build an engine.
AICE_TRAIN_GET_MONORAIL_WAGON | Check if we should build an engine.
AICE_TRAIN_GET_MAGLEV_WAGON | Check if we should build an engine.
AICE_TRAIN_GET_RAILTYPE | Check if we should build a railtype.
AICE_ROAD_CHECK_ENGINE | Check if we should build an engine.
AICE_ROAD_GET_FIRST_ENGINE | Unused, we check all.
AICE_ROAD_GET_NUMBER_ENGINES | Unused, we check all.
AICE_SHIP_CHECK_ENGINE | Check if we should build an engine.
AICE_SHIP_GET_FIRST_ENGINE | Unused, we check all.
AICE_SHIP_GET_NUMBER_ENGINES | Unused, we check all.
AICE_AIRCRAFT_CHECK_ENGINE | Check if we should build an engine.
AICE_STATION_GET_STATION_ID | Get a station ID to build.

Definition at line 20 of file newgrf_generic.h.

## 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

  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.

## ◆ AmbientSoundEffect()

void AmbientSoundEffect | ( | TileIndex | tile | ) |
| inline

Play an ambient sound effect for an empty tile.

Definition at line 54 of file newgrf_generic.h.

References AmbientSoundEffectCallback(), and HasGrfMiscBit().

Referenced by TileLoop_Water().

## ◆ AmbientSoundEffectCallback()

void AmbientSoundEffectCallback | ( | TileIndex | tile | ) |

'Execute' the ambient sound effect callback.

Parameters

  tile | Tile the sound effect should be generated for.

Definition at line 238 of file newgrf_generic.cpp.

References _settings_client, SoundSettings::ambient, CALLBACK_FAILED, CBID_SOUNDS_AMBIENT_EFFECT, Chance16R(), Clamp(), GB(), GetGenericCallbackResult(), GetTerrainType(), GetTileType(), GetTileZ(), GetWaterClass(), HasTileWaterClass(), IsTileType(), MP_CLEAR, MP_TREES, MP_WATER, PlayTileSound(), ClientSettings::sound, TileHeight(), and to_underlying().

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

  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)

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.

## ◆ ResetGenericCallbacks()

void ResetGenericCallbacks | ( |  | ) |

Reset all generic feature callback sprite groups.

Definition at line 94 of file newgrf_generic.cpp.

Referenced by ResetNewGRFData().

## Variable Documentation

## ◆ IT_AI_TOWN

const IndustryType IT_AI_TOWN = 0xFF
| static

The AI actually wants to transport to/from a town, not an industry.

Definition at line 45 of file newgrf_generic.h.

Referenced by GetAiPurchaseCallbackResult().

## ◆ IT_AI_UNKNOWN

const IndustryType IT_AI_UNKNOWN = 0xFE
| static

The AI has no specific industry in mind.

Definition at line 44 of file newgrf_generic.h.

Referenced by GetAiPurchaseCallbackResult().