OpenTTD
Data Structures | Functions | Variables
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_class_func.h"
#include "newgrf_object.h"
#include "newgrf_sound.h"
#include "object_base.h"
#include "object_map.h"
#include "tile_cmd.h"
#include "town.h"
#include "water.h"
#include "newgrf_animation_base.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. More...
 
static uint32 GetObjectIDAtOffset (TileIndex tile, uint32 cur_grfid)
 Make an analysis of a tile and get the object type. More...
 
static uint32 GetNearbyObjectTileInformation (byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
 Based on newhouses equivalent, but adapted for newobjects. More...
 
static uint32 GetClosestObject (TileIndex tile, ObjectType type, const Object *current)
 Get the closest object of a given type. More...
 
static uint32 GetCountAndDistanceOfClosestInstance (byte local_id, uint32 grfid, TileIndex tile, const Object *current)
 Implementation of var 65. More...
 
uint16 GetObjectCallback (CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
 Perform a callback for an object. More...
 
static void DrawTileLayout (const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
 Draw an group of sprites on the map. 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 view)
 Draw representation of an object (tile) for GUI purposes. More...
 
uint16 StubGetObjectCallback (CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
 Perform a callback for an object. 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

ObjectOverrideManager _object_mngr (NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
 The override manager for our objects. More...
 
const ObjectSpec _original_objects [NEW_OBJECT_OFFSET]
 
ObjectSpec _object_specs [NUM_OBJECTS]
 All the object specifications. More...
 

Detailed Description

Handling of object NewGRFs.

Definition in file newgrf_object.cpp.

Function Documentation

◆ AnimateNewObjectTile()

void AnimateNewObjectTile ( TileIndex  tile)

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

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

◆ DrawNewObjectTileInGUI()

void DrawNewObjectTileInGUI ( int  x,
int  y,
const ObjectSpec spec,
uint8  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 455 of file newgrf_object.cpp.

◆ DrawTileLayout()

static void DrawTileLayout ( const TileInfo ti,
const TileLayoutSpriteGroup group,
const ObjectSpec spec 
)
static

Draw an group of sprites on the map.

Parameters
tiInformation about the tile to draw on.
groupThe group of sprites to draw.
specObject spec to draw.

Definition at line 411 of file newgrf_object.cpp.

References ObjectSpec::flags, OBJECT_FLAG_2CC_COLOUR, and TileLayoutSpriteGroup::ProcessRegisters().

◆ GetClosestObject()

static uint32 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 186 of file newgrf_object.cpp.

Referenced by GetCountAndDistanceOfClosestInstance().

◆ GetCountAndDistanceOfClosestInstance()

static uint32 GetCountAndDistanceOfClosestInstance ( byte  local_id,
uint32  grfid,
TileIndex  tile,
const Object current 
)
static

Implementation of var 65.

Parameters
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 207 of file newgrf_object.cpp.

References _object_mngr, GetClosestObject(), OverrideManagerBase::GetID(), GetRegister(), Object::GetTypeCount(), min(), and NUM_OBJECTS.

Referenced by ObjectScopeResolver::GetVariable().

◆ GetNearbyObjectTileInformation()

static uint32 GetNearbyObjectTileInformation ( byte  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 171 of file newgrf_object.cpp.

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

Referenced by ObjectScopeResolver::GetVariable().

◆ GetObjectCallback()

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

Definition at line 399 of file newgrf_object.cpp.

Referenced by StubGetObjectCallback().

◆ GetObjectIDAtOffset()

static uint32 GetObjectIDAtOffset ( TileIndex  tile,
uint32  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 142 of file newgrf_object.cpp.

References ObjectSpec::Get(), Object::GetByTile(), ObjectSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, IsTileType(), GRFFilePropsBase< Tcnt >::local_id, MP_OBJECT, Object::type, and Object::view.

Referenced by ObjectScopeResolver::GetVariable().

◆ ResetObjects()

void ResetObjects ( )

◆ StubGetObjectCallback()

uint16 StubGetObjectCallback ( CallbackID  callback,
uint32  param1,
uint32  param2,
const ObjectSpec spec,
Object o,
TileIndex  tile,
int  extra_data 
)

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.
extra_dataIgnored.
Returns
The result of the callback.

Definition at line 498 of file newgrf_object.cpp.

References GetObjectCallback().

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

References ObjectSpec::animation, HasBit(), Object::location, TILE_AREA_LOOP, 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 531 of file newgrf_object.cpp.

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

Referenced by TriggerObjectAnimation().

Variable Documentation

◆ _object_mngr

The override manager for our objects.

Referenced by FinaliseObjectsArray(), and GetCountAndDistanceOfClosestInstance().

◆ _object_specs

ObjectSpec _object_specs[NUM_OBJECTS]

All the object specifications.

Definition at line 34 of file newgrf_object.cpp.

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