OpenTTD: src/newgrf_station.h Source File

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 27984 2018-03-11 13:19:41Z 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
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)
42 {
43 }
44
45 /* virtual */ uint32 GetRandomBits() const;
46 /* virtual */ uint32 GetTriggers() const;
47
48 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
49 };
50
52 struct StationResolverObject : public ResolverObject {
53 StationScopeResolver station_scope;
54 TownScopeResolver *town_scope;
55
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();
59
60 TownScopeResolver *GetTown();
61
62 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
63 {
64 switch (scope) {
65 case VSG_SCOPE_SELF:
66 return &this->station_scope;
67
68 case VSG_SCOPE_PARENT: {
69 TownScopeResolver *tsr = this->GetTown();
70 if (tsr != NULL) return tsr;
71 }
72 FALLTHROUGH;
73
74 default:
75 return ResolverObject::GetScope(scope, relative);
76 }
77 }
78
79 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
80 };
81
82 enum StationClassID {
83 STAT_CLASS_BEGIN = 0,
84 STAT_CLASS_DFLT = 0,
85 STAT_CLASS_WAYP,
86 STAT_CLASS_MAX = 256,
87 };
88 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
89 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
90
92 DECLARE_POSTFIX_INCREMENT(StationClassID)
93
94 enum StationSpecFlags {
95 SSF_SEPARATE_GROUND,
96 SSF_DIV_BY_STATION_SIZE,
97 SSF_CB141_RANDOM_BITS,
98 SSF_CUSTOM_FOUNDATIONS,
99 SSF_EXTENDED_FOUNDATIONS,
100 };
101
103 enum StationRandomTrigger {
104 SRT_NEW_CARGO,
105 SRT_CARGO_TAKEN,
106 SRT_TRAIN_ARRIVES,
107 SRT_TRAIN_DEPARTS,
108 SRT_TRAIN_LOADS,
109 SRT_PATH_RESERVATION,
110 };
111
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;
115
117 struct StationSpec {
124 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
125 StationClassID cls_id;
126 StringID name;
127
132 byte disallowed_platforms;
137 byte disallowed_lengths;
138
147 uint tiles;
148 NewGRFSpriteLayout *renderdata;
149
154 uint16 cargo_threshold;
155
156 uint32 cargo_triggers;
157
158 byte callback_mask;
159
160 byte flags;
161
162 byte pylons;
163 byte wires;
164 byte blocked;
165
166 AnimationInfo animation;
167
168 byte lengths;
169 byte *platforms;
170 StationLayout **layouts;
171 bool copied_layouts;
172 };
173
175 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
176
177 const StationSpec *GetStationSpec(TileIndex t);
178
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);
181
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);
186
187 /* Allocate a StationSpec to a Station. This is called once per build operation. */
188 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
189
190 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
191 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
192
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);
195
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);
200
201 #endif /* NEWGRF_STATION_H */