summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_object.hpp20
-rw-r--r--src/script/api/script_vehicle.cpp8
2 files changed, 22 insertions, 6 deletions
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp
index 26da500c4..8d9be14c4 100644
--- a/src/script/api/script_object.hpp
+++ b/src/script/api/script_object.hpp
@@ -347,6 +347,22 @@ namespace ScriptObjectInternal {
{
((SanitizeSingleStringHelper(std::get<Tindices>(values))), ...);
}
+
+ /** Helper to process a single ClientID argument. */
+ template <class T>
+ static inline void SetClientIdHelper(T &data)
+ {
+ if constexpr (std::is_same_v<ClientID, T>) {
+ if (data == INVALID_CLIENT_ID) data = (ClientID)UINT32_MAX;
+ }
+ }
+
+ /** Set all invalid ClientID's to the proper value. */
+ template<class Ttuple, size_t... Tindices>
+ static inline void SetClientIds(Ttuple &values, std::index_sequence<Tindices...>)
+ {
+ ((SetClientIdHelper(std::get<Tindices>(values))), ...);
+ }
}
template <Commands Tcmd, typename... Targs>
@@ -364,8 +380,8 @@ bool ScriptObject::ScriptDoCommandHelper<Tcmd, CommandCost(*)(DoCommandFlag, Tar
tile = std::get<0>(args);
}
- /* Only set p2 when the command does not come from the network. */
- if ((::GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) != 0 && std::get<2>(args) == 0) std::get<2>(args) = UINT32_MAX;
+ /* Only set ClientID parameters when the command does not come from the network. */
+ if constexpr ((::GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) != 0) ScriptObjectInternal::SetClientIds(args, std::index_sequence_for<Targs...>{});
/* Store the command for command callback validation. */
if (!estimate_only && networking) ScriptObject::SetLastCommand(tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), Tcmd);
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index d245f4132..3da5739ee 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -72,7 +72,7 @@
EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED);
- if (!ScriptObject::Command<CMD_BUILD_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, engine_id | (cargo << 24), 0, {})) return VEHICLE_INVALID;
+ if (!ScriptObject::Command<CMD_BUILD_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, engine_id, true, cargo, INVALID_CLIENT_ID)) return VEHICLE_INVALID;
/* In case of test-mode, we return VehicleID 0 */
return 0;
@@ -94,7 +94,7 @@
if (!ScriptEngine::IsBuildable(engine_id)) return -1;
if (!ScriptCargo::IsValidCargo(cargo)) return -1;
- CommandCost res = ::Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, depot, engine_id | (cargo << 24), 0, {});
+ CommandCost res = ::Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, depot, engine_id, true, cargo, INVALID_CLIENT_ID);
return res.Succeeded() ? _returned_refit_capacity : -1;
}
@@ -162,7 +162,7 @@
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
const Vehicle *v = ::Vehicle::Get(vehicle_id);
- return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, vehicle_id | (v->type == VEH_TRAIN ? 1 : 0) << 20, 0, {});
+ return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, vehicle_id, v->type == VEH_TRAIN, false, INVALID_CLIENT_ID);
}
/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
@@ -174,7 +174,7 @@
const Train *v = ::Train::Get(vehicle_id);
while (wagon-- > 0) v = v->GetNextUnit();
- return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, v->index | (sell_attached_wagons ? 1 : 0) << 20, 0, {});
+ return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, v->index, sell_attached_wagons, false, INVALID_CLIENT_ID);
}
/* static */ bool ScriptVehicle::SellWagon(VehicleID vehicle_id, int wagon)