2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-02-08 22:36:58 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
|
|
|
* Simulates repacking a set of magazines.
|
|
|
|
* Returns the timing and magazines counts at every stage.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: How many rounds in a full magazine <NUMBER>
|
|
|
|
* 1: Array of rounds in magazines <ARRAY>
|
2015-04-02 04:05:41 +00:00
|
|
|
* 2: Magazine is a belt <BOOL>
|
2015-02-08 22:36:58 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-10-21 20:52:21 +00:00
|
|
|
* Array in format [time, isBullet, array of ammo counts] <ARRAY>
|
2015-02-08 22:36:58 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-04-01 16:21:30 +00:00
|
|
|
* [10, [1,2,3,8], false] call ace_magazinerepack_fnc_simulateRepackEvents =
|
2015-02-08 22:36:58 +00:00
|
|
|
* [[1.5,true,[0,2,3,9]],[3.5,false,[0,2,3,9]],[5,true,[0,1,3,10]],[7,false,[0,1,3,10]],[8.5,true,[0,0,4,10]],[10.5,false,[0,0,4,10]]]
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-08-15 22:30:24 +00:00
|
|
|
params ["_fullMagazineCount", "_arrayOfAmmoCounts", "_isBelt"];
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2015-02-08 22:36:58 +00:00
|
|
|
// Sort Ascending - Don't modify original
|
2015-05-06 01:35:08 +00:00
|
|
|
_arrayOfAmmoCounts = +_arrayOfAmmoCounts;
|
|
|
|
_arrayOfAmmoCounts sort true;
|
2015-02-08 19:48:53 +00:00
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
private _fnc_newMag = {
|
2017-05-31 21:09:36 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_time", "_events"];
|
2015-02-08 19:48:53 +00:00
|
|
|
_time = _time + GVAR(TimePerMagazine);
|
2015-02-08 22:36:58 +00:00
|
|
|
_events pushBack [_time, false, +_arrayOfAmmoCounts];
|
2015-02-08 19:48:53 +00:00
|
|
|
};
|
2015-04-01 16:21:30 +00:00
|
|
|
|
2016-06-04 18:40:55 +00:00
|
|
|
private _lowIndex = 0;
|
|
|
|
private _highIndex = (count _arrayOfAmmoCounts) - 1;
|
|
|
|
private _ammoToTransfer = 0;
|
|
|
|
private _ammoAvailable = 0;
|
|
|
|
private _time = 0;
|
|
|
|
private _events = [];
|
2015-02-08 19:48:53 +00:00
|
|
|
|
|
|
|
while {_lowIndex < _highIndex} do {
|
2016-06-04 18:40:55 +00:00
|
|
|
private _ammoNeeded = _fullMagazineCount - (_arrayOfAmmoCounts select _highIndex);
|
2015-02-08 19:48:53 +00:00
|
|
|
_ammoAvailable = _arrayOfAmmoCounts select _lowIndex;
|
|
|
|
|
|
|
|
if (_ammoAvailable == 0) then {
|
|
|
|
_lowIndex = _lowIndex + 1;
|
2015-08-15 22:30:24 +00:00
|
|
|
call _fnc_newMag;
|
2015-02-08 19:48:53 +00:00
|
|
|
} else {
|
|
|
|
if (_ammoNeeded == 0) then {
|
|
|
|
_highIndex = _highIndex - 1;
|
2015-08-15 22:30:24 +00:00
|
|
|
call _fnc_newMag;
|
2015-02-08 19:48:53 +00:00
|
|
|
} else {
|
2016-06-04 18:40:55 +00:00
|
|
|
private _ammoSwaped = _ammoAvailable min _ammoNeeded;
|
|
|
|
if (_isBelt) then {
|
|
|
|
_time = _time + GVAR(TimePerBeltLink);
|
|
|
|
_arrayOfAmmoCounts set [_lowIndex, (_arrayOfAmmoCounts select _lowIndex) - _ammoSwaped];
|
|
|
|
_arrayOfAmmoCounts set [_highIndex, (_arrayOfAmmoCounts select _highIndex) + _ammoSwaped];
|
|
|
|
_events pushBack [_time, true, +_arrayOfAmmoCounts];
|
|
|
|
} else {
|
|
|
|
for "_swapProgress" from 0 to (_ammoSwaped - 1) do {
|
|
|
|
_time = _time + GVAR(TimePerAmmo);
|
|
|
|
_arrayOfAmmoCounts set [_lowIndex, (_arrayOfAmmoCounts select _lowIndex) - 1];
|
|
|
|
_arrayOfAmmoCounts set [_highIndex, (_arrayOfAmmoCounts select _highIndex) + 1];
|
|
|
|
_events pushBack [_time, true, +_arrayOfAmmoCounts];
|
|
|
|
};
|
|
|
|
};
|
2015-02-08 19:48:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_events
|