summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-26 10:45:20 +0000
committersmatz <smatz@openttd.org>2009-06-26 10:45:20 +0000
commit90554ee39091c98cb89b0c9a90b529564a82ff38 (patch)
treee599b70959074506c19535ce47a5a9d978f39507 /src
parentf2e55319dd165f57e008e0fac355ce294fc98905 (diff)
downloadopenttd-90554ee39091c98cb89b0c9a90b529564a82ff38.tar.xz
(svn r16662) -Codechange: replace GetRoadStopByTile() by RoadStop::GetByTile()
Diffstat (limited to 'src')
-rw-r--r--src/roadstop.cpp18
-rw-r--r--src/roadstop_base.h2
-rw-r--r--src/roadveh_cmd.cpp10
-rw-r--r--src/station_cmd.cpp17
4 files changed, 28 insertions, 19 deletions
diff --git a/src/roadstop.cpp b/src/roadstop.cpp
index eda4daa94..5082ee429 100644
--- a/src/roadstop.cpp
+++ b/src/roadstop.cpp
@@ -7,6 +7,7 @@
#include "station_map.h"
#include "core/pool_func.hpp"
#include "roadstop_base.h"
+#include "station_base.h"
RoadStopPool _roadstop_pool("RoadStop");
INSTANTIATE_POOL_METHODS(RoadStop)
@@ -48,6 +49,23 @@ RoadStop *RoadStop::GetNextRoadStop(const RoadVehicle *v) const
return NULL;
}
+/**
+ * Find a roadstop at given tile
+ * @param tile tile with roadstop
+ * @param type roadstop type
+ * @return pointer to RoadStop
+ * @pre there has to be roadstop of given type there!
+ */
+/* static */ RoadStop *RoadStop::GetByTile(TileIndex tile, RoadStopType type)
+{
+ const Station *st = Station::GetByTile(tile);
+
+ for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
+ if (rs->xy == tile) return rs;
+ assert(rs->next != NULL);
+ }
+}
+
void InitializeRoadStops()
{
_roadstop_pool.CleanPool();
diff --git a/src/roadstop_base.h b/src/roadstop_base.h
index 6a18f5cbe..695ada14a 100644
--- a/src/roadstop_base.h
+++ b/src/roadstop_base.h
@@ -114,6 +114,8 @@ struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
}
RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
+
+ static RoadStop *GetByTile(TileIndex tile, RoadStopType type);
};
#define FOR_ALL_ROADSTOPS_FROM(var, start) FOR_ALL_ITEMS_FROM(RoadStop, roadstop_index, var, start)
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 2b259635f..12f206f9b 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -496,7 +496,7 @@ void RoadVehicle::UpdateDeltaXY(Direction direction)
static void ClearCrashedStation(RoadVehicle *v)
{
- RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
+ RoadStop *rs = RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile));
/* Mark the station entrance as not busy */
rs->SetEntranceBusy(false);
@@ -1040,7 +1040,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
} else {
/* Proper station type, check if there is free loading bay */
if (!_settings_game.pf.roadveh_queue && IsStandardRoadStopTile(tile) &&
- !GetRoadStopByTile(tile, rstype)->HasFreeBay()) {
+ !RoadStop::GetByTile(tile, rstype)->HasFreeBay()) {
/* Station is full and RV queuing is off */
trackdirs = TRACKDIR_BIT_NONE;
}
@@ -1491,7 +1491,7 @@ again:
return false;
}
if (IsRoadStop(v->tile)) {
- RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
+ RoadStop *rs = RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile));
/* Vehicle is leaving a road stop tile, mark bay as free
* For drive-through stops, only do it if the vehicle stopped here */
@@ -1640,7 +1640,7 @@ again:
GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
v->frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
- RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
+ RoadStop *rs = RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile));
Station *st = Station::GetByTile(v->tile);
/* Vehicle is at the stop position (at a bay) in a road stop.
@@ -1655,7 +1655,7 @@ again:
/* Check if next inline bay is free */
if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type) && GetStationIndex(v->tile) == GetStationIndex(next_tile)) {
- RoadStop *rs_n = GetRoadStopByTile(next_tile, type);
+ RoadStop *rs_n = RoadStop::GetByTile(next_tile, type);
if (rs_n->IsFreeBay(HasBit(v->state, RVS_USING_SECOND_BAY)) && rs_n->num_vehicles < RoadStop::MAX_VEHICLES) {
/* Bay in next stop along is free - use it */
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 443321a92..abee45c61 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -56,17 +56,6 @@ bool IsHangar(TileIndex t)
return false;
}
-RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type)
-{
- const Station *st = Station::GetByTile(tile);
-
- for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
- if (rs->xy == tile) return rs;
- assert(rs->next != NULL);
- }
-}
-
-
static uint GetNumRoadStopsInStation(const Station *st, RoadStopType type)
{
uint num = 0;
@@ -1513,10 +1502,10 @@ static CommandCost RemoveRoadStop(Station *st, DoCommandFlag flags, TileIndex ti
RoadStop *cur_stop;
if (is_truck) { // truck stop
primary_stop = &st->truck_stops;
- cur_stop = GetRoadStopByTile(tile, ROADSTOP_TRUCK);
+ cur_stop = RoadStop::GetByTile(tile, ROADSTOP_TRUCK);
} else {
primary_stop = &st->bus_stops;
- cur_stop = GetRoadStopByTile(tile, ROADSTOP_BUS);
+ cur_stop = RoadStop::GetByTile(tile, ROADSTOP_BUS);
}
assert(cur_stop != NULL);
@@ -2560,7 +2549,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
if (IsRoadStop(tile) && IsRoadVehFront(v)) {
/* Attempt to allocate a parking bay in a road stop */
- RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
+ RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
if (IsDriveThroughStopTile(tile)) {
if (!rv->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;