Codechange: Un-bitstuff order commands.

This commit is contained in:
Michael Lutz 2021-11-02 22:58:40 +01:00
parent de45a8729c
commit 211c630cbe
10 changed files with 106 additions and 131 deletions

View File

@ -402,7 +402,7 @@ static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head,
CommandCost cost = CommandCost(); CommandCost cost = CommandCost();
/* Share orders */ /* Share orders */
if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_CLONE_ORDER>::Do(DC_EXEC, 0, new_head->index | CO_SHARE << 30, old_head->index, {})); if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_CLONE_ORDER>::Do(DC_EXEC, CO_SHARE, new_head->index, old_head->index));
/* Copy group membership */ /* Copy group membership */
if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_ADD_VEHICLE_GROUP>::Do(DC_EXEC, 0, old_head->group_id, new_head->index, {})); if (cost.Succeeded() && old_head != new_head) cost.AddCost(Command<CMD_ADD_VEHICLE_GROUP>::Do(DC_EXEC, 0, old_head->group_id, new_head->index, {}));

View File

@ -75,7 +75,7 @@ void OrderBackup::DoRestore(Vehicle *v)
{ {
/* If we had shared orders, recover that */ /* If we had shared orders, recover that */
if (this->clone != nullptr) { if (this->clone != nullptr) {
Command<CMD_CLONE_ORDER>::Do(DC_EXEC, 0, v->index | CO_SHARE << 30, this->clone->index, {}); Command<CMD_CLONE_ORDER>::Do(DC_EXEC, CO_SHARE, v->index, this->clone->index);
} else if (this->orders != nullptr && OrderList::CanAllocateItem()) { } else if (this->orders != nullptr && OrderList::CanAllocateItem()) {
v->orders.list = new OrderList(this->orders, v); v->orders.list = new OrderList(this->orders, v);
this->orders = nullptr; this->orders = nullptr;

View File

@ -25,6 +25,9 @@ typedef Pool<OrderList, OrderListID, 128, 64000> OrderListPool;
extern OrderPool _order_pool; extern OrderPool _order_pool;
extern OrderListPool _orderlist_pool; extern OrderListPool _orderlist_pool;
template <typename, typename>
class EndianBufferWriter;
/* If you change this, keep in mind that it is saved on 3 places: /* If you change this, keep in mind that it is saved on 3 places:
* - Load_ORDR, all the global orders * - Load_ORDR, all the global orders
* - Vehicle -> current_order * - Vehicle -> current_order
@ -38,6 +41,10 @@ private:
friend class SlVehicleCommon; friend class SlVehicleCommon;
friend class SlVehicleDisaster; friend class SlVehicleDisaster;
template <typename Tcont, typename Titer>
friend EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const Order &data);
friend class EndianBufferReader &operator >>(class EndianBufferReader &buffer, Order &order);
uint8 type; ///< The type of order + non-stop flags uint8 type; ///< The type of order + non-stop flags
uint8 flags; ///< Load/unload types, depot order/action types. uint8 flags; ///< Load/unload types, depot order/action types.
DestinationID dest; ///< The destination of the order. DestinationID dest; ///< The destination of the order.
@ -51,7 +58,7 @@ private:
public: public:
Order *next; ///< Pointer to next order. If nullptr, end of list Order *next; ///< Pointer to next order. If nullptr, end of list
Order() : flags(0), refit_cargo(CT_NO_REFIT), max_speed(UINT16_MAX) {} Order() : flags(0), refit_cargo(CT_NO_REFIT), wait_time(0), travel_time(0), max_speed(UINT16_MAX) {}
~Order(); ~Order();
Order(uint32 packed); Order(uint32 packed);

View File

@ -729,28 +729,25 @@ uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int
/** /**
* Add an order to the orderlist of a vehicle. * Add an order to the orderlist of a vehicle.
* @param flags operation to perform * @param flags operation to perform
* @param tile unused
* @param p1 various bitstuffed elements * @param p1 various bitstuffed elements
* - p1 = (bit 0 - 19) - ID of the vehicle * @param veh ID of the vehicle
* - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given, * @param sel_ord 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
* the maximum vehicle order id is 254. * the maximum vehicle order id is 254.
* @param p2 packed order to insert * @param new_order order to insert
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdInsertOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, const Order &new_order)
{ {
VehicleID veh = GB(p1, 0, 20);
VehicleOrderID sel_ord = GB(p1, 20, 8);
Order new_order(p2);
Vehicle *v = Vehicle::GetIfValid(veh); Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner); CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
/* Validate properties we don't want to have different from default as they are set by other commands. */
if (new_order.GetRefitCargo() != CT_NO_REFIT || new_order.GetWaitTime() != 0 || new_order.GetTravelTime() != 0 || new_order.GetMaxSpeed() != UINT16_MAX) return CMD_ERROR;
/* Check if the inserted order is to the correct destination (owner, type), /* Check if the inserted order is to the correct destination (owner, type),
* and has the correct flags if any */ * and has the correct flags if any */
switch (new_order.GetType()) { switch (new_order.GetType()) {
@ -1008,17 +1005,12 @@ static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
/** /**
* Delete an order from the orderlist of a vehicle. * Delete an order from the orderlist of a vehicle.
* @param flags operation to perform * @param flags operation to perform
* @param tile unused * @param veh_id the ID of the vehicle
* @param p1 the ID of the vehicle * @param sel_ord the order to delete (max 255)
* @param p2 the order to delete (max 255)
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdDeleteOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdDeleteOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord)
{ {
VehicleID veh_id = GB(p1, 0, 20);
VehicleOrderID sel_ord = GB(p2, 0, 8);
Vehicle *v = Vehicle::GetIfValid(veh_id); Vehicle *v = Vehicle::GetIfValid(veh_id);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
@ -1113,17 +1105,12 @@ void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
/** /**
* Goto order of order-list. * Goto order of order-list.
* @param flags operation to perform * @param flags operation to perform
* @param tile unused * @param veh_id The ID of the vehicle which order is skipped
* @param p1 The ID of the vehicle which order is skipped * @param sel_ord the selected order to which we want to skip
* @param p2 the selected order to which we want to skip
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdSkipToOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdSkipToOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord)
{ {
VehicleID veh_id = GB(p1, 0, 20);
VehicleOrderID sel_ord = GB(p2, 0, 8);
Vehicle *v = Vehicle::GetIfValid(veh_id); Vehicle *v = Vehicle::GetIfValid(veh_id);
if (v == nullptr || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
@ -1150,22 +1137,15 @@ CommandCost CmdSkipToOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint3
/** /**
* Move an order inside the orderlist * Move an order inside the orderlist
* @param flags operation to perform * @param flags operation to perform
* @param tile unused * @param veh the ID of the vehicle
* @param p1 the ID of the vehicle * @param moving_order the order to move
* @param p2 order to move and target * @param target_order the target order
* bit 0-15 : the order to move
* bit 16-31 : the target order
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
* @note The target order will move one place down in the orderlist * @note The target order will move one place down in the orderlist
* if you move the order upwards else it'll move it one place down * if you move the order upwards else it'll move it one place down
*/ */
CommandCost CmdMoveOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order)
{ {
VehicleID veh = GB(p1, 0, 20);
VehicleOrderID moving_order = GB(p2, 0, 16);
VehicleOrderID target_order = GB(p2, 16, 16);
Vehicle *v = Vehicle::GetIfValid(veh); Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR; if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
@ -1251,25 +1231,16 @@ CommandCost CmdMoveOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
/** /**
* Modify an order in the orderlist of a vehicle. * Modify an order in the orderlist of a vehicle.
* @param flags operation to perform * @param flags operation to perform
* @param tile unused * @param veh ID of the vehicle
* @param p1 various bitstuffed elements * @param sel_ord the selected order (if any). If the last order is given,
* - p1 = (bit 0 - 19) - ID of the vehicle * the order will be inserted before that one
* - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given, * the maximum vehicle order id is 254.
* the order will be inserted before that one * @param mof what data to modify (@see ModifyOrderFlags)
* the maximum vehicle order id is 254. * @param data the data to modify
* @param p2 various bitstuffed elements
* - p2 = (bit 0 - 3) - what data to modify (@see ModifyOrderFlags)
* - p2 = (bit 4 - 15) - the data to modify
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdModifyOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16 data)
{ {
VehicleOrderID sel_ord = GB(p1, 20, 8);
VehicleID veh = GB(p1, 0, 20);
ModifyOrderFlags mof = Extract<ModifyOrderFlags, 0, 4>(p2);
uint16 data = GB(p2, 4, 11);
if (mof >= MOF_END) return CMD_ERROR; if (mof >= MOF_END) return CMD_ERROR;
Vehicle *v = Vehicle::GetIfValid(veh); Vehicle *v = Vehicle::GetIfValid(veh);
@ -1524,26 +1495,20 @@ static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_o
/** /**
* Clone/share/copy an order-list of another vehicle. * Clone/share/copy an order-list of another vehicle.
* @param flags operation to perform * @param flags operation to perform
* @param tile unused * @param action action to perform
* @param p1 various bitstuffed elements * @param veh_dst destination vehicle to clone orders to
* - p1 = (bit 0-19) - destination vehicle to clone orders to * @param veh_src source vehicle to clone orders from, if any (none for CO_UNSHARE)
* - p1 = (bit 30-31) - action to perform
* @param p2 source vehicle to clone orders from, if any (none for CO_UNSHARE)
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdCloneOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src)
{ {
VehicleID veh_src = GB(p2, 0, 20);
VehicleID veh_dst = GB(p1, 0, 20);
Vehicle *dst = Vehicle::GetIfValid(veh_dst); Vehicle *dst = Vehicle::GetIfValid(veh_dst);
if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR; if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(dst->owner); CommandCost ret = CheckOwnership(dst->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
switch (GB(p1, 30, 2)) { switch (action) {
case CO_SHARE: { case CO_SHARE: {
Vehicle *src = Vehicle::GetIfValid(veh_src); Vehicle *src = Vehicle::GetIfValid(veh_src);
@ -1671,20 +1636,13 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32
/** /**
* Add/remove refit orders from an order * Add/remove refit orders from an order
* @param flags operation to perform * @param flags operation to perform
* @param tile Not used * @param veh VehicleIndex of the vehicle having the order
* @param p1 VehicleIndex of the vehicle having the order * @param order_number number of order to modify
* @param p2 bitmask * @param cargo CargoID
* - bit 0-7 CargoID
* - bit 16-23 number of order to modify
* @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdOrderRefit(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text) CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo)
{ {
VehicleID veh = GB(p1, 0, 20);
VehicleOrderID order_number = GB(p2, 16, 8);
CargoID cargo = GB(p2, 0, 8);
if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR; if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
const Vehicle *v = Vehicle::GetIfValid(veh); const Vehicle *v = Vehicle::GetIfValid(veh);

View File

@ -11,14 +11,16 @@
#define ORDER_CMD_H #define ORDER_CMD_H
#include "command_type.h" #include "command_type.h"
#include "order_base.h"
#include "misc/endian_buffer.hpp"
CommandProc CmdModifyOrder; CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16 data);
CommandProc CmdSkipToOrder; CommandCost CmdSkipToOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord);
CommandProc CmdDeleteOrder; CommandCost CmdDeleteOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord);
CommandProc CmdInsertOrder; CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, const Order &new_order);
CommandProc CmdOrderRefit; CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo);
CommandProc CmdCloneOrder; CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src);
CommandProc CmdMoveOrder; CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order);
CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID user_id); CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID user_id);
DEF_CMD_TRAIT(CMD_MODIFY_ORDER, CmdModifyOrder, 0, CMDT_ROUTE_MANAGEMENT) DEF_CMD_TRAIT(CMD_MODIFY_ORDER, CmdModifyOrder, 0, CMDT_ROUTE_MANAGEMENT)
@ -30,4 +32,15 @@ DEF_CMD_TRAIT(CMD_CLONE_ORDER, CmdCloneOrder, 0, CMDT_
DEF_CMD_TRAIT(CMD_MOVE_ORDER, CmdMoveOrder, 0, CMDT_ROUTE_MANAGEMENT) DEF_CMD_TRAIT(CMD_MOVE_ORDER, CmdMoveOrder, 0, CMDT_ROUTE_MANAGEMENT)
DEF_CMD_TRAIT(CMD_CLEAR_ORDER_BACKUP, CmdClearOrderBackup, CMD_CLIENT_ID, CMDT_SERVER_SETTING) DEF_CMD_TRAIT(CMD_CLEAR_ORDER_BACKUP, CmdClearOrderBackup, CMD_CLIENT_ID, CMDT_SERVER_SETTING)
template <typename Tcont, typename Titer>
inline EndianBufferWriter<Tcont, Titer> &operator <<(EndianBufferWriter<Tcont, Titer> &buffer, const Order &order)
{
return buffer << order.type << order.flags << order.dest << order.refit_cargo << order.wait_time << order.travel_time << order.max_speed;
}
inline EndianBufferReader &operator >>(EndianBufferReader &buffer, Order &order)
{
return buffer >> order.type >> order.flags >> order.dest >> order.refit_cargo >> order.wait_time >> order.travel_time >> order.max_speed;
}
#endif /* ORDER_CMD_H */ #endif /* ORDER_CMD_H */

View File

@ -30,6 +30,7 @@
#include "engine_func.h" #include "engine_func.h"
#include "vehicle_func.h" #include "vehicle_func.h"
#include "order_cmd.h" #include "order_cmd.h"
#include "company_cmd.h"
#include "widgets/order_widget.h" #include "widgets/order_widget.h"
@ -592,7 +593,7 @@ private:
} }
if (order->GetLoadType() == load_type) return; // If we still match, do nothing if (order->GetLoadType() == load_type) return; // If we still match, do nothing
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, load_type);
} }
/** /**
@ -607,7 +608,7 @@ private:
if (order == nullptr) return; if (order == nullptr) return;
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE; i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
} }
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_DEPOT_ACTION | (i << 4), {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, i);
} }
/** /**
@ -622,7 +623,7 @@ private:
_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
order.SetDepotActionType(ODATFB_NEAREST_DEPOT); order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), {}); Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
} }
/** /**
@ -642,11 +643,11 @@ private:
} }
if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_UNLOAD, unload_type);
/* Transfer and unload orders with leave empty as default */ /* Transfer and unload orders with leave empty as default */
if (unload_type == OUFB_TRANSFER || unload_type == OUFB_UNLOAD) { if (unload_type == OUFB_TRANSFER || unload_type == OUFB_UNLOAD) {
Command<CMD_MODIFY_ORDER>::Post(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), {}); Command<CMD_MODIFY_ORDER>::Post(this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, OLFB_NO_LOAD);
this->SetWidgetDirty(WID_O_FULL_LOAD); this->SetWidgetDirty(WID_O_FULL_LOAD);
} }
} }
@ -670,7 +671,7 @@ private:
} }
this->SetWidgetDirty(WID_O_NON_STOP); this->SetWidgetDirty(WID_O_NON_STOP);
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_NON_STOP | non_stop << 4, {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop);
} }
/** /**
@ -684,7 +685,7 @@ private:
if (this->vehicle->GetNumOrders() <= 1) return; if (this->vehicle->GetNumOrders() <= 1) return;
Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER, Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()), {}); this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
} }
/** /**
@ -695,7 +696,7 @@ private:
/* When networking, move one order lower */ /* When networking, move one order lower */
int selected = this->selected_order + (int)_networking; int selected = this->selected_order + (int)_networking;
if (Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), {})) { if (Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel())) {
this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected; this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
this->UpdateButtonState(); this->UpdateButtonState();
} }
@ -720,7 +721,7 @@ private:
/* Get another vehicle that share orders with this vehicle. */ /* Get another vehicle that share orders with this vehicle. */
Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared(); Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
/* Copy the order list of the other vehicle. */ /* Copy the order list of the other vehicle. */
if (Command<CMD_CLONE_ORDER>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST, this->vehicle->tile, this->vehicle->index | CO_COPY << 30, other_shared->index, {})) { if (Command<CMD_CLONE_ORDER>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST, this->vehicle->tile, CO_COPY, this->vehicle->index, other_shared->index)) {
this->UpdateButtonState(); this->UpdateButtonState();
} }
} }
@ -735,10 +736,10 @@ private:
{ {
if (_ctrl_pressed) { if (_ctrl_pressed) {
/* Cancel refitting */ /* Cancel refitting */
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, {}); Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_NO_REFIT);
} else { } else {
if (i == 1) { // Auto-refit to available cargo type. if (i == 1) { // Auto-refit to available cargo type.
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, {}); Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_AUTO_REFIT);
} else { } else {
ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit); ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
} }
@ -1160,7 +1161,7 @@ public:
order.index = 0; order.index = 0;
order.MakeConditional(order_id); order.MakeConditional(order_id);
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), {}); Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
} }
ResetObjectToPlace(); ResetObjectToPlace();
break; break;
@ -1184,8 +1185,8 @@ public:
} else if (sel == this->selected_order) { } else if (sel == this->selected_order) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) { if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
this->vehicle->tile, this->vehicle->index + (sel << 20), this->vehicle->tile, this->vehicle->index, sel,
MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4, {}); MOF_STOP_LOCATION, (this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END);
} }
} else { } else {
/* Select clicked order */ /* Select clicked order */
@ -1332,7 +1333,7 @@ public:
default: default:
break; break;
} }
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (sel << 20), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047));
} }
} }
@ -1370,11 +1371,11 @@ public:
break; break;
case WID_O_COND_VARIABLE: case WID_O_COND_VARIABLE:
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VARIABLE | index << 4, {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_VARIABLE, index);
break; break;
case WID_O_COND_COMPARATOR: case WID_O_COND_COMPARATOR:
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4, {}); Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_COMPARATOR, index);
break; break;
} }
} }
@ -1387,7 +1388,7 @@ public:
VehicleOrderID to_order = this->GetOrderFromPt(pt.y); VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) && if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) &&
Command<CMD_MOVE_ORDER>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), {})) { Command<CMD_MOVE_ORDER>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, from_order, to_order)) {
this->selected_order = -1; this->selected_order = -1;
this->UpdateButtonState(); this->UpdateButtonState();
} }
@ -1439,7 +1440,7 @@ public:
const Order cmd = GetOrderCmdFromTile(this->vehicle, tile); const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
if (cmd.IsType(OT_NOTHING)) return; if (cmd.IsType(OT_NOTHING)) return;
if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), cmd.Pack(), {})) { if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) {
/* With quick goto the Go To button stays active */ /* With quick goto the Go To button stays active */
if (!_settings_client.gui.quick_goto) ResetObjectToPlace(); if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
} }
@ -1457,7 +1458,7 @@ public:
if (this->vehicle->GetNumOrders() != 0 && !share_order) return false; if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
if (Command<CMD_CLONE_ORDER>::Post(share_order ? STR_ERROR_CAN_T_SHARE_ORDER_LIST : STR_ERROR_CAN_T_COPY_ORDER_LIST, if (Command<CMD_CLONE_ORDER>::Post(share_order ? STR_ERROR_CAN_T_SHARE_ORDER_LIST : STR_ERROR_CAN_T_COPY_ORDER_LIST,
this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index, {})) { this->vehicle->tile, share_order ? CO_SHARE : CO_COPY, this->vehicle->index, v->index)) {
this->selected_order = -1; this->selected_order = -1;
ResetObjectToPlace(); ResetObjectToPlace();
} }

View File

@ -140,7 +140,7 @@ enum OrderConditionComparator {
/** /**
* Enumeration for the data to set in #CmdModifyOrder. * Enumeration for the data to set in #CmdModifyOrder.
*/ */
enum ModifyOrderFlags { enum ModifyOrderFlags : byte {
MOF_NON_STOP, ///< Passes an OrderNonStopFlags. MOF_NON_STOP, ///< Passes an OrderNonStopFlags.
MOF_STOP_LOCATION, ///< Passes an OrderStopLocation. MOF_STOP_LOCATION, ///< Passes an OrderStopLocation.
MOF_UNLOAD, ///< Passes an OrderUnloadType. MOF_UNLOAD, ///< Passes an OrderUnloadType.
@ -177,7 +177,7 @@ template <> struct EnumPropsT<ModifyTimetableFlags> : MakeEnumPropsT<ModifyTimet
/** Clone actions. */ /** Clone actions. */
enum CloneOptions { enum CloneOptions : byte {
CO_SHARE = 0, CO_SHARE = 0,
CO_COPY = 1, CO_COPY = 1,
CO_UNSHARE = 2 CO_UNSHARE = 2

View File

@ -380,7 +380,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position)); EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_position, MOF_COND_DESTINATION, jump_to);
} }
/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition) /* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
@ -390,7 +390,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME); EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_pos, MOF_COND_VARIABLE, condition);
} }
/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare) /* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
@ -400,7 +400,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE); EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_pos, MOF_COND_COMPARATOR, compare);
} }
/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value) /* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value)
@ -411,7 +411,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16; if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16;
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_pos, MOF_COND_VALUE, value);
} }
/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location) /* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
@ -424,9 +424,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
uint32 p1 = vehicle_id | (order_pos << 20); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_pos, MOF_STOP_LOCATION, stop_location);
uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4);
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, p1, p2, {});
} }
/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo) /* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
@ -435,9 +433,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT)); EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT));
EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT); EnforcePrecondition(false, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT);
uint32 p1 = vehicle_id; return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, vehicle_id, ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)), refit_cargo);
uint32 p2 = refit_cargo | ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16;
return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, p1, p2, {});
} }
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags) /* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
@ -507,7 +503,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2)); order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {}); return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id, order_pos, order);
} }
/* static */ bool ScriptOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) /* static */ bool ScriptOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
@ -523,7 +519,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.MakeConditional(jump_to); order.MakeConditional(jump_to);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {}); return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id, order_pos, order);
} }
/* static */ bool ScriptOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position) /* static */ bool ScriptOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position)
@ -533,7 +529,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
return ScriptObject::Command<CMD_DELETE_ORDER>::Do(0, vehicle_id, order_pos, {}); return ScriptObject::Command<CMD_DELETE_ORDER>::Do(0, vehicle_id, order_pos);
} }
/* static */ bool ScriptOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order) /* static */ bool ScriptOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order)
@ -543,7 +539,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order); int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order);
return ScriptObject::Command<CMD_SKIP_TO_ORDER>::Do(0, vehicle_id, order_pos, {}); return ScriptObject::Command<CMD_SKIP_TO_ORDER>::Do(0, vehicle_id, order_pos);
} }
/** /**
@ -587,7 +583,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, (order_flags & OF_GOTO_NEAREST_DEPOT) == (current & OF_GOTO_NEAREST_DEPOT)); EnforcePrecondition(false, (order_flags & OF_GOTO_NEAREST_DEPOT) == (current & OF_GOTO_NEAREST_DEPOT));
if ((current & OF_NON_STOP_FLAGS) != (order_flags & OF_NON_STOP_FLAGS)) { if ((current & OF_NON_STOP_FLAGS) != (order_flags & OF_NON_STOP_FLAGS)) {
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_NON_STOP, order_flags & OF_NON_STOP_FLAGS);
} }
switch (order->GetType()) { switch (order->GetType()) {
@ -596,16 +592,16 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
uint data = DA_ALWAYS_GO; uint data = DA_ALWAYS_GO;
if (order_flags & OF_SERVICE_IF_NEEDED) data = DA_SERVICE; if (order_flags & OF_SERVICE_IF_NEEDED) data = DA_SERVICE;
if (order_flags & OF_STOP_IN_DEPOT) data = DA_STOP; if (order_flags & OF_STOP_IN_DEPOT) data = DA_STOP;
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_DEPOT_ACTION, data);
} }
break; break;
case OT_GOTO_STATION: case OT_GOTO_STATION:
if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) { if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) {
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_UNLOAD, (order_flags & OF_UNLOAD_FLAGS) >> 2);
} }
if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) { if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) {
return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, {}); return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, vehicle_id, order_pos, MOF_LOAD, (order_flags & OF_LOAD_FLAGS) >> 5);
} }
break; break;
@ -639,7 +635,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move); int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move);
int order_pos_target = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_target); int order_pos_target = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_target);
return ScriptObject::Command<CMD_MOVE_ORDER>::Do(0, vehicle_id, order_pos_move | (order_pos_target << 16), {}); return ScriptObject::Command<CMD_MOVE_ORDER>::Do(0, vehicle_id, order_pos_move, order_pos_target);
} }
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) /* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@ -647,7 +643,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_COPY << 30, main_vehicle_id, {}); return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_COPY, vehicle_id, main_vehicle_id);
} }
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id) /* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@ -655,14 +651,14 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, {}); return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_SHARE, vehicle_id, main_vehicle_id);
} }
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id) /* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
{ {
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id)); EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_UNSHARE << 30, 0, {}); return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, CO_UNSHARE, vehicle_id, 0);
} }
/* static */ uint ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile) /* static */ uint ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile)

View File

@ -970,7 +970,7 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
* the vehicle refitted before doing this, otherwise the moved * the vehicle refitted before doing this, otherwise the moved
* cargo types might not match (passenger vs non-passenger) * cargo types might not match (passenger vs non-passenger)
*/ */
CommandCost result = Command<CMD_CLONE_ORDER>::Do(flags, 0, w_front->index | (p2 & 1 ? CO_SHARE : CO_COPY) << 30, v_front->index, {}); CommandCost result = Command<CMD_CLONE_ORDER>::Do(flags, (p2 & 1 ? CO_SHARE : CO_COPY), w_front->index, v_front->index);
if (result.Failed()) { if (result.Failed()) {
/* The vehicle has already been bought, so now it must be sold again. */ /* The vehicle has already been bought, so now it must be sold again. */
Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index, true, false, INVALID_CLIENT_ID); Command<CMD_SELL_VEHICLE>::Do(flags, w_front->tile, w_front->index, true, false, INVALID_CLIENT_ID);

View File

@ -1040,7 +1040,7 @@ struct RefitWindow : public Window {
bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX; bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
if (Command<CMD_REFIT_VEHICLE>::Post(GetCmdRefitVehMsg(v), v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16, {}) && delete_window) this->Close(); if (Command<CMD_REFIT_VEHICLE>::Post(GetCmdRefitVehMsg(v), v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16, {}) && delete_window) this->Close();
} else { } else {
if (Command<CMD_ORDER_REFIT>::Post(v->tile, v->index, this->cargo->cargo | this->order << 16, {})) this->Close(); if (Command<CMD_ORDER_REFIT>::Post(v->tile, v->index, this->order, this->cargo->cargo)) this->Close();
} }
} }
break; break;