wip, fbcb2_assets, init, util
This commit is contained in:
181
framework/fbcb2_assets/functions/fn_updateAssetsByBase.sqf
Normal file
181
framework/fbcb2_assets/functions/fn_updateAssetsByBase.sqf
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "..\script_component.hpp"
|
||||
|
||||
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
|
||||
// If it is, add it to the base's assets list
|
||||
// This is to ensure bases with overlapping detection range don't have duplicate assets
|
||||
private _allVehicles = vehicles;
|
||||
private _allSaved = [];
|
||||
|
||||
private _assetsAtThisBaseVar = QGVAR(assetsAtThisBase);
|
||||
private _assetsStartedAtThisBaseVar = QGVAR(assetsStartedAtThisBase);
|
||||
|
||||
{
|
||||
private _className = configName _x;
|
||||
private _callsign = getText(_x >> "callsign");
|
||||
private _found = _allVehicles select { typeOf _x == _className };
|
||||
{
|
||||
private _asset = _x;
|
||||
// avoid duplicates
|
||||
if (_asset in _allSaved) then {continue};
|
||||
private _closestBase = [_asset] call EFUNC(util,getNearestBase);
|
||||
if (isNull _closestBase) then {
|
||||
// no base found
|
||||
continue;
|
||||
};
|
||||
if (
|
||||
_asset distance _closestBase >
|
||||
milsim_fbcb2_assets_setting_detectionRangeFromBase
|
||||
) then {
|
||||
// not within range
|
||||
continue;
|
||||
};
|
||||
|
||||
_asset setVariable [QGVAR(callsign), _callsign, true];
|
||||
|
||||
// add to base's assets list
|
||||
private _baseAssets = _closestBase getVariable [_assetsAtThisBaseVar, []];
|
||||
_baseAssets pushBackUnique _asset;
|
||||
// broadcast later so we're not spamming network
|
||||
_closestBase setVariable [
|
||||
_assetsAtThisBaseVar,
|
||||
_baseAssets
|
||||
];
|
||||
|
||||
// if this is the init, set the base's assets started at this base
|
||||
if (_isInit) then {
|
||||
// broadcast later so we're not spamming network
|
||||
_closestBase setVariable [
|
||||
_assetsStartedAtThisBaseVar,
|
||||
_baseAssets
|
||||
];
|
||||
};
|
||||
|
||||
_allSaved pushBack _asset;
|
||||
} forEach _found;
|
||||
} forEach ((missionConfigFile >> "ApprovedAssets") call BIS_fnc_returnChildren);
|
||||
|
||||
// Add all ground vehicles (LandVehicle)
|
||||
{
|
||||
private _asset = _x;
|
||||
// avoid duplicates
|
||||
if (_asset in _allSaved) then {continue};
|
||||
|
||||
private _closestBase = [_asset] call EFUNC(util,getNearestBase);
|
||||
if (isNull _closestBase) then {
|
||||
// no base found
|
||||
continue;
|
||||
};
|
||||
|
||||
if (
|
||||
_asset distance _closestBase >
|
||||
GVAR(setting_detectionRangeFromBase)
|
||||
) then {
|
||||
// not within range
|
||||
continue;
|
||||
};
|
||||
|
||||
// add to base's assets list
|
||||
private _baseAssets = _closestBase getVariable [_assetsAtThisBaseVar, []];
|
||||
_baseAssets pushBackUnique _asset;
|
||||
// broadcast later so we're not spamming network
|
||||
_closestBase setVariable [
|
||||
_assetsAtThisBaseVar,
|
||||
_baseAssets
|
||||
];
|
||||
|
||||
// if this is the init, set the base's assets started at this base
|
||||
if (_isInit) then {
|
||||
// broadcast later so we're not spamming network
|
||||
_closestBase setVariable [
|
||||
_assetsStartedAtThisBaseVar,
|
||||
_baseAssets
|
||||
];
|
||||
};
|
||||
} forEach (_allVehicles select { _x isKindOf "LandVehicle" });
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// publish updated base variables
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
private _base = _x;
|
||||
|
||||
// save current assets
|
||||
private _baseAssets = _base getVariable [_assetsAtThisBaseVar, []];
|
||||
_base setVariable [_assetsAtThisBaseVar, _baseAssets, true];
|
||||
|
||||
// if init, save starting assets
|
||||
if (_isInit) then {
|
||||
_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 [
|
||||
QGVAR(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_util_fnc_getNameOfBase]],
|
||||
["asset", _x]
|
||||
]
|
||||
] call milsim_util_fnc_log;
|
||||
} forEach _baseAssetsHashes;
|
||||
};
|
||||
|
||||
// if init, log starting assets
|
||||
if (_isInit) then {
|
||||
{
|
||||
[
|
||||
"fbcb2_assets",
|
||||
"STARTING ASSETS",
|
||||
[
|
||||
["baseName", [[_base] call milsim_util_fnc_getNameOfBase]],
|
||||
["asset", _x]
|
||||
]
|
||||
] call milsim_util_fnc_log;
|
||||
} forEach _baseAssetsHashes;
|
||||
};
|
||||
} forEach milsim_baseObjects;
|
||||
Reference in New Issue
Block a user