Update: Translations from eints
[openttd-github.git] / src / roadstop_base.h
blob16ec9094209240efa5d09ca823a5970afee87174
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <http://www.gnu.org/licenses/>.
6 */
8 /** @file roadstop_base.h Base class for roadstops. */
10 #ifndef ROADSTOP_BASE_H
11 #define ROADSTOP_BASE_H
13 #include "station_type.h"
14 #include "core/pool_type.hpp"
15 #include "core/bitmath_func.hpp"
16 #include "vehicle_type.h"
18 typedef Pool<RoadStop, RoadStopID, 32, 64000> RoadStopPool;
19 extern RoadStopPool _roadstop_pool;
21 /** A Stop for a Road Vehicle */
22 struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
23 enum RoadStopStatusFlags {
24 RSSFB_BAY0_FREE = 0, ///< Non-zero when bay 0 is free
25 RSSFB_BAY1_FREE = 1, ///< Non-zero when bay 1 is free
26 RSSFB_BASE_ENTRY = 6, ///< Non-zero when the entries on this road stop are the primary, i.e. the ones to delete
27 RSSFB_ENTRY_BUSY = 7, ///< Non-zero when roadstop entry is busy
30 static constexpr uint8_t BAY_COUNT = 2; ///< Max. number of bays
32 /** Container for each entry point of a drive through road stop */
33 struct Entry {
34 private:
35 int length; ///< The length of the stop in tile 'units'
36 int occupied; ///< The amount of occupied stop in tile 'units'
38 public:
39 friend struct RoadStop; ///< Oh yeah, the road stop may play with me.
41 /** Create an entry */
42 Entry() : length(0), occupied(0) {}
44 /**
45 * Get the length of this drive through stop.
46 * @return the length in tile units.
48 inline int GetLength() const
50 return this->length;
53 /**
54 * Get the amount of occupied space in this drive through stop.
55 * @return the occupied space in tile units.
57 inline int GetOccupied() const
59 return this->occupied;
62 void Leave(const RoadVehicle *rv);
63 void Enter(const RoadVehicle *rv);
64 void CheckIntegrity(const RoadStop *rs) const;
65 void Rebuild(const RoadStop *rs);
68 uint8_t status; ///< Current status of the Stop, @see RoadStopSatusFlag. Access using *Bay and *Busy functions.
69 TileIndex xy; ///< Position on the map
70 RoadStop *next; ///< Next stop of the given type at this station
72 /** Initializes a RoadStop */
73 inline RoadStop(TileIndex tile = INVALID_TILE) :
74 status((1 << BAY_COUNT) - 1),
75 xy(tile)
76 { }
78 ~RoadStop();
80 /**
81 * Checks whether there is a free bay in this road stop
82 * @return is at least one bay free?
84 inline bool HasFreeBay() const
86 return GB(this->status, 0, BAY_COUNT) != 0;
89 /**
90 * Checks whether the given bay is free in this road stop
91 * @param nr bay to check
92 * @return is given bay free?
94 inline bool IsFreeBay(uint nr) const
96 assert(nr < BAY_COUNT);
97 return HasBit(this->status, nr);
101 * Checks whether the entrance of the road stop is occupied by a vehicle
102 * @return is entrance busy?
104 inline bool IsEntranceBusy() const
106 return HasBit(this->status, RSSFB_ENTRY_BUSY);
110 * Makes an entrance occupied or free
111 * @param busy If true, marks busy; free otherwise.
113 inline void SetEntranceBusy(bool busy)
115 SB(this->status, RSSFB_ENTRY_BUSY, 1, busy);
119 * Get the drive through road stop entry struct for the given direction.
120 * @param dir The direction to get the entry for.
121 * @return the entry
123 inline const Entry *GetEntry(DiagDirection dir) const
125 return HasBit((int)dir, 1) ? this->west : this->east;
129 * Get the drive through road stop entry struct for the given direction.
130 * @param dir The direction to get the entry for.
131 * @return the entry
133 inline Entry *GetEntry(DiagDirection dir)
135 return HasBit((int)dir, 1) ? this->west : this->east;
138 void MakeDriveThrough();
139 void ClearDriveThrough();
141 void Leave(RoadVehicle *rv);
142 bool Enter(RoadVehicle *rv);
144 RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
146 static RoadStop *GetByTile(TileIndex tile, RoadStopType type);
148 static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next);
150 private:
151 Entry *east; ///< The vehicles that entered from the east
152 Entry *west; ///< The vehicles that entered from the west
155 * Allocates a bay
156 * @return the allocated bay number
157 * @pre this->HasFreeBay()
159 inline uint AllocateBay()
161 assert(this->HasFreeBay());
163 /* Find the first free bay. If the bit is set, the bay is free. */
164 uint bay_nr = 0;
165 while (!HasBit(this->status, bay_nr)) bay_nr++;
167 ClrBit(this->status, bay_nr);
168 return bay_nr;
172 * Allocates a bay in a drive-through road stop
173 * @param nr the number of the bay to allocate
175 inline void AllocateDriveThroughBay(uint nr)
177 assert(nr < BAY_COUNT);
178 ClrBit(this->status, nr);
182 * Frees the given bay
183 * @param nr the number of the bay to free
185 inline void FreeBay(uint nr)
187 assert(nr < BAY_COUNT);
188 SetBit(this->status, nr);
192 #endif /* ROADSTOP_BASE_H */