2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-05-31 22:54:57 +00:00
|
|
|
/*
|
2023-08-17 10:02:17 +00:00
|
|
|
* Author: kymckay
|
2023-11-17 23:07:28 +00:00
|
|
|
* Sets the cargo size of any object. Has global effect.
|
2017-05-31 22:54:57 +00:00
|
|
|
* Adds the load action menu if necessary.
|
2023-11-17 23:07:28 +00:00
|
|
|
* A negative size disables the object's cargo interactions.
|
2017-05-31 22:54:57 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2023-11-17 23:07:28 +00:00
|
|
|
* 0: Object <OBJECT> (default: objNull)
|
|
|
|
* 1: Cargo size <NUMBER> (default: nil)
|
2017-05-31 22:54:57 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2023-11-17 23:07:28 +00:00
|
|
|
* [cursorObject, 3] call ace_cargo_fnc_setSize
|
2017-05-31 22:54:57 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
params [
|
2023-11-17 23:07:28 +00:00
|
|
|
["_object", objNull, [objNull]],
|
|
|
|
["_size", nil, [0]] // default can't be a number since all are valid
|
2017-05-31 22:54:57 +00:00
|
|
|
];
|
|
|
|
TRACE_2("setSize",_object,_size);
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
private _oldSize = _object call FUNC(getSizeItem);
|
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// Nothing to do here
|
2023-11-17 23:07:28 +00:00
|
|
|
if (isNil "_size" || {isNull _object} || {_size == _oldSize}) exitWith {};
|
2017-05-31 22:54:57 +00:00
|
|
|
|
|
|
|
// Apply new size globally
|
2023-11-17 23:07:28 +00:00
|
|
|
// Necessary to update value, even if disabled, as API could be used again
|
2017-05-31 22:54:57 +00:00
|
|
|
_object setVariable [QGVAR(canLoad), _size >= 0, true];
|
|
|
|
_object setVariable [QGVAR(size), _size, true];
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Update remaining cargo space, if loaded as cargo in a vehicle
|
|
|
|
private _vehicle = attachedTo _object;
|
|
|
|
|
|
|
|
if (!isNull _vehicle && {_object in (_vehicle getVariable [QGVAR(loaded), []])}) then {
|
|
|
|
private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft);
|
|
|
|
|
|
|
|
_vehicle setVariable [QGVAR(space), _cargoSpace + (_oldSize max 0) - (_size max 0), true]; // don't let negative size items increase space
|
|
|
|
};
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Actions should be added for all future JIP players too, regardless of size
|
|
|
|
private _jipID = format [QGVAR(sizeJipID_%1), hashValue _object];
|
|
|
|
[QGVAR(initObject), _object, _jipID] call CBA_fnc_globalEventJIP;
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Remove from JIP queue if object is deleted
|
|
|
|
if !(_object getVariable [QGVAR(setSizeRemoveJip), false]) then {
|
2017-09-16 20:18:28 +00:00
|
|
|
[_jipID, _object] call CBA_fnc_removeGlobalEventJIP;
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
_object setVariable [QGVAR(setSizeRemoveJip), true, true];
|
2017-05-31 22:54:57 +00:00
|
|
|
};
|