From 8d93bb57439afab591b8cacab84e6e57a6b2c60a Mon Sep 17 00:00:00 2001 From: IndigoFox Date: Fri, 2 Feb 2024 15:13:45 -0800 Subject: [PATCH] adds starting assets and assets at mission end to RPT --- .../assets/byBase/fn_updateAssetsByBase.sqf | 85 +++++++++++++++++-- functions/init/fn_initServer.sqf | 15 +++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/functions/fbcb2/assets/byBase/fn_updateAssetsByBase.sqf b/functions/fbcb2/assets/byBase/fn_updateAssetsByBase.sqf index da06aef..e243526 100644 --- a/functions/fbcb2/assets/byBase/fn_updateAssetsByBase.sqf +++ b/functions/fbcb2/assets/byBase/fn_updateAssetsByBase.sqf @@ -1,5 +1,9 @@ -params [["_isInit", false, [false]]]; +params [ + ["_isInit", false, [false]], + ["_logCurrentAssets", false, [false]] +]; +if (!isServer) exitWith {}; // Get all approved assets on map, find the closest base // Then determine if it's within range @@ -10,6 +14,7 @@ private _allSaved = []; private _assetsAtThisBaseVar = "milsim_fbcb2_assets_assetsAtThisBase"; private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_assetsStartedAtThisBase"; + { private _className = configName _x; private _callsign = getText(_x >> "callsign"); @@ -94,13 +99,81 @@ private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_assetsStartedAtThisBa }; } forEach (_allVehicles select { _x isKindOf "LandVehicle" }); - -// make the asset lists public +//////////////////////////////////////////////////////////////////////// +// publish updated base variables +//////////////////////////////////////////////////////////////////////// { - private _baseAssets = _x getVariable [_assetsAtThisBaseVar, []]; - _x setVariable [_assetsAtThisBaseVar, _baseAssets, true]; + private _base = _x; + + // save current assets + private _baseAssets = _base getVariable [_assetsAtThisBaseVar, []]; + _base setVariable [_assetsAtThisBaseVar, _baseAssets, true]; + + // if init, save starting assets if (_isInit) then { - _x setVariable [_assetsStartedAtThisBaseVar, _baseAssets, true]; + _base setVariable [_assetsStartedAtThisBaseVar, _baseAssets, true]; }; } forEach milsim_baseObjects; +//////////////////////////////////////////////////////////////////////// +// log starting assets if init +// log current assets if requested (for end of mission counts) +//////////////////////////////////////////////////////////////////////// +if !(_isInit || _logCurrentAssets) exitWith {}; + +{ + private _base = _x; + + // get current assets + private _baseAssets = _base getVariable [_assetsAtThisBaseVar, []]; + + // prepare key value for logging + private _baseAssetsHashesPrep = _baseAssets apply { + private _asset = _x; + [ + ["callsign", _asset getVariable [ + "milsim_fbcb2_assets_callsign", + "N/A" + ]], + ["className", typeOf _asset], + ["displayName", (configOf _asset) call BIS_fnc_displayName] + ]; + }; + + _baseAssetsHashesPrep = _baseAssetsHashesPrep call BIS_fnc_consolidateArray; + + private _baseAssetsHashes = []; + { + private _out = createHashMapFromArray (_x#0); + _out set ["count", _x#1]; + _baseAssetsHashes pushBack _out; + } forEach _baseAssetsHashesPrep; + + // if logging current assets + if (_logCurrentAssets) then { + { + [ + "fbcb2_assets", + "CURRENT ASSETS", + [ + ["baseName", [[_base] call milsim_fnc_getNameOfBase]], + ["asset", _x] + ] + ] call milsim_fnc_log; + } forEach _baseAssetsHashes; + }; + + // if init, log starting assets + if (_isInit) then { + { + [ + "fbcb2_assets", + "STARTING ASSETS", + [ + ["baseName", [[_base] call milsim_fnc_getNameOfBase]], + ["asset", _x] + ] + ] call milsim_fnc_log; + } forEach _baseAssetsHashes; + }; +} forEach milsim_baseObjects; \ No newline at end of file diff --git a/functions/init/fn_initServer.sqf b/functions/init/fn_initServer.sqf index e851136..b3f1e57 100644 --- a/functions/init/fn_initServer.sqf +++ b/functions/init/fn_initServer.sqf @@ -8,8 +8,19 @@ publicVariable "milsim_baseObjects"; // init asset stores at bases [true] call milsim_fbcb2_assets_fnc_updateAssetsByBase; -// run update every 5 minutes -[{[false] call milsim_fbcb2_assets_fnc_updateAssetsByBase;}, 60*5] call CBA_fnc_addPerFrameHandler; +// starting 5 minutes after postInit, update asset stores every 5 minutes +[{ + [ + {[false] call milsim_fbcb2_assets_fnc_updateAssetsByBase;}, + 60*5 + ] call CBA_fnc_addPerFrameHandler; +}, 60*5] call CBA_fnc_waitAndExecute; + +// add end mission EH +addMissionEventHandler ["MPEnded", { + // log the "current" asset counts to RPT + [false, true] call milsim_fbcb2_assets_fnc_updateAssetsByBase; +}]; // Initializes the Dynamic Groups framework and groups ["Initialize", [true]] call BIS_fnc_dynamicGroups;