#include "..\..\script_component.hpp" /* * 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 * 1: Depot * 2: Max Materiel * 3: Current Materiel * 4: Generation Rate * * 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 ["generationRate", _generationRate, 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", "_generationRate"]; 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 = (_generationRate min _freeSpace); _depot setVariable [ "currentMateriel", _depotCurrent + _amount, true ]; }, 30, [_depot, _generationRate] ] call CBA_fnc_addPerFrameHandler; };