2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-08-18 00:32:10 +00:00
|
|
|
/*
|
2017-09-29 19:53:25 +00:00
|
|
|
* Author: Tuupertunut
|
|
|
|
* Returns information about every magazine that can be rearmed in the vehicle. Multiple mags of
|
|
|
|
* same class in the same turret are grouped together for practical reasons.
|
2015-08-18 00:32:10 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2016-02-27 20:05:19 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2015-08-18 00:32:10 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-09-29 19:53:25 +00:00
|
|
|
* Magazine info <ARRAY of ARRAYs>
|
|
|
|
* Child arrays:
|
|
|
|
* 0: Magazine class <STRING>
|
|
|
|
* 1: Turret path <ARRAY>
|
|
|
|
* 2: Is pylon magazine <BOOLEAN>
|
|
|
|
* 3: Pylon index (-1 if not pylon) <NUMBER>
|
|
|
|
* 4: Max magazines <NUMBER>
|
|
|
|
* 5: Current magazines <NUMBER>
|
|
|
|
* 6: Max rounds per magazine <NUMBER>
|
|
|
|
* 7: Current rounds in magazines <ARRAY of NUMBERs>
|
2015-08-18 00:32:10 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2017-09-29 19:53:25 +00:00
|
|
|
* [tank] call ace_rearm_fnc_getNeedRearmMagazines
|
2015-08-18 00:32:10 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
params ["_vehicle"];
|
2015-08-18 00:32:10 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
private _magazineInfo = [];
|
2015-08-18 00:32:10 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
// 1.70 pylons
|
2021-02-18 18:58:08 +00:00
|
|
|
private _pylonConfigs = configProperties [configOf _vehicle >> "Components" >> "TransportPylonsComponent" >> "Pylons", "isClass _x"];
|
2017-09-29 19:53:25 +00:00
|
|
|
{
|
|
|
|
private _pylonConfig = _x;
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
// Strangely, a 1-based index.
|
|
|
|
private _pylonIndex = _forEachIndex + 1;
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
// Retrieving pylon magazine by index. If the pylon is empty, it is marked with "".
|
|
|
|
private _pylonMagazine = (getPylonMagazines _vehicle) select (_pylonIndex - 1);
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
// Only care about pylons that have a magazine.
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_pylonMagazine isNotEqualTo "") then {
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
private _maxRounds = getNumber (configFile >> "CfgMagazines" >> _pylonMagazine >> "count");
|
|
|
|
private _currentRounds = _vehicle ammoOnPylon _pylonIndex;
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
if (_currentRounds < _maxRounds) then {
|
2017-09-30 16:14:41 +00:00
|
|
|
// getPylonTurret expects 0 based index, and returns driver turret as [-1]
|
2021-02-23 16:57:57 +00:00
|
|
|
private _pylonTurret = [_vehicle, _forEachIndex] call EFUNC(common,getPylonTurret);
|
2017-09-30 16:14:41 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
_magazineInfo pushBack [_pylonMagazine, _pylonTurret, true, _pylonIndex, 1, 1, _maxRounds, [_currentRounds]];
|
2015-08-18 00:32:10 +00:00
|
|
|
};
|
|
|
|
};
|
2017-09-29 19:53:25 +00:00
|
|
|
} forEach _pylonConfigs;
|
2015-08-18 00:32:10 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
private _turrets = [_vehicle] call FUNC(getAllRearmTurrets);
|
|
|
|
{
|
|
|
|
private _turretPath = _x;
|
|
|
|
private _magazines = [_vehicle, _turretPath] call FUNC(getTurretConfigMagazines);
|
2015-08-18 00:32:10 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
// _magazines without duplicates
|
|
|
|
private _magazineClasses = _magazines arrayIntersect _magazines;
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
{
|
2017-09-29 19:53:25 +00:00
|
|
|
private _magazineClass = _x;
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
private _maxMagazines = [_vehicle, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
|
|
|
private _maxRoundsPerMag = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
/* Array of ammo counts in every magazine. Example: [200, 200, 152] means 2 mags with 200
|
|
|
|
* rounds and 1 mag with 152 rounds. */
|
|
|
|
private _currentRounds = [_vehicle, _turretPath, _magazineClass] call FUNC(getTurretMagazineAmmo);
|
|
|
|
private _currentMagazines = count _currentRounds;
|
2017-06-08 16:47:52 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
/* If there is space for new magazines or if some magazines are not full, add the magazine
|
|
|
|
* type to _magazineInfo. */
|
|
|
|
if ((_currentMagazines < _maxMagazines) || {({_x < _maxRoundsPerMag} count _currentRounds) > 0}) then {
|
2019-07-05 22:57:22 +00:00
|
|
|
if (_magazineClass == "FakeWeapon") exitWith {};
|
2017-09-29 19:53:25 +00:00
|
|
|
_magazineInfo pushBack [_magazineClass, _turretPath, false, -1, _maxMagazines, _currentMagazines, _maxRoundsPerMag, _currentRounds];
|
2017-06-08 16:47:52 +00:00
|
|
|
};
|
2019-07-05 22:57:22 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
} forEach _magazineClasses;
|
|
|
|
} forEach _turrets;
|
2017-06-08 16:47:52 +00:00
|
|
|
|
2017-09-29 19:53:25 +00:00
|
|
|
TRACE_2("getNeedRearmMagazines",_vehicle,_magazineInfo);
|
|
|
|
_magazineInfo
|