Keep empty magazines when reloading

This commit is contained in:
BaerMitUmlaut 2016-08-09 20:36:21 +02:00
parent 02794a972b
commit 3e1e4fca27
5 changed files with 81 additions and 6 deletions

View File

@ -13,14 +13,12 @@ class Extended_PreInit_EventHandlers {
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE( call COMPILE_FILE(XEH_postInit) );
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_Take_EventHandlers {
class Extended_Reloaded_EventHandlers {
class CAManBase {
class ACE_AmmoIndicatorReload {
clientTake = QUOTE(if (_this select 0 == ACE_player && {GVAR(DisplayText)} && {(_this select 1) in [ARR_3(uniformContainer (_this select 0), vestContainer (_this select 0), backpackContainer (_this select 0))]} && {_this select 2 == currentMagazine (_this select 0)}) then {[ARR_2(_this select 0, vehicle (_this select 0))] call FUNC(displayAmmo)};);
};
ADDON = QUOTE(call FUNC(onReload));
};
};

View File

@ -1,6 +1,7 @@
PREP(canCheckAmmo);
PREP(canLinkBelt);
PREP(checkAmmo);
PREP(displayAmmo);
PREP(onInventoryChanged);
PREP(onReload);
PREP(startLinkingBelt);

View File

@ -59,3 +59,5 @@ if (!hasInterface) exitWith {};
_receiver addMagazine _magazine;
}] call CBA_fnc_addEventHandler;
["loadout", {call FUNC(onInventoryChanged)}] call CBA_fnc_addPlayerEventHandler;

View File

@ -0,0 +1,47 @@
/*
* Author: BaerMitUmlaut
* Handles unit weight coefficient for empty magazines.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Previous loadout <ARRAY>
*
* Return Value:
* None
*/
#include "script_component.hpp"
params ["_unit", "_previousLoadout"];
private _loadout = getUnitLoadout _unit;
_loadout params ["", "", "", "_uniformInventory", "_vestInventory", "_backpackInventory"];
private _prevEmptyMagsWeight = _unit getVariable [QGVAR(emptyMagazinesWeight), 0];
private _emptyMagsWeight = 0;
if (isNil QGVAR(magWeightCache)) then {
GVAR(magWeightCache) = [] call CBA_fnc_createNamespace;
};
{
if !(_x isEqualTo []) then {
private _mags = _x select 1;
{
_x params ["_classname", "_ammoCount", "_magCount"];
if (_ammoCount == 0) then {
private _weight = GVAR(magWeightCache) getVariable _classname;
if (isNil "_weight") then {
_weight = getNumber (configFile >> "CfgMagazines" >> _classname >> "mass");
GVAR(magWeightCache) setVariable [_classname, _weight];
systemChat "nocache";
};
_emptyMagsWeight = _emptyMagsWeight + _weight * _magCount;
};
} forEach _mags;
};
} forEach [_uniformInventory, _vestInventory, _backpackInventory];
if (_emptyMagsWeight != _prevEmptyMagsWeight) then {
_unit setVariable [QGVAR(emptyMagazinesWeight), _emptyMagsWeight];
[_unit, _unit, -0.8 * (_emptyMagsWeight - _prevEmptyMagsWeight)] call EFUNC(movement,addLoadToUnitContainer);
};

View File

@ -0,0 +1,27 @@
/*
* Author: BaerMitUmlaut
* Handles the ammo display on reload and and adds empty magazines.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
* 2: Muzzle <STRING>
* 3: New magazine info <ARRAY>
* 4: Old magazine info <ARRAY>
*
* Return Value:
* None
*/
#include "script_component.hpp"
params ["_unit", "_weapon", "_muzzle", "_newMagInfo", ["_oldMagInfo", ["", -1]]];
_oldMagInfo params ["_oldMagClassname", "_oldMagAmmo"];
if (_unit == ACE_player) then {
if (GVAR(DisplayText)) then {
[_unit] call FUNC(displayAmmo);
};
if (_oldMagAmmo == 0 && {_unit canAdd _oldMagClassname} && {_weapon != secondaryWeapon _unit}) then {
_unit addMagazine [_oldMagClassname, 0];
};
};