From b00977eda04b38d01bc0024f8ec6845fddd8c11b Mon Sep 17 00:00:00 2001 From: BaerMitUmlaut Date: Sun, 4 Oct 2020 22:39:52 +0200 Subject: [PATCH] Create clones for corpse carrying/dragging --- addons/dragging/CfgVehicles.hpp | 3 +++ addons/dragging/XEH_PREP.hpp | 2 ++ addons/dragging/XEH_postInit.sqf | 8 ++++++ addons/dragging/functions/fnc_canCarry.sqf | 2 +- addons/dragging/functions/fnc_canDrag.sqf | 2 +- addons/dragging/functions/fnc_carryObject.sqf | 3 +++ addons/dragging/functions/fnc_createClone.sqf | 26 +++++++++++++++++++ addons/dragging/functions/fnc_dropClone.sqf | 26 +++++++++++++++++++ addons/dragging/functions/fnc_dropObject.sqf | 5 ++++ .../functions/fnc_dropObject_carry.sqf | 5 ++++ addons/dragging/functions/fnc_startCarry.sqf | 4 +++ addons/dragging/functions/fnc_startDrag.sqf | 5 ++++ 12 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 addons/dragging/functions/fnc_createClone.sqf create mode 100644 addons/dragging/functions/fnc_dropClone.sqf diff --git a/addons/dragging/CfgVehicles.hpp b/addons/dragging/CfgVehicles.hpp index 4c43dd814e..d83fca3389 100644 --- a/addons/dragging/CfgVehicles.hpp +++ b/addons/dragging/CfgVehicles.hpp @@ -2,6 +2,9 @@ class CBA_Extended_EventHandlers; class CfgVehicles { + class C_man_1; + class GVAR(clone): C_man_1 {}; + // Static weapons class LandVehicle; class StaticWeapon: LandVehicle { diff --git a/addons/dragging/XEH_PREP.hpp b/addons/dragging/XEH_PREP.hpp index b04c15e7ec..f9fbd4529c 100644 --- a/addons/dragging/XEH_PREP.hpp +++ b/addons/dragging/XEH_PREP.hpp @@ -5,8 +5,10 @@ PREP(canDrop); PREP(canDrop_carry); PREP(carryObject); PREP(carryObjectPFH); +PREP(createClone); PREP(dragObject); PREP(dragObjectPFH); +PREP(dropClone); PREP(dropObject); PREP(dropObject_carry); PREP(getWeight); diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index dd782eddb2..7828d441b6 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -27,6 +27,14 @@ if (isNil "ACE_maxWeightCarry") then { // handle waking up dragged unit and falling unconscious while dragging ["ace_unconscious", {_this call FUNC(handleUnconscious)}] call CBA_fnc_addEventHandler; +// handle local effect commands for clones +[QGVAR(cloneCreated), { + params ["_unit", "_clone"]; + + _clone setFace face _unit; + _clone setMimic "unconscious"; +}] call CBA_fnc_addEventHandler; + // display event handler ["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; diff --git a/addons/dragging/functions/fnc_canCarry.sqf b/addons/dragging/functions/fnc_canCarry.sqf index b5edbd800c..1bb10f9377 100644 --- a/addons/dragging/functions/fnc_canCarry.sqf +++ b/addons/dragging/functions/fnc_canCarry.sqf @@ -27,4 +27,4 @@ if ((_unit getHitPointDamage "HitLegs") >= 0.5) exitWith {false}; // a static weapon has to be empty for dragging (ignore UAV AI) if (((typeOf _target) isKindOf "StaticWeapon") && {{(getText (configFile >> "CfgVehicles" >> (typeOf _x) >> "simulation")) != "UAVPilot"} count crew _target > 0}) exitWith {false}; -alive _target && {vehicle _target isEqualto _target} && {_target getVariable [QGVAR(canCarry), false]} && {animationState _target in ["", "unconscious"] || (_target getVariable ["ACE_isUnconscious", false]) || (_target isKindOf "CAManBase" && {(_target getHitPointDamage "HitLegs") > 0.4})} +(alive _target || {_target isKindOf "CAManBase"}) && {vehicle _target isEqualto _target} && {_target getVariable [QGVAR(canCarry), false]} && {animationState _target in ["", "unconscious", "deadstate"] || (_target getVariable ["ACE_isUnconscious", false]) || (_target isKindOf "CAManBase" && {(_target getHitPointDamage "HitLegs") > 0.4})} diff --git a/addons/dragging/functions/fnc_canDrag.sqf b/addons/dragging/functions/fnc_canDrag.sqf index dbae83521b..b43f5e71c7 100644 --- a/addons/dragging/functions/fnc_canDrag.sqf +++ b/addons/dragging/functions/fnc_canDrag.sqf @@ -23,4 +23,4 @@ if !([_unit, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)) exi // a static weapon has to be empty for dragging (ignore UAV AI) if ((typeOf _target) isKindOf "StaticWeapon" && {{(getText (configFile >> "CfgVehicles" >> (typeOf _x) >> "simulation")) != "UAVPilot"} count crew _target > 0}) exitWith {false}; -alive _target && {vehicle _target isEqualto _target} && {_target getVariable [QGVAR(canDrag), false]} && {animationState _target in ["", "unconscious"] || (_target getVariable ["ACE_isUnconscious", false]) || (_target isKindOf "CAManBase" && {(_target getHitPointDamage "HitLegs") > 0.4})} +(alive _target || {_target isKindOf "CAManBase"}) && {vehicle _target isEqualto _target} && {_target getVariable [QGVAR(canDrag), false]} && {animationState _target in ["", "unconscious", "deadstate"] || (_target getVariable ["ACE_isUnconscious", false]) || (_target isKindOf "CAManBase" && {(_target getHitPointDamage "HitLegs") > 0.4})} diff --git a/addons/dragging/functions/fnc_carryObject.sqf b/addons/dragging/functions/fnc_carryObject.sqf index e3f8c2b61e..121b673cf9 100644 --- a/addons/dragging/functions/fnc_carryObject.sqf +++ b/addons/dragging/functions/fnc_carryObject.sqf @@ -26,6 +26,9 @@ private _direction = _target getVariable [QGVAR(carryDirection), 0]; // handle objects vs persons if (_target isKindOf "CAManBase") then { + if (!alive _target) then { + _target = [_target] call FUNC(createClone); + }; [_unit, "AcinPercMstpSnonWnonDnon", 2, true] call EFUNC(common,doAnimation); [_target, "AinjPfalMstpSnonWnonDf_carried_dead", 2, true] call EFUNC(common,doAnimation); diff --git a/addons/dragging/functions/fnc_createClone.sqf b/addons/dragging/functions/fnc_createClone.sqf new file mode 100644 index 0000000000..bf38fa42e1 --- /dev/null +++ b/addons/dragging/functions/fnc_createClone.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: BaerMitUmlaut + * Creates a draggable / carryable clone of a dead unit. + * + * Arguments: + * 0: Dead unit + * + * Return Value: + * Cloned unit. + * + * Example: + * [player] call ace_dragging_fnc_createClone; + * + * Public: No + */ +params ["_unit"]; + +private _clone = QGVAR(clone) createVehicle [0, 0, 0]; +_clone setUnitLoadout getUnitLoadout _unit; +_clone setVariable [QGVAR(original), _unit]; +_unit hideObjectGlobal true; + +[QGVAR(cloneCreated), [_unit, _clone]] call CBA_fnc_globalEvent; + +_clone diff --git a/addons/dragging/functions/fnc_dropClone.sqf b/addons/dragging/functions/fnc_dropClone.sqf new file mode 100644 index 0000000000..5438a51290 --- /dev/null +++ b/addons/dragging/functions/fnc_dropClone.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: BaerMitUmlaut + * Drops a draggable / carryable clone of a dead unit. + * + * Arguments: + * 0: Clone + * + * Return Value: + * Original unit. + * + * Example: + * [player] call ace_dragging_fnc_createClone; + * + * Public: No + */ +params ["_clone"]; + +private _unit = _clone getVariable [QGVAR(original), objNull]; +_unit setPosASL getPosASL _clone; +_unit hideObjectGlobal false; + +detach _clone; +deleteVehicle _clone; + +_unit diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 4ecc876afd..18ec97fe48 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -24,6 +24,11 @@ TRACE_2("params",_unit,_target); private _inBuilding = [_unit] call FUNC(isObjectOnObject); +// drop cloned dead units +if (_target isKindOf QGVAR(clone)) then { + _target = [_target] call FUNC(dropClone); +}; + if !(_unit getVariable ["ACE_isUnconscious", false]) then { // play release animation [_unit, "released"] call EFUNC(common,doGesture); diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 5235b7e66d..66880cd0dd 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -24,6 +24,11 @@ TRACE_1("params",_this); private _inBuilding = [_unit] call FUNC(isObjectOnObject); +// drop cloned dead units +if (_target isKindOf QGVAR(clone)) then { + _target = [_target] call FUNC(dropClone); +}; + // prevent collision damage [QEGVAR(common,fixCollision), _unit] call CBA_fnc_localEvent; [QEGVAR(common,fixCollision), _target, _target] call CBA_fnc_targetEvent; diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf index a52afd1c27..b184a1e7bb 100644 --- a/addons/dragging/functions/fnc_startCarry.sqf +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -32,6 +32,10 @@ private _timer = CBA_missionTime + 5; // handle objects vs persons if (_target isKindOf "CAManBase") then { + // create clone for dead units + if (!alive _target) then { + _target = [_target] call FUNC(createClone); + }; // add a primary weapon if the unit has none. if (primaryWeapon _unit isEqualto "") then { diff --git a/addons/dragging/functions/fnc_startDrag.sqf b/addons/dragging/functions/fnc_startDrag.sqf index 7a4c8908d3..c09d921a83 100644 --- a/addons/dragging/functions/fnc_startDrag.sqf +++ b/addons/dragging/functions/fnc_startDrag.sqf @@ -28,6 +28,11 @@ if (!GETVAR(_target,GVAR(ignoreWeightDrag),false) && { [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); }; +// create clone for dead units +if (!alive _target) then { + _target = [_target] call FUNC(createClone); +}; + // add a primary weapon if the unit has none. // @todo prevent opening inventory when equipped with a fake weapon if (primaryWeapon _unit isEqualto "") then {