summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-11-02 22:58:40 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit211c630cbe4185a2adf8b8cd8f52ca58f8bf17ed (patch)
tree89290b522a2852d71e9a71c43b6d581fb8d1d36d /src
parentde45a8729c0f1ab965e4adf4e6ad7095a4a678c8 (diff)
downloadopenttd-211c630cbe4185a2adf8b8cd8f52ca58f8bf17ed.tar.xz
Codechange: Un-bitstuff order commands.
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_cmd.cpp2
-rw-r--r--src/order_backup.cpp2
-rw-r--r--src/order_base.h9
-rw-r--r--src/order_cmd.cpp108
-rw-r--r--src/order_cmd.h27
-rw-r--r--src/order_gui.cpp41
-rw-r--r--src/order_type.h4
-rw-r--r--src/script/api/script_order.cpp40
-rw-r--r--src/vehicle_cmd.cpp2
-rw-r--r--src/vehicle_gui.cpp2
10 files changed, 106 insertions, 131 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 6a8937cb6..cda42643b 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -402,7 +402,7 @@ static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head,
CommandCost cost = CommandCost();
/* 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 */
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, {}));
diff --git a/src/order_backup.cpp b/src/order_backup.cpp
index 69ae6507d..1818029f2 100644
--- a/src/order_backup.cpp
+++ b/src/order_backup.cpp
@@ -75,7 +75,7 @@ void OrderBackup::DoRestore(Vehicle *v)
{
/* If we had shared orders, recover that */
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()) {
v->orders.list = new OrderList(this->orders, v);
this->orders = nullptr;
diff --git a/src/order_base.h b/src/order_base.h
index a722ef5d4..836ceb4b0 100644
--- a/src/order_base.h
+++ b/src/order_base.h
@@ -25,6 +25,9 @@ typedef Pool<OrderList, OrderListID, 128, 64000> OrderListPool;
extern OrderPool _order_pool;
extern OrderListPool _orderlist_pool;
+template <typename, typename>
+class EndianBufferWriter;
+
/* If you change this, keep in mind that it is saved on 3 places:
* - Load_ORDR, all the global orders
* - Vehicle -> current_order
@@ -38,6 +41,10 @@ private:
friend class SlVehicleCommon;
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 flags; ///< Load/unload types, depot order/action types.
DestinationID dest; ///< The destination of the order.
@@ -51,7 +58,7 @@ private:
public:
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(uint32 packed);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 45a0db99f..66e79989a 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -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.
* @param flags operation to perform
- * @param tile unused
* @param p1 various bitstuffed elements
- * - p1 = (bit 0 - 19) - ID of the vehicle
- * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
+ * @param veh ID of the vehicle
+ * @param sel_ord the selected order (if any). If the last order is given,
* the order will be inserted before that one
* the maximum vehicle order id is 254.
- * @param p2 packed order to insert
- * @param text unused
+ * @param new_order order to insert
* @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);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
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),
* and has the correct flags if any */
switch (new_order.GetType()) {
@@ -1008,17 +1005,12 @@ static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
/**
* Delete an order from the orderlist of a vehicle.
* @param flags operation to perform
- * @param tile unused
- * @param p1 the ID of the vehicle
- * @param p2 the order to delete (max 255)
- * @param text unused
+ * @param veh_id the ID of the vehicle
+ * @param sel_ord the order to delete (max 255)
* @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);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
@@ -1113,17 +1105,12 @@ void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
/**
* Goto order of order-list.
* @param flags operation to perform
- * @param tile unused
- * @param p1 The ID of the vehicle which order is skipped
- * @param p2 the selected order to which we want to skip
- * @param text unused
+ * @param veh_id The ID of the vehicle which order is skipped
+ * @param sel_ord the selected order to which we want to skip
* @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);
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
* @param flags operation to perform
- * @param tile unused
- * @param p1 the ID of the vehicle
- * @param p2 order to move and target
- * bit 0-15 : the order to move
- * bit 16-31 : the target order
- * @param text unused
+ * @param veh the ID of the vehicle
+ * @param moving_order the order to move
+ * @param target_order the target order
* @return the cost of this operation or an error
* @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
*/
-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);
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.
* @param flags operation to perform
- * @param tile unused
- * @param p1 various bitstuffed elements
- * - p1 = (bit 0 - 19) - ID of the vehicle
- * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
- * the order will be inserted before that one
- * the maximum vehicle order id is 254.
- * @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
+ * @param veh ID of the vehicle
+ * @param sel_ord the selected order (if any). If the last order is given,
+ * the order will be inserted before that one
+ * the maximum vehicle order id is 254.
+ * @param mof what data to modify (@see ModifyOrderFlags)
+ * @param data the data to modify
* @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;
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.
* @param flags operation to perform
- * @param tile unused
- * @param p1 various bitstuffed elements
- * - p1 = (bit 0-19) - destination vehicle to clone orders to
- * - p1 = (bit 30-31) - action to perform
- * @param p2 source vehicle to clone orders from, if any (none for CO_UNSHARE)
- * @param text unused
+ * @param action action to perform
+ * @param veh_dst destination vehicle to clone orders to
+ * @param veh_src source vehicle to clone orders from, if any (none for CO_UNSHARE)
* @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);
if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(dst->owner);
if (ret.Failed()) return ret;
- switch (GB(p1, 30, 2)) {
+ switch (action) {
case CO_SHARE: {
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
* @param flags operation to perform
- * @param tile Not used
- * @param p1 VehicleIndex of the vehicle having the order
- * @param p2 bitmask
- * - bit 0-7 CargoID
- * - bit 16-23 number of order to modify
- * @param text unused
+ * @param veh VehicleIndex of the vehicle having the order
+ * @param order_number number of order to modify
+ * @param cargo CargoID
* @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;
const Vehicle *v = Vehicle::GetIfValid(veh);
diff --git a/src/order_cmd.h b/src/order_cmd.h
index fa3424ce4..aeb42b624 100644
--- a/src/order_cmd.h
+++ b/src/order_cmd.h
@@ -11,14 +11,16 @@
#define ORDER_CMD_H
#include "command_type.h"
+#include "order_base.h"
+#include "misc/endian_buffer.hpp"
-CommandProc CmdModifyOrder;
-CommandProc CmdSkipToOrder;
-CommandProc CmdDeleteOrder;
-CommandProc CmdInsertOrder;
-CommandProc CmdOrderRefit;
-CommandProc CmdCloneOrder;
-CommandProc CmdMoveOrder;
+CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16 data);
+CommandCost CmdSkipToOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord);
+CommandCost CmdDeleteOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID sel_ord);
+CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID sel_ord, const Order &new_order);
+CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo);
+CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src);
+CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order);
CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID user_id);
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_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 */
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 50413c735..982c8f7b2 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -30,6 +30,7 @@
#include "engine_func.h"
#include "vehicle_func.h"
#include "order_cmd.h"
+#include "company_cmd.h"
#include "widgets/order_widget.h"
@@ -592,7 +593,7 @@ private:
}
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;
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);
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
- 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 */
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);
}
}
@@ -670,7 +671,7 @@ private:
}
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;
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 */
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->UpdateButtonState();
}
@@ -720,7 +721,7 @@ private:
/* Get another vehicle that share orders with this vehicle. */
Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
/* 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();
}
}
@@ -735,10 +736,10 @@ private:
{
if (_ctrl_pressed) {
/* 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 {
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 {
ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
}
@@ -1160,7 +1161,7 @@ public:
order.index = 0;
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();
break;
@@ -1184,8 +1185,8 @@ public:
} else if (sel == this->selected_order) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
- this->vehicle->tile, this->vehicle->index + (sel << 20),
- MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4, {});
+ this->vehicle->tile, this->vehicle->index, sel,
+ MOF_STOP_LOCATION, (this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END);
}
} else {
/* Select clicked order */
@@ -1332,7 +1333,7 @@ public:
default:
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;
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;
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;
}
}
@@ -1387,7 +1388,7 @@ public:
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()) &&
- 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->UpdateButtonState();
}
@@ -1439,7 +1440,7 @@ public:
const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
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 */
if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
}
@@ -1457,7 +1458,7 @@ public:
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,
- 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;
ResetObjectToPlace();
}
diff --git a/src/order_type.h b/src/order_type.h
index 9f4d0ba22..674352907 100644
--- a/src/order_type.h
+++ b/src/order_type.h
@@ -140,7 +140,7 @@ enum OrderConditionComparator {
/**
* Enumeration for the data to set in #CmdModifyOrder.
*/
-enum ModifyOrderFlags {
+enum ModifyOrderFlags : byte {
MOF_NON_STOP, ///< Passes an OrderNonStopFlags.
MOF_STOP_LOCATION, ///< Passes an OrderStopLocation.
MOF_UNLOAD, ///< Passes an OrderUnloadType.
@@ -177,7 +177,7 @@ template <> struct EnumPropsT<ModifyTimetableFlags> : MakeEnumPropsT<ModifyTimet
/** Clone actions. */
-enum CloneOptions {
+enum CloneOptions : byte {
CO_SHARE = 0,
CO_COPY = 1,
CO_UNSHARE = 2
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp
index 8faec672f..e2ee1e608 100644
--- a/src/script/api/script_order.cpp
+++ b/src/script/api/script_order.cpp
@@ -380,7 +380,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
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)
@@ -390,7 +390,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME);
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)
@@ -400,7 +400,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
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)
@@ -411,7 +411,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16;
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)
@@ -424,9 +424,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- uint32 p1 = vehicle_id | (order_pos << 20);
- uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4);
- return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, p1, p2, {});
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id, order_pos, MOF_STOP_LOCATION, stop_location);
}
/* 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, ScriptCargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT);
- uint32 p1 = vehicle_id;
- uint32 p2 = refit_cargo | ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16;
- return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, p1, p2, {});
+ return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, vehicle_id, ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)), refit_cargo);
}
/* 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));
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)
@@ -523,7 +519,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.MakeConditional(jump_to);
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)
@@ -533,7 +529,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(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)
@@ -543,7 +539,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(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));
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()) {
@@ -596,16 +592,16 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
uint data = DA_ALWAYS_GO;
if (order_flags & OF_SERVICE_IF_NEEDED) data = DA_SERVICE;
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;
case OT_GOTO_STATION:
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)) {
- 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;
@@ -639,7 +635,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move);
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)
@@ -647,7 +643,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(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)
@@ -655,14 +651,14 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(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)
{
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)
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index f25a3cdd3..3f4bd2a5a 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -970,7 +970,7 @@ CommandCost CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint
* the vehicle refitted before doing this, otherwise the moved
* 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()) {
/* 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);
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 80b75e7ce..2b7446a5e 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1040,7 +1040,7 @@ struct RefitWindow : public Window {
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();
} 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;