mirror of https://github.com/OpenTTD/OpenTTD
(svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
parent
caa3b659b0
commit
c41624bb94
|
@ -720,61 +720,97 @@ CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||||
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
|
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
|
||||||
* the order will be inserted before that one
|
* the order will be inserted before that one
|
||||||
* only the first 8 bits used currently (bit 16 - 23) (max 255)
|
* only the first 8 bits used currently (bit 16 - 23) (max 255)
|
||||||
* @param p2 mode to change the order to (always set)
|
* @param p2 various bitstuffed elements
|
||||||
|
* - p2 = (bit 0 - 1) - what data to modify (@see ModifyOrderFlags)
|
||||||
|
* - p2 = (bit 2 - 5) - the data to modify
|
||||||
*/
|
*/
|
||||||
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
Vehicle *v;
|
|
||||||
Order *order;
|
|
||||||
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
|
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
|
||||||
VehicleID veh = GB(p1, 0, 16);
|
VehicleID veh = GB(p1, 0, 16);
|
||||||
|
ModifyOrderFlags mof = (ModifyOrderFlags)GB(p2, 0, 2);
|
||||||
|
uint8 data = GB(p2, 2, 4);
|
||||||
|
|
||||||
if (!IsValidVehicleID(veh)) return CMD_ERROR;
|
if (!IsValidVehicleID(veh)) return CMD_ERROR;
|
||||||
if (p2 != OF_FULL_LOAD && p2 != OF_UNLOAD && p2 != OF_NON_STOP && p2 != OF_TRANSFER) return CMD_ERROR;
|
|
||||||
|
|
||||||
v = GetVehicle(veh);
|
|
||||||
|
|
||||||
|
Vehicle *v = GetVehicle(veh);
|
||||||
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Is it a valid order? */
|
/* Is it a valid order? */
|
||||||
if (sel_ord >= v->num_orders) return CMD_ERROR;
|
if (sel_ord >= v->num_orders) return CMD_ERROR;
|
||||||
|
|
||||||
order = GetVehicleOrder(v, sel_ord);
|
Order *order = GetVehicleOrder(v, sel_ord);
|
||||||
if ((!order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->IsBuoy()) &&
|
switch (order->GetType()) {
|
||||||
(!order->IsType(OT_GOTO_DEPOT) || p2 == OF_UNLOAD) &&
|
case OT_GOTO_STATION:
|
||||||
(!order->IsType(OT_GOTO_WAYPOINT) || p2 != OF_NON_STOP)) {
|
if (mof == MOF_DEPOT_ACTION || GetStation(order->GetDestination())->IsBuoy()) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
break;
|
||||||
|
|
||||||
|
case OT_GOTO_DEPOT:
|
||||||
|
if (mof == MOF_UNLOAD || mof == MOF_LOAD) return CMD_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OT_GOTO_WAYPOINT:
|
||||||
|
if (mof != MOF_NON_STOP) return CMD_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mof) {
|
||||||
|
case MOF_NON_STOP:
|
||||||
|
if (data >= ONSF_END) return CMD_ERROR;
|
||||||
|
if (data == order->GetNonStopType()) return CMD_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOF_UNLOAD:
|
||||||
|
if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER)) != 0) return CMD_ERROR;
|
||||||
|
if (data == order->GetUnloadType()) return CMD_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOF_LOAD:
|
||||||
|
if ((data & ~OLFB_FULL_LOAD) != 0) return CMD_ERROR;
|
||||||
|
if (data == order->GetLoadType()) return CMD_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOF_DEPOT_ACTION:
|
||||||
|
if (data != 0) return CMD_ERROR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
switch (p2) {
|
switch (mof) {
|
||||||
case OF_FULL_LOAD:
|
case MOF_NON_STOP:
|
||||||
if (order->IsType(OT_GOTO_DEPOT)) {
|
order->SetNonStopType((OrderNonStopFlags)data);
|
||||||
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() ^ ODTFB_SERVICE));
|
break;
|
||||||
} else {
|
|
||||||
order->SetLoadType((OrderLoadFlags)(order->GetLoadType() ^ OLFB_FULL_LOAD));
|
case MOF_UNLOAD:
|
||||||
|
order->SetUnloadType((OrderUnloadFlags)data);
|
||||||
|
/* Full loading gets disabled when un loading! */
|
||||||
|
if ((data & OUFB_UNLOAD) != 0) {
|
||||||
|
order->SetLoadType((OrderLoadFlags)(order->GetLoadType() & ~OLFB_FULL_LOAD));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOF_LOAD:
|
||||||
|
order->SetLoadType((OrderLoadFlags)data);
|
||||||
|
/* Unloading gets disabled when full loading! */
|
||||||
|
if ((data & OLFB_FULL_LOAD) != 0) {
|
||||||
order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() & ~OUFB_UNLOAD));
|
order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() & ~OUFB_UNLOAD));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OF_UNLOAD:
|
|
||||||
order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() ^ OUFB_UNLOAD));
|
case MOF_DEPOT_ACTION:
|
||||||
order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() ^ ODTFB_SERVICE));
|
||||||
break;
|
|
||||||
case OF_NON_STOP:
|
|
||||||
order->SetNonStopType((order->GetNonStopType() == (_patches.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE)) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_STOP_EVERYWHERE);
|
|
||||||
break;
|
|
||||||
case OF_TRANSFER:
|
|
||||||
order->SetUnloadType((OrderUnloadFlags)(order->GetUnloadType() ^ OUFB_TRANSFER));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
||||||
{
|
Vehicle *u = GetFirstVehicleFromSharedList(v);
|
||||||
Vehicle* u;
|
DeleteOrderWarnings(u);
|
||||||
|
if (mof == MOF_LOAD || mof == MOF_UNLOAD) {
|
||||||
u = GetFirstVehicleFromSharedList(v);
|
|
||||||
DeleteOrderWarnings(u);
|
|
||||||
for (; u != NULL; u = u->next_shared) {
|
for (; u != NULL; u = u->next_shared) {
|
||||||
/* Toggle u->current_order "Full load" flag if it changed.
|
/* Toggle u->current_order "Full load" flag if it changed.
|
||||||
* However, as the same flag is used for depot orders, check
|
* However, as the same flag is used for depot orders, check
|
||||||
|
@ -786,7 +822,7 @@ CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||||
* when this function is called.
|
* when this function is called.
|
||||||
*/
|
*/
|
||||||
if (sel_ord == u->cur_order_index &&
|
if (sel_ord == u->cur_order_index &&
|
||||||
!u->current_order.IsType(OT_GOTO_DEPOT) &&
|
(u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) &&
|
||||||
u->current_order.GetLoadType() != order->GetLoadType()) {
|
u->current_order.GetLoadType() != order->GetLoadType()) {
|
||||||
u->current_order.SetLoadType(order->GetLoadType());
|
u->current_order.SetLoadType(order->GetLoadType());
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,7 +404,14 @@ static void OrderClick_Goto(Window *w, const Vehicle *v)
|
||||||
*/
|
*/
|
||||||
static void OrderClick_FullLoad(Window *w, const Vehicle *v)
|
static void OrderClick_FullLoad(Window *w, const Vehicle *v)
|
||||||
{
|
{
|
||||||
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OF_FULL_LOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
VehicleOrderID sel_ord = OrderGetSel(w);
|
||||||
|
const Order *order = GetVehicleOrder(v, sel_ord);
|
||||||
|
|
||||||
|
if (order->IsType(OT_GOTO_STATION)) {
|
||||||
|
DoCommandP(v->tile, v->index + (sel_ord << 16), MOF_LOAD | (order->GetLoadType() ^ OLFB_FULL_LOAD) << 2, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
||||||
|
} else {
|
||||||
|
DoCommandP(v->tile, v->index + (sel_ord << 16), MOF_DEPOT_ACTION, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -415,7 +422,10 @@ static void OrderClick_FullLoad(Window *w, const Vehicle *v)
|
||||||
*/
|
*/
|
||||||
static void OrderClick_Unload(Window *w, const Vehicle *v)
|
static void OrderClick_Unload(Window *w, const Vehicle *v)
|
||||||
{
|
{
|
||||||
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OF_UNLOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
VehicleOrderID sel_ord = OrderGetSel(w);
|
||||||
|
const Order *order = GetVehicleOrder(v, sel_ord);
|
||||||
|
|
||||||
|
DoCommandP(v->tile, v->index + (sel_ord << 16), MOF_UNLOAD | (order->GetUnloadType() ^ OUFB_UNLOAD) << 2, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -426,7 +436,10 @@ static void OrderClick_Unload(Window *w, const Vehicle *v)
|
||||||
*/
|
*/
|
||||||
static void OrderClick_Nonstop(Window *w, const Vehicle *v)
|
static void OrderClick_Nonstop(Window *w, const Vehicle *v)
|
||||||
{
|
{
|
||||||
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OF_NON_STOP, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
VehicleOrderID sel_ord = OrderGetSel(w);
|
||||||
|
const Order *order = GetVehicleOrder(v, sel_ord);
|
||||||
|
|
||||||
|
DoCommandP(v->tile, v->index + (sel_ord << 16), MOF_NON_STOP | ((order->GetNonStopType() == (_patches.new_nonstop ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE)) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_STOP_EVERYWHERE) << 2, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -437,7 +450,10 @@ static void OrderClick_Nonstop(Window *w, const Vehicle *v)
|
||||||
*/
|
*/
|
||||||
static void OrderClick_Transfer(Window* w, const Vehicle* v)
|
static void OrderClick_Transfer(Window* w, const Vehicle* v)
|
||||||
{
|
{
|
||||||
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OF_TRANSFER, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
VehicleOrderID sel_ord = OrderGetSel(w);
|
||||||
|
const Order *order = GetVehicleOrder(v, sel_ord);
|
||||||
|
|
||||||
|
DoCommandP(v->tile, v->index + (sel_ord << 16), MOF_UNLOAD | (order->GetUnloadType() ^ OUFB_TRANSFER) << 2, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -61,6 +61,7 @@ enum OrderNonStopFlags {
|
||||||
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS = 1, ///< The vehicle will not stop at any stations it passes except the destination.
|
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS = 1, ///< The vehicle will not stop at any stations it passes except the destination.
|
||||||
ONSF_NO_STOP_AT_DESTINATION_STATION = 2, ///< The vehicle will stop at any station it passes except the destination.
|
ONSF_NO_STOP_AT_DESTINATION_STATION = 2, ///< The vehicle will stop at any station it passes except the destination.
|
||||||
ONSF_NO_STOP_AT_ANY_STATION = 3, ///< The vehicle will not stop at any stations it passes including the destination.
|
ONSF_NO_STOP_AT_ANY_STATION = 3, ///< The vehicle will not stop at any stations it passes including the destination.
|
||||||
|
ONSF_END
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,13 +82,13 @@ enum OrderDepotActionFlags {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration for the 'flag' to toggle in CmdModifyOrder.
|
* Enumeration for the data to set in CmdModifyOrder.
|
||||||
*/
|
*/
|
||||||
enum {
|
enum ModifyOrderFlags {
|
||||||
OF_TRANSFER = 0,
|
MOF_NON_STOP, ///< Passes a OrderNonStopFlags.
|
||||||
OF_UNLOAD = 1,
|
MOF_UNLOAD, ///< Passes an OrderUnloadType.
|
||||||
OF_FULL_LOAD = 2,
|
MOF_LOAD, ///< Passes an OrderLoadType
|
||||||
OF_NON_STOP = 3
|
MOF_DEPOT_ACTION, ///< Toggle the 'service' if needed flag.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue