Skip to content

Update init.sqf and add VCOMAI : AI enhancement #110

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,408 changes: 3,408 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/VCOMAI/AIBEHAVIORNEW.fsm

Large diffs are not rendered by default.

586 changes: 586 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/VCOMAI/DangerIdentify.fsm

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/VCOMAI/functions/#crater.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
_list = position player nearObjects ["#explosion",20];
hint format ["%1",_list];


BOBBY = true;
while {BOBBY} do
{
sleep 1;
_list = position player nearObjects ["#crater",100];
{
_hierarchy = configHierarchy (configFile >> "CfgVehicles" >> (typeof _x));
hint format ["%1",_hierarchy];
} foreach _list;
};


BOBBY = false;




hint format ["%1",_hierarchy];

#crater - ground hits,
#crateronvehicle - vehicle/body/buildings (possible not all buildings/structures) hits.

(these two are long living, so must be obtained each already existing to sift off old ones (for this eg craters can be checked first time around aiming position in shooting moment, before bullet reach its destination), still it is not reliable, as there can be many new impacts there in one check cycle, if more than one bullet flies towards that point at the moment)

additionally: #explosion object type for "boom!s" - short live.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//Created on 8/14/14
// Modified on : 8/3/16: Resolved AI getting stuck when no enemies existed, or enemies were far away.

private ["_Unit", "_VCOM_MovedRecently", "_VCOM_VisuallyCanSee", "_NearestEnemy", "_intersections"];

_Unit = _this select 0;
_VCOM_MovedRecently = _this select 1;
_VCOM_VisuallyCanSee = _this select 2;
_VCOM_MovedRecentlyCover = _this select 3;

////systemchat format ["M %1",_Unit];
//_NearestEnemy = _Unit call VCOMAI_ClosestEnemy;
_NearestEnemy = _Unit findNearestEnemy _Unit;
_DistanceCheck = _NearestEnemy distance _Unit;
//if (isNil "_NearestEnemy" || {_VCOM_MovedRecentlyCover} || {(typeName _NearestEnemy isEqualTo "ARRAY")} || {isNil "_Unit"} || {!(alive _NearestEnemy)} || {(_NearestEnemy distance _Unit) > 5000}) exitWith {};
if (isNil "_NearestEnemy" || {(typeName _NearestEnemy isEqualTo "ARRAY")} || {isNil "_Unit"} || {!(alive _NearestEnemy)} || {(_DistanceCheck) > 2000}) exitWith {_Unit forcespeed -1;};


//This will tell the AI to regroup if they have wandered too far.
_ReturnedFriendly = [units (group _Unit),_Unit] call VCOMAI_ClosestObject;
if (isNil "_ReturnedFriendly") then {_ReturnedFriendly = [0,0,0]};
if (_ReturnedFriendly distance _Unit > 30 && !(_ReturnedFriendly isEqualTo [0,0,0])) then
{
_Unit doMove (getpos _ReturnedFriendly);_Unit forcespeed -1;
if (VCOM_AIDEBUG isEqualTo 1) then
{
[_Unit,"I wandered too far :(. Returning to group.",15,20000] remoteExec ["3DText",0];
};

};

//_intersections = lineIntersectsSurfaces [eyePos _Unit,eyepos _NearestEnemy,_Unit,_NearestEnemy, true, 1];
_cansee = [_Unit, "VIEW"] checkVisibility [eyePos _Unit, eyePos _NearestEnemy];
//systemchat format ["%1:,%2 -> %3",_unit,_cansee,_DistanceCheck];
//hintsilent format ["%2: %1",_cansee,_Unit];
//If the enemy is REALLY close, JUST OPEN FIRE!
//if ((count _intersections) isEqualTo 0 && ((_DistanceCheck) < 50)) exitwith

if (_cansee > 0 && {(_DistanceCheck) < 100}) exitwith
{
_VCOM_VisuallyCanSee = true;
_Unit forceSpeed 0;
_Unit setUnitPos "AUTO";
_Unit doSuppressiveFire _NearestEnemy;
if (VCOM_AIDEBUG isEqualTo 1) then
{
[_Unit,"Enemy is close! Fire fire fire!",15,20000] remoteExec ["3DText",0];
};
_VCOM_VisuallyCanSee

};


if (_VCOM_MovedRecentlyCover) exitwith {};
if (_DistanceCheck < 100) then {_Unit forcespeed 0.7;};

if (_cansee > 0 && ((_DistanceCheck) < 500)) exitwith
{
_VCOM_VisuallyCanSee = true;
_Unit setUnitPos "AUTO";
_Unit doSuppressiveFire _NearestEnemy;
_VCOM_VisuallyCanSee
};


if (_VCOM_MovedRecently) exitWith {};


if (_cansee > 0 && ((_DistanceCheck) < 1000)) then
{
_VCOM_VisuallyCanSee = true;
_Unit setUnitPos "AUTO";
_Unit doSuppressiveFire _NearestEnemy;
//systemchat "SUPPRESSIVE!";
}
else
{
_VCOM_VisuallyCanSee = false;
//_Unit spawn {sleep 10;if !(_Unit getVariable "VCOM_VisuallyCanSee") then {_Unit forceSpeed -1;};};
};
//};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private ["_Behavior"];

_Behavior = behaviour _this;
_Behavior
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
private ["_ClosestDead"];

//AllDeadMen because, you know, WOMEN DONT EXIST IN THIS GAME... -_-
private _nearlyallDeadMen = allDeadMen select {!(_x isKindOf "Animal")};
private _ClosestDead = [_nearlyallDeadMen,_this] call VCOMAI_ClosestObject;
if (isNil ("_ClosestDead")) then {_ClosestDead = [0,0,0];};
_ClosestDead
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
private ["_CraterList"];

_CraterList = position _this nearObjects ["#crater",100];

//Check if an enemy is close to the AI or not.
_Enemy = _this call VCOMAI_ClosestEnemy;
if (isNil "_Enemy") then {_Enemy = [0,0,0]};

if (_Enemy distance _this > 1000) then {_CraterList = [];};

_CraterList
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//Currently not being used
{
[_x,false,false,false,false] spawn VCOMAI_MoveToCover;
} foreach (units (group _this));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private ["_KnownEnemy"];

_KnownEnemy = _this findNearestEnemy _this;
_KnownEnemy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(group _this) setBehaviour "COMBAT";
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/*
_AssignedCargo = assignedCargo (vehicle _this);

if (_this in _AssignedCargo) then
{
[_this] orderGetIn false;
_this leaveVehicle (vehicle _this);
unassignVehicle _this;
commandGetOut _this;
doGetOut _this;
_this action ["eject", _Vehicle];
(vehicle _this) land "GET OUT";
_Vehicle land "GET OUT";
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_Unit = _this select 0;
if (isPlayer _Unit) exitWith {};
if ((vehicle _Unit) != _Unit) exitWith {};


//Lay down
_Unit setUnitPosWeak "DOWN";
[_Unit,false,false,false,false] spawn VCOMAI_MoveToCover;
if (VCOM_AIDEBUG isEqualTo 1) then
{
[_Unit,"I'M HIT!",30,20000] remoteExec ["3DText",0];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if (VCOM_STATICGARRISON isEqualTo 0) exitWith {};
_Unit = _this;
_Position = getPosATL _Unit;

_weapon = nearestObject [_Position,"StaticWeapon"];
if (isNull _weapon || {(_weapon distance _Unit) > 100}) exitWith {};

_AssignedGunner = assignedGunner _weapon;
if (isNull _AssignedGunner) then
{
_Unit doMove (getposATL _weapon);
_Unit assignAsGunner _weapon;
[_Unit] orderGetIn true;
_Waiting = 0;
while {_Waiting isEqualTo 0} do
{
sleep 1;
if ((_Unit distance _Weapon) < 3) then {_Waiting = 1};
};
_Unit moveInGunner _weapon;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//AI will use artillery/mortars when possible. This script makes it so each AI gets checked if they are arty capable or not
//First hash 6/14/2014
//Modified 8/15/14 - 8/5/15

//Find unit to be doing check upon.
_Unit = _this;

_Vehicle = (vehicle _Unit);
if (_Vehicle in ArtilleryArray) exitWith {};
//Pull the vehicle the unit is in.

//Get the vehicles class name.
_class = typeOf _Vehicle;
if (isNil ("_class")) exitWith {};
//player sidechat format ["%1",_class];
//Figure out if it is defined as artillery
_ArtyScan = getNumber(configfile/"CfgVehicles"/_class/"artilleryScanner");

//Exit the script if it is not defined as artillery
if (isNil "_ArtyScan") exitWith
{

//Check if unit somehow is in the ArtilleryArray and remove them. This can happen to units who were inside artillery pieces but ejected.
if (_Vehicle in ArtilleryArray) then
{
ArtilleryArray = ArtilleryArray - [_Vehicle];
};

};

if (_ArtyScan isEqualTo 1) then
{

//player sidechat format ["Added Unit to Arty: %1",_Vehicle];
//ArtilleryArray = ArtilleryArray + [_Vehicle];
ArtilleryArray pushBack _Vehicle;
//null = [_Unit] execFSM "\VCOM_AI\AIBEHAVIORARTY.fsm";
if (VCOM_AIDEBUG isEqualTo 1) then
{
[_Vehicle,"I am Artillery :D!!!!",500,20000] remoteExec ["3DText",0];
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

//Hint "LAUNCH!";
//AI will use artillery/mortars when possible. This script makes artillery AI fire at a certain position
//First hash 6/14/2014
//SYSTEmchat "CALLED ARTY!";
_Unit = _this select 0;
_Enemy = _this select 1;

{
if (isNull _x) then {ArtilleryArray = ArtilleryArray - [_x];};
} foreach ArtilleryArray;

//Hint format ["%1",ArtilleryArray];

_Indsupport = [];
_Bluforsupport = [];
_Opforsupport = [];
_Chosen = [];
_ArtilleryUnits = [];

if (side _Unit isEqualTo West) then
{
{
if (side _x isEqualTo West) then {_Bluforsupport = _Bluforsupport + [(vehicle _x)];};
} foreach ArtilleryArray;
_Chosen = _Bluforsupport;
};

if (side _Unit isEqualTo East) then
{
{
if (side _x isEqualTo East) then {_Opforsupport = _Opforsupport + [(vehicle _x)];};
} foreach ArtilleryArray;
_Chosen = _Opforsupport;
};

if (side _Unit isEqualTo Resistance) then
{
{
if (side _x isEqualTo Resistance) then {_Indsupport = _Indsupport + [(vehicle _x)];};
} foreach ArtilleryArray;
_Chosen = _Indsupport;
};

//systemchat format ["_Chosen: %1",_Chosen];
if ((count _Chosen) <= 0) exitWith {};

//player sidechat format ["ARTY CALLED: %1",(vehicle _Unit)];
_ReturnedSupport = [_Chosen,(vehicle _Unit)] call VCOMAI_ClosestObject;
if (isNil "_ReturnedSupport") exitWith {};

if !(_ReturnedSupport in ArtilleryArray) exitWith {};
//player sidechat format ["ARTY _ReturnedSupport: %1",_ReturnedSupport];

_ArtilleryGroup = group _ReturnedSupport;
_ArtilleryGroupActual = [];
{
if (group _x isEqualTo _ArtilleryGroup) then
{
_ArtilleryGroupActual pushback _x;
};

} foreach _Chosen;


////player sidechat format ["ARTY _ArtilleryGroup: %1",_ArtilleryGroup];

_ArtilleryGroupUnits = units _ArtilleryGroup;
//player sidechat format ["ARTY _ArtilleryGroupUnits: %1",_ArtilleryGroupUnits];


//player sidechat format ["ARTY _ArtilleryGroupActual: %1",_ArtilleryGroupActual];
_AmmoArray = getArtilleryAmmo _ArtilleryGroupActual;
//player sidechat format ["ARTY _AmmoArray: %1",_AmmoArray];
if (isNil "_AmmoArray") exitWith {};

_RandomAmmoArray = _AmmoArray call BIS_fnc_selectRandom;
if (isNil "_RandomAmmoArray") exitWith {};
//player sidechat format ["ARTY _RandomAmmoArray: %1",_RandomAmmoArray];
_ContinueFiring = (getPos _Enemy) inRangeOfArtillery [_ArtilleryGroupActual,_RandomAmmoArray];
//player sidechat format ["_ContinueFiring _ContinueFiring: %1",_ContinueFiring];
if !(_ContinueFiring) exitWith {};
//Hint format ["_ArtilleryGroupActual : %1",_ArtilleryGroupActual];


{
_target = _Enemy;
_dist = random (5 + (random 150));
_dir = random 360;
_pos = getpos _target;
_positions = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0];

sleep (random 3);
_x doArtilleryFire [_positions,_RandomAmmoArray,(floor(random 4))];
//_x commandArtilleryFire [(getPos _Enemy),_RandomAmmoArray,(floor(random 4))];
if (VCOM_AIDEBUG isEqualTo 1) then
{
[_x,"I am firing my ARTY >:D!!!",120,20000] remoteExec ["3DText",0];
};

} foreach _ArtilleryGroupActual;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_Unit = _this select 0;
_AttachObject = _this select 1;
_VCOM_GRENADETHROWN = _this select 2;

_GuessLocation = _Unit getHideFrom _NearestEnemy;

if (isNull _NearestEnemy) exitWith
{
//Throw grenades and seek for any kind of cover
[_Unit,_VCOM_GRENADETHROWN] spawn VCOMAI_ThrowGrenade;
};

_coverObjectsClosest = [];

for "_i" from 0 to 20 do
{
_coverObjectsClosest pushback (_coverObjects call BIS_fnc_selectRandom);
};

_Closestobject = _coverObjectsClosest call BIS_fnc_selectRandom;

_BoundingArray = boundingBoxReal _Closestobject;
_p1 = _BoundingArray select 0;
_p2 = _BoundingArray select 1;
_maxWidth = abs ((_p2 select 0) - (_p1 select 0));

_coverObjectspos = [_GuessLocation, (_Closestobject distance _NearestEnemy) + 2, ([_GuessLocation, _Closestobject] call BIS_fnc_dirTo)] call BIS_fnc_relPos;
Loading