add framework to add virtual mass to containers

This commit is contained in:
commy2 2016-05-03 18:12:47 +02:00
parent 0c55d0ca06
commit 8585ea5688
4 changed files with 78 additions and 0 deletions

View File

@ -1,5 +1,7 @@
PREP(addLoadToUnitContainer);
PREP(getWeight);
PREP(canClimb);
PREP(climb);
PREP(handleClimb);
PREP(handleVirtualMass);

View File

@ -3,6 +3,9 @@
if (!hasInterface) exitWith {};
["playerChanged", FUNC(handleVirtualMass)] call FUNC(addEventHandler);
["playerInventoryChanged", FUNC(handleVirtualMass)] call FUNC(addEventHandler);
["ACE3 Movement", QGVAR(climb), localize LSTRING(Climb),
{
// Conditions: canInteract

View 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 <OBEJCT>
* 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];
// update
_unit call FUNC(handleVirtualMass);
true

View 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];