Skip to content

Commit

Permalink
updated simpleSpawn to CBA standards (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin authored and Madin committed May 10, 2024
1 parent 1a4a7d6 commit 9ee4447
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
22 changes: 11 additions & 11 deletions addons/simpleSpawn/functions/fn_despawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ params [

if (_logic isEqualTo objNull) exitWith {};

private _spawnedGroups = _logic getVariable ["spawnedGroups", []];
private _spawnedGroups = _logic getVariable [QGVAR(spawnedGroups), []];
// check for every group if there are any allive units.
private _aliveGroupIndex = _spawnedGroups findIf {
(units _x findIf {alive _x}) != -1
};
if (_aliveGroupIndex == -1) exitWith {}; // no alive units left.

private _activation = _logic getVariable ["activation", 750];
private _deactivation = _logic getVariable ["deactivation", 750];
private _activation = _logic getVariable [QGVAR(activation), 750];
private _deactivation = _logic getVariable [QGVAR(deactivation), 750];
private _deactivationDistance = _activation + _deactivation;

private _nearUnits = _logic nearEntities ["AllVehicles", _deactivationDistance];
Expand All @@ -47,18 +47,18 @@ if !(_activateByDistance) exitWith {
[
{
params [["_logic", objNull, [objNull]]];
private _spawnedGroups = _logic getVariable ["spawnedGroups", []];
private _groupsArray = [_spawnedGroups] call MAI_fnc_simpleSpawnGetGroups;
private _spawnedGroups = _logic getVariable [QGVAR(spawnedGroups), []];
private _groupsArray = [_spawnedGroups] call FUNC(getGroups);
_groupsArray params ["_groups", "_vehiclesInfo", "_vehiclesToDelete"];
_logic setVariable ["groups", _groups];
_logic setVariable ["vehiclesInfo", _vehiclesInfo];
private _vehicles = _logic getVariable ["vehicles", []];
_logic setVariable [QGVAR(groups), _groups];
_logic setVariable [QGVAR(vehiclesInfo), _vehiclesInfo];
private _vehicles = _logic getVariable [QGVAR(vehicles), []];
{
deleteVehicle _x;
} forEach _vehicles;
_logic setVariable ["vehicles", nil];
_logic setVariable [QGVAR(vehicles), nil];
[
{_this call MAI_fnc_simpleSpawnWaitUntil},
{_this call FUNC(WaitUntil)},
_this,
random [0.9,1,1.1]
] call CBA_fnc_waitAndExecute;
Expand All @@ -69,7 +69,7 @@ if !(_activateByDistance) exitWith {
};

[
{_this call MAI_fnc_simpleSpawnDespawn},
{_this call call FUNC(despawn)},
_this,
random [0.9,1,1.1]
] call CBA_fnc_waitAndExecute;
Expand Down
32 changes: 16 additions & 16 deletions addons/simpleSpawn/functions/fn_firstState.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ params [
];

if (_logic isEqualTo objNull) exitWith {};
_logic setVariable ["activationTriggers", _activationTriggers];
_logic setVariable ["groups", _groups];
_logic setVariable ["vehiclesInfo", _vehiclesInfo];
_logic setVariable ["activation", _activation];
_logic setVariable ["deactivation", _deactivation];
_logic setVariable ["includeAir", _includeAir];
_logic setVariable ["forceActivate", _forceActivate];
_logic setVariable ["checkBuildings", _checkBuildings];
_logic setVariable ["activateCondition", _activateCondition];
_logic setVariable ["interval", _interval];
_logic setVariable ["deleteVehicles", _deleteVehicles];
_logic setVariable ["unitsPerInterval", _unitsPerInterval];
_logic setVariable ["executionCodeUnit", _executionCodeUnit];
_logic setVariable ["executionCodePatrol", _executionCodePatrol];
_logic setVariable ["executionCodeVehicle", _executionCodeVehicle];
_logic setVariable [QGVAR(activationTriggers), _activationTriggers];
_logic setVariable [QGVAR(groups), _groups];
_logic setVariable [QGVAR(vehiclesInfo), _vehiclesInfo];
_logic setVariable [QGVAR(activation), _activation];
_logic setVariable [QGVAR(deactivation), _deactivation];
_logic setVariable [QGVAR(includeAir), _includeAir];
_logic setVariable [QGVAR(forceActivate), _forceActivate];
_logic setVariable [QGVAR(checkBuildings), _checkBuildings];
_logic setVariable [QGVAR(activateCondition), _activateCondition];
_logic setVariable [QGVAR(interval), _interval];
_logic setVariable [QGVAR(deleteVehicles), _deleteVehicles];
_logic setVariable [QGVAR(unitsPerInterval), _unitsPerInterval];
_logic setVariable [QGVAR(executionCodeUnit), _executionCodeUnit];
_logic setVariable [QGVAR(executionCodePatrol), _executionCodePatrol];
_logic setVariable [QGVAR(executionCodeVehicle), _executionCodeVehicle];

[_logic, _groups, _vehiclesInfo] call MAI_fnc_simpleSpawnInterval;
[_logic, _groups, _vehiclesInfo] call call FUNC(interval);
2 changes: 1 addition & 1 deletion addons/simpleSpawn/functions/fn_getGroups.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private _vehiclesToDelete = [];
private _vehicleIndex = -1;
_vehicleIndex = _vehiclesToDelete findIf {_x isEqualTo _vehicle};
if (_vehicleIndex == -1) then {
private _vehInfo = _vehicle call MAI_fnc_getVehicleInfo;
private _vehInfo = _vehicle call EFUNC(main, getVehicleInfo);
_vehiclesInfo pushBack _vehInfo;
_vehiclesToDelete pushBack _vehicle;
_vehicleIndex = count _vehiclesInfo - 1;
Expand Down
12 changes: 6 additions & 6 deletions addons/simpleSpawn/functions/fn_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ private _groupSync = [];
};
} forEach _synchronizedObjects;

_logic setVariable ["activationTriggers",_activationTriggers];
_logic setVariable [QGVAR(activationTriggers),_activationTriggers];

private _groupsArray = [_groupSync] call MAI_fnc_simpleSpawnGetGroups;
private _groupsArray = [_groupSync] call FUNC(GetGroups);
_groupsArray params ["_groups", "_vehiclesInfo", "_vehiclesToDelete"];
_logic setVariable ["vehiclesInfo", _vehiclesInfo];
_logic setVariable [QGVAR(vehiclesInfo), _vehiclesInfo];

private _deleteVehicles = _logic getVariable ["deleteVehicles", false];
private _deleteVehicles = _logic getVariable [QGVAR(deleteVehicles), false];
if (_deleteVehicles) then {
{deleteVehicle _x} forEach _vehiclesToDelete;
};

_logic setVariable ["groups", _groups];
_logic setVariable [QGVAR(groups), _groups];

[
{_this call MAI_fnc_simpleSpawnWaitUntil},
{_this call FUNC(WaitUntil)},
[_logic],
1
]call CBA_fnc_waitAndExecute;
Expand Down
38 changes: 19 additions & 19 deletions addons/simpleSpawn/functions/fn_interval.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ params [
if (_logic isEqualTo objNull) exitWith {};
if (_groups isEqualTo []) exitWith {};

private _deleteVehicles = _logic getVariable ["deleteVehicles", false];
private _vehicles = _logic getVariable ["vehicles", []];
private _unitsPerInterval = _logic getVariable ["unitsPerInterval", 1];
private _interval = _logic getVariable ["interval", 0.1];
private _executionCodeVehicle = _logic getVariable ["executionCodeVehicle", {}];
private _checkBuildings = _logic getVariable ["checkBuildings", true];
private _deleteVehicles = _logic getVariable [QGVAR(deleteVehicles), false];
private _vehicles = _logic getVariable [QGVAR(vehicles), []];
private _unitsPerInterval = _logic getVariable [QGVAR(unitsPerInterval), 1];
private _interval = _logic getVariable [QGVAR(interval), 0.1];
private _executionCodeVehicle = _logic getVariable [QGVAR(executionCodeVehicle), {}];
private _checkBuildings = _logic getVariable [QGVAR(checkBuildings), true];

// spawn vehicles
if (_deleteVehicles && !(_vehiclesInfo isEqualTo [])) exitWith {
private _vehiclesInfoNew = +_vehiclesInfo;
for "_i" from 1 to (_unitsPerInterval min count _vehiclesInfoNew) do {
private _vehInfo = _vehiclesInfoNew deleteAt 0;
private _vehicle = _vehInfo call MAI_fnc_createVehicleFromInfo;
private _vehicle = _vehInfo call EFUNC(main, createVehicleFromInfo);
[_vehicle] call _executionCodeVehicle;
_vehicles pushBack _vehicle;
_logic setVariable ["vehicles", _vehicles];
_logic setVariable [QGVAR(vehicles), _vehicles];
};
[
{
_this call MAI_fnc_simpleSpawnInterval;
_this call FUNC(interval);
},
[_logic, _groups, _vehiclesInfoNew],
_interval
] call CBA_fnc_waitAndExecute;
};

private _executionCodeUnit = _logic getVariable ["executionCodeUnit", {}];
private _executionCodePatrol = _logic getVariable ["executionCodePatrol", {}];
private _executionCodeUnit = _logic getVariable [QGVAR(executionCodeUnit), {}];
private _executionCodePatrol = _logic getVariable [QGVAR(executionCodePatrol), {}];

private _spawnedUnits = _logic getVariable ["spawnedUnits", 0];

Expand All @@ -61,9 +61,9 @@ if (_group isEqualTo grpNull) then {
_group = createGroup [_side, true];
_groupArray set [7, _group];
[_group] call _executionCodePatrol;
private _spawnedGroups = _logic getVariable ["spawnedGroups", []];
private _spawnedGroups = _logic getVariable [QGVAR(spawnedGroups), []];
_spawnedGroups pushBack _group;
_logic setVariable ["spawnedGroups", _spawnedGroups];
_logic setVariable [QGVAR(spawnedGroups), _spawnedGroups];
{
_x params ["_wPos", "_wType", "_wTimeout", "_behaviourWp"];
private _wp =_group addWaypoint [_wPos, 0];
Expand All @@ -89,15 +89,15 @@ while {_spawnedUnits < _unitsPerInterval && !(_units isEqualTo [])} do {
_vehicle isKindOf "StaticWeapon" &&
{!(alive _building isEqualTo _buildingStatus)}
}) exitWith {};
_unit = [_group, _type, _pos, _dir, 0, false] call MAI_fnc_spawnAI;
_unit = [_group, _type, _pos, _dir, 0, false] call EFUNC(main, spawnAI);
_spawnedUnits = _spawnedUnits + 1;
_unit setUnitLoadout _loadout;
_group addVehicle _vehicle;
[_unit, _vehicle, _role, _cargoIndex] call MAI_fnc_moveInVehicleRole;
[_unit, _vehicle, _role, _cargoIndex] call EFUNC(main, moveInVehicleRole);
};
} else {
if (!_checkBuildings || alive _building isEqualTo _buildingStatus) then {
_unit = [_group, _type, _pos, _dir] call MAI_fnc_spawnAI;
_unit = [_group, _type, _pos, _dir] call EFUNC(main, spawnAI);
_spawnedUnits = _spawnedUnits + 1;
_unit setUnitLoadout _loadout;
_unit setUnitPos _stance;
Expand All @@ -123,10 +123,10 @@ while {_spawnedUnits < _unitsPerInterval && !(_units isEqualTo [])} do {
};

if (_groups isEqualTo []) exitWith {
private _deactivation = _logic getVariable ["deactivation", -1];
private _deactivation = _logic getVariable [QGVAR(deactivation), -1];
if (_deactivation >= 0) then {
[
{_this call MAI_fnc_simpleSpawnDespawn},
{_this call FUNC(despawn)},
[_logic],
1
]call CBA_fnc_waitAndExecute;
Expand All @@ -135,7 +135,7 @@ if (_groups isEqualTo []) exitWith {

[
{
_this call MAI_fnc_simpleSpawnInterval;
_this call FUNC(interval);
},
_this,
_interval
Expand Down
38 changes: 19 additions & 19 deletions addons/simpleSpawn/functions/fn_waitUntil.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ params [["_logic",objNull]];

if (_logic isEqualTo objNull) exitWith {};

private _activate = [_logic] call MAI_fnc_checkActivateConditions;
private _activate = [_logic] call FUNC(checkActivateConditions);

if (_activate) then {
private _groups = _logic getVariable ["groups", []];
private _vehiclesInfo = _logic getVariable ["vehiclesInfo" ,[]];
private _groups = _logic getVariable [QGVAR(groups), []];
private _vehiclesInfo = _logic getVariable [QGVAR(vehiclesInfo) ,[]];

if (!isServer && !hasInterface) exitWith {
[_logic, _groups, _vehiclesInfo] call MAI_fnc_simpleSpawnInterval;
[_logic, _groups, _vehiclesInfo] call FUNC(interval);
};

private _activationTriggers = _logic getVariable ["activationTriggers" ,[]];
private _interval = _logic getVariable ["interval" ,[]];
private _unitsPerInterval = _logic getVariable ["unitsPerInterval", []];
private _deleteVehicles = _logic getVariable ["deleteVehicles", false];
private _activation = _logic getVariable ["activation", 750];
private _deactivation = _logic getVariable ["deactivation", -1];
private _includeAir = _logic getVariable ["includeAir", false];
private _forceActivate = _logic getVariable ["forceActivate", false];
private _checkBuildings = _logic getVariable ["checkBuildings", true];
private _activateCondition = _logic getVariable ["activateCondition", {true}];
private _executionCodeUnit = _logic getVariable ["executionCodeUnit", {}];
private _executionCodePatrol = _logic getVariable ["executionCodePatrol", {}];
private _executionCodeVehicle = _logic getVariable ["executionCodeVehicle", {}];
private _activationTriggers = _logic getVariable [QGVAR(activationTriggers) ,[]];
private _interval = _logic getVariable [QGVAR(interval) ,[]];
private _unitsPerInterval = _logic getVariable [QGVAR(unitsPerInterval), []];
private _deleteVehicles = _logic getVariable [QGVAR(deleteVehicles), false];
private _activation = _logic getVariable [QGVAR(activation), 750];
private _deactivation = _logic getVariable [QGVAR(deactivation), -1];
private _includeAir = _logic getVariable [QGVAR(includeAir), false];
private _forceActivate = _logic getVariable [QGVAR(forceActivate), false];
private _checkBuildings = _logic getVariable [QGVAR(checkBuildings), true];
private _activateCondition = _logic getVariable [QGVAR(activateCondition), {true}];
private _executionCodeUnit = _logic getVariable [QGVAR(executionCodeUnit), {}];
private _executionCodePatrol = _logic getVariable [QGVAR(executionCodePatrol), {}];
private _executionCodeVehicle = _logic getVariable [QGVAR(executionCodeVehicle), {}];

private _owner = call MAI_fnc_HCfind;
private _owner = call EFUNC(main, HCfind);
[
_logic,
_activationTriggers,
Expand All @@ -59,7 +59,7 @@ if (_activate) then {
_executionCodeUnit,
_executionCodePatrol,
_executionCodeVehicle
] remoteExecCall ["MAI_fnc_simpleSpawnFirstState",_owner,false];
] remoteExecCall [QGWAR(FirstState),_owner,false];
}else
{
[{_this call MAI_fnc_simpleSpawnWaitUntil},
Expand Down

0 comments on commit 9ee4447

Please sign in to comment.