OpenTTD Source 20260206-master-g4d4e37dbf1
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)
 Wrapper for animation control, see GetRoadStopCallback.
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 591 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 381 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 624 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 641 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 )

Draw representation of a road stop tile for GUI purposes.

Parameters
xposition x of image.
yposition y of image.
roadtypethe RoadType of the underlying road.
specthe RoadStop's spec.
typeThe type of station.
viewThe road stop's view.
Returns
true of the tile was drawn (allows for fallback to default graphics)

Definition at line 290 of file newgrf_roadstop.cpp.

References _local_company, DrawCommonTileSeqInGUI(), DrawModeRegister, DrawSprite(), GB(), GetCompanyPalette(), GetCustomRoadSprite(), SpriteLayoutProcessor::GetLayout(), GetRoadTypeInfo(), GroundSpritePaletteTransform(), INVALID_ROADTYPE, INVALID_TILE, Overlay, TileLayoutSpriteGroup::ProcessRegisters(), Road, RoadWaypoint, ROTSG_GROUND, ROTSG_OVERLAY, ROTSG_ROADSTOP, SPRITE_WIDTH, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and WaypGround.

Referenced by RoadStopPickerCallbacks< roadstoptype >::DrawType(), RoadWaypointPickerCallbacks::DrawType(), and BuildRoadStationWindow::DrawWidget().

◆ GetAnimRoadStopCallback()

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.

Definition at line 362 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 536 of file newgrf_roadstop.cpp.

References GetIfStopIsForType(), and NewGRFClass< Tspec, Tindex, Tmax >::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 517 of file newgrf_roadstop.cpp.

References NewGRFClass< RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX >::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 551 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 350 of file newgrf_roadstop.cpp.

◆ GetRoadStopSpec()

const RoadStopSpec * GetRoadStopSpec ( TileIndex t)

Definition at line 576 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 682 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 389 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().