From 3237d203f0b4281f7d7b827c8c02da51c14aea64 Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sun, 22 May 2022 18:12:23 +0200 Subject: [PATCH] fix reverse * if reversing is not possible, let car drive back normally via doMove * fix bugs where somnetimes vic would not reverse at all * fix effectivecommander selection with multiple ppl on board * remove waypoints before issuing reverse command * fix where one 'go' gesture was not recognized * add infoline option where you se who's effective commander, and the moveInfo --- addons/activities/functions/fnc_doReverse.sqf | 54 ++++-- addons/activities/functions/fnc_reverse.sqf | 3 +- .../functions/fnc_showInfoLine.sqf | 156 ++++++++++-------- .../functions/fnc_handleAnimation.sqf | 3 +- 4 files changed, 127 insertions(+), 89 deletions(-) diff --git a/addons/activities/functions/fnc_doReverse.sqf b/addons/activities/functions/fnc_doReverse.sqf index 6c7ffba7..a764af1e 100644 --- a/addons/activities/functions/fnc_doReverse.sqf +++ b/addons/activities/functions/fnc_doReverse.sqf @@ -19,33 +19,57 @@ if (!(local _civ)) exitWith { // if not local, fix by deferring if (_civ == (call CBA_fnc_currentUnit)) exitWith {}; +private _veh = vehicle _civ; +if (_veh isEqualTo _civ) exitWith { + ERROR_1("civ %1 was told to reverse while not being mounted"); +}; + [ _civ, { - params ["_civ", "_reverseTargetPos"]; + params [ + ["_civ", objNull, [objNull]], + ["_reverseTargetPos", [0, 0, 0], [[]]], + ["_doTrueReverse", true, [true]] + ]; private _group = group driver vehicle _civ; - INFO_1("civ %1 is being sent away with vehicle, remove pre-existing waypoints", _civ); - + INFO_1("civ %1 is being sent away with vehicle. removing pre-existing waypoints", _civ); [_group] call CBA_fnc_clearWaypoints; - [ - vehicle _civ, - _reverseTargetPos, - 60, - {} - ] call FUNC(reverse); + if (_doTrueReverse) then { + [ + vehicle _civ, + _reverseTargetPos, + 60, + {} + ] call FUNC(reverse); - INFO_2("vehicle %1 reversing to %2 and then waiting", _civ, _reverseTargetPos); + INFO_2("vehicle %1 reverses to %2 and then waits", _civ, _reverseTargetPos); + } else { + INFO_2("vehicle %1 is moving back to %2 and then waits", _civ, _reverseTargetPos); + _civ doMove _reverseTargetPos; + }; }, { - params ["_civ", ""]; - [vehicle _civ] call FUNC(reverse_abort); + params [ + ["_civ", objNull, [objNull]], + ["_reverseTargetPos", [0, 0, 0], [[]]], + ["_doTrueReverse", true, [true]] + ]; + if (_doTrueReverse) then { + [vehicle _civ] call FUNC(reverse_abort); + }; }, { // wait for players to go away - params ["_civ"]; - [ALL_HUMAN_PLAYERS, getPos _civ, 200] call FUNC(isInDistanceFromOtherPlayers); + params [ + ["_civ", objNull, [objNull]] + ]; + [ALL_HUMAN_PLAYERS, getPos _civ, 200] call EFUNC(lifecycle,isInDistanceFromOtherPlayers); }, - [_reverseTargetPos], + [ + +_reverseTargetPos, + count (fullCrew [_veh, "", true]) > 1 // NOTE: driving in reverse needs a vehiclecommander, cannot be done with a single-seater + ], "reversing", "sent away. reversing, then doing nothing until players have left" ] call FUNC(doCustomActivity); diff --git a/addons/activities/functions/fnc_reverse.sqf b/addons/activities/functions/fnc_reverse.sqf index 4461be10..f2c63df0 100644 --- a/addons/activities/functions/fnc_reverse.sqf +++ b/addons/activities/functions/fnc_reverse.sqf @@ -30,11 +30,12 @@ if (effectiveCommander _vehicle == _driver) then { _ec moveInCargo _vehicle; _ec setVariable ["grad_civs_virtual_ec", true]; } else { - _ec = (crew _vehicle) select 1; + _ec = ((crew _vehicle) select {_x != _driver})#0; }; LOG_1("setting EC to %1", typeOf _ec); _vehicle setEffectiveCommander _ec; + _vehicle sendSimpleCommand "STOPTURNING"; }; private _pfhHandle = [FUNC(reverse_internal_pfh), 0, [_vehicle, _targetPos]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/diagnostics/functions/fnc_showInfoLine.sqf b/addons/diagnostics/functions/fnc_showInfoLine.sqf index bbd7b087..1b46f1b7 100644 --- a/addons/diagnostics/functions/fnc_showInfoLine.sqf +++ b/addons/diagnostics/functions/fnc_showInfoLine.sqf @@ -4,66 +4,77 @@ ISNILS(GVAR(civStateFormat), 0); ISNILS(GVAR(userActionIds), []); [{ - params [ - ["_args", [], [[]]], - ["_handle", 0, [0]] - ]; - if (!(GVAR(showInfoLine))) exitWith {[_handle] call CBA_fnc_removePerFrameHandler}; - - if (!isGameFocused || isGamePaused) exitWith {}; - - private _filterTimeVars = { - ((allVariables _this) select { - (_x find "grad_civs_state_time_") > -1 - } apply { - [_x, floor CBA_missionTime - (_this getVariable _x)] joinString ": " - }) joinString ", "; - }; - - private _camPos = AGLToASL positionCameraToWorld [0, 0, 0]; - private _camDir = getCameraViewDirection (call CBA_fnc_currentUnit); - - { - private _opacity = linearConversion [500, 50, _camPos distance _x, 0.2, 1, true]; - private _text = "o"; - - private _diff = (getPosASL _x) vectorDiff _camPos; - private _civAngle = acos (_camDir vectorCos _diff); - - private _fov = deg getObjectFOV (call CBA_fnc_currentUnit); - - if (_civAngle < _fov) then { - - _text = ""; - switch (GVAR(civStateFormat)) do { - case 0: { _text = _x getVariable [QGVAR(infoLine),""]; }; - case 1: { _text = format["%1 | speedmode: %2 %3", _x, speedMode _x, if (leader _x == _x) then {"(is leader)"} else {""}]; }; - case 2: { _text = format["%1 | %2 guns point at him", _x, _x getVariable [QEGVAR(interact,pointedAtCount), 0]]}; - case 3: { _text = format["%1 | is local at %2", _x, _x getVariable [QGVAR(localAt), 0]]}; - case 4: { _text = format["%1 | %2 %3 %4 | stopped: %5, unitReady: %6", _x, behaviour _x, combatMode _x, speedMode _x, stopped _x, unitReady _x]}; - case 5: { _text = format["%1 | state times: %2", _x, _x call _filterTimeVars]}; - case 6: { _text = format["%1 | waypoints: %2 , current wp is %3", _x, count waypoints group _x, currentWaypoint group _x ]}; - case 7: { _text = format["%1 | distance to player: %2", _x, _x distance (call CBA_fnc_currentUnit)]}; - case 8: { _text = format["%1 | %2%3", _x, typeOf _x, if (vehicle _x != _x) then {format [" in %1", typeOf (vehicle _x)]} else {""}]}; - default { _text = ""}; - }; - }; - - private _color = [0.8, 0, 1, _opacity]; // colorCivilian is too dark for text :/ - - drawIcon3D [ - "#(argb,8,8,3)color(0,0,0,0)", - _color, - (getPosATL _x) vectorAdd [0, 0, 2], - 1, 1, 0, - _text, 0, 0.03, "EtelkaNarrowMediumPro", "center", true - ]; - } forEach ([] call EFUNC(lifecycle,getGlobalCivs)); + params [ + ["_args", [], [[]]], + ["_handle", 0, [0]] + ]; + if (!(GVAR(showInfoLine))) exitWith {[_handle] call CBA_fnc_removePerFrameHandler}; + + if (!isGameFocused || isGamePaused) exitWith {}; + + private _filterTimeVars = { + ((allVariables _this) select { + (_x find "grad_civs_state_time_") > -1 + } apply { + [_x, floor CBA_missionTime - (_this getVariable _x)] joinString ": " + }) joinString ", "; + }; + + private _camPos = AGLToASL positionCameraToWorld [0, 0, 0]; + private _camDir = getCameraViewDirection (call CBA_fnc_currentUnit); + + { + private _opacity = linearConversion [500, 50, _camPos distance _x, 0.2, 1, true]; + + private _diff = (getPosASL _x) vectorDiff _camPos; + private _civAngle = acos (_camDir vectorCos _diff); + + private _fov = deg getObjectFOV (call CBA_fnc_currentUnit); + + private _text = if (_civAngle < _fov) then { + switch (GVAR(civStateFormat)) do { + case 0: {""}; + case 1: {_x getVariable [QGVAR(infoLine),""]; }; + case 2: {format["%1 | speedmode: %2 %3", _x, speedMode _x, if (leader _x == _x) then {"(is leader)"} else {""}]; }; + case 3: {format["%1 | %2 guns point at him", _x, _x getVariable [QEGVAR(interact,pointedAtCount), 0]]}; + case 4: {format["%1 | is local at %2", _x, _x getVariable [QGVAR(localAt), 0]]}; + case 5: {format["%1 | %2 %3 %4 | stopped: %5, unitReady: %6", _x, behaviour _x, combatMode _x, speedMode _x, stopped _x, unitReady _x]}; + case 6: {format["%1 | state times: %2", _x, _x call _filterTimeVars]}; + case 7: {format["%1 | waypoints: %2 , current wp is %3", _x, count waypoints group _x, currentWaypoint group _x ]}; + case 8: {format["%1 | distance to player: %2", _x, _x distance (call CBA_fnc_currentUnit)]}; + case 9: {format["%1 | %2%3", _x, typeOf _x, if (vehicle _x != _x) then {format [" in %1", typeOf (vehicle _x)]} else {""}]}; + case 10: { + private _vic = vehicle _x; + if (_vic != _x && (driver _vic == _x)) then { + private _i = vehicleMoveInfo _vic; + private _ec = effectiveCommander _vic; + if (isObjectHidden _ec) then { + _ec hideObject false; + }; + format["%1 | commander %2 | move %3 | turn %4", _x, _ec, _i#0, _i#1]; + } else { + "" + }; + }; + default {""}; + }; + } else {"o"}; + + private _color = [0.8, 0, 1, _opacity]; // colorCivilian is too dark for text :/ + + drawIcon3D [ + "#(argb,8,8,3)color(0,0,0,0)", + _color, + (getPosATL _x) vectorAdd [0, 0, 2], + 1, 1, 0, + _text, 0, 0.03, "EtelkaNarrowMediumPro", "center", true + ]; + } forEach ([] call EFUNC(lifecycle,getGlobalCivs)); }, 0, []] call CBA_fnc_addPerFrameHandler; if (GVAR(showInfoLine)) then { - if (!(GVAR(userActionIds) isEqualTo [])) exitWith {}; + if (!(GVAR(userActionIds) isEqualTo [])) exitWith {}; private _addCivAction = { params [ @@ -83,21 +94,22 @@ if (GVAR(showInfoLine)) then { ]; }; - GVAR(userActionIds) = [ - ["civstate format: infoLine", 0] call _addCivAction, - ["civstate format: speedmode", 1] call _addCivAction, - ["civstate format: guns", 2] call _addCivAction, - ["civstate format: locality", 3] call _addCivAction, - ["civstate format: behaviour", 4] call _addCivAction, - ["civstate format: state times", 5] call _addCivAction, - ["civstate format: waypoints", 6] call _addCivAction, - ["civstate format: distance", 7] call _addCivAction, - ["civstate format: type", 8] call _addCivAction, - ["civstate format: empty", 9] call _addCivAction - ]; + GVAR(userActionIds) = [ + ["civstate format: empty", 0] call _addCivAction, + ["civstate format: infoLine", 1] call _addCivAction, + ["civstate format: speedmode", 2] call _addCivAction, + ["civstate format: guns", 3] call _addCivAction, + ["civstate format: locality", 4] call _addCivAction, + ["civstate format: behaviour", 5] call _addCivAction, + ["civstate format: state times", 6] call _addCivAction, + ["civstate format: waypoints", 7] call _addCivAction, + ["civstate format: distance", 8] call _addCivAction, + ["civstate format: type", 9] call _addCivAction, + ["civstate format: vehicle move info", 10] call _addCivAction + ]; } else { - { - player removeAction _x; - } forEach GVAR(userActionIds); - GVAR(userActionIds) = []; + { + player removeAction _x; + } forEach GVAR(userActionIds); + GVAR(userActionIds) = []; }; diff --git a/addons/interact/functions/fnc_handleAnimation.sqf b/addons/interact/functions/fnc_handleAnimation.sqf index b69d9aee..65f31477 100644 --- a/addons/interact/functions/fnc_handleAnimation.sqf +++ b/addons/interact/functions/fnc_handleAnimation.sqf @@ -8,6 +8,7 @@ if ((toLower _animation) in ["gesturefreeze", "ace_gestures_hold", "ace_gestures [_unit] call FUNC(handleGestureStop); }; -if ((toLower _animation) in ["gesturego"]) exitWith { +if ((toLower _animation) in ["gesturegob", "gesturego"]) exitWith { + // see https://github.com/acemod/ACE3/blob/f3f57c6/addons/gestures/CfgVehicles.hpp#L22 [_unit] call FUNC(handleGestureGo); };