-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathfnc_brain.sqf
More file actions
117 lines (98 loc) · 3.38 KB
/
fnc_brain.sqf
File metadata and controls
117 lines (98 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "script_component.hpp"
/*
* Author: nkenny
* evaluates danger causes and returns most dangerous state and appropriate response
*
* Arguments:
* 0: unit doing the avaluation <OBJECT>
* 1: danger queue <ARRAY>
*
* Return Value:
* array
*
* Example:
* [bob, []] call lambs_danger_fnc_dangerBrain;
*
* Public: No
*/
/*
DESIGN
Immediate actions
1 Fire
2 Hit
4 Explosion
9 BulletClose
Hide actions
5 DeadBodyGroup
6 DeadBody
Engage actions
0 Enemy detected
3 Enemy near
8 CanFire
Assess actions
7 Scream
10 Assess
*/
#define ACTION_IMMEDIATE 0
#define ACTION_HIDE 1
#define ACTION_ENGAGE 2
#define ACTION_ASSESS 3
params ["_unit", ["_queue", []]];
// init ~ immediate action, hide, engage, assess
private _return = [false, false, false, false];
private _group = group _unit;
// empty queue ~ exit with assess!
if (_queue isEqualTo []) exitWith {
private _causeArray = [DANGER_ASSESS, getPosWorld _unit, time + GVAR(dangerUntil), assignedTarget _unit];
_unit setVariable [QEGVAR(main,FSMDangerCauseData), _causeArray, EGVAR(main,debug_functions)]; // debug variable
[false, false, false, true, _causeArray]
};
// modify priorities ~ own function!
private _priorities = [_unit] call FUNC(brainAdjust);
// pick the most relevant danger cause
private _priority = -1;
private _index = -1;
{
private _cause = _x select 0;
if ((_priorities select _cause) > _priority) then {
_index = _forEachIndex;
_priority = _priorities select _cause;
};
} foreach _queue;
// select cause
private _causeArray = _queue select _index;
_causeArray params ["_dangerCause", "_dangerPos", "", "_dangerCausedBy"]; // "_dangerUntil" - skipped for future use -nkenny
// debug variable
_unit setVariable [QEGVAR(main,FSMDangerCauseData), _causeArray, EGVAR(main,debug_functions)];
// add selected cause to return array
_return pushBack _causeArray;
// assess actions
if (_dangerCause isEqualTo DANGER_ASSESS) exitWith {
_return set [ACTION_ASSESS, true];
_return
};
// immediate actions
if (_dangerCause in [DANGER_HIT, DANGER_BULLETCLOSE, DANGER_EXPLOSION, DANGER_FIRE] && {getSuppression _unit < 0.9}) exitWith {
_return set [ACTION_IMMEDIATE, (side _group) isNotEqualTo side (group _dangerCausedBy)];
_return
};
// engage actions
if (_dangerCause in [DANGER_ENEMYDETECTED, DANGER_ENEMYNEAR, DANGER_CANFIRE]) exitWith {
// gesture + share information
if (_dangerCause isEqualTo DANGER_ENEMYNEAR && { (_group getVariable [QGVAR(contact), 0]) < time }) then {
[_unit, ["gestureFreeze", "gesturePoint"] select (_unit distance2D _dangerPos < 50)] call EFUNC(main,doGesture);
[_unit, ["Combat", "Stealth"] select (behaviour _unit isEqualTo "STEALTH"), "contact", 100] call EFUNC(main,doCallout);
[_unit, _dangerCausedBy, EGVAR(main,radioShout), true] call EFUNC(main,doShareInformation);
};
// return
_return set [ACTION_ENGAGE, (side _group) isNotEqualTo side (group _dangerCausedBy)];
_return set [ACTION_HIDE, _unit knowsAbout _dangerCausedBy < 0.1 && {(typeOf _dangerCausedBy) isNotEqualTo "SuppressTarget"}]; // hide if target unknown!
_return
};
// hide actions
if (_dangerCause in [DANGER_DEADBODYGROUP, DANGER_DEADBODY, DANGER_SCREAM]) exitWith {
_return set [ACTION_HIDE, true];
_return
};
// end
_return