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

Move panic feature from brain to eventhandlers #260

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 1 addition & 10 deletions addons/danger/functions/fnc_brain.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
Hide actions
5 DeadBodyGroup
6 DeadBody
- Panic

Engage actions
0 Enemy detected
Expand Down Expand Up @@ -109,15 +108,7 @@ if (_dangerCause in [DANGER_ENEMYDETECTED, DANGER_ENEMYNEAR, DANGER_CANFIRE]) ex
};

// hide actions
private _panic = RND(1 - GVAR(panicChance)) && {getSuppression _unit > 0.9};
if (_panic || {_dangerCause in [DANGER_DEADBODYGROUP, DANGER_DEADBODY, DANGER_SCREAM]}) exitWith {

// panic function
if (_panic) then {
[_unit] call EFUNC(main,doPanic);
};

// return
if (_dangerCause in [DANGER_DEADBODYGROUP, DANGER_DEADBODY, DANGER_SCREAM]) exitWith {
_return set [ACTION_HIDE, true];
_return
};
Expand Down
1 change: 0 additions & 1 deletion addons/danger/functions/fnc_brainHide.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
5 DeadBodyGroup
6 DeadBody
7 Hide
- Panic
*/

params ["_unit", ["_type", -1], ["_pos", [0, 0, 0]]];
Expand Down
11 changes: 0 additions & 11 deletions addons/danger/settings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ private _curCat = LSTRING(Settings_GeneralCat);
1
] call CBA_fnc_addSetting;


// Chance of panic expressed as percentage
[
QGVAR(panicChance),
"SLIDER",
[LSTRING(Settings_PanicChance), LSTRING(Settings_PanicChance_ToolTip)],
[COMPONENT_NAME, _curCat],
[0, 1, 0.1, 2, true],
1
] call CBA_fnc_addSetting;

/*
TEMPORARILY DISABLED FOR VERSION 2.5 RELEASE
WAITING BETTER OR OTHER SOLUTION
Expand Down
16 changes: 0 additions & 16 deletions addons/danger/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,6 @@
<Russian>Дальность, на которой юниты считают себя атакующими</Russian>
<Italian>Raggio al quale le unità si considerano nel raggio d'assalto</Italian>
</Key>
<Key ID="STR_Lambs_Danger_Settings_PanicChance">
<English>Panic Chance</English>
<Czech>Šance paniky</Czech>
<German>Panikwahrscheinlichkeit</German>
<Polish>Szansa na panikę</Polish>
<Russian>Шанс паники</Russian>
<Italian>Possibilità di panico</Italian>
</Key>
<Key ID="STR_Lambs_Danger_Settings_PanicChance_ToolTip">
<English>Chance to panic in percentage</English>
<Czech>Šance na zpanikaření v procentech</Czech>
<German>Die Wahrscheinlichkeit in Panik zu verfallen in Prozent.</German>
<Polish>Szansa, że jednostka spanikuje, wyrażona w procentach</Polish>
<Russian>Шанс паники в процентах</Russian>
<Italian>Possibilità di panico in percentuale</Italian>
</Key>
<Key ID="STR_Lambs_Danger_Settings_CQBFormation">
<English>Units set to CQB formations will methodically clear buildings when an enemy is encountered</English>
<Czech>Jednotky s nastavenou CQB formací budou metodicky čistit budovy pokud narazí na nepřítele</Czech>
Expand Down
8 changes: 8 additions & 0 deletions addons/eventhandlers/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ class Extended_Explosion_Eventhandlers {
};
};
};

class Extended_Suppressed_Eventhandlers {
class CAManBase {
class LAMBS_CAManBase_suppressed {
Suppressed = QUOTE(_this call FUNC(suppressedEH));
};
};
};
1 change: 1 addition & 0 deletions addons/eventhandlers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PREP(explosionEH);
PREP(suppressedEH);
36 changes: 36 additions & 0 deletions addons/eventhandlers/functions/fnc_suppressedEH.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "script_component.hpp"
/*
* Author: nkenny
* Suppression eventhandler that may trigger panic
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* boolean
*
* Example:
* [bob] call lambs_eventhandlers_fnc_suppressionEH;
*
* Public: No
*/

// init
params ["_unit", "", "_shooter"];
if (
!local _unit
|| {morale _unit > 0}
|| {getSuppression _unit < 0.97}
|| {!isNull objectParent _unit}
|| {_unit getVariable [QEGVAR(danger,forceMove), false]}
|| {_unit getVariable [QEGVAR(danger,disableAI), false]}
|| {RND(GVAR(panicChance))}
|| {_unit distanceSqr _shooter < 1225} // ~ exit if shooter is within 35m
|| {isPlayer _unit || {isPlayer (leader _unit)}}
) exitWith {false};

// doPanic
_unit call EFUNC(main,doPanic);

// end
true
10 changes: 10 additions & 0 deletions addons/eventhandlers/settings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ private _curCat = LSTRING(Settings_Cat);
[0, 25, 9, 2],
true // players may configure their own preferences
] call CBA_fnc_addSetting;

// Chance of panic expressed as percentage
[
QGVAR(panicChance),
"SLIDER",
[LSTRING(Settings_PanicChance), LSTRING(Settings_PanicChance_ToolTip)],
[COMPONENT_NAME, _curCat],
[0, 1, 0.1, 2, true],
1
] call CBA_fnc_addSetting;
106 changes: 61 additions & 45 deletions addons/eventhandlers/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="Lambs">
<Package name="Eventhandlers">
<Key ID="STR_Lambs_Eventhandlers_Settings_Cat">
<English>Explosion</English>
<Czech>Exploze</Czech>
<German>Explosion</German>
<Polish>Wybuch</Polish>
<Russian>Взрыв</Russian>
<Italian>Esplosione</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_EnabledExplosionEH_DisplayName">
<English>Enable Explosion Eventhandler</English>
<Czech>Povolit Eventhandler explozí</Czech>
<German>Explosionsereignis-Handler aktivieren</German>
<Polish>Włącz obsługę zdarzeń wybuchu</Polish>
<Russian>Включить обработчик событий взрыва</Russian>
<Italian>Abilita Explosion Eventhandler</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_EnabledExplosionEH_ToolTip">
<English>Toggle AI Reactions to nearby explosions</English>
<Czech>Přepnout reakce UI na blízké exploze</Czech>
<German>KI-Reaktionen auf umliegende Explosionen umschalten</German>
<Polish>Przełącza reakcję AI na pobliskie wybuchy</Polish>
<Russian>Переключить реакцию ИИ на ближайшие взрывы</Russian>
<Italian>Attiva/disattiva le reazioni dell'IA alle esplosioni vicine</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_ExplosionResetTime_DisplayName">
<English>Explosion Eventhandler reset time</English>
<Czech>Čas restartu Eventhandleru explozí</Czech>
<German>Explosionsereignis-Handler Reset-Timer</German>
<Polish>Czas resetowania reakcji na zdarzenie wybuchu</Polish>
<Russian>Время сброса обработчика событий взрыва</Russian>
<Italian>Tempo di ripristino dell'Eventhandler di esplosione</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_ExplosionResetTime_ToolTip">
<English>Configures explosions reset time.</English>
<Czech>Konfiguruje čas restartu explozí</Czech>
<German>Legt den Reset-Timer für den Explosionsereignis-Handler fest.</German>
<Polish>Konfiguruje czas resetowania reakcji na zdarzenie wybuchu.</Polish>
<Russian>Настраивает время сброса взрывов</Russian>
<Italian>Configura il tempo di ripristino delle esplosioni.</Italian>
</Key>
</Package>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project name="Lambs">
<Package name="Eventhandlers">
<Key ID="STR_Lambs_Eventhandlers_Settings_Cat">
<English>Explosion</English>
<Czech>Exploze</Czech>
<German>Explosion</German>
<Polish>Wybuch</Polish>
<Russian>Взрыв</Russian>
<Italian>Esplosione</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_EnabledExplosionEH_DisplayName">
<English>Enable Explosion Eventhandler</English>
<Czech>Povolit Eventhandler explozí</Czech>
<German>Explosionsereignis-Handler aktivieren</German>
<Polish>Włącz obsługę zdarzeń wybuchu</Polish>
<Russian>Включить обработчик событий взрыва</Russian>
<Italian>Abilita Explosion Eventhandler</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_EnabledExplosionEH_ToolTip">
<English>Toggle AI Reactions to nearby explosions</English>
<Czech>Přepnout reakce UI na blízké exploze</Czech>
<German>KI-Reaktionen auf umliegende Explosionen umschalten</German>
<Polish>Przełącza reakcję AI na pobliskie wybuchy</Polish>
<Russian>Переключить реакцию ИИ на ближайшие взрывы</Russian>
<Italian>Attiva/disattiva le reazioni dell'IA alle esplosioni vicine</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_ExplosionResetTime_DisplayName">
<English>Explosion Eventhandler reset time</English>
<Czech>Čas restartu Eventhandleru explozí</Czech>
<German>Explosionsereignis-Handler Reset-Timer</German>
<Polish>Czas resetowania reakcji na zdarzenie wybuchu</Polish>
<Russian>Время сброса обработчика событий взрыва</Russian>
<Italian>Tempo di ripristino dell'Eventhandler di esplosione</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_ExplosionResetTime_ToolTip">
<English>Configures explosions reset time.</English>
<Czech>Konfiguruje čas restartu explozí</Czech>
<German>Legt den Reset-Timer für den Explosionsereignis-Handler fest.</German>
<Polish>Konfiguruje czas resetowania reakcji na zdarzenie wybuchu.</Polish>
<Russian>Настраивает время сброса взрывов</Russian>
<Italian>Configura il tempo di ripristino delle esplosioni.</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_PanicChance">
<English>Panic Chance</English>
<Czech>Šance paniky</Czech>
<German>Panikwahrscheinlichkeit</German>
<Polish>Szansa na panikę</Polish>
<Russian>Шанс паники</Russian>
<Italian>Possibilità di panico</Italian>
</Key>
<Key ID="STR_Lambs_Eventhandlers_Settings_PanicChance_ToolTip">
<English>Chance to panic in percentage</English>
<Czech>Šance na zpanikaření v procentech</Czech>
<German>Die Wahrscheinlichkeit in Panik zu verfallen in Prozent.</German>
<Polish>Szansa, że jednostka spanikuje, wyrażona w procentach</Polish>
<Russian>Шанс паники в процентах</Russian>
<Italian>Possibilità di panico in percentuale</Italian>
</Key>
</Package>
</Project>
1 change: 1 addition & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SUBPREP(UnitAction,doDodge);
SUBPREP(UnitAction,doFleeing);
SUBPREP(UnitAction,doHide);
SUBPREP(UnitAction,doPanic);
SUBPREP(UnitAction,doPanicReset);
SUBPREP(UnitAction,doReposition);
SUBPREP(UnitAction,doSmoke);
SUBPREP(UnitAction,doSuppress);
Expand Down
60 changes: 59 additions & 1 deletion addons/main/functions/UnitAction/fnc_doPanic.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: nkenny
* Unit acts in panic ~ may be improved in the future using position of danger and re-implementing more actions -nkenny
* Unit acts in panic
*
* Arguments:
* 0: unit panicking <OBJECT>
Expand Down Expand Up @@ -36,5 +36,63 @@ _unit setVariable [QGVAR(currentTask), "Panic", GVAR(debug_functions)];
// debug
if (GVAR(debug_functions)) then {format ["%1 panic! (%2)", side _unit, name _unit] call FUNC(debugLog);};

// force AI
_unit doWatch objNull;
_unit setVariable [QEGVAR(danger,forceMove), true];

// indoor -- gesture
if (RND(0.8) || {lineIntersects [eyePos _unit, (eyePos _unit) vectorAdd [0, 0, 7]]}) exitWith {

// action
_unit forceSpeed 0;
_unit setUnitPos selectRandom ["MIDDLE", "MIDDLE", "DOWN"];
private _move = call {
private _stance = stance _unit;
if (_stance isEqualTo "PRONE") exitWith {"AmovPpneMstpSnonWnonDnon_AmovPknlMstpSnonWnonDnon"}; // stand up crouch
if (_stance isEqualTo "CROUCH") exitWith {"AmovPpneMstpSnonWnonDnon_AmovPercMstpSnonWnonDnon"}; // stand up stand
"AmovPercMstpSnonWnonDnon_AmovPpneMstpSnonWnonDnon"
};
_unit switchMove _move;
[{_this playMoveNow selectRandom ["AmovPercMstpSnonWnonDnon_Scared", "AmovPercMstpSnonWnonDnon_Scared2"];}, _unit] call CBA_fnc_execNextFrame; // ~ set civilian animation - nkenny

// return
[_unit, 6 + random 4] call FUNC(doPanicReset);
};

// outdoor -- crawl
if (RND(0.25)) exitWith {

// action
_unit setUnitPos "DOWN";
[_unit, ["FastB", "FastLB", "FastRB"], true] call EFUNC(main,doGesture);

// chance to randomly fire weapon
if ((RND(0.4)) && {!(primaryWeapon _unit isEqualTo "")}) then {
_unit forceWeaponFire [primaryWeapon _unit, selectRandom (getArray (configFile >> "CfgWeapons" >> (primaryWeapon _unit) >> "modes"))];
};

// chance to randomly wave
if (RND(0.4)) then {
[_unit, "GestureCover"] call FUNC(doGesture);
};

// return
[_unit, 6 + random 6] call FUNC(doPanicReset);
};

// outdoor -- hide

// animation
[_unit, "GestureAgonyCargo"] call FUNC(doGesture);

// action
[_unit, _unit getPos [-100, getDir _unit], 55] call FUNC(doHide);

// stance
_unit setUnitPos selectRandom ["MIDDLE", "UP"];

// reset
[_unit, 8 + random 6, true] call FUNC(doPanicReset);

// end
true
27 changes: 27 additions & 0 deletions addons/main/functions/UnitAction/fnc_doPanicReset.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"
/*
* Author: nkenny
* Reset panic state on unit
*
* Arguments:
* 0: unit panicking <OBJECT>
* 1: time until reset <NUMBER>
* 2: Unstick animation <BOOL>
*
* Return Value:
* nil
*
* Example:
* [bob] call lambs_main_fnc_doPanicReset;
*
* Public: No
*/
params ["_unit", "_timeout", ["_animation", false]];
[
{
params ["_unit", "_animation"];
_unit setUnitPos "AUTO";
_unit setVariable [QEGVAR(danger,forceMove), nil];
if (_animation) then {[_unit, "gestureYes"] call FUNC(doGesture);};
}, [_unit, _animation], _timeout
] call CBA_fnc_waitAndExecute;