locally tested, adds more features. ready for dedi

This commit is contained in:
2024-02-02 14:34:04 -08:00
parent 3f5c6c5a59
commit b67888f4f1
24 changed files with 416 additions and 163 deletions

View File

@@ -1,15 +1,106 @@
params [["_isInit", false, [false]]];
{ // find approved assets at each base
private _base = _x;
private _baseAssets = _base getVariable ["milsim_fbcb2_assets_assetsAtThisBase", []];
{
private _className = configName _x;
_a = _base nearEntities [_className, 750];
_baseAssets append _a;
} forEach ((missionConfigFile >> "ApprovedAssets") call BIS_fnc_returnChildren);
_base setVariable ["milsim_fbcb2_assets_assetsAtThisBase", _baseAssets, true];
if (_isInit) then {
_base setVariable ["milsim_fbcb2_assets_assetsStartedAtThisBase", _baseAssets, true];
// 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 = "milsim_fbcb2_assets_assetsAtThisBase";
private _assetsStartedAtThisBaseVar = "milsim_fbcb2_assets_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 milsim_fnc_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 ["milsim_fbcb2_assets_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 milsim_fnc_getNearestBase;
if (isNull _closestBase) then {
// no base found
continue;
};
} forEach milsim_baseObjects;
if (
_asset distance _closestBase >
milsim_fbcb2_assets_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" });
// make the asset lists public
{
private _baseAssets = _x getVariable [_assetsAtThisBaseVar, []];
_x setVariable [_assetsAtThisBaseVar, _baseAssets, true];
if (_isInit) then {
_x setVariable [_assetsStartedAtThisBaseVar, _baseAssets, true];
};
} forEach milsim_baseObjects;