From bd1a30f958d8b7f3e67cc9b6185892962b132fe5 Mon Sep 17 00:00:00 2001 From: Mike-MF Date: Tue, 2 Jul 2024 19:19:58 +0100 Subject: [PATCH] Mission - General improvements and optimizations (#699) --- addons/mission/functions/fnc_countAlive.sqf | 7 ++- .../functions/fnc_debugTriggerArea.sqf | 2 + addons/mission/functions/fnc_disableAI.sqf | 2 + addons/mission/functions/fnc_enableAI.sqf | 2 + .../mission/functions/fnc_markBuildings.sqf | 2 + addons/mission/functions/fnc_mortarStrike.sqf | 32 ++++++----- addons/mission/functions/fnc_reaction.sqf | 57 ++++++++++++------- .../functions/fnc_reinforcementWaves.sqf | 9 ++- .../mission/functions/fnc_reinforcements.sqf | 6 +- addons/mission/functions/fnc_setSleeping.sqf | 6 +- addons/mission/functions/fnc_surrender.sqf | 2 + 11 files changed, 83 insertions(+), 44 deletions(-) diff --git a/addons/mission/functions/fnc_countAlive.sqf b/addons/mission/functions/fnc_countAlive.sqf index ee5f7b49..521d4760 100644 --- a/addons/mission/functions/fnc_countAlive.sqf +++ b/addons/mission/functions/fnc_countAlive.sqf @@ -16,8 +16,11 @@ params ["_groups"]; -if ((_groups select 0) isEqualType "OBJECT") exitWith { - ERROR_MSG("Input only allows groups, detected unit."); +if (is3DENPreview) then { + private _typeCheck = _groups findIf {_x isEqualType "OBJECT"}; + if (_typeCheck != -1) exitWith { + ERROR_MSG_1("Input only allows groups, detected unit at index (%1)",_typeCheck); + }; }; private _count = 0; diff --git a/addons/mission/functions/fnc_debugTriggerArea.sqf b/addons/mission/functions/fnc_debugTriggerArea.sqf index 5d631089..bf11868a 100644 --- a/addons/mission/functions/fnc_debugTriggerArea.sqf +++ b/addons/mission/functions/fnc_debugTriggerArea.sqf @@ -15,6 +15,8 @@ * [] call MFUNC(debugTriggerArea) */ +if (!isServer) exitWith {}; + private _allTriggers = allMissionObjects "EmptyDetector"; { diff --git a/addons/mission/functions/fnc_disableAI.sqf b/addons/mission/functions/fnc_disableAI.sqf index 169c48d9..8bc59414 100644 --- a/addons/mission/functions/fnc_disableAI.sqf +++ b/addons/mission/functions/fnc_disableAI.sqf @@ -21,6 +21,8 @@ params ["_groupsOrUnits", "_feature"]; +if (!is3DENPreview && {hasInterface}) exitWith {}; + { if (_x isEqualType objNull) then { _x disableAI _feature; diff --git a/addons/mission/functions/fnc_enableAI.sqf b/addons/mission/functions/fnc_enableAI.sqf index 48dce0c8..1baafdf5 100644 --- a/addons/mission/functions/fnc_enableAI.sqf +++ b/addons/mission/functions/fnc_enableAI.sqf @@ -21,6 +21,8 @@ params ["_groupsOrUnits", "_feature"]; +if (!is3DENPreview && {hasInterface}) exitWith {}; + { if (_x isEqualType objNull) then { _x enableAI _feature; diff --git a/addons/mission/functions/fnc_markBuildings.sqf b/addons/mission/functions/fnc_markBuildings.sqf index c69b786e..7d974b0e 100644 --- a/addons/mission/functions/fnc_markBuildings.sqf +++ b/addons/mission/functions/fnc_markBuildings.sqf @@ -21,6 +21,8 @@ params ["_objectArray", ["_filter", true]]; +if (!isServer) exitWith {}; + if (_objectArray isEqualTo []) exitWith { WARNING("Object Array is empty"); }; diff --git a/addons/mission/functions/fnc_mortarStrike.sqf b/addons/mission/functions/fnc_mortarStrike.sqf index b14e7260..0e2a5891 100644 --- a/addons/mission/functions/fnc_mortarStrike.sqf +++ b/addons/mission/functions/fnc_mortarStrike.sqf @@ -45,27 +45,29 @@ private _gunner = gunner _mortar; private _ammo = _ammoTypes select _ammoType; private _eta = 0; -// Debug +// Randomised amount if (_amount == 0) then { _amount = floor (random 8 + 1); }; -// Disable relevant ace setting -if (ace_mk6mortar_useAmmoHandling) exitWith { - WARNING("ACE Ammo Handling setting is enabled."); -}; +if (is3DENPreview) then { + // Disable relevant ace setting + if (ace_mk6mortar_useAmmoHandling) exitWith { + WARNING("ACE Ammo Handling setting is enabled."); + }; -// Error on marker being incorrect type -private _invalidMarker = _markersArray findIf {!(markerShape _x in ["RECTANGLE", "ELLIPSE"])}; -if (_invalidMarker != -1) exitWith { - private _failedMarker = _markersArray select _invalidMarker; - ERROR_MSG_1("Marker: %1 is not an area marker (rectangle or ellipse)",_failedMarker); -}; + // Error on marker being incorrect type + private _invalidMarker = _markersArray findIf {!(markerShape _x in ["RECTANGLE", "ELLIPSE"])}; + if (_invalidMarker != -1) exitWith { + private _failedMarker = _markersArray select _invalidMarker; + ERROR_MSG_1("Marker: %1 is not an area marker (rectangle or ellipse)",_failedMarker); + }; -// Warn on first out of range marker found -private _outOfRange = _markersArray findIf {!((getMarkerPos _x) inRangeOfArtillery [[_mortar], _ammo])}; -if (_outOfRange != -1) exitWith { - WARNING_1("Marker Index: %1 is out of range of Artillery",_outOfRange); + // Warn on first out of range marker found + private _outOfRange = _markersArray findIf {!((getMarkerPos _x) inRangeOfArtillery [[_mortar], _ammo])}; + if (_outOfRange != -1) exitWith { + WARNING_1("Marker Index: %1 is out of range of Artillery",_outOfRange); + }; }; for "_i" from 0 to _amount - 1 do { diff --git a/addons/mission/functions/fnc_reaction.sqf b/addons/mission/functions/fnc_reaction.sqf index 850cb436..c1605651 100644 --- a/addons/mission/functions/fnc_reaction.sqf +++ b/addons/mission/functions/fnc_reaction.sqf @@ -12,6 +12,7 @@ * Arguments: * 0: Types (default: []) * 1: Groups + * 2: Remove after use (default: true) * * Return Value: * None @@ -21,10 +22,22 @@ * [["Patrol", "Combat"], [My_Group_One]] call MFUNC(reaction) */ -params [["_types", []], "_groups"]; +params [["_types", []], "_groups", ["_removeAfterUse", true]]; -if ((_groups select 0) isEqualType "OBJECT") exitWith { - ERROR_MSG("Input only allows groups, detected unit."); +if (!is3DENPreview && {hasInterface}) exitWith {}; + +if (is3DENPreview) then { + private _typeCheck = _groups findIf {_x isEqualType "OBJECT"}; + if (_typeCheck != -1) then { + ERROR_MSG_1("Input only allows groups, detected unit at index (%1)",_typeCheck); + }; + + // Typo debug + { + if !(toLower _x in ["static", "patrol", "combat"]) then { + ERROR_MSG_1("Unknown reaction type value: %1",_x); + }; + } forEach _types; }; // Backward compatibility @@ -32,28 +45,27 @@ if (_types isEqualType "STRING") then { _types = [_types]; }; -// Typo debug -{ - if !(toLower _x in ["static", "patrol", "combat"]) then { - ERROR_MSG_1("Unknown reaction type value: %1",_x); - }; -} forEach _types; - private _static = _types findIf {_x == "static"} != -1; private _patrol = _types findIf {_x == "patrol"} != -1; private _combat = _types findIf {_x == "combat"} != -1; +// Allow optionally not removing the eventhandler. +{_x setVariable [QGVAR(reactionParams), [_removeAfterUse]]} forEach _groups; + // Rapidly increase static units knowledge for faster returned fire if (_static) then { { { _x addEventHandler ["Suppressed", { params ["_unit", "", "_shooter"]; + private _group = group _unit; + (_group getVariable [QGVAR(reactionParams), 0]) params ["_removeAfterUse"]; - _unit removeEventHandler [_thisEvent, _thisEventHandler]; + if (_removeAfterUse) then { + _unit removeEventHandler [_thisEvent, _thisEventHandler]; + }; - private _unitGroup = group _unit; - _unitGroup reveal [_shooter, 1.5]; + _group reveal [_shooter, 1.5]; }]; } forEach (units _x); } forEach _groups; @@ -65,17 +77,21 @@ if (_patrol) then { private _leader = leader _x; _leader addEventHandler ["Suppressed", { params ["_unit", "", "_shooter"]; + private _group = group _unit; + (_group getVariable [QGVAR(reactionParams), 0]) params ["_removeAfterUse"]; - _unit removeEventHandler [_thisEvent, _thisEventHandler]; + if (_removeAfterUse) then { + _unit removeEventHandler [_thisEvent, _thisEventHandler]; + }; - private _unitGroup = units (group _unit); + private _unitGroup = units _group; private _enemyPos = getPos _shooter; _unitGroup doMove _enemyPos; }]; } forEach _groups; }; -// Re-enable PATH or MOVE ai types when entering combat +// Allow movement on entering combat, EH is always removed after use. if (_combat) then { { _x addEventHandler ["CombatModeChanged", { @@ -84,18 +100,15 @@ if (_combat) then { if (_newMode != "COMBAT") exitWith {}; private _leader = leader _group; + private _units = units _group; private _pathEnabled = _leader checkAIFeature "PATH"; private _moveEnabled = _leader checkAIFeature "MOVE"; if !(_pathEnabled) then { - { - _x enableAI "PATH"; - } forEach (units _group); + {_x enableAI "PATH"} forEach _units; }; if !(_moveEnabled) then { - { - _x enableAI "MOVE"; - } forEach (units _group); + {_x enableAI "MOVE"} forEach _units; }; _group removeEventHandler [_thisEvent, _thisEventHandler]; diff --git a/addons/mission/functions/fnc_reinforcementWaves.sqf b/addons/mission/functions/fnc_reinforcementWaves.sqf index 52110d2b..2a57e201 100644 --- a/addons/mission/functions/fnc_reinforcementWaves.sqf +++ b/addons/mission/functions/fnc_reinforcementWaves.sqf @@ -18,8 +18,13 @@ params ["_groups", "_time"]; -if ((_groups select 0) isEqualType "OBJECT") exitWith { - ERROR_MSG("Input only allows groups, detected unit."); +if (!isServer) exitWith {}; + +if (is3DENPreview) then { + private _typeCheck = _groups findIf {_x isEqualType "OBJECT"}; + if (_typeCheck != -1) exitWith { + ERROR_MSG_1("Input only allows groups, detected unit at index (%1)",_typeCheck); + }; }; { diff --git a/addons/mission/functions/fnc_reinforcements.sqf b/addons/mission/functions/fnc_reinforcements.sqf index 51dca002..1c9bfdb8 100644 --- a/addons/mission/functions/fnc_reinforcements.sqf +++ b/addons/mission/functions/fnc_reinforcements.sqf @@ -29,7 +29,11 @@ if (_groups isEqualType grpNull) then { { private _groupLeader = leader _x; - private _anyClose = (true call FUNC(players)) select {_groupLeader distance _x < _distance}; + private _anyClose = []; + + if (_distance > 0) then { + _anyClose = (true call FUNC(players)) select {_groupLeader distance _x < _distance}; + }; if (_anyClose isEqualTo [] || CBA_MissionTime == 0) then { { diff --git a/addons/mission/functions/fnc_setSleeping.sqf b/addons/mission/functions/fnc_setSleeping.sqf index 9c56a8e8..cf3dd8cc 100644 --- a/addons/mission/functions/fnc_setSleeping.sqf +++ b/addons/mission/functions/fnc_setSleeping.sqf @@ -22,6 +22,8 @@ params ["_group", ["_asleep", true], ["_time", 0]]; +if (!is3DENPreview && {hasInterface}) exitWith {}; + if (_group isEqualType "OBJECT") exitWith { ERROR_MSG("Input only allows group, detected unit."); }; @@ -32,7 +34,7 @@ if (_asleep) then { { _x switchMove "Acts_LyingWounded_loop3"; _x disableAI "ANIM"; - } forEach (units _group); + } forEach _units; } else { { if (alive _x && {animationState _x == "acts_lyingwounded_loop3"}) then { @@ -44,5 +46,5 @@ if (_asleep) then { }; }, _x, _forEachIndex * _time] call CBA_fnc_waitAndExecute; }; - } forEach (units _group); + } forEach _units; }; diff --git a/addons/mission/functions/fnc_surrender.sqf b/addons/mission/functions/fnc_surrender.sqf index 90254932..0b688780 100644 --- a/addons/mission/functions/fnc_surrender.sqf +++ b/addons/mission/functions/fnc_surrender.sqf @@ -20,6 +20,8 @@ params ["_group", ["_surrenderChance", 5], ["_minimumDistance", 400], ["_rallyChance", 0]]; +if (!is3DENPreview && {hasInterface}) exitWith {}; + if (_group isEqualType "OBJECT") exitWith { ERROR_MSG("Input only allows group, detected unit."); };