OpenTTD Source 20250428-master-ga5578166bb
RoadStop Struct Reference

A Stop for a Road Vehicle. More...

#include <roadstop_base.h>

Inheritance diagram for RoadStop:
Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >

Data Structures

struct  Entries
 Container for both east and west entry points. More...
 
struct  Entry
 Container for each entry point of a drive through road stop. More...
 

Public Types

enum class  RoadStopStatusFlag : uint8_t { Bay0Free = 0 , Bay1Free = 1 , BaseEntry = 6 , EntryBusy = 7 }
 
using RoadStopStatusFlags = EnumBitSet< RoadStopStatusFlag, uint8_t >
 
- Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > Pool
 Type of the pool this item is going to be part of.
 

Public Member Functions

 RoadStop (TileIndex tile=INVALID_TILE)
 Initializes a RoadStop.
 
 ~RoadStop ()
 De-Initializes RoadStops.
 
bool HasFreeBay () const
 Checks whether there is a free bay in this road stop.
 
bool IsFreeBay (uint nr) const
 Checks whether the given bay is free in this road stop.
 
bool IsEntranceBusy () const
 Checks whether the entrance of the road stop is occupied by a vehicle.
 
void SetEntranceBusy (bool busy)
 Makes an entrance occupied or free.
 
const EntryGetEntry (DiagDirection dir) const
 Get the drive through road stop entry struct for the given direction.
 
EntryGetEntry (DiagDirection dir)
 Get the drive through road stop entry struct for the given direction.
 
void MakeDriveThrough ()
 Join this road stop to another 'base' road stop if possible; fill all necessary data to become an actual drive through road stop.
 
void ClearDriveThrough ()
 Prepare for removal of this stop; update other neighbouring stops if needed.
 
void Leave (RoadVehicle *rv)
 Leave the road stop.
 
bool Enter (RoadVehicle *rv)
 Enter the road stop.
 
RoadStopGetNextRoadStop (const struct RoadVehicle *v) const
 Get the next road stop accessible by this vehicle.
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >
void * operator new (size_t size)
 Allocates space for new Titem.
 
void * operator new (size_t size, Tindex index)
 Allocates space for new Titem with given index.
 
void * operator new (size_t, void *ptr)
 Allocates space for new Titem at given memory address.
 
void operator delete (void *p, size_t size)
 Marks Titem as free.
 

Static Public Member Functions

static RoadStopGetByTile (TileIndex tile, RoadStopType type)
 Find a roadstop at given tile.
 
static bool IsDriveThroughRoadStopContinuation (TileIndex rs, TileIndex next)
 Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same direction for the same vehicle.
 
- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no.
 
static bool IsValidID (auto index)
 Tests whether given index can be used to get valid (non-nullptr) Titem.
 
static Titem * Get (auto index)
 Returns Titem with given index.
 
static Titem * GetIfValid (auto index)
 Returns Titem with given index.
 
static size_t GetPoolSize ()
 Returns first unused index.
 
static size_t GetNumItems ()
 Returns number of valid items in the pool.
 
static void PostDestructor (size_t index)
 Dummy function called after destructor of each member.
 
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem.
 

Data Fields

RoadStopStatusFlags status {RoadStopStatusFlag::Bay0Free, RoadStopStatusFlag::Bay1Free}
 Current status of the Stop. Access using *Bay and *Busy functions.
 
TileIndex xy = INVALID_TILE
 Position on the map.
 
RoadStopnext = nullptr
 Next stop of the given type at this station.
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >
Tindex index
 Index of this pool item.
 

Private Member Functions

uint AllocateBay ()
 Allocates a bay.
 
void AllocateDriveThroughBay (uint nr)
 Allocates a bay in a drive-through road stop.
 
void FreeBay (uint nr)
 Frees the given bay.
 

Private Attributes

Entriesentries = nullptr
 Information about available and allocated bays.
 

Detailed Description

A Stop for a Road Vehicle.

Definition at line 22 of file roadstop_base.h.

Member Typedef Documentation

◆ RoadStopStatusFlags

Definition at line 29 of file roadstop_base.h.

Member Enumeration Documentation

◆ RoadStopStatusFlag

enum class RoadStop::RoadStopStatusFlag : uint8_t
strong
Enumerator
Bay0Free 

Non-zero when bay 0 is free.

Bay1Free 

Non-zero when bay 1 is free.

BaseEntry 

Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.

EntryBusy 

Non-zero when roadstop entry is busy.

Definition at line 23 of file roadstop_base.h.

Constructor & Destructor Documentation

◆ RoadStop()

RoadStop::RoadStop ( TileIndex  tile = INVALID_TILE)
inline

Initializes a RoadStop.

Definition at line 75 of file roadstop_base.h.

◆ ~RoadStop()

RoadStop::~RoadStop ( )

De-Initializes RoadStops.

Definition at line 27 of file roadstop.cpp.

Member Function Documentation

◆ AllocateBay()

uint RoadStop::AllocateBay ( )
inlineprivate

Allocates a bay.

Returns
the allocated bay number
Precondition
this->HasFreeBay()

Definition at line 160 of file roadstop_base.h.

References AllocateDriveThroughBay(), HasFreeBay(), and IsFreeBay().

Referenced by Enter().

◆ AllocateDriveThroughBay()

void RoadStop::AllocateDriveThroughBay ( uint  nr)
inlineprivate

Allocates a bay in a drive-through road stop.

Parameters
nrthe number of the bay to allocate

Definition at line 176 of file roadstop_base.h.

References Bay0Free, Bay1Free, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), and status.

Referenced by AllocateBay().

◆ ClearDriveThrough()

◆ Enter()

bool RoadStop::Enter ( RoadVehicle rv)

Enter the road stop.

Parameters
rvthe vehicle that enters the stop
Returns
whether the road stop could actually be entered

Definition at line 222 of file roadstop.cpp.

References AllocateBay(), Vehicle::direction, DirToDiagDir(), RoadStop::Entry::Enter(), GetEntry(), Vehicle::HasArticulatedPart(), HasFreeBay(), IsBayRoadStopTile(), IsEntranceBusy(), RVS_IN_DT_ROAD_STOP, RVS_IN_ROAD_STOP, RVS_USING_SECOND_BAY, SB(), SetBit(), SetEntranceBusy(), RoadVehicle::state, and xy.

◆ FreeBay()

void RoadStop::FreeBay ( uint  nr)
inlineprivate

Frees the given bay.

Parameters
nrthe number of the bay to free

Definition at line 189 of file roadstop_base.h.

References Bay0Free, Bay1Free, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and status.

Referenced by Leave().

◆ GetByTile()

RoadStop * RoadStop::GetByTile ( TileIndex  tile,
RoadStopType  type 
)
static

Find a roadstop at given tile.

Parameters
tiletile with roadstop
typeroadstop type
Returns
pointer to RoadStop
Precondition
there has to be roadstop of given type there!

Definition at line 255 of file roadstop.cpp.

References BaseStation::GetByTile().

Referenced by ClearDriveThrough(), RoadVehicle::Crash(), DeleteLastRoadVeh(), MakeDriveThrough(), CYapfCostRoadT< Types >::OneTileCost(), Vehicle::PreDestructor(), RemoveRoadStop(), and RoadFindPathToDest().

◆ GetEntry() [1/2]

Entry & RoadStop::GetEntry ( DiagDirection  dir)
inline

Get the drive through road stop entry struct for the given direction.

Parameters
dirThe direction to get the entry for.
Returns
the entry

Definition at line 135 of file roadstop_base.h.

References DIAGDIR_SW, RoadStop::Entries::east, entries, and RoadStop::Entries::west.

◆ GetEntry() [2/2]

const Entry & RoadStop::GetEntry ( DiagDirection  dir) const
inline

Get the drive through road stop entry struct for the given direction.

Parameters
dirThe direction to get the entry for.
Returns
the entry

Definition at line 125 of file roadstop_base.h.

References DIAGDIR_SW, RoadStop::Entries::east, entries, and RoadStop::Entries::west.

Referenced by Enter(), Leave(), and CYapfCostRoadT< Types >::OneTileCost().

◆ GetNextRoadStop()

RoadStop * RoadStop::GetNextRoadStop ( const struct RoadVehicle v) const

Get the next road stop accessible by this vehicle.

Parameters
vthe vehicle to get the next road stop for.
Returns
the next road stop accessible.

Definition at line 42 of file roadstop.cpp.

References RoadVehicle::compatible_roadtypes, Vehicle::HasArticulatedPart(), HasTileAnyRoadType(), IsBayRoadStopTile(), and next.

◆ HasFreeBay()

bool RoadStop::HasFreeBay ( ) const
inline

Checks whether there is a free bay in this road stop.

Returns
is at least one bay free?

Definition at line 83 of file roadstop_base.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Bay0Free, Bay1Free, and status.

Referenced by AllocateBay(), and Enter().

◆ IsDriveThroughRoadStopContinuation()

bool RoadStop::IsDriveThroughRoadStopContinuation ( TileIndex  rs,
TileIndex  next 
)
static

Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same direction for the same vehicle.

Parameters
rsthe road stop tile to check against
nextthe 'next' tile to check
Returns
true if the 'next' tile is part of the road stop at 'next'.

Definition at line 294 of file roadstop.cpp.

References GetDriveThroughStopAxis(), GetStationIndex(), GetStationType(), IsDriveThroughStopTile(), IsTileType(), MP_STATION, and next.

Referenced by RoadStop::Entry::CheckIntegrity(), ClearDriveThrough(), MakeDriveThrough(), CYapfCostRoadT< Types >::OneTileCost(), and RoadStop::Entry::Rebuild().

◆ IsEntranceBusy()

bool RoadStop::IsEntranceBusy ( ) const
inline

Checks whether the entrance of the road stop is occupied by a vehicle.

Returns
is entrance busy?

Definition at line 106 of file roadstop_base.h.

References EntryBusy, status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by Enter().

◆ IsFreeBay()

bool RoadStop::IsFreeBay ( uint  nr) const
inline

Checks whether the given bay is free in this road stop.

Parameters
nrbay to check
Returns
is given bay free?

Definition at line 93 of file roadstop_base.h.

References Bay0Free, Bay1Free, status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by AllocateBay(), and CYapfCostRoadT< Types >::OneTileCost().

◆ Leave()

void RoadStop::Leave ( RoadVehicle rv)

◆ MakeDriveThrough()

void RoadStop::MakeDriveThrough ( )

Join this road stop to another 'base' road stop if possible; fill all necessary data to become an actual drive through road stop.

Also update the length etc.

Definition at line 62 of file roadstop.cpp.

References BaseEntry, RoadStop::Entries::east, entries, GetByTile(), GetDriveThroughStopAxis(), GetRoadStopType(), IsDriveThroughRoadStopContinuation(), RoadStop::Entry::length, RoadStop::Entry::occupied, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), status, TILE_SIZE, TileOffsByAxis(), RoadStop::Entries::west, and xy.

Referenced by CmdBuildRoadStop().

◆ SetEntranceBusy()

void RoadStop::SetEntranceBusy ( bool  busy)
inline

Makes an entrance occupied or free.

Parameters
busyIf true, marks busy; free otherwise.

Definition at line 115 of file roadstop_base.h.

References EntryBusy, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and status.

Referenced by Enter(), and Leave().

Field Documentation

◆ entries

Entries* RoadStop::entries = nullptr
private

Information about available and allocated bays.

Definition at line 153 of file roadstop_base.h.

Referenced by RoadStop::Entry::CheckIntegrity(), ClearDriveThrough(), GetEntry(), GetEntry(), MakeDriveThrough(), and RoadStop::Entry::Rebuild().

◆ next

RoadStop* RoadStop::next = nullptr

Next stop of the given type at this station.

Definition at line 72 of file roadstop_base.h.

Referenced by FindRoadStopSpot(), GetNextRoadStop(), GetVehicleCannotUseStationReason(), IsDriveThroughRoadStopContinuation(), and RemoveRoadStop().

◆ status

◆ xy


The documentation for this struct was generated from the following files: