OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf_station.h
Go to the documentation of this file.
1 /* $Id: newgrf_station.h 27928 2017-10-25 15:38:14Z 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
33 StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
34
35 /* virtual */ uint32 GetRandomBits() const;
36 /* virtual */ uint32 GetTriggers() const;
37
38 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
39 };
40
42 struct StationResolverObject : public ResolverObject {
43 StationScopeResolver station_scope;
44 TownScopeResolver *town_scope;
45
46 StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
47 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
48 ~StationResolverObject();
49
50 TownScopeResolver *GetTown();
51
52 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
53 {
54 switch (scope) {
55 case VSG_SCOPE_SELF:
56 return &this->station_scope;
57
58 case VSG_SCOPE_PARENT: {
59 TownScopeResolver *tsr = this->GetTown();
60 if (tsr != NULL) return tsr;
61 }
62 FALLTHROUGH;
63
64 default:
65 return ResolverObject::GetScope(scope, relative);
66 }
67 }
68
69 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
70 };
71
72 enum StationClassID {
73 STAT_CLASS_BEGIN = 0,
74 STAT_CLASS_DFLT = 0,
75 STAT_CLASS_WAYP,
76 STAT_CLASS_MAX = 256,
77 };
78 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
79 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
80
82 DECLARE_POSTFIX_INCREMENT(StationClassID)
83
84 enum StationSpecFlags {
85 SSF_SEPARATE_GROUND,
86 SSF_DIV_BY_STATION_SIZE,
87 SSF_CB141_RANDOM_BITS,
88 SSF_CUSTOM_FOUNDATIONS,
89 SSF_EXTENDED_FOUNDATIONS,
90 };
91
93 enum StationRandomTrigger {
94 SRT_NEW_CARGO,
95 SRT_CARGO_TAKEN,
96 SRT_TRAIN_ARRIVES,
97 SRT_TRAIN_DEPARTS,
98 SRT_TRAIN_LOADS,
99 SRT_PATH_RESERVATION,
100 };
101
102 /* Station layout for given dimensions - it is a two-dimensional array
103 * where index is computed as (x * platforms) + platform. */
104 typedef byte *StationLayout;
105
107 struct StationSpec {
114 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
115 StationClassID cls_id;
116 StringID name;
117
122 byte disallowed_platforms;
127 byte disallowed_lengths;
128
137 uint tiles;
138 NewGRFSpriteLayout *renderdata;
139
144 uint16 cargo_threshold;
145
146 uint32 cargo_triggers;
147
148 byte callback_mask;
149
150 byte flags;
151
152 byte pylons;
153 byte wires;
154 byte blocked;
155
156 AnimationInfo animation;
157
158 byte lengths;
159 byte *platforms;
160 StationLayout **layouts;
161 bool copied_layouts;
162 };
163
165 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
166
167 const StationSpec *GetStationSpec(TileIndex t);
168
169 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
170 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
171
172 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
173 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
174 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
175 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
176
177 /* Allocate a StationSpec to a Station. This is called once per build operation. */
178 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
179
180 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
181 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
182
183 /* Draw representation of a station tile for GUI purposes. */
184 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
185
186 void AnimateStationTile(TileIndex tile);
187 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
188 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
189 void StationUpdateCachedTriggers(BaseStation *st);
190
191 #endif /* NEWGRF_STATION_H */