Skip to content

Commit

Permalink
Merge pull request #151 from gruppe-adler/fix-reverse-for-one-seaters
Browse files Browse the repository at this point in the history
probably fix #141
  • Loading branch information
Fusselwurm authored May 24, 2022
2 parents 7a0624c + 3237d20 commit d481726
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 89 deletions.
54 changes: 39 additions & 15 deletions addons/activities/functions/fnc_doReverse.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 2 additions & 1 deletion addons/activities/functions/fnc_reverse.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
156 changes: 84 additions & 72 deletions addons/diagnostics/functions/fnc_showInfoLine.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<empty>";
switch (GVAR(civStateFormat)) do {
case 0: { _text = _x getVariable [QGVAR(infoLine),"<no info found. is debug mode enabled where the civs are local?>"]; };
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),"<no info found. is debug mode enabled where the civs are local?>"]; };
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 {"<empty>"};
};
} 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 [
Expand All @@ -83,21 +94,22 @@ if (GVAR(showInfoLine)) then {
];
};

GVAR(userActionIds) = [
["<t color='#3333FF'>civstate format: infoLine</t>", 0] call _addCivAction,
["<t color='#3333FF'>civstate format: speedmode</t>", 1] call _addCivAction,
["<t color='#3333FF'>civstate format: guns</t>", 2] call _addCivAction,
["<t color='#3333FF'>civstate format: locality</t>", 3] call _addCivAction,
["<t color='#3333FF'>civstate format: behaviour</t>", 4] call _addCivAction,
["<t color='#3333FF'>civstate format: state times</t>", 5] call _addCivAction,
["<t color='#3333FF'>civstate format: waypoints</t>", 6] call _addCivAction,
["<t color='#3333FF'>civstate format: distance</t>", 7] call _addCivAction,
["<t color='#3333FF'>civstate format: type</t>", 8] call _addCivAction,
["<t color='#3333FF'>civstate format: empty</t>", 9] call _addCivAction
];
GVAR(userActionIds) = [
["<t color='#3333FF'>civstate format: empty</t>", 0] call _addCivAction,
["<t color='#3333FF'>civstate format: infoLine</t>", 1] call _addCivAction,
["<t color='#3333FF'>civstate format: speedmode</t>", 2] call _addCivAction,
["<t color='#3333FF'>civstate format: guns</t>", 3] call _addCivAction,
["<t color='#3333FF'>civstate format: locality</t>", 4] call _addCivAction,
["<t color='#3333FF'>civstate format: behaviour</t>", 5] call _addCivAction,
["<t color='#3333FF'>civstate format: state times</t>", 6] call _addCivAction,
["<t color='#3333FF'>civstate format: waypoints</t>", 7] call _addCivAction,
["<t color='#3333FF'>civstate format: distance</t>", 8] call _addCivAction,
["<t color='#3333FF'>civstate format: type</t>", 9] call _addCivAction,
["<t color='#3333FF'>civstate format: vehicle move info</t>", 10] call _addCivAction
];
} else {
{
player removeAction _x;
} forEach GVAR(userActionIds);
GVAR(userActionIds) = [];
{
player removeAction _x;
} forEach GVAR(userActionIds);
GVAR(userActionIds) = [];
};
3 changes: 2 additions & 1 deletion addons/interact/functions/fnc_handleAnimation.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit d481726

Please sign in to comment.