adds starting assets and assets at mission end to RPT

This commit is contained in:
2024-02-02 15:13:45 -08:00
parent b67888f4f1
commit 8d93bb5743
2 changed files with 92 additions and 8 deletions

View File

@@ -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 // Get all approved assets on map, find the closest base
// Then determine if it's within range // Then determine if it's within range
@@ -10,6 +14,7 @@ private _allSaved = [];
private _assetsAtThisBaseVar = "milsim_fbcb2_assets_assetsAtThisBase"; private _assetsAtThisBaseVar = "milsim_fbcb2_assets_assetsAtThisBase";
private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_assetsStartedAtThisBase"; private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_assetsStartedAtThisBase";
{ {
private _className = configName _x; private _className = configName _x;
private _callsign = getText(_x >> "callsign"); private _callsign = getText(_x >> "callsign");
@@ -94,13 +99,81 @@ private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_assetsStartedAtThisBa
}; };
} forEach (_allVehicles select { _x isKindOf "LandVehicle" }); } forEach (_allVehicles select { _x isKindOf "LandVehicle" });
////////////////////////////////////////////////////////////////////////
// make the asset lists public // publish updated base variables
////////////////////////////////////////////////////////////////////////
{ {
private _baseAssets = _x getVariable [_assetsAtThisBaseVar, []]; private _base = _x;
_x setVariable [_assetsAtThisBaseVar, _baseAssets, true];
// save current assets
private _baseAssets = _base getVariable [_assetsAtThisBaseVar, []];
_base setVariable [_assetsAtThisBaseVar, _baseAssets, true];
// if init, save starting assets
if (_isInit) then { if (_isInit) then {
_x setVariable [_assetsStartedAtThisBaseVar, _baseAssets, true]; _base setVariable [_assetsStartedAtThisBaseVar, _baseAssets, true];
}; };
} forEach milsim_baseObjects; } 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;

View File

@@ -8,8 +8,19 @@ publicVariable "milsim_baseObjects";
// init asset stores at bases // init asset stores at bases
[true] call milsim_fbcb2_assets_fnc_updateAssetsByBase; [true] call milsim_fbcb2_assets_fnc_updateAssetsByBase;
// run update every 5 minutes // starting 5 minutes after postInit, update asset stores every 5 minutes
[{[false] call milsim_fbcb2_assets_fnc_updateAssetsByBase;}, 60*5] call CBA_fnc_addPerFrameHandler; [{
[
{[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 // Initializes the Dynamic Groups framework and groups
["Initialize", [true]] call BIS_fnc_dynamicGroups; ["Initialize", [true]] call BIS_fnc_dynamicGroups;