OpenTTD Source  20241108-master-g80f628063a
newgrf_object.h File Reference

Functions related to NewGRF objects. More...

#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_class.h"
#include "newgrf_commons.h"

Go to the source code of this file.

Data Structures

struct  ObjectSpec
 Allow incrementing of ObjectClassID variables. More...
 
struct  ObjectScopeResolver
 Object scope resolver. More...
 
struct  ObjectResolverObject
 A resolver object to be used with feature 0F spritegroups. More...
 

Typedefs

using ObjectClass = NewGRFClass< ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX >
 Class containing information relating to object classes.
 

Enumerations

enum  ObjectFlags : uint16_t {
  OBJECT_FLAG_NONE = 0 , OBJECT_FLAG_ONLY_IN_SCENEDIT = 1 << 0 , OBJECT_FLAG_CANNOT_REMOVE = 1 << 1 , OBJECT_FLAG_AUTOREMOVE = 1 << 2 ,
  OBJECT_FLAG_BUILT_ON_WATER = 1 << 3 , OBJECT_FLAG_CLEAR_INCOME = 1 << 4 , OBJECT_FLAG_HAS_NO_FOUNDATION = 1 << 5 , OBJECT_FLAG_ANIMATION = 1 << 6 ,
  OBJECT_FLAG_ONLY_IN_GAME = 1 << 7 , OBJECT_FLAG_2CC_COLOUR = 1 << 8 , OBJECT_FLAG_NOT_ON_LAND = 1 << 9 , OBJECT_FLAG_DRAW_WATER = 1 << 10 ,
  OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11 , OBJECT_FLAG_ANIM_RANDOM_BITS = 1 << 12 , OBJECT_FLAG_SCALE_BY_WATER = 1 << 13
}
 Various object behaviours. More...
 
enum  ObjectClassID : uint16_t { OBJECT_CLASS_BEGIN = 0 , OBJECT_CLASS_MAX = UINT16_MAX , INVALID_OBJECT_CLASS = UINT16_MAX }
 Class IDs for objects. 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, uint8_t view=0)
 Perform a callback for an object. More...
 
void DrawNewObjectTile (TileInfo *ti, const ObjectSpec *spec)
 Draw an object on the map. More...
 
void DrawNewObjectTileInGUI (int x, int y, const ObjectSpec *spec, uint8_t view)
 Draw representation of an object (tile) for GUI purposes. More...
 
void AnimateNewObjectTile (TileIndex tile)
 Handle the animation of the object tile. More...
 
void TriggerObjectTileAnimation (Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a single tile. More...
 
void TriggerObjectAnimation (Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a whole object. More...
 

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.
 
static const size_t OBJECT_SPRITE_GROUP_DEFAULT = 0
 
static const size_t OBJECT_SPRITE_GROUP_PURCHASE = 1
 

Detailed Description

Functions related to NewGRF objects.

Definition in file newgrf_object.h.

Enumeration Type Documentation

◆ ObjectClassID

enum ObjectClassID : uint16_t

Class IDs for objects.

Enumerator
OBJECT_CLASS_BEGIN 

The lowest valid value.

OBJECT_CLASS_MAX 

Maximum number of classes.

INVALID_OBJECT_CLASS 

Class for the less fortunate.

Definition at line 48 of file newgrf_object.h.

◆ ObjectFlags

enum ObjectFlags : uint16_t

Various object behaviours.

Enumerator
OBJECT_FLAG_NONE 

Just nothing.

OBJECT_FLAG_ONLY_IN_SCENEDIT 

Object can only be constructed in the scenario editor.

OBJECT_FLAG_CANNOT_REMOVE 

Object can not be removed.

OBJECT_FLAG_AUTOREMOVE 

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

OBJECT_FLAG_BUILT_ON_WATER 

Object can be built on water (not required).

OBJECT_FLAG_CLEAR_INCOME 

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

OBJECT_FLAG_HAS_NO_FOUNDATION 

Do not display foundations when on a slope.

OBJECT_FLAG_ANIMATION 

Object has animated tiles.

OBJECT_FLAG_ONLY_IN_GAME 

Object can only be built in game.

OBJECT_FLAG_2CC_COLOUR 

Object wants 2CC colour mapping.

OBJECT_FLAG_NOT_ON_LAND 

Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.

OBJECT_FLAG_DRAW_WATER 

Object wants to be drawn on water.

OBJECT_FLAG_ALLOW_UNDER_BRIDGE 

Object can built under a bridge.

OBJECT_FLAG_ANIM_RANDOM_BITS 

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

OBJECT_FLAG_SCALE_BY_WATER 

Object count is roughly scaled by water amount at edges.

Definition at line 24 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 464 of file newgrf_object.cpp.

References Object::GetByTile(), SpriteGroup::Resolve(), and TileInfo::tile.

◆ DrawNewObjectTileInGUI()

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

Draw representation of an object (tile) for GUI purposes.

Parameters
xPosition x of image.
yPosition y of image.
specObject spec to draw.
viewThe object's view.

Definition at line 482 of file newgrf_object.cpp.

◆ GetObjectCallback()

uint16_t GetObjectCallback ( CallbackID  callback,
uint32_t  param1,
uint32_t  param2,
const ObjectSpec spec,
Object o,
TileIndex  tile,
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).
Returns
The result of the callback.

Definition at line 426 of file newgrf_object.cpp.

◆ TriggerObjectAnimation()

void 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 570 of file newgrf_object.cpp.

References ObjectSpec::animation, HasBit(), Object::location, TriggerObjectTileAnimation(), and AnimationInfo::triggers.

◆ TriggerObjectTileAnimation()

void 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 557 of file newgrf_object.cpp.

References ObjectSpec::animation, CBID_OBJECT_ANIMATION_START_STOP, AnimationBase< ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback, TileAnimationFrameAnimationHelper< Object > >::ChangeAnimationFrame(), HasBit(), and AnimationInfo::triggers.

Referenced by TriggerObjectAnimation().