OpenTTD
newgrf_station.h
Go to the documentation of this file.
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  */
7 
10 #ifndef NEWGRF_STATION_H
11 #define NEWGRF_STATION_H
12 
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"
22 
26  struct BaseStation *st;
27  const struct StationSpec *statspec;
30 
39  : ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
40  {
41  }
42 
43  uint32 GetRandomBits() const override;
44  uint32 GetTriggers() const override;
45 
46  uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
47 };
48 
53 
55  CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
57 
58  TownScopeResolver *GetTown();
59 
60  ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
61  {
62  switch (scope) {
63  case VSG_SCOPE_SELF:
64  return &this->station_scope;
65 
66  case VSG_SCOPE_PARENT: {
67  TownScopeResolver *tsr = this->GetTown();
68  if (tsr != nullptr) return tsr;
69  FALLTHROUGH;
70  }
71 
72  default:
73  return ResolverObject::GetScope(scope, relative);
74  }
75  }
76 
77  const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
78 };
79 
80 enum StationClassID : byte {
85 };
86 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
87 
89 DECLARE_POSTFIX_INCREMENT(StationClassID)
90 
97 };
98 
107 };
108 
109 /* Station layout for given dimensions - it is a two-dimensional array
110  * where index is computed as (x * platforms) + platform. */
111 typedef byte *StationLayout;
112 
114 struct StationSpec {
122  StationClassID cls_id;
124 
135 
144  uint tiles;
146 
152 
153  CargoTypes cargo_triggers;
154 
156 
157  byte flags;
158 
159  byte pylons;
160  byte wires;
161  byte blocked;
162 
163  AnimationInfo animation;
164 
165  byte lengths;
166  byte *platforms;
167  StationLayout **layouts;
168  bool copied_layouts;
169 };
170 
173 
174 const StationSpec *GetStationSpec(TileIndex t);
175 
176 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
177 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
178 
181 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
182 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
183 
184 /* Allocate a StationSpec to a Station. This is called once per build operation. */
185 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
186 
187 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
188 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
189 
190 /* Draw representation of a station tile for GUI purposes. */
191 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
192 
193 void AnimateStationTile(TileIndex tile);
194 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
197 
198 #endif /* NEWGRF_STATION_H */
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:62
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
Callback 141 needs random bits.
Trigger station when cargo is completely taken.
Waypoint class.
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
ResolverObject & ro
Surrounding resolver object.
StationScopeResolver station_scope
The station scope resolver.
VarSpriteGroupScope
Interface for SpriteGroup-s to access the gamestate.
Station specification.
Default station class.
Definitions related to NewGRF animation.
Trigger platform when train leaves.
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
Evaluate a tile&#39;s position within a station, and return the result in a bit-stuffed format...
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Set when using the callback resolve system, but not to resolve a callback.
uint32 GetRandomBits() const override
Get a few random bits.
Draw custom foundations.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Common return value for all commands.
Definition: command_type.h:23
Types related to cargoes...
uint tiles
Number of tile layouts.
Callbacks that NewGRFs could implement.
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10=0)
Resolve sprites for drawing a station tile.
Invalid cargo type.
Definition: cargo_type.h:68
uint32 GetTriggers() const override
Get the triggers.
Scope resolver for stations.
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
Types related to stations.
Action 2 handling.
Axis axis
Station axis, used only for the slope check callback.
NewGRFClass< StationSpec, StationClassID, STAT_CLASS_MAX > StationClass
Struct containing information relating to station classes.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
StationSpecFlags
Allow incrementing of StationClassID variables.
Trigger platform when train reserves path.
Scope resolver for a town.
Definition: newgrf_town.h:22
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type=CT_INVALID)
Trigger station randomisation.
the lowest valid value
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Resolved object itself.
NewGRF supplied spritelayout.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
TileIndex tile
Tile of the station.
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size...
StationAnimationTrigger
Animation triggers for station.
Header file for classes to be used by e.g.
CargoID cargo_type
Type of cargo of the station.
const struct StationSpec * statspec
Station (type) specification.
Trigger platform when train arrives.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
struct BaseStation * st
Instance of the station.
StationClassID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Use different sprite set for ground sprites.
Extended foundation block instead of simple.
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
Check the slope of a tile of a new station.
Trigger station on new cargo arrival.
Related object of the resolved one.
Trigger platform when train loads/unloads.
Maximum number of classes.
uint16 cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
Constructor for station scopes.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
Information about animation.
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
StationRandomTrigger
Randomisation triggers for stations.
CallbackID
List of implemented NewGRF callbacks.
Station resolver.
byte callback_mask
Bitmask of station callbacks that have to be called.
byte disallowed_lengths
Bitmask of platform lengths available for the station.
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
Functions to handle the town part of NewGRF towns.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
NewGRFSpriteLayout * renderdata
Array of tile layouts.
Divide cargo amount by station size.
StringID name
Name of this station.
Flag for an invalid Axis.
byte disallowed_platforms
Bitmask of number of platforms available for the station.
StationClassID cls_id
The class to which this spec belongs.
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
Base class for all station-ish types.
Station data structure.
Definition: station_base.h:450
Axis
Allow incrementing of DiagDirDiff variables.
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
The different types of rail.