diff --git a/addons/zeus/XEH_PREP.hpp b/addons/zeus/XEH_PREP.hpp index 561355f..6a0a02a 100644 --- a/addons/zeus/XEH_PREP.hpp +++ b/addons/zeus/XEH_PREP.hpp @@ -1,19 +1,25 @@ -PREP(moduleArtillery); +PREP(addAISuppressionPFH); +PREP(addSuppressedLocalUnit); +PREP(artyAirburst); PREP(artyFireMissionHE); PREP(artyFireMissionSMOKE); PREP(artyFireMissionILLUM); -PREP(execArtyStrike); -PREP(artyAirburst); +PREP(contextMeasureDistance); +PREP(disableSuppression); PREP(drawACEUnconsciousIcon); +PREP(enableSuppression); +PREP(execArtyStrike); +PREP(getModuleDestination); +PREP(getTargetKnowledge); +PREP(initAISuppression); PREP(initDrawIconEH); +PREP(moduleArtillery); +PREP(moduleTargetKnowledge); PREP(moduleUnflipVehicle); PREP(onZeusDisplayOpen); -PREP(moduleTargetKnowledge); -PREP(setAIStance); -PREP(switchAIPathBehaviour); +PREP(removeSuppressedLocalUnit); PREP(setAIBehaviour); PREP(setAICombatMode); -PREP(getModuleDestination); -PREP(contextMeasureDistance); +PREP(setAIStance); PREP(setTargetKnowledge); -PREP(getTargetKnowledge); +PREP(switchAIPathBehaviour); diff --git a/addons/zeus/XEH_postInit.sqf b/addons/zeus/XEH_postInit.sqf index 34b6509..a996456 100644 --- a/addons/zeus/XEH_postInit.sqf +++ b/addons/zeus/XEH_postInit.sqf @@ -17,6 +17,8 @@ } forEach _toUnits; }] call CBA_fnc_addEventHandler; +call FUNC(initAISuppression); + CHECK(!hasinterface); GVAR(moduleDestination_running) = false; diff --git a/addons/zeus/functions/fnc_addAISuppressionPFH.sqf b/addons/zeus/functions/fnc_addAISuppressionPFH.sqf new file mode 100644 index 0000000..fd40058 --- /dev/null +++ b/addons/zeus/functions/fnc_addAISuppressionPFH.sqf @@ -0,0 +1,47 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Adds PFH to handle suppression for local units. + * + * Parameter(s): + * None. + * + * Returns: + * Nothing. + * + * Example: + * [] call mts_zeus_fnc_addAISuppressionPFH + * + */ + +[{ + if (GVAR(suppressedLocalUnits) isEqualTo []) exitWith { + GVAR(suppressedLocalUnits) = nil; + (_this select 1) call CBA_fnc_removePerFrameHandler; + }; + + { + if (!alive _x) then { + [QGVAR(disableSuppression), [_x]] call CBA_fnc_localEvent; + continue; + }; + + private _suppressionParams = _x getVariable [QGVAR(suppressionParameters), []]; + if (_suppressedParams isEqualTo []) then { + continue; + }; + _suppressionParams params ["_suppressionThreshold", "_suppressedStance", "_originalStance"]; + + if (getSuppression _x >= _suppressionThreshold) then { + if (unitPos _x isNotEqualTo _suppressedStance) then { + _x setUnitPos _suppressedStance; + }; + } else { + if (unitPos _x isNotEqualTo _originalStance) then { + _x setUnitPos _originalStance; + }; + }; + } forEach GVAR(suppressedLocalUnits); +}, 1, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/zeus/functions/fnc_addSuppressedLocalUnit.sqf b/addons/zeus/functions/fnc_addSuppressedLocalUnit.sqf new file mode 100644 index 0000000..88203d2 --- /dev/null +++ b/addons/zeus/functions/fnc_addSuppressedLocalUnit.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Adds a unit to the suppressed units which are on this local machine. + * Starts the suppression PFH if it doesn't already run on the local machine. + * + * Parameter(s): + * 0: OBJECT - Unit. + * + * Returns: + * Nothing. + * + * Example: + * [_unit] call mts_zeus_fnc_addSuppressedLocalUnit + * + */ + +params ["_unit"]; + +if (isNil QGVAR(suppressedLocalUnits)) then { + GVAR(suppressedLocalUnits) = []; + GVAR(suppressedLocalUnits) pushBackUnique _unit; + + [] call FUNC(addAISuppressionPFH); +} else { + GVAR(suppressedLocalUnits) pushBackUnique _unit; +}; diff --git a/addons/zeus/functions/fnc_disableSuppression.sqf b/addons/zeus/functions/fnc_disableSuppression.sqf new file mode 100644 index 0000000..5aa5e3e --- /dev/null +++ b/addons/zeus/functions/fnc_disableSuppression.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Disables suppression for the unit. + * + * Parameter(s): + * 0: OBJECT - Unit. + * + * Returns: + * Nothing. + * + * Example: + * [_unit] call mts_zeus_fnc_disableSuppression + * + */ + +params [["_unit", objNull, [objNull]]]; + +CHECK(isNull _unit); + +[_unit] call FUNC(removeSuppressedLocalUnit); + +if (_x getVariable [QGVAR(suppressionEnabled), false]) then { + _unit setVariable [QGVAR(suppressionEnabled), false, true]; +}; diff --git a/addons/zeus/functions/fnc_enableSuppression.sqf b/addons/zeus/functions/fnc_enableSuppression.sqf new file mode 100644 index 0000000..06415c1 --- /dev/null +++ b/addons/zeus/functions/fnc_enableSuppression.sqf @@ -0,0 +1,34 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Enables suppression on the unit. + * Must be called where unit is local. + * + * Parameter(s): + * 0: OBJECT - Unit. + * 1: NUMBER - Unit will change stance if suppression is higher than this threshold value. + * 2: STRING - The stance to take when unit is suppressed (DOWN, MIDDLE, UP). + * + * Returns: + * Nothing. + * + * Example: + * [_unit, 0.7, "MIDDLE"] call mts_zeus_fnc_enableSuppression + * + */ + +params [["_unit", objNull, [objNull]], ["_suppressionThreshold", -1, [0]], ["_suppressedStance", "", [""]]]; + +CHECK(isNull _unit || !local _unit || _unit getVariable [ARR_2(QGVAR(suppressionEnabled), false)]); +CHECK(_suppressionThreshold < 0 || _suppressionThreshold > 1); +_suppressedStance = toUpper _suppressedStance; +CHECK(!(_suppressedStance in [ARR_3("DOWN", "MIDDLE", "UP")])); + +private _originalStance = GVAR(stanceMapping) getOrDefault [stance _unit, "UP"]; + +_unit setVariable [QGVAR(suppressionEnabled), true, true]; +_unit setVariable [QGVAR(suppressionParameters), [_suppressionThreshold, _suppressedStance, _originalStance], true]; + +[_unit] call FUNC(addSuppressedLocalUnit); diff --git a/addons/zeus/functions/fnc_initAISuppression.sqf b/addons/zeus/functions/fnc_initAISuppression.sqf new file mode 100644 index 0000000..5b65184 --- /dev/null +++ b/addons/zeus/functions/fnc_initAISuppression.sqf @@ -0,0 +1,113 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Initializes AI suppression behaviour. This behaviour is handled on every machine on which local units exists. + * E.g. Server and zeus have placed AI units -> Units behaviour will be handled where unit is local, so all units of the server on the server, etc. + * + * Parameter(s): + * None. + * + * Returns: + * Nothing. + * + * Example: + * [] call mts_zeus_fnc_initAISuppression + * + */ + +GVAR(stanceMapping) = createHashMapFromArray [["PRONE", "DOWN"], ["CROUCH", "MIDDLE"], ["STAND", "UP"]]; + +[QGVAR(enableSuppression), LINKFUNC(enableSuppression)] call CBA_fnc_addEventHandler; +[QGVAR(disableSuppression), LINKFUNC(disableSuppression)] call CBA_fnc_addEventHandler; + +player addEventHandler ["Local", { + params ["_unit", "_isLocal"]; + + CHECK(isNull _unit); + CHECK(!(_unit getVariable [ARR_2(QGVAR(suppressionEnabled), false)])); + + // transfer unit ownership + if (_isLocal) then { + // Add to new owner + [_unit] call FUNC(addSuppressedLocalUnit); + } else { + // Remove unit from old Owner + [_unit] call FUNC(removeSuppressedLocalUnit); + }; +}]; + +if (hasInterface) then { + private _enableSuppressionAction = [ + QGVAR(enableSuppression), + LLSTRING(suppression_enable), + "", + { + params ["", "_objects"]; + + [ + LLSTRING(suppression_enable), + [ + ["SLIDER", [LLSTRING(suppression_threshold), LLSTRING(suppression_threshold_tooltip)], [0, 1, 0.5, 2]], + ["COMBO", ["STR_A3_RscAttributeUnitPos_Title", LLSTRING(suppression_stance_tooltip)], + [ + ["DOWN", "MIDDLE", "UP"], + [ + ["STR_A3_RscAttributeUnitPos_Down_tooltip", "", "\a3\Ui_f\data\IGUI\RscIngameUI\RscUnitInfo\SI_prone_ca.paa"], + ["STR_A3_RscAttributeUnitPos_Crouch_tooltip", "", "\a3\Ui_f\data\IGUI\RscIngameUI\RscUnitInfo\SI_crouch_ca.paa"], + ["STR_A3_RscAttributeUnitPos_Up_tooltip", "", "\a3\Ui_f\data\IGUI\RscIngameUI\RscUnitInfo\SI_stand_ca.paa"] + ], + 0 + ] + ] + ], + { + (_this select 0) params ["_suppressionThreshold", "_suppressedStance"]; + (_this select 1) params ["", "_objects"]; + + { + if (!(_x isKindOf "CAManBase") || _x getVariable [QGVAR(suppressionEnabled), false] || isPlayer _x) then { + continue; + }; + + [QGVAR(enableSuppression), [_x, _suppressionThreshold, _suppressedStance], _x] call CBA_fnc_targetEvent; + } forEach _objects; + + [LLSTRING(suppression_enabled)] call zen_common_fnc_showMessage; + }, + {}, + _this + ] call zen_dialog_fnc_create; + }, + { + params ["", "_objects"]; + + ({_x isKindOf "CAManBase" && !(_x getVariable [QGVAR(suppressionEnabled), false]) && !isPlayer _x} count _objects) > 0 + } + ] call zen_context_menu_fnc_createAction; + [_enableSuppressionAction, [], 0] call zen_context_menu_fnc_addAction; + + private _disableSuppressionAction = [ + QGVAR(disableSuppression), + LLSTRING(suppression_disable), + "", + { + params ["", "_objects"]; + + { + if (!(_x getVariable [QGVAR(suppressionEnabled), false])) then { + continue; + }; + + _x setVariable [QGVAR(suppressionEnabled), false, true]; + } forEach _objects; + }, + { + params ["", "_objects"]; + + ({_x getVariable [QGVAR(suppressionEnabled), false]} count _objects) > 0 + } + ] call zen_context_menu_fnc_createAction; + [_disableSuppressionAction, [], 0] call zen_context_menu_fnc_addAction; +}; diff --git a/addons/zeus/functions/fnc_removeSuppressedLocalUnit.sqf b/addons/zeus/functions/fnc_removeSuppressedLocalUnit.sqf new file mode 100644 index 0000000..f4ffb32 --- /dev/null +++ b/addons/zeus/functions/fnc_removeSuppressedLocalUnit.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/** + * Author: Timi007 + * + * Description: + * Removes a unit from the suppressed units which are on this local machine. + * + * Parameter(s): + * 0: OBJECT - Unit. + * + * Returns: + * Nothing. + * + * Example: + * [_unit] call mts_zeus_fnc_removeSuppressedLocalUnit + * + */ + +params ["_unit"]; + +CHECK(isNil QGVAR(suppressedLocalUnits)); + +private _index = GVAR(suppressedLocalUnits) findIf {_x isEqualTo _unit}; +// Unit wasn't suppressed before +CHECK(_index < 0); +GVAR(suppressedLocalUnits) deleteAt _index; diff --git a/addons/zeus/stringtable.xml b/addons/zeus/stringtable.xml index ca22616..5b8d150 100644 --- a/addons/zeus/stringtable.xml +++ b/addons/zeus/stringtable.xml @@ -295,5 +295,35 @@ Feuereröffnung der Gruppe auf feuerfrei geschaltet + + + Enable suppression + Aktiviere Niederhaltung + + + Suppression enabled + Niederhaltung aktiviert + + + Disable suppression + Deaktiviere Niederhaltung + + + Threshold + Schwellenwert + + + Units will change stance if suppression is higher than this value. + Einheiten werden ihre Haltung ändern, sobald der Wert überschritten wird. + + + Stance + Haltung + + + The stance to take when suppressed. + Die Haltung während der Niedergehaltung. + +