Code cleanup of Dragging module

This commit is contained in:
jokoho48 2015-08-09 14:53:13 +02:00
parent 58fc69c2a6
commit 323832474f
28 changed files with 335 additions and 255 deletions

View File

@ -1,7 +1,7 @@
// by PabstMirror, commy2 // by PabstMirror, commy2
#include "script_component.hpp" #include "script_component.hpp"
[{_this call DFUNC(handleScrollWheel)}] call EFUNC(common,addScrollWheelEventHandler); [DFUNC(handleScrollWheel)] call EFUNC(common,addScrollWheelEventHandler);
if (isNil "ACE_maxWeightDrag") then { if (isNil "ACE_maxWeightDrag") then {
ACE_maxWeightDrag = 800; ACE_maxWeightDrag = 800;
@ -15,11 +15,11 @@ if (isNil "ACE_maxWeightCarry") then {
["isNotCarrying", {!((_this select 0) getVariable [QGVAR(isCarrying), 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. // release object on player change. This does work when returning to lobby, but not when hard disconnecting.
["playerChanged", {_this call DFUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler); ["playerChanged", DFUNC(handlePlayerChanged)] call EFUNC(common,addEventhandler);
["playerVehicleChanged", {[ACE_player, objNull] call DFUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler); ["playerVehicleChanged", {[ACE_player, objNull] call DFUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler);
["playerWeaponChanged", {_this call DFUNC(handlePlayerWeaponChanged)}] call EFUNC(common,addEventhandler); ["playerWeaponChanged", DFUNC(handlePlayerWeaponChanged)] call EFUNC(common,addEventhandler);
// handle waking up dragged unit and falling unconscious while dragging // handle waking up dragged unit and falling unconscious while dragging
["medical_onUnconscious", {_this call DFUNC(handleUnconscious)}] call EFUNC(common,addEventhandler); ["medical_onUnconscious", DFUNC(handleUnconscious)] call EFUNC(common,addEventhandler);
//@todo Captivity? //@todo Captivity?

View File

@ -2,4 +2,4 @@
#include "script_component.hpp" #include "script_component.hpp"
// release object on hard disconnection. Function is identical to killed // release object on hard disconnection. Function is identical to killed
addMissionEventHandler ["HandleDisconnect", {_this call DFUNC(handleKilled)}]; addMissionEventHandler ["HandleDisconnect", DFUNC(handleKilled)];

View File

@ -3,19 +3,19 @@
* *
* Check if unit can carry the object. Doesn't check weight. * Check if unit can carry the object. Doesn't check weight.
* *
* Argument: * Arguments:
* 0: Unit that should do the carrying (Object) * 0: Unit that should do the carrying <OBJECT>
* 1: Object to carry (Object) * 1: Object to carry <OBJECT>
* *
* Return value: * Return Value:
* Can the unit carry the object? (Bool) * Can the unit carry the object? <BOOL>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; private
params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false}; if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};

View File

@ -3,12 +3,14 @@
* *
* Check if unit can drag the object. Doesn't check weight. * Check if unit can drag the object. Doesn't check weight.
* *
* Argument: * Arguments:
* 0: Unit that should do the dragging (Object) * 0: Unit that should do the dragging <OBJECT>
* 1: Object to drag (Object) * 1: Object to drag <OBJECT>
* *
* Return value: * Return Value:
* Can the unit drag the object? (Bool) * Can the unit drag the object? <BOOL>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
@ -22,4 +24,4 @@ if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};
// a static weapon has to be empty for dragging // a static weapon has to be empty for dragging
if ((typeOf _target) isKindOf "StaticWeapon" && {count crew _target > 0}) exitWith {false}; if ((typeOf _target) isKindOf "StaticWeapon" && {count crew _target > 0}) exitWith {false};
alive _target && {vehicle _target == _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 && {vehicle _target == _target} && {_target getVariable [QGVAR(canDrag), false]} && {animationState _target in ["", "unconscious"] || (_target getvariable ["ACE_isUnconscious", false]) || (_target isKindOf "CAManBase" && {(_target getHitPointDamage "HitLegs") > 0.4})};

View File

@ -3,19 +3,18 @@
* *
* Check if unit can drop the object. * Check if unit can drop the object.
* *
* Argument: * Arguments:
* 0: Unit that currently drags a object (Object) * 0: Unit that currently drags a object <OBJECT>
* 1: Object that is dragged (Object) * 1: Object that is dragged <OBJECT>
* *
* Return value: * Return Value:
* Can the unit drop the object? (Bool) * Can the unit drop the object? <BOOL>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
if !([_unit, _target, ["isNotDragging"]] call EFUNC(common,canInteractWith)) exitWith {false}; if !([_unit, _target, ["isNotDragging"]] call EFUNC(common,canInteractWith)) exitWith {false};

View File

@ -3,19 +3,18 @@
* *
* Check if unit can drop the carried object. * Check if unit can drop the carried object.
* *
* Argument: * Arguments:
* 0: Unit that currently carries a object (Object) * 0: Unit that currently carries a object <OBJECT>
* 1: Object that is carried (Object) * 1: Object that is carried <OBJECT>
* *
* Return value: * Return Value:
* Can the unit drop the object? (Bool) * Can the unit drop the object? <BOOL>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
if !([_unit, _target, ["isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false}; if !([_unit, _target, ["isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {false};

View File

@ -3,19 +3,18 @@
* *
* Carry an object. * Carry an object.
* *
* Argument: * Arguments:
* 0: Unit that should do the carrying (Object) * 0: Unit that should do the carrying <OBJECT>
* 1: Object to carry (Object) * 1: Object to carry <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// get attachTo offset and direction. // get attachTo offset and direction.
private ["_position", "_direction"]; private ["_position", "_direction"];

View File

@ -1,4 +1,16 @@
// by commy2 /*
* Author: commy2
*
* PFH for Crarry Object
*
* Arguments:
* ?
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#ifdef DEBUG_ENABLED_DRAGGING #ifdef DEBUG_ENABLED_DRAGGING
@ -6,16 +18,15 @@
#endif #endif
private ["_unit", "_target"]; private ["_unit", "_target"];
params ["_args", "_idPFH"];
_unit = _this select 0 select 0; _args params ["_unit","_target"];
_target = _this select 0 select 1;
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith { if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled)) // drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled))
if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then { if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then {
[_unit, _target] call FUNC(dropObject_carry); [_unit, _target] call FUNC(dropObject_carry);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };

View File

@ -3,28 +3,25 @@
* *
* Drag an object. Called from ace_dragging_fnc_startDrag * Drag an object. Called from ace_dragging_fnc_startDrag
* *
* Argument: * Arguments:
* 0: Unit that should do the dragging (Object) * 0: Unit that should do the dragging <OBJECT>
* 1: Object to drag (Object) * 1: Object to drag <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; private ["_position", "_direction", "_offset", "_actionID"];
params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// get attachTo offset and direction. // get attachTo offset and direction.
private ["_position", "_direction"];
_position = _target getVariable [QGVAR(dragPosition), [0, 0, 0]]; _position = _target getVariable [QGVAR(dragPosition), [0, 0, 0]];
_direction = _target getVariable [QGVAR(dragDirection), 0]; _direction = _target getVariable [QGVAR(dragDirection), 0];
// add height offset of model // add height offset of model
private "_offset";
_offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2); _offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2);
_position = _position vectorAdd [0, 0, _offset]; _position = _position vectorAdd [0, 0, _offset];
@ -41,7 +38,6 @@ _unit setVariable [QGVAR(isDragging), true, true];
_unit setVariable [QGVAR(draggedObject), _target, true]; _unit setVariable [QGVAR(draggedObject), _target, true];
// add scrollwheel action to release object // add scrollwheel action to release object
private "_actionID";
_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1];
if (_actionID != -1) then { if (_actionID != -1) then {
@ -50,7 +46,7 @@ if (_actionID != -1) then {
_actionID = _unit addAction [ _actionID = _unit addAction [
format ["<t color='#FF0000'>%1</t>", localize LSTRING(Drop)], format ["<t color='#FF0000'>%1</t>", localize LSTRING(Drop)],
QUOTE([ARR_2(_this select 0, (_this select 0) getVariable [ARR_2(QUOTE(QGVAR(draggedObject)),objNull)])] call FUNC(dropObject)), QUOTE(param ['_unit']; [ARR_2('_unit', ('_unit') getVariable [ARR_2(QUOTE(QGVAR(draggedObject)),objNull)])] call FUNC(dropObject)),
nil, nil,
20, 20,
false, false,

View File

@ -1,21 +1,31 @@
// by commy2 /*
* Author: commy2
*
* PFH for Drag Object
*
* Arguments:
* ?
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#ifdef DEBUG_ENABLED_DRAGGING #ifdef DEBUG_ENABLED_DRAGGING
systemChat format ["%1 dragObjectPFH running", ACE_time]; systemChat format ["%1 dragObjectPFH running", ACE_time];
#endif #endif
private ["_unit", "_target"]; params ["_args", "_idPFH"];
_args params ["_unit", "_target"];
_unit = _this select 0 select 0;
_target = _this select 0 select 1;
if !(_unit getVariable [QGVAR(isDragging), false]) exitWith { if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled)) // drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled))
if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then { if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then {
[_unit, _target] call FUNC(dropObject); [_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };

View File

@ -3,19 +3,18 @@
* *
* Drop a dragged object. * Drop a dragged object.
* *
* Argument: * Arguments:
* 0: Unit that drags the other object (Object) * 0: Unit that drags the other object <OBJECT>
* 1: Dragged object to drop (Object) * 1: Dragged object to drop <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// remove scroll wheel action // remove scroll wheel action
_unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]); _unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]);

View File

@ -3,19 +3,18 @@
* *
* Drop a carried object. * Drop a carried object.
* *
* Argument: * Arguments:
* 0: Unit that carries the other object (Object) * 0: Unit that carries the other object <OBJECT>
* 1: Carried object to drop (Object) * 1: Carried object to drop <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// remove scroll wheel action // remove scroll wheel action
_unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]); _unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]);

View File

@ -1,54 +1,45 @@
/* /*
Name: AGM_Drag_fnc_GetWeight * Author: L-H, edited by commy2, rewritten by joko // Jonas
*
Author(s): * Returns the weight of a crate.
L-H, edited by commy2 *
* Arguments:
Description: * Crate to get weight of <OBJECT>
Returns the weight of a crate. *
* Return Value:
Parameters: * Total Weight <NUMBER>
0: OBJECT - Crate to get weight of *
* Example:
Returns: * _weight = Crate1 call ace_dragging_fnc_getweight;
NUMBER - Weight *
* Public: No
Example:
_weight = Crate1 call AGM_Drag_fnc_GetWeight;
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private "_object"; private "_totalWeight";
_object = _this select 0; // Initialize the total weight.
private ["_totalWeight", "_fnc","_fnc_Extra"];
_totalWeight = 0; _totalWeight = 0;
_fnc_Extra = {
private ["_weight", "_items"];
_items = _this select 0;
_weight = 0;
{
_weight = _weight + (getNumber (ConfigFile >> (_this select 1) >> _x >> (_this select 2) >> "mass") * ((_items select 1) select _foreachIndex));
} foreach (_items select 0);
_weight
};
_fnc = {
private ["_weight", "_items"];
_items = _this select 0;
_weight = 0;
{
_weight = _weight + (getNumber (ConfigFile >> (_this select 1) >> _x >> "mass") * ((_items select 1) select _foreachIndex));
} foreach (_items select 0);
_weight
};
_totalWeight = ([getMagazineCargo _object, "CfgMagazines"] call _fnc);
_totalWeight = _totalWeight + ([getItemCargo _object, "CfgWeapons", "ItemInfo"] call _fnc_Extra);
_totalWeight = _totalWeight + ([getWeaponCargo _object, "CfgWeapons", "WeaponSlotsInfo"] call _fnc_Extra);
_totalWeight = _totalWeight + ([getBackpackCargo _object, "CfgVehicles"] call _fnc);
_totalWeight = _totalWeight * 0.5; // Mass in Arma isn't an exact amount but rather a volume/weight value. This attempts to work around that by making it a usable value. (sort of). // Cycle through all item types with their assigned config paths.
{
_x params["_items","_getConfigCode"];
_items params ["_item", "_count"]
// Cycle through all items and read their mass out of the config.
{
// Multiply mass with amount of items and add the mass to the total weight.
_totalWeight = _totalWeight + (getNumber ((call _getConfigCode) >> "mass") * (_count select _forEachIndex));
} forEach _item;
true
} count [
[getMagazineCargo _this, {configFile >> "CfgMagazines" >> _x}],
[getBackpackCargo _this, {configFile >> "CfgVehicles" >> _x}],
[getItemCargo _this, {configFile >> "CfgWeapons" >> _x >> "ItemInfo"}],
[getWeaponCargo _this, {configFile >> "CfgWeapons" >> _x >> "WeaponSlotsInfo"}]
];
_totalWeight // add Weight of create to totalWeight
_totalWeight = _totalWeight + (getNumber (configFile >> "CfgVehicles" >> _this >> "mass"));
// Mass in Arma isn't an exact amount but rather a volume/weight value. This attempts to work around that by making it a usable value. (sort of).
_totalWeight * 0.5

View File

@ -1,4 +1,20 @@
// by commy2 /*
* Author: commy2
*
* Handle the Animaion for a Unit for Dragging Module
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Animaion <STRING>
*
* Return Value:
* None
*
* Example:
* [_unit, "amovpercmstpsnonwnondnon"] call ace_dragging_fnc_handleAnimChanged;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_anim"]; private ["_unit", "_anim"];

View File

@ -1,9 +1,22 @@
// by commy2 /*
* Author: commy2
*
* Handle the Kill of the Dragger
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_unit] call ace_dragging_fnc_handleKilled;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private "_unit"; params ["_unit"];
_unit = _this select 0;
if (_unit getVariable [QGVAR(isDragging), false]) then { if (_unit getVariable [QGVAR(isDragging), false]) then {
private "_draggedObject"; private "_draggedObject";

View File

@ -1,10 +1,23 @@
// by commy2 /*
* Author: commy2
*
* Handle the Event if player is Changed
*
* Arguments:
* 0: New Player Unit <OBJECT>
* 1: Old Player Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_unitNew, _unitOld] call ace_dragging_fnc_handlePlayerChanged;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_newPlayer", "_oldPlayer"]; params ["_newPlayer", "_oldPlayer"];
_newPlayer = _this select 0;
_oldPlayer = _this select 1;
{ {
if (_x getVariable [QGVAR(isDragging), false]) then { if (_x getVariable [QGVAR(isDragging), false]) then {

View File

@ -1,10 +1,23 @@
// by commy2 /*
* Author: commy2
*
* Handle the Weapon Changed Event
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return Value:
* None
*
* Example:
* [_unit, _currentWeapon] call ace_dragging_fnc_handlePlayerWeaponChanged;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_weapon"]; params ["_unit", "_weapon"];
_unit = _this select 0;
_weapon = _this select 1;
if (_unit getVariable [QGVAR(isDragging), false]) then { if (_unit getVariable [QGVAR(isDragging), false]) then {

View File

@ -3,38 +3,38 @@
* *
* Handles raising and lowering the dragged weapon to be able to place it on top of objects. * Handles raising and lowering the dragged weapon to be able to place it on top of objects.
* *
* Argument: * Arguments:
* 0: Scroll amount (Number) * 0: Scroll amount <NUMBER>
* *
* Return value: * Return Value:
* Handled or not. (Bool) * Handled or not. <BOOL>
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_carriedItem", "_position", "_maxHeight", ]
params ["_scrollAmount"];
// requires modifier key to be hold down // requires modifier key to be hold down
if (GETMVAR(ACE_Modifier,0) == 0) exitWith {false}; if (GETMVAR(ACE_Modifier,0) == 0) exitWith {false};
private "_unit";
_unit = ACE_player; _unit = ACE_player;
// EH is always assigned. Exit and don't overwrite input if not carrying // EH is always assigned. Exit and don't overwrite input if not carrying
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {false}; if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {false};
private "_scrollAmount";
_scrollAmount = _this select 0;
// move carried item 15 cm per scroll interval // move carried item 15 cm per scroll interval
_scrollAmount = _scrollAmount * 0.15; _scrollAmount = _scrollAmount * 0.15;
private "_carriedItem";
_carriedItem = _unit getVariable [QGVAR(carriedObject), objNull]; _carriedItem = _unit getVariable [QGVAR(carriedObject), objNull];
//disabled for persons //disabled for persons
if (_carriedItem isKindOf "CAManBase") exitWith {false}; if (_carriedItem isKindOf "CAManBase") exitWith {false};
private ["_position", "_maxHeight"];
_position = getPosATL _carriedItem; _position = getPosATL _carriedItem;
_maxHeight = (_unit modelToWorldVisual [0,0,0]) select 2; _maxHeight = (_unit modelToWorldVisual [0,0,0]) select 2;

View File

@ -1,17 +1,29 @@
// by commy2 /*
* Author: commy2
*
* Handle the Unconscious of a Unit while Dragging
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_unit] call ace_dragging_fnc_handlePlayerWeaponChanged;
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_isUnconscious"]; private ["_player", "_draggedObject", "_carriedObject"];
_unit = _this select 0; params ["_unit"];
_isUnconscious = _this select 1;
private "_player";
_player = ACE_player; _player = ACE_player;
if (_player getVariable [QGVAR(isDragging), false]) then { if (_player getVariable [QGVAR(isDragging), false]) then {
private "_draggedObject";
_draggedObject = _player getVariable [QGVAR(draggedObject), objNull]; _draggedObject = _player getVariable [QGVAR(draggedObject), objNull];
// handle falling unconscious // handle falling unconscious
@ -28,7 +40,6 @@ if (_player getVariable [QGVAR(isDragging), false]) then {
if (_player getVariable [QGVAR(isCarrying), false]) then { if (_player getVariable [QGVAR(isCarrying), false]) then {
private "_carriedObject";
_carriedObject = _player getVariable [QGVAR(carriedObject), objNull]; _carriedObject = _player getVariable [QGVAR(carriedObject), objNull];
// handle falling unconscious // handle falling unconscious

View File

@ -4,32 +4,29 @@
* Initialize variables for drag or carryable objects. Called from init EH. * Initialize variables for drag or carryable objects. Called from init EH.
* *
* Argument: * Argument:
* 0: Any object (Object) * 0: Any object <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private "_object"; private ["_position", "_direction", "config"];
_object = _this select 0; params ["_object"];
private "_config";
_config = configFile >> "CfgVehicles" >> typeOf _object; _config = configFile >> "CfgVehicles" >> typeOf _object;
if (getNumber (_config >> QGVAR(canDrag)) == 1) then { if (getNumber (_config >> QGVAR(canDrag)) == 1) then {
private ["_position", "_direction"];
_position = getArray (_config >> QGVAR(dragPosition)); _position = getArray (_config >> QGVAR(dragPosition));
_direction = getNumber (_config >> QGVAR(dragDirection)); _direction = getNumber (_config >> QGVAR(dragDirection));
[_object, true, _position, _direction] call FUNC(setDraggable); [_object, true, _position, _direction] call FUNC(setDraggable);
}; };
if (getNumber (_config >> QGVAR(canCarry)) == 1) then { if (getNumber (_config >> QGVAR(canCarry)) == 1) then
private ["_position", "_direction"];
_position = getArray (_config >> QGVAR(carryPosition)); _position = getArray (_config >> QGVAR(carryPosition));
_direction = getNumber (_config >> QGVAR(carryDirection)); _direction = getNumber (_config >> QGVAR(carryDirection));

View File

@ -4,16 +4,16 @@
* Initialize variables for drag or carryable persons. Called from init EH. * Initialize variables for drag or carryable persons. Called from init EH.
* *
* Argument: * Argument:
* 0: Any Unit (Object) * 0: Unit <OBJECT>
* *
* Return value: * Return value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private "_unit"; params ["_unit"];
_unit = _this select 0;
[_unit, true, [0,1.1,0.092], 180] call FUNC(setDraggable); [_unit, true, [0,1.1,0.092], 180] call FUNC(setDraggable);
[_unit, true, [0.4,-0.1,-1.25], 195] call FUNC(setCarryable); // hard-coded selection: "LeftShoulder" [_unit, true, [0.4,-0.1,-1.25], 195] call FUNC(setCarryable); // hard-coded selection: "LeftShoulder"

View File

@ -1,6 +1,16 @@
// by commy2 /*
* Author: commy2
private "_object"; *
_object = _this select 0; * Check if Object is Overlapping
*
* Argument:
* 0: Object <OBJECT>
*
* Return value:
* <BOOL>
*
* Public: No
*/
params ["_object"];
(getPosATL _object select 2) - (getPos _object select 2) > 1E-5 (getPosATL _object select 2) - (getPos _object select 2) > 1E-5

View File

@ -4,25 +4,21 @@
* Enable the object to be carried. * Enable the object to be carried.
* *
* Argument: * Argument:
* 0: Any object (Object) * 0: Any object <OBJECT>
* 1: true to enable carrying, false to disable (Bool) * 1: true to enable carrying, false to disable <BOOL>
* 2: Position offset for attachTo command (Array, optinal; default: [0,1,1]) * 2: Position offset for attachTo command <ARRAY> (default: [0,1,1])
* 3: Direction in degree to rotate the object after attachTo (Number, optional; default: 0) * 3: Direction in degree to rotate the object after attachTo <NUMBER> (default: 0)
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_carryAction", "_dropAction", "_object", "_enableCarry", "_position", "_direction"]; private ["_carryAction", "_dropAction", "_type", "_initializedClasses"];
//IGNORE_PRIVATE_WARNING("_player", "_target");
_this resize 4; params ["_object", "_enableCarry", "_position", "_direction"];
_object = _this select 0;
_enableCarry = _this select 1;
_position = _this select 2;
_direction = _this select 3;
if (isNil "_position") then { if (isNil "_position") then {
_position = _object getVariable [QGVAR(carryPosition), [0,1,1]]; _position = _object getVariable [QGVAR(carryPosition), [0,1,1]];
@ -38,8 +34,6 @@ _object setVariable [QGVAR(carryPosition), _position];
_object setVariable [QGVAR(carryDirection), _direction]; _object setVariable [QGVAR(carryDirection), _direction];
// add action to class if it is not already present // add action to class if it is not already present
private ["_type", "_initializedClasses"];
_type = typeOf _object; _type = typeOf _object;
_initializedClasses = GETGVAR(initializedClasses_carry,[]); _initializedClasses = GETGVAR(initializedClasses_carry,[]);

View File

@ -10,19 +10,15 @@
* 3: Direction in degree to rotate the object after attachTo (Number, optional; default: 0) * 3: Direction in degree to rotate the object after attachTo (Number, optional; default: 0)
* *
* Return value: * Return value:
* NONE. * None
*
* Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_dragAction", "_dropAction", "_object", "_enableDrag", "_position", "_direction"]; private ["_dragAction", "_dropAction", "_type", "_initializedClasses"];
//IGNORE_PRIVATE_WARNING("_player", "_target"); //IGNORE_PRIVATE_WARNING("_player", "_target");
params ["_object", "_enableDrag", "_position", "_direction"];
_this resize 4;
_object = _this select 0;
_enableDrag = _this select 1;
_position = _this select 2;
_direction = _this select 3;
if (isNil "_position") then { if (isNil "_position") then {
_position = _object getVariable [QGVAR(dragPosition), [0,0,0]]; _position = _object getVariable [QGVAR(dragPosition), [0,0,0]];
@ -38,8 +34,6 @@ _object setVariable [QGVAR(dragPosition), _position];
_object setVariable [QGVAR(dragDirection), _direction]; _object setVariable [QGVAR(dragDirection), _direction];
// add action to class if it is not already present // add action to class if it is not already present
private ["_type", "_initializedClasses"];
_type = typeOf _object; _type = typeOf _object;
_initializedClasses = GETGVAR(initializedClasses,[]); _initializedClasses = GETGVAR(initializedClasses,[]);

View File

@ -3,29 +3,28 @@
* *
* Start the carrying process. * Start the carrying process.
* *
* Argument: * Arguments:
* 0: Unit that should do the carrying (Object) * 0: Unit that should do the carrying <OBJECT>
* 1: Object to carry (Object) * 1: Object to carry <OBJECT>
* *
* Return value: * Return Value:
* NONE. * None
*
* Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; private ["_weight", "_timer"];
_unit = _this select 0; params ["_unit", "_target"];
_target = _this select 1;
// check weight // check weight
private "_weight";
_weight = [_target] call FUNC(getWeight); _weight = [_target] call FUNC(getWeight);
if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith { if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith {
[localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured);
}; };
private "_timer";
_timer = ACE_time + 5; _timer = ACE_time + 5;
// handle objects vs persons // handle objects vs persons

View File

@ -1,25 +1,34 @@
// by commy2 /*
* Author: commy2
*
* Carry PFH
*
* Arguments:
* ?
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#ifdef DEBUG_ENABLED_DRAGGING #ifdef DEBUG_ENABLED_DRAGGING
systemChat format ["%1 startCarryPFH running", ACE_time]; systemChat format ["%1 startCarryPFH running", ACE_time];
#endif #endif
private ["_unit", "_target", "_timeOut"]; params ["_args", "_idPFH"];
_args params ["_unit", "_target", "_timeOut"];
_unit = _this select 0 select 0;
_target = _this select 0 select 1;
_timeOut = _this select 0 select 2;
// handle aborting carry // handle aborting carry
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith { if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled)) // same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled))
if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then { if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then {
[_unit, _target] call FUNC(dropObject); [_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// handle persons vs objects // handle persons vs objects
@ -27,11 +36,11 @@ if (_target isKindOf "CAManBase") then {
if (ACE_time > _timeOut) exitWith { if (ACE_time > _timeOut) exitWith {
[_unit, _target] call FUNC(carryObject); [_unit, _target] call FUNC(carryObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
} else { } else {
if (ACE_time > _timeOut) exitWith { if (ACE_time > _timeOut) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
// drop if in timeout // drop if in timeout
private "_draggedObject"; private "_draggedObject";
@ -43,7 +52,7 @@ if (_target isKindOf "CAManBase") then {
if (stance _unit == "STAND") exitWith { if (stance _unit == "STAND") exitWith {
[_unit, _target] call FUNC(carryObject); [_unit, _target] call FUNC(carryObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
}; };

View File

@ -4,18 +4,15 @@
* Start the dragging process. * Start the dragging process.
* *
* Argument: * Argument:
* 0: Unit that should do the dragging (Object) * 0: Unit that should do the dragging <OBJECT>
* 1: Object to drag (Object) * 1: Object to drag <OBJECT>
* *
* Return value: * Return value:
* NONE. * None
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unit", "_target"]; params ["_unit", "_target"];
_unit = _this select 0;
_target = _this select 1;
// check weight // check weight
private "_weight"; private "_weight";

View File

@ -1,30 +1,39 @@
// by commy2 /*
* Author: commy2
*
* Drag PFH
*
* Arguments:
* ?
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp" #include "script_component.hpp"
#ifdef DEBUG_ENABLED_DRAGGING #ifdef DEBUG_ENABLED_DRAGGING
systemChat format ["%1 startDragPFH running", ACE_time]; systemChat format ["%1 startDragPFH running", ACE_time];
#endif #endif
private ["_unit", "_target", "_timeOut"]; params ["_args", "_idPFH"];
_args params ["_unit", "_target", "_timeOut"];
_unit = _this select 0 select 0;
_target = _this select 0 select 1;
_timeOut = _this select 0 select 2;
// handle aborting drag // handle aborting drag
if !(_unit getVariable [QGVAR(isDragging), false]) exitWith { if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled)) // same as dragObjectPFH, checks if object is deleted or dead OR (target moved away from carrier (weapon disasembled))
if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then { if ((!([_target] call EFUNC(common,isAlive))) || {(_unit distance _target) > 10}) then {
[_unit, _target] call FUNC(dropObject); [_unit, _target] call FUNC(dropObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
// timeout. Do nothing. Quit. ACE_time, because anim length is linked to ingame ACE_time. // timeout. Do nothing. Quit. ACE_time, because anim length is linked to ingame ACE_time.
if (ACE_time > _timeOut) exitWith { if (ACE_time > _timeOut) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
// drop if in timeout // drop if in timeout
private "_draggedObject"; private "_draggedObject";
@ -36,5 +45,5 @@ if (ACE_time > _timeOut) exitWith {
if (animationState _unit in DRAG_ANIMATIONS) exitWith { if (animationState _unit in DRAG_ANIMATIONS) exitWith {
[_unit, _target] call FUNC(dragObject); [_unit, _target] call FUNC(dragObject);
[_this select 1] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };