Dragging - Minor code cleanup (#9859)

* Dragging minor code cleanup

* Update fnc_startCarryPFH.sqf

* Revert UAV changes
This commit is contained in:
johnb432 2024-03-26 13:50:21 +01:00 committed by GitHub
parent 5ca81b7ef3
commit a8ed533004
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 65 additions and 41 deletions

View File

@ -68,6 +68,3 @@ if (_UAVCrew isNotEqualTo []) then {
// Check everything
[FUNC(carryObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler;
// Reset current dragging height
GVAR(currentHeightChange) = 0;

View File

@ -35,16 +35,36 @@ if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Drop if the crate is destroyed OR target moved away from carrier (weapon disassembled) OR carrier starts limping
if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage "HitLegs" < 0.5}) exitWith {
TRACE_2("dead/distance",_unit,_target);
// Drop if the target is destroyed
if (!alive _target) exitWith {
TRACE_2("dead",_unit,_target);
if ((_unit distance _target > 10) && {(CBA_missionTime - _startTime) < 1}) exitWith {
[_unit, _target] call FUNC(dropObject_carry);
_unit setVariable [QGVAR(hint), nil];
call EFUNC(interaction,hideMouseHint);
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Drop if the target moved away from carrier (e.g. weapon disassembled)
// attachTo seems to have some kind of network delay and target can return an odd position during the first few frames,
// So wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos)
TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,CBA_missionTime);
if (_unit distance _target > 10 && {(CBA_missionTime - _startTime) >= 1}) exitWith {
TRACE_2("distance",_unit,_target);
[_unit, _target] call FUNC(dropObject_carry);
_unit setVariable [QGVAR(hint), nil];
call EFUNC(interaction,hideMouseHint);
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Drop if the carrier starts limping
if (_unit getHitPointDamage "HitLegs" >= 0.5) exitWith {
TRACE_2("limping",_unit,_target);
[_unit, _target] call FUNC(dropObject_carry);
_unit setVariable [QGVAR(hint), nil];
@ -54,7 +74,7 @@ if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage
};
// Drop static if crew is in it (UAV crew deletion may take a few frames)
if (_target isKindOf "StaticWeapon" && {(crew _target) isNotEqualTo []} && {!(_target getVariable [QGVAR(isUAV), false])}) then {
if (_target isKindOf "StaticWeapon" && {!(_target getVariable [QGVAR(isUAV), false])} && {(crew _target) isNotEqualTo []}) exitWith {
TRACE_2("static weapon crewed",_unit,_target);
[_unit, _target] call FUNC(dropObject_carry);

View File

@ -57,7 +57,7 @@ GVAR(releaseActionID) = [0xF1, [false, false, false], {
["", LLSTRING(Drop)] call EFUNC(interaction,showMouseHint);
// Block firing
if !(GVAR(dragAndFire)) then {
if (!GVAR(dragAndFire)) then {
_unit setVariable [QGVAR(blockFire), [
_unit, "DefaultAction",
{true},
@ -70,6 +70,7 @@ if !(GVAR(dragAndFire)) then {
// Prevent UAVs from firing
private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew);
if (_UAVCrew isNotEqualTo []) then {
{
_target deleteVehicleCrew _x;
@ -81,8 +82,5 @@ if (_UAVCrew isNotEqualTo []) then {
// Check everything
[FUNC(dragObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler;
// Reset current dragging height.
GVAR(currentHeightChange) = 0;
// Fixes not being able to move when in combat pace
[_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);

View File

@ -31,15 +31,20 @@ if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled))
if (!alive _target || {_unit distance _target > 10}) then {
TRACE_2("dead/distance",_unit,_target);
// Drop if the target is destroyed
if (!alive _target) exitWith {
TRACE_2("dead",_unit,_target);
if ((_unit distance _target > 10) && {(CBA_missionTime - _startTime) < 1}) exitWith {
[_unit, _target] call FUNC(dropObject);
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Drop if the target moved away from carrier (e.g. weapon disassembled)
// attachTo seems to have some kind of network delay and target can return an odd position during the first few frames,
// So wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos)
TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,CBA_missionTime);
};
if (_unit distance _target > 10 && {(CBA_missionTime - _startTime) >= 1}) exitWith {
TRACE_2("distance",_unit,_target);
[_unit, _target] call FUNC(dropObject);
@ -47,7 +52,7 @@ if (!alive _target || {_unit distance _target > 10}) then {
};
// Drop static if crew is in it (UAV crew deletion may take a few frames)
if (_target isKindOf "StaticWeapon" && {(crew _target) isNotEqualTo []} && {!(_target getVariable [QGVAR(isUAV), false])}) then {
if (_target isKindOf "StaticWeapon" && {!(_target getVariable [QGVAR(isUAV), false])} && {(crew _target) isNotEqualTo []}) exitWith {
TRACE_2("static weapon crewed",_unit,_target);
[_unit, _target] call FUNC(dropObject);

View File

@ -26,7 +26,7 @@ if (!isNil QGVAR(releaseActionID)) then {
};
// Stop blocking
if !(GVAR(dragAndFire)) then {
if (!GVAR(dragAndFire)) then {
[_unit, "DefaultAction", _unit getVariable [QGVAR(blockFire), -1]] call EFUNC(common,removeActionEventHandler);
};
@ -82,6 +82,8 @@ if (_unit getVariable ["ACE_isUnconscious", false]) then {
// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0])
if (_target getVariable [QGVAR(isUAV), false]) then {
_target setVariable [QGVAR(isUAV), nil, true];
[{
params ["_target"];
if (!alive _target) exitWith {};

View File

@ -88,6 +88,8 @@ if !(_target isKindOf "CAManBase") then {
// Recreate UAV crew (add a frame delay or this may cause the vehicle to be moved to [0,0,0])
if (_target getVariable [QGVAR(isUAV), false]) then {
_target setVariable [QGVAR(isUAV), nil, true];
[{
params ["_target"];
if (!alive _target) exitWith {};

View File

@ -27,7 +27,7 @@ private _carriedItem = _unit getVariable [QGVAR(carriedObject), objNull];
// Disabled for persons
if (_carriedItem isKindOf "CAManBase") exitWith {false};
if !(CBA_events_control) then {
if (!CBA_events_control) then {
// Raise/lower
// Move carried item 15 cm per scroll interval
_scrollAmount = _scrollAmount * 0.15;

View File

@ -17,7 +17,7 @@
params ["_unit"];
// If not dragging, don't do anything
// If not carrying, don't do anything
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {};
// If action is already present, don't add it again

View File

@ -49,7 +49,7 @@ if (_target isKindOf "CAManBase") then {
_primaryWeapon = "ACE_FakePrimaryWeapon";
};
// Select primary, otherwise the drag animation actions don't work
// Select primary, otherwise the carry animation actions don't work
_unit selectWeapon _primaryWeapon;
// Move a bit closer and adjust direction when trying to pick up a person

View File

@ -32,9 +32,9 @@ if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled))
if (!alive _target || {_unit distance _target > 10}) then {
TRACE_4("dead/distance",_unit,_target,_timeOut,CBA_missionTime);
// Drop if the target is destroyed, if the target moved away from carrier (e.g. weapon disassembled) or if the carrier starts limping
if !(alive _target && {_unit distance _target <= 10} && {_unit getHitPointDamage "HitLegs" < 0.5}) exitWith {
TRACE_4("dead/distance/limping",_unit,_target,_timeOut,CBA_missionTime);
[_unit, _target] call FUNC(dropObject_carry);
_idPFH call CBA_fnc_removePerFrameHandler;
@ -42,7 +42,7 @@ if (!alive _target || {_unit distance _target > 10}) then {
// Handle persons vs. objects
if (_target isKindOf "CAManBase") then {
// Drop if in timeout
// Carry person after timeout (animation takes a long time to finish)
if (CBA_missionTime > _timeOut) exitWith {
TRACE_4("Start carry person",_unit,_target,_timeOut,CBA_missionTime);
[_unit, _target] call FUNC(carryObject);
@ -50,7 +50,7 @@ if (_target isKindOf "CAManBase") then {
_idPFH call CBA_fnc_removePerFrameHandler;
};
} else {
// Drop if in timeout
// Timeout: Drop target. CBA_missionTime, because anim length is linked to ingame time
if (CBA_missionTime > _timeOut) exitWith {
TRACE_4("timeout",_unit,_target,_timeOut,CBA_missionTime);
_idPFH call CBA_fnc_removePerFrameHandler;

View File

@ -40,7 +40,7 @@ if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith {
private _primaryWeapon = primaryWeapon _unit;
// Add a primary weapon if the unit has none
if !(GVAR(dragAndFire)) then {
if (!GVAR(dragAndFire)) then {
if (_primaryWeapon == "") then {
_unit addWeapon "ACE_FakePrimaryWeapon";
_primaryWeapon = "ACE_FakePrimaryWeapon";

View File

@ -32,15 +32,15 @@ if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Same as dragObjectPFH, checks if object is deleted, dead or target moved away from carrier (e.g. weapon disassembled)
if (!alive _target || {_unit distance _target > 10}) then {
// Drop if the target is destroyed or if the target moved away from carrier (e.g. weapon disassembled)
if (!alive _target || {_unit distance _target > 10}) exitWith {
TRACE_4("dead/distance",_unit,_target,_timeOut,CBA_missionTime);
[_unit, _target] call FUNC(dropObject);
_idPFH call CBA_fnc_removePerFrameHandler;
};
// Timeout: Do nothing, quit. CBA_missionTime, because anim length is linked to ingame time
// Timeout: Drop target. CBA_missionTime, because anim length is linked to ingame time
if (CBA_missionTime > _timeOut) exitWith {
TRACE_4("timeout",_unit,_target,_timeOut,CBA_missionTime);
_idPFH call CBA_fnc_removePerFrameHandler;

View File

@ -21,7 +21,7 @@
[LSTRING(allowRunWithLightweight_DisplayName), LSTRING(allowRunWithLightweight_Description)],
LLSTRING(SettingsName),
true,
true
1
] call CBA_fnc_addSetting;
[
@ -30,5 +30,5 @@
[LSTRING(skipContainerWeight_DisplayName), LSTRING(skipContainerWeight_Description)],
LLSTRING(SettingsName),
false,
true
1
] call CBA_fnc_addSetting;