Add feature to reverse the order of an order list

See: #120
This commit is contained in:
Jonathan G Rennison
2020-11-02 20:10:44 +00:00
parent 7381e00859
commit 9984f39c96
6 changed files with 92 additions and 4 deletions

View File

@@ -1573,6 +1573,34 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return CommandCost();
}
/**
* Reverse an orderlist
* @param tile unused
* @param flags operation to perform
* @param p1 the ID of the vehicle
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdReverseOrderList(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
VehicleID veh = GB(p1, 0, 20);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
uint order_count = v->GetNumOrders();
if (order_count < 2) return CMD_ERROR;
uint max_order = order_count - 1;
for (uint i = 0; i < max_order; i++) {
CommandCost cost = DoCommand(tile, p1, max_order | (i << 16), flags, CMD_MOVE_ORDER);
if (cost.Failed()) return cost;
}
return CommandCost();
}
/**
* Modify an order in the orderlist of a vehicle.
* @param tile unused