diff options
-rw-r--r-- | src/roadstop.cpp | 18 | ||||
-rw-r--r-- | src/roadstop_base.h | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 10 | ||||
-rw-r--r-- | src/station_cmd.cpp | 17 |
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; |