OpenTTD

newgrf_station.h
Go to the documentation of this file.
1 /* $Id: newgrf_station.h 27984 2018-03-11 13:19:41Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef NEWGRF_STATION_H
13 #define NEWGRF_STATION_H
14
15 #include "newgrf_animation_type.h"
16 #include "newgrf_callbacks.h"
17 #include "newgrf_class.h"
18 #include "newgrf_commons.h"
19 #include "cargo_type.h"
20 #include "station_type.h"
21 #include "rail_type.h"
22 #include "newgrf_spritegroup.h"
23 #include "newgrf_town.h"
24
26 struct StationScopeResolver : public ScopeResolver {
27 TileIndex tile;
28 struct BaseStation *st;
29 const struct StationSpec *statspec;
30 CargoID cargo_type;
31 Axis axis;
32
40 StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
41 : ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
42 {
43 }
44
45 /* virtual */ uint32 GetRandomBits() const;
46 /* virtual */ uint32 GetTriggers() const;
47
48 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
49 };
50
52 struct StationResolverObject : public ResolverObject {
53 StationScopeResolver station_scope;
54 TownScopeResolver *town_scope;
55
56 StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
57 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
58 ~StationResolverObject();
59
60 TownScopeResolver *GetTown();
61
62 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
63 {
64 switch (scope) {
65 case VSG_SCOPE_SELF:
66 return &this->station_scope;
67
68 case VSG_SCOPE_PARENT: {
69 TownScopeResolver *tsr = this->GetTown();
70 if (tsr != NULL) return tsr;
71 }
72 FALLTHROUGH;
73
74 default:
75 return ResolverObject::GetScope(scope, relative);
76 }
77 }
78
79 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
80 };
81
82 enum StationClassID {
83 STAT_CLASS_BEGIN = 0,
84 STAT_CLASS_DFLT = 0,
85 STAT_CLASS_WAYP,
86 STAT_CLASS_MAX = 256,
87 };
88 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
89 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
90
92 DECLARE_POSTFIX_INCREMENT(StationClassID)
93
94 enum StationSpecFlags {
95 SSF_SEPARATE_GROUND,
96 SSF_DIV_BY_STATION_SIZE,
97 SSF_CB141_RANDOM_BITS,
98 SSF_CUSTOM_FOUNDATIONS,
99 SSF_EXTENDED_FOUNDATIONS,
100 };
101
103 enum StationRandomTrigger {
104 SRT_NEW_CARGO,
105 SRT_CARGO_TAKEN,
106 SRT_TRAIN_ARRIVES,
107 SRT_TRAIN_DEPARTS,
108 SRT_TRAIN_LOADS,
109 SRT_PATH_RESERVATION,
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 {
124 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
125 StationClassID cls_id;
126 StringID name;
127
132 byte disallowed_platforms;
137 byte disallowed_lengths;
138
147 uint tiles;
148 NewGRFSpriteLayout *renderdata;
149
154 uint16 cargo_threshold;
155
156 uint32 cargo_triggers;
157
158 byte callback_mask;
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
175 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
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);
198 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
199 void StationUpdateCachedTriggers(BaseStation *st);
200
201 #endif /* NEWGRF_STATION_H */
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:66
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
Definition: newgrf_spritegroup.h:291
SSF_CB141_RANDOM_BITS
Callback 141 needs random bits.
Definition: newgrf_station.h:97
SRT_CARGO_TAKEN
Trigger station when cargo is completely taken.
Definition: newgrf_station.h:105
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:663
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:292
StationResolverObject::station_scope
StationScopeResolver station_scope
The station scope resolver.
Definition: newgrf_station.h:53
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:310
StationSpec
Station specification.
Definition: newgrf_station.h:117
newgrf_animation_type.h
Definitions related to NewGRF animation.
SRT_TRAIN_DEPARTS
Trigger platform when train leaves.
Definition: newgrf_station.h:107
GetPlatformInfo
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
Evaluate a tile&#39;s position within a station, and return the result in a bit-stuffed format...
Definition: newgrf_station.cpp:107
StationSpec::cargo_triggers
uint32 cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Definition: newgrf_station.h:156
CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:24
SSF_CUSTOM_FOUNDATIONS
Draw custom foundations.
Definition: newgrf_station.h:98
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:142
CommandCost
Common return value for all commands.
Definition: command_type.h:25
cargo_type.h
Types related to cargoes...
StationSpec::tiles
uint tiles
Number of tile layouts.
Definition: newgrf_station.h:147
StationScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_station.cpp:273
STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:85
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
GetCustomStationRelocation
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10=0)
Resolve sprites for drawing a station tile.
Definition: newgrf_station.cpp:589
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
StationScopeResolver
Scope resolver for stations.
Definition: newgrf_station.h:26
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
StationSpec::pylons
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
Definition: newgrf_station.h:162
station_type.h
Types related to stations.
newgrf_spritegroup.h
Action 2 handling.
StationScopeResolver::axis
Axis axis
Station axis, used only for the slope check callback.
Definition: newgrf_station.h:31
StationScopeResolver::GetRandomBits
uint32 GetRandomBits() const
Get a few random bits.
Definition: newgrf_station.cpp:226
StationClass
NewGRFClass< StationSpec, StationClassID, STAT_CLASS_MAX > StationClass
Struct containing information relating to station classes.
Definition: newgrf_station.h:175
StationSpec::grf_prop
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Definition: newgrf_station.h:124
StationSpecFlags
StationSpecFlags
Allow incrementing of StationClassID variables.
Definition: newgrf_station.h:94
SRT_PATH_RESERVATION
Trigger platform when train reserves path.
Definition: newgrf_station.h:109
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:24
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:52
SpriteGroup
Definition: newgrf_spritegroup.h:58
TriggerStationRandomisation
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type=CT_INVALID)
Trigger station randomisation.
Definition: newgrf_station.cpp:948
STAT_CLASS_BEGIN
the lowest valid value
Definition: newgrf_station.h:83
StationSpec::wires
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
Definition: newgrf_station.h:163
StationResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_station.h:54
CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:70
VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition: newgrf_commons.h:115
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
StationScopeResolver::tile
TileIndex tile
Tile of the station.
Definition: newgrf_station.h:27
SimpleTinyEnumT
Template of struct holding enum types (on most archs, enums are stored in an int32).
Definition: enum_type.hpp:139
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
StationAnimationTrigger
StationAnimationTrigger
Animation triggers for station.
Definition: newgrf_animation_type.h:28
newgrf_class.h
Header file for classes to be used by e.g.
StationScopeResolver::cargo_type
CargoID cargo_type
Type of cargo of the station.
Definition: newgrf_station.h:30
StationScopeResolver::statspec
const struct StationSpec * statspec
Station (type) specification.
Definition: newgrf_station.h:29
SRT_TRAIN_ARRIVES
Trigger platform when train arrives.
Definition: newgrf_station.h:106
StationScopeResolver::st
struct BaseStation * st
Instance of the station.
Definition: newgrf_station.h:28
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
SSF_SEPARATE_GROUND
Use different sprite set for ground sprites.
Definition: newgrf_station.h:95
SSF_EXTENDED_FOUNDATIONS
Extended foundation block instead of simple.
Definition: newgrf_station.h:99
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:635
SRT_NEW_CARGO
Trigger station on new cargo arrival.
Definition: newgrf_station.h:104
StationResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_station.h:62
VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:104
SRT_TRAIN_LOADS
Trigger platform when train loads/unloads.
Definition: newgrf_station.h:108
STAT_CLASS_DFLT
Default station class.
Definition: newgrf_station.h:84
GRFFilePropsBase< NUM_CARGO+3 >
StationSpec::cargo_threshold
uint16 cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
Definition: newgrf_station.h:154
StationUpdateCachedTriggers
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition: newgrf_station.cpp:1030
StationScopeResolver::StationScopeResolver
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
Constructor for station scopes.
Definition: newgrf_station.h:40
STAT_CLASS_MAX
Maximum number of classes.
Definition: newgrf_station.h:86
newgrf_commons.h
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
AnimationInfo
Information about animation.
Definition: newgrf_animation_type.h:20
StationClassID
StationClassID
Definition: newgrf_station.h:82
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:716
StationRandomTrigger
StationRandomTrigger
Randomisation triggers for stations.
Definition: newgrf_station.h:103
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:22
StationResolverObject
Station resolver.
Definition: newgrf_station.h:52
StationSpec::callback_mask
byte callback_mask
Bitmask of station callbacks that have to be called.
Definition: newgrf_station.h:158
StationSpec::disallowed_lengths
byte disallowed_lengths
Bitmask of platform lengths available for the station.
Definition: newgrf_station.h:137
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:606
newgrf_town.h
Functions to handle the town part of NewGRF towns.
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
StationSpec::renderdata
NewGRFSpriteLayout * renderdata
Array of tile layouts.
Definition: newgrf_station.h:148
SSF_DIV_BY_STATION_SIZE
Divide cargo amount by station size.
Definition: newgrf_station.h:96
StationSpec::name
StringID name
Name of this station.
Definition: newgrf_station.h:126
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:131
StationSpec::disallowed_platforms
byte disallowed_platforms
Bitmask of number of platforms available for the station.
Definition: newgrf_station.h:132
StationSpec::cls_id
StationClassID cls_id
The class to which this spec belongs.
Definition: newgrf_station.h:125
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:763
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:54
Station
Station data structure.
Definition: station_base.h:446
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:127
StationScopeResolver::GetTriggers
uint32 GetTriggers() const
Get the triggers.
Definition: newgrf_station.cpp:232
StationSpec::blocked
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
Definition: newgrf_station.h:164
rail_type.h
The different types of rail.