OpenTTD Source 20260206-master-g4d4e37dbf1
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 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().

◆ 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 337 of file newgrf_act2.cpp.

◆ 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 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(), 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().

◆ 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.

◆ GROUPID_CALLBACK_FAILED

uint16_t GROUPID_CALLBACK_FAILED = 0x7FFF
constexpr

Explicit "failure" result.

Definition at line 25 of file newgrf_act2.cpp.