Translations update
[openttd/fttd.git] / src / newgrf_station.h
blob824fe523fd28247e648cff53af8eed0d697d6154
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 <vector>
17 #include "core/pointer.h"
18 #include "newgrf_animation_type.h"
19 #include "newgrf_callbacks.h"
20 #include "newgrf_class.h"
21 #include "newgrf_commons.h"
22 #include "cargo_type.h"
23 #include "station_type.h"
24 #include "rail_type.h"
25 #include "newgrf_spritegroup.h"
26 #include "newgrf_town.h"
28 /** Scope resolver for stations. */
29 struct StationScopeResolver : public ScopeResolver {
30 const GRFFile *const grffile; ///< GRFFile the resolved SpriteGroup belongs to.
31 TileIndex tile; ///< %Tile of the station.
32 struct BaseStation *st; ///< Instance of the station.
33 const struct StationSpec *statspec; ///< Station (type) specification.
34 CargoID cargo_type; ///< Type of cargo of the station.
36 StationScopeResolver (const GRFFile *grffile, const StationSpec *statspec, BaseStation *st, TileIndex tile);
38 /* virtual */ uint32 GetRandomBits() const;
39 /* virtual */ uint32 GetTriggers() const;
40 /* virtual */ void SetTriggers(int triggers) const;
42 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
45 /** Station resolver. */
46 struct StationResolverObject : public ResolverObject {
47 StationScopeResolver station_scope; ///< The station scope resolver.
48 TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
50 const SpriteGroup *root_spritegroup; ///< Root SpriteGroup to use for resolving
52 StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
53 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
54 ~StationResolverObject();
56 TownScopeResolver *GetTown();
58 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
60 switch (scope) {
61 case VSG_SCOPE_SELF:
62 return &this->station_scope;
64 case VSG_SCOPE_PARENT: {
65 TownScopeResolver *tsr = this->GetTown();
66 if (tsr != NULL) return tsr;
67 /* FALL-THROUGH */
70 default:
71 return ResolverObject::GetScope(scope, relative);
75 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
77 /**
78 * Resolve SpriteGroup.
79 * @return Result spritegroup.
81 const SpriteGroup *Resolve()
83 return SpriteGroup::Resolve (this->root_spritegroup, *this);
87 enum StationClassID {
88 STAT_CLASS_BEGIN = 0, ///< the lowest valid value
89 STAT_CLASS_DFLT = 0, ///< Default station class.
90 STAT_CLASS_WAYP, ///< Waypoint class.
91 STAT_CLASS_MAX = 256, ///< Maximum number of classes.
93 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
94 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
96 /** Allow incrementing of StationClassID variables */
97 DECLARE_POSTFIX_INCREMENT(StationClassID)
99 enum StationSpecFlags {
100 SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites.
101 SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size.
102 SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
103 SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations.
104 SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
107 /** Randomisation triggers for stations */
108 enum StationRandomTrigger {
109 SRT_NEW_CARGO, ///< Trigger station on new cargo arrival.
110 SRT_CARGO_TAKEN, ///< Trigger station when cargo is completely taken.
111 SRT_TRAIN_ARRIVES, ///< Trigger platform when train arrives.
112 SRT_TRAIN_DEPARTS, ///< Trigger platform when train leaves.
113 SRT_TRAIN_LOADS, ///< Trigger platform when train loads/unloads.
114 SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path.
117 /* Station layout for given dimensions - it is a two-dimensional array
118 * where index is computed as (x * platforms) + platform. */
119 typedef byte *StationLayout;
121 /** Station specification. */
122 struct StationSpec {
124 * Properties related the the grf file.
125 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
126 * Used for obtaining the sprite offset of custom sprites, and for
127 * evaluating callbacks.
129 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
130 StationClassID cls_id; ///< The class to which this spec belongs.
131 StringID name; ///< Name of this station.
134 * Bitmask of number of platforms available for the station.
135 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
137 byte disallowed_platforms;
139 * Bitmask of platform lengths available for the station.
140 * 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
142 byte disallowed_lengths;
145 * Tile layouts.
146 * A minimum of 8 is required is required for stations.
147 * 0-1 = plain platform
148 * 2-3 = platform with building
149 * 4-5 = platform with roof, left side
150 * 6-7 = platform with roof, right side
152 std::vector <ttd_unique_ptr <NewGRFSpriteLayout> > renderdata;
155 * Cargo threshold for choosing between little and lots of cargo
156 * @note little/lots are equivalent to the moving/loading states for vehicles
158 uint16 cargo_threshold;
160 uint32 cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
162 byte callback_mask; ///< Bitmask of station callbacks that have to be called
164 byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
166 byte pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
167 byte wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
168 byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
170 AnimationInfo animation;
172 byte lengths;
173 byte *platforms;
174 StationLayout **layouts;
175 bool copied_layouts;
178 /** Struct containing information relating to station classes. */
179 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
181 const StationSpec *GetStationSpec(TileIndex t);
183 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
184 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
186 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
187 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
188 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
190 uint16 GetStationCallback (CallbackID callback, uint32 param1, uint32 param2,
191 const StationSpec *statspec, RailType rt, TileIndex tile = INVALID_TILE);
192 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile,
193 TileIndex cur_tile, const StationSpec *statspec, RailType rt,
194 Axis axis, byte plat_len, byte numtracks);
196 /* Allocate a StationSpec to a Station. This is called once per build operation. */
197 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
199 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
200 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
202 /* Draw representation of a station tile for GUI purposes. */
203 bool DrawStationTile (BlitArea *dpi, int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
205 void AnimateStationTile(TileIndex tile);
206 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
207 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
208 void StationUpdateCachedTriggers(BaseStation *st);
210 #endif /* NEWGRF_STATION_H */