OpenTTD Source 20260311-master-g511d3794ce
newgrf_roadstop.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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NEWGRF_ROADSTATION_H
11#define NEWGRF_ROADSTATION_H
12
13#include "bridge_type.h"
15#include "newgrf_spritegroup.h"
16#include "newgrf_badge_type.h"
17#include "newgrf_callbacks.h"
18#include "newgrf_class.h"
19#include "newgrf_commons.h"
20#include "newgrf_town.h"
21#include "road.h"
22
23struct TileInfo;
24
26static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1;
27
28static const uint32_t ROADSTOP_CLASS_LABEL_DEFAULT = 'DFLT';
29static const uint32_t ROADSTOP_CLASS_LABEL_WAYPOINT = 'WAYP';
30
33
36
48
53enum class RoadStopDrawMode : uint8_t {
54 Road = 0,
55 Overlay = 1,
57};
58using RoadStopDrawModes = EnumBitSet<RoadStopDrawMode, uint8_t>;
59
69using RoadStopSpecFlags = EnumBitSet<RoadStopSpecFlag, uint8_t>;
70
79
81struct RoadStopScopeResolver : public ScopeResolver {
83 struct BaseStation *st = nullptr;
84 const struct RoadStopSpec *roadstopspec = nullptr;
87 uint8_t view = 0;
89
92 {
93 }
94
95 uint32_t GetRandomBits() const override;
96 uint32_t GetRandomTriggers() const override;
97
98 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
99};
100
102struct RoadStopResolverObject : public SpecializedResolverObject<StationRandomTriggers> {
104 std::optional<TownScopeResolver> town_scope = std::nullopt;
105
106 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);
107
108 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
109 {
110 switch (scope) {
111 case VSG_SCOPE_SELF: return &this->roadstop_scope;
112 case VSG_SCOPE_PARENT: {
113 TownScopeResolver *tsr = this->GetTown();
114 if (tsr != nullptr) return tsr;
115 [[fallthrough]];
116 }
117 default: return ResolverObject::GetScope(scope, relative);
118 }
119 }
120
121 TownScopeResolver *GetTown();
122};
123
125struct RoadStopSpec : NewGRFSpecBase<RoadStopClassID> {
128
130 RoadStopDrawModes draw_mode = {RoadStopDrawMode::Road, RoadStopDrawMode::Overlay};
131 RoadStopCallbackMasks callback_mask{};
132 RoadStopSpecFlags flags{};
133
134 CargoTypes cargo_triggers = 0;
135
137
140
141 std::array<BridgeableTileInfo, 6> bridgeable_info{};
142 std::vector<BadgeID> badges;
143
149 Money GetBuildCost(Price category) const { return GetPrice(category, this->build_cost_multiplier, this->grf_prop.grffile, -4); }
150
156 Money GetClearCost(Price category) const { return GetPrice(category, this->clear_cost_multiplier, this->grf_prop.grffile, -4); }
157
158 static const RoadStopSpec *Get(uint16_t index);
159};
160
162
163std::optional<SpriteLayoutProcessor> GetRoadStopLayout(TileInfo *ti, const RoadStopSpec *spec, BaseStation *st, StationType type, int view, std::span<int32_t> regs100 = {});
164void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
165
166uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view, std::span<int32_t> regs100 = {});
167
168void AnimateRoadStopTile(TileIndex tile);
169uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile);
170void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoType cargo_type = INVALID_CARGO);
171void TriggerRoadStopRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type = INVALID_CARGO);
172
173bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype);
174bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
175bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype);
176
177const RoadStopSpec *GetRoadStopSpec(TileIndex t);
178std::optional<uint8_t> AllocateSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st);
179void AssignSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st, uint8_t specindex);
180void DeallocateSpecFromRoadStop(BaseStation *st, uint8_t specindex);
182
188inline bool IsWaypointClass(const RoadStopClass &cls)
189{
190 return cls.global_id == ROADSTOP_CLASS_LABEL_WAYPOINT || GB(cls.global_id, 24, 8) == UINT8_MAX;
191}
192
193#endif /* NEWGRF_ROADSTATION_H */
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Header file for bridge types.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
Enum-as-bit-set wrapper.
Struct containing information relating to NewGRF classes for stations and airports.
uint32_t global_id
Global ID for class, e.g. 'DFLT', 'WAYP', etc.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition economy.cpp:940
Price
Enumeration of all base prices for use with Prices.
Definitions related to NewGRF animation.
Types related to NewGRF badges.
Callbacks that NewGRFs could implement.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Header file for classes to be used by for example, NewGRF stations and airports.
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
RoadStopDrawMode
Different draw modes to disallow rendering of some parts of the stop or road.
@ Overlay
Drive-through stops: Draw the road overlay, e.g. pavement.
@ WaypGround
Waypoints: Draw the sprite layout ground tile (on top of the road).
@ Road
Bay stops: Draw the road itself.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
PoolID< uint16_t, struct RoadStopClassIDTag, UINT16_MAX, UINT16_MAX > RoadStopClassID
Class IDs for stations.
static constexpr RoadStopClassID ROADSTOP_CLASS_DFLT
Default road stop class.
void TriggerRoadStopRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type=INVALID_CARGO)
Trigger road stop randomisation.
static constexpr RoadStopClassID ROADSTOP_CLASS_WAYP
Waypoint class.
void DeallocateSpecFromRoadStop(BaseStation *st, uint8_t specindex)
Deallocate a RoadStopSpec from a Station.
std::optional< uint8_t > AllocateSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st)
Allocate a RoadStopSpec to a Station.
void RoadStopUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
void AssignSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st, uint8_t specindex)
Assign a previously allocated RoadStopSpec specindex to a Station.
RoadStopAvailabilityType
Various different options for availability, restricting the roadstop to be only for busses or for tru...
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
Draw representation of a road stop tile for GUI purposes.
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
Checks if there's any new stations by a specific RoadStopType.
static const int NUM_ROADSTOPS_PER_GRF
The maximum amount of roadstops a single GRF is allowed to add.
RoadStopView
@ RSV_BAY_NW
Bay road stop, facing Northwest.
@ RSV_BAY_SW
Bay road stop, facing Southwest.
@ RSV_BAY_SE
Bay road stop, facing Southeast.
@ RSV_BAY_NE
Bay road stop, facing Northeast.
@ RSV_DRIVE_THROUGH_X
Drive through road stop, X axis.
@ RSV_DRIVE_THROUGH_Y
Drive through road stop, Y axis.
RoadStopSpecFlag
@ NoCatenary
Do not show catenary.
@ NoAutoRoadConnection
No auto road connection.
@ RoadOnly
Only show in the road build menu (not tram).
@ Cb141RandomBits
Callback 141 needs random bits.
@ TramOnly
Only show in the tram build menu (not road).
@ DriveThroughOnly
Stop is drive-through only.
@ DrawModeRegister
Read draw mode from register 0x100.
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopSpec is compatible with the given RoadStopType.
Action 2 handling.
VarSpriteGroupScope
Shared by deterministic and random groups.
@ VSG_SCOPE_SELF
Resolved object itself.
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Functions to handle the town part of NewGRF towns.
Road specific functions.
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ Road
Truck or bus stop.
RoadStopType
Types of RoadStops.
StationType
Station types.
StationRandomTrigger
Randomisation triggers for stations and roadstops.
StationAnimationTrigger
Animation triggers for stations and roadstops.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Information about animation.
Base class for all station-ish types.
Sprite groups indexed by CargoType.
const struct GRFFile * grffile
grf file that introduced this entity
Base for each type of NewGRF spec to be used with NewGRFClass.
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:47
Interface for SpriteGroup-s to access the gamestate.
CallbackID callback
Callback being resolved.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
RoadStopScopeResolver roadstop_scope
The stop scope resolver.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
Scope resolver for road stops.
uint8_t view
Station axis.
RoadType roadtype
Road type (used when no tile).
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
StationType type
Station type.
const struct RoadStopSpec * roadstopspec
Station (type) specification.
struct BaseStation * st
Instance of the station.
uint32_t GetRandomTriggers() const override
Get the triggers.
CargoType cargo_type
Type of cargo of the station.
TileIndex tile
Tile of the station.
uint32_t GetRandomBits() const override
Get a few random bits.
Road stop specification.
StringID name
Name of this stop.
uint8_t clear_cost_multiplier
Clear cost multiplier per tile.
Money GetBuildCost(Price category) const
Get the cost for building a road stop of this type.
uint8_t build_cost_multiplier
Build cost multiplier per tile.
std::array< BridgeableTileInfo, 6 > bridgeable_info
Per tile layout bridge information.
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
CargoGRFFileProps grf_prop
Link to NewGRF.
Money GetClearCost(Price category) const
Get the cost for clearing a road stop of this type.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
Specialization of ResolverObject with type-safe access to RandomTriggers.
Tile information, used while rendering the tile.
Definition tile_cmd.h:32
Scope resolver for a town.
Definition newgrf_town.h:22
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92