ACE3/addons/magazinerepack/functions/fnc_simulateRepackEvents.sqf

68 lines
2.0 KiB
Plaintext
Raw Normal View History

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>
*
* Return Value:
* Array in format [time, isBullet, array of ammo counts] <ARRAY>
*
* Example:
* [5, [1,2,3,8]] call ace_magazinerepack_fnc_simulateRepackEvents =
* [[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
*/
#include "script_component.hpp"
2015-02-08 22:36:58 +00:00
private ["_newMagFnc", "_time", "_events", "_swapAmmoFnc", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
2015-02-08 22:36:58 +00:00
PARAMS_2(_fullMagazineCount,_arrayOfAmmoCounts);
2015-02-08 22:36:58 +00:00
// Sort Ascending - Don't modify original
_arrayOfAmmoCounts = (+_arrayOfAmmoCounts) call BIS_fnc_sortNum;
2015-02-08 22:36:58 +00:00
_newMagFnc = {
_time = _time + GVAR(TimePerMagazine);
2015-02-08 22:36:58 +00:00
_events pushBack [_time, false, +_arrayOfAmmoCounts];
};
2015-02-08 22:36:58 +00:00
_swapAmmoFnc = {
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)];
2015-02-08 22:36:58 +00:00
_events pushBack [_time, true, +_arrayOfAmmoCounts];
};
};
_lowIndex = 0;
_highIndex = (count _arrayOfAmmoCounts) - 1;
_ammoToTransfer = 0;
_ammoAvailable = 0;
_time = 0;
_events = [];
while {_lowIndex < _highIndex} do {
_ammoNeeded = _fullMagazineCount - (_arrayOfAmmoCounts select _highIndex);
_ammoAvailable = _arrayOfAmmoCounts select _lowIndex;
if (_ammoAvailable == 0) then {
_lowIndex = _lowIndex + 1;
2015-02-08 22:36:58 +00:00
call _newMagFnc;
} else {
if (_ammoNeeded == 0) then {
_highIndex = _highIndex - 1;
2015-02-08 22:36:58 +00:00
call _newMagFnc;
} else {
_ammoSwaped = _ammoAvailable min _ammoNeeded;
2015-02-08 22:36:58 +00:00
call _swapAmmoFnc;
};
};
};
_events