Fix: [OSX] Don't show a crash/assertion message box for a GUI-less video driver.
[openttd-github.git] / src / newgrf_station.h
bloba79ea3fe29f9b563cd7a7d6a15bc554427497263
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 */
8 /** @file newgrf_station.h Header file for NewGRF stations */
10 #ifndef NEWGRF_STATION_H
11 #define NEWGRF_STATION_H
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"
23 /** Scope resolver for stations. */
24 struct StationScopeResolver : public ScopeResolver {
25 TileIndex tile; ///< %Tile of the station.
26 struct BaseStation *st; ///< Instance of the station.
27 const struct StationSpec *statspec; ///< Station (type) specification.
28 CargoID cargo_type; ///< Type of cargo of the station.
29 Axis axis; ///< Station axis, used only for the slope check callback.
31 /**
32 * Constructor for station scopes.
33 * @param ro Surrounding resolver.
34 * @param statspec Station (type) specification.
35 * @param st Instance of the station.
36 * @param tile %Tile of the station.
38 StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
39 : ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
43 uint32 GetRandomBits() const override;
44 uint32 GetTriggers() const override;
46 uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
49 /** Station resolver. */
50 struct StationResolverObject : public ResolverObject {
51 StationScopeResolver station_scope; ///< The station scope resolver.
52 TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
54 StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
55 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
56 ~StationResolverObject();
58 TownScopeResolver *GetTown();
60 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
62 switch (scope) {
63 case VSG_SCOPE_SELF:
64 return &this->station_scope;
66 case VSG_SCOPE_PARENT: {
67 TownScopeResolver *tsr = this->GetTown();
68 if (tsr != nullptr) return tsr;
69 FALLTHROUGH;
72 default:
73 return ResolverObject::GetScope(scope, relative);
77 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
80 enum StationClassID : byte {
81 STAT_CLASS_BEGIN = 0, ///< the lowest valid value
82 STAT_CLASS_DFLT = 0, ///< Default station class.
83 STAT_CLASS_WAYP, ///< Waypoint class.
84 STAT_CLASS_MAX = 255, ///< Maximum number of classes.
86 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
88 /** Allow incrementing of StationClassID variables */
89 DECLARE_POSTFIX_INCREMENT(StationClassID)
91 enum StationSpecFlags {
92 SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites.
93 SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size.
94 SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
95 SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations.
96 SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
99 /** Randomisation triggers for stations */
100 enum StationRandomTrigger {
101 SRT_NEW_CARGO, ///< Trigger station on new cargo arrival.
102 SRT_CARGO_TAKEN, ///< Trigger station when cargo is completely taken.
103 SRT_TRAIN_ARRIVES, ///< Trigger platform when train arrives.
104 SRT_TRAIN_DEPARTS, ///< Trigger platform when train leaves.
105 SRT_TRAIN_LOADS, ///< Trigger platform when train loads/unloads.
106 SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path.
109 /* Station layout for given dimensions - it is a two-dimensional array
110 * where index is computed as (x * platforms) + platform. */
111 typedef byte *StationLayout;
113 /** Station specification. */
114 struct StationSpec {
116 * Properties related the the grf file.
117 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
118 * Used for obtaining the sprite offset of custom sprites, and for
119 * evaluating callbacks.
121 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
122 StationClassID cls_id; ///< The class to which this spec belongs.
123 StringID name; ///< Name of this station.
126 * Bitmask of number of platforms available for the station.
127 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
129 byte disallowed_platforms;
131 * Bitmask of platform lengths available for the station.
132 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
134 byte disallowed_lengths;
137 * Number of tile layouts.
138 * A minimum of 8 is required is required for stations.
139 * 0-1 = plain platform
140 * 2-3 = platform with building
141 * 4-5 = platform with roof, left side
142 * 6-7 = platform with roof, right side
144 uint tiles;
145 NewGRFSpriteLayout *renderdata; ///< Array of tile layouts.
148 * Cargo threshold for choosing between little and lots of cargo
149 * @note little/lots are equivalent to the moving/loading states for vehicles
151 uint16 cargo_threshold;
153 CargoTypes cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
155 byte callback_mask; ///< Bitmask of station callbacks that have to be called
157 byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
159 byte pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
160 byte wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
161 byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
163 AnimationInfo animation;
165 byte lengths;
166 byte *platforms;
167 StationLayout **layouts;
168 bool copied_layouts;
171 /** Struct containing information relating to station classes. */
172 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
174 const StationSpec *GetStationSpec(TileIndex t);
176 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
177 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
179 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
180 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
181 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
182 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
184 /* Allocate a StationSpec to a Station. This is called once per build operation. */
185 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
187 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
188 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
190 /* Draw representation of a station tile for GUI purposes. */
191 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
193 void AnimateStationTile(TileIndex tile);
194 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
195 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
196 void StationUpdateCachedTriggers(BaseStation *st);
198 #endif /* NEWGRF_STATION_H */