From f734aeee95737dfc8573096061811f73a76de703 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 22 Mar 2015 14:05:31 +0100 Subject: [PATCH] reload launcher mag progress bar --- addons/common/functions/fnc_progressBar.sqf | 1 + addons/reloadlaunchers/CfgVehicles.hpp | 15 ++++++ addons/reloadlaunchers/XEH_preInit.sqf | 1 + addons/reloadlaunchers/config.cpp | 4 +- .../functions/fnc_addMissileReloadActions.sqf | 53 +++++++++++++++++++ .../reloadlaunchers/functions/fnc_canLoad.sqf | 19 ++++--- addons/reloadlaunchers/functions/fnc_load.sqf | 27 ++++++++-- .../functions/fnc_reloadLauncher.sqf | 20 +++---- 8 files changed, 119 insertions(+), 21 deletions(-) create mode 100644 addons/reloadlaunchers/CfgVehicles.hpp create mode 100644 addons/reloadlaunchers/functions/fnc_addMissileReloadActions.sqf diff --git a/addons/common/functions/fnc_progressBar.sqf b/addons/common/functions/fnc_progressBar.sqf index 69b91237e6..3191a57d72 100644 --- a/addons/common/functions/fnc_progressBar.sqf +++ b/addons/common/functions/fnc_progressBar.sqf @@ -53,6 +53,7 @@ _perFrameFunction = { _elapsedTime = time - _startTime; _errorCode = -1; + // this does not check: target fell unconscious, target died, target moved inside vehicle / left vehicle, target moved outside of players range, target moves at all. if (isNull (uiNamespace getVariable [QGVAR(ctrlProgressBar), controlNull])) then { _errorCode = 1; } else { diff --git a/addons/reloadlaunchers/CfgVehicles.hpp b/addons/reloadlaunchers/CfgVehicles.hpp new file mode 100644 index 0000000000..6cdf2b1cfc --- /dev/null +++ b/addons/reloadlaunchers/CfgVehicles.hpp @@ -0,0 +1,15 @@ + +class CfgVehicles { + class Man; + class CAManBase: Man { + class ACE_Actions { + class GVAR(ReloadLauncher) { + displayName = "RELOAD LAUNCHERS"; + selection = "launcher"; + distance = 4; + condition = ""; + insertChildren = QUOTE(_this call FUNC(addMissileReloadActions)); + }; + }; + }; +}; diff --git a/addons/reloadlaunchers/XEH_preInit.sqf b/addons/reloadlaunchers/XEH_preInit.sqf index 2b937b8284..3b60f99b8e 100644 --- a/addons/reloadlaunchers/XEH_preInit.sqf +++ b/addons/reloadlaunchers/XEH_preInit.sqf @@ -2,6 +2,7 @@ ADDON = false; +PREP(addMissileReloadActions); PREP(canLoad); PREP(getLoadableMissiles); PREP(load); diff --git a/addons/reloadlaunchers/config.cpp b/addons/reloadlaunchers/config.cpp index 09aee548bf..a039ef87c4 100644 --- a/addons/reloadlaunchers/config.cpp +++ b/addons/reloadlaunchers/config.cpp @@ -5,7 +5,7 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_common"}; + requiredAddons[] = {"ace_common","ace_interaction","ace_interact_menu"}; author[] = {""}; authorUrl = ""; VERSION_CONFIG; @@ -13,4 +13,6 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" + +#include "CfgVehicles.hpp" #include "CfgWeapons.hpp" diff --git a/addons/reloadlaunchers/functions/fnc_addMissileReloadActions.sqf b/addons/reloadlaunchers/functions/fnc_addMissileReloadActions.sqf new file mode 100644 index 0000000000..71cc72e839 --- /dev/null +++ b/addons/reloadlaunchers/functions/fnc_addMissileReloadActions.sqf @@ -0,0 +1,53 @@ +/* + * Author: commy2 + * Create one action per reloadable missile + * + * Argument: + * 1: Player (Object) + * 0: Target (Object) + * 2: Parameters ??? (Array) + * + * Return value: + * Children actions (Array) + * + */ +#include "script_component.hpp" + +private ["_unit", "_target", "_parameters"]; + +_unit = _this select 1; +_target = _this select 0; +_parameters = _this select 2; // ??? + +private ["_actions", "_weapon", "_loadableMissiles"]; + +_actions = []; + +_weapon = secondaryWeapon _target; +_loadableMissiles = [_unit, _weapon] call FUNC(getLoadableMissiles); + +{ + private ["_name", "_displayName", "_statement", "_condition", "_action"]; + +/* +getText (configFile >> "CfgWeapons" >> _weapon >> "displayName") +getText (configFile >> "CfgMagazines" >> _x >> "displayName") +*/ + + _name = format [QGVAR(Missile_%1), _x]; + _displayName = format ["RELOAD %1", _x]; + + _statement = { + (_this select 2) call DFUNC(load); + }; + + _condition = { + (_this select 2) call DFUNC(canLoad) + }; + + _action = [_name, _displayName, "", _statement, _condition, {}, [_unit, _target, _weapon, _x], "", 4] call EFUNC(interact_menu,createAction); + + _actions pushBack [_action, [], _unit]; +} forEach _loadableMissiles; + +_actions diff --git a/addons/reloadlaunchers/functions/fnc_canLoad.sqf b/addons/reloadlaunchers/functions/fnc_canLoad.sqf index d2a4828038..5bbfe4dd87 100644 --- a/addons/reloadlaunchers/functions/fnc_canLoad.sqf +++ b/addons/reloadlaunchers/functions/fnc_canLoad.sqf @@ -6,31 +6,36 @@ * Argument: * 0: Unit to do the reloading (Object) * 1: Unit eqipped with launcher (Object) + * 2: weapon name (String) + * 3: missile name (String) * * Return value: * NONE */ #include "script_component.hpp" -private ["_unit", "_target"]; +private ["_unit", "_target", "_weapon", "_magazine"]; _unit = _this select 0; _target = _this select 1; +_weapon = _this select 2; +_magazine = _this select 3; if (!alive _target) exitWith {false}; +if (vehicle _target != _target) exitWith {false}; if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false}; -private "_weapon"; -_weapon = secondaryWeapon _unit; +// target is awake +if (_target getVariable ["ACE_isUnconscious", false]) exitWith {false}; // has secondary weapon equipped -if (_weapon == "" || {currentWeapon _target != _weapon}) exitWith {false}; +if !(_weapon in weapons _target) exitWith {false}; // check if the target really needs to be reloaded -if (currentMagazine _target != "") exitWith {false}; +if (count secondaryWeaponMagazine _target > 0) exitWith {false}; // check if the launcher is compatible if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false}; -// check if the reloader has a magazine compatible with targets launcher -count ([_unit, _weapon] call FUNC(getLoadableMissiles)) > 0 +// check if the magazine compatible with targets launcher +_magazine in ([_unit, _weapon] call FUNC(getLoadableMissiles)) diff --git a/addons/reloadlaunchers/functions/fnc_load.sqf b/addons/reloadlaunchers/functions/fnc_load.sqf index 6a795fd0a6..8806d835d6 100644 --- a/addons/reloadlaunchers/functions/fnc_load.sqf +++ b/addons/reloadlaunchers/functions/fnc_load.sqf @@ -21,9 +21,28 @@ _target = _this select 1; _weapon = _this select 2; _magazine = _this select 3; -//do stuff +private "_reloadTime"; +_reloadTime = getNumber (configFile >> "CfgWeapons" >> _weapon >> "magazineReloadTime"); -/**/ +// do animation +[_unit] call EFUNC(common,goKneeling); -// reload launcher on remote machine -["reloadLauncher", _target, [_target, _weapon, _magazine]] call EFUNC(common,targetEvent); +// show progress bar +private ["_onSuccess", "_onFailure", "_condition"]; + +_onSuccess = { + (_this select 0 select 0) removeMagazine (_this select 0 select 3); + ["reloadLauncher", _this select 0 select 0, _this select 0] call DEFUNC(common,targetEvent); + + ["WEAPON RELOADED"] call DEFUNC(common,displayTextStructured); +}; + +_onFailure = { + ["WEAPON NOT RELOADED"] call DEFUNC(common,displayTextStructured); +}; + +_condition = { + (_this select 0) call DFUNC(canLoad) && {(_this select 0 select 0) distance (_this select 0 select 1) < 4} +}; + +[_reloadTime, [_unit, _target, _weapon, _magazine], _onSuccess, _onFailure, "RELOADING WEAPON", _condition] call EFUNC(common,progressBar); diff --git a/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf index 763e88dc3d..36772f9dfd 100644 --- a/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf +++ b/addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf @@ -4,9 +4,10 @@ * Reload a launcher * * Argument: - * 0: Unit to reload (Object) - * 1: weapon name (String) - * 2: missile name (String) + * 0: Unit to do the reloading (Object) + * 1: Target to rload (Object) + * 2: weapon name (String) + * 3: missile name (String) * * Return value: * NONE @@ -16,13 +17,14 @@ private ["_unit", "_weapon", "_magazine"]; _unit = _this select 0; -_weapon = _this select 1; -_magazine = _this select 2; +_target = _this select 1; +_weapon = _this select 2; +_magazine = _this select 3; -_unit selectWeapon _weapon; +_target selectWeapon _weapon; -if (currentWeapon _unit != _weapon) exitWith {}; -if (currentMagazine _unit != "") exitWith {}; +if (currentWeapon _target != _weapon) exitWith {}; +if (currentMagazine _target != "") exitWith {}; // command is wip, reload time for launchers is not intended. -_unit addWeaponItem [_weapon, _magazine]; +_target addWeaponItem [_weapon, _magazine];