mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3750 from acemod/addLoadToUnitContainer
add framework to add virtual mass to containers
This commit is contained in:
commit
55aa4d08f8
@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
|
PREP(addLoadToUnitContainer);
|
||||||
PREP(getWeight);
|
PREP(getWeight);
|
||||||
PREP(canClimb);
|
PREP(canClimb);
|
||||||
PREP(climb);
|
PREP(climb);
|
||||||
PREP(handleClimb);
|
PREP(handleClimb);
|
||||||
|
PREP(handleVirtualMass);
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
if (!hasInterface) exitWith {};
|
if (!hasInterface) exitWith {};
|
||||||
|
|
||||||
|
["playerChanged", FUNC(handleVirtualMass)] call FUNC(addEventHandler);
|
||||||
|
["playerInventoryChanged", FUNC(handleVirtualMass)] call FUNC(addEventHandler);
|
||||||
|
|
||||||
["ACE3 Movement", QGVAR(climb), localize LSTRING(Climb),
|
["ACE3 Movement", QGVAR(climb), localize LSTRING(Climb),
|
||||||
{
|
{
|
||||||
// Conditions: canInteract
|
// Conditions: canInteract
|
||||||
|
31
addons/movement/functions/fnc_addLoadToUnitContainer.sqf
Normal file
31
addons/movement/functions/fnc_addLoadToUnitContainer.sqf
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Author: commy2
|
||||||
|
* Add (negative numbers to subtract) a virtual mass to a units container.
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: The Unit <OBJECT>
|
||||||
|
* 1: The Container <OBJECT>
|
||||||
|
* 2: The Virtual Load <NUMBER>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* Success? <BOOLEAN>
|
||||||
|
*
|
||||||
|
* Public: No
|
||||||
|
*/
|
||||||
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
params [["_unit", objNull, [objNull]], ["_container", objNull, [objNull]], ["_virtualLoadToAdd", 0, [0]]];
|
||||||
|
|
||||||
|
if !(_container in [
|
||||||
|
uniformContainer _unit,
|
||||||
|
vestContainer _unit,
|
||||||
|
backpackContainer _unit
|
||||||
|
]) exitWith {false};
|
||||||
|
|
||||||
|
private _virtualLoad = (_container getVariable [QGVAR(vLoad), 0]) + _virtualLoadToAdd;
|
||||||
|
_container setVariable [QGVAR(vLoad), _virtualLoad, true];
|
||||||
|
|
||||||
|
// update
|
||||||
|
_unit call FUNC(handleVirtualMass);
|
||||||
|
|
||||||
|
true
|
42
addons/movement/functions/fnc_handleVirtualMass.sqf
Normal file
42
addons/movement/functions/fnc_handleVirtualMass.sqf
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Author: commy2
|
||||||
|
* Recalculate the units loadCoef to emulate a mass added to uniform, vest or backpack.
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: The Unit (usually the player) <OBJECT>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* Nothing
|
||||||
|
*
|
||||||
|
* Public: No
|
||||||
|
*/
|
||||||
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
params ["_unit"];
|
||||||
|
|
||||||
|
// add sum of virtual loads
|
||||||
|
private _virtualLoad = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
_virtualLoad = _virtualLoad + (_x getVariable [QGVAR(vLoad), 0]);
|
||||||
|
} forEach [
|
||||||
|
uniformContainer _unit,
|
||||||
|
vestContainer _unit,
|
||||||
|
backpackContainer _unit
|
||||||
|
];
|
||||||
|
|
||||||
|
// get absolute vanilla load
|
||||||
|
private _absLoad = loadAbs _unit / load _unit;
|
||||||
|
|
||||||
|
// try to preserve other changes to the "LoadCoef" unitTrait
|
||||||
|
private _loadCoef = _unit getVariable QGVAR(loadCoef);
|
||||||
|
|
||||||
|
if (isNil "_loadCoef") then {
|
||||||
|
_loadCoef = _unit getUnitTrait "loadCoef";
|
||||||
|
_unit setVariable [QGVAR(loadCoef), _loadCoef, true];
|
||||||
|
};
|
||||||
|
|
||||||
|
// calc. new "virtual" loadCoef
|
||||||
|
private _virtualLoadCoef = (1 + _virtualLoad / _absLoad) * _loadCoef;
|
||||||
|
|
||||||
|
_unit setUnitTrait ["loadCoef", _virtualLoadCoef];
|
Loading…
Reference in New Issue
Block a user