Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zeus suppression module #79

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions addons/zeus/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions addons/zeus/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
} forEach _toUnits;
}] call CBA_fnc_addEventHandler;

call FUNC(initAISuppression);

CHECK(!hasinterface);

GVAR(moduleDestination_running) = false;
Expand Down
47 changes: 47 additions & 0 deletions addons/zeus/functions/fnc_addAISuppressionPFH.sqf
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 29 additions & 0 deletions addons/zeus/functions/fnc_addSuppressedLocalUnit.sqf
Original file line number Diff line number Diff line change
@@ -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;
};
27 changes: 27 additions & 0 deletions addons/zeus/functions/fnc_disableSuppression.sqf
Original file line number Diff line number Diff line change
@@ -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];
};
34 changes: 34 additions & 0 deletions addons/zeus/functions/fnc_enableSuppression.sqf
Original file line number Diff line number Diff line change
@@ -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);
113 changes: 113 additions & 0 deletions addons/zeus/functions/fnc_initAISuppression.sqf
Original file line number Diff line number Diff line change
@@ -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;
};
26 changes: 26 additions & 0 deletions addons/zeus/functions/fnc_removeSuppressedLocalUnit.sqf
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions addons/zeus/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,35 @@
<German>Feuereröffnung der Gruppe auf feuerfrei geschaltet</German>
</Key>
</Container>
<Container name="suppression">
<Key ID="STR_mts_zeus_suppression_enable">
<Original>Enable suppression</Original>
<German>Aktiviere Niederhaltung</German>
</Key>
<Key ID="STR_mts_zeus_suppression_enabled">
<Original>Suppression enabled</Original>
<German>Niederhaltung aktiviert</German>
</Key>
<Key ID="STR_mts_zeus_suppression_disable">
<Original>Disable suppression</Original>
<German>Deaktiviere Niederhaltung</German>
</Key>
<Key ID="STR_mts_zeus_suppression_threshold">
<Original>Threshold</Original>
<German>Schwellenwert</German>
</Key>
<Key ID="STR_mts_zeus_suppression_threshold_tooltip">
<Original>Units will change stance if suppression is higher than this value.</Original>
<German>Einheiten werden ihre Haltung ändern, sobald der Wert überschritten wird.</German>
</Key>
<Key ID="STR_mts_zeus_suppression_stance">
<Original>Stance</Original>
<German>Haltung</German>
</Key>
<Key ID="STR_mts_zeus_suppression_stance_tooltip">
<Original>The stance to take when suppressed.</Original>
<German>Die Haltung während der Niedergehaltung.</German>
</Key>
</Container>
</Package>
</Project>