Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / newgrf_station.h
blob8c9aa60976de5bb1bce5494e4091432e21ca881b
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(INVALID_CARGO), axis(INVALID_AXIS)
43 uint32_t GetRandomBits() const override;
44 uint32_t GetTriggers() const override;
46 uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t 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_t callback_param1 = 0, uint32_t 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;
79 GrfSpecFeature GetFeature() const override;
80 uint32_t GetDebugID() const override;
83 enum StationClassID : byte {
84 STAT_CLASS_BEGIN = 0, ///< the lowest valid value
85 STAT_CLASS_DFLT = 0, ///< Default station class.
86 STAT_CLASS_WAYP, ///< Waypoint class.
87 STAT_CLASS_MAX = 255, ///< Maximum number of classes.
90 /** Allow incrementing of StationClassID variables */
91 DECLARE_POSTFIX_INCREMENT(StationClassID)
93 enum StationSpecFlags {
94 SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites.
95 SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size.
96 SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
97 SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations.
98 SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
101 /** Randomisation triggers for stations */
102 enum StationRandomTrigger {
103 SRT_NEW_CARGO, ///< Trigger station on new cargo arrival.
104 SRT_CARGO_TAKEN, ///< Trigger station when cargo is completely taken.
105 SRT_TRAIN_ARRIVES, ///< Trigger platform when train arrives.
106 SRT_TRAIN_DEPARTS, ///< Trigger platform when train leaves.
107 SRT_TRAIN_LOADS, ///< Trigger platform when train loads/unloads.
108 SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path.
111 /** Station specification. */
112 struct StationSpec {
113 StationSpec() : cls_id(STAT_CLASS_DFLT), name(0),
114 disallowed_platforms(0), disallowed_lengths(0),
115 cargo_threshold(0), cargo_triggers(0),
116 callback_mask(0), flags(0), pylons(0), wires(0), blocked(0),
117 animation({0, 0, 0, 0}) {}
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
147 std::vector<NewGRFSpriteLayout> renderdata; ///< Array of tile layouts.
150 * Cargo threshold for choosing between little and lots of cargo
151 * @note little/lots are equivalent to the moving/loading states for vehicles
153 uint16_t cargo_threshold;
155 CargoTypes cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
157 byte callback_mask; ///< Bitmask of station callbacks that have to be called
159 byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
161 byte pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
162 byte wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
163 byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
165 AnimationInfo animation;
168 * Custom platform layouts.
169 * This is a 2D array containing an array of tiles.
170 * 1st layer is platform lengths.
171 * 2nd layer is tracks (width).
172 * These can be sparsely populated, and the upper limit is not defined but
173 * limited to 255.
175 std::vector<std::vector<std::vector<byte>>> layouts;
178 /** Struct containing information relating to station classes. */
179 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
181 const StationSpec *GetStationSpec(TileIndex t);
183 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
184 uint32_t GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
186 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10 = 0);
187 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
188 uint16_t GetStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
189 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
191 /* Allocate a StationSpec to a Station. This is called once per build operation. */
192 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
194 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
195 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
197 /* Draw representation of a station tile for GUI purposes. */
198 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
200 void AnimateStationTile(TileIndex tile);
201 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
202 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
203 void StationUpdateCachedTriggers(BaseStation *st);
205 #endif /* NEWGRF_STATION_H */