OpenTTD Source  14.0-beta3
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 <http://www.gnu.org/licenses/>.
6  */
7 
12 #ifndef NEWGRF_ROADSTATION_H
13 #define NEWGRF_ROADSTATION_H
14 
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"
21 
23 static const int NUM_ROADSTOPS_PER_GRF = UINT16_MAX - 1;
24 
25 enum RoadStopClassID : byte {
30 };
32 
33 /* Some Triggers etc. */
40 };
41 
50 
51  ROADSTOPTYPE_END,
52 };
53 
58 enum RoadStopDrawMode : byte {
59  ROADSTOP_DRAW_MODE_NONE = 0,
62 };
64 
72 };
73 
77  struct BaseStation *st;
78  const struct RoadStopSpec *roadstopspec;
81  uint8_t view;
83 
86  {
87  }
88 
89  uint32_t GetRandomBits() const override;
90  uint32_t GetTriggers() const override;
91 
92  uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override;
93 };
94 
99 
100  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);
102 
103  ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
104  {
105  switch (scope) {
106  case VSG_SCOPE_SELF: return &this->roadstop_scope;
107  case VSG_SCOPE_PARENT: {
108  TownScopeResolver *tsr = this->GetTown();
109  if (tsr != nullptr) return tsr;
110  [[fallthrough]];
111  }
112  default: return ResolverObject::GetScope(scope, relative);
113  }
114  }
115 
116  TownScopeResolver *GetTown();
117 
118  const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
119 };
120 
122 struct RoadStopSpec {
131  int spec_id;
133 
136  uint8_t callback_mask = 0;
137  uint8_t flags = 0;
138 
139  CargoTypes cargo_triggers = 0;
140 
141  AnimationInfo animation;
142 
143  byte bridge_height[6];
145 
146  uint8_t build_cost_multiplier = 16;
147  uint8_t clear_cost_multiplier = 16;
148 
153  Money GetBuildCost(Price category) const { return GetPrice(category, this->build_cost_multiplier, this->grf_prop.grffile, -4); }
154 
159  Money GetClearCost(Price category) const { return GetPrice(category, this->clear_cost_multiplier, this->grf_prop.grffile, -4); }
160 
161  static const RoadStopSpec *Get(uint16_t index);
162 };
163 
165 
166 void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
167 
168 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);
169 
170 void AnimateRoadStopTile(TileIndex tile);
171 uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile);
172 void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
173 void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
174 
175 bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype);
176 bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
177 bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype);
178 
179 uint GetCountOfCompatibleStopsByType(RoadStopClass *roadstopclass, RoadStopType rs);
180 
181 const RoadStopSpec *GetRoadStopSpec(TileIndex t);
182 int AllocateSpecToRoadStop(const RoadStopSpec *statspec, BaseStation *st, bool exec);
183 void DeallocateSpecFromRoadStop(BaseStation *st, byte specindex);
185 
186 #endif /* NEWGRF_ROADSTATION_H */
RoadStopScopeResolver::st
struct BaseStation * st
Instance of the station.
Definition: newgrf_roadstop.h:77
RoadStopSpec::clear_cost_multiplier
uint8_t clear_cost_multiplier
Clear cost multiplier per tile.
Definition: newgrf_roadstop.h:147
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:97
ROADSTOPTYPE_ALL
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
Definition: newgrf_roadstop.h:49
RSF_CB141_RANDOM_BITS
@ RSF_CB141_RANDOM_BITS
Callback 141 needs random bits.
Definition: newgrf_roadstop.h:66
RoadStopAvailabilityType
RoadStopAvailabilityType
Various different options for availability, restricting the roadstop to be only for busses or for tru...
Definition: newgrf_roadstop.h:46
GetPrice
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:970
RoadStopType
RoadStopType
Types of RoadStops.
Definition: station_type.h:43
RoadStopSpec
Road stop specification.
Definition: newgrf_roadstop.h:122
newgrf_commons.h
Station
Station data structure.
Definition: station_base.h:442
RoadStopSpec::name
StringID name
Name of this stop.
Definition: newgrf_roadstop.h:132
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:89
RSRT_CARGO_TAKEN
@ RSRT_CARGO_TAKEN
Trigger roadstop when cargo is completely taken.
Definition: newgrf_roadstop.h:36
ROADSTOPTYPE_FREIGHT
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
Definition: newgrf_roadstop.h:48
RoadStopScopeResolver::tile
TileIndex tile
Tile of the station.
Definition: newgrf_roadstop.h:76
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
AnimationInfo
Information about animation.
Definition: newgrf_animation_type.h:18
RoadStopScopeResolver::roadtype
RoadType roadtype
Road type (used when no tile)
Definition: newgrf_roadstop.h:82
RoadStopSpecFlags
RoadStopSpecFlags
Definition: newgrf_roadstop.h:65
RSRT_VEH_DEPARTS
@ RSRT_VEH_DEPARTS
Trigger roadstop when road vehicle leaves.
Definition: newgrf_roadstop.h:38
RoadStopSpec::cls_id
RoadStopClassID cls_id
The class to which this spec belongs.
Definition: newgrf_roadstop.h:130
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetIfNewStopsByType
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
Checks if there's any new stations by a specific RoadStopType.
Definition: newgrf_roadstop.cpp:465
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:101
RSRT_VEH_ARRIVES
@ RSRT_VEH_ARRIVES
Trigger roadstop when road vehicle arrives.
Definition: newgrf_roadstop.h:37
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:288
ROADSTOP_DRAW_MODE_OVERLAY
@ ROADSTOP_DRAW_MODE_OVERLAY
Drive-through stops: Draw the road overlay, e.g. pavement.
Definition: newgrf_roadstop.h:61
TriggerRoadStopRandomisation
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type=INVALID_CARGO)
Trigger road stop randomisation.
Definition: newgrf_roadstop.cpp:392
RSRT_VEH_LOADS
@ RSRT_VEH_LOADS
Trigger roadstop when road vehicle loads.
Definition: newgrf_roadstop.h:39
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
GetIfClassHasNewStopsByType
bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
Definition: newgrf_roadstop.cpp:484
DrawRoadStopTile
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.
Definition: newgrf_roadstop.cpp:277
RSF_NO_CATENARY
@ RSF_NO_CATENARY
Do not show catenary.
Definition: newgrf_roadstop.h:67
StationType
StationType
Station types.
Definition: station_type.h:31
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
RSF_BUILD_MENU_TRAM_ONLY
@ RSF_BUILD_MENU_TRAM_ONLY
Only show in the tram build menu (not road).
Definition: newgrf_roadstop.h:71
ROADSTOP_CLASS_BEGIN
@ ROADSTOP_CLASS_BEGIN
The lowest valid value.
Definition: newgrf_roadstop.h:26
RoadStopRandomTrigger
RoadStopRandomTrigger
Definition: newgrf_roadstop.h:34
RoadStopSpec::spec_id
int spec_id
The ID of this spec inside the class.
Definition: newgrf_roadstop.h:131
RoadStopResolverObject
Road stop resolver.
Definition: newgrf_roadstop.h:96
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
RoadStopSpec::GetClearCost
Money GetClearCost(Price category) const
Get the cost for clearing a road stop of this type.
Definition: newgrf_roadstop.h:159
RoadStopSpec::build_cost_multiplier
uint8_t build_cost_multiplier
Build cost multiplier per tile.
Definition: newgrf_roadstop.h:146
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:20
RoadStopSpec::grf_prop
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Definition: newgrf_roadstop.h:129
RSF_DRIVE_THROUGH_ONLY
@ RSF_DRIVE_THROUGH_ONLY
Stop is drive-through only.
Definition: newgrf_roadstop.h:68
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:135
road.h
RSF_NO_AUTO_ROAD_CONNECTION
@ RSF_NO_AUTO_ROAD_CONNECTION
No auto road connection.
Definition: newgrf_roadstop.h:69
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
RoadStopResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_roadstop.h:98
RoadStopResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_roadstop.h:103
RoadStopScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Get a variable value.
Definition: newgrf_roadstop.cpp:66
RoadStopScopeResolver::cargo_type
CargoID cargo_type
Type of cargo of the station.
Definition: newgrf_roadstop.h:79
newgrf_spritegroup.h
newgrf_town.h
ROADSTOP_CLASS_WAYP
@ ROADSTOP_CLASS_WAYP
Waypoint class (unimplemented: this is reserved for future use with road waypoints).
Definition: newgrf_roadstop.h:28
NUM_ROADSTOPS_PER_GRF
static const int NUM_ROADSTOPS_PER_GRF
The maximum amount of roadstops a single GRF is allowed to add.
Definition: newgrf_roadstop.h:23
ROADSTOP_CLASS_DFLT
@ ROADSTOP_CLASS_DFLT
Default road stop class.
Definition: newgrf_roadstop.h:27
newgrf_class.h
ROADSTOP_DRAW_MODE_ROAD
@ ROADSTOP_DRAW_MODE_ROAD
Bay stops: Draw the road itself.
Definition: newgrf_roadstop.h:60
ROADSTOP_CLASS_MAX
@ ROADSTOP_CLASS_MAX
Maximum number of classes.
Definition: newgrf_roadstop.h:29
RoadStopScopeResolver::roadstopspec
const struct RoadStopSpec * roadstopspec
Station (type) specification.
Definition: newgrf_roadstop.h:78
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
RSRT_NEW_CARGO
@ RSRT_NEW_CARGO
Trigger roadstop on arrival of new cargo.
Definition: newgrf_roadstop.h:35
StationAnimationTrigger
StationAnimationTrigger
Animation triggers for station.
Definition: newgrf_animation_type.h:26
RoadStopSpec::GetBuildCost
Money GetBuildCost(Price category) const
Get the cost for building a road stop of this type.
Definition: newgrf_roadstop.h:153
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:325
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:64
RoadStopResolverObject::roadstop_scope
RoadStopScopeResolver roadstop_scope
The stop scope resolver.
Definition: newgrf_roadstop.h:97
RSF_BUILD_MENU_ROAD_ONLY
@ RSF_BUILD_MENU_ROAD_ONLY
Only show in the road build menu (not tram).
Definition: newgrf_roadstop.h:70
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
RoadStopResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition: newgrf_roadstop.cpp:202
OverflowSafeInt< int64_t >
RoadStopDrawMode
RoadStopDrawMode
Different draw modes to disallow rendering of some parts of the stop or road.
Definition: newgrf_roadstop.h:58
RoadStopSpec::bridge_disallowed_pillars
byte bridge_disallowed_pillars[6]
Disallowed pillar flags for a bridge above.
Definition: newgrf_roadstop.h:144
RoadStopScopeResolver
Scope resolver for road stops.
Definition: newgrf_roadstop.h:75
RoadStopScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition: newgrf_roadstop.cpp:50
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
RoadStopUpdateCachedTriggers
void RoadStopUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition: newgrf_roadstop.cpp:607
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
RoadStopSpec::bridge_height
byte bridge_height[6]
Minimum height for a bridge above, 0 for none.
Definition: newgrf_roadstop.h:143
RoadStopScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition: newgrf_roadstop.cpp:61
RoadStopClassID
RoadStopClassID
Definition: newgrf_roadstop.h:25
RoadStopScopeResolver::view
uint8_t view
Station axis.
Definition: newgrf_roadstop.h:81
newgrf_animation_type.h
GetIfStopIsForType
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopSpec is compatible with the given RoadStopType.
Definition: newgrf_roadstop.cpp:499
GRFFilePropsBase< NUM_CARGO+3 >
SpriteGroup
Definition: newgrf_spritegroup.h:57
RoadStopSpec::cargo_triggers
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Definition: newgrf_roadstop.h:139
RoadStopScopeResolver::type
StationType type
Station type.
Definition: newgrf_roadstop.h:80
ROADSTOPTYPE_PASSENGER
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
Definition: newgrf_roadstop.h:47