summaryrefslogtreecommitdiff
path: root/src/station.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-02-13 00:25:42 +0000
committerrubidium <rubidium@openttd.org>2007-02-13 00:25:42 +0000
commiteab6dd989821a2cacb96a94de0da789214f6e2b4 (patch)
tree1659c231e1a1a50b63b787697ddedc12a7d2895f /src/station.cpp
parent3b0e00e2f91c524153f804a6a53946d3b555f021 (diff)
downloadopenttd-eab6dd989821a2cacb96a94de0da789214f6e2b4.tar.xz
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
Diffstat (limited to 'src/station.cpp')
-rw-r--r--src/station.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/station.cpp b/src/station.cpp
index 985d39850..296a974fd 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -437,3 +437,52 @@ bool RoadStop::IsValid() const
{
return xy != INVALID_TILE;
}
+
+/** Checks whether there is a free bay in this road stop */
+bool RoadStop::HasFreeBay() const
+{
+ return GB(status, 0, MAX_BAY_COUNT) != 0;
+}
+
+/**
+ * Allocates a bay
+ * @return the allocated bay number
+ * @pre this->HasFreeBay()
+ */
+uint RoadStop::AllocateBay()
+{
+ /* Find the first free bay. If the bit is set, the bay is free. */
+ for (uint bay_nr = 0; bay_nr < MAX_BAY_COUNT; bay_nr++) {
+ if (HASBIT(status, bay_nr)) {
+ CLRBIT(status, bay_nr);
+ return bay_nr;
+ }
+ }
+
+ /* There has to be a free bay (precondition) */
+ NOT_REACHED();
+ return 0;
+}
+
+/**
+ * Frees the given bay
+ * @param nr the number of the bay to free
+ */
+void RoadStop::FreeBay(uint nr)
+{
+ assert(nr < MAX_BAY_COUNT);
+ SETBIT(status, nr);
+}
+
+
+/** Checks whether the entrance of the road stop is occupied by a vehicle */
+bool RoadStop::IsEntranceBusy() const
+{
+ return HASBIT(status, 7);
+}
+
+/** Makes an entrance occupied or free */
+void RoadStop::SetEntranceBusy(bool busy)
+{
+ SB(status, 7, 1, !!busy);
+}