From e5654914cc2ac513c7518c33c8a723cf49527e46 Mon Sep 17 00:00:00 2001 From: Ampersand Date: Fri, 23 Jun 2023 08:11:16 -0400 Subject: [PATCH] Dragging - Improve carrying by allowing carried object to be loaded into vehicle by key or mouse (#9138) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * load carried object * check for medical loaded * space Co-authored-by: Jouni Järvinen * consolidate mouse hint in pfh --------- Co-authored-by: Jouni Järvinen --- addons/dragging/XEH_postInit.sqf | 2 +- addons/dragging/functions/fnc_carryObject.sqf | 9 +---- .../dragging/functions/fnc_carryObjectPFH.sqf | 35 ++++++++++++++++++- .../functions/fnc_dropObject_carry.sqf | 23 +++++++++--- addons/dragging/script_component.hpp | 2 ++ 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index dd782eddb2..e151eb6db6 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -65,7 +65,7 @@ if (isNil "ACE_maxWeightCarry") then { false }; if (ACE_player getVariable [QGVAR(isCarrying), false]) exitWith { - [ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull]] call FUNC(dropObject_carry); + [ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry); false }; diff --git a/addons/dragging/functions/fnc_carryObject.sqf b/addons/dragging/functions/fnc_carryObject.sqf index c819f20347..7e783bd0c5 100644 --- a/addons/dragging/functions/fnc_carryObject.sqf +++ b/addons/dragging/functions/fnc_carryObject.sqf @@ -53,19 +53,12 @@ _unit setVariable [QGVAR(carriedObject), _target, true]; _unit setVariable [QGVAR(ReleaseActionID), [ _unit, "DefaultAction", {!isNull ((_this select 0) getVariable [QGVAR(carriedObject), objNull])}, - {[_this select 0, (_this select 0) getVariable [QGVAR(carriedObject), objNull]] call FUNC(dropObject_carry)} + {[_this select 0, (_this select 0) getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry)} ] call EFUNC(common,addActionEventHandler)]; // add anim changed EH [_unit, "AnimChanged", FUNC(handleAnimChanged), [_unit]] call CBA_fnc_addBISEventHandler; -// show mouse hint -if (_target isKindOf "CAManBase") then { - [localize LSTRING(Drop), "", ""] call EFUNC(interaction,showMouseHint); -} else { - [localize LSTRING(Drop), "", localize LSTRING(RaiseLowerRotate)] call EFUNC(interaction,showMouseHint); -}; - // check everything [FUNC(carryObjectPFH), 0.5, [_unit, _target, CBA_missionTime]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/dragging/functions/fnc_carryObjectPFH.sqf b/addons/dragging/functions/fnc_carryObjectPFH.sqf index 6204bbae62..93e35547ad 100644 --- a/addons/dragging/functions/fnc_carryObjectPFH.sqf +++ b/addons/dragging/functions/fnc_carryObjectPFH.sqf @@ -28,11 +28,13 @@ _args params ["_unit", "_target", "_startTime"]; if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith { TRACE_2("carry false",_unit,_target); + _unit setVariable [QGVAR(hint), nil]; + [] call EFUNC(interaction,hideMouseHint); [_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 { +if (!alive _target || {_unit distance _target > 10}) exitWith { TRACE_2("dead/distance",_unit,_target); if ((_unit distance _target > 10) && {(CBA_missionTime - _startTime) < 1}) exitWith { //attachTo seems to have some kind of network delay and target can return an odd position during the first few frames, @@ -40,5 +42,36 @@ if (!alive _target || {_unit distance _target > 10}) then { TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,CBA_missionTime); }; [_unit, _target] call FUNC(dropObject_carry); + _unit setVariable [QGVAR(hint), nil]; + [] call EFUNC(interaction,hideMouseHint); [_idPFH] call CBA_fnc_removePerFrameHandler; }; + +// Mouse hint +private _hintLMB = localize LSTRING(Drop); +getCursorObjectParams params ["_cursorObject", "", "_distance"]; +if ( + !isNull _cursorObject + && {_distance < MAX_LOAD_DISTANCE} + && {([_unit, _cursorObject, ["isNotCarrying"]] call EFUNC(common,canInteractWith))} + && { + if (_target isKindOf "CAManBase") then { + [_cursorObject, 0, true] call EFUNC(common,nearestVehiclesFreeSeat) isNotEqualTo [] + } else { + [_target, _cursorObject] call EFUNC(cargo,canLoadItemIn) + } + } +) then { + _hintLMB = localize ELSTRING(Cargo,loadObject); +}; + +private _hintMMB = localize LSTRING(RaiseLowerRotate); +if (_target isKindOf "CAManBase") then { + _hintMMB = ""; +}; + +private _hint = [_hintLMB, "", _hintMMB]; +if (_hint isNotEqualTo (_unit getVariable [QGVAR(hint), []])) then { + _unit setVariable [QGVAR(hint), _hint]; + _hint call EFUNC(interaction,showMouseHint); +}; diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 7f681d4658..c81fb2247b 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -16,7 +16,7 @@ * Public: No */ -params ["_unit", "_target"]; +params ["_unit", "_target", ["_tryLoad", false]]; TRACE_1("params",_this); // remove drop action @@ -63,9 +63,6 @@ if (_inBuilding) then { _target setPosASL (getPosASL _target vectorAdd [0, 0, 0.05]); }; -// hide mouse hint -[] call EFUNC(interaction,hideMouseHint); - _unit setVariable [QGVAR(isCarrying), false, true]; _unit setVariable [QGVAR(carriedObject), objNull, true]; @@ -91,3 +88,21 @@ if (_mass != 0) then { // reset temp direction _target setVariable [QGVAR(carryDirection_temp), nil]; + +// try loading into vehicle +if (_tryLoad && {!isNull cursorObject} && {([ACE_player, cursorObject, []] call EFUNC(common,canInteractWith))}) then { + if (_target isKindOf "CAManBase") then { + private _vehicles = [cursorObject, 0, true] call EFUNC(common,nearestVehiclesFreeSeat); + if ([cursorObject] isEqualTo _vehicles) then { + if (["ACE_Medical"] call EFUNC(common,isModLoaded)) then { + [_unit, _target, cursorObject] call EFUNC(medical_treatment,loadUnit); + } else { + [_unit, _target, cursorObject] call EFUNC(common,loadPerson); + }; + }; + } else { + if ([_target, cursorObject] call EFUNC(cargo,canLoadItemIn)) then { + [player, _target, cursorObject] call EFUNC(cargo,startLoadIn); + }; + }; +}; diff --git a/addons/dragging/script_component.hpp b/addons/dragging/script_component.hpp index 12ed8efff3..5befaede9c 100644 --- a/addons/dragging/script_component.hpp +++ b/addons/dragging/script_component.hpp @@ -16,5 +16,7 @@ #include "\z\ace\addons\main\script_macros.hpp" +#define MAX_LOAD_DISTANCE 5 + #define DRAG_ANIMATIONS ["amovpercmstpslowwrfldnon_acinpknlmwlkslowwrfldb_2", "amovpercmstpsraswpstdnon_acinpknlmwlksnonwpstdb_2", "amovpercmstpsnonwnondnon_acinpknlmwlksnonwnondb_2", "acinpknlmstpsraswrfldnon", "acinpknlmstpsnonwpstdnon", "acinpknlmstpsnonwnondnon", "acinpknlmwlksraswrfldb", "acinpknlmwlksnonwnondb", "ace_dragging", "ace_dragging_static", "ace_dragging_drop"] #define CARRY_ANIMATIONS ["acinpercmstpsnonwnondnon", "acinpknlmstpsnonwnondnon_acinpercmrunsnonwnondnon"]