29#include "table/strings.h"
58 if (this->
st ==
nullptr)
return 0;
60 uint32_t bits = this->
st->random_bits;
69 if (this->
st ==
nullptr)
return 0;
71 StationRandomTriggers triggers =
st->waiting_random_triggers;
73 auto it = this->
st->tile_waiting_random_triggers.find(this->
tile);
74 if (it != std::end(this->
st->tile_waiting_random_triggers)) triggers.
Set(it->second);
76 return triggers.
base();
81 auto get_road_type_variable = [&](
RoadTramType rtt) -> uint32_t {
86 rt = GetRoadType(this->
tile, rtt);
97 case 0x40:
return this->
view;
109 case 0x43:
return get_road_type_variable(
RTT_ROAD);
112 case 0x44:
return get_road_type_variable(
RTT_TRAM);
172 uint32_t res =
GetStationGfx(nearby_tile) << 12 | !same_orientation << 11 | !!same_station << 10;
208 if (sm.grfid == grfid) {
217 case 0xF0:
return this->
st ==
nullptr ? 0 : this->
st->facilities.base();
222 if (this->
st !=
nullptr)
return this->
st->GetNewGRFVariable(this->
ro, variable, parameter, available);
229 CallbackID callback, uint32_t param1, uint32_t param2)
230 :
SpecializedResolverObject<StationRandomTriggers>(roadstopspec->grf_prop.grffile, callback, param1, param2), roadstop_scope(*this, st, roadstopspec, tile, roadtype, type, view)
240 for (
const auto &[cargo, spritegroup] :
roadstopspec->grf_prop.spritegroups) {
241 if (cargo < NUM_CARGO && station->goods[cargo].TotalCount() > 0) {
243 this->root_spritegroup = spritegroup;
249 this->root_spritegroup = this->roadstop_scope.roadstopspec->grf_prop.GetSpriteGroup(ctype);
250 if (this->root_spritegroup ==
nullptr) {
252 this->root_spritegroup = this->roadstop_scope.roadstopspec->grf_prop.GetSpriteGroup(ctype);
256 this->roadstop_scope.cargo_type = ctype;
268 if (t ==
nullptr)
return nullptr;
277 return object.ResolveCallback(regs100);
293 assert(spec !=
nullptr);
298 if (group ==
nullptr)
return;
307 RoadStopDrawModes draw_mode;
309 draw_mode =
static_cast<RoadStopDrawModes
>(
object.GetRegister(0x100));
311 draw_mode = spec->draw_mode;
315 DrawSprite(SPR_ROAD_PAVED_STRAIGHT_X, PAL_NONE, x, y);
325 uint sprite_offset = 5 - view;
329 if (rti->UsesOverlay()) {
331 DrawSprite(ground + sprite_offset, PAL_NONE, x, y);
334 if (overlay)
DrawSprite(overlay + sprite_offset, PAL_NONE, x, y);
335 }
else if (RoadTypeIsTram(roadtype)) {
336 DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
354 if (group ==
nullptr)
return std::nullopt;
355 for (uint i = 0; i < regs100.size(); ++i) {
356 regs100[i] =
object.GetRegister(0x100 + i);
368 static uint8_t Get(
BaseStation *st,
TileIndex tile) {
return st->GetRoadStopAnimationFrame(tile); }
369 static bool Set(
BaseStation *st,
TileIndex tile, uint8_t frame) {
return st->SetRoadStopAnimationFrame(tile, frame); }
384 if (ss ==
nullptr)
return;
391 assert(st !=
nullptr);
397 uint16_t random_bits = Random();
398 auto process_tile = [&](
TileIndex cur_tile) {
400 if (ss !=
nullptr && ss->animation.triggers.Test(trigger)) {
401 uint8_t var18_extra = 0;
411 process_tile(tile_data.tile);
414 process_tile(trigger_tile);
428 enum TriggerArea : uint8_t {
435 static constexpr TriggerArea tas[] = {
436 TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM
439 assert(st !=
nullptr);
449 StationRandomTriggers used_random_triggers;
451 uint32_t whole_reseed = 0;
454 CargoTypes empty_mask{};
459 auto process_tile = [&](
TileIndex cur_tile) {
461 if (ss ==
nullptr)
return;
463 st->tile_waiting_random_triggers[tile].Set(trigger);
475 object.ResolveRerandomisation();
477 st->tile_waiting_random_triggers[tile].Reset(
object.GetUsedRandomTriggers());
478 used_random_triggers.
Set(
object.GetUsedRandomTriggers());
480 uint32_t reseed =
object.GetReseedSum();
482 whole_reseed |= reseed;
486 uint8_t random_bits = st->GetRoadStopRandomBits(cur_tile);
487 random_bits &= ~reseed;
488 random_bits |= Random() & reseed;
489 st->SetRoadStopRandomBits(cur_tile, random_bits);
495 if (ta == TA_WHOLE) {
497 process_tile(tile_data.tile);
505 if ((whole_reseed & 0xFFFF) != 0) {
538 for (
const auto spec : roadstopclass->
Specs()) {
554 if (roadstopspec ==
nullptr)
return true;
595 if (spec ==
nullptr)
return 0;
598 if (st ==
nullptr)
return 1;
626 if (specindex == 0)
return;
644 if (specindex == 0)
return;
690 if (sm.spec ==
nullptr)
continue;
std::vector< SpecMapping< T > > & GetStationSpecList(BaseStation *bst)
Get spec mapping list for each supported custom spec type.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
Struct containing information relating to NewGRF classes for stations and airports.
static std::span< NewGRFClass< RoadStopSpec, RoadStopClassID, Tmax > const > Classes()
StringID name
Name of this class.
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
bool IsUIAvailable(uint index) const
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
static NewGRFClass * Get(RoadStopClassID class_index)
static void InsertDefaults()
static RoadStopClassID Allocate(uint32_t global_id)
DrawTileSpriteSpan GetLayout() const
Returns the result spritelayout after preprocessing.
static Date date
Current date in days (day counter).
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Functions related to debugging.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32_t PaletteID
The number of the palette.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ TownEdge
Edge of the town; roads without pavement.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
Function implementations related to NewGRF animation.
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Functions related to NewGRF badges.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_STATION_ANIMATION_TRIGGER
Called for periodically starting or stopping the animation.
@ CBID_STATION_ANIMATION_NEXT_FRAME
Called to determine station tile next animation frame.
@ CBID_STATION_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
RoadStopCallbackMask
Callback masks for road stops.
@ AnimationNextFrame
Use a custom next frame callback.
@ AnimationSpeed
Customize the animation speed of the road stop.
Cargo support for NewGRFs.
Implementation of the NewGRF class' functions.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
@ TCX_NORMAL
Nothing special.
static const uint NUM_ROADSTOPSPECS_PER_STATION
Maximum number of parts per station.
void TriggerRoadStopRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type)
Trigger road stop randomisation.
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.
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.
uint16_t GetAnimRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, int)
Wrapper for animation control, see GetRoadStopCallback.
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopSpec is compatible with the given RoadStopType.
NewGRF definitions and structures for road stops.
@ 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.
@ ROADSTOP_CLASS_DFLT
Default road stop class.
@ 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.
@ 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).
@ DrawModeRegister
Read draw mode from register 0x100.
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
NewGRF handling of road types.
Functions related to NewGRF provided sounds.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
@ ROTSG_ROADSTOP
Required: Bay stop surface.
@ ROTSG_GROUND
Required: Main group of ground images.
RoadTramType
The different types of road type.
@ RTT_ROAD
Road road type.
@ RTT_TRAM
Tram road type.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
Base class for roadstops.
A number of safeguards to prevent using unsafe methods.
@ Town
Source/destination is a town.
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence in the GUI.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Base classes/functions for stations.
CargoTypes GetEmptyMask(const Station *st)
Get a mask of the cargo types that are empty at the station.
StationType GetStationType(Tile t)
Get the station type of this tile.
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
uint GetCustomRoadStopSpecIndex(Tile t)
Get the custom road stop spec for this tile.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
bool IsCustomRoadStopSpecIndex(Tile t)
Is there a custom road stop spec on this tile?
bool IsAnyRoadStopTile(Tile t)
Is tile t a road stop station?
RoadStopType
Types of RoadStops.
@ Bus
A standard stop for buses.
@ Truck
A standard stop for trucks.
StationType
Station types.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RoadWaypoint
Waypoint for trucks and busses.
StationRandomTrigger
Randomisation triggers for stations and roadstops.
@ CargoTaken
Trigger station when cargo is completely taken.
StationAnimationTrigger
Animation triggers for stations and roadstops.
@ NewCargo
Trigger station on new cargo arrival.
@ AcceptanceTick
Trigger station every 250 ticks.
@ CargoTaken
Trigger station when cargo is completely taken.
Definition of base types and functions in a cross-platform compatible way.
Helper class for a unified approach to NewGRF animation.
static void AnimateTile(const RoadStopSpec *spec, BaseStation *obj, TileIndex tile, bool random_animation, int extra_data=0)
static void ChangeAnimationFrame(CallbackID cb, const RoadStopSpec *spec, BaseStation *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, int extra_data=0)
Base class for all station-ish types.
std::vector< SpecMapping< RoadStopSpec > > roadstop_speclist
List of road stop specs of this station.
StationAnimationTriggers cached_roadstop_anim_triggers
NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing sh...
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
CargoTypes cached_roadstop_cargo_triggers
NOSAVE: Combined cargo trigger bitmask for road stops.
uint16_t random_bits
Random bits assigned to this station.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
StationRandomTriggers waiting_random_triggers
Waiting triggers (NewGRF), shared by all station parts/tiles, road stops, ... essentially useless and...
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
static constexpr CargoType SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
const struct GRFFile * grffile
grf file that introduced this entity
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID).
Helper class for animation control.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
RoadStopScopeResolver roadstop_scope
The stop scope resolver.
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.
TileIndex tile
Tile of the station.
uint32_t GetRandomBits() const override
Get a few random bits.
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
CargoGRFFileProps grf_prop
Link to NewGRF.
ResolverObject & ro
Surrounding resolver object.
Specialization of ResolverObject with type-safe access to RandomTriggers.
static bool IsExpected(const BaseStation *st)
static Station * From(BaseStation *st)
Tile information, used while rendering the tile.
TileIndex tile
Tile index.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Scope resolver for a town.
TileIndex xy
town center tile
Generic 'commands' that can be performed on all tiles.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the game-calendar-timer.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Functions related to (drawing on) viewports.
Types related to windows.
@ Station
station encountered (could be a target next time)