Skip to content
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

WIP: Improve doCover logic #368

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions addons/danger/functions/fnc_brainReact.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ private _timeout = time + 1.4;
// ACE3
_unit setVariable ["ace_medical_ai_lastHit", CBA_missionTime];

// cover move when explosion
// Move to cover if it's relatively safe
if (
getSuppression _unit < 0.6
getSuppression _unit < 0.4
&& {RND(0.67)} // Add some randomness so they aren't taking cover all the time
&& {(speed _unit) isEqualTo 0}
&& {_type in [DANGER_EXPLOSION, DANGER_FIRE]}
&& {!(_unit call EFUNC(main,isIndoor))} // Don't try anything indoors
) exitWith {
_unit setUnitPosWeak "DOWN";
[_unit] call EFUNC(main,doCover);
_timeout + 1
[_unit, _pos] call EFUNC(main,doCover);
_timeout + 2
};

// dodge!
Expand Down
59 changes: 38 additions & 21 deletions addons/main/functions/UnitAction/fnc_doCover.sqf
Original file line number Diff line number Diff line change
@@ -1,50 +1,67 @@
#include "script_component.hpp"
/*
* Author: nkenny
* moved the unit into cover
* Unit tries to move into cover from danger
* Cover that is towards the enemy is prioritised,-
* so the unit will slowly advance if cover allows
*
* Arguments:
* 0: unit doing the flight <OBJECT>
* 1: position of cover <ARRAY>
* 1: position of danger <ARRAY>
*
* Return Value:
* bool
*
* Example:
* [bob] call lambs_main_fnc_doCover;
* [bob, getPosATL badguy] call lambs_main_fnc_doCover;
*
* Public: No
*/
#define SEARCH_FOR_HIDE 6
#define SEARCH_FOR_HIDE 6.5

params ["_unit", ["_pos", [], [[]]]];
params [
["_unit", objNull, [objNull]],
["_dangerPos", [0,0,0], [[]]]
];

// check if stopped
if (isNull _unit || _dangerPos isEqualTo [0,0,0]) exitWith {false};
if ((_unit distance2D _dangerPos) < 20) exitWith {false};
if (!(_unit checkAIFeature "MOVE")) exitWith {false};
if (!(_unit checkAIFeature "PATH")) exitWith {false};

// find cover
if (_pos isEqualTo []) then {
_pos = nearestTerrainObjects [_unit, ["BUSH", "TREE", "HIDE"], SEARCH_FOR_HIDE, true, true];
_pos = if (_pos isEqualTo []) then {
getPosASL _unit
} else {
(_pos select 0) getPos [-1.2, _unit getDir (_pos select 0)]
};
// Take cover
_unit setVariable [QGVAR(currentTask), "Take Cover!", GVAR(debug_functions)];

// Drop stance
if ((stance _unit) isEqualTo "STAND") then {_unit setUnitPosWeak "MIDDLE"};

// find cover, preferably towards the opponent
private _coverPositions = nearestTerrainObjects [_unit getPos [1.5, _unit getDir _dangerPos], ["BUSH", "TREE", "HIDE"], SEARCH_FOR_HIDE, true, true];

private _pos = if (_coverPositions isEqualTo []) then {
getPosATL _unit
} else {
private _cover = _coverPositions select 0;
_cover getPos [2, _dangerPos getDir _cover]
};

// force anim
// Sanity checks to try prevent constant moving between cover positions -
// and units wandering away from the formation
if (_unit distance2D _pos < 0.6) exitWith {false};
if (_pos distance2D (leader _unit) > 20) exitWith {false};

// Force anim
private _direction = _unit getRelDir _pos;
private _anim = call {
if (_direction > 315) exitWith {["WalkF", "WalkLF"]};
if (_direction > 225) exitWith {["WalkL", "WalkLF"]};
if (_direction > 135) exitWith {["WalkB"]};
if (_direction > 45) exitWith {["WalkR", "WalRF"]};
["WalkF", "WalkRF"]
if (_direction > 315) exitWith {["FastF", "FastLF"]};
if (_direction > 225) exitWith {["FastL", "FastLF"]};
if (_direction > 135) exitWith {["FastB"]};
if (_direction > 45) exitWith {["FastR", "FastRF"]};
["FastF", "FastRF"]
};

// prevent run in place
_unit moveTo _pos;
_unit doMove _pos;
_unit setDestination [_pos, "FORMATION PLANNED", true];

// do anim
Expand Down