diff --git a/addons/gunbag/CfgEventHandlers.hpp b/addons/gunbag/CfgEventHandlers.hpp index b4342c6f0f..be284a9d70 100644 --- a/addons/gunbag/CfgEventHandlers.hpp +++ b/addons/gunbag/CfgEventHandlers.hpp @@ -1,12 +1,12 @@ class Extended_PreStart_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preStart)); - }; + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; }; class Extended_PreInit_EventHandlers { - class ADDON { - init = QUOTE( call COMPILE_FILE(XEH_preInit) ); - }; + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; }; diff --git a/addons/gunbag/CfgVehicles.hpp b/addons/gunbag/CfgVehicles.hpp index e3f9f4e2d6..7d23f16db1 100644 --- a/addons/gunbag/CfgVehicles.hpp +++ b/addons/gunbag/CfgVehicles.hpp @@ -21,7 +21,7 @@ class CfgVehicles { }; class GVAR(StatusGunbag) { displayName = CSTRING(Status); - condition = QUOTE([_target] call FUNC(isGunbag)); + condition = QUOTE([_target] call FUNC(hasGunbag)); statement = QUOTE([_target] call FUNC(status)); showDisabled = 0; priority = 2; @@ -34,7 +34,7 @@ class CfgVehicles { class ACE_Equipment { class GVAR(actions) { displayName = CSTRING(displayname); - condition = QUOTE([_player] call FUNC(isGunbag)); + condition = QUOTE([_player] call FUNC(hasGunbag)); showDisabled = 0; priority = 0.1; icon = PATHTOF(ui\gunbag_icon_ca.paa); @@ -57,7 +57,7 @@ class CfgVehicles { }; class GVAR(StatusGunbag) { displayName = CSTRING(Status); - condition = QUOTE([_player] call FUNC(isGunbag)); + condition = QUOTE([_player] call FUNC(hasGunbag)); statement = QUOTE([_player] call FUNC(status)); showDisabled = 0; priority = 2; @@ -84,6 +84,8 @@ class CfgVehicles { }; class DOUBLES(CLASSNAME,Tan): CLASSNAME { + _generalMacro = QUOTE(DOUBLES(CLASSNAME,Tan)); + author = "Ir0n1E"; displayName = CSTRING(Displayname_Tan); picture = PATHTOF(ui\gunbag_tan_ca.paa); hiddenSelectionsTextures[] = {PATHTOF(data\gunbag_tan_co.paa)}; diff --git a/addons/gunbag/XEH_PREP.hpp b/addons/gunbag/XEH_PREP.hpp index 920dd966fa..df84b594bf 100644 --- a/addons/gunbag/XEH_PREP.hpp +++ b/addons/gunbag/XEH_PREP.hpp @@ -1,6 +1,9 @@ + PREP(toGunbag); +PREP(toGunbagCallback); PREP(offGunbag); +PREP(offGunbagCallback); PREP(status); PREP(canInteract); PREP(calculateMass); -PREP(isGunbag); +PREP(hasGunbag); diff --git a/addons/gunbag/XEH_preInit.sqf b/addons/gunbag/XEH_preInit.sqf index a7feade1c3..73b1a7ea75 100644 --- a/addons/gunbag/XEH_preInit.sqf +++ b/addons/gunbag/XEH_preInit.sqf @@ -4,4 +4,22 @@ ADDON = false; #include "XEH_PREP.hpp" +// restore gunbag info after respawn +["CAManBase", "respawn", { + [{ + params ["_unit", "_corpse"]; + + private _newBackpack = backpackContainer _unit; + private _oldBackpack = backpackContainer _corpse; + + if !(typeOf _newBackpack isEqualTo typeOf _oldBackpack) exitWith {}; + + private _state = _oldBackpack getVariable [QGVAR(gunbagWeapon), []]; + + if !(_state isEqualTo []) then { + _newBackpack setVariable [QGVAR(gunbagWeapon), _state, true]; + }; + }, _this] call CBA_fnc_execNextFrame; +}] call CBA_fnc_addClassEventHandler; + ADDON = true; diff --git a/addons/gunbag/functions/fnc_calculateMass.sqf b/addons/gunbag/functions/fnc_calculateMass.sqf index 89ba84110c..47e8a9151d 100644 --- a/addons/gunbag/functions/fnc_calculateMass.sqf +++ b/addons/gunbag/functions/fnc_calculateMass.sqf @@ -5,16 +5,16 @@ * Arguments: * 0: Weapon * 1: Items + * 2: Magazines * * Return Value: * Mass * * Public: No */ - #include "script_component.hpp" -params ["_weapon","_items"]; +params ["_weapon", "_items", "_magazines"]; private _mass = getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlotsInfo" >> "mass"); @@ -22,4 +22,8 @@ private _mass = getNumber (configFile >> "CfgWeapons" >> _weapon >> "WeaponSlots _mass = _mass + getNumber (configFile >> "CfgWeapons" >> _x >> "ItemInfo" >> "mass"); } foreach _items; +{ + _mass = _mass + getNumber (configFile >> "CfgWeapons" >> _x >> "mass"); +} forEach _magazines; + _mass diff --git a/addons/gunbag/functions/fnc_canInteract.sqf b/addons/gunbag/functions/fnc_canInteract.sqf index b4746a7f9d..0d098b9f7e 100644 --- a/addons/gunbag/functions/fnc_canInteract.sqf +++ b/addons/gunbag/functions/fnc_canInteract.sqf @@ -11,21 +11,18 @@ * * Public: No */ - #include "script_component.hpp" -params ["_unit","_target"]; +params ["_unit", "_target"]; -private ["_result","_gunbag"]; +private _result = -1; +private _gunbag = backpackContainer _target; -_result = -1; -_gunbag = backpackContainer _target; - -if(count (_gunbag getVariable [QGVAR(GunbagWeapon),[]]) <= 0 && {primaryWeapon _unit != ""} && {getNumber (configFile >> "CfgWeapons" >> primaryWeapon _unit >> QGVAR(allowGunbag)) == 1}) then { +if ((_gunbag getVariable [QGVAR(gunbagWeapon), []]) isEqualTo [] && {primaryWeapon _unit != ""} && {getNumber (configFile >> "CfgWeapons" >> primaryWeapon _unit >> QGVAR(allowGunbag)) == 1}) then { _result = 0; }; -if(count (_gunbag getVariable [QGVAR(GunbagWeapon),[]]) >= 1 && {primaryWeapon _unit == ""}) then { +if (!((_gunbag getVariable [QGVAR(gunbagWeapon), []]) isEqualTo []) && {primaryWeapon _unit == ""}) then { _result = 1; }; diff --git a/addons/gunbag/functions/fnc_isGunbag.sqf b/addons/gunbag/functions/fnc_hasGunbag.sqf similarity index 99% rename from addons/gunbag/functions/fnc_isGunbag.sqf rename to addons/gunbag/functions/fnc_hasGunbag.sqf index 3594bf8618..f7cab0435d 100644 --- a/addons/gunbag/functions/fnc_isGunbag.sqf +++ b/addons/gunbag/functions/fnc_hasGunbag.sqf @@ -10,7 +10,6 @@ * * Public: No */ - #include "script_component.hpp" params ["_unit"]; diff --git a/addons/gunbag/functions/fnc_offGunbag.sqf b/addons/gunbag/functions/fnc_offGunbag.sqf index 07147b4829..d11043f065 100644 --- a/addons/gunbag/functions/fnc_offGunbag.sqf +++ b/addons/gunbag/functions/fnc_offGunbag.sqf @@ -11,35 +11,21 @@ * * Public: No */ - #include "script_component.hpp" -params ["_unit","_target"]; +params ["_unit", "_target"]; -private ["_weapon", "_items", "_gunbag", "_state"]; +private _gunbag = backpackContainer _target; -_gunbag = backpackContainer _target; -_state = _gunbag getVariable [QGVAR(GunbagWeapon),[]]; - -if (count _state <= 0) exitWith { - [localize LSTRING(empty)] call EFUNC(common,displayTextStructured); -}; - -_weapon = (_state select 0) select 0; -_items = (_state select 1); - -_unit addWeapon _weapon; -removeAllPrimaryWeaponItems _unit; - -{ - _unit addWeaponItem [_weapon, _x]; -} forEach _items; - -// remove virtual load -[_target, backpackContainer _target, -([_weapon, _items] call FUNC(calculateMass))] call EFUNC(movement,addLoadToUnitContainer); -_gunbag setVariable [QGVAR(GunbagWeapon), [], true]; +_unit call EFUNC(common,goKneeling); // play sound -if(["ACE_Backpacks"] call EFUNC(common,isModLoaded)) then { - [_unit, _target, backpackContainer _target] call EFUNC(backpacks,backpackOpened); +if (!isNil "ACE_Backpacks") then { + [_target, _gunbag] call EFUNC(backpacks,backpackOpened); }; + +[PROGRESSBAR_TIME, _this, { + (_this select 0) call FUNC(offGunbagCallback) +}, {}, localize LSTRING(offGunbag), { + (_this select 0) call FUNC(canInteract) == 1 +}] call EFUNC(common,progressBar); diff --git a/addons/gunbag/functions/fnc_offGunbagCallback.sqf b/addons/gunbag/functions/fnc_offGunbagCallback.sqf new file mode 100644 index 0000000000..2bee565bd1 --- /dev/null +++ b/addons/gunbag/functions/fnc_offGunbagCallback.sqf @@ -0,0 +1,48 @@ +/* + * Author: Ir0n1E + * get weapon out of gunbag + * + * Arguments: + * 0: Unit + * 1: Target + * + * Return Value: + * Nothing + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_target"]; + +private _gunbag = backpackContainer _target; + +private _state = _gunbag getVariable [QGVAR(gunbagWeapon), []]; + +if (_state isEqualTo []) exitWith { + [localize LSTRING(empty)] call EFUNC(common,displayTextStructured); +}; + +_state params ["_weapon", "_items", "_magazines"]; + +_unit addWeapon _weapon; +removeAllPrimaryWeaponItems _unit; + +{ + _unit addWeaponItem [_weapon, _x]; +} forEach (_items + _magazines); + +_unit selectWeapon _weapon; + +_magazines = _magazines apply {_x select 0}; + +private _mass = [_weapon, _items, _magazines] call FUNC(calculateMass); + +// remove virtual load +[_target, _gunbag, -_mass] call EFUNC(movement,addLoadToUnitContainer); +_gunbag setVariable [QGVAR(gunbagWeapon), [], true]; + +// play sound +if (!isNil "ACE_Backpacks") then { + [_target, _gunbag] call EFUNC(backpacks,backpackOpened); +}; diff --git a/addons/gunbag/functions/fnc_status.sqf b/addons/gunbag/functions/fnc_status.sqf index 060c244462..6b6196ba01 100644 --- a/addons/gunbag/functions/fnc_status.sqf +++ b/addons/gunbag/functions/fnc_status.sqf @@ -10,17 +10,19 @@ * * Public: No */ - #include "script_component.hpp" params ["_unit"]; -private _state = (backpackContainer _unit) getVariable [QGVAR(GunbagWeapon),[]]; +private _state = (backpackContainer _unit) getVariable [QGVAR(gunbagWeapon), []]; -if (count _state <= 0) then { +if (_state isEqualTo []) then { [localize LSTRING(empty)] call EFUNC(common,displayTextStructured); } else { - private _weapon = (_state select 0) select 0; - [getText (configFile >> "CfgWeapons" >> _weapon >> "displayname"), - getText (configFile >> "CfgWeapons" >> _weapon >> "picture")] call EFUNC(common,displayTextPicture); + _state params ["_weapon"]; + + [ + getText (configFile >> "CfgWeapons" >> _weapon >> "displayname"), + getText (configFile >> "CfgWeapons" >> _weapon >> "picture") + ] call EFUNC(common,displayTextPicture); }; diff --git a/addons/gunbag/functions/fnc_toGunbag.sqf b/addons/gunbag/functions/fnc_toGunbag.sqf index 8d89a67899..27ca4e2924 100644 --- a/addons/gunbag/functions/fnc_toGunbag.sqf +++ b/addons/gunbag/functions/fnc_toGunbag.sqf @@ -11,41 +11,21 @@ * * Public: No */ - #include "script_component.hpp" params ["_unit", "_target"]; -private ["_weapon", "_magazine", "_magazine_gl", "_items", "_gunbag", "_state", "_mass"]; +private _gunbag = backpackContainer _target; -_gunbag = backpackContainer _target; -_state = [_unit, primaryWeapon _unit] call EFUNC(common,getWeaponState); - -/* -* example returnvalue _state -* [["","","optic_Aco",""],["arifle_MX_GL_ACO_F","GL_3GL_F"],["30Rnd_65x39_caseless_mag","1Rnd_HE_Grenade_shell"],[30,1]] -*/ - -_weapon = (_state select 1) select 0; -_magazine = [(_state select 2) select 0, (_state select 3) select 0]; -_magazine_gl = [(_state select 2) select 1, (_state select 3) select 1]; -_items = _state select 0; - -if ((_magazine_gl select 0) != "") then { - _unit addMagazine _magazine_gl; -}; - -if ((_magazine select 0) != "") then { - _unit addMagazine _magazine; -}; - -_unit removeWeapon _weapon; - -// add virtual load -[_target, backpackContainer _target, [_weapon, _items] call FUNC(calculateMass)] call EFUNC(movement,addLoadToUnitContainer); -_gunbag setVariable [QGVAR(GunbagWeapon), [[_weapon], _items], true]; +_unit call EFUNC(common,goKneeling); // play sound -if(["ACE_Backpacks"] call EFUNC(common,isModLoaded)) then { - [_unit, _target, backpackContainer _target] call EFUNC(backpacks,backpackOpened); +if (!isNil "ACE_Backpacks") then { + [_target, _gunbag] call EFUNC(backpacks,backpackOpened); }; + +[PROGRESSBAR_TIME, _this, { + (_this select 0) call FUNC(toGunbagCallback) +}, {}, localize LSTRING(toGunbag), { + (_this select 0) call FUNC(canInteract) == 0 +}] call EFUNC(common,progressBar); diff --git a/addons/gunbag/functions/fnc_toGunbagCallback.sqf b/addons/gunbag/functions/fnc_toGunbagCallback.sqf new file mode 100644 index 0000000000..c02d29e0e3 --- /dev/null +++ b/addons/gunbag/functions/fnc_toGunbagCallback.sqf @@ -0,0 +1,45 @@ +/* + * Author: Ir0n1E + * put weapon into gunbag + * + * Arguments: + * 0: Unit + * 1: Target + * + * Return Value: + * Nothing + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit", "_target"]; + +private _weapon = primaryWeapon _unit; +private _gunbag = backpackContainer _target; + +private _state = [_unit, _weapon] call EFUNC(common,getWeaponState); + +/* + * example return value _state + * [["","","optic_Aco",""],["arifle_MX_GL_ACO_F","GL_3GL_F"],["30Rnd_65x39_caseless_mag","1Rnd_HE_Grenade_shell"],[30,1]] + */ + +_state params ["_items", "", "_magazines", "_ammo"]; + +private _mass = [_weapon, _items, _magazines] call FUNC(calculateMass); + +{ + _magazines set [_forEachIndex, [_x, _ammo select _forEachIndex]]; +} forEach _magazines; + +_unit removeWeapon _weapon; + +// add virtual load +[_target, _gunbag, _mass] call EFUNC(movement,addLoadToUnitContainer); +_gunbag setVariable [QGVAR(gunbagWeapon), [_weapon, _items, _magazines], true]; + +// play sound +if (!isNil "ACE_Backpacks") then { + [_target, _gunbag] call EFUNC(backpacks,backpackOpened); +}; diff --git a/addons/gunbag/script_component.hpp b/addons/gunbag/script_component.hpp index eba4bf473e..2bfb3235a8 100644 --- a/addons/gunbag/script_component.hpp +++ b/addons/gunbag/script_component.hpp @@ -1,11 +1,10 @@ #define COMPONENT gunbag #include "\z\ace\addons\main\script_mod.hpp" -#define CLASSNAME ACE_Gunbag -#define DEBUG_MODE_FULL -#define DISABLE_COMPILE_CACHE -#define CBA_DEBUG_SYNCHRONOUS -#define ENABLE_PERFORMANCE_COUNTERS +//#define DEBUG_ENABLED_GUNBAG +//#define DISABLE_COMPILE_CACHE +//#define CBA_DEBUG_SYNCHRONOUS +//#define ENABLE_PERFORMANCE_COUNTERS #ifdef DEBUG_ENABLED_GUNBAG #define DEBUG_MODE_FULL @@ -16,3 +15,6 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define CLASSNAME ACE_Gunbag +#define PROGRESSBAR_TIME 5 diff --git a/addons/gunbag/stringtable.xml b/addons/gunbag/stringtable.xml index 83d995977a..d779918988 100644 --- a/addons/gunbag/stringtable.xml +++ b/addons/gunbag/stringtable.xml @@ -26,4 +26,4 @@ Waffentasche leer - \ No newline at end of file + diff --git a/addons/gunbag/Source/gunbag_ca.png b/extras/assets/gunbag/gunbag_ca.png similarity index 100% rename from addons/gunbag/Source/gunbag_ca.png rename to extras/assets/gunbag/gunbag_ca.png diff --git a/addons/gunbag/Source/gunbag_co.png b/extras/assets/gunbag/gunbag_co.png similarity index 100% rename from addons/gunbag/Source/gunbag_co.png rename to extras/assets/gunbag/gunbag_co.png diff --git a/addons/gunbag/Source/gunbag_nohq.png b/extras/assets/gunbag/gunbag_nohq.png similarity index 100% rename from addons/gunbag/Source/gunbag_nohq.png rename to extras/assets/gunbag/gunbag_nohq.png diff --git a/addons/gunbag/Source/gunbag_tan_ca.png b/extras/assets/gunbag/gunbag_tan_ca.png similarity index 100% rename from addons/gunbag/Source/gunbag_tan_ca.png rename to extras/assets/gunbag/gunbag_tan_ca.png diff --git a/addons/gunbag/Source/gunbag_tan_co.png b/extras/assets/gunbag/gunbag_tan_co.png similarity index 100% rename from addons/gunbag/Source/gunbag_tan_co.png rename to extras/assets/gunbag/gunbag_tan_co.png