Go to the documentation of this file.
1 /* $Id: roadstop_base.h 23704 2012-01-01 17:22:32Z alberth $ */
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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 <>.
8  */
12 #ifndef ROADSTOP_BASE_H
13 #define ROADSTOP_BASE_H
15 #include "station_type.h"
16 #include "core/pool_type.hpp"
17 #include "core/bitmath_func.hpp"
18 #include "vehicle_type.h"
24 struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
31  };
34  struct Entry {
35  private:
36  int length;
37  int occupied;
39  public:
40  friend struct RoadStop;
43  Entry() : length(0), occupied(0) {}
49  inline int GetLength() const
50  {
51  return this->length;
52  }
58  inline int GetOccupied() const
59  {
60  return this->occupied;
61  }
63  void Leave(const RoadVehicle *rv);
64  void Enter(const RoadVehicle *rv);
65  void CheckIntegrity(const RoadStop *rs) const;
66  void Rebuild(const RoadStop *rs, int side = -1);
67  };
70  byte status;
71  struct RoadStop *next;
74  inline RoadStop(TileIndex tile = INVALID_TILE) :
75  xy(tile),
76  status((1 << RSSFB_BAY_COUNT) - 1)
77  { }
79  ~RoadStop();
85  inline bool HasFreeBay() const
86  {
87  return GB(this->status, 0, RSSFB_BAY_COUNT) != 0;
88  }
95  inline bool IsFreeBay(uint nr) const
96  {
97  assert(nr < RSSFB_BAY_COUNT);
98  return HasBit(this->status, nr);
99  }
105  inline bool IsEntranceBusy() const
106  {
107  return HasBit(this->status, RSSFB_ENTRY_BUSY);
108  }
114  inline void SetEntranceBusy(bool busy)
115  {
116  SB(this->status, RSSFB_ENTRY_BUSY, 1, busy);
117  }
124  inline const Entry *GetEntry(DiagDirection dir) const
125  {
126  return HasBit((int)dir, 1) ? this->west : this->east;
127  }
135  {
136  return HasBit((int)dir, 1) ? this->west : this->east;
137  }
139  void MakeDriveThrough();
140  void ClearDriveThrough();
142  void Leave(RoadVehicle *rv);
143  bool Enter(RoadVehicle *rv);
145  RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
147  static RoadStop *GetByTile(TileIndex tile, RoadStopType type);
151 private:
160  inline uint AllocateBay()
161  {
162  assert(this->HasFreeBay());
164  /* Find the first free bay. If the bit is set, the bay is free. */
165  uint bay_nr = 0;
166  while (!HasBit(this->status, bay_nr)) bay_nr++;
168  ClrBit(this->status, bay_nr);
169  return bay_nr;
170  }
176  inline void AllocateDriveThroughBay(uint nr)
177  {
178  assert(nr < RSSFB_BAY_COUNT);
179  ClrBit(this->status, nr);
180  }
186  inline void FreeBay(uint nr)
187  {
188  assert(nr < RSSFB_BAY_COUNT);
189  SetBit(this->status, nr);
190  }
191 };
193 #define FOR_ALL_ROADSTOPS_FROM(var, start) FOR_ALL_ITEMS_FROM(RoadStop, roadstop_index, var, start)
196 #endif /* ROADSTOP_BASE_H */
Create an entry.
Definition: roadstop_base.h:43
byte status
Current status of the Stop,.
Definition: roadstop_base.h:70
bool IsEntranceBusy() const
Checks whether the entrance of the road stop is occupied by a vehicle.
uint AllocateBay()
Allocates a bay.
int GetLength() const
Get the length of this drive through stop.
Definition: roadstop_base.h:49
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Non-zero when roadstop entry is busy.
Definition: roadstop_base.h:30
int GetOccupied() const
Get the amount of occupied space in this drive through stop.
Definition: roadstop_base.h:58
TileIndex xy
Position on the map.
Definition: roadstop_base.h:69
void MakeDriveThrough()
Join this road stop to another &#39;base&#39; road stop if possible; fill all necessary data to become an act...
Definition: roadstop.cpp:64
void FreeBay(uint nr)
Frees the given bay.
void Enter(const RoadVehicle *rv)
Enter the road stop.
Definition: roadstop.cpp:292
Functions related to bit mathematics.
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
RoadStop * GetNextRoadStop(const struct RoadVehicle *v) const
Get the next road stop accessible by this vehicle.
Definition: roadstop.cpp:44
Types of RoadStops.
Definition: station_type.h:47
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Non-zero when bay 1 is free.
Definition: roadstop_base.h:27
Buses, trucks and trams belong to this class.
Definition: roadveh.h:88
Max. number of bays.
Definition: roadstop_base.h:28
Types related to stations.
void ClearDriveThrough()
Prepare for removal of this stop; update other neighbouring stops if needed.
Definition: roadstop.cpp:132
void CheckIntegrity(const RoadStop *rs) const
Check the integrity of the data in this struct.
Definition: roadstop.cpp:382
Non-zero when bay 0 is free.
Definition: roadstop_base.h:26
Entry * east
The vehicles that entered from the east.
void SetEntranceBusy(bool busy)
Makes an entrance occupied or free.
struct RoadStop * next
Next stop of the given type at this station.
Definition: roadstop_base.h:71
void AllocateDriveThroughBay(uint nr)
Allocates a bay in a drive-through road stop.
Entry * GetEntry(DiagDirection dir)
Get the drive through road stop entry struct for the given direction.
bool IsFreeBay(uint nr) const
Checks whether the given bay is free in this road stop.
Definition: roadstop_base.h:95
Enumeration for diagonal directions.
int length
The length of the stop in tile &#39;units&#39;.
Definition: roadstop_base.h:36
Entry * west
The vehicles that entered from the west.
Base class for all PoolItems.
Definition: pool_type.hpp:146
Base class for all pools.
Definition: pool_type.hpp:83
Container for each entry point of a drive through road stop.
Definition: roadstop_base.h:34
De-Initializes RoadStops.
Definition: roadstop.cpp:28
bool HasFreeBay() const
Checks whether there is a free bay in this road stop.
Definition: roadstop_base.h:85
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
RoadStopPool _roadstop_pool
The pool of roadstops.
Types related to vehicles.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
int occupied
The amount of occupied stop in tile &#39;units&#39;.
Definition: roadstop_base.h:37
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the &#39;next&#39; tile is still part of the road same drive through stop &#39;rs&#39; in the same dir...
Definition: roadstop.cpp:307
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
void Leave(const RoadVehicle *rv)
Leave the road stop.
Definition: roadstop.cpp:282
RoadStop(TileIndex tile=INVALID_TILE)
Initializes a RoadStop.
Definition: roadstop_base.h:74
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
Definition: roadstop_base.h:29
void Rebuild(const RoadStop *rs, int side=-1)
Rebuild, from scratch, the vehicles and other metadata on this stop.
Definition: roadstop.cpp:354
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition: roadstop.cpp:268