mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Vehicles - Add Resume/Set functionality to speed control (#8967)
* Add Resume/Set functionality to speed control * Apply suggestions from code review Co-authored-by: BrettMayson <brett@mayson.io> --------- Co-authored-by: BrettMayson <brett@mayson.io>
This commit is contained in:
parent
8b94d765aa
commit
22b93e2d03
@ -2,3 +2,4 @@ PREP(autoThrottle);
|
|||||||
PREP(speedLimiter);
|
PREP(speedLimiter);
|
||||||
PREP(startEngine);
|
PREP(startEngine);
|
||||||
PREP(setVehicleStartDelay);
|
PREP(setVehicleStartDelay);
|
||||||
|
PREP(toggleSpeedControl);
|
||||||
|
@ -3,65 +3,15 @@
|
|||||||
|
|
||||||
if (!hasInterface) exitWith {};
|
if (!hasInterface) exitWith {};
|
||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
// Add keybinds
|
|
||||||
["ACE3 Vehicles", QGVAR(speedLimiter), localize LSTRING(SpeedLimiter),
|
|
||||||
{
|
|
||||||
private _connectedUAV = getConnectedUAV ACE_player;
|
|
||||||
private _uavControl = UAVControl _connectedUAV;
|
|
||||||
if ((_uavControl select 1) == "DRIVER") then {
|
|
||||||
if !(_connectedUAV isKindOf "UGV_01_base_F") exitWith {false};
|
|
||||||
GVAR(isUAV) = true;
|
|
||||||
[_uavControl select 0, _connectedUAV] call FUNC(speedLimiter);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
// Conditions: canInteract
|
|
||||||
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
|
|
||||||
// Conditions: specific
|
|
||||||
private _vehicle = vehicle ACE_player;
|
|
||||||
if (
|
|
||||||
ACE_player != driver _vehicle
|
|
||||||
|| {-1 == ["Car", "Tank", "Ship"] findIf {_vehicle isKindOf _x}}
|
|
||||||
) exitWith {false};
|
|
||||||
|
|
||||||
GVAR(isUAV) = false;
|
// Add keybinds
|
||||||
// Statement
|
["ACE3 Vehicles", QGVAR(speedLimiter), localize LSTRING(SpeedLimiter), {
|
||||||
[ACE_player, _vehicle] call FUNC(speedLimiter);
|
false call FUNC(toggleSpeedControl)
|
||||||
true
|
}, {false}, [DIK_DELETE, [false, false, false]], false] call CBA_fnc_addKeybind;
|
||||||
};
|
|
||||||
},
|
|
||||||
{false},
|
|
||||||
[DIK_DELETE, [false, false, false]], false] call CBA_fnc_addKeybind;
|
|
||||||
|
|
||||||
["ACE3 Vehicles", QGVAR(cruiseControl), localize LSTRING(CruiseControl), {
|
["ACE3 Vehicles", QGVAR(cruiseControl), localize LSTRING(CruiseControl), {
|
||||||
private _connectedUAV = getConnectedUAV ACE_player;
|
true call FUNC(toggleSpeedControl)
|
||||||
private _uavControl = UAVControl _connectedUAV;
|
}, {false}, [DIK_INSERT, [false, false, false]], false] call CBA_fnc_addKeybind;
|
||||||
if ((_uavControl select 1) == "DRIVER") then {
|
|
||||||
if !(_connectedUAV isKindOf "UGV_01_base_F") exitWith {false};
|
|
||||||
GVAR(isUAV) = true;
|
|
||||||
[_uavControl select 0, _connectedUAV, true] call FUNC(speedLimiter);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
// Conditions: canInteract
|
|
||||||
if !([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)) exitWith {false};
|
|
||||||
// Conditions: specific
|
|
||||||
private _vehicle = vehicle ACE_player;
|
|
||||||
if (
|
|
||||||
ACE_player != driver _vehicle
|
|
||||||
|| {-1 == ["Car", "Tank", "Ship", "Plane"] findIf {_vehicle isKindOf _x}}
|
|
||||||
) exitWith {false};
|
|
||||||
|
|
||||||
GVAR(isUAV) = false;
|
|
||||||
// Statement
|
|
||||||
if (_vehicle isKindOf "Plane") then {
|
|
||||||
[ACE_player, _vehicle] call FUNC(autoThrottle);
|
|
||||||
} else {
|
|
||||||
[ACE_player, _vehicle, true] call FUNC(speedLimiter);
|
|
||||||
};
|
|
||||||
true
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{false},
|
|
||||||
[DIK_INSERT, [false, false, false]], false] call CBA_fnc_addKeybind;
|
|
||||||
|
|
||||||
["ACE3 Vehicles", QGVAR(scrollUp), localize LSTRING(IncreaseSpeedLimit), {
|
["ACE3 Vehicles", QGVAR(scrollUp), localize LSTRING(IncreaseSpeedLimit), {
|
||||||
if (GVAR(isSpeedLimiter)) then {
|
if (GVAR(isSpeedLimiter)) then {
|
||||||
@ -69,6 +19,9 @@ GVAR(isSpeedLimiter) = false;
|
|||||||
GVAR(speedLimit) = 5 max GVAR(speedLimiterStep) * floor (GVAR(speedLimit) / GVAR(speedLimiterStep));
|
GVAR(speedLimit) = 5 max GVAR(speedLimiterStep) * floor (GVAR(speedLimit) / GVAR(speedLimiterStep));
|
||||||
[["%1: %2", LSTRING(SpeedLimit), GVAR(speedLimit)]] call EFUNC(common,displayTextStructured);
|
[["%1: %2", LSTRING(SpeedLimit), GVAR(speedLimit)]] call EFUNC(common,displayTextStructured);
|
||||||
true
|
true
|
||||||
|
} else {
|
||||||
|
!isNil QGVAR(speedLimit)
|
||||||
|
&& {[GVAR(isCruiseControl), true] call FUNC(toggleSpeedControl)} // RESUME
|
||||||
};
|
};
|
||||||
}, {false}, [MOUSE_SCROLL_UP, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + Mouse Wheel Scroll Up
|
}, {false}, [MOUSE_SCROLL_UP, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + Mouse Wheel Scroll Up
|
||||||
|
|
||||||
@ -78,5 +31,8 @@ GVAR(isSpeedLimiter) = false;
|
|||||||
GVAR(speedLimit) = 5 max GVAR(speedLimiterStep) * ceil (GVAR(speedLimit) / GVAR(speedLimiterStep));
|
GVAR(speedLimit) = 5 max GVAR(speedLimiterStep) * ceil (GVAR(speedLimit) / GVAR(speedLimiterStep));
|
||||||
[["%1: %2", LSTRING(SpeedLimit), GVAR(speedLimit)]] call EFUNC(common,displayTextStructured);
|
[["%1: %2", LSTRING(SpeedLimit), GVAR(speedLimit)]] call EFUNC(common,displayTextStructured);
|
||||||
true
|
true
|
||||||
|
} else {
|
||||||
|
!isNil QGVAR(isCruiseControl)
|
||||||
|
&& {GVAR(isCruiseControl) call FUNC(toggleSpeedControl)} // SET
|
||||||
};
|
};
|
||||||
}, {false}, [MOUSE_SCROLL_DOWN, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + Mouse Wheel Scroll Down
|
}, {false}, [MOUSE_SCROLL_DOWN, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + Mouse Wheel Scroll Down
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: Driver <OBJECT>
|
* 0: Driver <OBJECT>
|
||||||
* 1: Vehicle <OBJECT>
|
* 1: Vehicle <OBJECT>
|
||||||
|
* 2: Preserve Speed Limit <BOOL>
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
@ -20,7 +21,7 @@
|
|||||||
#define PID_D 0
|
#define PID_D 0
|
||||||
#define EPSILON 0.001
|
#define EPSILON 0.001
|
||||||
|
|
||||||
params ["_driver", "_vehicle"];
|
params ["_driver", "_vehicle", ["_preserveSpeedLimit", false]];
|
||||||
|
|
||||||
if (GVAR(isSpeedLimiter)) exitWith {
|
if (GVAR(isSpeedLimiter)) exitWith {
|
||||||
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
|
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
|
||||||
@ -31,9 +32,12 @@ if (GVAR(isSpeedLimiter)) exitWith {
|
|||||||
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
||||||
playSound "ACE_Sound_Click";
|
playSound "ACE_Sound_Click";
|
||||||
GVAR(isSpeedLimiter) = true;
|
GVAR(isSpeedLimiter) = true;
|
||||||
|
GVAR(isCruiseControl) = true; // enables SET/RESUME
|
||||||
|
|
||||||
|
if (!_preserveSpeedLimit) then {
|
||||||
// Convert forward speed to KM/H. `speed _vehicle` isnt accurate enough for this controller to work well, so its easier to use M/S. The system assumes it is KM/H so we need the conversion
|
// Convert forward speed to KM/H. `speed _vehicle` isnt accurate enough for this controller to work well, so its easier to use M/S. The system assumes it is KM/H so we need the conversion
|
||||||
GVAR(speedLimit) = (((velocityModelSpace _vehicle) select 1) * 3.6) max 5;
|
GVAR(speedLimit) = (((velocityModelSpace _vehicle) select 1) * 3.6) max 5;
|
||||||
|
};
|
||||||
|
|
||||||
[{
|
[{
|
||||||
params ["_args", "_idPFH"];
|
params ["_args", "_idPFH"];
|
||||||
@ -43,9 +47,16 @@ GVAR(speedLimit) = (((velocityModelSpace _vehicle) select 1) * 3.6) max 5;
|
|||||||
// this will take into account game being pausesd
|
// this will take into account game being pausesd
|
||||||
private _deltaTime = CBA_missionTime - _lastTime;
|
private _deltaTime = CBA_missionTime - _lastTime;
|
||||||
|
|
||||||
if (_driver != driver _vehicle) then {
|
private _role = _driver call EFUNC(common,getUavControlPosition);
|
||||||
|
if (GVAR(isUAV)) then {
|
||||||
|
if (_role != "DRIVER") then {
|
||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
if (_driver != currentPilot _vehicle || {_role != ""}) then {
|
||||||
|
GVAR(isSpeedLimiter) = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if (_throttleLogValue == 0) then {
|
if (_throttleLogValue == 0) then {
|
||||||
_throttleLogValue = 1;
|
_throttleLogValue = 1;
|
||||||
@ -60,6 +71,10 @@ GVAR(speedLimit) = (((velocityModelSpace _vehicle) select 1) * 3.6) max 5;
|
|||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (call CBA_fnc_getActiveFeatureCamera != "") then {
|
||||||
|
GVAR(isSpeedLimiter) = false;
|
||||||
|
};
|
||||||
|
|
||||||
if (!GVAR(isSpeedLimiter)) exitWith {
|
if (!GVAR(isSpeedLimiter)) exitWith {
|
||||||
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* 0: Driver <OBJECT>
|
* 0: Driver <OBJECT>
|
||||||
* 1: Vehicle <OBJECT>
|
* 1: Vehicle <OBJECT>
|
||||||
* 2: Cruise Control <BOOL>
|
* 2: Cruise Control <BOOL>
|
||||||
|
* 3: Preserve Speed Limit <BOOL>
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
@ -17,7 +18,7 @@
|
|||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_driver", "_vehicle", ["_cruiseControl", false]];
|
params ["_driver", "_vehicle", ["_cruiseControl", false], ["_preserveSpeedLimit", false]];
|
||||||
|
|
||||||
if (GVAR(isSpeedLimiter)) exitWith {
|
if (GVAR(isSpeedLimiter)) exitWith {
|
||||||
switch ([GVAR(isCruiseControl), _cruiseControl]) do {
|
switch ([GVAR(isCruiseControl), _cruiseControl]) do {
|
||||||
@ -26,7 +27,6 @@ if (GVAR(isSpeedLimiter)) exitWith {
|
|||||||
playSound "ACE_Sound_Click";
|
playSound "ACE_Sound_Click";
|
||||||
_vehicle setCruiseControl [0, false];
|
_vehicle setCruiseControl [0, false];
|
||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
GVAR(isCruiseControl) = false;
|
|
||||||
};
|
};
|
||||||
case [true, false]: {
|
case [true, false]: {
|
||||||
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
||||||
@ -59,28 +59,32 @@ playSound "ACE_Sound_Click";
|
|||||||
GVAR(isSpeedLimiter) = true;
|
GVAR(isSpeedLimiter) = true;
|
||||||
GVAR(isCruiseControl) = _cruiseControl;
|
GVAR(isCruiseControl) = _cruiseControl;
|
||||||
|
|
||||||
|
if (!_preserveSpeedLimit) then {
|
||||||
GVAR(speedLimit) = round (speed _vehicle max 5);
|
GVAR(speedLimit) = round (speed _vehicle max 5);
|
||||||
|
};
|
||||||
GVAR(speedLimitInit) = true;
|
GVAR(speedLimitInit) = true;
|
||||||
|
|
||||||
[{
|
[{
|
||||||
params ["_args", "_idPFH"];
|
params ["_args", "_idPFH"];
|
||||||
_args params ["_driver", "_vehicle"];
|
_args params ["_driver", "_vehicle"];
|
||||||
|
|
||||||
|
private _role = _driver call EFUNC(common,getUavControlPosition);
|
||||||
if (GVAR(isUAV)) then {
|
if (GVAR(isUAV)) then {
|
||||||
private _uavControl = UAVControl _vehicle;
|
if (_role == "") then {
|
||||||
if ((_uavControl select 0) != _driver || _uavControl select 1 != "DRIVER") then {
|
|
||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
TRACE_1("UAV driver changed, disabling speedlimit",_vehicle);
|
TRACE_1("UAV controller changed, disabling speedlimit",_vehicle);
|
||||||
_vehicle setCruiseControl [0, false];
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (_driver != driver _vehicle) then {
|
if (_driver != driver _vehicle || {_role != ""}) then {
|
||||||
GVAR(isSpeedLimiter) = false;
|
GVAR(isSpeedLimiter) = false;
|
||||||
TRACE_3("Vehicle driver changed, disabling speedlimit",_driver,driver _vehicle,_vehicle);
|
TRACE_3("Vehicle driver changed, disabling speedlimit",_driver,driver _vehicle,_vehicle);
|
||||||
_vehicle setCruiseControl [0, false];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (call CBA_fnc_getActiveFeatureCamera != "") then {
|
||||||
|
GVAR(isSpeedLimiter) = false;
|
||||||
|
};
|
||||||
|
|
||||||
if (!GVAR(isSpeedLimiter)) exitWith {
|
if (!GVAR(isSpeedLimiter)) exitWith {
|
||||||
_vehicle setCruiseControl [0, false];
|
_vehicle setCruiseControl [0, false];
|
||||||
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
||||||
|
59
addons/vehicles/functions/fnc_toggleSpeedControl.sqf
Normal file
59
addons/vehicles/functions/fnc_toggleSpeedControl.sqf
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "script_component.hpp"
|
||||||
|
/*
|
||||||
|
* Author: Dystopian
|
||||||
|
* Checks if player can toggle speed control and runs proper speed control mode.
|
||||||
|
* Should run as key handler.
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: Cruise Control <BOOL>
|
||||||
|
* 1: Preserve Speed Limit <BOOL>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* Key handled <BOOL>
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* true call ace_vehicles_fnc_toggleSpeedControl
|
||||||
|
*
|
||||||
|
* Public: No
|
||||||
|
*/
|
||||||
|
|
||||||
|
params [["_cruiseControl", false], ["_preserveSpeedLimit", false]];
|
||||||
|
|
||||||
|
private _role = ACE_player call EFUNC(common,getUavControlPosition);
|
||||||
|
|
||||||
|
private _vehicle = objNull;
|
||||||
|
private _continue = true;
|
||||||
|
if (_role != "") then {
|
||||||
|
GVAR(isUAV) = true;
|
||||||
|
_vehicle = getConnectedUAV ACE_player;
|
||||||
|
_continue = (
|
||||||
|
!visibleMap
|
||||||
|
&& {_role == "DRIVER" || {!(_vehicle isKindOf "Plane")}}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
GVAR(isUAV) = false;
|
||||||
|
_vehicle = vehicle ACE_player;
|
||||||
|
_continue = (
|
||||||
|
ACE_player == currentPilot _vehicle
|
||||||
|
&& {[ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith)}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
if (
|
||||||
|
!_continue
|
||||||
|
|| {!(isEngineOn _vehicle)}
|
||||||
|
|| {!GVAR(isSpeedLimiter) && _cruiseControl && {speed _vehicle < 1}} // don't enable CC when stop or move backward
|
||||||
|
) exitWith {false};
|
||||||
|
|
||||||
|
private _allowedVehicleClasses = ["Car", "Tank", "Ship"];
|
||||||
|
if (_cruiseControl) then {
|
||||||
|
_allowedVehicleClasses pushBack "Plane";
|
||||||
|
};
|
||||||
|
if (-1 == _allowedVehicleClasses findIf {_vehicle isKindOf _x}) exitWith {false};
|
||||||
|
|
||||||
|
if (_vehicle isKindOf "Plane") then {
|
||||||
|
[ACE_player, _vehicle, _preserveSpeedLimit] call FUNC(autoThrottle);
|
||||||
|
} else {
|
||||||
|
[ACE_player, _vehicle, _cruiseControl, _preserveSpeedLimit] call FUNC(speedLimiter);
|
||||||
|
};
|
||||||
|
|
||||||
|
true
|
Loading…
Reference in New Issue
Block a user