Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towing - Add conditions to cancel towing in exceptional scenarios #8612

Merged
merged 2 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/towing/functions/fnc_startTow.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if (_ropeLength == 0) then {

_unit removeItem _ropeClass;

GVAR(cancel) = false;
GVAR(canAttach) = false;
[LINKFUNC(towStateMachinePFH), 0, [TOW_STATE_ATTACH_PARENT, _unit, _target, objNull, _ropeLength, _ropeClass]] call CBA_fnc_addPerFrameHandler;

18 changes: 14 additions & 4 deletions addons/towing/functions/fnc_towStateMachinePFH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ private _exitCondition = !(
{ "" isEqualTo currentWeapon _unit || { _unit call EFUNC(common,isSwimming) }} &&
{ [_unit, objNull, [INTERACTION_EXCEPTIONS]] call EFUNC(common,canInteractWith) } &&
{ "unconscious" isNotEqualTo toLower animationState _unit } &&
{ !(_unit getVariable ["ACE_isUnconscious", false]) }
{ !(_unit getVariable ["ACE_isUnconscious", false]) } &&
{ ACE_player == _unit }
);

if (_exitCondition) then {
if (_exitCondition && {_state < TOW_STATE_CANCEL}) then {
_state = TOW_STATE_CANCEL;
};

Expand All @@ -45,8 +46,9 @@ switch (_state) do {
_args set [3, _rope];
};

if (GVAR(mouseRight)) then {
if (GVAR(mouseRight) || GVAR(cancel)) then {
_args set [0, TOW_STATE_CANCEL];
GVAR(cancel) = false;
};
};
case TOW_STATE_ATTACH_CHILD: {
Expand Down Expand Up @@ -74,6 +76,11 @@ switch (_state) do {
ERROR_MSG("_child isEqualTo _parent");
};

if (GVAR(cancel)) exitWith {
_args set [0, TOW_STATE_CANCEL];
GVAR(cancel) = false;
};

[QGVAR(setTowParent), [_parent, _child], _parent] call CBA_fnc_targetEvent;

GVAR(attachHelper) ropeDetach _rope;
Expand Down Expand Up @@ -127,9 +134,12 @@ switch (_state) do {
};
case TOW_STATE_CANCEL: {
TRACE_1("state cancel",_rope);
ropeDestroy _rope;
if !(isNull _rope) then {
ropeDestroy _rope;
};
[_unit, _ropeClass, true] call CBA_fnc_addItem;
_args set [0, TOW_STATE_CLEANUP];
GVAR(cancel) = false;

(localize LSTRING(canceled)) call CBA_fnc_notify;
};
Expand Down
2 changes: 1 addition & 1 deletion addons/towing/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "\z\ace\addons\main\script_macros.hpp"

#define TOW_ACTION_DISTANCE 3
#define INTERACTION_EXCEPTIONS "isNotInside", "isNotOnLadder", "isNotSwimming"
#define INTERACTION_EXCEPTIONS "isNotOnLadder", "isNotSwimming"

#define TOW_STATE_ATTACH_PARENT 0
#define TOW_STATE_ATTACH_CHILD 1
Expand Down