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