Files

84 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

#include "..\..\script_component.hpp"
/*
* Author: Clarky
* Description:
* Initialises an Ore 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 Ore <INT>
* 3: Current Ore <INT>
* 4: Generation Rate <INT>
*
* Usage:
* [_base, this, 1000, 0, false, 0] call CLRK_fnc_initOreDepot
*
*/
params [["_base", "", ["", objNull]], "_depot", "_maxOre", "_currentOre", "_generationRate"];
if (!isServer) exitWith {};
_depot setVariable ["isOreDepot", true, true];
_depot setVariable ["maxOre", _maxOre, true];
_depot setVariable ["currentOre", _currentOre, 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 "oreDepots";
_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_initOreDepotInteractions",
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 "currentOre";
private _depotMax =
_depot getVariable "maxOre";
private _freeSpace =
_depotMax - _depotCurrent;
private _amount =
(_generationRate min _freeSpace);
_depot setVariable [
"currentOre",
_depotCurrent + _amount,
true
];
},
30,
[_depot, _generationRate]
] call CBA_fnc_addPerFrameHandler;
};