forked from acemod/ACE3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnc_addRearmActions.sqf
More file actions
121 lines (108 loc) · 3.98 KB
/
fnc_addRearmActions.sqf
File metadata and controls
121 lines (108 loc) · 3.98 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
#include "..\script_component.hpp"
/*
* Author: GitHawk
* Show the resupplyable ammunition of all surrounding vehicles.
*
* Arguments:
* 0: Ammo Truck <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* ChildActions <ARRAY>
*
* Example:
* [tank, player] call ace_rearm_fnc_addRearmActions
*
* Public: No
*/
params ["_truck", "_player"];
private _vehicles = nearestObjects [_truck, ["AllVehicles"], GVAR(distance)];
_vehicles = _vehicles select {
_x != _truck
&& {!(_x isKindOf "CAManBase")}
&& {alive _x}
&& {!(_x getVariable [QGVAR(disabled), false])}
};
private _cswCarryMagazines = [];
private _vehicleActions = [];
{
private _vehicle = _x;
private _displayName = getText (configOf _vehicle >> "displayName");
private _distanceStr = (ACE_player distance _vehicle) toFixed 1;
private _actionName = format ["%1 (%2m)", _displayName, _distanceStr];
// Array of magazines that can be rearmed in the vehicle
private _needRearmMags = ([_vehicle] call FUNC(getNeedRearmMagazines)) apply {_x select 0};
// _needRearmMags without duplicates
private _magazineHelper = _needRearmMags arrayIntersect _needRearmMags;
_magazineHelper = _magazineHelper select {[_truck, _x] call FUNC(hasEnoughSupply)};
if (["ace_csw"] call EFUNC(common,isModLoaded)) then {
([_vehicle] call EFUNC(csw,aceRearmGetCarryMagazines)) params ["_turretMagsCSW", "_allCarryMags"];
TRACE_3("csw compat",_vehicle,_turretMagsCSW,_allCarryMags);
_cswCarryMagazines append _allCarryMags;
_magazineHelper = _magazineHelper - _turretMagsCSW;
};
TRACE_2("can add",_x,_magazineHelper);
if (_magazineHelper isNotEqualTo []) then {
private _icon = getText(configOf _vehicle >> "Icon");
if !((_icon select [0, 1]) == "\") then {
_icon = "";
};
if (GVAR(level) == 0) then {
// [Level 0] adds a single action to rearm the entire vic
private _action = [
_vehicle,
_actionName,
_icon,
{_this call FUNC(rearmEntireVehicle)},
{true},
{},
_vehicle
] call EFUNC(interact_menu,createAction);
_vehicleActions pushBack [_action, [], _truck];
} else {
// [Level 1,2] - Add actions for each magazine
private _actions = [];
{
private _action = [
_x,
_x call FUNC(getMagazineName),
getText(configFile >> "CfgMagazines" >> _x >> "picture"),
{_this call FUNC(takeAmmo)},
{true},
{},
[_x, _vehicle]
] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _truck];
} forEach _magazineHelper;
private _action = [
_vehicle,
_actionName,
_icon,
{},
{true},
{},
[]
] call EFUNC(interact_menu,createAction);
_vehicleActions pushBack [_action, _actions, _truck];
};
};
} forEach _vehicles;
if (_cswCarryMagazines isNotEqualTo []) then {
_cswCarryMagazines = _cswCarryMagazines arrayIntersect _cswCarryMagazines;
_cswCarryMagazines = _cswCarryMagazines select {[_truck, _x] call FUNC(hasEnoughSupply)};
private _baseAction = [QGVAR(cswTake), "CSW", "", {}, {true}] call EFUNC(interact_menu,createAction);
private _subActions = _cswCarryMagazines apply {
private _action = [
_x,
_x call FUNC(getMagazineName),
getText(configFile >> "CfgMagazines" >> _x >> "picture"),
{_this call FUNC(takeAmmo)},
{true},
{},
[_x, _player]
] call EFUNC(interact_menu,createAction);
[_action, [], _truck];
};
_vehicleActions pushBack [_baseAction, _subActions, _truck];
};
_vehicleActions