Files
Clarksons_Logi_Framework/Addons/logistics/functions/init/fn_initMaterielDepot.sqf
T

83 lines
2.1 KiB
Plaintext
Raw Normal View History

/*
* Author: Clarky
* Description:
* Initialises a Materiel Depot. Intended to be called as a function by internal processes, or exposed as a module in Eden and Zeus
*
* Arguments:
* 0: Linked HQ <OBJECT>
* 1: Depot <OBJECT>
* 2: Max Materiel <INT>
* 3: Current Materiel <INT>
* 4: Generation Rate <INT>
*
* Usage:
* [_base, this, 1000, 0, false, 0] call CLRK_fnc_initSupplyDepot
*
*/
params [["_base", "", ["", objNull]], "_depot", "_maxMateriel", "_currentMateriel", "_generationRate"];
if (!isServer) exitWith {};
_depot setVariable ["isSupplyDepot", true, true];
_depot setVariable ["maxMateriel", _maxMateriel, true];
_depot setVariable ["currentMateriel", _currentMateriel, true];
_depot setVariable ["materielRate", _materielRate, true];
// Wait to run the initialisaion for mission start -- Prevents base push until HQ object is initialised
if (_base isNotEqualTo "") then {
[
{
params ["_depot", "_base"];
_depot setVariable ["hq", _base, true];
private _baseDetails = _base getVariable "baseDetails";
private _depots = _baseDetails get "supplyDepots";
_depots pushBack _depot;
},
[_depot, _base],
2
] call CBA_fnc_waitAndExecute;
};
// Set object to invulnerable -- May be removed once base building is fully implemented.
[_depot, false] remoteExec ["allowDamage", 0, true];
[_depot] remoteExecCall [
"CLF_fnc_initSupplyDepotInteractions",
0,
true
];
// If a generation rate was supplied, spawn in per frame handler to generate resources every 30 seconds
if (_generationRate > 0) then {
[
{
params ["_args", "_handle"];
_args params ["_depot", "_materielRate"];
if (!alive _depot || isNull _depot) then {
[_handle] call CBA_fnc_removePerFrameHandler;
};
private _depotCurrent =
_depot getVariable "currentMateriel";
private _depotMax =
_depot getVariable "maxMateriel";
private _freeSpace =
_depotMax - _depotCurrent;
private _amount =
(_materielRate min _freeSpace);
_depot setVariable [
"currentMateriel",
_depotCurrent + _amount,
true
];
},
30,
[_depot, _materielRate]
] call CBA_fnc_addPerFrameHandler;
};