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 const GRFFile
*const grffile
; ///< GRFFile the resolved SpriteGroup belongs to.
28 TileIndex tile
; ///< %Tile of the station.
29 struct BaseStation
*st
; ///< Instance of the station.
30 const struct StationSpec
*statspec
; ///< Station (type) specification.
31 CargoID cargo_type
; ///< Type of cargo of the station.
32 Axis axis
; ///< Station axis, used only for the slope check callback.
34 StationScopeResolver (const GRFFile
*grffile
, const StationSpec
*statspec
, BaseStation
*st
, TileIndex tile
);
36 /* virtual */ uint32
GetRandomBits() const;
37 /* virtual */ uint32
GetTriggers() const;
38 /* virtual */ void SetTriggers(int triggers
) const;
40 /* virtual */ uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
43 /** Station resolver. */
44 struct StationResolverObject
: public ResolverObject
{
45 StationScopeResolver station_scope
; ///< The station scope resolver.
46 TownScopeResolver
*town_scope
; ///< The town scope resolver (created on the first call).
48 const SpriteGroup
*root_spritegroup
; ///< Root SpriteGroup to use for resolving
50 StationResolverObject(const StationSpec
*statspec
, BaseStation
*st
, TileIndex tile
,
51 CallbackID callback
= CBID_NO_CALLBACK
, uint32 callback_param1
= 0, uint32 callback_param2
= 0);
52 ~StationResolverObject();
54 TownScopeResolver
*GetTown();
56 /* virtual */ ScopeResolver
*GetScope(VarSpriteGroupScope scope
= VSG_SCOPE_SELF
, byte relative
= 0)
60 return &this->station_scope
;
62 case VSG_SCOPE_PARENT
: {
63 TownScopeResolver
*tsr
= this->GetTown();
64 if (tsr
!= NULL
) return tsr
;
69 return ResolverObject::GetScope(scope
, relative
);
73 /* virtual */ const SpriteGroup
*ResolveReal(const RealSpriteGroup
*group
) const;
76 * Resolve SpriteGroup.
77 * @return Result spritegroup.
79 const SpriteGroup
*Resolve()
81 return SpriteGroup::Resolve (this->root_spritegroup
, *this);
86 STAT_CLASS_BEGIN
= 0, ///< the lowest valid value
87 STAT_CLASS_DFLT
= 0, ///< Default station class.
88 STAT_CLASS_WAYP
, ///< Waypoint class.
89 STAT_CLASS_MAX
= 256, ///< Maximum number of classes.
91 typedef SimpleTinyEnumT
<StationClassID
, byte
> StationClassIDByte
;
92 template <> struct EnumPropsT
<StationClassID
> : MakeEnumPropsT
<StationClassID
, byte
, STAT_CLASS_BEGIN
, STAT_CLASS_MAX
, STAT_CLASS_MAX
, 8> {};
94 /** Allow incrementing of StationClassID variables */
95 DECLARE_POSTFIX_INCREMENT(StationClassID
)
97 enum StationSpecFlags
{
98 SSF_SEPARATE_GROUND
, ///< Use different sprite set for ground sprites.
99 SSF_DIV_BY_STATION_SIZE
, ///< Divide cargo amount by station size.
100 SSF_CB141_RANDOM_BITS
, ///< Callback 141 needs random bits.
101 SSF_CUSTOM_FOUNDATIONS
, ///< Draw custom foundations.
102 SSF_EXTENDED_FOUNDATIONS
, ///< Extended foundation block instead of simple.
105 /** Randomisation triggers for stations */
106 enum StationRandomTrigger
{
107 SRT_NEW_CARGO
, ///< Trigger station on new cargo arrival.
108 SRT_CARGO_TAKEN
, ///< Trigger station when cargo is completely taken.
109 SRT_TRAIN_ARRIVES
, ///< Trigger platform when train arrives.
110 SRT_TRAIN_DEPARTS
, ///< Trigger platform when train leaves.
111 SRT_TRAIN_LOADS
, ///< Trigger platform when train loads/unloads.
112 SRT_PATH_RESERVATION
, ///< Trigger platform when train reserves path.
115 /* Station layout for given dimensions - it is a two-dimensional array
116 * where index is computed as (x * platforms) + platform. */
117 typedef byte
*StationLayout
;
119 /** Station specification. */
122 * Properties related the the grf file.
123 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
124 * Used for obtaining the sprite offset of custom sprites, and for
125 * evaluating callbacks.
127 GRFFilePropsBase
<NUM_CARGO
+ 3> grf_prop
;
128 StationClassID cls_id
; ///< The class to which this spec belongs.
129 StringID name
; ///< Name of this station.
132 * Bitmask of number of platforms available for the station.
133 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
135 byte disallowed_platforms
;
137 * Bitmask of platform lengths available for the station.
138 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
140 byte disallowed_lengths
;
143 * Number of tile layouts.
144 * A minimum of 8 is required is required for stations.
145 * 0-1 = plain platform
146 * 2-3 = platform with building
147 * 4-5 = platform with roof, left side
148 * 6-7 = platform with roof, right side
151 NewGRFSpriteLayout
*renderdata
; ///< Array of tile layouts.
154 * Cargo threshold for choosing between little and lots of cargo
155 * @note little/lots are equivalent to the moving/loading states for vehicles
157 uint16 cargo_threshold
;
159 uint32 cargo_triggers
; ///< Bitmask of cargo types which cause trigger re-randomizing
161 byte callback_mask
; ///< Bitmask of station callbacks that have to be called
163 byte flags
; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
165 byte pylons
; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
166 byte wires
; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
167 byte blocked
; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
169 AnimationInfo animation
;
173 StationLayout
**layouts
;
177 /** Struct containing information relating to station classes. */
178 typedef NewGRFClass
<StationSpec
, StationClassID
, STAT_CLASS_MAX
> StationClass
;
180 const StationSpec
*GetStationSpec(TileIndex t
);
182 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
183 uint32
GetPlatformInfo(Axis axis
, byte tile
, int platforms
, int length
, int x
, int y
, bool centred
);
185 SpriteID
GetCustomStationRelocation(const StationSpec
*statspec
, BaseStation
*st
, TileIndex tile
, uint32 var10
= 0);
186 SpriteID
GetCustomStationFoundationRelocation(const StationSpec
*statspec
, BaseStation
*st
, TileIndex tile
, uint layout
, uint edge_info
);
187 uint16
GetStationCallback(CallbackID callback
, uint32 param1
, uint32 param2
, const StationSpec
*statspec
, BaseStation
*st
, TileIndex tile
);
188 CommandCost
PerformStationTileSlopeCheck(TileIndex north_tile
, TileIndex cur_tile
, const StationSpec
*statspec
, Axis axis
, byte plat_len
, byte numtracks
);
190 /* Allocate a StationSpec to a Station. This is called once per build operation. */
191 int AllocateSpecToStation(const StationSpec
*statspec
, BaseStation
*st
, bool exec
);
193 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
194 void DeallocateSpecFromStation(BaseStation
*st
, byte specindex
);
196 /* Draw representation of a station tile for GUI purposes. */
197 bool DrawStationTile (BlitArea
*dpi
, int x
, int y
, RailType railtype
, Axis axis
, StationClassID sclass
, uint station
);
199 void AnimateStationTile(TileIndex tile
);
200 void TriggerStationAnimation(BaseStation
*st
, TileIndex tile
, StationAnimationTrigger trigger
, CargoID cargo_type
= CT_INVALID
);
201 void TriggerStationRandomisation(Station
*st
, TileIndex tile
, StationRandomTrigger trigger
, CargoID cargo_type
= CT_INVALID
);
202 void StationUpdateCachedTriggers(BaseStation
*st
);
204 #endif /* NEWGRF_STATION_H */