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

optimize suicide bomber zeus module #6314

Merged
merged 3 commits into from
May 4, 2018
Merged
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
18 changes: 12 additions & 6 deletions addons/zeus/functions/fnc_moduleSuicideBomber.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#define DISTANCE_FAR 15
#define DISTANCE_CLOSE 2
#define MOVE_TIME 10
#define SCANNING_PERIOD 1

#ifdef DEBUG_MODE_FULL
#define SCANNING_PERIOD 0
#endif

TRACE_1("params",_this);

Expand Down Expand Up @@ -66,8 +71,8 @@ if (_autoSeek) then {
private _memory = _unit getVariable [QGVAR(suicideBomber_memory), [nil, CBA_missionTime]];
_memory params ["_lastMove", "_lastTime"];

private _range = 100 max (200 * (_unit skill "spotDistance")); // 100-200
private _nearestObjects = (nearestObjects [_unit, [], _range]) select {side _x == _activationSide && {_x != _unit} && {alive _x}};
private _range = 100 + 100 * (_unit skillFinal "spotDistance"); // 100-200
private _nearestObjects = nearestObjects [_unit, [], _range] select {side _x == _activationSide && {_x != _unit} && {alive _x}};

#ifdef DEBUG_MODE_FULL
if !(isNil "_lastMove") then {
Expand All @@ -92,11 +97,12 @@ if (_autoSeek) then {
private _moveToPos = (_nearestObjects select 0) getPos [1, random 360];

if (isNil "_lastMove" || // No move given yet
{(_lastMove distance _moveToPos) > DISTANCE_FAR} || // New target is too far from last move
{(_lastMove distance _unit) < DISTANCE_CLOSE} || // Unit has reached last move
{CBA_missionTime >= _lastTime}) then { // Too much time passed between last move (also acts as a fail-safe if unit gets stuck)
{_lastMove distance _moveToPos > DISTANCE_FAR} || // New target is too far from last move
{_lastMove distance _unit < DISTANCE_CLOSE} || // Unit has reached last move
{CBA_missionTime >= _lastTime} // Too much time passed between last move (also acts as a fail-safe if unit gets stuck)
) then {
[QEGVAR(ai,doMove), [[[_unit, _moveToPos]]], _unit] call CBA_fnc_targetEvent;
_unit setVariable [QGVAR(suicideBomber_memory), [_moveToPos, CBA_missionTime + MOVE_TIME]];
TRACE_2("Moving unit",_moveToPos,CBA_missionTime);
};
}, 0, _this] call CBA_fnc_addPerFrameHandler;
}, SCANNING_PERIOD, _this] call CBA_fnc_addPerFrameHandler;