Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(v0.96.8) Objects and Static Weapons management in enemy sectors #975

Open
wants to merge 47 commits into
base: v0.96.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d74b0d1
Update CfgFunctions.hpp
PiG13BR Nov 23, 2024
e98dcbf
Add files via upload
PiG13BR Nov 23, 2024
b0c4f0e
Update custom.sqf
PiG13BR Nov 23, 2024
043fd03
Update init_presets.sqf
PiG13BR Nov 23, 2024
b12d246
Update manage_one_sector.sqf
PiG13BR Nov 23, 2024
f64fec0
Add files via upload
PiG13BR Nov 23, 2024
77076d6
Update init_presets.sqf
PiG13BR Nov 23, 2024
aede76e
Update fn_createStaticWeapons.sqf
PiG13BR Nov 23, 2024
a89bb42
Update KPLIB_staticsConfigs.sqf
PiG13BR Nov 24, 2024
f6b09e7
Update and rename fn_createGarrisons.sqf to fn_createSectorObjects.sqf
PiG13BR Nov 24, 2024
e1b9e71
Update and rename fn_registerGarrison.sqf to fn_registerSectorObjects…
PiG13BR Nov 24, 2024
0c90920
Update fn_createStaticWeapons.sqf
PiG13BR Nov 24, 2024
922e7ae
Add files via upload
PiG13BR Nov 24, 2024
dc06255
Update fn_sectorObjectBlacklist.sqf
PiG13BR Nov 24, 2024
1eeb989
Update CfgFunctions.hpp
PiG13BR Nov 24, 2024
bd29bee
Update manage_one_sector.sqf
PiG13BR Nov 24, 2024
19801c3
Update fn_createStaticWeapons.sqf
PiG13BR Nov 24, 2024
924e41b
Update KPLIB_staticsConfigs.sqf
PiG13BR Nov 24, 2024
75edc60
Update fn_createStaticWeapons.sqf
PiG13BR Nov 24, 2024
ebde174
Update KPLIB_staticsConfigs.sqf
PiG13BR Nov 24, 2024
06ca9a8
Update manage_one_sector.sqf
PiG13BR Nov 24, 2024
7699254
Update CfgFunctions.hpp
PiG13BR Nov 24, 2024
073fb3b
Update fn_registerSectorObjects.sqf
PiG13BR Nov 24, 2024
aa5f636
Update fn_sectorObjectBlacklist.sqf
PiG13BR Nov 24, 2024
69e1d72
Update fn_createSectorObjects.sqf
PiG13BR Nov 24, 2024
3452709
Update fn_createStaticWeapons.sqf
PiG13BR Nov 24, 2024
e3b0e6a
Update KPLIB_staticsConfigs.sqf
PiG13BR Nov 24, 2024
036b11a
Update KPLIB_staticsConfigs.sqf with new types
PiG13BR Nov 30, 2024
c2044e5
Update custom.sqf with new variables
PiG13BR Nov 30, 2024
0be7a7f
Update init_presets.sqf
PiG13BR Nov 30, 2024
1356425
Update hashmap variable for sector objects
PiG13BR Nov 30, 2024
cf584c1
Update fn_createSectorObjects.sqf
PiG13BR Nov 30, 2024
55d0091
Update fn_createStaticWeapons.sqf
PiG13BR Nov 30, 2024
837a7e5
Update fn_createStaticWeapons.sqf
PiG13BR Nov 30, 2024
5e2c4ed
Update fn_createStaticWeapons.sqf
PiG13BR Nov 30, 2024
fae93cc
Update fn_sectorObjectBlacklist.sqf
PiG13BR Dec 1, 2024
8461570
Update fn_sectorObjectBlacklist.sqf
PiG13BR Dec 1, 2024
fafa672
Update fn_sectorObjectBlacklist.sqf
PiG13BR Dec 2, 2024
4ee880d
Update fn_registerSectorObjects.sqf
PiG13BR Dec 4, 2024
50ebb70
Update init_server.sqf
PiG13BR Dec 4, 2024
9fd4bf1
Update fn_spawnStaticWeapon.sqf
PiG13BR Dec 10, 2024
bb3efd9
Update init.sqf
PiG13BR Dec 15, 2024
371b6e4
Update fn_registerSectorObjects.sqf
PiG13BR Dec 16, 2024
fccde8b
fn_registerSectorObjects.sqf Rethink
PiG13BR Dec 16, 2024
f6f2fb0
fn_sectorObjectBlacklist.sqf Rethink
PiG13BR Dec 16, 2024
9f9a6a8
Update fn_createStaticWeapons.sqf
PiG13BR Dec 18, 2024
b81981a
Update fn_spawnStaticWeapon.sqf
PiG13BR Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Missionframework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class KPLIB {
class createClearanceConfirm {};
class createCrate {};
class createManagedUnit {};
class createSectorObjects {};
class createStaticWeapons {};
class crGetMulti {};
class crGlobalMsg {};
class doSave {};
Expand Down Expand Up @@ -69,7 +71,9 @@ class KPLIB {
class log {};
class potatoScan {};
class protectObject {};
class registerSectorObjects {};
class secondsToTimer {};
class sectorObjectBlacklist {};
class setDiscordState {};
class setFobMass {};
class setLoadableViV {};
Expand All @@ -83,6 +87,7 @@ class KPLIB {
class spawnMilitaryPostSquad {};
class spawnMilitiaCrew {};
class spawnRegularSquad {};
class spawnStaticWeapon {};
class spawnVehicle {};
class swapInventory {};
};
Expand Down
46 changes: 46 additions & 0 deletions Missionframework/KPLIB_staticsConfigs.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
- Place here the structures that you want the enemy static weapons to spawn. For that, you need:
The classname of the building [STRING], followed by an bigger array;
The type of the static weapon ("RAISED-HMG", "LOWERED-HMG", "RAISED-GMG", "LOWERED-GMG", "AT", "AA") [ARRAY], related to ones in the presets. Can be more than one. Recommended: one type per position;
The PositionRelative coordinates [ARRAY] where the static weapon will spawn, relative to the structure;
The direction of the weapon [NUMBER] (it will be relative to the object).
- Example:
- [STRING, [[[STRING], ARRAY, NUMBER]]]
- ["building_classname", [[["type"], [relative position], relative direction], [["RAISED-HMG", "AT", "AA"], [x,y,z], (+/- dir)], [["RAISED-HMG"], [-1.14307,-1.2998,-0.55952], (180)]]]
- To get positionRelative, stand your character where you want to static weapon to spawn and run the code below in debug, it will return a [x,y,z] array.
(varNameOfTheObject or cursorObject) worldToModel ASLToAGL getPosASL player
- Using modded static weapons may require small adjustments in relative positions.
- To open the possibility of spawning static weapons, it requires more editing by placing those buildings classnames referenced below in the map. Some building classes may be already in the map.
- The static weapons will only spawn near sectors, so place the garrisons buildings near them.
- Don't duplicate classnames.
- Be careful when making a new array. Copy an example and change the values, and then check for missing or additional commas.
*/

KPLIB_staticsConfigs = [
// Vanilla
["Land_Cargo_Patrol_V1_F", [[["RAISED-HMG"], [-1.14307,-1.2998,-0.55952], (180)]]],
["Land_Cargo_Patrol_V2_F", [[["RAISED-HMG"], [-1,-1.3,-0.5], (180)]]],
["Land_Cargo_Patrol_V3_F", [[["RAISED-HMG"], [-1,-1.3,-0.5], (180)]]],
["Land_Cargo_HQ_V1_F", [[["AA"], [1.54492,0.740723,-0.747444], (0)], [["RAISED-HMG"], [-1.57813,-4.04639,-0.747444], (180)], [["RAISED-HMG"], [-2.64551,3.2,-0.747444], (- 45)], [["RAISED-HMG"], [5.88232,1.84473,-0.747444], (- 45)]]],
["Land_Cargo_HQ_V2_F", [[["AA"], [1.54492,0.740723,-0.747444], (0)], [["RAISED-HMG"], [-1.57813,-4.04639,-0.747444], (180)], [["RAISED-HMG"], [-2.64551,3.2,-0.747444], (- 45)], [["RAISED-HMG"], [5.88232,1.84473,-0.747444], (- 45)]]],
["Land_Cargo_HQ_V3_F", [[["AA"], [1.54492,0.740723,-0.747444], (0)], [["RAISED-HMG"], [-1.57813,-4.04639,-0.747444], (180)], [["RAISED-HMG"], [-2.64551,3.2,-0.747444], (- 45)], [["RAISED-HMG"], [5.88232,1.84473,-0.747444], (- 45)]]],
["Land_Cargo_Tower_V1_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V2_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V3_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No1_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No2_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No3_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No4_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No5_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No6_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_Cargo_Tower_V1_No7_F", [[["RAISED-HMG"], [4.61279,3.98389,5.00471], (45)], [["RAISED-HMG"], [4.8584,-2.90234,5.00471], (140)], [["RAISED-HMG"], [-4.18359,-3.16211,5.00471], (- 90)], [["RAISED-HMG"], [-3.07178,4.40283,5.00471], (0)]]],
["Land_BagFence_Round_F", [[["AT"], [0,1.5,0], (180)]]],
["Land_BagFence_Long_F", [[["AA"], [0,1.5,0], (180)]]],
["Land_HBarrierTower_F", [[["RAISED-HMG"], [0,-1.2793,0.0967188], (180)]]],
["Land_BagBunker_Small_F", [[["RAISED-HMG"], [0,0,-0.9], (180)]]],
["Land_BagBunker_Large_F", [[["RAISED-HMG"], [0.0717773,-3.24316,-0.709913], (180)], [["RAISED-HMG"], [2.7627,-1.0293,-0.709913], (90)]]],
["Land_BagBunker_Tower_F", [[["AA", "AT"], [0.163086,1.16992,0.571415], (0)], [["RAISED-HMG", "RAISED-GMG"], [-0.599121,-1.44092,0.571415], (180)]]],
["Land_ClutterCutter_medium_F", [[["LOWERED-HMG", "LOWERED-GMG"], [0,0,0], (0)]]]
];

KPLIB_staticConfigs_classes = KPLIB_staticsConfigs apply { _x select 0 };
38 changes: 38 additions & 0 deletions Missionframework/functions/fn_createSectorObjects.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
File: fn_createSectorObjects.sqf
Author: PiG13BR - https://github.com/PiG13BR
Date: 2024-11-22
Last Update: 2024-11-30
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Create registered objects in the designated sector

Parameter(s):
_sector - sector where the objects will be created [STRING]

Returns:
All objects created in this sector [ARRAY]
*/

if (!isServer) exitWith {};

params ["_sector"];

private _allGarrisons = [];

private _structures = KPLIB_sectorObjects_hashMap get _sector;
if ((isNil "_structures") || {count _structures < 1}) exitWith {_allGarrisons};

{
_class = _x # 0;
_pos = ((_x # 1) # 0);
_dir = ((_x # 1) # 1);

_object = createVehicle [_class, _pos, [], 0, "CAN_COLLIDE"];
_object setDir _dir;

_allGarrisons pushBack _object;
}forEach _structures;

_allGarrisons
106 changes: 106 additions & 0 deletions Missionframework/functions/fn_createStaticWeapons.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
File: fn_createStaticWeapons.sqf
Author: PiG13BR - https://github.com/PiG13BR
Date: 2024-11-22
Last Update: 2024-11-30
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Create static weapons on available structures in the sector, provided the structures are defined in KPLIB_staticsConfig.sqf file

Parameter(s):
_sector - sector to search for buildings to spawn static weapons
_radius - radius of search

Returns:
All static weapons created [ARRAY]
*/

if (!isServer) exitWith {};

params[
["_sector", "", [""]],
["_radius", 500, [0]]
];

private _allStaticWeapons = [];
private _sectorpos = markerPos _sector;

// Find garrisons objects for static weapons in the activated sector
private _allGarrisons = (nearestObjects [_sectorpos, KPLIB_staticConfigs_classes, (_radius * 1.5)]) select {alive _x};

private _blacklistGarrisons = (KPLIB_GarrisonsBlacklist_HashMap get _sector);
if (!isNil "_blacklistGarrisons") then {
{
_pos = _x;
_allGarrisons = _allGarrisons select {!(_pos distance2d _x < 2)};
}forEach _blacklistGarrisons;
};

// Create a group for the static weapons for the sector
private _staticGroup = createGroup KPLIB_side_enemy;

if (count _allGarrisons > 0) then {
// Loop the garrison objects found
{
private _garrison = _x;

// Loop statics configuration provided in KPLIB_staticsConfigs.sqf
{
// Check if the object type matches one of the configuration
if (_x # 0 == typeOf _garrison) then {
// Count how many positions are available for static weapons by counting the second element of the main array
private _positions = count (_x # 1);
if (_positions > 0) then {
for "_index" from 0 to (_positions - 1) do {
// The provided _index number in this loop will select each array that contains the necessary values to spawn correctly the static weapon for each relative position provided in the configuration
private _type = (((_x # 1) # _index) # 0); // Get the types
private _relPos = (((_x # 1) # _index) # 1); // Get the relativePosition
private _relDir = (((_x # 1) # _index) # 2); // Get the rotation

private _typeSel = "";
// It will select randomly the type if more than one is provided.
if (count _type > 1) then {
_typeSel = selectRandom _type;
} else {
_typeSel = _type # 0;
};

// For the selected type, it will check the static weapons presets
private _staticClass = "";
switch _typeSel do {
case "RAISED-HMG" : {
_staticClass = selectRandom KPLIB_o_statics_raisedHMG;
};
case "LOWERED-HMG" : {
_staticClass = selectRandom KPLIB_o_statics_loweredHMG;
};
case "RAISED-GMG" : {
_staticClass = selectRandom KPLIB_o_statics_raisedGMG;
};
case "LOWERED-GMG" : {
_staticClass = selectRandom KPLIB_o_statics_loweredGMG;
};
case "AT" : {
_staticClass = selectRandom KPLIB_o_statics_AT;
};
case "AA" : {
_staticClass = selectRandom KPLIB_o_statics_AA;
}
};

if (_staticClass isEqualTo "") then {[format ["No static weapon classname found in type %1", _typeSel], "WARNING"] call KPLIB_fnc_log; continue};

// Create the static weapon and it's crew
_weapon = [(_garrison modelToWorld _relPos), _staticClass, (getDir _garrison + (_relDir))] call KPLIB_fnc_spawnStaticWeapon;
// Group the static weapons to share information easily.
(crew _weapon) joinSilent _staticGroup;
_allStaticWeapons pushBack _weapon;
};
};
}
}forEach KPLIB_staticsConfigs;
}forEach _allGarrisons;
};

_allStaticWeapons
69 changes: 69 additions & 0 deletions Missionframework/functions/fn_registerSectorObjects.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
File: fn_registerSectorObjects.sqf
Author: PiG13BR - https://github.com/PiG13BR
Date: 2024-11-23
Last Update: 2024-12-15
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
Registers pre-placed objects from a sector into a hashmap and deletes them from the map.
Only objects close enough to sectors will be registered.

Parameter(s):
-

Returns:
-
*/

if (!isServer) exitWith {};

[{(!isNil "KPLIB_sectors_all") && {!isNil "KPLIB_sector_ObjectsBlacklist"}}, {
private _radius = KPLIB_range_sectorCapture;
private _allObjects = [];
// Get all placed objects near sectors
{
_editedObjs = nearestObjects [(markerPos _x), ["Static", "Thing"], _radius];
// Get the terrain objects. It will also get simple objects set up from attributes.
_terrainObjs = nearestTerrainObjects [(markerPos _x), [], _radius, false];

// Protect terrain objects, radio towers and production objects
_onlyEditedObjs = (_editedObjs - _terrainObjs);

_allObjects append _onlyEditedObjs;

}forEach KPLIB_sectors_all;

if (isNil "KPLIB_sectorObjects_hashMap") then {
// Creates the hashmap
KPLIB_sectorObjects_hashMap = createHashMap;
};

{
// Ignore object from blacklist (the object will not be deleted in game start and will retain any attributes from editor)
if (_x in KPLIB_sector_ObjectsBlacklist) then { continue };
// Ignore objects from config and player presets
if ((typeOf _x) in KPLIB_radioTowerClassnames) then { continue };
if ((typeOf _x) in [KPLIB_b_smallStorage, KPLIB_b_largeStorage, KPLIB_b_crateSupply, KPLIB_b_crateAmmo, KPLIB_b_crateFuel]) then { continue };

private _sector = [_radius, getPos _x] call KPLIB_fnc_getNearestSector; // Nearest sector will be the key for the hashmap
if (_sector isEqualTo "") then {[format ["%1 in position %2 is too far away from any sectors. Deleting the object.", (typeOf _x), (getPos _x)], "WARNING"] call KPLIB_fnc_log; deleteVehicle _x; continue};

// Check if the key (sector) is already in the hashmap
if !(_sector in KPLIB_sectorObjects_hashMap) then {
// Create a new key with a value
KPLIB_sectorObjects_hashMap set [_sector, [[typeOf _x, [getPosATL _x, getDir _x]]]];
} else {
// Update key values if key already exists
private _mapValue = KPLIB_sectorObjects_hashMap get _sector;
private _mapNewValues = _mapValue + [[typeOf _x, [getPosATL _x, getDir _x]]];
KPLIB_sectorObjects_hashMap set [_sector, _mapNewValues];
};

// Delete the object to spawn it later when the sector is activated
deleteVehicle _x;
}forEach _allObjects;

KPLIB_sector_ObjectsBlacklist = nil;

}, []] call CBA_fnc_waitUntilAndExecute;
78 changes: 78 additions & 0 deletions Missionframework/functions/fn_sectorObjectBlacklist.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
File: fn_sectorObjectBlacklist.sqf
Author: PiG13BR - https://github.com/PiG13BR
Date: 2024-11-23
Last Update: 2024-12-16
License: MIT License - http://www.opensource.org/licenses/MIT

Description:
This is where the object have the option to remain in the map and not be spawned/despawned in designated sector.
Adds the object in a blacklist. The object in the blacklist will not be deleted in the game start and will retain any attributes from editor. If the object is a simple object, it will be automatic ignored in the fn_registerSectorObjects.sqf file.
Also, if the object classname is in KPLIB_staticsConfigs, the spawning of static weapons for this building object can be disabled (NOT THE ENTIRE CLASS) and it will be managed in a different blacklist.
To add an object in the blacklist, put this code in its init field. Follow the examples below:
[this] call KPLIB_fnc_sectorObjectBlacklist - object blacklisted, static weapons can spawn in garrison buildings as default
[this, false, false] call KPLIB_fnc_sectorObjectBlacklist - object not blacklisted and static weapon spawn disabled
[this, true, false] call KPLIB_fnc_sectorObjectBlacklist - object blacklisted and static weapon spawn disabled
[this, false, true] call KPLIB_fnc_sectorObjectBlacklist - Normal behaviour without calling this function
This function must be put in the init field of the objects to run before any liberation script (https://community.bistudio.com/wiki/Initialisation_Order)

If some of those buildings already exists in the map (as terrain) and you want to disable the spawning of static weapons, for example, place a logic near the object and in its init field:
{[_x, true, false] call KPLIB_fnc_sectorObjectBlacklist}forEach (nearestObjects [getPos this, ["classname_object"], 25, false])
Find the correct classname of the object and change the radius of search if needed. Those terrain objects can't be deleted, so leave the second parameter of the function as TRUE.

Parameter(s):
_object - structure that will be registered [OBJECT]
_blacklisted - true for blacklisting the object [BOOL, defaults as true]
_canGarrison - if the object is a garrison building (KPLIB_staticsConfigs.sqf), false for disabling any static weapon spawning on it [BOOL, defaults as true]

Returns:
-
*/
if (!isServer) exitWith {};

params[
["_object", objNull, [objNull]],
["_blacklisted", true, [FALSE]],
["_canGarrison", true, [FALSE]] // To work, the structure classname must be under KPLIB_staticsConfigs. This will not enable a structure to accept static weapons spawn by magic.
];

if (isNull _object) exitWith {};

// General blacklist variable
if (isNil "KPLIB_sector_ObjectsBlacklist") then {
KPLIB_sector_ObjectsBlacklist = [];
};

// Add object to the general blacklist
if (_blacklisted) then {
KPLIB_sector_ObjectsBlacklist pushBack _object;
};

// This is for the buildings/structures that the spawning of static weapons is disabled.
if (isNil "KPLIB_GarrisonsBlacklist_HashMap") then {
// Creates the hashmap
KPLIB_GarrisonsBlacklist_HashMap = createHashMap;
};

private _radius = KPLIB_range_sectorCapture;

if (!_canGarrison) then {
[{!isNil "KPLIB_sectors_all"}, {
_this params ["_object", "_canGarrison"];
// Because a deleted object will give a <NULL-OBJECT> in the garrison array, save the position of the object instead to find a match later.
private _objectPos = [round parseNumber (((getPosATL _object) # 0) toFixed 2), round parseNumber (((getPosATL _object) # 1) toFixed 2), round parseNumber (((getPosATL _object) # 2) toFixed 2)];
private _sector = [_radius, getPos _object] call KPLIB_fnc_getNearestSector;
//private _objectPos = _object worldToModel (markerPos _sector);

if !(_sector in KPLIB_GarrisonsBlacklist_HashMap) then {
// Create a new key with a value
KPLIB_GarrisonsBlacklist_HashMap set [_sector, [_objectPos]];
} else {
// Update key values if key already exists
private _mapValue = KPLIB_GarrisonsBlacklist_HashMap get _sector;
private _mapNewValues = _mapValue + [_objectPos];
KPLIB_GarrisonsBlacklist_HashMap set [_sector, _mapNewValues];
};

}, [_object, _canGarrison]] call CBA_fnc_waitUntilAndExecute;
};
Loading
Loading