Skip to content

Commit

Permalink
added simple spawn (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 f17f59d commit 1a4a7d6
Show file tree
Hide file tree
Showing 19 changed files with 674 additions and 45 deletions.
1 change: 1 addition & 0 deletions addons/simpleSpawn/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afmf\addons\simplespawn
11 changes: 11 additions & 0 deletions addons/simpleSpawn/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Cfg3DEN {
class Object {
class AttributeCategories {
class PREFIX {
displayName = CSTRING(Attributes);
collapsed = 1;
class Attributes {};
};
};
};
};
12 changes: 12 additions & 0 deletions addons/simpleSpawn/CfgModuleCategories.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CfgFactionClasses {
class NO_CATEGORY;
class PREFIX: NO_CATEGORY {
displayName = CSTRING(Category);
};
};

class CfgVehicleClasses {
class PREFIX##_Vehicles {
displayName = CSTRING(Category);
};
};
13 changes: 13 additions & 0 deletions addons/simpleSpawn/DisplayEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CtrlMenuStrip;
class Display3DEN {
class Controls {
class MenuStrip: CtrlMenuStrip {
class Items {
items[] += {QUOTE(PREFIX)};
class PREFIX {
text = CSTRING(Toolbar);
};
};
};
};
};
8 changes: 8 additions & 0 deletions addons/simpleSpawn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Main

Base for other components. Provides CBA Macros framework, editor categories and similar.

### Authors

- [3Mydlo3](http://github.com/3Mydlo3)
- [Madin](http://github.com/Madin5)
19 changes: 19 additions & 0 deletions addons/simpleSpawn/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"cba_main"
};
author = "ArmaForces";
VERSION_CONFIG;
};
};

#include "CfgEden.hpp"
#include "CfgModuleCategories.hpp"
#include "DisplayEden.hpp"
77 changes: 77 additions & 0 deletions addons/simpleSpawn/functions/fn_despawn.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
MAI_fnc_simpleSpawnDespawn
Description:
Despawn units
Arguments:
0: Logic <OBJECT>
1:
Return Value:
None
*/

params [
["_logic", objNull, [objNull]]
];

if (_logic isEqualTo objNull) exitWith {};

private _spawnedGroups = _logic getVariable ["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 _deactivationDistance = _activation + _deactivation;

private _nearUnits = _logic nearEntities ["AllVehicles", _deactivationDistance];

private _playersNear = (_nearUnits findIf {isPlayer _x && {alive _x}}) != -1;

private _activateByDistance = ((_nearUnits findIf {isPlayer _x}) != -1);

if !(_activateByDistance) exitWith {
{
{
if (alive _x && stance _x == "STAND") then {
[_x,"AmovPercMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon"] remoteExecCall ["switchMove", 0];
};
} forEach units _x;
} forEach _spawnedGroups;
[
{
params [["_logic", objNull, [objNull]]];
private _spawnedGroups = _logic getVariable ["spawnedGroups", []];
private _groupsArray = [_spawnedGroups] call MAI_fnc_simpleSpawnGetGroups;
_groupsArray params ["_groups", "_vehiclesInfo", "_vehiclesToDelete"];
_logic setVariable ["groups", _groups];
_logic setVariable ["vehiclesInfo", _vehiclesInfo];
private _vehicles = _logic getVariable ["vehicles", []];
{
deleteVehicle _x;
} forEach _vehicles;
_logic setVariable ["vehicles", nil];
[
{_this call MAI_fnc_simpleSpawnWaitUntil},
_this,
random [0.9,1,1.1]
] call CBA_fnc_waitAndExecute;
},
_this,
0.5
] call CBA_fnc_waitAndExecute;
};

[
{_this call MAI_fnc_simpleSpawnDespawn},
_this,
random [0.9,1,1.1]
] call CBA_fnc_waitAndExecute;

Nil
52 changes: 52 additions & 0 deletions addons/simpleSpawn/functions/fn_firstState.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
MAI_fnc_simpleSpawnFirstState
Description:
wait until Resp Point condition meet to start script
Arguments:
0: Logic <OBJECT>
1:
Return Value:
None
*/

params [
["_logic", objNull],
"_activationTriggers",
["_groups", []],
["_vehiclesInfo", []],
["_interval", 0.1],
["_unitsPerInterval", 1],
["_deleteVehicles", false],
["_activation", 750],
["_deactivation", -1],
["_includeAir", false],
["_forceActivate", true],
["_checkBuildings", true],
["_activateCondition", {true}],
["_executionCodeUnit", {}],
["_executionCodePatrol", {}],
["_executionCodeVehicle", {}]
];

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, _groups, _vehiclesInfo] call MAI_fnc_simpleSpawnInterval;
125 changes: 125 additions & 0 deletions addons/simpleSpawn/functions/fn_getGroups.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
MAI_fnc_simpleSpawnGetGroups
Description:
Initiate simple spawn on server, then wait until condition meet
Arguments:
0: Logic <OBJECT>
1: Trigger activated <BOLEAN>
2: Placed by curator <BOLEAN>
Return Value:
None
*/
params [
["_groupsInput",[],[[]]]
];

private _groups = [];
private _vehiclesInfo = [];
private _vehiclesToDelete = [];
{
private _group = _x;
private _leader = leader _group;

private _side = side _x;
private _waypoints = [];
private _behaviour = behaviour _leader;
private _units = [];

// waypoints
{
private _wPos = waypointPosition _x;
// don't include "dummy" waypoint
if (_forEachIndex > 0) then {
private _wType = waypointType _x;
private _wTimeout = waypointTimeout _x;
private _behaviourWp = waypointBehaviour _x;
_waypoints pushBack [_wPos, _wType, _wTimeout, _behaviourWp];
};
} forEach (waypoints _group);
// units
{
private _unit = _x;
if (alive _unit) then {
private _type = typeOf _unit;
private _loadout = getUnitLoadout _unit;
private _pos = _unit modelToWorld [0, 0, 0];
private _dir = getDir _unit;
private _stance = unitPos _unit;

private _disabledAiFeatures = [];
{
if !(_unit checkAIFeature _x) then {
_disabledAiFeatures pushBack _x
};
}forEach [
"TARGET",
"AUTOTARGET",
"MOVE",
"ANIM",
"TEAMSWITCH",
"FSM",
"WEAPONAIM",
"AIMINGERROR",
"SUPPRESSION",
"CHECKVISIBLE",
"COVER",
"AUTOCOMBAT",
"PATH",
"MINEDETECTION",
"NVG",
"LIGHTS",
"RADIOPROTOCOL"
];

private _vehicleArray = [];
private _vehicle = vehicle _unit;
if !(_vehicle isKindOf "MAN") then {
private _vehicleRole = assignedVehicleRole _unit;
private _vehicleIndex = -1;
_vehicleIndex = _vehiclesToDelete findIf {_x isEqualTo _vehicle};
if (_vehicleIndex == -1) then {
private _vehInfo = _vehicle call MAI_fnc_getVehicleInfo;
_vehiclesInfo pushBack _vehInfo;
_vehiclesToDelete pushBack _vehicle;
_vehicleIndex = count _vehiclesInfo - 1;
};
private _assignedRole = assignedVehicleRole _unit;
private _cargoIndex = _vehicle getCargoIndex _unit;
_vehicleArray = [
_vehicle,
_assignedRole,
_cargoIndex,
_vehicleIndex
];
};

// check if building above/below unit is "alive"
// if true, do not spawn unit when that building will not be "alive"
private _posASL = getposASL _unit;
private _building = objNull;
private _buildingStatus = false;
private _objects = lineIntersectsWith [_posASL vectorAdd [0,0,0.5], _posASL vectorAdd [0,0,50], _unit, vehicle _unit, true];
if (_objects isEqualTo []) then {
_objects = lineIntersectsWith [_posASL vectorAdd [0,0,0.5], _posASL vectorAdd [0,0,-1.5], _unit, vehicle _unit, true];
};
if !(_objects isEqualTo [])then {
private _object = _objects select 0;
_building = _object;
_buildingStatus = alive _object;
};

_units pushBack [_type, _loadout, _pos, _dir, _stance, _disabledAiFeatures, _vehicleArray, _building, _buildingStatus];
};
deleteVehicle _unit;
} forEach units _group;
if !(_units isEqualTo []) then {
_groups pushBack [_side, _units, _waypoints, _behaviour, formation _group, combatMode _group, speedMode _group];
};
deleteGroup _group;
} forEach _groupsInput;

[_groups, _vehiclesInfo, _vehiclesToDelete]
Loading

0 comments on commit 1a4a7d6

Please sign in to comment.