OpenTTD Source 20260206-master-g4d4e37dbf1
newgrf_object.cpp File Reference

Handling of object NewGRFs. More...

#include "stdafx.h"
#include "company_base.h"
#include "company_func.h"
#include "debug.h"
#include "genworld.h"
#include "newgrf_badge.h"
#include "newgrf_object.h"
#include "newgrf_sound.h"
#include "object_base.h"
#include "object_map.h"
#include "timer/timer_game_calendar.h"
#include "tile_cmd.h"
#include "town.h"
#include "water.h"
#include "newgrf_animation_base.h"
#include "table/strings.h"
#include "newgrf_class_func.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  ObjectAnimationBase
 Helper class for animation control. More...

Functions

void ResetObjects ()
 This function initialize the spec arrays of objects.
static uint32_t GetObjectIDAtOffset (TileIndex tile, uint32_t cur_grfid)
 Make an analysis of a tile and get the object type.
static uint32_t GetNearbyObjectTileInformation (uint8_t parameter, TileIndex tile, ObjectID index, bool grf_version8)
 Based on newhouses equivalent, but adapted for newobjects.
static uint32_t GetClosestObject (TileIndex tile, ObjectType type, const Object *current)
 Get the closest object of a given type.
static uint32_t GetCountAndDistanceOfClosestInstance (const ResolverObject &object, uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current)
 Implementation of var 65.
uint16_t GetObjectCallback (CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span< int32_t > regs100, uint8_t view)
 Perform a callback for an object.
static void DrawTileLayout (const TileInfo *ti, const DrawTileSpriteSpan &dts, const ObjectSpec *spec)
 Draw an group of sprites on the map.
void DrawNewObjectTile (TileInfo *ti, const ObjectSpec *spec)
 Draw an object on the map.
void DrawNewObjectTileInGUI (int x, int y, const ObjectSpec *spec, uint8_t view)
 Draw representation of an object (tile) for GUI purposes.
uint16_t StubGetObjectCallback (CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, int)
 Perform a callback for an object.
void AnimateNewObjectTile (TileIndex tile)
 Handle the animation of the object tile.
static bool DoTriggerObjectTileAnimation (Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec, uint32_t random, uint32_t var18_extra=0)
bool TriggerObjectTileAnimation (Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a single tile.
bool TriggerObjectAnimation (Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a whole object.

Variables

ObjectOverrideManager _object_mngr (NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
 The override manager for our objects.
const ObjectSpec _original_objects [NEW_OBJECT_OFFSET]
std::vector< ObjectSpec_object_specs
 All the object specifications.

Detailed Description

Handling of object NewGRFs.

Definition in file newgrf_object.cpp.

Function Documentation

◆ AnimateNewObjectTile()

◆ DoTriggerObjectTileAnimation()

bool DoTriggerObjectTileAnimation ( Object * o,
TileIndex tile,
ObjectAnimationTrigger trigger,
const ObjectSpec * spec,
uint32_t random,
uint32_t var18_extra = 0 )
static

Definition at line 562 of file newgrf_object.cpp.

◆ DrawNewObjectTile()

void DrawNewObjectTile ( TileInfo * ti,
const ObjectSpec * spec )

Draw an object on the map.

Parameters
tiInformation about the tile to draw on.
specObject spec to draw.

Definition at line 473 of file newgrf_object.cpp.

References DrawTileLayout(), Object::GetByTile(), SpriteLayoutProcessor::GetLayout(), TileLayoutSpriteGroup::ProcessRegisters(), and TileInfo::tile.

◆ DrawNewObjectTileInGUI()

void DrawNewObjectTileInGUI ( int x,
int y,
const ObjectSpec * spec,
uint8_t view )

◆ DrawTileLayout()

void DrawTileLayout ( const TileInfo * ti,
const DrawTileSpriteSpan & dts,
const ObjectSpec * spec )
static

◆ GetClosestObject()

uint32_t GetClosestObject ( TileIndex tile,
ObjectType type,
const Object * current )
static

Get the closest object of a given type.

Parameters
tileThe tile to start searching from.
typeThe type of the object to search for.
currentThe current object (to ignore).
Returns
The distance to the closest object.

Definition at line 214 of file newgrf_object.cpp.

References DistanceManhattan().

Referenced by GetCountAndDistanceOfClosestInstance().

◆ GetCountAndDistanceOfClosestInstance()

uint32_t GetCountAndDistanceOfClosestInstance ( const ResolverObject & object,
uint8_t local_id,
uint32_t grfid,
TileIndex tile,
const Object * current )
static

Implementation of var 65.

Parameters
objectResolverObject owning the temporary storage.
local_idParameter given to the callback, which is the set id, or the local id, in our terminology.
grfidThe object's GRFID.
tileThe tile to look from.
currentObject for which the inquiry is made
Returns
The formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)

Definition at line 235 of file newgrf_object.cpp.

References ClampTo(), GetClosestObject(), Object::GetTypeCount(), and NUM_OBJECTS.

◆ GetNearbyObjectTileInformation()

uint32_t GetNearbyObjectTileInformation ( uint8_t parameter,
TileIndex tile,
ObjectID index,
bool grf_version8 )
static

Based on newhouses equivalent, but adapted for newobjects.

Parameters
parameterfrom callback. It's in fact a pair of coordinates
tileTileIndex from which the callback was initiated
indexof the object been queried for
grf_version8True, if we are dealing with a new NewGRF which uses GRF version >= 8.
Returns
a construction of bits obeying the newgrf format

Definition at line 199 of file newgrf_object.cpp.

References GetNearbyTile(), GetNearbyTileInformation(), GetObjectIndex(), IsTileType(), and Object.

Referenced by ObjectScopeResolver::GetVariable().

◆ GetObjectCallback()

uint16_t GetObjectCallback ( CallbackID callback,
uint32_t param1,
uint32_t param2,
const ObjectSpec * spec,
Object * o,
TileIndex tile,
std::span< int32_t > regs100,
uint8_t view )

Perform a callback for an object.

Parameters
callbackThe callback to perform.
param1The first parameter to pass to the NewGRF.
param2The second parameter to pass to the NewGRF.
specThe specification of the object / the entry point.
oThe object to call the callback for.
tileThe tile the callback is called for.
viewThe view of the object (only used when o == nullptr).
[out]regs100Additional result values from registers 100+
Returns
The result of the callback.

Definition at line 436 of file newgrf_object.cpp.

Referenced by BuildObject(), CmdBuildObject(), BuildObjectWindow::DrawWidget(), and StubGetObjectCallback().

◆ GetObjectIDAtOffset()

uint32_t GetObjectIDAtOffset ( TileIndex tile,
uint32_t cur_grfid )
static

Make an analysis of a tile and get the object type.

Parameters
tileTileIndex of the tile to query
cur_grfidGRFID of the current callback chain
Returns
value encoded as per NFO specs

Definition at line 170 of file newgrf_object.cpp.

References ObjectSpec::Get(), Object::GetByTile(), ObjectSpec::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::HasGrfFile(), IsTileType(), GRFFilePropsBase::local_id, Object, Object::type, and Object::view.

Referenced by ObjectScopeResolver::GetVariable().

◆ ResetObjects()

void ResetObjects ( )

◆ StubGetObjectCallback()

uint16_t StubGetObjectCallback ( CallbackID callback,
uint32_t param1,
uint32_t param2,
const ObjectSpec * spec,
Object * o,
TileIndex tile,
int  )

Perform a callback for an object.

Parameters
callbackThe callback to perform.
param1The first parameter to pass to the NewGRF.
param2The second parameter to pass to the NewGRF.
specThe specification of the object / the entry point.
oThe object to call the callback for.
tileThe tile the callback is called for.
Returns
The result of the callback.

Definition at line 536 of file newgrf_object.cpp.

References GetObjectCallback().

◆ TriggerObjectAnimation()

bool TriggerObjectAnimation ( Object * o,
ObjectAnimationTrigger trigger,
const ObjectSpec * spec )

Trigger the update of animation on a whole object.

Parameters
oThe object that got triggered.
triggerThe trigger that is triggered.
specThe spec associated with the object.

Definition at line 588 of file newgrf_object.cpp.

References ObjectSpec::animation, Object::location, and SB().

Referenced by BuildObject().

◆ TriggerObjectTileAnimation()

bool TriggerObjectTileAnimation ( Object * o,
TileIndex tile,
ObjectAnimationTrigger trigger,
const ObjectSpec * spec )

Trigger the update of animation on a single tile.

Parameters
oThe object that got triggered.
tileThe location of the triggered tile.
triggerThe trigger that is triggered.
specThe spec associated with the object.

Definition at line 577 of file newgrf_object.cpp.

Variable Documentation

◆ _object_specs

std::vector<ObjectSpec> _object_specs

All the object specifications.

Definition at line 37 of file newgrf_object.cpp.

Referenced by ObjectSpec::BindToClasses(), ObjectSpec::Get(), ObjectSpec::Index(), ResetObjects(), and ObjectOverrideManager::SetEntitySpec().