ACE3/addons/rearm/functions/fnc_addRearmActions.sqf

94 lines
3.8 KiB
Plaintext
Raw Normal View History

2015-08-15 16:43:13 +00:00
/*
* Author: GitHawk
* Show the resupplyable ammunition of all surrounding vehicles.
*
* Argument:
* 0: Target <OBJECT>
*
* Return value:
* ChildActions <ARRAY>
*
* Example:
* [tank] call ace_rearm_fnc_addRearmActions
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicleActions", "_actions", "_action", "_vehicles", "_vehicle", "_needToAdd", "_magazineHelper", "_turretPath", "_magazines", "_magazine", "_icon", "_cnt"];
2016-02-01 19:05:53 +00:00
params [["_target", objNull, [objNull]]];
2015-08-15 16:43:13 +00:00
_vehicles = nearestObjects [_target, ["AllVehicles"], 20];
if (count _vehicles < 2) exitWith {false}; // Rearming needs at least 2 vehicles
2015-08-15 16:43:13 +00:00
_vehicleActions = [];
{
_actions = [];
_vehicle = _x;
_needToAdd = false;
_action = [];
if !((_vehicle == _target) || (_vehicle isKindOf "CAManBase")) then {
2015-08-15 16:43:13 +00:00
_magazineHelper = [];
{
_turretPath = _x;
2016-02-01 19:05:53 +00:00
_magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines);
2015-08-15 16:43:13 +00:00
{
_magazine = _x;
2016-02-01 19:05:53 +00:00
_currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
if ((_currentMagazines < ([_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines))) && !(_magazine in _magazineHelper)) then {
_action = [_magazine,
getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"),
getText(configFile >> "CfgMagazines" >> _magazine >> "picture"),
{_this call FUNC(takeAmmo)},
{true},
{},
2015-08-16 00:18:53 +00:00
[_magazine, _vehicle]] call EFUNC(interact_menu,createAction);
2015-08-15 16:43:13 +00:00
_actions pushBack [_action, [], _target];
_magazineHelper pushBack _magazine;
_needToAdd = true;
} else {
if (((_vehicle magazineTurretAmmo [_magazine, _turretPath]) < getNumber (configFile >> "CfgMagazines" >> _magazine >> "count")) && !(_magazine in _magazineHelper)) then {
_action = [_magazine,
getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"),
getText(configFile >> "CfgMagazines" >> _magazine >> "picture"),
{_this call FUNC(takeAmmo)},
{true},
{},
2015-08-16 00:18:53 +00:00
[_magazine, _vehicle]] call EFUNC(interact_menu,createAction);
2015-08-15 16:43:13 +00:00
_actions pushBack [_action, [], _target];
_magazineHelper pushBack _magazine;
_needToAdd = true;
};
};
} forEach _magazines;
} forEach REARM_TURRET_PATHS;
2015-08-15 16:43:13 +00:00
};
if (_needToAdd && !(_vehicle getVariable [QGVAR(disabled), false])) then {
2015-08-15 16:43:13 +00:00
_icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon");
if !((_icon select [0, 1]) == "\") then {
_icon = "";
};
2015-08-16 00:18:53 +00:00
if (GVAR(level) == 0) then {
_action = [_vehicle,
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"),
_icon,
{_this call FUNC(rearmEntireVehicle)},
{true},
{},
2015-08-16 00:18:53 +00:00
_vehicle] call EFUNC(interact_menu,createAction);
_vehicleActions pushBack [_action, [], _target];
} else {
_action = [_vehicle,
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"),
_icon,
{},
{true},
{},
2015-08-16 00:18:53 +00:00
[]] call EFUNC(interact_menu,createAction);
_vehicleActions pushBack [_action, _actions, _target];
};
2015-08-15 16:43:13 +00:00
};
} forEach _vehicles;
2015-08-16 00:18:53 +00:00
2015-08-15 16:43:13 +00:00
_vehicleActions