OpenTTD Source 20260311-master-g511d3794ce
newgrf_object.h File Reference

Functions related to NewGRF objects. More...

#include "core/pool_type.hpp"
#include "newgrf_callbacks.h"
#include "newgrf_spritegroup.h"
#include "newgrf_town.h"
#include "economy_func.h"
#include "timer/timer_game_calendar.h"
#include "object_type.h"
#include "newgrf_animation_type.h"
#include "newgrf_badge_type.h"
#include "newgrf_class.h"
#include "newgrf_commons.h"

Go to the source code of this file.

Data Structures

struct  ObjectSpec
 An object that isn't use for transport, industries or houses. More...
struct  ObjectScopeResolver
 Object scope resolver. More...
struct  ObjectResolverObject
 A resolver object to be used with feature 0F spritegroups. More...

Typedefs

using ObjectFlags = EnumBitSet<ObjectFlag, uint16_t>
using ObjectClassID = PoolID<uint16_t, struct ObjectClassIDTag, UINT16_MAX, UINT16_MAX>
 Class IDs for objects.
using ObjectClass = NewGRFClass<ObjectSpec, ObjectClassID>
 Class containing information relating to object classes.

Enumerations

enum class  ObjectFlag : uint8_t {
  OnlyInScenedit = 0 , CannotRemove = 1 , Autoremove = 2 , BuiltOnWater = 3 ,
  ClearIncome = 4 , HasNoFoundation = 5 , Animation = 6 , OnlyInGame = 7 ,
  Uses2CC = 8 , NotOnLand = 9 , DrawWater = 10 , AllowUnderBridge = 11 ,
  AnimRandomBits = 12 , ScaleByWater = 13
}
 Various object behaviours. More...

Functions

void ResetObjects ()
 This function initialize the spec arrays of objects.
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=0)
 Perform a callback for an object.
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.
void AnimateNewObjectTile (TileIndex tile)
 Handle the animation of the object tile.
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

static const uint8_t OBJECT_SIZE_1X1 = 0x11
 The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X, high nibble for Y.

Detailed Description

Functions related to NewGRF objects.

Definition in file newgrf_object.h.

Typedef Documentation

◆ ObjectClass

Class containing information relating to object classes.

Definition at line 162 of file newgrf_object.h.

◆ ObjectClassID

using ObjectClassID = PoolID<uint16_t, struct ObjectClassIDTag, UINT16_MAX, UINT16_MAX>

Class IDs for objects.

Definition at line 49 of file newgrf_object.h.

◆ ObjectFlags

using ObjectFlags = EnumBitSet<ObjectFlag, uint16_t>

Definition at line 42 of file newgrf_object.h.

Enumeration Type Documentation

◆ ObjectFlag

enum class ObjectFlag : uint8_t
strong

Various object behaviours.

Enumerator
OnlyInScenedit 

Object can only be constructed in the scenario editor.

CannotRemove 

Object can not be removed.

Autoremove 

Object get automatically removed (like "owned land").

BuiltOnWater 

Object can be built on water (not required).

ClearIncome 

When object is cleared a positive income is generated instead of a cost.

HasNoFoundation 

Do not display foundations when on a slope.

Animation 

Object has animated tiles.

OnlyInGame 

Object can only be built in game.

Uses2CC 

Object wants 2CC colour mapping.

NotOnLand 

Object can not be on land, implicitly sets ObjectFlag::BuiltOnWater.

DrawWater 

Object wants to be drawn on water.

AllowUnderBridge 

Object can built under a bridge.

AnimRandomBits 

Object wants random bits in "next animation frame" callback.

ScaleByWater 

Object count is roughly scaled by water amount at edges.

Definition at line 26 of file newgrf_object.h.

Function Documentation

◆ AnimateNewObjectTile()

◆ 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 472 of file newgrf_object.cpp.

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

Referenced by DrawTile_Object().

◆ DrawNewObjectTileInGUI()

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

◆ 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 435 of file newgrf_object.cpp.

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

◆ ResetObjects()

void ResetObjects ( )

This function initialize the spec arrays of objects.

Definition at line 125 of file newgrf_object.cpp.

References _object_specs, NewGRFClass< ObjectSpec, ObjectClassID >::Allocate(), ObjectSpec::grf_prop, lengthof, GRFFilePropsBase::local_id, OBJECT_LIGHTHOUSE, and OBJECT_TRANSMITTER.

Referenced by ResetNewGRFData().

◆ 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.
Returns
true iff all tiles of the object had an animation trigger set.

Definition at line 589 of file newgrf_object.cpp.

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

Referenced by BuildObject(), and TileLoop_Object().

◆ 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.
Returns
true iff the object has an animation trigger set.

Definition at line 577 of file newgrf_object.cpp.

Referenced by TileLoop_Object().

Variable Documentation

◆ OBJECT_SIZE_1X1

const uint8_t OBJECT_SIZE_1X1 = 0x11
static

The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X, high nibble for Y.

Definition at line 44 of file newgrf_object.h.

Referenced by CmdBuildObjectArea(), ObjectChangeInfo(), and BuildObjectWindow::OnPlaceObject().