From fa6da1ae7cb09c53c5ea6383322accd3c5f90e45 Mon Sep 17 00:00:00 2001 From: Serg Vergun <1197314+severgun@users.noreply.github.com> Date: Tue, 27 Jul 2021 20:47:07 +0300 Subject: [PATCH] Vehicles - Add configurable engine startup delay (#8327) * Add configurable engine startup delay * add suggested change Add space char Co-authored-by: Dystopian * Squashed commit of the following: commit 14f5483d8fa49d36effa8b18a3df392ed39b19da Author: Serg Vergun <1197314+severgun@users.noreply.github.com> Date: Fri Jul 23 20:23:52 2021 +0300 Add 0 cap and update docs commit e3ce7f273882b3f4e2cba916c39b506f857b20db Author: severgun Date: Fri Jul 23 12:42:42 2021 +0300 add parentheses commit b36eedc61b5e6bb868c37901bd4191767fbdaff8 Author: severgun Date: Fri Jul 23 12:34:30 2021 +0300 Add ability to set engine startup delay per vehicle by script * Change function name * add suggested exitWith condition Co-authored-by: PabstMirror * Update docs/wiki/framework/vehicles-framework.md Co-authored-by: PabstMirror Co-authored-by: Dystopian Co-authored-by: PabstMirror --- addons/vehicles/CfgVehicles.hpp | 4 +- addons/vehicles/XEH_PREP.hpp | 1 + .../functions/fnc_setVehicleStartDelay.sqf | 23 ++++++++ addons/vehicles/functions/fnc_startEngine.sqf | 5 +- addons/vehicles/script_component.hpp | 1 - docs/wiki/framework/vehicles-framework.md | 55 +++++++++++++++++++ 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 addons/vehicles/functions/fnc_setVehicleStartDelay.sqf create mode 100644 docs/wiki/framework/vehicles-framework.md diff --git a/addons/vehicles/CfgVehicles.hpp b/addons/vehicles/CfgVehicles.hpp index ff79ed26f4..995c9e577f 100644 --- a/addons/vehicles/CfgVehicles.hpp +++ b/addons/vehicles/CfgVehicles.hpp @@ -16,7 +16,9 @@ class CfgVehicles { class CommanderOptics;//: NewTurret {}; }; - class Car: LandVehicle {}; + class Car: LandVehicle { + GVAR(engineStartDelay) = 1.3; + }; class Tank: LandVehicle { class Turrets { diff --git a/addons/vehicles/XEH_PREP.hpp b/addons/vehicles/XEH_PREP.hpp index ec2e27a94e..1e505f6e3e 100644 --- a/addons/vehicles/XEH_PREP.hpp +++ b/addons/vehicles/XEH_PREP.hpp @@ -1,3 +1,4 @@ PREP(speedLimiter); PREP(startEngine); +PREP(setVehicleStartDelay); \ No newline at end of file diff --git a/addons/vehicles/functions/fnc_setVehicleStartDelay.sqf b/addons/vehicles/functions/fnc_setVehicleStartDelay.sqf new file mode 100644 index 0000000000..337a1d961b --- /dev/null +++ b/addons/vehicles/functions/fnc_setVehicleStartDelay.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: severgun + * Set engine startup delay to specific vehicle. + * + * Arguments: + * 0: Vehicle + * 1: Delay (seconds) + * + * Return Value: + * None + * + * Example: + * [hemmt, 3.2] call ace_vehicles_fnc_setVehicleStartDelay + * + * Public: Yes + */ + +params [["_veh", objNull, [objNull]], ["_delay", 0, [99]]]; + +if (isNull _veh || {!(_veh isKindOf "AllVehicles")}) exitWith {}; + +_veh setVariable [QGVAR(engineStartDelay), _delay max 0, true]; \ No newline at end of file diff --git a/addons/vehicles/functions/fnc_startEngine.sqf b/addons/vehicles/functions/fnc_startEngine.sqf index 4277f518e1..4a4633b080 100644 --- a/addons/vehicles/functions/fnc_startEngine.sqf +++ b/addons/vehicles/functions/fnc_startEngine.sqf @@ -20,6 +20,9 @@ params ["_vehicle", "_isEngineOn"]; if (!_isEngineOn || {floor abs speed _vehicle > 0 || {!isNull isVehicleCargo _vehicle}}) exitWith {}; +private _startupDelay = _vehicle getVariable [QGVAR(engineStartDelay), getNumber (configOf _vehicle >> QGVAR(engineStartDelay))]; +if (_startupDelay <= 0) exitWith {}; + [{ params ["_args", "_idPFH"]; _args params ["_vehicle", "_time", "_direction"]; @@ -29,4 +32,4 @@ if (!_isEngineOn || {floor abs speed _vehicle > 0 || {!isNull isVehicleCargo _ve _vehicle setVelocity [0, 0, 0]; _vehicle setVectorDirAndUp _direction; -} , 0, [_vehicle, CBA_missionTime + STARTUP_DELAY, [vectorDir _vehicle, vectorUp _vehicle]]] call CBA_fnc_addPerFrameHandler; +} , 0, [_vehicle, CBA_missionTime + _startupDelay, [vectorDir _vehicle, vectorUp _vehicle]]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/vehicles/script_component.hpp b/addons/vehicles/script_component.hpp index b985da6632..ae4eec2fd0 100644 --- a/addons/vehicles/script_component.hpp +++ b/addons/vehicles/script_component.hpp @@ -20,4 +20,3 @@ #define MOUSE_SCROLL_DOWN 0xF9 #define FUEL_FACTOR 0.165 // fuel capacity = range in km * FUEL_FACTOR -#define STARTUP_DELAY 1.3 diff --git a/docs/wiki/framework/vehicles-framework.md b/docs/wiki/framework/vehicles-framework.md new file mode 100644 index 0000000000..a1f66e807a --- /dev/null +++ b/docs/wiki/framework/vehicles-framework.md @@ -0,0 +1,55 @@ +--- +layout: wiki +title: Vehicles Framework +description: Explains how to set-up vehicles startup delay. +group: framework +order: 5 +parent: wiki +mod: ace +version: + major: 3 + minor: 14 + patch: 0 +--- + +## 1. Engine startup delay + +The engine has to be started before the vehicle can move. Delay can be configured per class via config or per vehicle via script. +By default starting the engine takes aprox. 1 to 2 seconds. + +### 1.1 Setting the startup delay by config + +```cpp +class CfgVehicles { + class MyFuelTruck { + ace_vehicles_engineStartDelay = 3; // Startup delay in seconds + }; + class MyCar { + ace_vehicles_engineStartDelay = 2.2; + }; + class MyElectricCar { + ace_vehicles_engineStartDelay = 0.1; + }; +}; +``` + +### 1.2 Setting the startup delay by script + +`ace_vehicles_fnc_setVehicleStartDelay` +Has global effects. + + | Arguments | Type | Optional (default value) +---| --------- | ---- | ------------------------ +0 | Vehicle | Object | Required +1 | Delay (in seconds) | Number | Required +**R** | None | None | Return value + + +#### 1.2.1 Example + +`[myCar, 2.2] call ace_vehicles_fnc_setVehicleStartDelay;` + + | Arguments | Explanation +---| --------- | ----------- +0 | `myCar` | My car object +1 | `2.2` | New startup delay