newgrf_station.cpp File Reference

Functions for dealing with station classes and custom stations. More...

#include "stdafx.h"
#include "debug.h"
#include "station_base.h"
#include "waypoint_base.h"
#include "roadstop_base.h"
#include "newgrf_cargo.h"
#include "newgrf_station.h"
#include "newgrf_spritegroup.h"
#include "newgrf_sound.h"
#include "newgrf_railtype.h"
#include "town.h"
#include "newgrf_town.h"
#include "company_func.h"
#include "tunnelbridge_map.h"
#include "newgrf.h"
#include "newgrf_animation_base.h"
#include "newgrf_class_func.h"

Go to the source code of this file.

Data Structures

struct  ETileArea
struct  StationAnimationBase
 Helper class for animation control. More...

Enumerations

enum  TriggerArea { TA_TILE, TA_PLATFORM, TA_WHOLE }

Functions

uint32 GetPlatformInfo (Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
 Evaluate a tile's position within a station, and return the result in a bit-stuffed format.
static TileIndex FindRailStationEnd (TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
 Find the end of a railway station, from the tile, in the direction of delta.
static uint32 GetPlatformInfoHelper (TileIndex tile, bool check_type, bool check_axis, bool centred)
static uint32 GetRailContinuationInfo (TileIndex tile)
static uint32 StationGetRandomBits (const ResolverObject *object)
static uint32 StationGetTriggers (const ResolverObject *object)
static void StationSetTriggers (const ResolverObject *object, int triggers)
static uint32 StationGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
static const SpriteGroupStationResolveReal (const ResolverObject *object, const RealSpriteGroup *group)
static void NewStationResolver (ResolverObject *res, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
static const SpriteGroupResolveStation (ResolverObject *object)
SpriteID GetCustomStationRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
SpriteID GetCustomStationGroundRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
SpriteID GetCustomStationFoundationRelocation (const StationSpec *statspec, const BaseStation *st, TileIndex tile)
uint16 GetStationCallback (CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
int AllocateSpecToStation (const StationSpec *statspec, BaseStation *st, bool exec)
 Allocate a StationSpec to a Station.
void DeallocateSpecFromStation (BaseStation *st, byte specindex)
 Deallocate a StationSpec from a Station.
bool DrawStationTile (int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
 Draw representation of a station tile for GUI purposes.
const StationSpecGetStationSpec (TileIndex t)
bool IsStationTileBlocked (TileIndex tile)
 Check whether a rail station tile is NOT traversable.
bool IsStationTileElectrifiable (TileIndex tile)
 Check if a rail station tile can be electrified.
void AnimateStationTile (TileIndex tile)
void TriggerStationAnimation (const BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type)
void StationUpdateAnimTriggers (BaseStation *st)
 Update the cached animation trigger bitmask for a station.
void GetStationResolver (ResolverObject *ro, uint index)
 Resolve a station's spec and such so we can get a variable.

Variables

static const uint MAX_SPECLIST = 255
struct {
   uint32   v40
   uint32   v41
   uint32   v45
   uint32   v46
   uint32   v47
   uint32   v49
   uint8   valid
 Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
_svc
 Station variable cache This caches 'expensive' station variable lookups which iterate over several tiles that may be called multiple times per Resolve().

Detailed Description

Functions for dealing with station classes and custom stations.

Definition in file newgrf_station.cpp.


Function Documentation

int AllocateSpecToStation ( const StationSpec statspec,
BaseStation st,
bool  exec 
)

Allocate a StationSpec to a Station.

This is called once per build operation.

Parameters:
statspec StationSpec to allocate.
st Station to allocate it to.
exec Whether to actually allocate the spec.
Returns:
Index within the Station's spec list, or -1 if the allocation failed.

Definition at line 649 of file newgrf_station.cpp.

References StationSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, StationSpecList::grfid, GRFFilePropsBase< Tcnt >::local_id, StationSpecList::localidx, BaseStation::num_specs, ReallocT(), and BaseStation::speclist.

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), and MoveWaypointsToBaseStations().

void DeallocateSpecFromStation ( BaseStation st,
byte  specindex 
)

Deallocate a StationSpec from a Station.

Called when removing a single station tile.

Parameters:
st Station to work with.
specindex Index of the custom station within the Station's spec list.
Returns:
Indicates whether the StationSpec was deallocated.

Definition at line 700 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, GetCustomStationSpecIndex(), StationSpecList::grfid, INVALID_TILE, StationSpecList::localidx, BaseStation::num_specs, ReallocT(), BaseStation::speclist, StationUpdateAnimTriggers(), TILE_AREA_LOOP, and BaseStation::TileBelongsToRailStation().

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), and RemoveFromRailBaseStation().

bool DrawStationTile ( int  x,
int  y,
RailType  railtype,
Axis  axis,
StationClassID  sclass,
uint  station 
)

Draw representation of a station tile for GUI purposes.

Parameters:
x Position x of image.
y Position y of image.
axis Axis.
railtype Rail type.
sclass,station Type of station.
station station ID
Returns:
True if the tile was drawn (allows for fallback to default graphic)

Definition at line 746 of file newgrf_station.cpp.

References _local_company, CALLBACK_FAILED, StationSpec::callback_mask, CBID_STATION_SPRITE_LAYOUT, CBM_STATION_SPRITE_LAYOUT, RailtypeInfo::custom_ground_offset, DrawRailTileSeqInGUI(), DrawSprite(), GetRailTypeInfo(), DrawTileSprites::ground, GroundSpritePaletteTransform(), HasBit(), INVALID_TILE, PalSpriteID::pal, StationSpec::renderdata, PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, StationSpec::tiles, and RailtypeInfo::total_offset.

Referenced by DrawWaypointSprite(), and BuildRailStationWindow::DrawWidget().

static TileIndex FindRailStationEnd ( TileIndex  tile,
TileIndexDiff  delta,
bool  check_type,
bool  check_axis 
) [static]

Find the end of a railway station, from the tile, in the direction of delta.

Parameters:
tile Start tile.
delta Movement direction.
check_type Stop when the custom station type changes.
check_axis Stop when the station direction changes.
Returns:
Found end of the railway station.

Definition at line 145 of file newgrf_station.cpp.

References AXIS_X, GetCustomStationSpecIndex(), GetRailStationAxis(), GetStationIndex(), HasStationRail(), IsTileType(), MP_STATION, and TILE_ADD.

uint32 GetPlatformInfo ( Axis  axis,
byte  tile,
int  platforms,
int  length,
int  x,
int  y,
bool  centred 
)

Evaluate a tile's position within a station, and return the result in a bit-stuffed format.

if not centered: .TNLcCpP, if centered: .TNL..CP

  • T = Tile layout number (GetStationGfx)
  • N = Number of platforms
  • L = Length of platforms
  • C = Current platform number from start, c = from end
  • P = Position along platform from start, p = from end

if centered, C/P start from the centre and c/p are not available.

Returns:
Platform information in bit-stuffed format.

Definition at line 104 of file newgrf_station.cpp.

References AXIS_X, min(), SB(), and Swap().

Referenced by CmdBuildRailStation().

void GetStationResolver ( ResolverObject ro,
uint  index 
)

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

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

Definition at line 897 of file newgrf_station.cpp.

References SpecializedStation< Station, false >::GetByTile().

Referenced by NIHStation::Resolve().

bool IsStationTileBlocked ( TileIndex  tile  ) 

Check whether a rail station tile is NOT traversable.

Parameters:
tile Tile to test.
Returns:
Station tile is blocked.
Note:
This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 803 of file newgrf_station.cpp.

References StationSpec::blocked, GetStationGfx(), and HasBit().

Referenced by ExploreSegment(), IsCompatibleTrainStationTile(), AIRail::IsRailTile(), and RemoveFromRailBaseStation().

bool IsStationTileElectrifiable ( TileIndex  tile  ) 

Check if a rail station tile can be electrified.

Parameters:
tile Tile to test.
Returns:
Tile can be electrified.
Note:
This could be cached (during build) in the map array to save on all the dereferencing.

Definition at line 816 of file newgrf_station.cpp.

References GetStationGfx(), HasBit(), StationSpec::pylons, and StationSpec::wires.

Referenced by GetRailTrackBitsUniversal().

void StationUpdateAnimTriggers ( BaseStation st  ) 

Update the cached animation trigger bitmask for a station.

Parameters:
st Station to update.

Definition at line 880 of file newgrf_station.cpp.

References BaseStation::cached_anim_triggers, BaseStation::num_specs, BaseStation::speclist, and AnimationInfo::triggers.

Referenced by DeallocateSpecFromStation().


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