Skip to content

Commit

Permalink
Mission - General improvements and optimizations (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-MF authored Jul 2, 2024
1 parent 6ccad44 commit bd1a30f
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 44 deletions.
7 changes: 5 additions & 2 deletions addons/mission/functions/fnc_countAlive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions addons/mission/functions/fnc_debugTriggerArea.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* [] call MFUNC(debugTriggerArea)
*/

if (!isServer) exitWith {};

private _allTriggers = allMissionObjects "EmptyDetector";

{
Expand Down
2 changes: 2 additions & 0 deletions addons/mission/functions/fnc_disableAI.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

params ["_groupsOrUnits", "_feature"];

if (!is3DENPreview && {hasInterface}) exitWith {};

{
if (_x isEqualType objNull) then {
_x disableAI _feature;
Expand Down
2 changes: 2 additions & 0 deletions addons/mission/functions/fnc_enableAI.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

params ["_groupsOrUnits", "_feature"];

if (!is3DENPreview && {hasInterface}) exitWith {};

{
if (_x isEqualType objNull) then {
_x enableAI _feature;
Expand Down
2 changes: 2 additions & 0 deletions addons/mission/functions/fnc_markBuildings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

params ["_objectArray", ["_filter", true]];

if (!isServer) exitWith {};

if (_objectArray isEqualTo []) exitWith {
WARNING("Object Array is empty");
};
Expand Down
32 changes: 17 additions & 15 deletions addons/mission/functions/fnc_mortarStrike.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 35 additions & 22 deletions addons/mission/functions/fnc_reaction.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Arguments:
* 0: Types <ARRAY> (default: [])
* 1: Groups <ARRAY>
* 2: Remove after use <BOOL> (default: true)
*
* Return Value:
* None
Expand All @@ -21,39 +22,50 @@
* [["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
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;
Expand All @@ -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", {
Expand All @@ -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];
Expand Down
9 changes: 7 additions & 2 deletions addons/mission/functions/fnc_reinforcementWaves.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

{
Expand Down
6 changes: 5 additions & 1 deletion addons/mission/functions/fnc_reinforcements.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
{
Expand Down
6 changes: 4 additions & 2 deletions addons/mission/functions/fnc_setSleeping.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
};
Expand All @@ -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 {
Expand All @@ -44,5 +46,5 @@ if (_asleep) then {
};
}, _x, _forEachIndex * _time] call CBA_fnc_waitAndExecute;
};
} forEach (units _group);
} forEach _units;
};
2 changes: 2 additions & 0 deletions addons/mission/functions/fnc_surrender.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
};
Expand Down

0 comments on commit bd1a30f

Please sign in to comment.