Translations update
[openttd/fttd.git] / src / newgrf_station.h
blob62bb940a4e7789bee1ab8d956a6f20f1d1658a96
1 /* $Id$ */
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 */
10 /** @file newgrf_station.h Header file for NewGRF stations */
12 #ifndef NEWGRF_STATION_H
13 #define NEWGRF_STATION_H
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"
25 /** Scope resolver for stations. */
26 struct StationScopeResolver : public ScopeResolver {
27 TileIndex tile; ///< %Tile of the station.
28 struct BaseStation *st; ///< Instance of the station.
29 const struct StationSpec *statspec; ///< Station (type) specification.
30 CargoID cargo_type; ///< Type of cargo of the station.
31 Axis axis; ///< Station axis, used only for the slope check callback.
33 StationScopeResolver(ResolverObject *ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
35 /* virtual */ uint32 GetRandomBits() const;
36 /* virtual */ uint32 GetTriggers() const;
37 /* virtual */ void SetTriggers(int triggers) const;
39 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
42 /** Station resolver. */
43 struct StationResolverObject : public ResolverObject {
44 StationScopeResolver station_scope; ///< The station scope resolver.
45 TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
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();
51 TownScopeResolver *GetTown();
53 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
55 switch (scope) {
56 case VSG_SCOPE_SELF:
57 return &this->station_scope;
59 case VSG_SCOPE_PARENT: {
60 TownScopeResolver *tsr = this->GetTown();
61 if (tsr != NULL) return tsr;
62 /* FALL-THROUGH */
65 default:
66 return ResolverObject::GetScope(scope, relative);
70 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
73 enum StationClassID {
74 STAT_CLASS_BEGIN = 0, ///< the lowest valid value
75 STAT_CLASS_DFLT = 0, ///< Default station class.
76 STAT_CLASS_WAYP, ///< Waypoint class.
77 STAT_CLASS_MAX = 256, ///< Maximum number of classes.
79 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
80 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
82 /** Allow incrementing of StationClassID variables */
83 DECLARE_POSTFIX_INCREMENT(StationClassID)
85 enum StationSpecFlags {
86 SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites.
87 SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size.
88 SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
89 SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations.
90 SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
93 /** Randomisation triggers for stations */
94 enum StationRandomTrigger {
95 SRT_NEW_CARGO, ///< Trigger station on new cargo arrival.
96 SRT_CARGO_TAKEN, ///< Trigger station when cargo is completely taken.
97 SRT_TRAIN_ARRIVES, ///< Trigger platform when train arrives.
98 SRT_TRAIN_DEPARTS, ///< Trigger platform when train leaves.
99 SRT_TRAIN_LOADS, ///< Trigger platform when train loads/unloads.
100 SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path.
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;
107 /** Station specification. */
108 struct StationSpec {
110 * Properties related the the grf file.
111 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
112 * Used for obtaining the sprite offset of custom sprites, and for
113 * evaluating callbacks.
115 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
116 StationClassID cls_id; ///< The class to which this spec belongs.
117 StringID name; ///< Name of this station.
120 * Bitmask of number of platforms available for the station.
121 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
123 byte disallowed_platforms;
125 * Bitmask of platform lengths available for the station.
126 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
128 byte disallowed_lengths;
131 * Number of tile layouts.
132 * A minimum of 8 is required is required for stations.
133 * 0-1 = plain platform
134 * 2-3 = platform with building
135 * 4-5 = platform with roof, left side
136 * 6-7 = platform with roof, right side
138 uint tiles;
139 NewGRFSpriteLayout *renderdata; ///< Array of tile layouts.
142 * Cargo threshold for choosing between little and lots of cargo
143 * @note little/lots are equivalent to the moving/loading states for vehicles
145 uint16 cargo_threshold;
147 uint32 cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
149 byte callback_mask; ///< Bitmask of station callbacks that have to be called
151 byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
153 byte pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
154 byte wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
155 byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
157 AnimationInfo animation;
159 byte lengths;
160 byte *platforms;
161 StationLayout **layouts;
162 bool copied_layouts;
165 /** Struct containing information relating to station classes. */
166 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
168 const StationSpec *GetStationSpec(TileIndex t);
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);
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);
178 /* Allocate a StationSpec to a Station. This is called once per build operation. */
179 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
181 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
182 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
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);
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);
192 #endif /* NEWGRF_STATION_H */