-
Notifications
You must be signed in to change notification settings - Fork 751
Expand file tree
/
Copy pathfnc_initAnimActions.sqf
More file actions
202 lines (162 loc) · 7.25 KB
/
fnc_initAnimActions.sqf
File metadata and controls
202 lines (162 loc) · 7.25 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "..\script_component.hpp"
/*
* Author: Dystopian
* Initializes object interactions based on animations.
*
* Arguments:
* 0: Target <OBJECT>
*
* Return Value:
* None
*
* Example:
* cursorObject call ace_interaction_fnc_initAnimActions
*
* Public: No
*/
params ["_object"];
private _class = typeOf _object;
if (_class in GVAR(initializedAnimClasses)) exitWith {};
GVAR(initializedAnimClasses) pushBack _class;
private _statement = {
params ["_target", "_player", "_params"];
_params params ["_anim", "_phase", "_duration", "_text"];
TRACE_5("statement",_target,_player,_anim,_phase,_duration);
[
_duration,
[_target, _player, _anim, _phase],
{
(_this select 0) params ["_target", "_player", "_anim", "_phase"];
private _items = _target getVariable [
format [QGVAR(animsItems_%1), _anim],
getArray (configOf _target >> QGVAR(anims) >> _anim >> "items")
];
// If 1 object was spawned in, consider it a success
private _success = false;
if (_items isNotEqualTo []) then {
if (_items isEqualType "") then {
_items = [_items];
};
private _weaponHolder = objNull;
{
private _type = (_x call EFUNC(common,getItemType)) select 0;
if (_type == "") then {
private _emptyPosAGL = [];
// This covers testing vehicle stability and finding a safe position
for "_i" from 1 to 3 do {
_emptyPosAGL = [_target, _x, _player] call EFUNC(common,findUnloadPosition);
if (_emptyPosAGL isNotEqualTo []) exitWith {};
};
// If still no valid position, try the next item
if (_emptyPosAGL isEqualTo []) then {
[LELSTRING(common,NoRoomToUnload)] call EFUNC(common,displayTextStructured);
continue;
};
private _object = createVehicle [_x, _emptyPosAGL, [], 0, "CAN_COLLIDE"];
if (!isNull _object) then {
// Prevent items from taking damage when unloaded
[_object, "blockDamage", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
[EFUNC(common,statusEffect_set), [_object, "blockDamage", QUOTE(ADDON), false], 2] call CBA_fnc_waitAndExecute;
_success = true;
} else {
WARNING_1("Failed to create object of type '%1'",_x);
};
continue;
};
// Functions/code below are guaranteed to spawn in objects
_success = true;
// getItemType considers backpacks as weapons, so handle them first
if (getNumber (configFile >> "CfgVehicles" >> _x >> "isBackpack") == 1) then {
if (backpack _player == "") then {
_player addBackpackGlobal _x;
} else {
if (isNull _weaponHolder) then {
_weaponHolder = nearestObject [_player, "WeaponHolder"];
if (isNull _weaponHolder || {_player distance _weaponHolder > 2}) then {
_weaponHolder = createVehicle ["GroundWeaponHolder", [0, 0, 0], [], 0, "NONE"];
_weaponHolder setPosASL getPosASL _player;
};
};
_weaponHolder addBackpackCargoGlobal [_x, 1];
};
continue;
};
switch (_type) do {
case "weapon": {
[_player, _x, true] call CBA_fnc_addWeapon;
};
case "item": {
[_player, _x, true] call CBA_fnc_addItem;
};
case "magazine": {
[_player, _x, -1, true] call CBA_fnc_addMagazine;
};
};
} forEach _items;
} else {
[LELSTRING(common,disabled)] call EFUNC(common,displayTextStructured);
};
if (!_success) exitWith {};
_target animate [_anim, _phase, true];
},
{},
_text,
{
(_this select 0) params ["_target", "", "_anim", "_phase"];
_target animationPhase _anim != _phase
},
["isNotSwimming"]
] call EFUNC(common,progressBar);
};
private _condition = {
params ["_target", "_player", "_params"];
_params params ["_anim", "_phase"];
_target animationPhase _anim != _phase
&& {[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
};
private _config = configOf _object;
{
private _animConfig = _x;
private _anim = configName _animConfig;
private _animationSourcesConfig = _config >> "AnimationSources" >> _anim;
if !(
isClass _animationSourcesConfig // anim exist
&& {0 != [_animationSourcesConfig >> "scope", "NUMBER", 1] call CBA_fnc_getConfigEntry} // anim not hidden
&& {isNumber (_animationSourcesConfig >> "initPhase")} // anim correct (some CUP anims are inherited and cleared)
&& {0 != [_animConfig >> "enabled", "NUMBER", 1] call CBA_fnc_getConfigEntry} // anim enabled
) then {continue};
private _positions = [];
{
if (_x isEqualType "") then {
_positions pushBack compile _x;
} else {
_positions pushBack _x;
};
} forEach getArray (_animConfig >> "positions");
_positions append getArray (_animConfig >> "selections");
if (_positions isEqualTo []) then {
ERROR_2("No action position for _class %1 anim %2",_class,_anim);
continue;
};
private _phase = [_animConfig >> "phase", "NUMBER", 1] call CBA_fnc_getConfigEntry;
private _name = [_animConfig >> "name", "TEXT", localize "str_a3_cfgactions_unmountitem0"] call CBA_fnc_getConfigEntry;
private _icon = [_animConfig >> "icon", "TEXT", "\A3\ui_f\data\igui\cfg\actions\take_ca.paa"] call CBA_fnc_getConfigEntry;
private _duration = [_animConfig >> "duration", "NUMBER", 10] call CBA_fnc_getConfigEntry;
private _text = getText (_animConfig >> "text");
private _distance = [_animConfig >> "distance", "NUMBER", 2] call CBA_fnc_getConfigEntry;
{
private _action = [
format [QGVAR(anim_%1_%2), _anim, _forEachIndex],
_name,
_icon,
_statement,
_condition,
{},
[_anim, _phase, _duration, _text],
_x,
_distance
] call EFUNC(interact_menu,createAction);
[_class, 0, [], _action] call EFUNC(interact_menu,addActionToClass);
TRACE_3("add anim",_class,_anim,_x);
} forEach _positions;
} forEach ("true" configClasses (_config >> QGVAR(anims)));