OpenTTD
Data Structures | Enumerations | Functions | Variables
newgrf_commons.h File Reference

This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities. More...

#include "sprite.h"
#include "core/alloc_type.hpp"
#include "core/smallvec_type.hpp"
#include "command_type.h"
#include "direction_type.h"
#include "company_type.h"

Go to the source code of this file.

Data Structures

struct  TileLayoutRegisters
 Additional modifiers for items in sprite layouts. More...
 
struct  NewGRFSpriteLayout
 NewGRF supplied spritelayout. More...
 
struct  EntityIDMapping
 Maps an entity id stored on the map to a GRF file. More...
 
class  OverrideManagerBase
 
class  HouseOverrideManager
 
class  IndustryOverrideManager
 
class  IndustryTileOverrideManager
 
class  AirportOverrideManager
 
class  AirportTileOverrideManager
 
class  ObjectOverrideManager
 
struct  GRFFilePropsBase< Tcnt >
 Data related to the handling of grf files. More...
 
struct  GRFFileProps
 Data related to the handling of grf files. More...
 

Enumerations

enum  TileContext { TCX_NORMAL, TCX_UPPER_HALFTILE, TCX_ON_BRIDGE }
 Context for tile accesses. More...
 
enum  TileLayoutFlags {
  TLF_NOTHING = 0x00, TLF_DODRAW = 0x01, TLF_SPRITE = 0x02, TLF_PALETTE = 0x04,
  TLF_CUSTOM_PALETTE = 0x08, TLF_BB_XY_OFFSET = 0x10, TLF_BB_Z_OFFSET = 0x20, TLF_CHILD_X_OFFSET = 0x10,
  TLF_CHILD_Y_OFFSET = 0x20, TLF_SPRITE_VAR10 = 0x40, TLF_PALETTE_VAR10 = 0x80, TLF_KNOWN_FLAGS = 0xFF,
  TLF_DRAWING_FLAGS = ~TLF_CUSTOM_PALETTE, TLF_NON_GROUND_FLAGS = TLF_BB_XY_OFFSET | TLF_BB_Z_OFFSET | TLF_CHILD_X_OFFSET | TLF_CHILD_Y_OFFSET, TLF_VAR10_FLAGS = TLF_SPRITE_VAR10 | TLF_PALETTE_VAR10, TLF_SPRITE_REG_FLAGS = TLF_DODRAW | TLF_SPRITE | TLF_BB_XY_OFFSET | TLF_BB_Z_OFFSET | TLF_CHILD_X_OFFSET | TLF_CHILD_Y_OFFSET,
  TLF_PALETTE_REG_FLAGS = TLF_PALETTE
}
 Flags to enable register usage in sprite layouts. More...
 

Functions

static uint GetConstructionStageOffset (uint construction_stage, uint num_sprites)
 Determines which sprite to use from a spriteset for a specific construction stage. More...
 
uint32 GetTerrainType (TileIndex tile, TileContext context=TCX_NORMAL)
 Function used by houses (and soon industries) to get information on type of "terrain" the tile it is queries sits on. More...
 
TileIndex GetNearbyTile (byte parameter, TileIndex tile, bool signed_offsets=true, Axis axis=INVALID_AXIS)
 Get the tile at the given offset. More...
 
uint32 GetNearbyTileInformation (TileIndex tile, bool grf_version8)
 Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62. More...
 
uint32 GetCompanyInfo (CompanyID owner, const struct Livery *l=NULL)
 
CommandCost GetErrorMessageFromLocationCallbackResult (uint16 cb_res, const GRFFile *grffile, StringID default_error)
 Get the error message from a shape/location/slope check callback result. More...
 
void ErrorUnknownCallbackResult (uint32 grfid, uint16 cbid, uint16 cb_res)
 Record that a NewGRF returned an unknown/invalid callback result. More...
 
bool ConvertBooleanCallback (const struct GRFFile *grffile, uint16 cbid, uint16 cb_res)
 
bool Convert8bitBooleanCallback (const struct GRFFile *grffile, uint16 cbid, uint16 cb_res)
 

Variables

static const uint TLR_MAX_VAR10 = 7
 Maximum value for var 10.
 
HouseOverrideManager _house_mngr
 
IndustryOverrideManager _industry_mngr
 
IndustryTileOverrideManager _industile_mngr
 
AirportOverrideManager _airport_mngr
 
AirportTileOverrideManager _airporttile_mngr
 
ObjectOverrideManager _object_mngr
 The override manager for our objects. More...
 

Detailed Description

This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities.

Definition in file newgrf_commons.h.

Enumeration Type Documentation

◆ TileContext

Context for tile accesses.

Enumerator
TCX_NORMAL 

Nothing special.

TCX_UPPER_HALFTILE 

Querying information about the upper part of a tile with halftile foundation.

TCX_ON_BRIDGE 

Querying information about stuff on the bridge (via some bridgehead).

Definition at line 26 of file newgrf_commons.h.

◆ TileLayoutFlags

Flags to enable register usage in sprite layouts.

Enumerator
TLF_DODRAW 

Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.

TLF_SPRITE 

Add signed offset to sprite from register TileLayoutRegisters::sprite.

TLF_PALETTE 

Add signed offset to palette from register TileLayoutRegisters::palette.

TLF_CUSTOM_PALETTE 

Palette is from Action 1 (moved to SPRITE_MODIFIER_CUSTOM_SPRITE in palette during loading).

TLF_BB_XY_OFFSET 

Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta.parent[0..1].

TLF_BB_Z_OFFSET 

Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta.parent[2].

TLF_CHILD_X_OFFSET 

Add signed offset to child sprite X positions from register TileLayoutRegisters::delta.child[0].

TLF_CHILD_Y_OFFSET 

Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta.child[1].

TLF_SPRITE_VAR10 

Resolve sprite with a specific value in variable 10.

TLF_PALETTE_VAR10 

Resolve palette with a specific value in variable 10.

TLF_KNOWN_FLAGS 

Known flags. Any unknown set flag will disable the GRF.

TLF_DRAWING_FLAGS 

Flags which are still required after loading the GRF.

TLF_NON_GROUND_FLAGS 

Flags which do not work for the (first) ground sprite.

TLF_VAR10_FLAGS 

Flags which refer to using multiple action-1-2-3 chains.

TLF_SPRITE_REG_FLAGS 

Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite.

TLF_PALETTE_REG_FLAGS 

Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palette.

Definition at line 35 of file newgrf_commons.h.

Function Documentation

◆ ErrorUnknownCallbackResult()

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
grfidID of the NewGRF causing the problem.
cbidCallback causing the problem.
cb_resInvalid result returned by the callback.

Definition at line 518 of file newgrf_commons.cpp.

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

Referenced by CheckTrainAttachment(), GetAirportTextCallback(), GetIndustryProbabilityCallback(), and Vehicle::UpdateVisualEffect().

◆ GetConstructionStageOffset()

static uint GetConstructionStageOffset ( uint  construction_stage,
uint  num_sprites 
)
inlinestatic

Determines which sprite to use from a spriteset for a specific construction stage.

Parameters
construction_stageConstruction stage 0 - 3.
num_spritesNumber of available sprites to select stage from.
Returns
Sprite to use

Definition at line 77 of file newgrf_commons.h.

Referenced by TileLayoutSpriteGroup::ProcessRegisters().

◆ GetErrorMessageFromLocationCallbackResult()

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_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 482 of file newgrf_commons.cpp.

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

◆ GetNearbyTile()

TileIndex GetNearbyTile ( byte  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 425 of file newgrf_commons.cpp.

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

◆ GetNearbyTileInformation()

uint32 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 448 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(), and GetNearbyObjectTileInformation().

◆ GetTerrainType()

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
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 350 of file newgrf_commons.cpp.

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

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

Variable Documentation

◆ _object_mngr

ObjectOverrideManager _object_mngr

The override manager for our objects.

Referenced by FinaliseObjectsArray(), and GetCountAndDistanceOfClosestInstance().