summaryrefslogtreecommitdiff
path: root/src/script/api/script_order.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-11-01 21:30:34 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit6691ee3b963ee3282490360bb3cc1ea09d0c58ea (patch)
tree398b1139844d2566831e249836b6923bd88b6124 /src/script/api/script_order.cpp
parenteab18f06a47e558fe313cb86c855e8949b01feed (diff)
downloadopenttd-6691ee3b963ee3282490360bb3cc1ea09d0c58ea.tar.xz
Codechange: Template script command calls.
Diffstat (limited to 'src/script/api/script_order.cpp')
-rw-r--r--src/script/api/script_order.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp
index ce0ee76de..8faec672f 100644
--- a/src/script/api/script_order.cpp
+++ b/src/script/api/script_order.cpp
@@ -18,6 +18,7 @@
#include "../../depot_base.h"
#include "../../station_base.h"
#include "../../waypoint_base.h"
+#include "../../order_cmd.h"
#include "../../safeguards.h"
@@ -379,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::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
@@ -389,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::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
@@ -399,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::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value)
@@ -410,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::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), {});
}
/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
@@ -425,7 +426,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
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::DoCommand(0, p1, p2, CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, p1, p2, {});
}
/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
@@ -436,7 +437,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
uint32 p1 = vehicle_id;
uint32 p2 = refit_cargo | ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16;
- return ScriptObject::DoCommand(0, p1, p2, CMD_ORDER_REFIT);
+ return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, p1, p2, {});
}
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
@@ -506,7 +507,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::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER);
+ return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {});
}
/* static */ bool ScriptOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
@@ -522,7 +523,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.MakeConditional(jump_to);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER);
+ return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {});
}
/* static */ bool ScriptOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position)
@@ -532,7 +533,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::DoCommand(0, vehicle_id, order_pos, CMD_DELETE_ORDER);
+ return ScriptObject::Command<CMD_DELETE_ORDER>::Do(0, vehicle_id, order_pos, {});
}
/* static */ bool ScriptOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order)
@@ -542,7 +543,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::DoCommand(0, vehicle_id, order_pos, CMD_SKIP_TO_ORDER);
+ return ScriptObject::Command<CMD_SKIP_TO_ORDER>::Do(0, vehicle_id, order_pos, {});
}
/**
@@ -586,7 +587,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::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, {});
}
switch (order->GetType()) {
@@ -595,16 +596,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::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, {});
}
break;
case OT_GOTO_STATION:
if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) {
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, {});
}
if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) {
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, {});
}
break;
@@ -638,7 +639,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::DoCommand(0, vehicle_id, order_pos_move | (order_pos_target << 16), CMD_MOVE_ORDER);
+ return ScriptObject::Command<CMD_MOVE_ORDER>::Do(0, vehicle_id, order_pos_move | (order_pos_target << 16), {});
}
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@@ -646,7 +647,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_COPY << 30, main_vehicle_id, {});
}
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@@ -654,14 +655,14 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, {});
}
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
{
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_UNSHARE << 30, 0, {});
}
/* static */ uint ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile)