OpenTTD Source  1.11.2
newgrf_station.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef NEWGRF_STATION_H
11 #define NEWGRF_STATION_H
12 
13 #include "newgrf_animation_type.h"
14 #include "newgrf_callbacks.h"
15 #include "newgrf_class.h"
16 #include "newgrf_commons.h"
17 #include "cargo_type.h"
18 #include "station_type.h"
19 #include "rail_type.h"
20 #include "newgrf_spritegroup.h"
21 #include "newgrf_town.h"
22 
26  struct BaseStation *st;
27  const struct StationSpec *statspec;
30 
40  {
41  }
42 
43  uint32 GetRandomBits() const override;
44  uint32 GetTriggers() const override;
45 
46  uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
47 };
48 
53 
54  StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
57 
59 
60  ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
61  {
62  switch (scope) {
63  case VSG_SCOPE_SELF:
64  return &this->station_scope;
65 
66  case VSG_SCOPE_PARENT: {
67  TownScopeResolver *tsr = this->GetTown();
68  if (tsr != nullptr) return tsr;
69  FALLTHROUGH;
70  }
71 
72  default:
73  return ResolverObject::GetScope(scope, relative);
74  }
75  }
76 
77  const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
78 
79  GrfSpecFeature GetFeature() const override;
80  uint32 GetDebugID() const override;
81 };
82 
83 enum StationClassID : byte {
88 };
89 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
90 
93 
100 };
101 
110 };
111 
112 /* Station layout for given dimensions - it is a two-dimensional array
113  * where index is computed as (x * platforms) + platform. */
114 typedef byte *StationLayout;
115 
117 struct StationSpec {
127 
138 
147  uint tiles;
149 
155 
156  CargoTypes cargo_triggers;
157 
159 
160  byte flags;
161 
162  byte pylons;
163  byte wires;
164  byte blocked;
165 
166  AnimationInfo animation;
167 
168  byte lengths;
169  byte *platforms;
170  StationLayout **layouts;
171  bool copied_layouts;
172 };
173 
176 
177 const StationSpec *GetStationSpec(TileIndex t);
178 
179 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
180 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
181 
182 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
183 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
184 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
185 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
186 
187 /* Allocate a StationSpec to a Station. This is called once per build operation. */
188 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
189 
190 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
191 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
192 
193 /* Draw representation of a station tile for GUI purposes. */
194 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
195 
196 void AnimateStationTile(TileIndex tile);
197 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
200 
201 #endif /* NEWGRF_STATION_H */
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
StationScopeResolver::cargo_type
CargoID cargo_type
Type of cargo of the station.
Definition: newgrf_station.h:28
ResolverObject::callback_param1
uint32 callback_param1
First parameter (var 10) of the callback.
Definition: newgrf_spritegroup.h:334
StationUpdateCachedTriggers
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition: newgrf_station.cpp:1048
StationSpec::flags
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size.
Definition: newgrf_station.h:160
GetCustomStationRelocation
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10=0)
Resolve sprites for drawing a station tile.
Definition: newgrf_station.cpp:607
StationClass
NewGRFClass< StationSpec, StationClassID, STAT_CLASS_MAX > StationClass
Struct containing information relating to station classes.
Definition: newgrf_station.h:175
newgrf_commons.h
SSF_EXTENDED_FOUNDATIONS
@ SSF_EXTENDED_FOUNDATIONS
Extended foundation block instead of simple.
Definition: newgrf_station.h:99
StationRandomTrigger
StationRandomTrigger
Randomisation triggers for stations.
Definition: newgrf_station.h:103
StationScopeResolver::GetTriggers
uint32 GetTriggers() const override
Get the triggers.
Definition: newgrf_station.cpp:230
Station
Station data structure.
Definition: station_base.h:450
SSF_DIV_BY_STATION_SIZE
@ SSF_DIV_BY_STATION_SIZE
Divide cargo amount by station size.
Definition: newgrf_station.h:96
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:315
StationResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_station.h:60
AnimationInfo
Information about animation.
Definition: newgrf_animation_type.h:18
StationScopeResolver::statspec
const struct StationSpec * statspec
Station (type) specification.
Definition: newgrf_station.h:27
newgrf_callbacks.h
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:104
STAT_CLASS_BEGIN
@ STAT_CLASS_BEGIN
the lowest valid value
Definition: newgrf_station.h:84
StationResolverObject::station_scope
StationScopeResolver station_scope
The station scope resolver.
Definition: newgrf_station.h:51
StationResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
Definition: newgrf_station.cpp:256
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:296
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
StationSpec::renderdata
NewGRFSpriteLayout * renderdata
Array of tile layouts.
Definition: newgrf_station.h:148
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
SSF_SEPARATE_GROUND
@ SSF_SEPARATE_GROUND
Use different sprite set for ground sprites.
Definition: newgrf_station.h:95
SSF_CB141_RANDOM_BITS
@ SSF_CB141_RANDOM_BITS
Callback 141 needs random bits.
Definition: newgrf_station.h:97
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:734
StationScopeResolver::StationScopeResolver
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
Constructor for station scopes.
Definition: newgrf_station.h:38
StationSpec::tiles
uint tiles
Number of tile layouts.
Definition: newgrf_station.h:147
StationSpec::cls_id
StationClassID cls_id
The class to which this spec belongs.
Definition: newgrf_station.h:125
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
ResolverObject::callback_param2
uint32 callback_param2
Second parameter (var 18) of the callback.
Definition: newgrf_spritegroup.h:335
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
STAT_CLASS_WAYP
@ STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:86
CommandCost
Common return value for all commands.
Definition: command_type.h:23
StationScopeResolver
Scope resolver for stations.
Definition: newgrf_station.h:24
StationResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_station.h:52
StationSpec::pylons
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
Definition: newgrf_station.h:162
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
cargo_type.h
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
SRT_NEW_CARGO
@ SRT_NEW_CARGO
Trigger station on new cargo arrival.
Definition: newgrf_station.h:104
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition: newgrf_commons.h:113
StationSpec::name
StringID name
Name of this station.
Definition: newgrf_station.h:126
StationSpecFlags
StationSpecFlags
Allow incrementing of StationClassID variables.
Definition: newgrf_station.h:94
STAT_CLASS_MAX
@ STAT_CLASS_MAX
Maximum number of classes.
Definition: newgrf_station.h:87
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:153
SRT_TRAIN_DEPARTS
@ SRT_TRAIN_DEPARTS
Trigger platform when train leaves.
Definition: newgrf_station.h:107
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
StationSpec::disallowed_platforms
byte disallowed_platforms
Bitmask of number of platforms available for the station.
Definition: newgrf_station.h:132
StationResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_station.cpp:545
StationResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition: newgrf_station.cpp:495
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:681
PerformStationTileSlopeCheck
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
Check the slope of a tile of a new station.
Definition: newgrf_station.cpp:653
StationScopeResolver::axis
Axis axis
Station axis, used only for the slope check callback.
Definition: newgrf_station.h:29
newgrf_spritegroup.h
SSF_CUSTOM_FOUNDATIONS
@ SSF_CUSTOM_FOUNDATIONS
Draw custom foundations.
Definition: newgrf_station.h:98
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
SRT_CARGO_TAKEN
@ SRT_CARGO_TAKEN
Trigger station when cargo is completely taken.
Definition: newgrf_station.h:105
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
StationSpec
Station specification.
Definition: newgrf_station.h:117
GetPlatformInfo
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.
Definition: newgrf_station.cpp:105
newgrf_class.h
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
StationAnimationTrigger
StationAnimationTrigger
Animation triggers for station.
Definition: newgrf_animation_type.h:26
DrawStationTile
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Definition: newgrf_station.cpp:781
StationScopeResolver::st
struct BaseStation * st
Instance of the station.
Definition: newgrf_station.h:26
StationClassID
StationClassID
Definition: newgrf_station.h:83
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:333
StationScopeResolver::GetRandomBits
uint32 GetRandomBits() const override
Get a few random bits.
Definition: newgrf_station.cpp:224
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
rail_type.h
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize.
Definition: enum_type.hpp:62
StationSpec::cargo_threshold
uint16 cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
Definition: newgrf_station.h:154
SRT_PATH_RESERVATION
@ SRT_PATH_RESERVATION
Trigger platform when train reserves path.
Definition: newgrf_station.h:109
StationSpec::grf_prop
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Definition: newgrf_station.h:124
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:123
StationResolverObject
Station resolver.
Definition: newgrf_station.h:50
StationSpec::callback_mask
byte callback_mask
Bitmask of station callbacks that have to be called.
Definition: newgrf_station.h:158
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:297
StationSpec::disallowed_lengths
byte disallowed_lengths
Bitmask of platform lengths available for the station.
Definition: newgrf_station.h:137
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:127
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:68
StationScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
Definition: newgrf_station.cpp:271
newgrf_animation_type.h
STAT_CLASS_DFLT
@ STAT_CLASS_DFLT
Default station class.
Definition: newgrf_station.h:85
GetCustomStationFoundationRelocation
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
Definition: newgrf_station.cpp:624
StationResolverObject::StationResolverObject
StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Resolver for stations.
Definition: newgrf_station.cpp:559
GRFFilePropsBase< NUM_CARGO+3 >
SRT_TRAIN_ARRIVES
@ SRT_TRAIN_ARRIVES
Trigger platform when train arrives.
Definition: newgrf_station.h:106
StationSpec::cargo_triggers
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Definition: newgrf_station.h:156
StationScopeResolver::tile
TileIndex tile
Tile of the station.
Definition: newgrf_station.h:25
SpriteGroup
Definition: newgrf_spritegroup.h:57
StationSpec::wires
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
Definition: newgrf_station.h:163
StationSpec::blocked
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
Definition: newgrf_station.h:164
TriggerStationRandomisation
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type=CT_INVALID)
Trigger station randomisation.
Definition: newgrf_station.cpp:966
SRT_TRAIN_LOADS
@ SRT_TRAIN_LOADS
Trigger platform when train loads/unloads.
Definition: newgrf_station.h:108
station_type.h
StationResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_station.cpp:540