This commit is contained in:
PabstMirror 2015-02-08 16:36:58 -06:00
parent 3f6ffa6ac2
commit e770a74630
4 changed files with 106 additions and 50 deletions

View File

@ -1,17 +1,31 @@
// by commy2, esteldunedain
/*
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
* Handles each frame durring the repack progressBar.
* On each event (repacked bullet or move to new mag) it plays a sound and syncs up the new magazines to the player.
*
* Arguments:
* 0: Arguments [classname,lastAmmoStatus,events] <ARRAY>
* 1: Elapsed Time <NUMBER>
* 2: Total Time Repacking Will Take <NUMBER>
*
* Return Value:
* Keep going (on missing mags return false) <BOOL>
*
* Example:
* (args from progressBar) call ace_magazinerepack_fnc_magazineRepackProgress
*
* Public: No
*/
#include "script_component.hpp"
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,_nextEventType,_nextEventMags);
EXPLODE_3_PVT((_simEvents select 0),_nextEventTime,_nextEventIsBullet,_nextEventMags);
if (_nextEventTime > _elapsedTime) exitWith {true};//waiting on next event
systemChat format ["Event %1-%2-%3", _nextEventTime,_nextEventType,_nextEventMags];
//Verify we aren't missing any ammo
_currentAmmoCount = [];
@ -40,29 +54,24 @@ if ((count _addedMagazines) > 0) then {
TRACE_1("Added Magazine While Repacking",_addedMagazines);
};
_updateMagazinesOnPlayer = {
systemChat format ["Updating mags"];
_newMagazineList = _addedMagazines + _nextEventMags;
ACE_player removeMagazines _magazineClassname;
_updateMagazinesOnPlayerFnc = {
ACE_player removeMagazines _magazineClassname; //remove inventory magazines
{
if (_x > 0) then {
ACE_player addMagazine [_magazineClassname, _x];
};
} forEach _newMagazineList;
_args set [1, _nextEventMags];
} forEach (_addedMagazines + _nextEventMags);
_args set [1, _nextEventMags]; //store the new magazine
};
if (_nextEventType == 0) then {
systemChat "reloading bullet";
if (_nextEventIsBullet) then {
playSound QGVAR(soundMagazineFinished);
if (((count _simEvents) % 3) == 0) then {
call _updateMagazinesOnPlayer;
if ((((count _simEvents) % 3) == 0) || {(count _simEvents) == 1}) then {
call _updateMagazinesOnPlayerFnc;
};
} else {
systemChat "Moving to next mag";
playSound QGVAR(soundRoundFinished);
call _updateMagazinesOnPlayer;
call _updateMagazinesOnPlayerFnc;
};
_simEvents deleteAt 0; //pop off the event

View File

@ -1,7 +1,22 @@
// by commy2, esteldunedain
/*
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
* Opens the selectMenu UI to chose which magazine to repack.
* Only shows classnames that have 2+ partial magazines
*
* Arguments:
* 0: Unit (player) <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [_player] call ace_magazinerepack_fnc_openSelectMagazineUI
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_magazines", "_ammos", "_repackTime", "_magazine", "_ammo", "_count", "_index", "_i", "_j", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
private ["_unitMagazines", "_unitMagCounts", "_xFullMagazineCount", "_index", "_actions", "_displayName", "_picture"];
PARAMS_1(_unit);
@ -10,11 +25,10 @@ _unitMagCounts = [];
// get all mags and ammo count
{
_xClassname = _x select 0;
_xCount = _x select 1;
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
EXPLODE_2_PVT(_x,_xClassname,_xCount);
_xFullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _xClassname >> "count");
if ((_xCount != _fullMagazineCount) && {_xCount > 1}) then {//for every partial magazine
if ((_xCount != _xFullMagazineCount) && {_xCount > 0}) then {//for every partial magazine
_index = _unitMagazines find _xClassname;
if (_index == -1) then {
_unitMagazines pushBack _xClassname;
@ -27,8 +41,6 @@ _unitMagCounts = [];
_actions = [localize "STR_ACE_MagazineRepack_SelectMagazineMenu", localize "STR_ACE_MagazineRepack_SelectMagazine"] call EFUNC(interaction,prepareSelectMenu);
systemChat format ["%1 - %2", _unitMagazines, _unitMagCounts];
{
if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything)
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName");
@ -39,7 +51,7 @@ systemChat format ["%1 - %2", _unitMagazines, _unitMagCounts];
[
_actions,
{ [ACE_player, _this] call FUNC(startRepackingMagazine); },
{ [_this] call FUNC(startRepackingMagazine); },
{
call EFUNC(interaction,hideMenu);
if !(profileNamespace getVariable [QGVAR(AutoCloseMenu), false]) then {"Default" call EFUNC(interaction,openMenuSelf)};

View File

@ -1,25 +1,40 @@
/*
* 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"
private ["_fullMagazineCount", "_magazines", "_newMag", "_time", "_events", "_swapAmmo", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
private ["_newMagFnc", "_time", "_events", "_swapAmmoFnc", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
PARAMS_2(_magazineClassname,_arrayOfAmmoCounts);
PARAMS_2(_fullMagazineCount,_arrayOfAmmoCounts);
// Calculate actual ammo to transfer during repack
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _magazineClassname >> "count");
// Sort Ascending - Don't modify orginal
// Sort Ascending - Don't modify original
_arrayOfAmmoCounts = (+_arrayOfAmmoCounts) call BIS_fnc_sortNum;
_newMag = {
_newMagFnc = {
_time = _time + GVAR(TimePerMagazine);
_events pushBack [_time, 1, +_arrayOfAmmoCounts];
_events pushBack [_time, false, +_arrayOfAmmoCounts];
};
_swapAmmo = {
for "_swapProgress" from 1 to _ammoSwaped do {
_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)];
_events pushBack [_time, 0, +_arrayOfAmmoCounts];
_events pushBack [_time, true, +_arrayOfAmmoCounts];
};
};
@ -37,14 +52,14 @@ while {_lowIndex < _highIndex} do {
if (_ammoAvailable == 0) then {
_lowIndex = _lowIndex + 1;
call _newMag;
call _newMagFnc;
} else {
if (_ammoNeeded == 0) then {
_highIndex = _highIndex - 1;
call _newMag;
call _newMagFnc;
} else {
_ammoSwaped = _ammoAvailable min _ammoNeeded;
call _swapAmmo;
call _swapAmmoFnc;
};
};
};

View File

@ -1,18 +1,38 @@
// by commy2, esteldunedain
/*
* Author: PabstMirror (based on repack from commy2, esteldunedain, Ruthberg)
* Starts repacking a specific magazine classname.
* Precalcs all the event timings and starts the progressBar.
*
* Arguments:
* 0: Magazine Classname <STRING>
*
* Return Value:
* Nothing
*
* Example:
* ["30Rnd_65x39_caseless_mag"] call ace_magazinerepack_fnc_startRepackingMagazine
*
* Public: No
*/
#include "script_component.hpp"
private ["_unit", "_magazines", "_ammos", "_repackTime", "_magazine", "_ammo", "_count", "_index", "_i", "_j", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded"];
private ["_unit", "_fullMagazineCount", "_startingAmmoCounts", "_simEvents", "_totalTime"];
PARAMS_2(_unit,_magazineClassname);
PARAMS_1(_magazineClassname);
if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");};
[_unit] call EFUNC(common,goKneeling);
_unit = ACE_player;
[ACE_player] call EFUNC(common,goKneeling);
call EFUNC(interaction,hideMenu);
// Calculate actual ammo to transfer during repack
_fullMagazineCount = getNumber (configfile >> "CfgMagazines" >> _magazineClassname >> "count");
_startingAmmoCounts = [];
{
EXPLODE_4_PVT(_x,_xClassname,_xCount,_xLoaded,_xType);
if (_xClassname == _magazineClassname) then {
if ((_xClassname == _magazineClassname) && {(_xCount != _fullMagazineCount) && {_xCount > 0}}) then {
if (_xLoaded) then {
//Try to Remove from weapon and add to inventory, otherwise ignore
if (_unit canAdd _magazineClassname) then {
@ -31,9 +51,9 @@ _startingAmmoCounts = [];
};
} forEach (magazinesAmmoFull _unit);
if ((count _startingAmmoCounts) == 0) exitwith {ERROR("No Mags");};
if ((count _startingAmmoCounts) < 2) exitwith {ERROR("Not Enough Mags to Repack");};
_simEvents = [_magazineClassname, _startingAmmoCounts] call FUNC(simulateRepackEvents);
_simEvents = [_fullMagazineCount, _startingAmmoCounts] call FUNC(simulateRepackEvents);
_totalTime = (_simEvents select ((count _simEvents) - 1) select 0);
[_totalTime, [_magazineClassname, _startingAmmoCounts, _simEvents], {hint "done"}, {hint "fail"}, (localize "STR_ACE_MagazineRepack_RepackingMagazine"), {_this call FUNC(magazineRepackProgress)}] call EFUNC(common,progressBar);