Code Cleanup Magazine Repack Module.

This commit is contained in:
jokoho48 2015-08-16 00:30:24 +02:00
parent 508c6de2cb
commit 4478be096e
5 changed files with 35 additions and 30 deletions

View File

@ -7,7 +7,7 @@
* 1: Player <OBJECT>
*
* Return value:
* ChildActiosn<ARRAY>
* ChildActions <ARRAY>
*
* Example:
* [player, player] call ace_magazinerepack_fnc_getMagazineChildren
@ -16,15 +16,17 @@
*/
#include "script_component.hpp"
private ["_unitMagazines", "_unitMagCounts", "_xFullMagazineCount", "_index", "_actions", "_displayName", "_picture", "_action"];
private ["_unitMagazines", "_unitMagCounts", "_index", "_actions", "_displayName", "_picture", "_action"];
PARAMS_2(_target,_player);
params ["_target", "_player"];
// get all mags and ammo count
_unitMagazines = [];
_unitMagCounts = [];
{
EXPLODE_4_PVT(_x,_xClassname,_xCount,_xLoaded,_xType);
private "_xFullMagazineCount";
_x params ["_xClassname", "_xCount", "_xLoaded", "_xType"];
_xFullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
//for every partial magazine, that is either in inventory or can be moved there

View File

@ -10,7 +10,7 @@
* 3: Error Code <NUMBER>
*
* Return Value:
* Nothing
* None
*
* Example:
* (args from progressBar) call ace_magazinerepack_fnc_magazineRepackFinish
@ -21,8 +21,9 @@
private ["_structuredOutputText", "_picture", "_fullMags", "_partialMags", "_fullMagazineCount"];
PARAMS_4(_args,_elapsedTime,_totalTime,_errorCode);
EXPLODE_2_PVT(_args,_magazineClassname,_lastAmmoCount);
params ["_args", "_elapsedTime", "_totalTime", "_errorCode"];
_args params ["_magazineClassname", "_lastAmmoCount"];
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _magazineClassname >> "count");
//Don't show anything if player can't interact:

View File

@ -20,17 +20,19 @@
private ["_currentAmmoCount", "_addedMagazines", "_missingAmmo", "_index", "_updateMagazinesOnPlayerFnc"];
PARAMS_3(_args,_elapsedTime,_totalTime);
EXPLODE_3_PVT(_args,_magazineClassname,_lastAmmoCount,_simEvents);
if ((count _simEvents) == 0) exitWith {ERROR("No Event"); false};
EXPLODE_3_PVT((_simEvents select 0),_nextEventTime,_nextEventIsBullet,_nextEventMags);
params ["_ars", "_elapsedTime", "_totalTime"];
_args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"];
if (_nextEventTime > _elapsedTime) exitWith {true};//waiting on next event
if !((_simEvents select 0) params ["_nextEventTime", "_nextEventIsBullet", "_nextEventMags"]) exitWith { ERROR("No Event"); false };
if (_nextEventTime > _elapsedTime) exitWith { true };//waiting on next event
//Verify we aren't missing any ammo
_currentAmmoCount = [];
{
EXPLODE_2_PVT(_x,_xClassname,_xCount);
_x params ["_xClassname", "_xCount"];
if (_xClassname == _magazineClassname) then {
_currentAmmoCount pushBack _xCount;
};
@ -50,7 +52,7 @@ _missingAmmo = false;
};
} forEach _lastAmmoCount;
if (_missingAmmo) exitWith {false}; //something removed ammo that was being repacked (could be other players or scripts)
if (_missingAmmo) exitWith { false }; //something removed ammo that was being repacked (could be other players or scripts)
_updateMagazinesOnPlayerFnc = {
ACE_player removeMagazines _magazineClassname; //remove inventory magazines
@ -75,4 +77,4 @@ if (_nextEventIsBullet) then {
_simEvents deleteAt 0; //pop off the event
true;
true

View File

@ -19,20 +19,20 @@
*/
#include "script_component.hpp"
private ["_newMagFnc", "_time", "_events", "_swapAmmoFnc", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded", "_swapProgress"];
private ["_fnc_newMag", "_time", "_events", "_fnc_swapAmmo", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded", "_swapProgress"];
PARAMS_3(_fullMagazineCount,_arrayOfAmmoCounts,_isBelt);
params ["_fullMagazineCount", "_arrayOfAmmoCounts", "_isBelt"];
// Sort Ascending - Don't modify original
_arrayOfAmmoCounts = +_arrayOfAmmoCounts;
_arrayOfAmmoCounts sort true;
_newMagFnc = {
_fnc_newMag = {
_time = _time + GVAR(TimePerMagazine);
_events pushBack [_time, false, +_arrayOfAmmoCounts];
};
_swapAmmoFnc = if (_isBelt) then {
_fnc_swapAmmo = if (_isBelt) then {
{
_time = _time + GVAR(TimePerBeltLink);
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - _ammoSwaped)];
@ -64,14 +64,14 @@ while {_lowIndex < _highIndex} do {
if (_ammoAvailable == 0) then {
_lowIndex = _lowIndex + 1;
call _newMagFnc;
call _fnc_newMag;
} else {
if (_ammoNeeded == 0) then {
_highIndex = _highIndex - 1;
call _newMagFnc;
call _fnc_newMag;
} else {
_ammoSwaped = _ammoAvailable min _ammoNeeded;
call _swapAmmoFnc;
call _fnc_swapAmmo;
};
};
};

View File

@ -21,7 +21,7 @@
private ["_magazineCfg", "_fullMagazineCount", "_isBelt", "_startingAmmoCounts", "_simEvents", "_totalTime"];
PARAMS_3(_target,_player,_magazineClassname);
params ["_target", "_player", "_magazineClassname"];
if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");};
_magazineCfg = configfile >> "CfgMagazines" >> _magazineClassname;
@ -63,11 +63,11 @@ _simEvents = [_fullMagazineCount, _startingAmmoCounts, _isBelt] call FUNC(simula
_totalTime = (_simEvents select ((count _simEvents) - 1) select 0);
[
_totalTime,
[_magazineClassname, _startingAmmoCounts, _simEvents],
{_this call FUNC(magazineRepackFinish)},
{_this call FUNC(magazineRepackFinish)},
(localize LSTRING(RepackingMagazine)),
{_this call FUNC(magazineRepackProgress)},
["isNotInside", "isNotSitting"]
_totalTime,
[_magazineClassname, _startingAmmoCounts, _simEvents],
{_this call FUNC(magazineRepackFinish)},
{_this call FUNC(magazineRepackFinish)},
(localize LSTRING(RepackingMagazine)),
{_this call FUNC(magazineRepackProgress)},
["isNotInside", "isNotSitting"]
] call EFUNC(common,progressBar);