OpenTTD Source 20260311-master-g511d3794ce
newgrf_roadstop.cpp File Reference

Handling of NewGRF road stops. More...

#include "stdafx.h"
#include "debug.h"
#include "station_base.h"
#include "roadstop_base.h"
#include "newgrf_badge.h"
#include "newgrf_roadstop.h"
#include "newgrf_cargo.h"
#include "newgrf_roadtype.h"
#include "gfx_type.h"
#include "company_func.h"
#include "road.h"
#include "window_type.h"
#include "timer/timer_game_calendar.h"
#include "town.h"
#include "tile_cmd.h"
#include "viewport_func.h"
#include "newgrf_animation_base.h"
#include "newgrf_sound.h"
#include "table/strings.h"
#include "newgrf_class_func.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  RoadStopAnimationFrameAnimationHelper
struct  RoadStopAnimationBase
 Helper class for animation control. More...

Functions

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, std::span< int32_t > regs100)
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.
std::optional< SpriteLayoutProcessorGetRoadStopLayout (TileInfo *ti, const RoadStopSpec *spec, BaseStation *st, StationType type, int view, std::span< int32_t > regs100)
uint16_t GetAnimRoadStopCallback (CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, int)
 Perform the road stop callback in the context of the AnimationBase callback.
void AnimateRoadStopTile (TileIndex tile)
void TriggerRoadStopAnimation (BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type)
void TriggerRoadStopRandomisation (BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type)
 Trigger road stop randomisation.
bool GetIfNewStopsByType (RoadStopType rs, RoadType roadtype)
 Checks if there's any new stations by a specific RoadStopType.
bool GetIfClassHasNewStopsByType (const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
 Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopType.
bool GetIfStopIsForType (const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype)
 Checks if the given RoadStopSpec is compatible with the given RoadStopType.
const RoadStopSpecGetRoadStopSpec (TileIndex t)
std::optional< uint8_t > AllocateSpecToRoadStop (const RoadStopSpec *spec, BaseStation *st)
 Allocate a RoadStopSpec to a Station.
void AssignSpecToRoadStop (const RoadStopSpec *spec, BaseStation *st, uint8_t specindex)
 Assign a previously allocated RoadStopSpec specindex to a Station.
void DeallocateSpecFromRoadStop (BaseStation *st, uint8_t specindex)
 Deallocate a RoadStopSpec from a Station.
void RoadStopUpdateCachedTriggers (BaseStation *st)
 Update the cached animation trigger bitmask for a station.

Variables

static const uint NUM_ROADSTOPSPECS_PER_STATION = 63
 Maximum number of parts per station.

Detailed Description

Handling of NewGRF road stops.

Definition in file newgrf_roadstop.cpp.

Function Documentation

◆ AllocateSpecToRoadStop()

std::optional< uint8_t > AllocateSpecToRoadStop ( const RoadStopSpec * spec,
BaseStation * st )

Allocate a RoadStopSpec to a Station.

This is called once per build operation.

Parameters
specRoadStopSpec to allocate.
stStation to allocate it to.
Returns
Index within the Station's road stop spec list, or std::nullopt if the allocation failed.

Definition at line 599 of file newgrf_roadstop.cpp.

References NUM_ROADSTOPSPECS_PER_STATION, and BaseStation::roadstop_speclist.

Referenced by CmdBuildRoadStop(), and CmdBuildRoadWaypoint().

◆ AnimateRoadStopTile()

void AnimateRoadStopTile ( TileIndex tile)

Definition at line 389 of file newgrf_roadstop.cpp.

◆ AssignSpecToRoadStop()

void AssignSpecToRoadStop ( const RoadStopSpec * spec,
BaseStation * st,
uint8_t specindex )

Assign a previously allocated RoadStopSpec specindex to a Station.

Parameters
specRoadStopSpec to assign..
stStation to allocate it to.
specindexSpec index of allocation.

Definition at line 632 of file newgrf_roadstop.cpp.

References RoadStopSpec::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, BaseStation::roadstop_speclist, and RoadStopUpdateCachedTriggers().

Referenced by CmdBuildRoadStop(), and CmdBuildRoadWaypoint().

◆ DeallocateSpecFromRoadStop()

void DeallocateSpecFromRoadStop ( BaseStation * st,
uint8_t specindex )

Deallocate a RoadStopSpec from a Station.

Called when removing a single roadstop tile.

Parameters
stStation to work with.
specindexIndex of the custom roadstop within the Station's roadstop spec list.

Definition at line 649 of file newgrf_roadstop.cpp.

References BaseStation::cached_roadstop_anim_triggers, BaseStation::cached_roadstop_cargo_triggers, BaseStation::custom_roadstop_tile_data, GetCustomRoadStopSpecIndex(), BaseStation::roadstop_speclist, and RoadStopUpdateCachedTriggers().

Referenced by RemoveRoadStop(), and RemoveRoadWaypointStop().

◆ DrawRoadStopTile()

void DrawRoadStopTile ( int x,
int y,
RoadType roadtype,
const RoadStopSpec * spec,
StationType type,
int view )

◆ GetAnimRoadStopCallback()

uint16_t GetAnimRoadStopCallback ( CallbackID callback,
uint32_t param1,
uint32_t param2,
const RoadStopSpec * roadstopspec,
BaseStation * st,
TileIndex tile,
int  )

Perform the road stop callback in the context of the AnimationBase callback.

Parameters
callbackThe identifier of the callback.
param1The first parameter of the NewGRF callback.
param2The second parameter of the NewGRF callback.
roadstopspecThe specification to run the callback on.
stThe station the road stop is part of.
tileThe tile the road stop is at.
Returns
The NewGRF result of the callback.

Definition at line 370 of file newgrf_roadstop.cpp.

References GetStationGfx(), GetStationType(), and INVALID_ROADTYPE.

◆ GetIfClassHasNewStopsByType()

bool GetIfClassHasNewStopsByType ( const RoadStopClass * roadstopclass,
RoadStopType rs,
RoadType roadtype )

Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopType.

Parameters
roadstopclassthe RoadStopClass to check.
rsthe RoadStopType to check.
roadtypethe RoadType to check.
Returns
true if the RoadStopSpec has any specs compatible with the given RoadStopType and RoadType.

Definition at line 544 of file newgrf_roadstop.cpp.

References GetIfStopIsForType(), and NewGRFClass< Tspec, Tindex >::Specs().

Referenced by GetIfNewStopsByType(), and BuildRoadToolbarWindow::OnPlaceMouseUp().

◆ GetIfNewStopsByType()

bool GetIfNewStopsByType ( RoadStopType rs,
RoadType roadtype )

Checks if there's any new stations by a specific RoadStopType.

Parameters
rsthe RoadStopType to check.
roadtypethe RoadType to check.
Returns
true if there was any new RoadStopSpec's found for the given RoadStopType and RoadType, else false.

Definition at line 525 of file newgrf_roadstop.cpp.

References NewGRFClass< RoadStopSpec, RoadStopClassID >::Classes(), GetIfClassHasNewStopsByType(), IsWaypointClass(), and ROADSTOP_CLASS_DFLT.

◆ GetIfStopIsForType()

bool GetIfStopIsForType ( const RoadStopSpec * roadstopspec,
RoadStopType rs,
RoadType roadtype )

Checks if the given RoadStopSpec is compatible with the given RoadStopType.

Parameters
roadstopspecthe RoadStopSpec to check.
rsthe RoadStopType to check.
roadtypethe RoadType to check.
Returns
true if the RoadStopSpec is compatible with the given RoadStopType and RoadType.

Definition at line 559 of file newgrf_roadstop.cpp.

References Bus, RoadOnly, ROADSTOPTYPE_ALL, ROADSTOPTYPE_FREIGHT, ROADSTOPTYPE_PASSENGER, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TramOnly, and Truck.

Referenced by GetIfClassHasNewStopsByType().

◆ GetRoadStopCallback()

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,
std::span< int32_t > regs100 )

Definition at line 274 of file newgrf_roadstop.cpp.

◆ GetRoadStopLayout()

std::optional< SpriteLayoutProcessor > GetRoadStopLayout ( TileInfo * ti,
const RoadStopSpec * spec,
BaseStation * st,
StationType type,
int view,
std::span< int32_t > regs100 )

Definition at line 349 of file newgrf_roadstop.cpp.

◆ GetRoadStopSpec()

const RoadStopSpec * GetRoadStopSpec ( TileIndex t)

Definition at line 584 of file newgrf_roadstop.cpp.

◆ RoadStopUpdateCachedTriggers()

void RoadStopUpdateCachedTriggers ( BaseStation * st)

Update the cached animation trigger bitmask for a station.

Parameters
stStation to update.

Definition at line 690 of file newgrf_roadstop.cpp.

References BaseStation::cached_roadstop_anim_triggers, BaseStation::cached_roadstop_cargo_triggers, GetStationSpecList(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by AssignSpecToRoadStop(), and DeallocateSpecFromRoadStop().

◆ TriggerRoadStopAnimation()

void TriggerRoadStopAnimation ( BaseStation * st,
TileIndex trigger_tile,
StationAnimationTrigger trigger,
CargoType cargo_type )

Definition at line 397 of file newgrf_roadstop.cpp.

◆ TriggerRoadStopRandomisation()

Variable Documentation

◆ NUM_ROADSTOPSPECS_PER_STATION

const uint NUM_ROADSTOPSPECS_PER_STATION = 63
static

Maximum number of parts per station.

Definition at line 54 of file newgrf_roadstop.cpp.

Referenced by AllocateSpecToRoadStop().