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/>.
10 /** @file newgrf_station.h Header file for NewGRF stations */
12 #ifndef NEWGRF_STATION_H
13 #define NEWGRF_STATION_H
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"
25 /** Scope resolver for stations. */
26 struct StationScopeResolver
: public ScopeResolver
{
27 TileIndex tile
; ///< %Tile of the station.
28 struct BaseStation
*st
; ///< Instance of the station.
29 const struct StationSpec
*statspec
; ///< Station (type) specification.
30 CargoID cargo_type
; ///< Type of cargo of the station.
31 Axis axis
; ///< Station axis, used only for the slope check callback.
34 * Constructor for station scopes.
35 * @param ro Surrounding resolver.
36 * @param statspec Station (type) specification.
37 * @param st Instance of the station.
38 * @param tile %Tile of the station.
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
)
45 /* virtual */ uint32
GetRandomBits() const;
46 /* virtual */ uint32
GetTriggers() const;
48 /* virtual */ uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
51 /** Station resolver. */
52 struct StationResolverObject
: public ResolverObject
{
53 StationScopeResolver station_scope
; ///< The station scope resolver.
54 TownScopeResolver
*town_scope
; ///< The town scope resolver (created on the first call).
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();
60 TownScopeResolver
*GetTown();
62 /* virtual */ ScopeResolver
*GetScope(VarSpriteGroupScope scope
= VSG_SCOPE_SELF
, byte relative
= 0)
66 return &this->station_scope
;
68 case VSG_SCOPE_PARENT
: {
69 TownScopeResolver
*tsr
= this->GetTown();
70 if (tsr
!= NULL
) return tsr
;
75 return ResolverObject::GetScope(scope
, relative
);
79 /* virtual */ const SpriteGroup
*ResolveReal(const RealSpriteGroup
*group
) const;
83 STAT_CLASS_BEGIN
= 0, ///< the lowest valid value
84 STAT_CLASS_DFLT
= 0, ///< Default station class.
85 STAT_CLASS_WAYP
, ///< Waypoint class.
86 STAT_CLASS_MAX
= 256, ///< Maximum number of classes.
88 typedef SimpleTinyEnumT
<StationClassID
, byte
> StationClassIDByte
;
89 template <> struct EnumPropsT
<StationClassID
> : MakeEnumPropsT
<StationClassID
, byte
, STAT_CLASS_BEGIN
, STAT_CLASS_MAX
, STAT_CLASS_MAX
, 8> {};
91 /** Allow incrementing of StationClassID variables */
92 DECLARE_POSTFIX_INCREMENT(StationClassID
)
94 enum StationSpecFlags
{
95 SSF_SEPARATE_GROUND
, ///< Use different sprite set for ground sprites.
96 SSF_DIV_BY_STATION_SIZE
, ///< Divide cargo amount by station size.
97 SSF_CB141_RANDOM_BITS
, ///< Callback 141 needs random bits.
98 SSF_CUSTOM_FOUNDATIONS
, ///< Draw custom foundations.
99 SSF_EXTENDED_FOUNDATIONS
, ///< Extended foundation block instead of simple.
102 /** Randomisation triggers for stations */
103 enum StationRandomTrigger
{
104 SRT_NEW_CARGO
, ///< Trigger station on new cargo arrival.
105 SRT_CARGO_TAKEN
, ///< Trigger station when cargo is completely taken.
106 SRT_TRAIN_ARRIVES
, ///< Trigger platform when train arrives.
107 SRT_TRAIN_DEPARTS
, ///< Trigger platform when train leaves.
108 SRT_TRAIN_LOADS
, ///< Trigger platform when train loads/unloads.
109 SRT_PATH_RESERVATION
, ///< Trigger platform when train reserves path.
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
;
116 /** Station specification. */
119 * Properties related the the grf file.
120 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
121 * Used for obtaining the sprite offset of custom sprites, and for
122 * evaluating callbacks.
124 GRFFilePropsBase
<NUM_CARGO
+ 3> grf_prop
;
125 StationClassID cls_id
; ///< The class to which this spec belongs.
126 StringID name
; ///< Name of this station.
129 * Bitmask of number of platforms available for the station.
130 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
132 byte disallowed_platforms
;
134 * Bitmask of platform lengths available for the station.
135 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
137 byte disallowed_lengths
;
140 * Number of tile layouts.
141 * A minimum of 8 is required is required for stations.
142 * 0-1 = plain platform
143 * 2-3 = platform with building
144 * 4-5 = platform with roof, left side
145 * 6-7 = platform with roof, right side
148 NewGRFSpriteLayout
*renderdata
; ///< Array of tile layouts.
151 * Cargo threshold for choosing between little and lots of cargo
152 * @note little/lots are equivalent to the moving/loading states for vehicles
154 uint16 cargo_threshold
;
156 uint32 cargo_triggers
; ///< Bitmask of cargo types which cause trigger re-randomizing
158 byte callback_mask
; ///< Bitmask of station callbacks that have to be called
160 byte flags
; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
162 byte pylons
; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
163 byte wires
; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
164 byte blocked
; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
166 AnimationInfo animation
;
170 StationLayout
**layouts
;
174 /** Struct containing information relating to station classes. */
175 typedef NewGRFClass
<StationSpec
, StationClassID
, STAT_CLASS_MAX
> StationClass
;
177 const StationSpec
*GetStationSpec(TileIndex t
);
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
);
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
);
187 /* Allocate a StationSpec to a Station. This is called once per build operation. */
188 int AllocateSpecToStation(const StationSpec
*statspec
, BaseStation
*st
, bool exec
);
190 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
191 void DeallocateSpecFromStation(BaseStation
*st
, byte specindex
);
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
);
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
);
201 #endif /* NEWGRF_STATION_H */