Optimize suicide bomber zeus module (#6314)

- 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
This commit is contained in:
commy2 2018-05-04 17:35:28 +02:00 committed by SilentSpike
parent ab23f4e4dc
commit 898c01587a

View File

@ -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);
@ -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 {
@ -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;