OpenTTD Source  20240915-master-g3784a3d3d6
newgrf_commons.cpp File Reference
#include "stdafx.h"
#include "debug.h"
#include "landscape.h"
#include "house.h"
#include "industrytype.h"
#include "newgrf_config.h"
#include "clear_map.h"
#include "station_map.h"
#include "tree_map.h"
#include "tunnelbridge_map.h"
#include "newgrf_object.h"
#include "genworld.h"
#include "newgrf_spritegroup.h"
#include "newgrf_text.h"
#include "company_base.h"
#include "error.h"
#include "strings_func.h"
#include "string_func.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

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 queries sits on. More...
 
TileIndex GetNearbyTile (uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
 Get the tile at the given offset. More...
 
uint32_t GetNearbyTileInformation (TileIndex tile, bool grf_version8)
 Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62. More...
 
uint32_t GetCompanyInfo (CompanyID owner, const Livery *l)
 Returns company information like in vehicle var 43 or station var 43. More...
 
CommandCost GetErrorMessageFromLocationCallbackResult (uint16_t cb_res, const GRFFile *grffile, StringID default_error)
 Get the error message from a shape/location/slope check callback result. More...
 
void ErrorUnknownCallbackResult (uint32_t grfid, uint16_t cbid, uint16_t cb_res)
 Record that a NewGRF returned an unknown/invalid callback result. More...
 
bool ConvertBooleanCallback (const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
 Converts a callback result into a boolean. More...
 
bool Convert8bitBooleanCallback (const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
 Converts a callback result into a boolean. More...
 

Detailed Description

Implementation of the class OverrideManagerBase and its descendance, present and future.

Definition in file newgrf_commons.cpp.

Function Documentation

◆ Convert8bitBooleanCallback()

bool Convert8bitBooleanCallback ( const GRFFile grffile,
uint16_t  cbid,
uint16_t  cb_res 
)

Converts a callback result into a boolean.

For grf version < 8 the first 8 bit of the result are checked for zero or non-zero. For grf version >= 8 the callback result must be 0 or 1.

Parameters
grffileNewGRF returning the value.
cbidCallback returning the value.
cb_resCallback result.
Returns
Boolean value. True if cb_res != 0.

Definition at line 554 of file newgrf_commons.cpp.

◆ ConvertBooleanCallback()

bool ConvertBooleanCallback ( const GRFFile grffile,
uint16_t  cbid,
uint16_t  cb_res 
)

Converts a callback result into a boolean.

For grf version < 8 the result is checked for zero or non-zero. For grf version >= 8 the callback result must be 0 or 1.

Parameters
grffileNewGRF returning the value.
cbidCallback returning the value.
cb_resCallback result.
Returns
Boolean value. True if cb_res != 0.

Definition at line 535 of file newgrf_commons.cpp.

◆ ErrorUnknownCallbackResult()

void ErrorUnknownCallbackResult ( uint32_t  grfid,
uint16_t  cbid,
uint16_t  cb_res 
)

Record that a NewGRF returned an unknown/invalid callback result.

Also show an error to the user.

Parameters
grfidID of the NewGRF causing the problem.
cbidCallback causing the problem.
cb_resInvalid result returned by the callback.

Definition at line 505 of file newgrf_commons.cpp.

◆ GetCompanyInfo()

uint32_t GetCompanyInfo ( CompanyID  owner,
const Livery l 
)

Returns company information like in vehicle var 43 or station var 43.

Parameters
ownerOwner of the object.
lLivery of the object; nullptr to use default.
Returns
NewGRF company information.

Definition at line 456 of file newgrf_commons.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

Referenced by VehicleScopeResolver::GetVariable(), and StationScopeResolver::GetVariable().

◆ GetErrorMessageFromLocationCallbackResult()

CommandCost GetErrorMessageFromLocationCallbackResult ( uint16_t  cb_res,
const GRFFile grffile,
StringID  default_error 
)

Get the error message from a shape/location/slope check callback result.

Parameters
cb_resCallback result to translate. If bit 10 is set this is a standard error message, otherwise a NewGRF provided string.
grffileNewGRF to use to resolve a custom error message.
default_errorError message to use for the generic error.
Returns
CommandCost indicating success or the error message.

Definition at line 469 of file newgrf_commons.cpp.

◆ GetNearbyTile()

TileIndex GetNearbyTile ( uint8_t  parameter,
TileIndex  tile,
bool  signed_offsets,
Axis  axis 
)

Get the tile at the given offset.

Parameters
parameterThe NewGRF "encoded" offset.
tileThe tile to base the offset from.
signed_offsetsWhether the offsets are to be interpreted as signed or not.
axisAxis of a railways station.
Returns
The tile at the offset.

Definition at line 410 of file newgrf_commons.cpp.

Referenced by GetNearbyAirportTileInformation(), GetNearbyIndustryTileInformation(), GetNearbyObjectTileInformation(), GetNearbyTileInformation(), AirportTileScopeResolver::GetVariable(), StationScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().

◆ GetNearbyTileInformation()

uint32_t GetNearbyTileInformation ( TileIndex  tile,
bool  grf_version8 
)

Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.

Parameters
tilethe tile of interest.
grf_version8True, if we are dealing with a new NewGRF which uses GRF version >= 8.
Returns
0czzbbss: c = TileType; zz = TileZ; bb: 7-3 zero, 4-2 TerrainType, 1 water/shore, 0 zero; ss = TileSlope

Definition at line 433 of file newgrf_commons.cpp.

References GetTerrainType(), GetTilePixelSlope(), GetTileType(), GetTreeGround(), GetWaterClass(), HasTileWaterClass(), IsRoadWaypointTile(), IsTileType(), MP_ROAD, MP_TREES, MP_WATER, TILE_HEIGHT, and TREE_GROUND_SHORE.

Referenced by GetNearbyAirportTileInformation(), GetNearbyIndustryTileInformation(), and GetNearbyObjectTileInformation().

◆ GetTerrainType()

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 queries sits on.

Parameters
tileTileIndex of the tile been queried
contextThe context of the tile.
Returns
value corresponding to the grf expected format: Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline

Definition at line 335 of file newgrf_commons.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.

Referenced by GetNearbyTileInformation(), CanalScopeResolver::GetVariable(), IndustryTileScopeResolver::GetVariable(), IndustriesScopeResolver::GetVariable(), AirportTileScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().