Skip to content

Commit

Permalink
Merge pull request #248 from Global-Conflicts-ArmA/dev
Browse files Browse the repository at this point in the history
Dev to master merge
  • Loading branch information
PiZZAD0X authored Mar 28, 2023
2 parents a1e73a1 + c2eeb92 commit 8095c76
Show file tree
Hide file tree
Showing 71 changed files with 1,537 additions and 707 deletions.
18 changes: 12 additions & 6 deletions core/functions/fn_eventSpawned.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ params ["_unit"];
SETPVAR(_unit,Side,(side _unit));

if (
(isPlayer _unit ||
{!(GETVAR(_unit,DontTrack,false))}) &&
!isNull _unit &&
{isPlayer _unit ||
{!(GETVAR(_unit,DontTrack,false))}} &&
{!(GETVAR(_unit,Tracked,false))}
) then {
SETPVAR(_unit,Tracked,true);
Expand All @@ -29,12 +30,17 @@ if (
_x params ["_name", "_side", "_type", "_total", "_current"];
if (
((GETVAR(_unit,Side,sideUnknown)) isEqualto _side) &&
{(isPlayer _unit && {_type != "ai"}) || {_type == "ai"}}
{
(isPlayer _unit && {_type != "ai"}) ||
{!isPlayer _unit && {_type == "ai"}}
}
) exitWith {
if (_unit call FUNC(isAlive)) then {
TRACE_3("Setting new alive count",_unit,_total,_current);
_x set [3, _total + 1];
_x set [4, _current + 1];
private _newCurrent = _current + 1;
private _newTotal = _total + 1;
TRACE_3("Setting new alive count",_unit,_newTotal,_newCurrent);
_x set [3, _newTotal];
_x set [4, _newCurrent];
};
};
};
Expand Down
29 changes: 22 additions & 7 deletions core/functions/fn_untrackUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,33 @@

#include "script_component.hpp"

params ["_unit"];
params ["_unit", ["_forcedSide", sideEmpty, [sideEmpty]]];

if (GETVAR(_unit,Tracked,false)) then {
TRACE_2("untrackUnit",_unit,_forced);
private _forced = _forcedSide isNotEqualTo sideEmpty;

if (GETVAR(_unit,Tracked,false) || {_forced}) then {
GVAR(Teams) apply {
_x params ["", "_side", "_type", "_total", "_current"];
if (
((_unit getVariable [QGVAR(Side), sideEmpty]) isEqualTo _side) &&
{(((_type != "ai") && {isPlayer _unit}) || (_type == "ai"))}
(
(GETVAR(_unit,Side,sideUnknown)) isEqualto _side ||
{_forced && {_forcedSide isEqualto _side}}
) &&
{
(isPlayer _unit && {_type != "ai"} )||
{!isPlayer _unit && {_type == "ai"}}
}
) exitWith {
if (_unit call FUNC(isAlive)) then {
_x set [3, _total - 1];
_x set [4, _current - 1];
if (
_forced ||
{_unit call FUNC(isAlive)}
) then {
private _newCurrent = _current - 1;
private _newTotal = _total - 1;
TRACE_3("Setting new alive count",_unit,_newTotal,_newCurrent);
_x set [3, _newTotal];
_x set [4, _newCurrent];
};
};
};
Expand Down
28 changes: 14 additions & 14 deletions core/preinitServer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ GVAR(MissionEnded) = false; //Mission has not ended

[QGVAR(spawnedEvent), {
params ["_unit"];
//LOG_1("spawnedEvent started: %1",_unit);
TRACE_1("spawned Event",_unit);
_unit call FUNC(eventSpawned);
}] call CBA_fnc_addEventHandler;

[QGVAR(untrackEvent), {
params ["_unit"];
//LOG_1("untrackEvent started: %1",_unit);
_unit call FUNC(untrackUnit);
params ["_unit", ["_forced", sideEmpty, [sideEmpty]]];
TRACE_2("untrack Event",_unit,_forced);
[_unit, _forced] call FUNC(untrackUnit);
}] call CBA_fnc_addEventHandler;

[QGVAR(killedEvent), {
params [["_unit", objNull, [objNull]], ["_killer", objNull, [objNull]]];
//LOG_1("killedevent started: %1",_unit);
TRACE_2("killed Event",_unit,_killer);
[_unit, _killer] call FUNC(EventKilled);
}] call CBA_fnc_addEventHandler;

[QGVAR(respawnEvent), {
params [["_unit", objNull, [objNull]], ["_spectator", false, [false]]];
LOG_2("respawnEvent started: %1 spectator: %2",_unit,_spectator);
TRACE_2("respawnEvent started",_unit,_spectator);
[_unit, _spectator] call FUNC(EventRespawned);
}] call CBA_fnc_addEventHandler;

Expand Down Expand Up @@ -168,35 +168,35 @@ if (isClass (missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west")) t
GVAR(EndScreenDisplay_West) = ([missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west" >> "endScreenDisplay", "number", 1] call CBA_fnc_getConfigEntry) isEqualTo 1;
private _westTeam = [
west,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west" >> "name", "string", "USMC"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west" >> "type", "string", "player"] call CBA_fnc_getConfigEntry
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west" >> "name", "STRING", "USMC"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "west" >> "type", "STRING", "player"] call CBA_fnc_getConfigEntry
];
_westTeam call FUNC(AddTeam);
};
if (isClass (missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east")) then {
GVAR(EndScreenDisplay_East) = ([missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east" >> "endScreenDisplay", "number", 1] call CBA_fnc_getConfigEntry) isEqualTo 1;
private _eastTeam = [
east,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east" >> "name", "string", "VDV"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east" >> "type", "string", "ai"] call CBA_fnc_getConfigEntry
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east" >> "name", "STRING", "VDV"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "east" >> "type", "STRING", "ai"] call CBA_fnc_getConfigEntry
];
_eastTeam call FUNC(AddTeam);
};
if (isClass (missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent")) then {
GVAR(EndScreenDisplay_Ind) = ([missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent" >> "endScreenDisplay", "number", 1] call CBA_fnc_getConfigEntry) isEqualTo 1;
private _indTeam = [
independent,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent" >> "name", "string", "Local Militia"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent" >> "type", "string", "ai"] call CBA_fnc_getConfigEntry
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent" >> "name", "STRING", "Local Militia"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "independent" >> "type", "STRING", "ai"] call CBA_fnc_getConfigEntry
];
_indTeam call FUNC(AddTeam);
};
if (isClass (missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian")) then {
GVAR(EndScreenDisplay_Civ) = ([missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian" >> "endScreenDisplay", "number", 1] call CBA_fnc_getConfigEntry) isEqualTo 1;
private _civTeam = [
civilian,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian" >> "name", "string", "Local Civilians"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian" >> "type", "string", "ai"] call CBA_fnc_getConfigEntry
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian" >> "name", "STRING", "Local Civilians"] call CBA_fnc_getConfigEntry,
[missionConfigFile >> QGVAR(serverSettings) >> "Teams" >> "civilian" >> "type", "STRING", "ai"] call CBA_fnc_getConfigEntry
];
_civTeam call FUNC(AddTeam);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
params ["_unit"];

private _enemyInRange = [];
private _enemyArray = group _unit call FUNC(EnemyArray);
private _enemyArray = side _unit call FUNC(EnemyArray);
private _distance = GETVAR(_unit,bunkerDistance,(GVAR(bunkerDistance)));
if (_enemyArray isNotEqualTo []) then {
_enemyInRange = _enemyArray select {((vehicle _unit) distance2d _x) <= _distance};
Expand All @@ -12,4 +12,4 @@ if (_enemyArray isNotEqualTo []) then {
SETVAR(_unit,enemyInRange,_enemyInRange);
SETVAR(_unit,TargetSet,false);
SETVAR(_this,burstCount,0);
SETVAR(_this,BurstResetCount,0);
SETVAR(_this,BurstResetCount,0);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private _enemyInRange = false;
private _enemyArray = if (GETMVAR(CacheAllPlayers,true)) then {
[] call BIS_fnc_listPlayers;
} else {
_group call FUNC(EnemyArray);
side _leader call FUNC(EnemyArray);
};

if (_enemyArray isNotEqualTo []) then {
Expand Down
9 changes: 7 additions & 2 deletions modules/headless_ai/functions/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class COMPONENT {
class ForceHeal {};
class FormationChange {};
class FragmentMove {};
class GroupLoiter {};
class GroupPatrol {};
class LightGarrison {};
class LoiterAction {};
Expand All @@ -55,7 +54,6 @@ class COMPONENT {
class PlaceMine {};
class RadioCallForSupport {};
class RadioCommsEnemy {};
class RadioReportThreat {};
class ReinforcementResponse {};
class FireWeapon {};
class SuppressDirection {};
Expand All @@ -71,6 +69,7 @@ class COMPONENT {
class assignToArea {};
class CommanderHandler {};
class CommanderInit {};
class RadioReportThreat {};
};

class create {
Expand Down Expand Up @@ -110,15 +109,20 @@ class COMPONENT {
class Diag {
file = "modules\headless_ai\functions\Diag";
class checkView {};
class clearSight {};
class closestEnemy {};
class ClosestObject {};
class DriverCheck {};
class EnemyArray {};
class getGrenades {};
class getStance {};
class getWeaponType {};
class hasMine {};
class hasAT {};
class hasMG {};
class hasUGL {};
class UGLRoundType {};
class muzzleMags {};
class HasRadioGroup {};
class IRCheck {};
class isAimed {};
Expand All @@ -127,6 +131,7 @@ class COMPONENT {
class LOSCheck {};
class tempRemovePrimaryMags {};
class nearbyFriendlyEntities {};
class randPos {};
};

class Eventhandlers {
Expand Down
4 changes: 2 additions & 2 deletions modules/headless_ai/functions/Combat/fn_CombatAssault.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "script_component.hpp"

params ["_group", "_targetPos", ["_compradius", 250, [0]], ["_radius", 50, [0]]];
params ["_group", "_targetPos", ["_radius", 50, [0]]];
LOG_1("combatAssault started _this: %1",_this);

private _leader = leader _group;
Expand Down Expand Up @@ -138,6 +138,6 @@ private _assaultTaskPFH = [{
_unit setSuppression 0;
};
};
}, 4, [_group, _targetPos, _compradius]] call CBA_fnc_addPerFrameHandler;
}, 4, [_group, _targetPos, _radius]] call CBA_fnc_addPerFrameHandler;

SETVAR(_group,Task,"ASSAULT");
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
params ["_group", "_targetPos", ["_compradius", 250, [0]]];
LOG_1("combatAssault started _this: %1",_this);

private _leader = leader _group;
private _units = units _group;

[_group] call CBA_fnc_clearWaypoints;
Expand Down Expand Up @@ -38,7 +37,7 @@ private _assaultTaskPFH = [{
(getPosATL _leader distance2D _targetPos) <= _compradius
} ||
{
!(((_group call FUNC(EnemyArray)) findif {
!(((side _leader call FUNC(EnemyArray)) findif {
((_leader distance2D _x) <= (GETVAR(_group,AssaultEngageDistance,200))) &&
{[_leader, _x] call FUNC(LOSCheck)}
}) isEqualTo -1)
Expand Down
3 changes: 1 addition & 2 deletions modules/headless_ai/functions/Combat/fn_CombatAttack.sqf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "script_component.hpp"

params ["_group", "_targetPos"];
params ["_group", "_targetPos", "_radius"];

private _enemyDir = leader _group getDir _targetPos;
private _radius = 100;

//private _formation = if ((random 2) > 1) then {"LINE"} else {"WEDGE"};
//_group setFormation _formation;
Expand Down
50 changes: 40 additions & 10 deletions modules/headless_ai/functions/Combat/fn_CombatGarrison.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,55 @@
params [
"_group",
"_pos",
["_radius",100,[0]]
["_radius", 100, [0]],
["_buildings", [], [[]]]
];

//[_group, _pos, _radius] call CBA_fnc_taskDefend;
TRACE_2("Garrison Function:",_group,_buildings);

private _blgPos = [_pos, _radius, true] call FUNC(getBuildings);
private _firstPos = _blgPos select 0;
private _units = units _group select {!(INVEHICLE(_x))};

doStop units _group;
private _allPositions = [];
_buildings apply {
(_x buildingPos -1) select {!(_x in GVAR(OccupiedPositions))} apply {
_allPositions pushBackUnique _x;
};
};
TRACE_2("Garrison Function:",count _units,count _allPositions);
private _largerSearch = true;

units _group select {
!(INVEHICLE(_x))
} apply {
private _unitPos = if (_blgPos isEqualTo []) then {_firstPos} else {_blgPos deleteAt 0};
_units apply {
if (_allPositions isEqualTo []) then {
TRACE_2("Ran out of positions",_group,_allPositions);
if !(_largerSearch) exitWith {
TRACE_1("Larger Search disabled, setting to misc defence for remaining units",_group);
};
(nearestObjects [leader _group, ["House", "Strategic", "Ruins"], _radius * 3, true]) select {
((_x buildingPos -1) select {!(_x in GVAR(OccupiedPositions))}) isNotEqualTo []
} apply {
(_x buildingPos -1) select {!(_x in GVAR(OccupiedPositions))} apply {
_allPositions pushBackUnique _x;
};
};
TRACE_2("Ran larger search",_group,_allPositions);
};
private _unit = _x;
private _pos = _allPositions deleteAt 0;
SETVAR(_unit,Busy,true);
GVAR(OccupiedPositions) pushBackUnique _pos;
doStop _unit;
TRACE_2("unit occupying position",_unit,_pos);
[
{
params ["_unit", "_pos"];
_unit moveTo _pos;
_unit setDestination [_pos, "LEADER PLANNED", true];
}, [_x, _unitPos], 0.5 + random 2
[{
(_this select 0) distance (_this select 1) <= 1
}, {
params ["_unit", "_pos"];
SETVAR(_unit,Busy,false);
}, [_unit, _pos]] call CBA_fnc_waitUntilAndExecute;
}, [_unit, _pos], 0.5 + random 2
] call CBA_fnc_waitAndExecute;
};
Loading

0 comments on commit 8095c76

Please sign in to comment.