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 
57  CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
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 
87 };
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 
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 {
125  StationClassID cls_id;
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 
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 */
Helper template class that makes basic properties of given enumeration type visible from outsize...
Definition: enum_type.hpp:66
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.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
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.
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...
uint32 cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Set when using the callback resolve system, but not to resolve a callback.
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:25
Types related to cargoes...
uint tiles
Number of tile layouts.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Waypoint class.
Callbacks that NewGRFs could implement.
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10=0)
Resolve sprites for drawing a station tile.
Scope resolver for stations.
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
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.
uint32 GetRandomBits() const
Get a few random bits.
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:24
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:52
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).
Invalid cargo type.
Definition: cargo_type.h:70
Resolved object itself.
NewGRF supplied spritelayout.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
TileIndex tile
Tile of the station.
Template of struct holding enum types (on most archs, enums are stored in an int32).
Definition: enum_type.hpp:139
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.
struct BaseStation * st
Instance of the station.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
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.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Related object of the resolved one.
Trigger platform when train loads/unloads.
Default station class.
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.
Maximum number of classes.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
Information about animation.
StationClassID
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.
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:22
NewGRFSpriteLayout * renderdata
Array of tile layouts.
Divide cargo amount by station size.
StringID name
Name of this station.
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
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.
Base class for all station-ish types.
Station data structure.
Definition: station_base.h:446
Axis
Allow incrementing of DiagDirDiff variables.
uint32 GetTriggers() const
Get the triggers.
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
The different types of rail.