Skip to content

Commit

Permalink
Optimize suicide bomber zeus module (#6314)
Browse files Browse the repository at this point in the history
- decrease check frequency from each frame to 1 per second
- simplify some math
- remove some very redundant parenthesis
- re-formated if control structure for readability
- use more appropriate skillFinal
- macro to change check delay, set to 0 in debug mode for debug line drawing
  • Loading branch information
commy2 authored and kymckay committed May 4, 2018
1 parent ab23f4e commit 898c015
Showing 1 changed file with 12 additions and 6 deletions.
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;

0 comments on commit 898c015

Please sign in to comment.