Reload Launchers - Code cleanup (#9334)

* reloadlaunchers cleanup

* Update fnc_canLoad.sqf
This commit is contained in:
johnb432 2023-08-28 19:27:01 +02:00 committed by GitHub
parent 44e0fdb6fa
commit 59ee36560f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 68 deletions

View File

@ -1,4 +1,3 @@
class Extended_PreStart_EventHandlers { class Extended_PreStart_EventHandlers {
class ADDON { class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart)); init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));

View File

@ -1,4 +1,3 @@
class CfgVehicles { class CfgVehicles {
class Man; class Man;
class CAManBase: Man { class CAManBase: Man {

View File

@ -1,4 +1,3 @@
class CfgWeapons { class CfgWeapons {
class Launcher_Base_F; class Launcher_Base_F;
class launch_Titan_base: Launcher_Base_F { class launch_Titan_base: Launcher_Base_F {

View File

@ -1,4 +1,3 @@
PREP(addMissileReloadActions); PREP(addMissileReloadActions);
PREP(canLoad); PREP(canLoad);
PREP(getLoadableMissiles); PREP(getLoadableMissiles);

View File

@ -1,4 +1,4 @@
// by commy2 // by commy2
#include "script_component.hpp" #include "script_component.hpp"
[QGVAR(reloadLauncher), {_this call DFUNC(reloadLauncher)}] call CBA_fnc_addEventHandler; [QGVAR(reloadLauncher), LINKFUNC(reloadLauncher)] call CBA_fnc_addEventHandler;

View File

@ -15,6 +15,5 @@ class CfgPatches {
}; };
#include "CfgEventHandlers.hpp" #include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp" #include "CfgVehicles.hpp"
#include "CfgWeapons.hpp" #include "CfgWeapons.hpp"

View File

@ -1,17 +1,17 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: commy2 * Author: commy2
* Create one action per reloadable missile * Create one action per reloadable missile.
* *
* Arguments: * Arguments:
* 1: Target <OBJECT> * 0: Unit equipped with the launcher <OBJECT>
* 0: Player <OBJECT> * 1: Unit to execute the reload <OBJECT>
* *
* Return Value: * Return Value:
* Children actions <ARRAY> * Children actions <ARRAY>
* *
* Example: * Example:
* [bob, kevin] call ace_reloadlaunchers_fnc_addMissileReloadActions * [cursorTarget, player] call ace_reloadlaunchers_fnc_addMissileReloadActions
* *
* Public: No * Public: No
* *
@ -20,8 +20,9 @@
params ["_target", "_unit"]; params ["_target", "_unit"];
TRACE_2("params",_target,_unit); TRACE_2("params",_target,_unit);
//Fast exit for common case: // Fast exit for common cases
private _weapon = secondaryWeapon _target; private _weapon = secondaryWeapon _target;
if ((_weapon == "") || {(getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled))) == 0}) exitWith { if ((_weapon == "") || {(getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled))) == 0}) exitWith {
TRACE_1("weapon not supported",_weapon); TRACE_1("weapon not supported",_weapon);
[] []
@ -32,16 +33,18 @@ private _actions = [];
private _loadableMissiles = [_unit, _weapon] call FUNC(getLoadableMissiles); private _loadableMissiles = [_unit, _weapon] call FUNC(getLoadableMissiles);
TRACE_2("",_weapon,_loadableMissiles); TRACE_2("",_weapon,_loadableMissiles);
private _cfgMagazines = configFile >> "CfgMagazines";
{ {
private _name = format [QGVAR(Missile_%1), _x]; private _name = format [QGVAR(Missile_%1), _x];
private _displayName = format [localize LSTRING(LoadMagazine), getText (configFile >> "CfgMagazines" >> _x >> "displayName")]; private _displayName = format [LLSTRING(LoadMagazine), getText (_cfgMagazines >> _x >> "displayName")];
private _statement = { private _statement = {
(_this select 2) call DFUNC(load); (_this select 2) call FUNC(load);
}; };
private _condition = { private _condition = {
(_this select 2) call DFUNC(canLoad) (_this select 2) call FUNC(canLoad)
}; };
private _action = [_name, _displayName, "", _statement, _condition, {}, [_unit, _target, _weapon, _x], "", 4] call EFUNC(interact_menu,createAction); private _action = [_name, _displayName, "", _statement, _condition, {}, [_unit, _target, _weapon, _x], "", 4] call EFUNC(interact_menu,createAction);

View File

@ -4,16 +4,16 @@
* Check of the unit can reload the launcher of target unit. * Check of the unit can reload the launcher of target unit.
* *
* Arguments: * Arguments:
* 0: Unit to do the reloading <OBJECT> * 0: Unit to execute the reload <OBJECT>
* 1: Unit eqipped with launcher <OBJECT> * 1: Unit equipped with the launcher <OBJECT>
* 2: weapon name <STRING> * 2: Launcher name <STRING>
* 3: missile name <STRING> * 3: Missile name <STRING>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_canLoad * [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_canLoad
* *
* Public: No * Public: No
*/ */
@ -21,21 +21,21 @@
params ["_unit", "_target", "_weapon", "_magazine"]; params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine); TRACE_4("params",_unit,_target,_weapon,_magazine);
if (!alive _target) exitWith {false}; // Target must be awake
if (vehicle _target != _target) exitWith {false}; if !(_target call EFUNC(common,isAwake)) exitWith {false};
// Target must not be in a vehicle
if !(isNull objectParent _target) exitWith {false};
if !([_unit, _target, ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false}; if !([_unit, _target, ["isNotInside", "isNotSwimming"]] call EFUNC(common,canInteractWith)) exitWith {false};
// target is awake // Check if the launcher is compatible
if (_target getVariable ["ACE_isUnconscious", false]) exitWith {false};
// has secondary weapon equipped
if !(_weapon in weapons _target) exitWith {false};
// check if the target really needs to be reloaded
if (count secondaryWeaponMagazine _target > 0) exitWith {false};
// check if the launcher is compatible
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false}; if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false};
// check if the magazine compatible with targets launcher // Check if target has its secondary weapon equipped
if !(_weapon in weapons _target) exitWith {false};
// Check if the target's launcher's primary muzzle really needs to be reloaded
if (_target ammo _weapon != 0) exitWith {false};
// Check if the magazine is compatible with target's launcher
_magazine in ([_unit, _weapon] call FUNC(getLoadableMissiles)) _magazine in ([_unit, _weapon] call FUNC(getLoadableMissiles))

View File

@ -1,17 +1,17 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: commy2 * Author: commy2, johnb43
* Return all magazine types from reloaders inventory that are compatible with given weapon. * Return all magazine types from reloaders inventory that are compatible with given weapon.
* *
* Arguments: * Arguments:
* 0: Unit to to the reload <OBJECT> * 0: Unit to execute the reload <OBJECT>
* 1: A launcher <OBJECT> * 1: Launcher name <STRING>
* *
* Return Value: * Return Value:
* Reloable magazines <ARRAY> * Reloable magazines <ARRAY>
* *
* Example: * Example:
* [bob, launcher] call ace_reloadlaunchers_fnc_getLoadableMissiles * [player, "launch_RPG32_F"] call ace_reloadlaunchers_fnc_getLoadableMissiles
* *
* Public: No * Public: No
*/ */
@ -19,11 +19,5 @@
params ["_unit", "_weapon"]; params ["_unit", "_weapon"];
TRACE_2("params",_unit,_weapon); TRACE_2("params",_unit,_weapon);
// get available magazines of reloader, Note: "magazines" does not include currently loaded magazines // Look for primary muzzle magazines only
private _magazines = magazines _unit; (compatibleMagazines [_weapon, "this"]) arrayIntersect (magazines _unit)
// case sensitvity
_magazines = _magazines apply {toLower _x};
// get reloaders magazine types compatible with targets launcher. No duplicates.
getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select {toLower _x in _magazines} // return

View File

@ -1,19 +1,19 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: commy2 * Author: commy2
* Reload a launcher * Start reloading a launcher, reload started by the unit who has the missile.
* *
* Arguments: * Arguments:
* 0: Unit with magazine <OBJECT> * 0: Unit executing the reload <OBJECT>
* 1: Unit with launcher <OBJECT> * 1: Unit equipped with the launcher <OBJECT>
* 2: weapon name <STRING> * 2: Launcher name <STRING>
* 3: missile name <STRING> * 3: Missile name <STRING>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_load * [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_load
* *
* Public: No * Public: No
*/ */
@ -21,30 +21,37 @@
params ["_unit", "_target", "_weapon", "_magazine"]; params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine); TRACE_4("params",_unit,_target,_weapon,_magazine);
private _reloadTime = if (isNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime))) then { private _config = configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime);
getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime))
private _reloadTime = if (isNumber _config) then {
getNumber _config
} else { } else {
2.5 2.5
}; };
// do animation // Play animation
[_unit] call EFUNC(common,goKneeling); [_unit] call EFUNC(common,goKneeling);
// show progress bar // Show progress bar
private _onSuccess = { private _onSuccess = {
(_this select 0 select 0) removeMagazine (_this select 0 select 3); (_this select 0) params ["_unit", "_target", "_weapon", "_magazine"];
[QGVAR(reloadLauncher), _this select 0, _this select 0 select 1] call CBA_fnc_targetEvent;
[localize LSTRING(LauncherLoaded)] call DEFUNC(common,displayTextStructured); _unit removeMagazine _magazine;
// Reload target's launcher
[QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine], _target] call CBA_fnc_targetEvent;
[LLSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured);
}; };
private _onFailure = { private _onFailure = {
[localize ELSTRING(common,ActionAborted)] call DEFUNC(common,displayTextStructured); [LELSTRING(common,ActionAborted)] call EFUNC(common,displayTextStructured);
}; };
private _condition = { private _condition = {
(_this select 0) call DFUNC(canLoad) && {(_this select 0 select 0) distance (_this select 0 select 1) < 4} (_this select 0) params ["_unit", "_target"];
(_this select 0) call FUNC(canLoad) && {_unit distance _target < 4}
}; };
[_reloadTime, [_unit, _target, _weapon, _magazine], _onSuccess, _onFailure, localize LSTRING(LoadingLauncher), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar); [_reloadTime, [_unit, _target, _weapon, _magazine], _onSuccess, _onFailure, LLSTRING(LoadingLauncher), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar);

View File

@ -1,19 +1,19 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: commy2 * Author: commy2
* Reload a launcher * Reload a launcher for the unit who has the launcher.
* *
* Arguments: * Arguments:
* 0: Unit to do the reloading <OBJECT> * 0: Unit executing the reload <OBJECT>
* 1: Target to rload <OBJECT> * 1: Unit equipped with the launcher <OBJECT>
* 2: weapon name <STRING> * 2: Launcher name <STRING>
* 3: missile name <STRING> * 3: Missile name <STRING>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_reloadLauncher * [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_reloadLauncher
* *
* Public: No * Public: No
*/ */