OpenTTD Source 20260801-master-g0de95fb529
newgrf_act2.cpp File Reference

NewGRF Action 0x02 handler. More...

#include "../stdafx.h"
#include <ranges>
#include "../debug.h"
#include "../newgrf_engine.h"
#include "../newgrf_cargo.h"
#include "../error.h"
#include "../vehicle_base.h"
#include "../road.h"
#include "newgrf_bytereader.h"
#include "newgrf_internal.h"
#include "table/strings.h"
#include "../safeguards.h"

Go to the source code of this file.

Typedefs

using CachedCallback = std::pair<uint16_t, SpriteGroupID>

Functions

void MapSpriteMappingRecolour (PalSpriteID *grf_sprite)
 Map the colour modifiers of TTDPatch to those that Open is using.
TileLayoutFlags ReadSpriteLayoutSprite (ByteReader &buf, bool read_flags, bool invert_action1_flag, bool use_cur_spritesets, GrfSpecFeature feature, PalSpriteID *grf_sprite, uint16_t *max_sprite_offset, uint16_t *max_palette_offset)
 Read a sprite and a palette from the GRF and convert them into a format suitable to OpenTTD.
static void ReadSpriteLayoutRegisters (ByteReader &buf, TileLayoutFlags flags, bool is_parent, NewGRFSpriteLayout *dts, uint index)
 Preprocess the TileLayoutFlags and read register modifiers from the GRF.
bool ReadSpriteLayout (ByteReader &buf, uint num_building_sprites, bool use_cur_spritesets, GrfSpecFeature feature, bool allow_var10, bool no_z_position, NewGRFSpriteLayout *dts)
 Read a spritelayout from the GRF.
void ResetCallbacks (bool final)
static const SpriteGroupGetCallbackResultGroup (uint16_t value)
static const SpriteGroupGetGroupFromGroupID (uint8_t setid, uint8_t type, uint16_t groupid)
static const SpriteGroupCreateGroupFromGroupID (GrfSpecFeature feature, uint8_t setid, uint8_t type, uint16_t spriteid)
 Helper function to either create a callback or a result sprite group.
static const SpriteGroupReadDeterministicSpriteGroup (ByteReader &buf, uint8_t setid, uint8_t type)
 Read a Deterministic SpriteGroup.
static const SpriteGroupReadRandomizedSpriteGroup (ByteReader &buf, GrfSpecFeature feature, uint8_t setid, uint8_t type)
 Read a Randomized SpriteGroup.
static const SpriteGroupReadRealSpriteGroup (ByteReader &buf, GrfSpecFeature feature, uint8_t setid, uint8_t type)
 Read a Real SpriteGroup.
static const SpriteGroupReadTileLayoutSpriteGroup (ByteReader &buf, GrfSpecFeature feature, uint8_t type)
 Read a Tile Layout SpriteGroup.
static const SpriteGroupReadIndustryProductionSpriteGroup (ByteReader &buf, uint8_t type)
 Read an Industry Production SpriteGroup.
static const SpriteGroupReadSpriteGroup (ByteReader &buf, GrfSpecFeature feature, uint8_t setid, uint8_t type)
 Read a SpriteGroup.
static void NewSpriteGroup (ByteReader &buf)

Variables

constexpr uint16_t GROUPID_CALLBACK_FAILED = 0x7FFF
 Explicit "failure" result.
constexpr uint16_t GROUPID_CALCULATED_RESULT = 0x7FFE
 Return calculated result from VarAction2.
static std::vector< CachedCallback > _cached_callback_groups
 Sorted list of cached callback result spritegroups.

Detailed Description

NewGRF Action 0x02 handler.

Definition in file newgrf_act2.cpp.

Typedef Documentation

◆ CachedCallback

using CachedCallback = std::pair<uint16_t, SpriteGroupID>

Definition at line 264 of file newgrf_act2.cpp.

Function Documentation

◆ CreateGroupFromGroupID()

const SpriteGroup * CreateGroupFromGroupID ( GrfSpecFeature feature,
uint8_t setid,
uint8_t type,
uint16_t spriteid )
static

Helper function to either create a callback or a result sprite group.

Parameters
featureGrfSpecFeature to define spritegroup for.
setidSetID of the currently being parsed Action2. (only for debug output)
typeType of the currently being parsed Action2. (only for debug output)
spriteidRaw value from the GRF for the new spritegroup; describes either the return value or the referenced spritegroup.
Returns
Created spritegroup.

Definition at line 317 of file newgrf_act2.cpp.

References HasBit().

Referenced by ReadRealSpriteGroup().

◆ GetCallbackResultGroup()

const SpriteGroup * GetCallbackResultGroup ( uint16_t value)
static

Definition at line 273 of file newgrf_act2.cpp.

◆ GetGroupFromGroupID()

const SpriteGroup * GetGroupFromGroupID ( uint8_t setid,
uint8_t type,
uint16_t groupid )
static

Definition at line 296 of file newgrf_act2.cpp.

◆ MapSpriteMappingRecolour()

void MapSpriteMappingRecolour ( PalSpriteID * grf_sprite)

Map the colour modifiers of TTDPatch to those that Open is using.

Parameters
grf_spritePointer to the structure been modified.

Definition at line 32 of file newgrf_act2.cpp.

References ClrBit(), HasBit(), PalSpriteID::pal, PALETTE_MODIFIER_COLOUR, PALETTE_MODIFIER_TRANSPARENT, SetBit(), PalSpriteID::sprite, and SPRITE_MODIFIER_OPAQUE.

Referenced by BridgeChangeInfo(), and ReadSpriteLayoutSprite().

◆ NewSpriteGroup()

void NewSpriteGroup ( ByteReader & buf)
static

Definition at line 759 of file newgrf_act2.cpp.

◆ ReadDeterministicSpriteGroup()

const SpriteGroup * ReadDeterministicSpriteGroup ( ByteReader & buf,
uint8_t setid,
uint8_t type )
static

Read a Deterministic SpriteGroup.

Parameters
bufInput stream.
setidSetID of the currently being parsed Action2. (only for debug output)
typeType of the currently being parsed Action2. (only for debug output)
Returns
The SpriteGroup.

Definition at line 343 of file newgrf_act2.cpp.

References Add, Byte, DeterministicSpriteGroup::default_result, DWord, DeterministicSpriteGroup::error_group, GB(), GROUPID_CALCULATED_RESULT, HasBit(), IsInsideMM(), None, DeterministicSpriteGroupAdjust::parameter, Parent, ByteReader::ReadByte(), ByteReader::ReadVarSize(), ByteReader::ReadWord(), Self, and Word.

Referenced by ReadSpriteGroup().

◆ ReadIndustryProductionSpriteGroup()

◆ ReadRandomizedSpriteGroup()

const SpriteGroup * ReadRandomizedSpriteGroup ( ByteReader & buf,
GrfSpecFeature feature,
uint8_t setid,
uint8_t type )
static

Read a Randomized SpriteGroup.

Parameters
bufInput stream.
featureGrfSpecFeature to define spritegroup for.
setidSetID of the currently being parsed Action2. (only for debug output)
typeType of the currently being parsed Action2. (only for debug output)
Returns
The SpriteGroup.

Definition at line 469 of file newgrf_act2.cpp.

References Aircraft, All, Any, RandomizedSpriteGroup::cmp_mode, GB(), RandomizedSpriteGroup::groups, HasBit(), HasExactlyOneBit(), RandomizedSpriteGroup::lowest_randbit, Parent, ByteReader::ReadByte(), ByteReader::ReadWord(), Relative, Self, and RandomizedSpriteGroup::var_scope.

Referenced by ReadSpriteGroup().

◆ ReadRealSpriteGroup()

const SpriteGroup * ReadRealSpriteGroup ( ByteReader & buf,
GrfSpecFeature feature,
uint8_t setid,
uint8_t type )
static

Read a Real SpriteGroup.

Parameters
bufInput stream.
featureGrfSpecFeature to define spritegroup for.
setidSetID of the currently being parsed Action2. (only for debug output)
typeType of the currently being parsed Action2.
Returns
The SpriteGroup.

Definition at line 507 of file newgrf_act2.cpp.

References CreateGroupFromGroupID(), RealSpriteGroup::loaded, RealSpriteGroup::loading, ByteReader::ReadByte(), and ByteReader::ReadWord().

Referenced by ReadSpriteGroup().

◆ ReadSpriteGroup()

const SpriteGroup * ReadSpriteGroup ( ByteReader & buf,
GrfSpecFeature feature,
uint8_t setid,
uint8_t type )
static

Read a SpriteGroup.

Parameters
bufInput stream.
featureGrfSpecFeature to define spritegroup for.
setidSetID of the currently being parsed Action2. (only for debug output)
typeType of the currently being parsed Action2. (only for debug output)
Returns
The SpriteGroup.

Definition at line 693 of file newgrf_act2.cpp.

References Aircraft, Airports, AirportTiles, Badges, Canals, Cargoes, End, Houses, Industries, IndustryTiles, Objects, RailTypes, ReadDeterministicSpriteGroup(), ReadIndustryProductionSpriteGroup(), ReadRandomizedSpriteGroup(), ReadRealSpriteGroup(), ReadTileLayoutSpriteGroup(), RoadStops, RoadTypes, RoadVehicles, Ships, Stations, Trains, and TramTypes.

◆ ReadSpriteLayout()

bool ReadSpriteLayout ( ByteReader & buf,
uint num_building_sprites,
bool use_cur_spritesets,
GrfSpecFeature feature,
bool allow_var10,
bool no_z_position,
NewGRFSpriteLayout * dts )

Read a spritelayout from the GRF.

Parameters
bufInput
num_building_spritesNumber of building sprites to read
use_cur_spritesetsWhether to use currently referenceable action 1 sets.
featureGrfSpecFeature to use spritesets from.
allow_var10Whether the spritelayout may specify var10 values for resolving multiple action-1-2-3 chains
no_z_positionWhether bounding boxes have no Z offset
dtsLayout container to output into
Returns
True on error (GRF was disabled).

Definition at line 174 of file newgrf_act2.cpp.

References NewGRFSpriteLayout::Allocate(), NewGRFSpriteLayout::AllocateRegisters(), ClrBit(), NewGRFSpriteLayout::consistent_max_offset, DisableGrf(), SpriteBounds::extent, DrawTileSprites::ground, HasBit(), DrawTileSeqStruct::IsParentSprite(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, SpriteBounds::origin, ByteReader::ReadByte(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), TLF_KNOWN_FLAGS, TLF_NON_GROUND_FLAGS, TLF_VAR10_FLAGS, Coord3D< T >::x, Coord3D< T >::y, and Coord3D< T >::z.

Referenced by ReadTileLayoutSpriteGroup(), and StationChangeInfo().

◆ ReadSpriteLayoutRegisters()

void ReadSpriteLayoutRegisters ( ByteReader & buf,
TileLayoutFlags flags,
bool is_parent,
NewGRFSpriteLayout * dts,
uint index )
static

◆ ReadSpriteLayoutSprite()

TileLayoutFlags ReadSpriteLayoutSprite ( ByteReader & buf,
bool read_flags,
bool invert_action1_flag,
bool use_cur_spritesets,
GrfSpecFeature feature,
PalSpriteID * grf_sprite,
uint16_t * max_sprite_offset,
uint16_t * max_palette_offset )

Read a sprite and a palette from the GRF and convert them into a format suitable to OpenTTD.

Parameters
bufInput stream.
read_flagsWhether to read TileLayoutFlags.
invert_action1_flagSet to true, if palette bit 15 means 'not from action 1'.
use_cur_spritesetsWhether to use currently referenceable action 1 sets.
featureGrfSpecFeature to use spritesets from.
[out]grf_spriteRead sprite and palette.
[out]max_sprite_offsetOptionally returns the number of sprites in the spriteset of the sprite. (0 if no spritset)
[out]max_palette_offsetOptionally returns the number of sprites in the spriteset of the palette. (0 if no spritset)
Returns
Read TileLayoutFlags.

Definition at line 63 of file newgrf_act2.cpp.

References ClrBit(), DisableGrf(), GB(), HasBit(), MapSpriteMappingRecolour(), PalSpriteID::pal, ByteReader::ReadWord(), SB(), SetBit(), SPR_IMG_QUERY, PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, SPRITE_WIDTH, TLF_CUSTOM_PALETTE, TLF_PALETTE_REG_FLAGS, TLF_PALETTE_VAR10, TLF_SPRITE_REG_FLAGS, and TLF_SPRITE_VAR10.

Referenced by ReadSpriteLayout(), and StationChangeInfo().

◆ ReadTileLayoutSpriteGroup()

const SpriteGroup * ReadTileLayoutSpriteGroup ( ByteReader & buf,
GrfSpecFeature feature,
uint8_t type )
static

Read a Tile Layout SpriteGroup.

Parameters
bufInput stream.
featureGrfSpecFeature to define spritegroup for.
typeType of the currently being parsed Action2. (only for debug output)
Returns
The SpriteGroup.

Definition at line 582 of file newgrf_act2.cpp.

References ReadSpriteLayout().

Referenced by ReadSpriteGroup().

◆ ResetCallbacks()

void ResetCallbacks ( bool final)

Definition at line 267 of file newgrf_act2.cpp.

Variable Documentation

◆ _cached_callback_groups

std::vector<CachedCallback> _cached_callback_groups
static

Sorted list of cached callback result spritegroups.

Definition at line 265 of file newgrf_act2.cpp.

◆ GROUPID_CALCULATED_RESULT

uint16_t GROUPID_CALCULATED_RESULT = 0x7FFE
constexpr

Return calculated result from VarAction2.

Definition at line 26 of file newgrf_act2.cpp.

Referenced by ReadDeterministicSpriteGroup().

◆ GROUPID_CALLBACK_FAILED

uint16_t GROUPID_CALLBACK_FAILED = 0x7FFF
constexpr

Explicit "failure" result.

Definition at line 25 of file newgrf_act2.cpp.