OpenTTD Source 20250331-master-g3c15e0c889
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, int 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, uint8_t 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 (uint8_t 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

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

Function Documentation

◆ CreateGroupFromGroupID()

static const SpriteGroup * CreateGroupFromGroupID ( uint8_t  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 313 of file newgrf_act2.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_spritegroup_pool >::CanAllocateItem(), GrfProcessingState::GetNumEnts(), GrfProcessingState::GetSprite(), HasBit(), GrfProcessingState::IsValidSpriteSet(), and GrfProcessingState::spriteid.

◆ GetCallbackResultGroup()

static const SpriteGroup * GetCallbackResultGroup ( uint16_t  value)
static

Definition at line 270 of file newgrf_act2.cpp.

◆ GetGroupFromGroupID()

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

Definition at line 293 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 29 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 ReadSpriteLayoutSprite().

◆ NewSpriteGroup()

static void NewSpriteGroup ( ByteReader buf)
static

Definition at line 333 of file newgrf_act2.cpp.

◆ ReadSpriteLayout()

bool ReadSpriteLayout ( ByteReader buf,
uint  num_building_sprites,
bool  use_cur_spritesets,
uint8_t  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 171 of file newgrf_act2.cpp.

References NewGRFSpriteLayout::Allocate(), NewGRFSpriteLayout::AllocateRegisters(), ClrBit(), NewGRFSpriteLayout::consistent_max_offset, DrawTileSeqStruct::delta_z, DisableGrf(), DrawTileSprites::ground, HasBit(), DrawTileSeqStruct::IsParentSprite(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, ByteReader::ReadByte(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), GrfProcessingState::skip_sprites, TLF_KNOWN_FLAGS, and TLF_NON_GROUND_FLAGS.

Referenced by StationChangeInfo().

◆ ReadSpriteLayoutRegisters()

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

Preprocess the TileLayoutFlags and read register modifiers from the GRF.

Parameters
bufInput stream.
flagsTileLayoutFlags to process.
is_parentWhether the sprite is a parentsprite with a bounding box.
dtsSprite layout to insert data into.
indexSprite index to process; 0 for ground sprite.

Definition at line 118 of file newgrf_act2.cpp.

References NewGRFSpriteLayout::AllocateRegisters(), TileLayoutRegisters::child, DisableGrf(), TileLayoutRegisters::dodraw, TileLayoutRegisters::flags, TileLayoutRegisters::palette, TileLayoutRegisters::palette_var10, TileLayoutRegisters::parent, ByteReader::ReadByte(), TileLayoutRegisters::sprite, TileLayoutRegisters::sprite_var10, TLF_BB_XY_OFFSET, TLF_BB_Z_OFFSET, TLF_CHILD_X_OFFSET, TLF_CHILD_Y_OFFSET, TLF_DODRAW, TLF_DRAWING_FLAGS, TLF_PALETTE, TLF_PALETTE_VAR10, TLF_SPRITE, TLF_SPRITE_VAR10, and TLR_MAX_VAR10.

Referenced by ReadSpriteLayout().

◆ ReadSpriteLayoutSprite()

TileLayoutFlags ReadSpriteLayoutSprite ( ByteReader buf,
bool  read_flags,
bool  invert_action1_flag,
bool  use_cur_spritesets,
int  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 60 of file newgrf_act2.cpp.

References ClrBit(), DisableGrf(), GB(), GrfProcessingState::GetNumEnts(), GrfProcessingState::GetSprite(), HasBit(), GrfProcessingState::IsValidSpriteSet(), 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 264 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 262 of file newgrf_act2.cpp.