Functions

# newgrf_commons.cpp File Reference

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

`#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 "table/strings.h"`

Go to the source code of this file.

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

## Detailed Description

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

Definition in file newgrf_commons.cpp.

## Function Documentation

bool Convert8bitBooleanCallback | ( | const GRFFile * | grffile,
|  | uint16 | cbid,
|  | uint16 | 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:

  | grffile | NewGRF returning the value.
  | cbid | Callback returning the value.
  | cb_res | Callback result.

Returns:
  Boolean value. True if cb_res != 0.

Definition at line 569 of file newgrf_commons.cpp.

References CALLBACK_FAILED, ErrorUnknownCallbackResult(), and GB().

Referenced by BuildTownHouse(), CmdBuildRailStation(), and IsStationAvailable().

bool ConvertBooleanCallback | ( | const GRFFile * | grffile,
|  | uint16 | cbid,
|  | uint16 | 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:

  | grffile | NewGRF returning the value.
  | cbid | Callback returning the value.
  | cb_res | Callback result.

Returns:
  Boolean value. True if cb_res != 0.

Definition at line 550 of file newgrf_commons.cpp.

References CALLBACK_FAILED, and ErrorUnknownCallbackResult().

Referenced by GetFoundation_Town(), and IndustryTemporarilyRefusesCargo().

void ErrorUnknownCallbackResult | ( | uint32 | grfid,
|  | uint16 | cbid,
|  | uint16 | cb_res |
| ) |  |  |

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

Also show an error to the user.

Parameters:

  | grfid | ID of the NewGRF causing the problem.
  | cbid | Callback causing the problem.
  | cb_res | Invalid result returned by the callback.

Definition at line 516 of file newgrf_commons.cpp.

References DEBUG, GBUG_UNKNOWN_CB_RESULT, GetGRFConfig(), GRFConfig::GetName(), GRFConfig::grf_bugs, HasBit(), lastof, SetBit(), SetDParam(), SetDParamStr(), ShowErrorMessage(), and WL_CRITICAL.

Referenced by AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::AnimateTile(), BuildObject(), CheckTrainAttachment(), CmdBuildRailStation(), Train::ConsistChanged(), Convert8bitBooleanCallback(), ConvertBooleanCallback(), DoCreateNewIndustry(), IndustryViewWindow::DrawInfo(), BuildObjectWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), GetAirportTextCallback(), GetCargoSubtypeText(), GetCargoSuffix(), GetIndustryProbabilityCallback(), GetLoadAmount(), GetRoadVehLength(), RunVehicleDayProc(), ShowAdditionalText(), and Vehicle::UpdateVisualEffect().

uint32 GetCompanyInfo | ( | CompanyID | owner,
|  | const Livery * | l |
| ) |  |  |

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

Parameters:

  | owner | Owner of the object.
  | l | Livery of the object; NULL to use default.

Returns:
  NewGRF company information.

Definition at line 467 of file newgrf_commons.cpp.

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

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

CommandCost GetErrorMessageFromLocationCallbackResult | ( | uint16 | cb_res,
|  | const GRFFile * | grffile,
|  | StringID | default_error |
| ) |  |  |

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

Parameters:

  | cb_res | Callback result to translate. If bit 10 is set this is a standard error message, otherwise a NewGRF provided string.
  | grffile | NewGRF to use to resolve a custom error message.
  | default_error | Error message to use for the generic error.

Returns:
  CommandCost indicating success or the error message.

Definition at line 480 of file newgrf_commons.cpp.

References GetGRFStringID(), and CommandCost::UseTextRefStack().

Referenced by CheckIfCallBackAllowsCreation(), CmdBuildObject(), PerformIndustryTileSlopeCheck(), and PerformStationTileSlopeCheck().

TileIndex GetNearbyTile | ( | byte | parameter,
|  | TileIndex | tile,
|  | bool | signed_offsets,
|  | Axis | axis |
| ) |  |  |

Get the tile at the given offset.

Parameters:

  | parameter | The NewGRF "encoded" offset.
  | tile | The tile to base the offset from.
  | signed_offsets | Whether the offsets are to be interpreted as signed or not.
  | axis | Axis of a railways station.

Returns:
  The tile at the offset.

Definition at line 423 of file newgrf_commons.cpp.

References AXIS_Y, GB(), GetRailStationAxis(), HasStationTileRail(), INVALID_AXIS, Swap(), TILE_MASK, and TileDiffXY().

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

uint32 GetNearbyTileInformation | ( | TileIndex | tile,
|  | bool | grf_version8 |
| ) |  |  |

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

Parameters:

  | tile | the tile of interest.
  | grf_version8 | True, 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 446 of file newgrf_commons.cpp.

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

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

uint32 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:

  | tile | TileIndex of the tile been queried
  | context | The 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 348 of file newgrf_commons.cpp.

References _generating_world, _settings_game, GameSettings::game_creation, GetBridgeHeight(), GetClearDensity(), GetSnowLine(), GetTileMaxZ(), GetTileType(), GetTileZ(), GetTreeDensity(), GetTreeGround(), GetTropicZone(), HasTunnelBridgeSnowOrDesert(), IsOnSnow(), IsSnowTile(), GameCreationSettings::landscape, MP_CLEAR, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_RAILWAY, MP_ROAD, MP_STATION, MP_TREES, MP_TUNNELBRIDGE, MP_VOID, MP_WATER, RAIL_GROUND_ICE_DESERT, TCX_ON_BRIDGE, TCX_UPPER_HALFTILE, and TREE_GROUND_SNOW_DESERT.

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