2016-02-27 19:31:07 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk
|
|
|
|
* Removes a magazine from the supply.
|
|
|
|
*
|
2016-06-06 18:42:20 +00:00
|
|
|
* Arguments:
|
2016-02-27 20:05:19 +00:00
|
|
|
* 0: Ammo Truck <OBJECT>
|
2016-02-27 19:31:07 +00:00
|
|
|
* 1: Magazine Classname <STRING>
|
2017-06-08 16:47:52 +00:00
|
|
|
* 2: Number of Rounds to withdraw <NUMBER> (default: -1)
|
2016-02-27 19:31:07 +00:00
|
|
|
*
|
2016-06-06 18:42:20 +00:00
|
|
|
* Return Value:
|
2016-02-27 19:31:07 +00:00
|
|
|
* Magazine was removed <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_removeMagazineFromSupply
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
params [["_truck", objNull, [objNull]], ["_magazineClass", "", [""]], ["_numRounds", -1, [0]]];
|
|
|
|
TRACE_3("removeMagazineFromSupply",_truck,_magazineClass,_numRounds);
|
2016-02-27 19:31:07 +00:00
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
if (isNull _truck || {_magazineClass isEqualTo ""}) exitWith {false};
|
2016-02-27 19:31:07 +00:00
|
|
|
|
|
|
|
private _return = false;
|
|
|
|
([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"];
|
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
if (GVAR(supply) == 0) then {
|
|
|
|
WARNING("supply setting is set to unlimited"); // func shouldn't have been called
|
|
|
|
_return = true;
|
|
|
|
};
|
|
|
|
|
2016-02-27 19:31:07 +00:00
|
|
|
if (GVAR(supply) == 1) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
private _supply = [_truck] call FUNC(getSupplyCount);
|
2016-02-27 19:31:07 +00:00
|
|
|
if (GVAR(level) == 2) then {
|
|
|
|
// Remove partial magazine supply count
|
|
|
|
private _rearmAmount = (REARM_COUNT select _idx);
|
|
|
|
if (_numRounds > 0) then {
|
|
|
|
_rearmAmount = _numRounds;
|
|
|
|
};
|
|
|
|
private _magazinePart = (_rearmAmount / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1;
|
|
|
|
if (_supply >= (_cal * _magazinePart)) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
[_truck, (_supply - (_cal * _magazinePart))] call FUNC(setSupplyCount);
|
2016-02-27 19:31:07 +00:00
|
|
|
_return = true;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Remove entire magazine supply count
|
|
|
|
if (_supply >= _cal) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
[_truck, (_supply - _cal)] call FUNC(setSupplyCount);
|
2016-02-27 19:31:07 +00:00
|
|
|
_return = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2017-06-08 16:47:52 +00:00
|
|
|
|
2016-02-27 19:31:07 +00:00
|
|
|
if (GVAR(supply) == 2) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
private _magazineSupply = _truck getVariable [QGVAR(magazineSupply), []];
|
2016-02-27 19:31:07 +00:00
|
|
|
private _magazineIdx = -1;
|
|
|
|
{
|
|
|
|
_x params ["_magazine"];
|
|
|
|
if ((_magazine isEqualTo _magazineClass)) exitWith {
|
|
|
|
_magazineIdx = _forEachIndex;
|
|
|
|
};
|
|
|
|
} forEach _magazineSupply;
|
|
|
|
if (_magazineIdx == -1) exitWith {false};
|
|
|
|
|
|
|
|
(_magazineSupply select _magazineIdx) params ["", "_rounds"];
|
|
|
|
|
|
|
|
private _configRounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
|
|
|
if (GVAR(level) == 2) then {
|
|
|
|
// With caliber based rearming, we need to remove the correct amount
|
|
|
|
private _rearmAmount = (REARM_COUNT select _idx);
|
|
|
|
if (_numRounds > 0) then {
|
|
|
|
if (_numRounds > _rearmAmount) then {
|
|
|
|
_rearmAmount = ceil (_numRounds / _rearmAmount);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
private _roundsPerTransaction = _rearmAmount min _configRounds;
|
|
|
|
if (_rounds >= _roundsPerTransaction) then {
|
|
|
|
_magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _roundsPerTransaction)]];
|
2016-02-27 20:05:19 +00:00
|
|
|
_truck setVariable [QGVAR(magazineSupply), _magazineSupply, true];
|
2016-02-27 19:31:07 +00:00
|
|
|
_return = true;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Remove entire magazine
|
|
|
|
if (_rounds >= _configRounds) then {
|
|
|
|
_magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _configRounds)]];
|
2016-02-27 20:05:19 +00:00
|
|
|
_truck setVariable [QGVAR(magazineSupply), _magazineSupply, true];
|
2016-02-27 19:31:07 +00:00
|
|
|
_return = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
_return
|