mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
Codechange: Use FindVehiclesWithOrder when removing a road stop. (#12144)
This commit is contained in:
parent
907cb4fc53
commit
8746be8bf2
@ -10,6 +10,7 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "aircraft.h"
|
#include "aircraft.h"
|
||||||
#include "bridge_map.h"
|
#include "bridge_map.h"
|
||||||
|
#include "vehiclelist_func.h"
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
#include "viewport_kdtree.h"
|
#include "viewport_kdtree.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
@ -2174,13 +2175,18 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags, int repla
|
|||||||
|
|
||||||
delete cur_stop;
|
delete cur_stop;
|
||||||
|
|
||||||
/* Make sure no vehicle is going to the old roadstop */
|
/* Make sure no vehicle is going to the old roadstop. Narrow the search to any road vehicles with an order to
|
||||||
for (RoadVehicle *v : RoadVehicle::Iterate()) {
|
* this station, then look for any currently heading to the tile. */
|
||||||
if (v->First() == v && v->current_order.IsType(OT_GOTO_STATION) &&
|
StationID station_id = st->index;
|
||||||
v->dest_tile == tile) {
|
FindVehiclesWithOrder(
|
||||||
v->SetDestTile(v->GetOrderStationLocation(st->index));
|
[](const Vehicle *v) { return v->type == VEH_ROAD; },
|
||||||
|
[station_id](const Order *order) { return order->IsType(OT_GOTO_STATION) && order->GetDestination() == station_id; },
|
||||||
|
[station_id, tile](Vehicle *v) {
|
||||||
|
if (v->dest_tile == tile) {
|
||||||
|
v->SetDestTile(v->GetOrderStationLocation(station_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
st->rect.AfterRemoveTile(st, tile);
|
st->rect.AfterRemoveTile(st, tile);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void FindVehiclesWithOrder(VehiclePredicate veh_pred, OrderPredicate ord_pred, V
|
|||||||
for (const OrderList *orderlist : OrderList::Iterate()) {
|
for (const OrderList *orderlist : OrderList::Iterate()) {
|
||||||
|
|
||||||
/* We assume all vehicles sharing an order list match the condition. */
|
/* We assume all vehicles sharing an order list match the condition. */
|
||||||
const Vehicle *v = orderlist->GetFirstSharedVehicle();
|
Vehicle *v = orderlist->GetFirstSharedVehicle();
|
||||||
if (!veh_pred(v)) continue;
|
if (!veh_pred(v)) continue;
|
||||||
|
|
||||||
/* Vehicle is a candidate, search for a matching order. */
|
/* Vehicle is a candidate, search for a matching order. */
|
||||||
|
Loading…
Reference in New Issue
Block a user