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 "newgrf.h"
#include "newgrf_class_func.h"
#include "newgrf_object.h"
#include "newgrf_sound.h"
#include "newgrf_spritegroup.h"
#include "newgrf_town.h"
#include "object_base.h"
#include "object_map.h"
#include "sprite.h"
#include "town.h"
#include "viewport_func.h"
#include "water.h"
#include "newgrf_animation_base.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 ObjectGetRandomBits (const ResolverObject *object)
static uint32 ObjectGetTriggers (const ResolverObject *object)
static void ObjectSetTriggers (const ResolverObject *object, int triggers)
static uint32 GetObjectIDAtOffset (TileIndex tile, uint32 cur_grfid)
 Make an analysis of a tile and get the object type.
static uint32 GetNearbyObjectTileInformation (byte parameter, TileIndex tile, ObjectID index)
 Based on newhouses equivalent, but adapted for newobjects.
static uint32 GetClosestObject (TileIndex tile, ObjectType type, const Object *current)
 Get the closest object of a given type.
static uint32 GetCountAndDistanceOfClosestInstance (byte local_id, uint32 grfid, TileIndex tile, const Object *current)
 Implementation of var 65.
static uint32 ObjectGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
 Used by the resolver to get values for feature 0F deterministic spritegroups.
static const SpriteGroupObjectResolveReal (const ResolverObject *object, const RealSpriteGroup *group)
static const SpriteGroupGetObjectSpriteGroup (const ObjectSpec *spec, const Object *o)
 Get the object's sprite group.
static void NewObjectResolver (ResolverObject *res, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view=0)
 Returns a resolver object to be used with feature 0F spritegroups.
uint16 GetObjectCallback (CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view)
 Perform a callback for an object.
static void DrawTileLayout (const TileInfo *ti, const TileLayoutSpriteGroup *group, 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 view)
 Draw representation of an object (tile) for GUI purposes.
uint16 StubGetObjectCallback (CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile)
 Perform a callback for an object.
void AnimateNewObjectTile (TileIndex tile)
 Handle the animation of the object tile.
void TriggerObjectTileAnimation (const Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a single tile.
void TriggerObjectAnimation (const Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 Trigger the update of animation on a whole object.
void GetObjectResolver (ResolverObject *ro, uint index)
 Resolve an object's spec and such so we can get a variable.

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]
ObjectSpec _object_specs [NUM_OBJECTS]
 All the object specifications.

Detailed Description

Handling of object NewGRFs.

Definition in file newgrf_object.cpp.


Function Documentation

void AnimateNewObjectTile ( TileIndex  tile  ) 
void DrawNewObjectTile ( TileInfo ti,
const ObjectSpec spec 
)

Draw an object on the map.

Parameters:
ti Information about the tile to draw on.
spec Object spec to draw.

Definition at line 444 of file newgrf_object.cpp.

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

void DrawNewObjectTileInGUI ( int  x,
int  y,
const ObjectSpec spec,
uint8  view 
)
static void DrawTileLayout ( const TileInfo ti,
const TileLayoutSpriteGroup group,
const ObjectSpec spec 
) [static]

Draw an group of sprites on the map.

Parameters:
ti Information about the tile to draw on.
group The group of sprites to draw.
spec Object spec to draw.

Definition at line 418 of file newgrf_object.cpp.

References Object::colour, DrawGroundSprite(), DrawNewGRFTileSeq(), ObjectSpec::flags, GB(), Object::GetByTile(), DrawTileSprites::ground, GroundSpritePaletteTransform(), IsTileOnWater(), OBJECT_FLAG_2CC_COLOUR, OBJECT_FLAG_DRAW_WATER, PalSpriteID::pal, PalSpriteID::sprite, SPRITE_WIDTH, TileInfo::tile, and TO_STRUCTURES.

Referenced by DrawNewObjectTile().

static uint32 GetClosestObject ( TileIndex  tile,
ObjectType  type,
const Object current 
) [static]

Get the closest object of a given type.

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

Definition at line 172 of file newgrf_object.cpp.

References DistanceManhattan(), GetObjectType(), Object::location, min(), and TileArea::tile.

Referenced by GetCountAndDistanceOfClosestInstance().

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

Implementation of var 65.

Parameters:
local_id Parameter given to the callback, which is the set id, or the local id, in our terminology.
grfid The object's GRFID.
tile The tile to look from.
current Object 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 193 of file newgrf_object.cpp.

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

Referenced by ObjectGetVariable().

static uint32 GetNearbyObjectTileInformation ( byte  parameter,
TileIndex  tile,
ObjectID  index 
) [static]

Based on newhouses equivalent, but adapted for newobjects.

Parameters:
parameter from callback. It's in fact a pair of coordinates
tile TileIndex from which the callback was initiated
index of the object been queried for
Returns:
a construction of bits obeying the newgrf format

Definition at line 157 of file newgrf_object.cpp.

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

Referenced by ObjectGetVariable().

uint16 GetObjectCallback ( CallbackID  callback,
uint32  param1,
uint32  param2,
const ObjectSpec spec,
const Object o,
TileIndex  tile,
uint8  view 
)

Perform a callback for an object.

Parameters:
callback The callback to perform.
param1 The first parameter to pass to the NewGRF.
param2 The second parameter to pass to the NewGRF.
spec The specification of the object / the entry point.
o The object to call the callback for.
tile The tile the callback is called for.
view The view of the object (only used when o == NULL).
Returns:
The result of the callback.

Definition at line 398 of file newgrf_object.cpp.

References CALLBACK_FAILED, GetObjectSpriteGroup(), NewObjectResolver(), and SpriteGroup::Resolve().

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

static uint32 GetObjectIDAtOffset ( TileIndex  tile,
uint32  cur_grfid 
) [static]

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

Parameters:
tile TileIndex of the tile to query
cur_grfid GRFID of the current callback chain
Returns:
value encoded as per NFO specs

Definition at line 135 of file newgrf_object.cpp.

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

Referenced by ObjectGetVariable().

void GetObjectResolver ( ResolverObject ro,
uint  index 
)

Resolve an object's spec and such so we can get a variable.

Parameters:
ro The resolver object to fill.
index The object tile to get the data from.

Definition at line 567 of file newgrf_object.cpp.

References Object::GetByTile(), ObjectSpec::GetByTile(), and NewObjectResolver().

Referenced by NIHObject::Resolve().

static const SpriteGroup* GetObjectSpriteGroup ( const ObjectSpec spec,
const Object o 
) [static]

Get the object's sprite group.

Parameters:
spec The specification to get the sprite group from.
o The object to get he sprite group for.
Returns:
The resolved sprite group.

Definition at line 349 of file newgrf_object.cpp.

References CT_PURCHASE_OBJECT, ObjectSpec::grf_prop, and GRFFilePropsBase< Tcnt >::spritegroup.

Referenced by DrawNewObjectTile(), DrawNewObjectTileInGUI(), and GetObjectCallback().

static uint32 ObjectGetVariable ( const ResolverObject object,
byte  variable,
byte  parameter,
bool *  available 
) [static]
void ResetObjects (  ) 

This function initialize the spec arrays of objects.

Definition at line 80 of file newgrf_object.cpp.

References ObjectSpec::grf_prop, lengthof, GRFFilePropsBase< Tcnt >::local_id, MemCpyT(), and MemSetT().

Referenced by ResetNewGRFData().

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

Perform a callback for an object.

Parameters:
callback The callback to perform.
param1 The first parameter to pass to the NewGRF.
param2 The second parameter to pass to the NewGRF.
spec The specification of the object / the entry point.
o The object to call the callback for.
tile The tile the callback is called for.
Returns:
The result of the callback.

Definition at line 507 of file newgrf_object.cpp.

References GetObjectCallback().

void TriggerObjectAnimation ( const Object o,
ObjectAnimationTrigger  trigger,
const ObjectSpec spec 
)

Trigger the update of animation on a whole object.

Parameters:
o The object that got triggered.
trigger The trigger that is triggered.
spec The spec associated with the object.

Definition at line 553 of file newgrf_object.cpp.

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

Referenced by BuildObject().

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

Trigger the update of animation on a single tile.

Parameters:
o The object that got triggered.
tile The location of the triggered tile.
trigger The trigger that is triggered.
spec The spec associated with the object.

Definition at line 540 of file newgrf_object.cpp.

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

Referenced by TriggerObjectAnimation().


Variable Documentation

The override manager for our objects.

Referenced by FinaliseObjectsArray(), and GetCountAndDistanceOfClosestInstance().

All the object specifications.

Definition at line 35 of file newgrf_object.cpp.

Referenced by ObjectOverrideManager::SetEntitySpec().


Generated on Wed Apr 13 00:48:03 2011 for OpenTTD by  doxygen 1.6.1