diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-11-30 23:21:16 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | 41fa16f3254ffa9f44b85d6570a2293e8438b427 (patch) | |
tree | a508634b7dea7a0937e92c143db0a392cd99a4b0 /src/script/api | |
parent | 57b82e2e99aa30a649d1fd80f192ccf5338dc7c4 (diff) | |
download | openttd-41fa16f3254ffa9f44b85d6570a2293e8438b427.tar.xz |
Codechange: Don't use globals for return values from vehicle command procs.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/script_object.cpp | 12 | ||||
-rw-r--r-- | src/script/api/script_object.hpp | 11 | ||||
-rw-r--r-- | src/script/api/script_vehicle.cpp | 8 |
3 files changed, 4 insertions, 27 deletions
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index f95433bd9..3cddb12f8 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -159,8 +159,6 @@ ScriptObject::ActiveInstance::~ActiveInstance() /* static */ void ScriptObject::SetLastCommandRes(bool res) { GetStorage()->last_command_res = res; - /* Also store the results of various global variables */ - SetNewVehicleID(_new_vehicle_id); } /* static */ bool ScriptObject::GetLastCommandRes() @@ -178,16 +176,6 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->last_cmd_ret; } -/* static */ void ScriptObject::SetNewVehicleID(VehicleID vehicle_id) -{ - GetStorage()->new_vehicle_id = vehicle_id; -} - -/* static */ VehicleID ScriptObject::GetNewVehicleID() -{ - return GetStorage()->new_vehicle_id; -} - /* static */ void ScriptObject::SetAllowDoCommand(bool allow) { GetStorage()->allow_do_command = allow; diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index d90fec351..5fffe783b 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -193,11 +193,6 @@ protected: static const CommandDataBuffer &GetLastCommandResData(); /** - * Get the latest stored new_vehicle_id. - */ - static VehicleID GetNewVehicleID(); - - /** * Store a allow_do_command per company. * @param allow The new allow. */ @@ -274,12 +269,6 @@ protected: static char *GetString(StringID string); private: - /** - * Store a new_vehicle_id per company. - * @param vehicle_id The new VehicleID. - */ - static void SetNewVehicleID(VehicleID vehicle_id); - /* Helper functions for DoCommand. */ static std::tuple<bool, bool, bool> DoCommandPrep(); static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only); diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index c92502661..b7b5fd950 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -94,8 +94,8 @@ 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, true, cargo, INVALID_CLIENT_ID); - return res.Succeeded() ? _returned_refit_capacity : -1; + auto [res, veh_id, refit_capacity, refit_mail] = ::Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, depot, engine_id, true, cargo, INVALID_CLIENT_ID); + return res.Succeeded() ? refit_capacity : -1; } /* static */ VehicleID ScriptVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders) @@ -143,8 +143,8 @@ if (!IsValidVehicle(vehicle_id)) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; - CommandCost res = ::Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, vehicle_id, cargo, 0, false, false, 0); - return res.Succeeded() ? _returned_refit_capacity : -1; + auto [res, refit_capacity, refit_mail] = ::Command<CMD_REFIT_VEHICLE>::Do(DC_QUERY_COST, vehicle_id, cargo, 0, false, false, 0); + return res.Succeeded() ? refit_capacity : -1; } /* static */ bool ScriptVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo) |