diff --git a/addons/main/CfgVehicles.hpp b/addons/main/CfgVehicles.hpp index 74a9e40..ca62753 100644 --- a/addons/main/CfgVehicles.hpp +++ b/addons/main/CfgVehicles.hpp @@ -98,6 +98,14 @@ class CfgVehicles { class AnyPerson2 : AnyPerson1 {}; }; }; + class Buoy_base_F; + class GVAR(float): Buoy_base_F { + author = "Ampersand"; + displayName = "Float"; + _generalMacro = QGVAR(float); + model = QPATHTOF(data\float.p3d); + scope = 2; + }; class Man; class CAManBase: Man { class ACE_SelfActions { @@ -133,6 +141,12 @@ class CfgVehicles { condition = QUOTE([_player] call FUNC(canCutLoweringLine)); statement = QUOTE([_player] call FUNC(actionCutLoweringLine)); }; + class GVAR(discardParachute) : GVAR(onChest) { + displayName = CSTRING(DiscardParachute); + exceptions[] = {"isNotSwimming"}; + condition = QUOTE([_player] call FUNC(canDiscardParachute)); + statement = QUOTE([_player] call FUNC(actionDiscardParachute)); + }; }; }; }; diff --git a/addons/main/Stringtable.xml b/addons/main/Stringtable.xml index 82777f6..4bf4073 100644 --- a/addons/main/Stringtable.xml +++ b/addons/main/Stringtable.xml @@ -112,5 +112,9 @@ Cut Lowering Line Cut Lowering Line + + Discard Parachute + Discard Parachute + diff --git a/addons/main/XEH_PREP.hpp b/addons/main/XEH_PREP.hpp index 8e0cae9..807e070 100644 --- a/addons/main/XEH_PREP.hpp +++ b/addons/main/XEH_PREP.hpp @@ -2,9 +2,11 @@ PREP(ace_arsenal_onButtonClick); PREP(ace_arsenal_opened); PREP(ace_arsenal_updateUI); PREP(actionCutLoweringLine); +PREP(actionDiscardParachute); PREP(actionLower); PREP(actionOnBack); PREP(actionOnChest); +PREP(actionOnChest); PREP(actionSwap); PREP(addChestpack); PREP(addItemToChestpack); @@ -15,8 +17,10 @@ PREP(arsenal_postInit); PREP(arsenal_updateUI); PREP(canAddItemToChestpack); PREP(canCutLoweringLine); +PREP(canDiscardParachute); PREP(canMovePack); PREP(canLower); +PREP(checkLandedPFH); PREP(chestpack); PREP(chestpackContainer); PREP(chestpackLoadout); @@ -30,6 +34,7 @@ PREP(EHGetIn); PREP(EHGetOut); PREP(EHHandleDisconnect); PREP(EHKilled); +PREP(floatPack); PREP(itemMass); PREP(moduleAdd); PREP(moduleOnChest); diff --git a/addons/main/XEH_postInit.sqf b/addons/main/XEH_postInit.sqf index 2abff8b..25ac834 100644 --- a/addons/main/XEH_postInit.sqf +++ b/addons/main/XEH_postInit.sqf @@ -15,7 +15,14 @@ // Clear inventory of every backpack in a container [QGVAR(clearCargoBackpacks), {call FUNC(clearCargoBackpacks)}] call CBA_fnc_addEventHandler; +[QGVAR(floatPack), {call FUNC(floatPack)}] call CBA_fnc_addEventHandler; + if (isServer) then { + [QGVAR(hideObjectGlobal), { + params ["_object", "_isHidden"]; + _object hideObjectGlobal _isHidden; + }] call CBA_fnc_addEventHandler; + [QGVAR(handleDisconnect), { addMissionEventHandler ["HandleDisconnect", FUNC(EHHandleDisconnect)]; }] call CBA_fnc_addEventHandler; @@ -24,22 +31,11 @@ if (isServer) then { // holding the backpack have landed [QGVAR(checkLandedPFH), { params ["_ropeTop", "_holder"]; - [{ - params ["_ropeTop", "_pfhID"]; - if (speed _ropeTop < 1 && {getPos _ropeTop # 2 < 1}) exitWith { - deleteVehicle _ropeTop; - [_pfhID] call CBA_fnc_removePerFrameHandler; - }; - }, 1, _ropeTop] call CBA_fnc_addPerFrameHandler; - [{ - params ["_holder", "_pfhID"]; - if (speed _holder < 1 && {getPos _holder # 2 < 1}) exitWith { - private _pos = getPos _holder; - _pos set [2, 0]; - _holder setPos _pos; - [_pfhID] call CBA_fnc_removePerFrameHandler; - }; - }, 1, _holder] call CBA_fnc_addPerFrameHandler; + _ropeTop addEventHandler ["RopeBreak", { + //params ["_ropeTop", "_rope", "_holder"]; + deleteVehicle (_this select 0); + }]; + [{call FUNC(checkLandedPFH)}, 1, _this] call CBA_fnc_addPerFrameHandler; }] call CBA_fnc_addEventHandler; }; diff --git a/addons/main/data/float.p3d b/addons/main/data/float.p3d new file mode 100644 index 0000000..e97743e Binary files /dev/null and b/addons/main/data/float.p3d differ diff --git a/addons/main/functions/fnc_EHGetIn.sqf b/addons/main/functions/fnc_EHGetIn.sqf index 11f9867..ebc8b19 100644 --- a/addons/main/functions/fnc_EHGetIn.sqf +++ b/addons/main/functions/fnc_EHGetIn.sqf @@ -26,9 +26,9 @@ private _chestpack = [_unit] call FUNC(chestpackContainer); if (_veh isKindOf "ParachuteBase") then { _chestpack attachTo [_veh, [0, -0.03, -0.5]]; _chestpack setVectorDirAndUp [[-0.25, -1, 0], [0, 0, 1]]; - _chestpack hideObjectGlobal false; + [QGVAR(hideObjectGlobal), [_chestpack, false]] call CBA_fnc_serverEvent; } else { detach _chestpack; - hideObjectGlobal _chestpack; _chestpack setPos [-10000,-10000,-100]; + [QGVAR(hideObjectGlobal), [_chestpack, true]] call CBA_fnc_serverEvent; }; diff --git a/addons/main/functions/fnc_EHGetOut.sqf b/addons/main/functions/fnc_EHGetOut.sqf index ac828cc..20b0962 100644 --- a/addons/main/functions/fnc_EHGetOut.sqf +++ b/addons/main/functions/fnc_EHGetOut.sqf @@ -27,7 +27,7 @@ private _chestpackClass = [_unit] call FUNC(chestpack); if !(_chestpackClass in GVAR(exceptions)) then { _chestpack attachTo [_unit,[0,-0.03,-0.5],"pelvis"]; _chestpack setVectorDirAndUp [[-0.25,-1,0],[0,0,1]]; - _chestpack hideObjectGlobal false; + [QGVAR(hideObjectGlobal), [_chestpack, false]] call CBA_fnc_serverEvent; }; if (GVAR(walk)) then { diff --git a/addons/main/functions/fnc_EHKilled.sqf b/addons/main/functions/fnc_EHKilled.sqf index c4200db..c3f8e5c 100644 --- a/addons/main/functions/fnc_EHKilled.sqf +++ b/addons/main/functions/fnc_EHKilled.sqf @@ -21,7 +21,8 @@ private _chestpack = [_unit] call FUNC(chestpack); private _chestpackLoadout = [_unit] call FUNC(chestpackLoadout); private _chestpackVariables = [_unit] call FUNC(chestpackVariables); -private _holder = createVehicle ["WeaponHolderSimulated", (getPos _unit), [], 0, "CAN_COLLIDE"]; +private _holder = createVehicle ["WeaponHolderSimulated", [0, 0, 0], [], 0, "CAN_COLLIDE"]; +_holder setPosASL getPosASL _unit; //add pack _holder addBackpackCargoGlobal [_chestpack, 1]; diff --git a/addons/main/functions/fnc_actionCutLoweringLine.sqf b/addons/main/functions/fnc_actionCutLoweringLine.sqf index 7809f39..d246f48 100644 --- a/addons/main/functions/fnc_actionCutLoweringLine.sqf +++ b/addons/main/functions/fnc_actionCutLoweringLine.sqf @@ -16,17 +16,24 @@ */ params ["_unit"]; -private _chute = vehicle _unit; -private _ropeTop = _chute getVariable [QGVAR(loweringLine), objNull]; +private _vehicle = vehicle _unit; +private _ropeTop = _vehicle getVariable [QGVAR(loweringLine), objNull]; +_vehicle setVariable [QGVAR(loweringLine), objNull, true]; if (!isNull _ropeTop) then { private _rope = ropes _ropeTop # 0; - private _holder = ropeAttachedObjects _ropeTop # 0; - _holder ropeDetach _rope; - // ace_fastroping_helper is a helicopter and kind of autorotates down instead - // of falling, much slower than a falling object. Attaching to the holder - // also looks like the rope snapping under tension once cut - _ropeTop attachTo [_holder, [0.1,-0.45,-0.6]]; - - _chute setVariable [QGVAR(loweringLine), objNull, true]; + private _attachedObjects = ropeAttachedObjects _ropeTop; + if (_attachedObjects isEqualTo []) then { + deleteVehicle _ropeTop; + } else { + private _holder = _attachedObjects # 0; + _holder ropeDetach _rope; + // ace_fastroping_helper is a helicopter and kind of autorotates down instead + // of falling, much slower than a falling object. Attaching to the holder + // also looks like the rope snapping under tension once cut + [{ + params ["_ropeTop", "_holder"]; + _ropeTop attachTo [_holder, [0.1,-0.45,-0.6]]; + }, [_ropeTop, _holder]] call CBA_fnc_execNextFrame; + }; }; diff --git a/addons/main/functions/fnc_actionDiscardParachute.sqf b/addons/main/functions/fnc_actionDiscardParachute.sqf new file mode 100644 index 0000000..b42c21a --- /dev/null +++ b/addons/main/functions/fnc_actionDiscardParachute.sqf @@ -0,0 +1,31 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Triggered by the discard-reserve-action. + * Puts the reserve parachute into WeaponHolderSimulated to sink and + * moves the chestpack to back if present. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Nothing + * + * Example: + * [player] call bocr_main_fnc_actionDiscardParachute; + * + * Public: No + */ +params ["_unit"]; + +private _holder = createVehicle ["WeaponHolderSimulated", [0, 0, 0], [], 0, "CAN_COLLIDE"]; +_holder addBackpackCargoGlobal [backpack _unit, 1]; +removeBackpack _unit; +_holder setPosASL (getPosASL _unit vectorAdd vectorDir _unit); + +[QGVAR(floatPack), [_holder]] call CBA_fnc_globalEvent; + +private _chestpack = [_unit] call FUNC(chestpack); +if (_chestpack != "") then { + [_unit] call FUNC(actionOnBack); +}; diff --git a/addons/main/functions/fnc_actionLower.sqf b/addons/main/functions/fnc_actionLower.sqf index 720579d..ce3675a 100644 --- a/addons/main/functions/fnc_actionLower.sqf +++ b/addons/main/functions/fnc_actionLower.sqf @@ -17,19 +17,22 @@ params ["_unit"]; -private _chute = vehicle _unit; +private _vehicle = vehicle _unit; +private _pos = getPosASL _vehicle; // Rope top helper, workaround parachute rope visual bug, allow cut -private _ropeTop = createVehicle ["ace_fastroping_helper", getPos _chute, [], 0, "CAN_COLLIDE"]; -_chute setVariable [QGVAR(loweringLine), _ropeTop, true]; +private _ropeTop = createVehicle ["ace_fastroping_helper", [0, 0, 100], [], 0, "CAN_COLLIDE"]; +_vehicle setVariable [QGVAR(loweringLine), _ropeTop, true]; _ropeTop allowDamage false; -_ropeTop disableCollisionWith _chute; +_ropeTop disableCollisionWith _vehicle; +_ropeTop setPosASL _pos; // Weapon holder with backpack private _holder = [_unit] call FUNC(chestpackToHolder); // Chestpack to holder -_holder disableCollisionWith _chute; -_holder setPos (_chute modelToWorld [0, 1, -1]); -_holder setVelocity velocity _chute; +_holder disableCollisionWith _vehicle; +_holder attachTo [_vehicle, [0, 1, -1]]; +detach _holder; +_holder setVelocity velocity _vehicle; private _rope = ropeCreate [ _ropeTop, [0,0,0], @@ -38,8 +41,8 @@ private _rope = ropeCreate [ ]; [{ - params ["_chute", "_ropeTop"]; - _ropeTop attachTo [_chute, [0,0,0]]; -}, [_chute, _ropeTop]] call CBA_fnc_execNextFrame; + params ["_vehicle", "_ropeTop"]; + _ropeTop attachTo [_vehicle, [0, 0, 0]]; +}, [_vehicle, _ropeTop]] call CBA_fnc_execNextFrame; [QGVAR(checkLandedPFH), [_ropeTop, _holder]] call CBA_fnc_serverEvent; diff --git a/addons/main/functions/fnc_actionOnChest.sqf b/addons/main/functions/fnc_actionOnChest.sqf index 46d2fd4..7774bfb 100644 --- a/addons/main/functions/fnc_actionOnChest.sqf +++ b/addons/main/functions/fnc_actionOnChest.sqf @@ -15,7 +15,7 @@ * Public: No */ -params["_unit"]; +params ["_unit"]; private _backpack = backpack _unit; private _backpackLoad = loadBackpack _unit; diff --git a/addons/main/functions/fnc_canDiscardParachute.sqf b/addons/main/functions/fnc_canDiscardParachute.sqf new file mode 100644 index 0000000..31854a0 --- /dev/null +++ b/addons/main/functions/fnc_canDiscardParachute.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Checks if given unit can discard its reserve parachute + * + * Arguments: + * 0: Unit + * + * Return Value: + * Success + * + * Example: + * [_unit] call bocr_main_fnc_canDiscardParachute; + * + * Public: No + */ + +params ["_unit"]; + +if (GVAR(disabled)) exitWith {false}; + +// Can't move pack while in a parachute +[_unit] call ace_common_fnc_isSwimming && {backpackContainer _unit isKindOf "B_Parachute"} diff --git a/addons/main/functions/fnc_checkLandedPFH.sqf b/addons/main/functions/fnc_checkLandedPFH.sqf new file mode 100644 index 0000000..d5ac4b0 --- /dev/null +++ b/addons/main/functions/fnc_checkLandedPFH.sqf @@ -0,0 +1,33 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Called on server when chestpack is lowered. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Nothing + * + * Example: + * [_ropeTop, _holder] call bocr_main_fnc_checkLandedPFH; + * + * Public: No + */ + + params ["_args", "_pfhID"]; + _args params ["_ropeTop", "_holder"]; + + private _pos = getPos _holder; + private _alt = _pos # 2; + if (speed _holder < 1 && {_alt < 1}) exitWith { + deleteVehicle _ropeTop; + _alt = getPosASL _holder # 2; + if (_alt < 1 && {surfaceIsWater _pos}) then { + [_holder] call bocr_main_fnc_floatPack; + } else { + _holder setVectorUp [0,0,1]; + _holder setPosASL (_pos vectorAdd [0,0,0.1]); + }; + [_pfhID] call CBA_fnc_removePerFrameHandler; + }; diff --git a/addons/main/functions/fnc_chestpackToHolder.sqf b/addons/main/functions/fnc_chestpackToHolder.sqf index 7a0b88e..946f623 100644 --- a/addons/main/functions/fnc_chestpackToHolder.sqf +++ b/addons/main/functions/fnc_chestpackToHolder.sqf @@ -22,7 +22,8 @@ if (_chestpack isEqualTo "") exitWith {objNull}; private _chestpackLoadout = [_unit] call FUNC(chestpackLoadout); private _chestpackVariables = [_unit] call FUNC(chestpackVariables); -private _holder = createVehicle ["WeaponHolderSimulated", (getPos _unit), [], 0, "CAN_COLLIDE"]; +private _holder = createVehicle ["WeaponHolderSimulated", [0, 0, 0], [], 0, "CAN_COLLIDE"]; +_holder setPosASL getPosASL _unit; //add pack _holder addBackpackCargoGlobal [_chestpack, 1]; diff --git a/addons/main/functions/fnc_floatPack.sqf b/addons/main/functions/fnc_floatPack.sqf new file mode 100644 index 0000000..cc5ac4f --- /dev/null +++ b/addons/main/functions/fnc_floatPack.sqf @@ -0,0 +1,54 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Attaches a backpack's weaponholder to a floating helper + * + * Arguments: + * 0: Weapon Holder + * + * Return Value: + * Float + * + * Example: + * [_holder] call bocr_main_fnc_floatPack; + * + * Public: No + */ + +params ["_holder"]; + +// Float model is too big =/ Can't get it to be stable with a smaller model +_pos = getPosASL _holder; +_pos set [2, 0]; +private _depth = ASLToATL (_pos select 2); +if (_depth < 5) exitWith {}; + +// Make pack float +if (isServer) then { + private _float = QGVAR(float) createVehicle [0, 0, 0]; + _float setPosASL (getPosASL _holder vectorAdd [0, 0, -2]); + _holder attachTo [_float, [0, 0, 1.5]]; + _holder setVariable [QGVAR(float), _float, true]; + + _holder addEventHandler ["Deleted", { + params ["_holder"]; + deleteVehicle (_holder getVariable QGVAR(float)); + }]; + _float addEventHandler ["EpeContact", { + //params ["_object1", "_object2", "_selection1", "_selection2", "_force"]; + params ["_float", "_object2"]; + if (isNull _object2) then { + { + deleteVehicle _x; + } forEach attachedObjects _float; + deleteVehicle _float; // Delete when on ocean bottom + }; + }]; +}; + +if (hasInterface) then { + _holder addaction ["Discard", { + // Make pack sink + ((_this # 0) getVariable QGVAR(float) setMass 10000); + }, nil, 7, true, true, "", "firstBackpack _target isKindOf 'B_Parachute'"]; +};