Update: Translations from eints
[openttd-github.git] / src / newgrf_roadstop.h
blob9144986ab36920f6b0ba5ec36cf71e7bc90a2597
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 */
8 /**
9 * @file newgrf_roadstop.h NewGRF definitions and structures for road stops.
12 #ifndef NEWGRF_ROADSTATION_H
13 #define NEWGRF_ROADSTATION_H
15 #include "newgrf_animation_type.h"
16 #include "newgrf_spritegroup.h"
17 #include "newgrf_class.h"
18 #include "newgrf_commons.h"
19 #include "newgrf_town.h"
20 #include "road.h"
22 /** The maximum amount of roadstops a single GRF is allowed to add */
23 static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1;
25 static const uint32_t ROADSTOP_CLASS_LABEL_DEFAULT = 'DFLT';
26 static const uint32_t ROADSTOP_CLASS_LABEL_WAYPOINT = 'WAYP';
28 enum RoadStopClassID : uint16_t {
29 ROADSTOP_CLASS_BEGIN = 0, ///< The lowest valid value
30 ROADSTOP_CLASS_DFLT = 0, ///< Default road stop class.
31 ROADSTOP_CLASS_WAYP, ///< Waypoint class.
32 ROADSTOP_CLASS_MAX = UINT16_MAX, ///< Maximum number of classes.
34 DECLARE_POSTFIX_INCREMENT(RoadStopClassID)
36 /* Some Triggers etc. */
37 enum RoadStopRandomTrigger {
38 RSRT_NEW_CARGO, ///< Trigger roadstop on arrival of new cargo.
39 RSRT_CARGO_TAKEN, ///< Trigger roadstop when cargo is completely taken.
40 RSRT_VEH_ARRIVES, ///< Trigger roadstop when road vehicle arrives.
41 RSRT_VEH_DEPARTS, ///< Trigger roadstop when road vehicle leaves.
42 RSRT_VEH_LOADS, ///< Trigger roadstop when road vehicle loads.
45 /**
46 * Various different options for availability, restricting
47 * the roadstop to be only for busses or for trucks.
49 enum RoadStopAvailabilityType : uint8_t {
50 ROADSTOPTYPE_PASSENGER, ///< This RoadStop is for passenger (bus) stops.
51 ROADSTOPTYPE_FREIGHT, ///< This RoadStop is for freight (truck) stops.
52 ROADSTOPTYPE_ALL, ///< This RoadStop is for both types of station road stops.
54 ROADSTOPTYPE_END,
57 /**
58 * Different draw modes to disallow rendering of some parts of the stop
59 * or road.
61 enum RoadStopDrawMode : uint8_t {
62 ROADSTOP_DRAW_MODE_NONE = 0,
63 ROADSTOP_DRAW_MODE_ROAD = 1 << 0, ///< Bay stops: Draw the road itself
64 ROADSTOP_DRAW_MODE_OVERLAY = 1 << 1, ///< Drive-through stops: Draw the road overlay, e.g. pavement
65 ROADSTOP_DRAW_MODE_WAYP_GROUND = 1 << 2, ///< Waypoints: Draw the sprite layout ground tile (on top of the road)
67 DECLARE_ENUM_AS_BIT_SET(RoadStopDrawMode)
69 enum RoadStopSpecFlags {
70 RSF_CB141_RANDOM_BITS = 0, ///< Callback 141 needs random bits.
71 RSF_NO_CATENARY = 2, ///< Do not show catenary.
72 RSF_DRIVE_THROUGH_ONLY = 3, ///< Stop is drive-through only.
73 RSF_NO_AUTO_ROAD_CONNECTION = 4, ///< No auto road connection.
74 RSF_BUILD_MENU_ROAD_ONLY = 5, ///< Only show in the road build menu (not tram).
75 RSF_BUILD_MENU_TRAM_ONLY = 6, ///< Only show in the tram build menu (not road).
76 RSF_DRAW_MODE_REGISTER = 8, ///< Read draw mode from register 0x100.
79 enum RoadStopView {
80 RSV_BAY_NE = 0, ///< Bay road stop, facing Northeast
81 RSV_BAY_SE = 1, ///< Bay road stop, facing Southeast
82 RSV_BAY_SW = 2, ///< Bay road stop, facing Southwest
83 RSV_BAY_NW = 3, ///< Bay road stop, facing Northwest
84 RSV_DRIVE_THROUGH_X = 4, ///< Drive through road stop, X axis
85 RSV_DRIVE_THROUGH_Y = 5, ///< Drive through road stop, Y axis
88 /** Scope resolver for road stops. */
89 struct RoadStopScopeResolver : public ScopeResolver {
90 TileIndex tile; ///< %Tile of the station.
91 struct BaseStation *st; ///< Instance of the station.
92 const struct RoadStopSpec *roadstopspec; ///< Station (type) specification.
93 CargoID cargo_type; ///< Type of cargo of the station.
94 StationType type; ///< Station type.
95 uint8_t view; ///< Station axis.
96 RoadType roadtype; ///< Road type (used when no tile)
98 RoadStopScopeResolver(ResolverObject &ro, BaseStation *st, const RoadStopSpec *roadstopspec, TileIndex tile, RoadType roadtype, StationType type, uint8_t view = 0)
99 : ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), roadtype(roadtype)
103 uint32_t GetRandomBits() const override;
104 uint32_t GetTriggers() const override;
106 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
109 /** Road stop resolver. */
110 struct RoadStopResolverObject : public ResolverObject {
111 RoadStopScopeResolver roadstop_scope; ///< The stop scope resolver.
112 std::optional<TownScopeResolver> town_scope = std::nullopt; ///< The town scope resolver (created on the first call).
114 RoadStopResolverObject(const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view, CallbackID callback = CBID_NO_CALLBACK, uint32_t param1 = 0, uint32_t param2 = 0);
116 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
118 switch (scope) {
119 case VSG_SCOPE_SELF: return &this->roadstop_scope;
120 case VSG_SCOPE_PARENT: {
121 TownScopeResolver *tsr = this->GetTown();
122 if (tsr != nullptr) return tsr;
123 [[fallthrough]];
125 default: return ResolverObject::GetScope(scope, relative);
129 TownScopeResolver *GetTown();
131 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
134 /** Road stop specification. */
135 struct RoadStopSpec : NewGRFSpecBase<RoadStopClassID> {
137 * Properties related the the grf file.
138 * NUM_CARGO real cargo plus three pseudo cargo sprite groups.
139 * Used for obtaining the sprite offset of custom sprites, and for
140 * evaluating callbacks.
142 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
143 StringID name; ///< Name of this stop
145 RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL;
146 RoadStopDrawMode draw_mode = ROADSTOP_DRAW_MODE_ROAD | ROADSTOP_DRAW_MODE_OVERLAY;
147 uint8_t callback_mask = 0;
148 uint16_t flags = 0;
150 CargoTypes cargo_triggers = 0; ///< Bitmask of cargo types which cause trigger re-randomizing
152 AnimationInfo animation;
154 uint8_t bridge_height[6]; ///< Minimum height for a bridge above, 0 for none
155 uint8_t bridge_disallowed_pillars[6]; ///< Disallowed pillar flags for a bridge above
157 uint8_t build_cost_multiplier = 16; ///< Build cost multiplier per tile.
158 uint8_t clear_cost_multiplier = 16; ///< Clear cost multiplier per tile.
161 * Get the cost for building a road stop of this type.
162 * @return The cost for building.
164 Money GetBuildCost(Price category) const { return GetPrice(category, this->build_cost_multiplier, this->grf_prop.grffile, -4); }
167 * Get the cost for clearing a road stop of this type.
168 * @return The cost for clearing.
170 Money GetClearCost(Price category) const { return GetPrice(category, this->clear_cost_multiplier, this->grf_prop.grffile, -4); }
172 static const RoadStopSpec *Get(uint16_t index);
175 using RoadStopClass = NewGRFClass<RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX>;
177 void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
179 uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view);
181 void AnimateRoadStopTile(TileIndex tile);
182 uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile);
183 void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
184 void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
186 bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype);
187 bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
188 bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype);
190 const RoadStopSpec *GetRoadStopSpec(TileIndex t);
191 int AllocateSpecToRoadStop(const RoadStopSpec *statspec, BaseStation *st, bool exec);
192 void DeallocateSpecFromRoadStop(BaseStation *st, uint8_t specindex);
193 void RoadStopUpdateCachedTriggers(BaseStation *st);
196 * Test if a RoadStopClass is the waypoint class.
197 * @param cls RoadStopClass to test.
198 * @return true if the class is the waypoint class.
200 inline bool IsWaypointClass(const RoadStopClass &cls)
202 return cls.global_id == ROADSTOP_CLASS_LABEL_WAYPOINT || GB(cls.global_id, 24, 8) == UINT8_MAX;
205 #endif /* NEWGRF_ROADSTATION_H */