diff --git a/addons/mk6mortar/CfgEventHandlers.hpp b/addons/mk6mortar/CfgEventHandlers.hpp index a4aee88a22..1e5de1815e 100644 --- a/addons/mk6mortar/CfgEventHandlers.hpp +++ b/addons/mk6mortar/CfgEventHandlers.hpp @@ -5,7 +5,7 @@ class Extended_PreInit_EventHandlers { }; class Extended_PostInit_EventHandlers { class ADDON { - clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit)); + init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; class Extended_FiredBIS_EventHandlers { @@ -15,3 +15,10 @@ class Extended_FiredBIS_EventHandlers { }; }; }; +class Extended_InitPost_EventHandlers { + class Mortar_01_base_F { + class ADDON { + init = QUOTE(_this call COMPILE_FILE(XEH_initPost)); + }; + }; +}; diff --git a/addons/mk6mortar/CfgWeapons.hpp b/addons/mk6mortar/CfgWeapons.hpp index f535840e99..448bb55271 100644 --- a/addons/mk6mortar/CfgWeapons.hpp +++ b/addons/mk6mortar/CfgWeapons.hpp @@ -16,6 +16,7 @@ class CfgWeapons { class CannonCore; class mortar_82mm: CannonCore { class Single1; + GVAR(replaceWith) = "ACE_mortar_82mm"; }; class ACE_mortar_82mm: mortar_82mm { author = ECSTRING(common,ACETeam); diff --git a/addons/mk6mortar/XEH_initPost.sqf b/addons/mk6mortar/XEH_initPost.sqf new file mode 100644 index 0000000000..4f6fd7b44d --- /dev/null +++ b/addons/mk6mortar/XEH_initPost.sqf @@ -0,0 +1,5 @@ +#include "script_component.hpp" + +// if (GVAR(useAmmoHandling)) then { + _this call FUNC(mortarInit); +// }; diff --git a/addons/mk6mortar/XEH_clientInit.sqf b/addons/mk6mortar/XEH_postInit.sqf similarity index 99% rename from addons/mk6mortar/XEH_clientInit.sqf rename to addons/mk6mortar/XEH_postInit.sqf index 3937e11f0e..5c82d55f50 100644 --- a/addons/mk6mortar/XEH_clientInit.sqf +++ b/addons/mk6mortar/XEH_postInit.sqf @@ -1,27 +1,21 @@ #include "script_component.hpp" +[QGVAR(addMagazine), { + params ["_static", "_magazine"]; + _static addMagazineTurret [_magazine,[0]]; +}] call EFUNC(common,addEventHandler); + +[QGVAR(removeMagazine), { + params ["_static", "_magazine"]; + _static removeMagazineTurret [_magazine,[0]]; +}] call EFUNC(common,addEventHandler); + +[QGVAR(setAmmo), { + params ["_static", "_magazine","_ammoCount"]; + _static setMagazineTurretAmmo [_magazine, _ammoCount, [0]]; +}] call EFUNC(common,addEventHandler); + if (!hasInterface) exitWith {}; ["playerVehicleChanged", {_this call FUNC(handlePlayerVehicleChanged);}] call EFUNC(common,addEventHandler); ["infoDisplayChanged", {_this call FUNC(turretDisplayLoaded);}] call EFUNC(common,addEventHandler); - -[QGVAR(addMagazine), { - params ["_static", "_magazine"]; - - _static addMagazineTurret [_magazine,[0]]; - -}] call EFUNC(common,addEventHandler); - -[QGVAR(removeMagazine), { - params ["_static", "_magazine"]; - - _static removeMagazineTurret [_magazine,[0]]; - -}] call EFUNC(common,addEventHandler); - -[QGVAR(setAmmo), { - params ["_static", "_magazine","_ammoCount"]; - - _static setMagazineTurretAmmo [_magazine, _ammoCount, [0]]; - -}] call EFUNC(common,addEventHandler); diff --git a/addons/mk6mortar/XEH_preInit.sqf b/addons/mk6mortar/XEH_preInit.sqf index 3ec031b751..057618cd7a 100644 --- a/addons/mk6mortar/XEH_preInit.sqf +++ b/addons/mk6mortar/XEH_preInit.sqf @@ -15,6 +15,7 @@ PREP(handlePlayerVehicleChanged); PREP(loadMagazine); PREP(loadMagazineTimer); PREP(moduleInit); +PREP(mortarInit); PREP(rangeTableCanUse); PREP(rangeTableOpen); PREP(rangeTablePageChange); diff --git a/addons/mk6mortar/functions/fnc_mortarInit.sqf b/addons/mk6mortar/functions/fnc_mortarInit.sqf new file mode 100644 index 0000000000..b499462cbe --- /dev/null +++ b/addons/mk6mortar/functions/fnc_mortarInit.sqf @@ -0,0 +1,36 @@ +/* + * Author: VKing + * Initializes mortar for use with ammunition handling magazines. + * + * Arguments: + * 0: Mortar + * + * Return Value: + * None + * + * Example: + * [mortar1] call ace_mk6mortar_fnc_mortarInit + * + * Public: No + */ +#define DEBUG_MODE_FULL +#include "script_component.hpp" + +PARAMS_1(_mortar); + +if (_mortar getVariable [QGVAR(initialized),false]) exitWith {}; + +// Remove all magazines +if (count magazines _mortar > 0) then { + {_mortar removeMagazineGlobal _x} forEach magazines _mortar; +}; + +// Replace current weapon with ammo handling weapon +private _currentWeapon = _mortar weaponsTurret [0] select 0; +if (getText (configFile >> "CfgWeapons" >> _currentWeapon >> QGVAR(replaceWith)) != "") then { + _mortar removeWeaponGlobal _currentWeapon; + _mortar addWeaponGlobal _newWeapon; +}; + +_mortar setVariable [QGVAR(initialized),true,true]; +TRACE_1("Init complete",_mortar);