Skip to content

Commit

Permalink
Merge pull request #510 from Ansible2/master
Browse files Browse the repository at this point in the history
Update Release To 0.9
  • Loading branch information
Ansible2 authored May 25, 2021
2 parents 9597b8d + 73fdf83 commit a9d7894
Show file tree
Hide file tree
Showing 254 changed files with 13,311 additions and 2,932 deletions.
47 changes: 47 additions & 0 deletions Functions/AI Pathing/fn_pathing_checkGroupStatus.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_pathing_checkGroupStatus
Description:
Checks if a group is still alive.
Parameters:
0: _groupToCheck : <GROUP> - The group to check over
Returns:
<BOOL> - true if active, false if not
Examples:
(begin example)
_isActive = [_group] call BLWK_fnc_pathing_checkGroupStatus;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_pathing_checkGroupStatus";

params ["_groupToCheck"];

// check if it was deleted
if (isNull _groupToCheck) exitWith {
[["Found that ",_groupToCheck," is a null group"],false] call KISKA_fnc_log;
false
};

// check if anyone is in it
private _groupUnits = units _groupToCheck;
if (_groupUnits isEqualTo []) exitWith {
[["Found that ",_groupToCheck," is an empty group"],false] call KISKA_fnc_log;
false
};

// check if anyone is alive
private _aliveIndex = _groupUnits findIf {alive _x};
if (_aliveIndex != -1) exitWith {
true
};


false
38 changes: 38 additions & 0 deletions Functions/AI Pathing/fn_pathing_checkLeaderVelocity.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_pathing_checkLeaderVelocity
Description:
Checks the velocity of a unit to see if they are currently moving.
Parameters:
0: _unit : <OBJECT> - The group to check over
Returns:
<BOOL> - true if any velocity is detected, otherwise false
Examples:
(begin example)
_isActive = [_unit] call BLWK_fnc_pathing_checkLeaderVelocity;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
params ["_unit"];

if (isNull _unit OR {!alive _unit}) exitWith {
false
};

// forward/backward velocity is the most telling of movement
private _leaderVelocity = (velocityModelSpace _unit) select 0;

// if leader is stationary
if (_leaderVelocity isEqualTo 0) exitWith {
false
};


true
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_aiCollisionLoop
Function: BLWK_fnc_pathing_collisionLoop
Description:
Used to keep the AI from attempting to walk through a placed object.
Expand All @@ -16,18 +16,22 @@ Returns:
Examples:
(begin example)
null = [myUnit] spawn BLWK_fnc_aiCollisionLoop;
[myUnit] spawn BLWK_fnc_pathing_collisionLoop;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
if (!BLWK_doDetectCollision) exitWith {};
scriptName "BLWK_fnc_pathing_collisionLoop";

if (!BLWK_doDetectCollision) exitWith {
["BLWK_doDetectCollision is set to be false, exiting...",false] call KISKA_fnc_log;
};

if (!canSuspend) exitWith {
"BLWK_fnc_aiCollisionLoop: should be run in scheduled environment" call BIS_fnc_error;
null = _this spawn BLWK_fnc_aiCollisionLoop;
["Needs to be run in scheduled, exting to run in scheduled",true] call KISKA_fnc_log;
_this spawn BLWK_fnc_pathing_collisionLoop;
};

params ["_unit"];
Expand All @@ -46,10 +50,14 @@ while {BLWK_doDetectCollision AND {alive _unit}} do {
_position = getposASL _unit;
_objects = lineIntersectsObjs [_position,AGLToASL (_unit getRelPos [1,0]), objNull, _unit, false, 4];

if !(_objects isEqualTo []) then {
if (_objects isNotEqualTo []) then {

// check if any encountered object is a built one
_index = _objects findIf {!(isNull _x) AND {_x getVariable ["BLWK_collisionObject",false]}};
_index = _objects findIf {
!(isNull _x) AND
{_x getVariable ["BLWK_collisionObject",false]}
};

if (_index != -1) then {
private _collisionObject = _objects select _index;
_moveToPosition = (_unit getRelPos [20,180]);
Expand All @@ -60,7 +68,7 @@ while {BLWK_doDetectCollision AND {alive _unit}} do {
_unitGroup setBehaviour "SAFE";
_unit disableAI "TARGET";
_unit disableAI "AUTOTARGET";
_unit disableAI "AUTOCOMBAT";
//_unit disableAI "AUTOCOMBAT";

[group _unit] call CBAP_fnc_clearWaypoints;
/*
Expand All @@ -87,7 +95,7 @@ while {BLWK_doDetectCollision AND {alive _unit}} do {
_unitGroup setBehaviour "AWARE";
_unit enableAI "TARGET";
_unit enableAI "AUTOTARGET";
_unit enableAI "AUTOCOMBAT";
//_unit enableAI "AUTOCOMBAT";
};
};
};
Expand Down
65 changes: 65 additions & 0 deletions Functions/AI Pathing/fn_pathing_detailedStuckCheck.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_pathing_detailedStuckCheck
Description:
If a units leader was detected as not moving in BLWK_fnc_pathing_checkLeaderVelocity
this will do further checks that make sure a unit actually should be teleported
to "unstick" them.
Needs to be run in scheduled environment.
Parameters:
0: _unit : <OBJECT> - The unit to handle
Returns:
<BOOL> - true if unit is stuck, false if not
Examples:
(begin example)
_needsToBeReset = [_unit] call BLWK_fnc_pathing_detailedStuckCheck;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_pathing_detailedStuckCheck";

params ["_unit"];

// don't mess with vehicle units
if (!isNull (objectParent _unit)) exitWith {false};

private _currentPosition = getPosWorld _unit;

sleep 20;

// exit if all units are dead
if !([_groupToCheck] call BLWK_fnc_pathing_checkGroupStatus) exitWith {
[[_groupToCheck," failed secondary group status check..."],false] call KISKA_fnc_log;
false
};

private _needsReset = true;
// if the leader fails the velocity check again
if !([_unit] call BLWK_fnc_pathing_checkLeaderVelocity) then {
[[_groupToCheck," failed secondary velocity status check..."],false] call KISKA_fnc_log;

// check if there is enough difference in their position to justify not reseting them
private _positionDifference = (getPosWorld _unit) vectorDiff _currentPosition;
[["Checking position differences for group ", _groupToCheck,"... Position differences are: ",_positionDifference],false] call KISKA_fnc_log;
_positionDifference apply {
// check to make sure there was some significant movement in the unit on any axis
if ((abs _x) > 0.5) exitWith {
[[_groupToCheck," found a position axis that passed..."],false] call KISKA_fnc_log;
_needsReset = false;
};
};
} else {
[[_groupToCheck," had immediate velocity check that passed."],false] call KISKA_fnc_log;
_needsReset = false;
};


_needsReset
96 changes: 96 additions & 0 deletions Functions/AI Pathing/fn_pathing_mainLoop.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_pathing_mainLoop
Description:
AI enemies sometimes get stuck an refuse to move or just rotate while
decding how to proceed. Often in urban environments.
During the main loop, if the leader has a velocity of zero, he will then
be given 10 seconds to have a meaningful movement on any axis before
being teleported to a random spawn location.
Hopefully this resets his pathing.
Parameters:
0: _groupToCheck : <OBJECT OR GROUP> - The unit or group to add to check over
1: _timeBetweenChecks : <NUMBER> - How often to check the unit leader's velocity
Returns:
NOTHING
Examples:
(begin example)
[myGroup,25] spawn BLWK_fnc_pathing_mainLoop;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
#define RESET_POSITION\
_groupLeader setPos ([BLWK_mainCrate, 75, 120, 2, 0] call BIS_fnc_findSafePos);\
sleep 1;\
[_groupLeader,position BLWK_mainCrate] remoteExecCall ["move",_groupLeader];

#define LOOP_VAR_NAME "BLWK_runPathingLoop"
#define SCRIPT_NAME "BLWK_fnc_pathing_mainLoop"
scriptName SCRIPT_NAME;


if (!canSuspend) exitWith {
["Should be run in scheduled environment, exiting to scheduled...",true] call KISKA_fnc_log;
_this spawn BLWK_fnc_pathing_mainLoop;
};

params [
["_groupToCheck",objNull,[grpNull,objNull]],
["_timeBetweenChecks",25,[123]]
];


if (isNull _groupToCheck) exitWith {
["_groupToCheck is null. Exiting...",true] call KISKA_fnc_log;
};

// follower units won't likely get stuck as their primary goal is to join the formation at all cost
if (_groupToCheck isEqualType objNull) then {
_groupToCheck = group _groupToCheck;
};

private _groupLeader = leader _groupToCheck;
if (!alive _groupLeader) exitWith {
["_groupLeader is null. Exiting...",true] call KISKA_fnc_log;
};


_groupToCheck setVariable [LOOP_VAR_NAME,true];
while {sleep _timeBetweenChecks; true} do {

if (!(isNull _groupToCheck) AND {!(_groupToCheck getVariable [LOOP_VAR_NAME,false])}) exitWith {
[["Loop var for group ",_groupToCheck," was set to false. Exiting..."],false] call KISKA_fnc_log;
};

if !([_groupToCheck] call BLWK_fnc_pathing_checkGroupStatus) exitWith {
[["Found that ",_groupToCheck," failed group status check. Exiting..."],false] call KISKA_fnc_log;
_groupToCheck setVariable [LOOP_VAR_NAME,nil];
};

_groupLeader = leader _groupToCheck;

// checks for units that walk aways from play area
if (isNull (objectParent _groupLeader) AND {(_groupLeader distance2D BLWK_playAreaCenter) >= BLWK_maxDistanceFromPlayArea}) then {
[["_groupLeader ",_groupLeader," appears to have walked too far from the play area and will be reset"],true] call KISKA_fnc_log;
RESET_POSITION
} else {

if !([_groupLeader] call BLWK_fnc_pathing_checkLeaderVelocity) then {
[["_groupLeader ",_groupLeader," failed velocity check at point 1"],false] call KISKA_fnc_log;

if ([_groupLeader] call BLWK_fnc_pathing_detailedStuckCheck) then {
[["_groupLeader ",_groupLeader," failed detailted stuck check at point 1"],false] call KISKA_fnc_log;
RESET_POSITION
};
};
};
};
41 changes: 41 additions & 0 deletions Functions/Build/fn_addAllowDamageEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* ----------------------------------------------------------------------------
Function: BLWK_fnc_addAllowDamageEH
Description:
In order to avoid setting and reseting the allowDamage to false for certain
items when they change locality (are picked up for example), this eventhandler
will be added to any object from the shop (and the main crate) that don't allow
damage.
Parameters:
0: _object : <OBJECT> - The object to add the eventhandler to
Returns:
NOTHING
Examples:
(begin example)
[anObject] call BLWK_fnc_addAllowDamageEH;
(end)
Author(s):
Ansible2 // Cipher
---------------------------------------------------------------------------- */
scriptName "BLWK_fnc_addAllowDamageEH";

if (!hasInterface) exitWith {};

params ["_object"];

if (isNull _object) exitWith {
["_object was null, event handler will not be added, exiting...",true] call KISKA_fnc_log;
nil
};

_object addEventHandler ["LOCAL",{
params ["_object"];
_object allowDamage false;
}];


nil
Loading

0 comments on commit a9d7894

Please sign in to comment.