From 39cd791b3d89cefc367d201f113004ffecff3a3c Mon Sep 17 00:00:00 2001 From: abridgford Date: Thu, 28 Mar 2024 13:17:35 +0000 Subject: [PATCH 01/11] initial commit --- addons/populate/$PBOPREFIX$ | 1 + addons/populate/Cfg3den.hpp | 20 +++++ addons/populate/CfgEventHandlers.hpp | 17 ++++ addons/populate/CfgFactionClasses.hpp | 6 ++ addons/populate/CfgVehicles.hpp | 84 +++++++++++++++++++ addons/populate/README.md | 5 ++ addons/populate/XEH_PREP.hpp | 4 + addons/populate/XEH_postInit.sqf | 9 ++ addons/populate/XEH_preInit.sqf | 12 +++ addons/populate/XEH_preStart.sqf | 3 + addons/populate/config.cpp | 24 ++++++ .../functions/fnc_getValidPositions.sqf | 60 +++++++++++++ .../functions/fnc_modulePopulateArea.sqf | 20 +++++ .../functions/fnc_selectSpawnPosition.sqf | 76 +++++++++++++++++ addons/populate/functions/fnc_spawnUnit.sqf | 29 +++++++ .../populate/functions/script_component.hpp | 1 + addons/populate/initSettings.sqf | 24 ++++++ addons/populate/script_component.hpp | 9 ++ 18 files changed, 404 insertions(+) create mode 100644 addons/populate/$PBOPREFIX$ create mode 100644 addons/populate/Cfg3den.hpp create mode 100644 addons/populate/CfgEventHandlers.hpp create mode 100644 addons/populate/CfgFactionClasses.hpp create mode 100644 addons/populate/CfgVehicles.hpp create mode 100644 addons/populate/README.md create mode 100644 addons/populate/XEH_PREP.hpp create mode 100644 addons/populate/XEH_postInit.sqf create mode 100644 addons/populate/XEH_preInit.sqf create mode 100644 addons/populate/XEH_preStart.sqf create mode 100644 addons/populate/config.cpp create mode 100644 addons/populate/functions/fnc_getValidPositions.sqf create mode 100644 addons/populate/functions/fnc_modulePopulateArea.sqf create mode 100644 addons/populate/functions/fnc_selectSpawnPosition.sqf create mode 100644 addons/populate/functions/fnc_spawnUnit.sqf create mode 100644 addons/populate/functions/script_component.hpp create mode 100644 addons/populate/initSettings.sqf create mode 100644 addons/populate/script_component.hpp diff --git a/addons/populate/$PBOPREFIX$ b/addons/populate/$PBOPREFIX$ new file mode 100644 index 000000000..0c2d1a1bc --- /dev/null +++ b/addons/populate/$PBOPREFIX$ @@ -0,0 +1 @@ +u\uksf\addons\populate diff --git a/addons/populate/Cfg3den.hpp b/addons/populate/Cfg3den.hpp new file mode 100644 index 000000000..90352dba2 --- /dev/null +++ b/addons/populate/Cfg3den.hpp @@ -0,0 +1,20 @@ +// class Cfg3DEN { +// class Object { +// class AttributeCategories { +// class uksf_attributes { +// class Attributes { +// class GVAR(excluded) { +// property = QGVAR(excluded); +// control = "Checkbox"; +// displayName = QUOTE(Cleanup exclude); +// tooltip = QUOTE(Excludes object from cleanup); +// expression = QUOTE(_this setVariable [ARR_3(QQGVAR(excluded),_value,true)]); +// typeName = "BOOL"; +// defaultValue = "(false)"; +// condition = "1"; +// }; +// }; +// }; +// }; +// }; +// }; diff --git a/addons/populate/CfgEventHandlers.hpp b/addons/populate/CfgEventHandlers.hpp new file mode 100644 index 000000000..f6503c247 --- /dev/null +++ b/addons/populate/CfgEventHandlers.hpp @@ -0,0 +1,17 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); + }; +}; diff --git a/addons/populate/CfgFactionClasses.hpp b/addons/populate/CfgFactionClasses.hpp new file mode 100644 index 000000000..7a1e764ff --- /dev/null +++ b/addons/populate/CfgFactionClasses.hpp @@ -0,0 +1,6 @@ +class CfgFactionClasses { + class EGVAR(common,eden); + class ADDON: EGVAR(common,eden){ + displayName = "Auto Populate Area"; + }; +}; diff --git a/addons/populate/CfgVehicles.hpp b/addons/populate/CfgVehicles.hpp new file mode 100644 index 000000000..0cada64c8 --- /dev/null +++ b/addons/populate/CfgVehicles.hpp @@ -0,0 +1,84 @@ +class CfgVehicles { + class Module_F; + class GVAR(module) : Module_F { + scope = 1; + is3DEN = 1; + functionPriority = 1; + category = ADDON; + class AttributesBase; + }; + class GVAR(populateAreaModule) : GVAR(module) { + scope = 2; + displayName = "(AP) Auto Populate)"; + icon = "A3\ui_f\data\map\markers\nato\o_inf.paa"; + portrait = "A3\ui_f\data\map\markers\nato\o_inf.paa"; + function = QFUNC(modulePopulateArea); + canSetArea = 1; + canSetAreaHeight = 0; + canSetAreaShape = 1; + class AttributeValues { + size3[] = { 200, 200, -1 }; + isRectangle = 1; + }; + class Attributes : AttributesBase { + class GVAR(numberOfUnits) { + property = QGVAR(numberOfUnits); + displayName = "Number of Units"; + tooltip = "The number of units to spawn"; + control = "EditShort"; + validate = "NUMBER"; + defaultValue = 30; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); + }; + class GVAR(unitPoolString) { + property = QGVAR(unitPoolString); + displayName = "Unit Pool"; + tooltip = "Class names of units to spawn for counter-mortar groups. Comma-separated list of class names in single quotes, no spaces"; + control = "Edit"; + defaultValue = "[]"; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(unitPoolString),_value,true)]); + }; + class GVAR(occupyStaticGunsBool) { + property = QGVAR(occupyStaticGunsBool); + displayName = "Occupy Static Weapons"; + tooltip = "Should units man placed static weapons"; + control = "CheckBox"; + typeName = "BOOL"; + defaultValue = "(false)"; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(occupyStaticGunsBool),_value,true)]); + }; + class GVAR(percentageOfPositionsToOccupy) { + property = QGVAR(percentageOfPositionsToOccupy); + displayName = "Percentage of Positions to Occupy"; + tooltip = "What percentage of the total positions will be occupied - low % may result in units being spread out"; + control = "EditShort"; + validate = "NUMBER"; + defaultValue = 30; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(percentageOfPositionsToOccupy),_value,true)]); + }; + class GVAR(side) { + property = QGVAR(side); + displayName = "Side"; + tooltip = "Side of spawned units"; + control = "Combo"; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(side),_value,true)]); + typeName = "NUMBER"; + defaultValue = 0; + class values { + class East { + name = "OPFOR"; + value = 0; + }; + class Guer { + name = "Independent"; + value = 1; + }; + class West { + name = "BLUFOR"; + value = 2; + }; + }; + }; + }; + }; +}; diff --git a/addons/populate/README.md b/addons/populate/README.md new file mode 100644 index 000000000..72dcbe05f --- /dev/null +++ b/addons/populate/README.md @@ -0,0 +1,5 @@ +# Auto Populate + +Takes all building positions and AI Building Positions and populates them with units +If the number of AI to spawn is more than 10, group sizes will be 10 +Runs once at mission start diff --git a/addons/populate/XEH_PREP.hpp b/addons/populate/XEH_PREP.hpp new file mode 100644 index 000000000..8ce9d187e --- /dev/null +++ b/addons/populate/XEH_PREP.hpp @@ -0,0 +1,4 @@ +PREP(modulePopulateArea); +PREP(getValidPositions); +PREP(selectSpawnPosition); +PREP(spawnUnit); diff --git a/addons/populate/XEH_postInit.sqf b/addons/populate/XEH_postInit.sqf new file mode 100644 index 000000000..247594120 --- /dev/null +++ b/addons/populate/XEH_postInit.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + + +["CBA_BuildingPos", "initPost", { + params ["_pos"]; + + GVAR(aiBuildingPositions) pushBack (getPosATL _pos); +}, true] call CBA_fnc_addClassEventHandler; + diff --git a/addons/populate/XEH_preInit.sqf b/addons/populate/XEH_preInit.sqf new file mode 100644 index 000000000..81dd9c2be --- /dev/null +++ b/addons/populate/XEH_preInit.sqf @@ -0,0 +1,12 @@ +#include "script_component.hpp" + +ADDON = false; + +#include "XEH_PREP.hpp" + +// #include "initSettings.sqf" + +GVAR(groupSize) = 10; +GVAR(aiBuildingPositions) = []; + +ADDON = true; diff --git a/addons/populate/XEH_preStart.sqf b/addons/populate/XEH_preStart.sqf new file mode 100644 index 000000000..022888575 --- /dev/null +++ b/addons/populate/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/populate/config.cpp b/addons/populate/config.cpp new file mode 100644 index 000000000..b05957b1f --- /dev/null +++ b/addons/populate/config.cpp @@ -0,0 +1,24 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = { + QGVAR(populateAreaModule) + }; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = { + "uksf_mission" + }; + author = QUOTE(UKSF); + authors[] = { "Bridgford.A" }; + url = URL; + VERSION_CONFIG; + }; +}; + +// #include "Cfg3den.hpp" +#include "CfgEventHandlers.hpp" +#include "CfgFactionClasses.hpp" +#include "CfgVehicles.hpp" diff --git a/addons/populate/functions/fnc_getValidPositions.sqf b/addons/populate/functions/fnc_getValidPositions.sqf new file mode 100644 index 000000000..012620574 --- /dev/null +++ b/addons/populate/functions/fnc_getValidPositions.sqf @@ -0,0 +1,60 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Gets any valid building positions AND AI Building Positions in the area + + Parameters: + 0: _module + + Return value: + Nothing +*/ + +params ["_module"]; + +if !(isServer) exitWith {}; + +private _radius = 0; + +// get the area +private _area = _module getVariable ["objectarea", []]; +if (_area isEqualTo []) exitWith {}; + +// get which dimension is largest to use as radius +private _a = _area#1; +private _b = _area#2; + +if (_a > _b) then { _radius = _a}; +if (_b > _a) then { _radius = _b}; + +diag_log format ["UKSF_POPULATE - a %1, b %2, r: %3", _a, _b, _radius]; + +// get all buildings in radius then in area +private _allBuildingsInRadius = nearestTerrainObjects [_module, ["BUILDING", "HOUSE"], _radius, false, true]; +diag_log format ["UKSF_POPULATE - abir %1", _allBuildingsInRadius]; +private _allBuildingsInArea = _allBuildingsInRadius inAreaArray _area; + +// // get all ai buildings in radius then in area +// private _allAiBuildingPositionsInRadius = GVAR(aiBuildingPositions) select {_x distance2D _module <= _radius}; +// private _aiBuildingPositions = _allAiBuildingPositionsInRadius inAreaArray _area; + +// // get the building positions for the buildings +// private _buildingPositions = []; +// { +// private _building = _x; +// private _buildingPositionsArray = _building buildingPos -1; +// { +// private _buildingPosition = _x; +// _buildingPositions pushBack _buildingPosition; +// } forEach _buildingPositionsArray; +// } forEach _allBuildingsInArea; + +// // append building positions and ai building positions +// private _spawnPositions = _buildingPositions + _aiBuildingPositions; + +// // call out to select position function +// [_spawnPositions, _module] call FUNC(selectSpawnPosition); + diff --git a/addons/populate/functions/fnc_modulePopulateArea.sqf b/addons/populate/functions/fnc_modulePopulateArea.sqf new file mode 100644 index 000000000..19281f28f --- /dev/null +++ b/addons/populate/functions/fnc_modulePopulateArea.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Sets the settings from the module up as global vars + + Parameters: + 0: The module object + + Return value: + Nothing +*/ + +(_this select 1) params ["_module"]; + +if (!isServer) exitWith {}; + +[_module] call FUNC(getValidPositions); diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf new file mode 100644 index 000000000..958957812 --- /dev/null +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -0,0 +1,76 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Selects a position from the list of the positions passed + calls the spawn unit function for those positions + _currenGrouptUnitCount is checked to create a group every 10 units + _numberOfUnitsToSpawn is checked to make sure the number of units defined is spawned + + + Parameters: + 0: _spawnPositions + + Return value: + Nothing +*/ + +params ["_spawnPositions", "_module"]; + +if (!isServer) exitWith {}; + +private _fnc_getArrayFromModule = { + params ["_module", "_property"]; + + private _value = _module getVariable [_property, []]; + + if (_value isEqualType "") then { + if (_value != "") then { + _value = call compile _value; + } else { + _value = []; + }; + }; + _value +}; + +private _numberOfUnitsToSpawn = [_module, QGVAR(numberOfUnits)] call _fnc_getArrayFromModule; +private _side = _module getVariable [QGVAR(side), 0]; +private _currenGrouptUnitCount = 0; +private _group = grpNull; + +[{ + params ["_args", "_idPFH"]; + _args params ["_spawnPositions", "_currenGrouptUnitCount", "_numberOfUnitsToSpawn", "_side", "_group"]; + + if (_numberOfUnitsToSpawn <= 0 || (count _spawnPositions) <= 0) exitWith { // TODO: if _numberOfUnitsToSpawn has left over units, handle in some way, maybe a patrol?? + [_idPFH] call cba_fnc_removePerFrameHandler; + }; + + private _spawnPos = selectRandom _spawnPositions; + + // delete the position from the array to avoid doubling + _spawnPositions deleteAt (_spawnPositions findIf {_x == _spawnPos}); + + // create a group if the _currenGrouptUnitCount is == 0 + if (_currenGrouptUnitCount == 0) then { + _group = createGroup _side; + }; + + // call a create unit function + [_spawnPos, _module, _group] call FUNC(spawnUnit); + _currenGrouptUnitCount = _currenGrouptUnitCount + 1; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; + if (_currenGrouptUnitCount == 10) then { + _currenGrouptUnitCount = 0; + }; + + // update pfh vars + _args set [0, _spawnPositions]; + _args set [1, _currenGrouptUnitCount]; + _args set [2, _numberOfUnitsToSpawn]; + _args set [4, _group]; + +}, 1, [_spawnPositions, _currenGrouptUnitCount, _numberOfUnitsToSpawn, _side, _group]] call cba_fnc_addPerFrameHandler; diff --git a/addons/populate/functions/fnc_spawnUnit.sqf b/addons/populate/functions/fnc_spawnUnit.sqf new file mode 100644 index 000000000..40cbfadbd --- /dev/null +++ b/addons/populate/functions/fnc_spawnUnit.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Spawns a unit at the passed position + + Parameters: + 0: _spawnPos + 1: _module + 2: _group + + Return value: + Nothing +*/ + +params ["_spawnPos", "_module", "_group"]; + +// select random unit to spawn and spawn it at the pos +private _unitPool = _module getVariable [QGVAR(unitPoolString), []]; +private _unitType = selectRandom _unitPool; + +private _unit = _group createUnit [_unitType, _spawnPos, [], 0, "NONE"]; +_unit disableAI "PATH"; + +// TODO: exclude virtualization until the group is spawned, then set to true + + diff --git a/addons/populate/functions/script_component.hpp b/addons/populate/functions/script_component.hpp new file mode 100644 index 000000000..1b703f354 --- /dev/null +++ b/addons/populate/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\u\uksf\addons\populate\script_component.hpp" diff --git a/addons/populate/initSettings.sqf b/addons/populate/initSettings.sqf new file mode 100644 index 000000000..b84b34a4b --- /dev/null +++ b/addons/populate/initSettings.sqf @@ -0,0 +1,24 @@ +// [ +// QGVAR(enabled), +// "CHECKBOX", +// ["Cleanup", "Enables cleanup of dead units/vehicles"], +// ["UKSF", QUOTE(COMPONENT_BEAUTIFIED)], +// false, +// 1, +// { +// params ["_value"]; + +// if (isServer && _value) then { +// [{call FUNC(cleanupCheck)}, [], 0] call CBA_fnc_waitAndExecute; +// }; +// } +// ] call CBA_settings_fnc_init; + +// [ +// QGVAR(delay), +// "SLIDER", +// ["Cleanup Delay", "Delay in seconds between death and cleanup"], +// ["UKSF", QUOTE(COMPONENT_BEAUTIFIED)], +// [5, 600, 300, 0], +// 1 +// ] call CBA_settings_fnc_init; diff --git a/addons/populate/script_component.hpp b/addons/populate/script_component.hpp new file mode 100644 index 000000000..9cc9d1ed5 --- /dev/null +++ b/addons/populate/script_component.hpp @@ -0,0 +1,9 @@ +#define COMPONENT populate +#define COMPONENT_BEAUTIFIED Populate +#include "\u\uksf\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define CBA_DEBUG_SYNCHRONOUS + +#include "\u\uksf\addons\main\script_macros.hpp" From 3edff9c428acbbb71d4561f9a5aef7e9d571f25a Mon Sep 17 00:00:00 2001 From: Tim Beswick Date: Tue, 9 Apr 2024 18:35:33 +0100 Subject: [PATCH 02/11] Use trace, fix script error --- .../functions/fnc_getValidPositions.sqf | 19 ++++++++----------- addons/populate/script_component.hpp | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/addons/populate/functions/fnc_getValidPositions.sqf b/addons/populate/functions/fnc_getValidPositions.sqf index 012620574..97d7519ad 100644 --- a/addons/populate/functions/fnc_getValidPositions.sqf +++ b/addons/populate/functions/fnc_getValidPositions.sqf @@ -12,29 +12,26 @@ Return value: Nothing */ - params ["_module"]; if !(isServer) exitWith {}; -private _radius = 0; - // get the area -private _area = _module getVariable ["objectarea", []]; +private _areaParams = _module getVariable ["objectarea", []]; +private _area = [getPos _module] + _areaParams; if (_area isEqualTo []) exitWith {}; -// get which dimension is largest to use as radius -private _a = _area#1; -private _b = _area#2; +_area params ["", "_a", "_b"]; -if (_a > _b) then { _radius = _a}; -if (_b > _a) then { _radius = _b}; +// get which dimension is largest to use as radius +private _radius = [_b, _a] select (_a > _b); -diag_log format ["UKSF_POPULATE - a %1, b %2, r: %3", _a, _b, _radius]; +TRACE_4("",_area,_a,_b,_radius); // get all buildings in radius then in area private _allBuildingsInRadius = nearestTerrainObjects [_module, ["BUILDING", "HOUSE"], _radius, false, true]; -diag_log format ["UKSF_POPULATE - abir %1", _allBuildingsInRadius]; +TRACE_1("",_allBuildingsInRadius); + private _allBuildingsInArea = _allBuildingsInRadius inAreaArray _area; // // get all ai buildings in radius then in area diff --git a/addons/populate/script_component.hpp b/addons/populate/script_component.hpp index 9cc9d1ed5..7d43019d1 100644 --- a/addons/populate/script_component.hpp +++ b/addons/populate/script_component.hpp @@ -2,7 +2,7 @@ #define COMPONENT_BEAUTIFIED Populate #include "\u\uksf\addons\main\script_mod.hpp" -// #define DEBUG_MODE_FULL +#define DEBUG_MODE_FULL // #define DISABLE_COMPILE_CACHE // #define CBA_DEBUG_SYNCHRONOUS From 0156d552781cd61b145c385d81effbbcdbd8c621 Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 15 Apr 2024 16:37:24 +0100 Subject: [PATCH 03/11] minor tweaks, remove files --- addons/populate/XEH_PREP.hpp | 3 +- addons/populate/XEH_postInit.sqf | 8 --- addons/populate/XEH_preInit.sqf | 1 - .../functions/fnc_modulePopulateArea.sqf | 2 +- .../functions/fnc_spawnBuildingUnit.sqf | 60 +++++++++++++++++++ addons/populate/functions/fnc_spawnUnit.sqf | 29 --------- 6 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 addons/populate/functions/fnc_spawnBuildingUnit.sqf delete mode 100644 addons/populate/functions/fnc_spawnUnit.sqf diff --git a/addons/populate/XEH_PREP.hpp b/addons/populate/XEH_PREP.hpp index 8ce9d187e..54814b5e7 100644 --- a/addons/populate/XEH_PREP.hpp +++ b/addons/populate/XEH_PREP.hpp @@ -1,4 +1,5 @@ PREP(modulePopulateArea); PREP(getValidPositions); PREP(selectSpawnPosition); -PREP(spawnUnit); +PREP(spawnBuildingUnit); +PREP(createPatrols); diff --git a/addons/populate/XEH_postInit.sqf b/addons/populate/XEH_postInit.sqf index 247594120..421c54b49 100644 --- a/addons/populate/XEH_postInit.sqf +++ b/addons/populate/XEH_postInit.sqf @@ -1,9 +1 @@ #include "script_component.hpp" - - -["CBA_BuildingPos", "initPost", { - params ["_pos"]; - - GVAR(aiBuildingPositions) pushBack (getPosATL _pos); -}, true] call CBA_fnc_addClassEventHandler; - diff --git a/addons/populate/XEH_preInit.sqf b/addons/populate/XEH_preInit.sqf index 81dd9c2be..da6f4101d 100644 --- a/addons/populate/XEH_preInit.sqf +++ b/addons/populate/XEH_preInit.sqf @@ -7,6 +7,5 @@ ADDON = false; // #include "initSettings.sqf" GVAR(groupSize) = 10; -GVAR(aiBuildingPositions) = []; ADDON = true; diff --git a/addons/populate/functions/fnc_modulePopulateArea.sqf b/addons/populate/functions/fnc_modulePopulateArea.sqf index 19281f28f..185afe9a1 100644 --- a/addons/populate/functions/fnc_modulePopulateArea.sqf +++ b/addons/populate/functions/fnc_modulePopulateArea.sqf @@ -13,7 +13,7 @@ Nothing */ -(_this select 1) params ["_module"]; +(_this#1) params ["_module"]; if (!isServer) exitWith {}; diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf new file mode 100644 index 000000000..44463fae0 --- /dev/null +++ b/addons/populate/functions/fnc_spawnBuildingUnit.sqf @@ -0,0 +1,60 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Spawns a unit at the passed position + + Parameters: + 0: _spawnPos + 1: _module + 2: _group + + Return value: + Nothing +*/ + +params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount"]; + +private _group = grpNull; + +[{ + params ["_args", "_idPFH"]; + _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group"]; + + if (_numberOfPositionsToOccupy <= 0) exitWith { + [_idPFH] call cba_fnc_removePerFrameHandler; + if (_numberOfUnitsToSpawn > 0) then { + [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _patrolRadius] call FUNC(createPatrols); + ;} + }; + + // create a group if the _currenGrouptUnitCount is == 0, set previous group to patrol + if (_currenGrouptUnitCount == 0) then { + _group = createGroup _side; + }; + + private _unitType = selectRandom _unitPoolArray; + private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; + private _spawnPos = selectRandom _spawnPositions; + // private _spawnPos = getPos _spawn; + _unit setPos _spawnPos; + TRACE_3("", _spawn, _spawnPos, _spawnPositions); + + _unit disableAI "PATH"; + + _currenGrouptUnitCount = _currenGrouptUnitCount + 1; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; + _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + if (_currenGrouptUnitCount == 10) then { + _currenGrouptUnitCount = 0; + }; + + _args set [6, _currenGrouptUnitCount]; + _args set [2, _numberOfPositionsToOccupy]; + _args set [7, _group]; + +}, 1, [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _group]] call cba_fnc_addPerFrameHandler; + +// TODO: exclude virtualization until the group is spawned, then set to true diff --git a/addons/populate/functions/fnc_spawnUnit.sqf b/addons/populate/functions/fnc_spawnUnit.sqf deleted file mode 100644 index 40cbfadbd..000000000 --- a/addons/populate/functions/fnc_spawnUnit.sqf +++ /dev/null @@ -1,29 +0,0 @@ -#include "script_component.hpp" -/* - Author: - Bridg - - Description: - Spawns a unit at the passed position - - Parameters: - 0: _spawnPos - 1: _module - 2: _group - - Return value: - Nothing -*/ - -params ["_spawnPos", "_module", "_group"]; - -// select random unit to spawn and spawn it at the pos -private _unitPool = _module getVariable [QGVAR(unitPoolString), []]; -private _unitType = selectRandom _unitPool; - -private _unit = _group createUnit [_unitType, _spawnPos, [], 0, "NONE"]; -_unit disableAI "PATH"; - -// TODO: exclude virtualization until the group is spawned, then set to true - - From d5bc7aa53a0b0bf841c0751cb818fd1f3c9b43ed Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 15 Apr 2024 16:37:45 +0100 Subject: [PATCH 04/11] add new function, improvements --- addons/populate/CfgVehicles.hpp | 20 ++++++- .../populate/functions/fnc_createPatrols.sqf | 54 +++++++++++++++++++ .../functions/fnc_getValidPositions.sqf | 54 +++++++++++-------- .../functions/fnc_selectSpawnPosition.sqf | 46 ++++++---------- 4 files changed, 123 insertions(+), 51 deletions(-) create mode 100644 addons/populate/functions/fnc_createPatrols.sqf diff --git a/addons/populate/CfgVehicles.hpp b/addons/populate/CfgVehicles.hpp index 0cada64c8..1ed93253b 100644 --- a/addons/populate/CfgVehicles.hpp +++ b/addons/populate/CfgVehicles.hpp @@ -30,6 +30,24 @@ class CfgVehicles { defaultValue = 30; expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); }; + class GVAR(patrolRadius) { + property = QGVAR(patrolRadius); + displayName = "Patrol Radius"; + tooltip = "The radius any left over units will patrol around the module location. Used for when positions to occupy isn't 100%"; + control = "EditShort"; + validate = "NUMBER"; + defaultValue = 50; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); + }; + class GVAR(patrolSize) { + property = QGVAR(patrolSize); + displayName = "Patrol Size"; + tooltip = "The number of units in each patrol. Patrols occur once all building positions are filled."; + control = "EditShort"; + validate = "NUMBER"; + defaultValue = 6; + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); + }; class GVAR(unitPoolString) { property = QGVAR(unitPoolString); displayName = "Unit Pool"; @@ -70,7 +88,7 @@ class CfgVehicles { value = 0; }; class Guer { - name = "Independent"; + name = "INDEPENDENT"; value = 1; }; class West { diff --git a/addons/populate/functions/fnc_createPatrols.sqf b/addons/populate/functions/fnc_createPatrols.sqf new file mode 100644 index 000000000..1b565590b --- /dev/null +++ b/addons/populate/functions/fnc_createPatrols.sqf @@ -0,0 +1,54 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Spawns a unit at the passed position + + Parameters: + 0: _numberOfUnitsToSpawn + 1: _module + 2: _group + + Return value: + Nothing +*/ + +params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_patrolRadius"]; + +private _group = grpNull; +private _patrolSize = _module getVariable [QGVAR(patrolSize), 0]; + +[{ + params ["_args", "_idPFH"]; + _args params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_patrolRadius", "_group", "_patrolSize"]; + + if (_numberOfUnitsToSpawn <= 0) exitWith { + [_idPFH] call cba_fnc_removePerFrameHandler; + }; + + // create a group if the _currenGrouptUnitCount is == 0, set previous group to patrol + if (_currenGrouptUnitCount == 0) then { + _group = createGroup _side; + }; + + private _unitType = selectRandom _unitPoolArray; + private _unit = _group createUnit [_unitType, getPos _module, [], 0, "NONE"]; + + _currenGrouptUnitCount = _currenGrouptUnitCount + 1; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; + if (_currenGrouptUnitCount == _patrolSize) then { + [_group, _group, _patrolRadius, 5, "SAFE"] call cba_fnc_taskPatrol; + _currenGrouptUnitCount = 0; + }; + + _args set [4, _currenGrouptUnitCount]; + _args set [0, _numberOfUnitsToSpawn]; + _args set [6, _group]; + +}, 1, [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _patrolRadius, _group, _patrolSize]] call cba_fnc_addPerFrameHandler; + +// TODO: exclude virtualization until the group is spawned, then set to true + + diff --git a/addons/populate/functions/fnc_getValidPositions.sqf b/addons/populate/functions/fnc_getValidPositions.sqf index 97d7519ad..ea4708b8b 100644 --- a/addons/populate/functions/fnc_getValidPositions.sqf +++ b/addons/populate/functions/fnc_getValidPositions.sqf @@ -25,33 +25,45 @@ _area params ["", "_a", "_b"]; // get which dimension is largest to use as radius private _radius = [_b, _a] select (_a > _b); - TRACE_4("",_area,_a,_b,_radius); + // get all buildings in radius then in area + +// private _allBuildingsInArea = _allBuildingsInRadius inAreaArray _area; + private _allBuildingsInRadius = nearestTerrainObjects [_module, ["BUILDING", "HOUSE"], _radius, false, true]; -TRACE_1("",_allBuildingsInRadius); +private _allBuildingsInArea = _allBuildingsInRadius select {_x inArea _area}; -private _allBuildingsInArea = _allBuildingsInRadius inAreaArray _area; +// get the building positions for the buildings +private _buildingPositions = []; +{ + private _building = _x; + private _buildingPositionsArray = _building buildingPos -1; + { + private _buildingPosition = _x; + _buildingPositions pushBack _buildingPosition; + } forEach _buildingPositionsArray; +} forEach _allBuildingsInArea; -// // get all ai buildings in radius then in area -// private _allAiBuildingPositionsInRadius = GVAR(aiBuildingPositions) select {_x distance2D _module <= _radius}; -// private _aiBuildingPositions = _allAiBuildingPositionsInRadius inAreaArray _area; -// // get the building positions for the buildings -// private _buildingPositions = []; +// private _allAiBuildingPositionsInRadius = []; // { -// private _building = _x; -// private _buildingPositionsArray = _building buildingPos -1; -// { -// private _buildingPosition = _x; -// _buildingPositions pushBack _buildingPosition; -// } forEach _buildingPositionsArray; -// } forEach _allBuildingsInArea; - -// // append building positions and ai building positions -// private _spawnPositions = _buildingPositions + _aiBuildingPositions; - -// // call out to select position function -// [_spawnPositions, _module] call FUNC(selectSpawnPosition); +// _allAiBuildingPositionsInRadius pushBack _x; +// } forEach (_module nearObjects ["CBA_BuildingPos", _radius]); +// private _aiBuildingPositions = _allAiBuildingPositionsInRadius inAreaArray _area; + +// get all ai buildings in the area +private _aiBuildingPositions = []; +private _aiBuildingPositionsInArea = (_module nearObjects ["CBA_BuildingPos", _radius]) select {_x inArea _area}; +{ + _aiBuildingPositions pushBack (getPos _x); +} forEach _aiBuildingPositionsInArea; + +// append building positions and ai building positions +private _spawnPositions = _buildingPositions + _aiBuildingPositions; +TRACE_1("",count _spawnPositions); + +// call out to select position function +[_spawnPositions, _module] call FUNC(selectSpawnPosition); diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf index 958957812..7083f9a29 100644 --- a/addons/populate/functions/fnc_selectSpawnPosition.sqf +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -12,6 +12,7 @@ Parameters: 0: _spawnPositions + 1: _module Return value: Nothing @@ -36,41 +37,28 @@ private _fnc_getArrayFromModule = { _value }; +private _unitPool = _module getVariable [QGVAR(unitPoolString), []]; +private _unitPoolArray = parseSimpleArray _unitPool; +private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; +private _spawnPercentage = _module getVariable [QGVAR(percentageOfPositionsToOccupy), 0]; +private _numberOfPositionsToOccupy = round((count _spawnPositions) * (_spawnPercentage / 100)); private _numberOfUnitsToSpawn = [_module, QGVAR(numberOfUnits)] call _fnc_getArrayFromModule; private _side = _module getVariable [QGVAR(side), 0]; private _currenGrouptUnitCount = 0; -private _group = grpNull; -[{ - params ["_args", "_idPFH"]; - _args params ["_spawnPositions", "_currenGrouptUnitCount", "_numberOfUnitsToSpawn", "_side", "_group"]; +TRACE_2("",_unitPoolArray, _unitPool); - if (_numberOfUnitsToSpawn <= 0 || (count _spawnPositions) <= 0) exitWith { // TODO: if _numberOfUnitsToSpawn has left over units, handle in some way, maybe a patrol?? - [_idPFH] call cba_fnc_removePerFrameHandler; - }; - private _spawnPos = selectRandom _spawnPositions; - - // delete the position from the array to avoid doubling - _spawnPositions deleteAt (_spawnPositions findIf {_x == _spawnPos}); - - // create a group if the _currenGrouptUnitCount is == 0 - if (_currenGrouptUnitCount == 0) then { - _group = createGroup _side; - }; +if (_side isEqualTo 0) then { + _side = east; +}; - // call a create unit function - [_spawnPos, _module, _group] call FUNC(spawnUnit); - _currenGrouptUnitCount = _currenGrouptUnitCount + 1; - _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; - if (_currenGrouptUnitCount == 10) then { - _currenGrouptUnitCount = 0; - }; +if (_side isEqualTo 1) then { + _side = independent; +}; - // update pfh vars - _args set [0, _spawnPositions]; - _args set [1, _currenGrouptUnitCount]; - _args set [2, _numberOfUnitsToSpawn]; - _args set [4, _group]; +if (_side isEqualTo 2) then { + _side = west; +}; -}, 1, [_spawnPositions, _currenGrouptUnitCount, _numberOfUnitsToSpawn, _side, _group]] call cba_fnc_addPerFrameHandler; +[_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount] call FUNC(spawnBuildingUnit); From 0e99bcbae50d7c6aae37223081569389e3ab4096 Mon Sep 17 00:00:00 2001 From: abridgford Date: Sun, 19 May 2024 12:07:11 +0100 Subject: [PATCH 05/11] added statics, corrections, some refactor --- addons/populate/CfgVehicles.hpp | 4 +- addons/populate/XEH_PREP.hpp | 1 + .../populate/functions/fnc_createPatrols.sqf | 14 ++++-- .../functions/fnc_getValidPositions.sqf | 28 +++++------ .../functions/fnc_getValidStatics.sqf | 36 ++++++++++++++ .../functions/fnc_selectSpawnPosition.sqf | 7 ++- .../functions/fnc_spawnBuildingUnit.sqf | 47 +++++++++++++++---- 7 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 addons/populate/functions/fnc_getValidStatics.sqf diff --git a/addons/populate/CfgVehicles.hpp b/addons/populate/CfgVehicles.hpp index 1ed93253b..e23c784fe 100644 --- a/addons/populate/CfgVehicles.hpp +++ b/addons/populate/CfgVehicles.hpp @@ -37,7 +37,7 @@ class CfgVehicles { control = "EditShort"; validate = "NUMBER"; defaultValue = 50; - expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(patrolRadius),_value,true)]); }; class GVAR(patrolSize) { property = QGVAR(patrolSize); @@ -46,7 +46,7 @@ class CfgVehicles { control = "EditShort"; validate = "NUMBER"; defaultValue = 6; - expression = QUOTE(_this setVariable [ARR_3(QQGVAR(numberOfUnits),_value,true)]); + expression = QUOTE(_this setVariable [ARR_3(QQGVAR(patrolSize),_value,true)]); }; class GVAR(unitPoolString) { property = QGVAR(unitPoolString); diff --git a/addons/populate/XEH_PREP.hpp b/addons/populate/XEH_PREP.hpp index 54814b5e7..22c7490c1 100644 --- a/addons/populate/XEH_PREP.hpp +++ b/addons/populate/XEH_PREP.hpp @@ -3,3 +3,4 @@ PREP(getValidPositions); PREP(selectSpawnPosition); PREP(spawnBuildingUnit); PREP(createPatrols); +PREP(getValidStatics); diff --git a/addons/populate/functions/fnc_createPatrols.sqf b/addons/populate/functions/fnc_createPatrols.sqf index 1b565590b..48716f413 100644 --- a/addons/populate/functions/fnc_createPatrols.sqf +++ b/addons/populate/functions/fnc_createPatrols.sqf @@ -15,10 +15,12 @@ Nothing */ -params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_patrolRadius"]; +params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray"]; private _group = grpNull; +private _currenGrouptUnitCount = 0; private _patrolSize = _module getVariable [QGVAR(patrolSize), 0]; +private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; [{ params ["_args", "_idPFH"]; @@ -33,18 +35,22 @@ private _patrolSize = _module getVariable [QGVAR(patrolSize), 0]; _group = createGroup _side; }; + TRACE_4("",_numberOfUnitsToSpawn, _unitPoolArray, _currenGrouptUnitCount, _group); + private _unitType = selectRandom _unitPoolArray; - private _unit = _group createUnit [_unitType, getPos _module, [], 0, "NONE"]; + private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; + _unit setPos (getPos _module); _currenGrouptUnitCount = _currenGrouptUnitCount + 1; _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; if (_currenGrouptUnitCount == _patrolSize) then { - [_group, _group, _patrolRadius, 5, "SAFE"] call cba_fnc_taskPatrol; + // [_group, _group, _patrolRadius, 5, "SAFE"] call cba_fnc_taskPatrol; + [_group, _group, _patrolRadius, 6] call lambs_wp_fnc_taskPatrol; // infantry only _currenGrouptUnitCount = 0; }; - _args set [4, _currenGrouptUnitCount]; _args set [0, _numberOfUnitsToSpawn]; + _args set [4, _currenGrouptUnitCount]; _args set [6, _group]; }, 1, [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _patrolRadius, _group, _patrolSize]] call cba_fnc_addPerFrameHandler; diff --git a/addons/populate/functions/fnc_getValidPositions.sqf b/addons/populate/functions/fnc_getValidPositions.sqf index ea4708b8b..bf9dd3204 100644 --- a/addons/populate/functions/fnc_getValidPositions.sqf +++ b/addons/populate/functions/fnc_getValidPositions.sqf @@ -16,6 +16,8 @@ params ["_module"]; if !(isServer) exitWith {}; +private _statics = []; + // get the area private _areaParams = _module getVariable ["objectarea", []]; private _area = [getPos _module] + _areaParams; @@ -25,14 +27,9 @@ _area params ["", "_a", "_b"]; // get which dimension is largest to use as radius private _radius = [_b, _a] select (_a > _b); -TRACE_4("",_area,_a,_b,_radius); - // get all buildings in radius then in area - -// private _allBuildingsInArea = _allBuildingsInRadius inAreaArray _area; - -private _allBuildingsInRadius = nearestTerrainObjects [_module, ["BUILDING", "HOUSE"], _radius, false, true]; +private _allBuildingsInRadius = nearestTerrainObjects [_module, ["BUILDING", "HOUSE", "BUNKER"], _radius, false, true]; private _allBuildingsInArea = _allBuildingsInRadius select {_x inArea _area}; // get the building positions for the buildings @@ -46,24 +43,23 @@ private _buildingPositions = []; } forEach _buildingPositionsArray; } forEach _allBuildingsInArea; - -// private _allAiBuildingPositionsInRadius = []; -// { -// _allAiBuildingPositionsInRadius pushBack _x; -// } forEach (_module nearObjects ["CBA_BuildingPos", _radius]); -// private _aiBuildingPositions = _allAiBuildingPositionsInRadius inAreaArray _area; - // get all ai buildings in the area private _aiBuildingPositions = []; private _aiBuildingPositionsInArea = (_module nearObjects ["CBA_BuildingPos", _radius]) select {_x inArea _area}; { - _aiBuildingPositions pushBack (getPos _x); + // _aiBuildingPositions pushBack [getPos _x, getDir _x]; + _aiBuildingPositions pushBack _x; } forEach _aiBuildingPositionsInArea; +// get statics in the area +private _occupyStatics = _module getVariable [QGVAR(occupyStaticGunsBool), false]; +if (_occupyStatics) then { + _statics = [_module] call FUNC(getValidStatics); +}; + // append building positions and ai building positions private _spawnPositions = _buildingPositions + _aiBuildingPositions; -TRACE_1("",count _spawnPositions); // call out to select position function -[_spawnPositions, _module] call FUNC(selectSpawnPosition); +[_spawnPositions, _statics, _module] call FUNC(selectSpawnPosition); diff --git a/addons/populate/functions/fnc_getValidStatics.sqf b/addons/populate/functions/fnc_getValidStatics.sqf new file mode 100644 index 000000000..8ff59ca4b --- /dev/null +++ b/addons/populate/functions/fnc_getValidStatics.sqf @@ -0,0 +1,36 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Gets any valid static guns in the area + + Parameters: + 0: _module + + Return value: + _statics +*/ +params ["_module"]; + +if !(isServer) exitWith {}; + +// get the area +private _areaParams = _module getVariable ["objectarea", []]; +private _area = [getPos _module] + _areaParams; +if (_area isEqualTo []) exitWith {}; + +_area params ["", "_a", "_b"]; + +// get which dimension is largest to use as radius +private _radius = [_b, _a] select (_a > _b); + +// get all statics in the area +private _statics = []; +private _staticsInArea = (_module nearEntities [["StaticWeapon"], _radius]) select {_x inArea _area && (_x emptyPositions "" > 0)}; +{ + _statics pushBack _x; +} forEach _staticsInArea; + +_statics diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf index 7083f9a29..bbbd5dbcf 100644 --- a/addons/populate/functions/fnc_selectSpawnPosition.sqf +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -18,7 +18,7 @@ Nothing */ -params ["_spawnPositions", "_module"]; +params ["_spawnPositions", "_statics", "_module"]; if (!isServer) exitWith {}; @@ -39,12 +39,10 @@ private _fnc_getArrayFromModule = { private _unitPool = _module getVariable [QGVAR(unitPoolString), []]; private _unitPoolArray = parseSimpleArray _unitPool; -private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; private _spawnPercentage = _module getVariable [QGVAR(percentageOfPositionsToOccupy), 0]; private _numberOfPositionsToOccupy = round((count _spawnPositions) * (_spawnPercentage / 100)); private _numberOfUnitsToSpawn = [_module, QGVAR(numberOfUnits)] call _fnc_getArrayFromModule; private _side = _module getVariable [QGVAR(side), 0]; -private _currenGrouptUnitCount = 0; TRACE_2("",_unitPoolArray, _unitPool); @@ -61,4 +59,5 @@ if (_side isEqualTo 2) then { _side = west; }; -[_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount] call FUNC(spawnBuildingUnit); + +[_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _statics] call FUNC(spawnBuildingUnit); diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf index 44463fae0..e9d2627f3 100644 --- a/addons/populate/functions/fnc_spawnBuildingUnit.sqf +++ b/addons/populate/functions/fnc_spawnBuildingUnit.sqf @@ -15,32 +15,57 @@ Nothing */ -params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount"]; +params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_statics"]; private _group = grpNull; +private _currenGrouptUnitCount = 0; [{ params ["_args", "_idPFH"]; - _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group"]; + _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group", "_statics"]; + + private _pos = [0,0,0]; + private _dir = -1; if (_numberOfPositionsToOccupy <= 0) exitWith { [_idPFH] call cba_fnc_removePerFrameHandler; if (_numberOfUnitsToSpawn > 0) then { - [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _patrolRadius] call FUNC(createPatrols); + [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray] call FUNC(createPatrols); ;} }; - // create a group if the _currenGrouptUnitCount is == 0, set previous group to patrol - if (_currenGrouptUnitCount == 0) then { + // create a group if the _currenGrouptUnitCount is == 0 + if (_currenGrouptUnitCount isEqualTo 0) then { _group = createGroup _side; }; private _unitType = selectRandom _unitPoolArray; private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; + + // do statics first - use exit with to stop spawning of other units + if (_statics isNotEqualTo []) exitWith { + private _static = selectRandom _statics; + _unit moveInAny _static; + _statics deleteAt (_statics findIf {_x isEqualTo _static}); + _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + _args set [1, _numberOfUnitsToSpawn]; + _args set [7, _group]; + _args set [8, _statics]; + }; + private _spawnPos = selectRandom _spawnPositions; - // private _spawnPos = getPos _spawn; - _unit setPos _spawnPos; - TRACE_3("", _spawn, _spawnPos, _spawnPositions); + if (typeName _spawnPos == "OBJECT") then { // handle cba positions as theyre objects + _pos = getPos _spawnPos; + _dir = getDir _spawnPos; + } else { + _pos = _spawnPos; + }; + + TRACE_4("", _pos, _dir, typeName _spawnPos, _spawnPos); + + _unit setPos _pos; + _unit setDir _dir; // groups will follow the group leaders dir most of the time + _spawnPositions deleteAt (_spawnPositions findIf {_x isEqualTo _spawnPos}); _unit disableAI "PATH"; @@ -51,10 +76,12 @@ private _group = grpNull; _currenGrouptUnitCount = 0; }; - _args set [6, _currenGrouptUnitCount]; + _args set [0, _spawnPositions]; + _args set [1, _numberOfUnitsToSpawn]; _args set [2, _numberOfPositionsToOccupy]; + _args set [6, _currenGrouptUnitCount]; _args set [7, _group]; -}, 1, [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _group]] call cba_fnc_addPerFrameHandler; +}, 1, [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _group, _statics]] call cba_fnc_addPerFrameHandler; // TODO: exclude virtualization until the group is spawned, then set to true From 5b6b6e584007fc3b1dbf897f45bedf910610c067 Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 3 Jun 2024 15:18:40 +0100 Subject: [PATCH 06/11] reemove trace --- addons/populate/functions/fnc_createPatrols.sqf | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/populate/functions/fnc_createPatrols.sqf b/addons/populate/functions/fnc_createPatrols.sqf index 48716f413..3c0526482 100644 --- a/addons/populate/functions/fnc_createPatrols.sqf +++ b/addons/populate/functions/fnc_createPatrols.sqf @@ -35,8 +35,6 @@ private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; _group = createGroup _side; }; - TRACE_4("",_numberOfUnitsToSpawn, _unitPoolArray, _currenGrouptUnitCount, _group); - private _unitType = selectRandom _unitPoolArray; private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; _unit setPos (getPos _module); From c88520c89a5e79a44bab7c39cc4f0845cfcf3197 Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 3 Jun 2024 15:18:56 +0100 Subject: [PATCH 07/11] add params --- addons/populate/functions/fnc_selectSpawnPosition.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf index bbbd5dbcf..02265752d 100644 --- a/addons/populate/functions/fnc_selectSpawnPosition.sqf +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -12,7 +12,8 @@ Parameters: 0: _spawnPositions - 1: _module + 1: _statics + 2: _module Return value: Nothing From bfa26662168a5f431eaa908d43adba0cdf1d02e9 Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 3 Jun 2024 15:19:26 +0100 Subject: [PATCH 08/11] add params, fixes --- .../functions/fnc_spawnBuildingUnit.sqf | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf index e9d2627f3..9e91dd3fc 100644 --- a/addons/populate/functions/fnc_spawnBuildingUnit.sqf +++ b/addons/populate/functions/fnc_spawnBuildingUnit.sqf @@ -7,9 +7,13 @@ Spawns a unit at the passed position Parameters: - 0: _spawnPos - 1: _module - 2: _group + 0: _spawnPositions + 1: _numberOfUnitsToSpawn + 2: _numberOfPositionsToOccupy + 3: _side + 4: _module + 5: _unitPoolArray + 6: _statics Return value: Nothing @@ -27,7 +31,7 @@ private _currenGrouptUnitCount = 0; private _pos = [0,0,0]; private _dir = -1; - if (_numberOfPositionsToOccupy <= 0) exitWith { + if (_numberOfPositionsToOccupy <= 1) exitWith { [_idPFH] call cba_fnc_removePerFrameHandler; if (_numberOfUnitsToSpawn > 0) then { [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray] call FUNC(createPatrols); @@ -42,13 +46,19 @@ private _currenGrouptUnitCount = 0; private _unitType = selectRandom _unitPoolArray; private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; + _currenGrouptUnitCount = _currenGrouptUnitCount + 1; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; + // do statics first - use exit with to stop spawning of other units if (_statics isNotEqualTo []) exitWith { private _static = selectRandom _statics; _unit moveInAny _static; _statics deleteAt (_statics findIf {_x isEqualTo _static}); _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + _args set [1, _numberOfUnitsToSpawn]; + _args set [2, _numberOfPositionsToOccupy]; + _args set [6, _currenGrouptUnitCount]; _args set [7, _group]; _args set [8, _statics]; }; @@ -66,12 +76,10 @@ private _currenGrouptUnitCount = 0; _unit setPos _pos; _unit setDir _dir; // groups will follow the group leaders dir most of the time _spawnPositions deleteAt (_spawnPositions findIf {_x isEqualTo _spawnPos}); + _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; _unit disableAI "PATH"; - _currenGrouptUnitCount = _currenGrouptUnitCount + 1; - _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; - _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; if (_currenGrouptUnitCount == 10) then { _currenGrouptUnitCount = 0; }; From 4b1a43dabe45c41ed2cff7990119c50d1e2a990c Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 3 Jun 2024 21:30:21 +0100 Subject: [PATCH 09/11] tabs --- addons/populate/functions/fnc_createPatrols.sqf | 5 ++--- addons/populate/functions/fnc_spawnBuildingUnit.sqf | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/populate/functions/fnc_createPatrols.sqf b/addons/populate/functions/fnc_createPatrols.sqf index 3c0526482..31ba67736 100644 --- a/addons/populate/functions/fnc_createPatrols.sqf +++ b/addons/populate/functions/fnc_createPatrols.sqf @@ -23,8 +23,8 @@ private _patrolSize = _module getVariable [QGVAR(patrolSize), 0]; private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; [{ - params ["_args", "_idPFH"]; - _args params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_patrolRadius", "_group", "_patrolSize"]; + params ["_args", "_idPFH"]; + _args params ["_numberOfUnitsToSpawn", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_patrolRadius", "_group", "_patrolSize"]; if (_numberOfUnitsToSpawn <= 0) exitWith { [_idPFH] call cba_fnc_removePerFrameHandler; @@ -42,7 +42,6 @@ private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; _currenGrouptUnitCount = _currenGrouptUnitCount + 1; _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; if (_currenGrouptUnitCount == _patrolSize) then { - // [_group, _group, _patrolRadius, 5, "SAFE"] call cba_fnc_taskPatrol; [_group, _group, _patrolRadius, 6] call lambs_wp_fnc_taskPatrol; // infantry only _currenGrouptUnitCount = 0; }; diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf index 9e91dd3fc..ddab548a9 100644 --- a/addons/populate/functions/fnc_spawnBuildingUnit.sqf +++ b/addons/populate/functions/fnc_spawnBuildingUnit.sqf @@ -25,8 +25,8 @@ private _group = grpNull; private _currenGrouptUnitCount = 0; [{ - params ["_args", "_idPFH"]; - _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group", "_statics"]; + params ["_args", "_idPFH"]; + _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group", "_statics"]; private _pos = [0,0,0]; private _dir = -1; From b8c68c3917e7b36fc9b3b284d835ff8797768179 Mon Sep 17 00:00:00 2001 From: abridgford Date: Mon, 26 Aug 2024 09:35:24 +0100 Subject: [PATCH 10/11] updates --- addons/common/script_component.hpp | 2 +- addons/populate/Cfg3den.hpp | 20 ------------- addons/populate/CfgEventHandlers.hpp | 6 ---- addons/populate/CfgVehicles.hpp | 2 +- addons/populate/XEH_PREP.hpp | 6 ++-- addons/populate/XEH_postInit.sqf | 1 - .../populate/functions/fnc_createPatrols.sqf | 2 ++ .../functions/fnc_getValidPositions.sqf | 9 ++---- .../functions/fnc_selectSpawnPosition.sqf | 17 +++++++---- .../functions/fnc_spawnBuildingUnit.sqf | 30 ++++++++----------- addons/populate/initSettings.sqf | 24 --------------- addons/populate/script_component.hpp | 2 +- 12 files changed, 35 insertions(+), 86 deletions(-) delete mode 100644 addons/populate/Cfg3den.hpp delete mode 100644 addons/populate/XEH_postInit.sqf delete mode 100644 addons/populate/initSettings.sqf diff --git a/addons/common/script_component.hpp b/addons/common/script_component.hpp index 7fa6315f7..92bd454b5 100644 --- a/addons/common/script_component.hpp +++ b/addons/common/script_component.hpp @@ -2,7 +2,7 @@ #define COMPONENT_BEAUTIFIED Common #include "\u\uksf\addons\main\script_mod.hpp" -// #define DEBUG_MODE_FULL +#define DEBUG_MODE_FULL // #define DISABLE_COMPILE_CACHE // #define CBA_DEBUG_SYNCHRONOUS diff --git a/addons/populate/Cfg3den.hpp b/addons/populate/Cfg3den.hpp deleted file mode 100644 index 90352dba2..000000000 --- a/addons/populate/Cfg3den.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// class Cfg3DEN { -// class Object { -// class AttributeCategories { -// class uksf_attributes { -// class Attributes { -// class GVAR(excluded) { -// property = QGVAR(excluded); -// control = "Checkbox"; -// displayName = QUOTE(Cleanup exclude); -// tooltip = QUOTE(Excludes object from cleanup); -// expression = QUOTE(_this setVariable [ARR_3(QQGVAR(excluded),_value,true)]); -// typeName = "BOOL"; -// defaultValue = "(false)"; -// condition = "1"; -// }; -// }; -// }; -// }; -// }; -// }; diff --git a/addons/populate/CfgEventHandlers.hpp b/addons/populate/CfgEventHandlers.hpp index f6503c247..865276cfb 100644 --- a/addons/populate/CfgEventHandlers.hpp +++ b/addons/populate/CfgEventHandlers.hpp @@ -9,9 +9,3 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); }; }; - -class Extended_PostInit_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_SCRIPT(XEH_postInit)); - }; -}; diff --git a/addons/populate/CfgVehicles.hpp b/addons/populate/CfgVehicles.hpp index e23c784fe..6c372d20a 100644 --- a/addons/populate/CfgVehicles.hpp +++ b/addons/populate/CfgVehicles.hpp @@ -9,7 +9,7 @@ class CfgVehicles { }; class GVAR(populateAreaModule) : GVAR(module) { scope = 2; - displayName = "(AP) Auto Populate)"; + displayName = "Auto Populate)"; icon = "A3\ui_f\data\map\markers\nato\o_inf.paa"; portrait = "A3\ui_f\data\map\markers\nato\o_inf.paa"; function = QFUNC(modulePopulateArea); diff --git a/addons/populate/XEH_PREP.hpp b/addons/populate/XEH_PREP.hpp index 22c7490c1..2be96be01 100644 --- a/addons/populate/XEH_PREP.hpp +++ b/addons/populate/XEH_PREP.hpp @@ -1,6 +1,6 @@ -PREP(modulePopulateArea); +PREP(createPatrols); PREP(getValidPositions); +PREP(getValidStatics); +PREP(modulePopulateArea); PREP(selectSpawnPosition); PREP(spawnBuildingUnit); -PREP(createPatrols); -PREP(getValidStatics); diff --git a/addons/populate/XEH_postInit.sqf b/addons/populate/XEH_postInit.sqf deleted file mode 100644 index 421c54b49..000000000 --- a/addons/populate/XEH_postInit.sqf +++ /dev/null @@ -1 +0,0 @@ -#include "script_component.hpp" diff --git a/addons/populate/functions/fnc_createPatrols.sqf b/addons/populate/functions/fnc_createPatrols.sqf index 31ba67736..99fbaa581 100644 --- a/addons/populate/functions/fnc_createPatrols.sqf +++ b/addons/populate/functions/fnc_createPatrols.sqf @@ -28,11 +28,13 @@ private _patrolRadius = _module getVariable [QGVAR(patrolRadius), 0]; if (_numberOfUnitsToSpawn <= 0) exitWith { [_idPFH] call cba_fnc_removePerFrameHandler; + [QEGVAR(virtualisation,include), _group] call CBA_fnc_serverEvent; }; // create a group if the _currenGrouptUnitCount is == 0, set previous group to patrol if (_currenGrouptUnitCount == 0) then { _group = createGroup _side; + [QEGVAR(virtualisation,exclude), _group] call CBA_fnc_serverEvent; }; private _unitType = selectRandom _unitPoolArray; diff --git a/addons/populate/functions/fnc_getValidPositions.sqf b/addons/populate/functions/fnc_getValidPositions.sqf index bf9dd3204..37b49e7bf 100644 --- a/addons/populate/functions/fnc_getValidPositions.sqf +++ b/addons/populate/functions/fnc_getValidPositions.sqf @@ -44,12 +44,7 @@ private _buildingPositions = []; } forEach _allBuildingsInArea; // get all ai buildings in the area -private _aiBuildingPositions = []; private _aiBuildingPositionsInArea = (_module nearObjects ["CBA_BuildingPos", _radius]) select {_x inArea _area}; -{ - // _aiBuildingPositions pushBack [getPos _x, getDir _x]; - _aiBuildingPositions pushBack _x; -} forEach _aiBuildingPositionsInArea; // get statics in the area private _occupyStatics = _module getVariable [QGVAR(occupyStaticGunsBool), false]; @@ -58,7 +53,9 @@ if (_occupyStatics) then { }; // append building positions and ai building positions -private _spawnPositions = _buildingPositions + _aiBuildingPositions; +private _spawnPositions = _buildingPositions + _aiBuildingPositionsInArea; + +if (_spawnPositions isEqualTo [] && _statics isEqualTo []) exitWith {}; // call out to select position function [_spawnPositions, _statics, _module] call FUNC(selectSpawnPosition); diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf index 02265752d..70c49d534 100644 --- a/addons/populate/functions/fnc_selectSpawnPosition.sqf +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -38,15 +38,12 @@ private _fnc_getArrayFromModule = { _value }; -private _unitPool = _module getVariable [QGVAR(unitPoolString), []]; -private _unitPoolArray = parseSimpleArray _unitPool; +private _unitPoolArray = [_module, QGVAR(unitPoolString)] call _fnc_getArrayFromModule; private _spawnPercentage = _module getVariable [QGVAR(percentageOfPositionsToOccupy), 0]; private _numberOfPositionsToOccupy = round((count _spawnPositions) * (_spawnPercentage / 100)); -private _numberOfUnitsToSpawn = [_module, QGVAR(numberOfUnits)] call _fnc_getArrayFromModule; +private _numberOfUnitsToSpawn = _module getVariable [QGVAR(numberOfUnits), 0]; private _side = _module getVariable [QGVAR(side), 0]; -TRACE_2("",_unitPoolArray, _unitPool); - if (_side isEqualTo 0) then { _side = east; @@ -60,5 +57,15 @@ if (_side isEqualTo 2) then { _side = west; }; +// pre calculate what to spawn and how many + + +// spawn statics + +// spawn ai building positions + +// spawn building positions + +// spawn patrols [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _statics] call FUNC(spawnBuildingUnit); diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf index ddab548a9..d3a4048fc 100644 --- a/addons/populate/functions/fnc_spawnBuildingUnit.sqf +++ b/addons/populate/functions/fnc_spawnBuildingUnit.sqf @@ -23,16 +23,15 @@ params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy" private _group = grpNull; private _currenGrouptUnitCount = 0; +systemchat format ["st 1: %1", _statics]; [{ params ["_args", "_idPFH"]; _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group", "_statics"]; - private _pos = [0,0,0]; - private _dir = -1; - if (_numberOfPositionsToOccupy <= 1) exitWith { [_idPFH] call cba_fnc_removePerFrameHandler; + [QEGVAR(virtualisation,include), _group] call CBA_fnc_serverEvent; if (_numberOfUnitsToSpawn > 0) then { [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray] call FUNC(createPatrols); ;} @@ -41,28 +40,25 @@ private _currenGrouptUnitCount = 0; // create a group if the _currenGrouptUnitCount is == 0 if (_currenGrouptUnitCount isEqualTo 0) then { _group = createGroup _side; + [QEGVAR(virtualisation,exclude), _group] call CBA_fnc_serverEvent; }; private _unitType = selectRandom _unitPoolArray; private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; _currenGrouptUnitCount = _currenGrouptUnitCount + 1; - _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; - // do statics first - use exit with to stop spawning of other units - if (_statics isNotEqualTo []) exitWith { + // do statics + if (_statics isNotEqualTo []) then { private _static = selectRandom _statics; _unit moveInAny _static; - _statics deleteAt (_statics findIf {_x isEqualTo _static}); + _statics deleteAt (_statics find _static); _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; - - _args set [1, _numberOfUnitsToSpawn]; - _args set [2, _numberOfPositionsToOccupy]; - _args set [6, _currenGrouptUnitCount]; - _args set [7, _group]; - _args set [8, _statics]; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; }; + private _pos = [0,0,0]; + private _dir = -1; private _spawnPos = selectRandom _spawnPositions; if (typeName _spawnPos == "OBJECT") then { // handle cba positions as theyre objects _pos = getPos _spawnPos; @@ -75,8 +71,9 @@ private _currenGrouptUnitCount = 0; _unit setPos _pos; _unit setDir _dir; // groups will follow the group leaders dir most of the time - _spawnPositions deleteAt (_spawnPositions findIf {_x isEqualTo _spawnPos}); - _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + _spawnPositions deleteAt (_spawnPositions find _spawnPos); + _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; _unit disableAI "PATH"; @@ -84,12 +81,9 @@ private _currenGrouptUnitCount = 0; _currenGrouptUnitCount = 0; }; - _args set [0, _spawnPositions]; _args set [1, _numberOfUnitsToSpawn]; _args set [2, _numberOfPositionsToOccupy]; _args set [6, _currenGrouptUnitCount]; _args set [7, _group]; }, 1, [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _group, _statics]] call cba_fnc_addPerFrameHandler; - -// TODO: exclude virtualization until the group is spawned, then set to true diff --git a/addons/populate/initSettings.sqf b/addons/populate/initSettings.sqf deleted file mode 100644 index b84b34a4b..000000000 --- a/addons/populate/initSettings.sqf +++ /dev/null @@ -1,24 +0,0 @@ -// [ -// QGVAR(enabled), -// "CHECKBOX", -// ["Cleanup", "Enables cleanup of dead units/vehicles"], -// ["UKSF", QUOTE(COMPONENT_BEAUTIFIED)], -// false, -// 1, -// { -// params ["_value"]; - -// if (isServer && _value) then { -// [{call FUNC(cleanupCheck)}, [], 0] call CBA_fnc_waitAndExecute; -// }; -// } -// ] call CBA_settings_fnc_init; - -// [ -// QGVAR(delay), -// "SLIDER", -// ["Cleanup Delay", "Delay in seconds between death and cleanup"], -// ["UKSF", QUOTE(COMPONENT_BEAUTIFIED)], -// [5, 600, 300, 0], -// 1 -// ] call CBA_settings_fnc_init; diff --git a/addons/populate/script_component.hpp b/addons/populate/script_component.hpp index 7d43019d1..9cc9d1ed5 100644 --- a/addons/populate/script_component.hpp +++ b/addons/populate/script_component.hpp @@ -2,7 +2,7 @@ #define COMPONENT_BEAUTIFIED Populate #include "\u\uksf\addons\main\script_mod.hpp" -#define DEBUG_MODE_FULL +// #define DEBUG_MODE_FULL // #define DISABLE_COMPILE_CACHE // #define CBA_DEBUG_SYNCHRONOUS From 83e18f19f0eaa6a3b95de3459104ae63bc36051a Mon Sep 17 00:00:00 2001 From: abridgford Date: Tue, 3 Sep 2024 13:53:33 +0100 Subject: [PATCH 11/11] refactor --- addons/populate/XEH_PREP.hpp | 3 +- .../fnc_populateBuildingPositions.sqf | 70 +++++++++++++++ .../functions/fnc_populateStatics.sqf | 27 ++++++ .../functions/fnc_selectSpawnPosition.sqf | 18 ++-- .../functions/fnc_spawnBuildingUnit.sqf | 89 ------------------- 5 files changed, 107 insertions(+), 100 deletions(-) create mode 100644 addons/populate/functions/fnc_populateBuildingPositions.sqf create mode 100644 addons/populate/functions/fnc_populateStatics.sqf delete mode 100644 addons/populate/functions/fnc_spawnBuildingUnit.sqf diff --git a/addons/populate/XEH_PREP.hpp b/addons/populate/XEH_PREP.hpp index 2be96be01..f56af87f4 100644 --- a/addons/populate/XEH_PREP.hpp +++ b/addons/populate/XEH_PREP.hpp @@ -3,4 +3,5 @@ PREP(getValidPositions); PREP(getValidStatics); PREP(modulePopulateArea); PREP(selectSpawnPosition); -PREP(spawnBuildingUnit); +PREP(populateBuildingPositions); +PREP(populateStatics); diff --git a/addons/populate/functions/fnc_populateBuildingPositions.sqf b/addons/populate/functions/fnc_populateBuildingPositions.sqf new file mode 100644 index 000000000..786e7551d --- /dev/null +++ b/addons/populate/functions/fnc_populateBuildingPositions.sqf @@ -0,0 +1,70 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Sets the settings from the module up as global vars + + Parameters: + 0: The module object + + Return value: + Nothing +*/ + +params ["_spawnPositions", "_numberOfPositionsToOccupy", "_side", "_unitPoolArray", "_numberOfUnitsToSpawn"]; + +private _updatedNumberOfUnitsToSpawn = _numberOfUnitsToSpawn; +private _group = grpNull; +private _currenGrouptUnitCount = 0; + + +[{ + params ["_args", "_idPFH"]; + _args params ["_spawnPositions", "_numberOfPositionsToOccupy", "_side", "_unitPoolArray", "_updatedNumberOfUnitsToSpawn", "_currenGrouptUnitCount", "_group"]; + + if (_numberOfPositionsToOccupy <= 1) exitWith { + [_idPFH] call cba_fnc_removePerFrameHandler; + [QEGVAR(virtualisation,include), _group] call CBA_fnc_serverEvent; + _updatedNumberOfUnitsToSpawn + }; + + // create a group if the _currenGrouptUnitCount is == 0 + if (_currenGrouptUnitCount isEqualTo 0) then { + _group = createGroup _side; + [QEGVAR(virtualisation,exclude), _group] call CBA_fnc_serverEvent; + }; + + private _unitType = selectRandom _unitPoolArray; + private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; + _currenGrouptUnitCount = _currenGrouptUnitCount + 1; + + private _pos = selectRandom _spawnPositions; + if (_pos isEqualType []) then { + _unit setPos _pos; + } else { + _unit setPos (getPos _pos); + }; + + _spawnPositions deleteAt (_spawnPositions find _pos); + + // TRACE_4("", _pos, _dir, typeName _spawnPos, _spawnPos); + + _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; + _updatedNumberOfUnitsToSpawn = _updatedNumberOfUnitsToSpawn - 1; + + _unit disableAI "PATH"; + + if (_currenGrouptUnitCount == 10) then { + _currenGrouptUnitCount = 0; + }; + + _args set [0, _spawnPositions]; + _args set [1, _numberOfPositionsToOccupy]; + _args set [4, _updatedNumberOfUnitsToSpawn]; + _args set [5, _currenGrouptUnitCount]; + _args set [6, _group]; + +}, 1, [_spawnPositions, _numberOfPositionsToOccupy, _side, _unitPoolArray, _updatedNumberOfUnitsToSpawn, _currenGrouptUnitCount, _group]] call cba_fnc_addPerFrameHandler; + diff --git a/addons/populate/functions/fnc_populateStatics.sqf b/addons/populate/functions/fnc_populateStatics.sqf new file mode 100644 index 000000000..29175df6e --- /dev/null +++ b/addons/populate/functions/fnc_populateStatics.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" +/* + Author: + Bridg + + Description: + Sets the settings from the module up as global vars + + Parameters: + 0: The module object + + Return value: + Nothing +*/ + +params ["_statics", "_side", "_unitPoolArray", "_numberOfUnitsToSpawn"]; + +private _group = createGroup _side; +private _updatedNumberOfUnitsToSpawn = _numberOfUnitsToSpawn; + +{ + private _unit = _group createUnit [selectRandom _unitPoolArray, [0, 0, 0], [], 0, "NONE"]; + _unit moveInGunner _x; + _updatedNumberOfUnitsToSpawn - 1; +} forEach _statics; + +_updatedNumberOfUnitsToSpawn diff --git a/addons/populate/functions/fnc_selectSpawnPosition.sqf b/addons/populate/functions/fnc_selectSpawnPosition.sqf index 70c49d534..8b0837e29 100644 --- a/addons/populate/functions/fnc_selectSpawnPosition.sqf +++ b/addons/populate/functions/fnc_selectSpawnPosition.sqf @@ -57,15 +57,13 @@ if (_side isEqualTo 2) then { _side = west; }; -// pre calculate what to spawn and how many +// populate statics +_numberOfUnitsToSpawn = [_statics, _side, _unitPoolArray, _numberOfUnitsToSpawn] call FUNC(populateStatics); +// populate ai building positions and building positions +_numberOfUnitsToSpawn = [_spawnPositions, _numberOfPositionsToOccupy, _side, _unitPoolArray, _numberOfUnitsToSpawn] call FUNC(populateBuildingPositions); -// spawn statics - -// spawn ai building positions - -// spawn building positions - -// spawn patrols - -[_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _statics] call FUNC(spawnBuildingUnit); +// handle patrols +// if (_numberOfUnitsToSpawn > 0) then { +// [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray] call FUNC(createPatrols); +// ;} diff --git a/addons/populate/functions/fnc_spawnBuildingUnit.sqf b/addons/populate/functions/fnc_spawnBuildingUnit.sqf deleted file mode 100644 index d3a4048fc..000000000 --- a/addons/populate/functions/fnc_spawnBuildingUnit.sqf +++ /dev/null @@ -1,89 +0,0 @@ -#include "script_component.hpp" -/* - Author: - Bridg - - Description: - Spawns a unit at the passed position - - Parameters: - 0: _spawnPositions - 1: _numberOfUnitsToSpawn - 2: _numberOfPositionsToOccupy - 3: _side - 4: _module - 5: _unitPoolArray - 6: _statics - - Return value: - Nothing -*/ - -params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_statics"]; - -private _group = grpNull; -private _currenGrouptUnitCount = 0; -systemchat format ["st 1: %1", _statics]; - -[{ - params ["_args", "_idPFH"]; - _args params ["_spawnPositions", "_numberOfUnitsToSpawn", "_numberOfPositionsToOccupy", "_side", "_module", "_unitPoolArray", "_currenGrouptUnitCount", "_group", "_statics"]; - - if (_numberOfPositionsToOccupy <= 1) exitWith { - [_idPFH] call cba_fnc_removePerFrameHandler; - [QEGVAR(virtualisation,include), _group] call CBA_fnc_serverEvent; - if (_numberOfUnitsToSpawn > 0) then { - [_numberOfUnitsToSpawn, _side, _module, _unitPoolArray] call FUNC(createPatrols); - ;} - }; - - // create a group if the _currenGrouptUnitCount is == 0 - if (_currenGrouptUnitCount isEqualTo 0) then { - _group = createGroup _side; - [QEGVAR(virtualisation,exclude), _group] call CBA_fnc_serverEvent; - }; - - private _unitType = selectRandom _unitPoolArray; - private _unit = _group createUnit [_unitType, [0,0,0], [], 0, "NONE"]; - - _currenGrouptUnitCount = _currenGrouptUnitCount + 1; - - // do statics - if (_statics isNotEqualTo []) then { - private _static = selectRandom _statics; - _unit moveInAny _static; - _statics deleteAt (_statics find _static); - _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; - _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; - }; - - private _pos = [0,0,0]; - private _dir = -1; - private _spawnPos = selectRandom _spawnPositions; - if (typeName _spawnPos == "OBJECT") then { // handle cba positions as theyre objects - _pos = getPos _spawnPos; - _dir = getDir _spawnPos; - } else { - _pos = _spawnPos; - }; - - TRACE_4("", _pos, _dir, typeName _spawnPos, _spawnPos); - - _unit setPos _pos; - _unit setDir _dir; // groups will follow the group leaders dir most of the time - _spawnPositions deleteAt (_spawnPositions find _spawnPos); - _numberOfPositionsToOccupy = _numberOfPositionsToOccupy - 1; - _numberOfUnitsToSpawn = _numberOfUnitsToSpawn - 1; - - _unit disableAI "PATH"; - - if (_currenGrouptUnitCount == 10) then { - _currenGrouptUnitCount = 0; - }; - - _args set [1, _numberOfUnitsToSpawn]; - _args set [2, _numberOfPositionsToOccupy]; - _args set [6, _currenGrouptUnitCount]; - _args set [7, _group]; - -}, 1, [_spawnPositions, _numberOfUnitsToSpawn, _numberOfPositionsToOccupy, _side, _module, _unitPoolArray, _currenGrouptUnitCount, _group, _statics]] call cba_fnc_addPerFrameHandler;