-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathfnc_repair.sqf
More file actions
270 lines (240 loc) · 10.1 KB
/
fnc_repair.sqf
File metadata and controls
270 lines (240 loc) · 10.1 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "..\script_component.hpp"
/*
* Author: Glowbal, KoffeinFlummi
* Starts the repair process.
*
* Arguments:
* 0: Unit that does the repairing <OBJECT>
* 1: Vehicle to repair <OBJECT>
* 2: Selected hitpoint or hitpointIndex <STRING>or<NUMBER>
* 3: Repair Action Classname <STRING>
*
* Return Value:
* Succesful Repair Started <BOOL>
*
* Example:
* [unit, vehicle, "hitpoint", "classname"] call ace_repair_fnc_repair
*
* Public: Yes
*/
params ["_caller", "_target", "_hitPoint", "_className"];
TRACE_4("params",_caller,_target,_hitPoint,_className);
private _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
if !(isClass _config) exitWith {false}; // or go for a default?
private _engineerRequired = if (isNumber (_config >> "requiredEngineer")) then {
getNumber (_config >> "requiredEngineer");
} else {
// Check for required class
if (isText (_config >> "requiredEngineer")) exitWith {
missionNamespace getVariable [(getText (_config >> "requiredEngineer")), 0];
};
0;
};
if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitWith {false};
if ((isEngineOn _target) && {GVAR(autoShutOffEngineWhenStartingRepair)}) then {
[QEGVAR(common,engineOn), [_target, false], _target] call CBA_fnc_targetEvent;
};
if ((isEngineOn _target) && {!GVAR(autoShutOffEngineWhenStartingRepair)}) exitWith {
[LSTRING(shutOffEngineWarning), 1.5, _caller] call EFUNC(common,displayTextStructured);
false
};
private _items = _config call FUNC(getRepairItems);
if (_items isNotEqualTo [] && {!([_caller, _items] call FUNC(hasItems))}) exitWith {false};
private _return = true;
if (getText (_config >> "condition") != "") then {
private _condition = getText (_config >> "condition");
if (isNil _condition) then {
_condition = compile _condition;
} else {
_condition = missionNamespace getVariable _condition;
};
if (_condition isEqualType false) then {
_return = _condition;
} else {
_return = [_caller, _target, _hitPoint, _className] call _condition;
};
};
if (!_return) exitWith {false};
// private _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then {
// missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0]
// } else {
// getNumber(_config >> "vehicleStateCondition")
// };
// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitWith {false};
private _repairLocations = getArray (_config >> "repairLocations");
if (!("All" in _repairLocations)) then {
private _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))};
private _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))};
{
if (_x == "field") exitWith {_return = true;};
if (_x == "RepairFacility" && _repairFacility) exitWith {_return = true;};
if (_x == "RepairVehicle" && _repairVeh) exitWith {_return = true;};
if (!isNil _x) exitWith {
private _val = missionNamespace getVariable _x;
if (_val isEqualType 0) then {
_return = switch (_val) do {
case 0: {true}; //useAnywhere
case 1: {call _repairVeh}; //repairVehicleOnly
case 2: {call _repairFacility}; //repairFacilityOnly
case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility
default {false}; //Disabled
};
};
};
} forEach _repairLocations;
};
private _requiredObjects = getArray (_config >> "claimObjects");
private _claimObjectsAvailable = [];
if (_requiredObjects isNotEqualTo []) then {
_claimObjectsAvailable = [_caller, 5, _requiredObjects, true] call FUNC(getClaimObjects);
if (_claimObjectsAvailable isEqualTo []) then {
TRACE_2("Missing Required Objects",_requiredObjects,_claimObjectsAvailable);
_return = false
};
};
if !(_return && alive _target) exitWith {false};
//Last exitWith: repair_success or repair_failure will be run
//Claim required objects
{
TRACE_2("Claiming",_x,(typeOf _x));
[_caller, _x, false] call EFUNC(common,claim);
} forEach _claimObjectsAvailable;
private _consumeItems = if (isNumber (_config >> "itemConsumed")) then {
getNumber (_config >> "itemConsumed");
} else {
// Check for required class
if (isText (_config >> "itemConsumed")) exitWith {
missionNamespace getVariable [(getText (_config >> "itemConsumed")), 0];
};
0;
};
private _usersOfItems = [];
if (_consumeItems > 0) then {
_usersOfItems = ([_caller, _items] call FUNC(useItems)) select 1;
};
// Parse the config for the progress callback
private _callbackProgress = getText (_config >> "callbackProgress");
if (_callbackProgress == "") then {
_callbackProgress = {
(_this select 0) params ["_caller", "_target", "", "", "", "", "_claimObjectsAvailable"];
(
(alive _target) &&
{(abs speed _target) < 1} && // make sure vehicle doesn't drive off
{_claimObjectsAvailable findIf {!alive _x || {_x getVariable [QEGVAR(common,owner), objNull] isNotEqualTo _caller}} == -1} // make sure claim objects are still available
)
};
} else {
if (isNil _callbackProgress) then {
_callbackProgress = compile _callbackProgress;
} else {
_callbackProgress = missionNamespace getVariable _callbackProgress;
};
};
// Player Animation
private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
private _loopAnim = (getNumber (_config >> "loopAnimation")) isEqualTo 1;
_caller setVariable [QGVAR(selectedWeaponOnrepair), currentWeapon _caller];
// Cannot use secondairy weapon for animation
if (currentWeapon _caller == secondaryWeapon _caller) then {
_caller selectWeapon (primaryWeapon _caller);
};
private _wpn = ["non", "rfl", "pst"] select (1 + ([primaryWeapon _caller, handgunWeapon _caller] find (currentWeapon _caller)));
_callerAnim = [_callerAnim, "[wpn]", _wpn] call CBA_fnc_replace;
if (vehicle _caller == _caller && {_callerAnim != ""}) then {
if (primaryWeapon _caller == "") then {
_caller addWeapon "ACE_FakePrimaryWeapon";
};
if (currentWeapon _caller == "") then {
_caller selectWeapon (primaryWeapon _caller); // unit always has a primary weapon here
};
if !(_caller call EFUNC(common,isSwimming)) then {
if (stance _caller == "STAND") then {
_caller setVariable [QGVAR(repairPrevAnimCaller), "amovpknlmstpsraswrfldnon"];
} else {
_caller setVariable [QGVAR(repairPrevAnimCaller), animationState _caller];
};
_caller setVariable [QGVAR(repairCurrentAnimCaller), toLowerANSI _callerAnim];
[_caller, _callerAnim] call EFUNC(common,doAnimation);
};
};
if (_loopAnim) then {
private _animDoneEh = _caller addEventHandler ["AnimDone", {
params ["_caller", "_anim"];
if (_anim isEqualTo (_caller getVariable [QGVAR(repairCurrentAnimCaller), ""])) then {
[{
params ["_caller", "_anim"];
if !(isNil {_caller getVariable QGVAR(repairCurrentAnimCaller)}) then {
TRACE_2("loop",_caller,_anim);
_this call EFUNC(common,doAnimation)
};
}, [_caller, _anim], 2.5] call CBA_fnc_waitAndExecute;
};
}];
_caller setVariable [QGVAR(repairLoopAnimEh), _animDoneEh];
};
private _soundPosition = _caller modelToWorldVisualWorld (_caller selectionPosition "RightHand");
["Acts_carFixingWheel", _soundPosition, nil, 50] call EFUNC(common,playConfigSound3D);
// Get repair time
private _repairTime = [
configOf _target >> QGVAR(repairTimes) >> configName _config,
"number",
-1
] call CBA_fnc_getConfigEntry;
if (_repairTime < 0) then {
_repairTime = if (isNumber (_config >> "repairingTime")) then {
getNumber (_config >> "repairingTime");
} else {
if (isText (_config >> "repairingTime")) exitWith {
private _repairTimeConfig = getText (_config >> "repairingTime");
if (isNil _repairTimeConfig) then {
_repairTimeConfig = compile _repairTimeConfig;
} else {
_repairTimeConfig = missionNamespace getVariable _repairTimeConfig;
};
if (_repairTimeConfig isEqualType 0) exitWith {
_repairTimeConfig;
};
[_caller, _target, _hitPoint, _className] call _repairTimeConfig;
};
0;
};
};
// Find localized string
private _hitPointClassname = if (_hitPoint isEqualType "") then {
_hitPoint
} else {
((getAllHitPointsDamage _target) select 0) select _hitPoint
};
private _processText = getText (_config >> "displayNameProgress");
private _backupText = format [localize LSTRING(RepairingHitPoint), _hitPointClassname];
private _text = _processText;
if (getNumber (_config >> "forceDisplayName") isNotEqualTo 1) then {
_text = ([_hitPointClassname, _processText, _backupText] call FUNC(getHitPointString)) select 0;
};
TRACE_4("display",_hitPoint,_hitPointClassname,_processText,_text);
// Start repair
[
_repairTime,
[_caller, _target, _hitPoint, _className, _items, _usersOfItems, _claimObjectsAvailable],
DFUNC(repair_success),
DFUNC(repair_failure),
_text,
_callbackProgress,
["isNotSwimming", "isNotOnLadder"]
] call EFUNC(common,progressBar);
// Display Icon
private _iconDisplayed = getText (_config >> "actionIconPath");
if (_iconDisplayed != "") then {
[QGVAR(repairActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber(_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon);
};
// handle display of text/hints
private _displayText = "";
if (_target != _caller) then {
_displayText = getText(_config >> "displayTextOther");
} else {
_displayText = getText(_config >> "displayTextSelf");
};
if (_displayText != "") then {
[QEGVAR(common,displayTextStructured), [[_displayText, [_caller] call EFUNC(common,getName), [_target] call EFUNC(common,getName)], 1.5, _caller], [_caller]] call CBA_fnc_targetEvent;
};
true;