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

Dragging - Corpse carrying and dragging - continued #9269

Closed
wants to merge 8 commits into from
Closed
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
5 changes: 5 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
_object setMass _mass;
}] call CBA_fnc_addEventHandler;

[QGVAR(awake), {
params ["_object", "_awake"];
_object awake _awake;
}] call CBA_fnc_addEventHandler;

//Add a fix for BIS's zeus remoteControl module not reseting variables on DC when RC a unit
//This variable is used for isPlayer checks
if (isServer) then {
Expand Down
15 changes: 7 additions & 8 deletions addons/dragging/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand All @@ -20,42 +19,42 @@ class Extended_PostInit_EventHandlers {
class Extended_Init_EventHandlers {
class CAManBase {
class ADDON {
init = QUOTE(_this call DFUNC(initPerson));
init = QUOTE(_this call FUNC(initPerson));
exclude[] = {"VirtualMan_F"};
};
};
class StaticWeapon {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
init = QUOTE(_this call FUNC(initObject));
};
};
class Thing {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
init = QUOTE(_this call FUNC(initObject));
exclude[] = {"ModuleEmpty_F", "ThingEffect", "Wreck"};
};
};
class NonStrategic {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
init = QUOTE(_this call FUNC(initObject));
};
};
class WeaponHolder {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
init = QUOTE(_this call FUNC(initObject));
};
};
class Land_Camping_Light_F {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
init = QUOTE(_this call FUNC(initObject));
};
};
};

class Extended_Killed_EventHandlers {
class CAManBase {
class ADDON {
killed = QUOTE(_this call DFUNC(handleKilled));
killed = QUOTE(_this call FUNC(handleKilled));
};
};
};
26 changes: 14 additions & 12 deletions addons/dragging/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
class CBA_Extended_EventHandlers;

class CfgVehicles {
class C_man_1;
class GVAR(clone): C_man_1 {};

// Static weapons
class LandVehicle;
class StaticWeapon: LandVehicle {
Expand Down Expand Up @@ -72,7 +75,7 @@ class CfgVehicles {
GVAR(canDrag) = 0;
};

// ammo boxes
// Ammo boxes
class ThingX;
class Items_base_F;
class ReammoBox_F: ThingX {
Expand All @@ -86,7 +89,7 @@ class CfgVehicles {
GVAR(canCarry) = 0;
GVAR(canDrag) = 0;
};
//remove actions from Taru Pods
// Remove actions from Taru Pods
class Pod_Heli_Transport_04_base_F: Slingload_base_F {
GVAR(canCarry) = 0;
GVAR(canDrag) = 0;
Expand Down Expand Up @@ -160,7 +163,7 @@ class CfgVehicles {
GVAR(canDrag) = 0;
};

//Plastic and metal case
// Plastic and metal case
class PlasticCase_01_base_F: Items_base_F {
GVAR(canCarry) = 1;
GVAR(carryDirection) = 270;
Expand Down Expand Up @@ -226,22 +229,22 @@ class CfgVehicles {
GVAR(canCarry) = 1;
};

// weapons dropped from dead body
// Weapons dropped from dead body
class WeaponHolderSimulated: ThingX {
GVAR(canCarry) = 1;
GVAR(carryPosition[]) = {0,0.5,1.3};
GVAR(carryDirection) = 0;

// z-position floats from -1.2 to >0
// it's OK for carrying but odd for dragging
// needs workaround to drag correctly. Disabled ATM
// z-position floats from -1.2 to > 0
// It's OK for carrying but odd for dragging
// Needs workaround to drag correctly. Disabled ATM
GVAR(canDrag) = 0;
GVAR(dragPosition[]) = {0,1,0};
GVAR(dragDirection) = 0;
};

class ReammoBox;
// dropped weapons/gear
// Dropped weapons/gear
class WeaponHolder: ReammoBox {
GVAR(canCarry) = 1;
GVAR(carryPosition[]) = {0,0.5,1};
Expand All @@ -265,7 +268,7 @@ class CfgVehicles {
class FloatingStructure_F;
class Land_Camping_Light_F: FloatingStructure_F {
GVAR(canCarry) = 1;
// if y < 0.9 player gets damage
// If y < 0.9 player gets damaged
GVAR(carryPosition)[] = {0,0.9,1};

GVAR(canDrag) = 1;
Expand All @@ -288,8 +291,7 @@ class CfgVehicles {
GVAR(dragPosition)[] = {0,1,0};
};

// some terrain objects

// Some terrain objects
class Land_CampingTable_F: ThingX {
EGVAR(interaction,replaceTerrainObject) = 1;
GVAR(canCarry) = 1;
Expand Down Expand Up @@ -400,8 +402,8 @@ class CfgVehicles {
GVAR(canDrag) = 1;
};

// static classes need XEH

// Static classes need XEH
class NonStrategic;
class Land_Pallets_F: NonStrategic {
XEH_INHERITED;
Expand Down
3 changes: 2 additions & 1 deletion addons/dragging/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

PREP(canCarry);
PREP(canDrag);
PREP(canDrop);
PREP(canDrop_carry);
PREP(carryObject);
PREP(carryObjectPFH);
PREP(createClone);
PREP(dragObject);
PREP(dragObjectPFH);
PREP(dropClone);
PREP(dropObject);
PREP(dropObject_carry);
PREP(getWeight);
Expand Down
48 changes: 34 additions & 14 deletions addons/dragging/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// by PabstMirror, commy2
#include "script_component.hpp"

// Release object on disconnection. Function is identical to killed
if (isServer) then {
// release object on hard disconnection. Function is identical to killed
addMissionEventHandler ["HandleDisconnect", {_this call FUNC(handleKilled)}];
// 'HandleDisconnect' EH triggers too late
addMissionEventHandler ["PlayerDisconnected", {
private _unit = (getUserInfo (_this select 5)) select 10;

_unit call FUNC(handleKilled);
}];
};

if (!hasInterface) exitWith {};
Expand All @@ -15,28 +20,37 @@ if (isNil "ACE_maxWeightDrag") then {
if (isNil "ACE_maxWeightCarry") then {
ACE_maxWeightCarry = 600;
};

if (isNil QGVAR(maxWeightCarryRun)) then {
GVAR(maxWeightCarryRun) = 50;
};

["isNotDragging", {!((_this select 0) getVariable [QGVAR(isDragging), false])}] call EFUNC(common,addCanInteractWithCondition);
["isNotCarrying", {!((_this select 0) getVariable [QGVAR(isCarrying), false])}] call EFUNC(common,addCanInteractWithCondition);

// release object on player change. This does work when returning to lobby, but not when hard disconnecting.
["unit", FUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler;
// Release object on player change. This does work when returning to lobby, but not when hard disconnecting.
["unit", LINKFUNC(handlePlayerChanged)] call CBA_fnc_addPlayerEventHandler;
["vehicle", {[ACE_player, objNull] call FUNC(handlePlayerChanged)}] call CBA_fnc_addPlayerEventHandler;
["weapon", FUNC(handlePlayerWeaponChanged)] call CBA_fnc_addPlayerEventHandler;
["weapon", LINKFUNC(handlePlayerWeaponChanged)] call CBA_fnc_addPlayerEventHandler;

// Handle waking up dragged unit and falling unconscious while dragging
["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler;

// 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"];

// display event handler
["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler;
_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;

//@todo Captivity?

//Add Keybind:
["ACE3 Common", QGVAR(drag), (localize LSTRING(DragKeybind)), {
// Add Keybind:
["ACE3 Common", QGVAR(drag), LLSTRING(DragKeybind), {
if (!alive ACE_player) exitWith {false};
if !([ACE_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false};

Expand All @@ -45,20 +59,23 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
[ACE_player, ACE_player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject);
false
};

if (ACE_player getVariable [QGVAR(isCarrying), false]) exitWith {
[ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull]] call FUNC(dropObject_carry);
false
};

private _cursor = cursorObject;

if ((isNull _cursor) || {(_cursor distance ACE_player) > 2.6}) exitWith {false};
if (!([ACE_player, _cursor] call FUNC(canDrag))) exitWith {false};
if !([ACE_player, _cursor] call FUNC(canDrag)) exitWith {false};

[ACE_player, _cursor] call FUNC(startDrag);

false
}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND

["ACE3 Common", QGVAR(carry), (localize LSTRING(CarryKeybind)), {
["ACE3 Common", QGVAR(carry), LLSTRING(CarryKeybind), {
if (!alive ACE_player) exitWith {false};
if !([ACE_player, objNull, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false};

Expand All @@ -67,15 +84,18 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
[ACE_player, ACE_player getVariable [QGVAR(draggedObject), objNull]] call FUNC(dropObject);
false
};

if (ACE_player getVariable [QGVAR(isCarrying), false]) exitWith {
[ACE_player, ACE_player getVariable [QGVAR(carriedObject), objNull], true] call FUNC(dropObject_carry);
false
};

private _cursor = cursorObject;

if ((isNull _cursor) || {(_cursor distance ACE_player) > 2.6}) exitWith {false};
if (!([ACE_player, _cursor] call FUNC(canCarry))) exitWith {false};
if !([ACE_player, _cursor] call FUNC(canCarry)) exitWith {false};

[ACE_player, _cursor] call FUNC(startCarry);

false
}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND
2 changes: 1 addition & 1 deletion addons/dragging/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interaction"};
requiredAddons[] = {"ace_interaction","ace_cargo"};
author = ECSTRING(common,ACETeam);
authors[] = {"Garth 'L-H' de Wet", "commy2", "PiZZADOX", "Malbryn"};
url = ECSTRING(main,URL);
Expand Down
19 changes: 10 additions & 9 deletions addons/dragging/functions/fnc_canCarry.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: commy2, Dystopian
* Check if unit can carry the object. Doesn't check weight.
* Checks if unit can carry the object. Doesn't check weight.
*
* Arguments:
* 0: Unit that should do the carrying <OBJECT>
Expand All @@ -11,35 +11,36 @@
* Can the unit carry the object? <BOOL>
*
* Example:
* [player, cursorTarget] call ace_dragging_fnc_canCarry
* [player, cursorObject] call ace_dragging_fnc_canCarry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cursorObject anywhere? That's way too fiddly compared to cursorTarget and returns irrelevant stuff like map props.

*
* Public: No
*/

params ["_unit", "_target"];

if !(alive _target && {_target getVariable [QGVAR(canCarry), false]} && {isNull objectParent _target}) exitWith {false};
if !((alive _target || {_target isKindOf "CAManBase"}) && {_target getVariable [QGVAR(canCarry), false]} && {isNull objectParent _target}) exitWith {false};

if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};

//#2644 - Units with injured legs cannot bear the extra weight of carrying an object
//The fireman carry animation does not slow down for injured legs, so you could carry and run
// #2644 - Units with injured legs cannot bear the extra weight of carrying an object
// The fireman carry animation does not slow down for injured legs, so you could carry and run
if ((_unit getHitPointDamage "HitLegs") >= 0.5) exitWith {false};

// Static weapons need to be empty for carrying (ignore UAV AI)
if (_target isKindOf "StaticWeapon") exitWith {
crew _target findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1
(crew _target) findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1
};

// Units need to be unconscious or limping
if (_target isKindOf "CAManBase") exitWith {
lifeState _target isEqualTo "INCAPACITATED"
|| {_target getHitPointDamage "HitLegs" >= 0.5}
lifeState _target == "INCAPACITATED" ||
{_target getHitPointDamage "HitLegs" >= 0.5} ||
{(animationState _target) in ["", "unconscious", "deadstate"]}
};

// Check max items for WeaponHolders
if (["WeaponHolder", "WeaponHolderSimulated"] findIf {_target isKindOf _x} != -1) exitWith {
(count (weaponCargo _target + magazineCargo _target + itemCargo _target)) <= MAX_DRAGGED_ITEMS
};

true // return
true // Return
15 changes: 8 additions & 7 deletions addons/dragging/functions/fnc_canDrag.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: commy2, Dystopian
* Check if unit can drag the object. Doesn't check weight.
* Checks if unit can drag the object. Doesn't check weight.
*
* Arguments:
* 0: Unit that should do the dragging <OBJECT>
Expand All @@ -11,31 +11,32 @@
* Can the unit drag the object? <BOOL>
*
* Example:
* [player, cursorTarget] call ace_dragging_fnc_canDrag
* [player, cursorObject] call ace_dragging_fnc_canDrag
*
* Public: No
*/

params ["_unit", "_target"];

if !(alive _target && {_target getVariable [QGVAR(canDrag), false]} && {isNull objectParent _target}) exitWith {false};
if !((alive _target || {_target isKindOf "CAManBase"}) && {_target getVariable [QGVAR(canDrag), false]} && {isNull objectParent _target}) exitWith {false};

if !([_unit, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false};

// Static weapons need to be empty for dragging (ignore UAV AI)
if (_target isKindOf "StaticWeapon") exitWith {
crew _target findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1
(crew _target) findIf {getText (configOf _x >> "simulation") != "UAVPilot"} == -1
};

// Units need to be unconscious or limping
if (_target isKindOf "CAManBase") exitWith {
lifeState _target isEqualTo "INCAPACITATED"
|| {_target getHitPointDamage "HitLegs" >= 0.5}
lifeState _target == "INCAPACITATED" ||
{_target getHitPointDamage "HitLegs" >= 0.5} ||
{(animationState _target) in ["", "unconscious", "deadstate"]}
};

// Check max items for WeaponHolders
if (["WeaponHolder", "WeaponHolderSimulated"] findIf {_target isKindOf _x} != -1) exitWith {
(count (weaponCargo _target + magazineCargo _target + itemCargo _target)) <= MAX_DRAGGED_ITEMS
};

true // return
true // Return
Loading