OpenTTD
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 
28  struct BaseStation *st;
29  const struct StationSpec *statspec;
32 
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 
55 
56  StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
59 
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 
87 };
89 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
90 
93 
100 };
101 
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 {
127 
138 
147  uint tiles;
149 
155 
156  uint32 cargo_triggers;
157 
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 
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);
200 
201 #endif /* NEWGRF_STATION_H */