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 - Code cleanup #9271

Merged
merged 8 commits into from
Jul 23, 2023
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
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));
};
};
};
23 changes: 11 additions & 12 deletions addons/dragging/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CfgVehicles {
GVAR(canDrag) = 0;
};

// ammo boxes
// Ammo boxes
class ThingX;
class Items_base_F;
class ReammoBox_F: ThingX {
Expand All @@ -86,7 +86,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 +160,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 +226,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 +265,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 +288,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 +399,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
1 change: 0 additions & 1 deletion addons/dragging/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PREP(canCarry);
PREP(canDrag);
PREP(canDrop);
Expand Down
67 changes: 13 additions & 54 deletions addons/dragging/XEH_postInit.sqf
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// by PabstMirror, commy2
#include "script_component.hpp"

// Release object on disconnection. Function is identical to killed
if (isServer) then {
// 'HandleDisconnect' EH triggers too late
addMissionEventHandler ["PlayerDisconnected", {
Expand Down Expand Up @@ -29,23 +30,24 @@ 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", {_this call FUNC(handleUnconscious)}] call CBA_fnc_addEventHandler;
// Handle waking up dragged unit and falling unconscious while dragging
["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler;

// display event handler
["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler;
// Display event handler
["MouseZChanged", {(_this select 1) call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler;

[QGVAR(carryingContainerClosed), {
params ["_container", "_owner"];
Expand All @@ -57,13 +59,13 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
_weight = [_container] call FUNC(getWeight);
};

// drop the object if overweight
// Drop the object if overweight
if (_weight > ACE_maxWeightCarry) exitWith {
[_owner, _container] call FUNC(dropObject_carry);
};
private _canRun = [_weight] call FUNC(canRun_carry);

// force walking based on weight
// Force walking based on weight
[_owner, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set);
[_owner, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set);
}] call CBA_fnc_addEventHandler;
Expand All @@ -78,53 +80,10 @@ if (isNil QGVAR(maxWeightCarryRun)) then {
_weight = [_container] call FUNC(getWeight);
};

// drop the object if overweight
// Drop the object if overweight
if (_weight > ACE_maxWeightDrag) exitWith {
[_owner, _container] call FUNC(dropObject);
};
}] call CBA_fnc_addEventHandler;

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

// If we are drag/carrying something right now then just drop it:
if (ACE_player getVariable [QGVAR(isDragging), false]) exitWith {
[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};

[ACE_player, _cursor] call FUNC(startDrag);
false
}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND

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

// If we are drag/carrying something right now then just drop it:
if (ACE_player getVariable [QGVAR(isDragging), false]) exitWith {
[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};

[ACE_player, _cursor] call FUNC(startCarry);
false
}, {}, [-1, [false, false, false]]] call CBA_fnc_addKeybind; // UNBOUND
#include "initKeybinds.sqf"
10 changes: 5 additions & 5 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 @@ -22,19 +22,19 @@ if !(alive _target && {_target getVariable [QGVAR(canCarry), false]} && {isNull

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
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
};

// Units need to be unconscious or limping; Units also need to not be in ragdoll, as that causes desync issues
if (_target isKindOf "CAManBase") exitWith {
!(alive _target != isAwake _target) &&
{lifeState _target isEqualTo "INCAPACITATED" ||
{lifeState _target == "INCAPACITATED" ||
{_target getHitPointDamage "HitLegs" >= 0.5}}
};

Expand Down
6 changes: 3 additions & 3 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 @@ -24,13 +24,13 @@ if !([_unit, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)) exi

// 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; Units also need to not be in ragdoll, as that causes desync issues
if (_target isKindOf "CAManBase") exitWith {
!(alive _target != isAwake _target) &&
{lifeState _target isEqualTo "INCAPACITATED" ||
{lifeState _target == "INCAPACITATED" ||
{_target getHitPointDamage "HitLegs" >= 0.5}}
};

Expand Down
6 changes: 3 additions & 3 deletions addons/dragging/functions/fnc_canDrop.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "script_component.hpp"
/*
* Author: commy2
* Check if unit can drop the object.
* Checks if unit can drop the dragged object.
*
* Arguments:
* 0: Unit that currently drags a object <OBJECT>
* 1: Object that is dragged <OBJECT>
* 0: Unit that is currently dragging an object <OBJECT>
* 1: Object being dragged <OBJECT>
*
* Return Value:
* Can the unit drop the object? <BOOL>
Expand Down
6 changes: 3 additions & 3 deletions addons/dragging/functions/fnc_canDrop_carry.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "script_component.hpp"
/*
* Author: commy2
* Check if unit can drop the carried object.
* Checks if unit can drop the carried object.
*
* Arguments:
* 0: Unit that currently carries a object <OBJECT>
* 1: Object that is carried <OBJECT>
* 0: Unit that is currently carrying an object <OBJECT>
* 1: Object being carried <OBJECT>
*
* Return Value:
* Can the unit drop the object? <BOOL>
Expand Down
Loading