diff --git a/addons/reloadlaunchers/CfgEventHandlers.hpp b/addons/reloadlaunchers/CfgEventHandlers.hpp index f0a9f14d91..0cd959a047 100644 --- a/addons/reloadlaunchers/CfgEventHandlers.hpp +++ b/addons/reloadlaunchers/CfgEventHandlers.hpp @@ -4,3 +4,9 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; diff --git a/addons/reloadlaunchers/CfgWeapons.hpp b/addons/reloadlaunchers/CfgWeapons.hpp new file mode 100644 index 0000000000..08fbdb76b0 --- /dev/null +++ b/addons/reloadlaunchers/CfgWeapons.hpp @@ -0,0 +1,11 @@ + +class CfgWeapons { + class Launcher_Base_F; + class launch_Titan_base: Launcher_Base_F { + GVAR(enabled) = 1; + }; + + class launch_RPG32_F: Launcher_Base_F { + GVAR(enabled) = 1; + }; +}; diff --git a/addons/reloadlaunchers/XEH_postInit.sqf b/addons/reloadlaunchers/XEH_postInit.sqf new file mode 100644 index 0000000000..437927602a --- /dev/null +++ b/addons/reloadlaunchers/XEH_postInit.sqf @@ -0,0 +1,4 @@ +// by commy2 +#include "script_component.hpp" + +["reloadLauncher", {_this call DFUNC(reloadLauncher)}] call EFUNC(common,addEventhandler); diff --git a/addons/reloadlaunchers/XEH_preInit.sqf b/addons/reloadlaunchers/XEH_preInit.sqf index 69abb46fa9..d4c36fc948 100644 --- a/addons/reloadlaunchers/XEH_preInit.sqf +++ b/addons/reloadlaunchers/XEH_preInit.sqf @@ -2,6 +2,8 @@ ADDON = false; -PREP(empty); +PREP(canLoad); +PREP(load); +PREP(reloadLauncher); ADDON = true; diff --git a/addons/reloadlaunchers/config.cpp b/addons/reloadlaunchers/config.cpp index a7b7bae6df..09aee548bf 100644 --- a/addons/reloadlaunchers/config.cpp +++ b/addons/reloadlaunchers/config.cpp @@ -13,3 +13,4 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" +#include "CfgWeapons.hpp" diff --git a/addons/reloadlaunchers/functions/fnc_canLoad.sqf b/addons/reloadlaunchers/functions/fnc_canLoad.sqf new file mode 100644 index 0000000000..b318e162ef --- /dev/null +++ b/addons/reloadlaunchers/functions/fnc_canLoad.sqf @@ -0,0 +1,56 @@ +/* + * Author: commy2 + * + * Check of the unit can reload the launcher of target unit. + * + * Argument: + * 0: Unit to to the reload (Object) + * 1: Unit eqipped with launcher (Object) + * + * Return value: + * NONE + */ +#include "script_component.hpp" + +private ["_unit", "_target"]; + +_unit = _this select 0; +_target = _this select 1; + +if (!alive _target) exitWith {false}; +if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false}; + +private "_weapon"; +_weapon = secondaryWeapon _unit; + +// has secondary weapon equipped +if (_weapon == "" || {currentWeapon _target != _weapon}) exitWith {false}; + +// check if the target really needs to be reloaded +if (currentMagazine _target != "") exitWith {false}; + +// check if the launcher is compatible +private "_config"; +_config = configFile >> "CfgWeapons" >> _weapon; + +if (getNumber (_config >> QGVAR(enabled)) == 0) exitWith {false}; + +// get magazine of reloader +private "_magazines"; +_magazines = magazines _unit; + +{ + _magazines deleteAt (_magazines find _x); +} forEach secondaryWeaponMagazine _unit; + +// check if the reloader has a magazine compatible with targets launcher +private "_hasMagazine"; +_hasMagazine = false; + +{ + if (_x in _magazines) exitWith { + _hasMagazine = true; + }; +} forEach getArray (_config >> "magazines"); + +_hasMagazine diff --git a/addons/reloadlaunchers/functions/fnc_empty.sqf b/addons/reloadlaunchers/functions/fnc_empty.sqf deleted file mode 100644 index c60a82b2d8..0000000000 --- a/addons/reloadlaunchers/functions/fnc_empty.sqf +++ /dev/null @@ -1,3 +0,0 @@ -#include "script_component.hpp" - -diag_log text format["This is here as an example!!!"]; diff --git a/addons/reloadlaunchers/functions/fnc_load.sqf b/addons/reloadlaunchers/functions/fnc_load.sqf new file mode 100644 index 0000000000..6a795fd0a6 --- /dev/null +++ b/addons/reloadlaunchers/functions/fnc_load.sqf @@ -0,0 +1,29 @@ +/* + * Author: commy2 + * + * Reload a launcher + * + * Argument: + * 0: Unit with magazine (Object) + * 1: Unit with launcher (Object) + * 2: weapon name (String) + * 3: missile name (String) + * + * Return value: + * NONE + */ +#include "script_component.hpp" + +private ["_unit", "_target", "_weapon", "_magazine"]; + +_unit = _this select 0; +_target = _this select 1; +_weapon = _this select 2; +_magazine = _this select 3; + +//do stuff + +/**/ + +// reload launcher on remote machine +["reloadLauncher", _target, [_target, _weapon, _magazine]] call EFUNC(common,targetEvent); diff --git a/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf new file mode 100644 index 0000000000..763e88dc3d --- /dev/null +++ b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf @@ -0,0 +1,28 @@ +/* + * Author: commy2 + * + * Reload a launcher + * + * Argument: + * 0: Unit to reload (Object) + * 1: weapon name (String) + * 2: missile name (String) + * + * Return value: + * NONE + */ +#include "script_component.hpp" + +private ["_unit", "_weapon", "_magazine"]; + +_unit = _this select 0; +_weapon = _this select 1; +_magazine = _this select 2; + +_unit selectWeapon _weapon; + +if (currentWeapon _unit != _weapon) exitWith {}; +if (currentMagazine _unit != "") exitWith {}; + +// command is wip, reload time for launchers is not intended. +_unit addWeaponItem [_weapon, _magazine];