Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload Launchers - Code cleanup #9334

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/reloadlaunchers/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand Down
1 change: 0 additions & 1 deletion addons/reloadlaunchers/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CfgVehicles {
class Man;
class CAManBase: Man {
Expand Down
1 change: 0 additions & 1 deletion addons/reloadlaunchers/CfgWeapons.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CfgWeapons {
class Launcher_Base_F;
class launch_Titan_base: Launcher_Base_F {
Expand Down
1 change: 0 additions & 1 deletion addons/reloadlaunchers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PREP(addMissileReloadActions);
PREP(canLoad);
PREP(getLoadableMissiles);
Expand Down
2 changes: 1 addition & 1 deletion addons/reloadlaunchers/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// by commy2
#include "script_component.hpp"

[QGVAR(reloadLauncher), {_this call DFUNC(reloadLauncher)}] call CBA_fnc_addEventHandler;
[QGVAR(reloadLauncher), LINKFUNC(reloadLauncher)] call CBA_fnc_addEventHandler;
1 change: 0 additions & 1 deletion addons/reloadlaunchers/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ class CfgPatches {
};

#include "CfgEventHandlers.hpp"

#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
19 changes: 11 additions & 8 deletions addons/reloadlaunchers/functions/fnc_addMissileReloadActions.sqf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "script_component.hpp"
/*
* Author: commy2
* Create one action per reloadable missile
* Create one action per reloadable missile.
*
* Arguments:
* 1: Target <OBJECT>
* 0: Player <OBJECT>
* 0: Unit equipped with the launcher <OBJECT>
* 1: Unit to execute the reload <OBJECT>
*
* Return Value:
* Children actions <ARRAY>
*
* Example:
* [bob, kevin] call ace_reloadlaunchers_fnc_addMissileReloadActions
* [cursorTarget, player] call ace_reloadlaunchers_fnc_addMissileReloadActions
*
* Public: No
*
Expand All @@ -20,8 +20,9 @@
params ["_target", "_unit"];
TRACE_2("params",_target,_unit);

//Fast exit for common case:
// Fast exit for common cases
private _weapon = secondaryWeapon _target;

if ((_weapon == "") || {(getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled))) == 0}) exitWith {
TRACE_1("weapon not supported",_weapon);
[]
Expand All @@ -32,16 +33,18 @@ private _actions = [];
private _loadableMissiles = [_unit, _weapon] call FUNC(getLoadableMissiles);
TRACE_2("",_weapon,_loadableMissiles);

private _cfgMagazines = configFile >> "CfgMagazines";

{
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 = {
(_this select 2) call DFUNC(load);
(_this select 2) call FUNC(load);
};

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);
Expand Down
32 changes: 16 additions & 16 deletions addons/reloadlaunchers/functions/fnc_canLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
* Check of the unit can reload the launcher of target unit.
*
* Arguments:
* 0: Unit to do the reloading <OBJECT>
* 1: Unit eqipped with launcher <OBJECT>
* 2: weapon name <STRING>
* 3: missile name <STRING>
* 0: Unit to execute the reload <OBJECT>
* 1: Unit equipped with the launcher <OBJECT>
* 2: Launcher name <STRING>
* 3: Missile name <STRING>
*
* Return Value:
* None
*
* Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_canLoad
* [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_canLoad
*
* Public: No
*/

params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine);

if (!alive _target) exitWith {false};
if (vehicle _target != _target) exitWith {false};
// Target must be awake
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};

// target is awake
if (_target getVariable ["ACE_isUnconscious", false]) exitWith {false};
// Check if the launcher is compatible
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(enabled)) == 0) exitWith {false};

// has secondary weapon equipped
// Check if target has its 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};
// Check if the target's launcher's primary muzzle really needs to be reloaded
if (((getUnitLoadout _target) select 1 param [4, []] param [1, 0]) != 0) exitWith {false};
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

// check if the magazine compatible with targets launcher
// Check if the magazine is compatible with target's launcher
_magazine in ([_unit, _weapon] call FUNC(getLoadableMissiles))
18 changes: 6 additions & 12 deletions addons/reloadlaunchers/functions/fnc_getLoadableMissiles.sqf
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
#include "script_component.hpp"
/*
* Author: commy2
* Author: commy2, johnb43
* Return all magazine types from reloaders inventory that are compatible with given weapon.
*
* Arguments:
* 0: Unit to to the reload <OBJECT>
* 1: A launcher <OBJECT>
* 0: Unit to execute the reload <OBJECT>
* 1: Launcher name <STRING>
*
* Return Value:
* Reloable magazines <ARRAY>
*
* Example:
* [bob, launcher] call ace_reloadlaunchers_fnc_getLoadableMissiles
* [player, "launch_RPG32_F"] call ace_reloadlaunchers_fnc_getLoadableMissiles
*
* Public: No
*/

params ["_unit", "_weapon"];
TRACE_2("params",_unit,_weapon);

// get available magazines of reloader, Note: "magazines" does not include currently loaded magazines
private _magazines = 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
// Look for primary muzzle magazines only
(compatibleMagazines [_weapon, "this"]) arrayIntersect (magazines _unit)
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
41 changes: 24 additions & 17 deletions addons/reloadlaunchers/functions/fnc_load.sqf
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
#include "script_component.hpp"
/*
* Author: commy2
* Reload a launcher
* Start reloading a launcher, reload started by the unit who has the missile.
*
* Arguments:
* 0: Unit with magazine <OBJECT>
* 1: Unit with launcher <OBJECT>
* 2: weapon name <STRING>
* 3: missile name <STRING>
* 0: Unit executing the reload <OBJECT>
* 1: Unit equipped with the launcher <OBJECT>
* 2: Launcher name <STRING>
* 3: Missile name <STRING>
*
* Return Value:
* None
*
* Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_load
* [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_load
*
* Public: No
*/

params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine);

private _reloadTime = if (isNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime))) then {
getNumber (configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime))
private _config = configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime);

private _reloadTime = if (isNumber _config) then {
getNumber _config
} else {
2.5
};

// do animation
// Play animation
[_unit] call EFUNC(common,goKneeling);

// show progress bar

// Show progress bar
private _onSuccess = {
(_this select 0 select 0) removeMagazine (_this select 0 select 3);
[QGVAR(reloadLauncher), _this select 0, _this select 0 select 1] call CBA_fnc_targetEvent;
(_this select 0) params ["_unit", "_target", "_weapon", "_magazine"];

_unit removeMagazine _magazine;

[localize LSTRING(LauncherLoaded)] call DEFUNC(common,displayTextStructured);
// Reload target's launcher
[QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine], _target] call CBA_fnc_targetEvent;

[LLSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured);
};

private _onFailure = {
[localize ELSTRING(common,ActionAborted)] call DEFUNC(common,displayTextStructured);
[LELSTRING(common,ActionAborted)] call EFUNC(common,displayTextStructured);
};

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);
14 changes: 7 additions & 7 deletions addons/reloadlaunchers/functions/fnc_reloadLauncher.sqf
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "script_component.hpp"
/*
* Author: commy2
* Reload a launcher
* Reload a launcher for the unit who has the launcher.
*
* Arguments:
* 0: Unit to do the reloading <OBJECT>
* 1: Target to rload <OBJECT>
* 2: weapon name <STRING>
* 3: missile name <STRING>
* 0: Unit executing the reload <OBJECT>
* 1: Unit equipped with the launcher <OBJECT>
* 2: Launcher name <STRING>
* 3: Missile name <STRING>
*
* Return Value:
* None
*
* Example:
* [bob, kevin, "weapon", "missile"] call ace_reloadlaunchers_fnc_reloadLauncher
* [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_reloadLauncher
*
* Public: No
*/

params ["_unit","_target","_weapon","_magazine"];
params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine);

_target selectWeapon _weapon;
Expand Down