summaryrefslogtreecommitdiff
path: root/src/station.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-24 19:19:18 +0000
committerrubidium <rubidium@openttd.org>2007-08-24 19:19:18 +0000
commit8a86526d0531be07b012bd216417e485bfdd559b (patch)
tree4ba5c20c99a256e84546732ef66ef1a12b6255a1 /src/station.cpp
parent6c061ecfb491ab0cfc6665156ad7bed316ccb3e8 (diff)
downloadopenttd-8a86526d0531be07b012bd216417e485bfdd559b.tar.xz
(svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
Diffstat (limited to 'src/station.cpp')
-rw-r--r--src/station.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/station.cpp b/src/station.cpp
index 16723fc68..6f0c12ce4 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -34,6 +34,8 @@
#include "yapf/yapf.h"
#include "date.h"
#include "helpers.hpp"
+#include "cargotype.h"
+#include "roadveh.h"
Station::Station(TileIndex tile)
{
@@ -92,6 +94,29 @@ Station::~Station()
}
}
+
+/**
+ * Get the primary road stop (the first road stop) that the given vehicle can load/unload.
+ * @param v the vehicle to get the first road stop for
+ * @return the first roadstop that this vehicle can load at
+ */
+RoadStop *Station::GetPrimaryRoadStop(const Vehicle *v) const
+{
+ RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK);
+
+ for (; rs != NULL; rs = rs->next) {
+ /* The vehicle cannot go to this roadstop (different roadtype) */
+ if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) == ROADTYPES_NONE) continue;
+ /* The vehicle is articulated and can therefor not go the a standard road stop */
+ if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
+
+ /* The vehicle can actually go to this road stop. So, return it! */
+ break;
+ }
+
+ return rs;
+}
+
/** Called when new facility is built on the station. If it is the first facility
* it initializes also 'xy' and 'random_bits' members */
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
@@ -480,3 +505,23 @@ void RoadStop::SetEntranceBusy(bool busy)
{
SB(status, 7, 1, busy);
}
+
+/**
+ * Get the next road stop accessible by this vehicle.
+ * @param v the vehicle to get the next road stop for.
+ * @return the next road stop accessible.
+ */
+RoadStop *RoadStop::GetNextRoadStop(const Vehicle *v) const
+{
+ for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
+ /* The vehicle cannot go to this roadstop (different roadtype) */
+ if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) != ROADTYPES_NONE) continue;
+ /* The vehicle is articulated and can therefor not go the a standard road stop */
+ if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
+
+ /* The vehicle can actually go to this road stop. So, return it! */
+ return rs;
+ }
+
+ return NULL;
+}