1
0
Fork 0

(svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen

release/1.1
rubidium 2010-12-22 21:16:34 +00:00
parent fba9670a62
commit a38a1e7b0d
2 changed files with 99 additions and 78 deletions

View File

@ -254,6 +254,9 @@ public:
void ConvertFromOldSavegame(); void ConvertFromOldSavegame();
}; };
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord);
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord);
/** /**
* Shared order list linking together the linked list of orders and the list * Shared order list linking together the linked list of orders and the list
* of vehicles sharing this order list. * of vehicles sharing this order list.

View File

@ -663,7 +663,20 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Order *new_o = new Order(); Order *new_o = new Order();
new_o->AssignOrder(new_order); new_o->AssignOrder(new_order);
InsertOrder(v, new_o, sel_ord);
}
return CommandCost();
}
/**
* Insert a new order but skip the validation.
* @param v The vehicle to insert the order to.
* @param new_o The new order.
* @param sel_ord The position the order should be inserted at.
*/
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
{
/* Create new order and link in list */ /* Create new order and link in list */
if (v->orders.list == NULL) { if (v->orders.list == NULL) {
v->orders.list = new OrderList(new_o, v); v->orders.list = new OrderList(new_o, v);
@ -677,7 +690,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
assert(v->orders.list == u->orders.list); assert(v->orders.list == u->orders.list);
/* If there is added an order before the current one, we need /* If there is added an order before the current one, we need
to update the selected order */ * to update the selected order */
if (sel_ord <= u->cur_order_index) { if (sel_ord <= u->cur_order_index) {
uint cur = u->cur_order_index + 1; uint cur = u->cur_order_index + 1;
/* Check if we don't go out of bound */ /* Check if we don't go out of bound */
@ -709,9 +722,6 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
} }
return CommandCost();
}
/** /**
* Declone an order-list * Declone an order-list
* @param *dst delete the orders of this vehicle * @param *dst delete the orders of this vehicle
@ -755,7 +765,17 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
order = v->GetOrder(sel_ord); order = v->GetOrder(sel_ord);
if (order == NULL) return CMD_ERROR; if (order == NULL) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) DeleteOrder(v, sel_ord);
return CommandCost();
}
/**
* Delete an order but skip the parameter validation.
* @param v The vehicle to delete the order from.
* @param sel_ord The id of the order to be deleted.
*/
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
{
v->orders.list->DeleteOrderAt(sel_ord); v->orders.list->DeleteOrderAt(sel_ord);
Vehicle *u = v->FirstShared(); Vehicle *u = v->FirstShared();
@ -780,6 +800,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* As we delete an order, the order to skip to will be 'wrong'. */ /* As we delete an order, the order to skip to will be 'wrong'. */
VehicleOrderID cur_order_id = 0; VehicleOrderID cur_order_id = 0;
Order *order = NULL;
FOR_VEHICLE_ORDERS(v, order) { FOR_VEHICLE_ORDERS(v, order) {
if (order->IsType(OT_CONDITIONAL)) { if (order->IsType(OT_CONDITIONAL)) {
VehicleOrderID order_id = order->GetConditionSkipToOrder(); VehicleOrderID order_id = order->GetConditionSkipToOrder();
@ -796,9 +817,6 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
} }
return CommandCost();
}
/** /**
* Goto order of order-list. * Goto order of order-list.
* @param tile unused * @param tile unused