Reload - Add manual reload for vehicle weapons - continued (#9398)

* Add manual reload to turrets

* Added reload via reload keybind

* Update fnc_canSwapTurretMagazine.sqf

* Update fnc_canSwapTurretMagazine.sqf

* Update fnc_canSwapTurretMagazine.sqf

* Engine based reloading, added more checks

* Update addons/reload/functions/fnc_canSwapTurretMagazine.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

---------

Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
This commit is contained in:
johnb432 2024-02-07 00:14:25 +01:00 committed by GitHub
parent 244bee4a61
commit 8de0740e94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 176 additions and 4 deletions

View File

@ -45,5 +45,48 @@ class CfgVehicles {
};
};
};
class ACE_SelfActions {
class GVAR(reloadTurret) {
displayName = "$STR_controls_tooltips_RELOAD_MAGAZINE";
condition = QUOTE(call FUNC(canSwapTurretMagazine));
statement = QUOTE(call FUNC(swapTurretMagazine));
icon = "\A3\ui_f\data\igui\cfg\simpletasks\types\rearm_ca.paa";
};
};
};
class Tank: LandVehicle {
class ACE_SelfActions {
class GVAR(reloadTurret) {
displayName = "$STR_controls_tooltips_RELOAD_MAGAZINE";
condition = QUOTE(call FUNC(canSwapTurretMagazine));
statement = QUOTE(call FUNC(swapTurretMagazine));
icon = "\A3\ui_f\data\igui\cfg\simpletasks\types\rearm_ca.paa";
};
};
};
class Car: LandVehicle {
class ACE_SelfActions {
class GVAR(reloadTurret) {
displayName = "$STR_controls_tooltips_RELOAD_MAGAZINE";
condition = QUOTE(call FUNC(canSwapTurretMagazine));
statement = QUOTE(call FUNC(swapTurretMagazine));
icon = "\A3\ui_f\data\igui\cfg\simpletasks\types\rearm_ca.paa";
};
};
};
class Air;
class Helicopter: Air {
class ACE_SelfActions {
class GVAR(reloadTurret) {
displayName = "$STR_controls_tooltips_RELOAD_MAGAZINE";
condition = QUOTE(call FUNC(canSwapTurretMagazine));
statement = QUOTE(call FUNC(swapTurretMagazine));
icon = "\A3\ui_f\data\igui\cfg\simpletasks\types\rearm_ca.paa";
};
};
};
};

View File

@ -0,0 +1,16 @@
class CfgWeapons {
class HMG_01;
class HMG_static: HMG_01 {
type = 1; // makes it possible to swap to the fullest magazine
};
class GMG_F;
class GMG_20mm: GMG_F {
type = 1;
};
class CannonCore;
class mortar_82mm: CannonCore {
type = 1;
};
};

View File

@ -1,7 +1,9 @@
PREP(canCheckAmmo);
PREP(canCheckAmmoSelf);
PREP(canSwapTurretMagazine);
PREP(getAmmoToLinkBelt);
PREP(checkAmmo);
PREP(displayAmmo);
PREP(onTake);
PREP(startLinkingBelt);
PREP(swapTurretMagazine);

View File

@ -53,3 +53,18 @@
if (!hasInterface) exitWith {};
#include "initKeybinds.inc.sqf"
// Reload when default reload keybind is pressed
addUserActionEventHandler ["ReloadMagazine", "Activate", {
private _vehicle = objectParent ACE_player;
// If on foot, skip
if (isNull _vehicle) exitWith {};
// weaponState is only updated after 3 frames, so wait to run checks in case we're doing an engine reload at the same time
[{
if !(_this call FUNC(canSwapTurretMagazine)) exitWith {};
_this call FUNC(swapTurretMagazine);
}, [_vehicle, ACE_player], 3] call CBA_fnc_execAfterNFrames;
}];

View File

@ -14,10 +14,11 @@ class CfgPatches {
};
};
#include "ACE_Arsenal_Stats.hpp"
#include "CfgVehicles.hpp"
#include "CfgMagazines.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgActions.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgMagazines.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "ACE_Arsenal_Stats.hpp"
#include "ACE_Settings.hpp"
#include "ACE_UI.hpp"

View File

@ -0,0 +1,52 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror, johnb43
* Check if the player can reload their vehicle's magazine to one with more ammo.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* Can swap turret magazine <BOOL>
*
* Example:
* [vehicle player, player] call ace_reload_fnc_canSwapTurretMagazine
*
* Public: No
*/
params ["_vehicle", "_unit"];
TRACE_2("canSwapTurretMagazine",_vehicle,_unit);
private _turretPath = _vehicle unitTurret _unit;
if (_turretPath in [[-1], []]) exitWith {false}; // skip driver / cargo
if !(_vehicle turretLocal _turretPath) exitWith {false}; // just to be safe
(weaponState [_vehicle, _turretPath]) params ["_weapon", "_muzzle", "", "_magazine", "_ammoCount", "_roundReloadPhase", "_magazineReloadPhase"];
TRACE_5("",_weapon,_muzzle,_magazine,_ammoCount,typeOf _vehicle);
if ((_weapon == "") || {_weapon != _muzzle}) exitWith {false}; // skip multi-muzzle (he/ap auto-cannons)
if (_magazine == "") exitWith {false};
if (_roundReloadPhase + _magazineReloadPhase != 0) exitWith {false}; // can't reload while already reloading or while shooting
if (isText (configFile >> "CfgMagazines" >> _magazine >> "pylonWeapon")) exitWith {false};
if (getNumber (configFile >> "CfgWeapons" >> _weapon >> "type") % 2 == 1) exitWith {false}; // engine support for magazine swapping
private _maxAmmo = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
if ((_ammoCount == 0) || {_ammoCount == _maxAmmo}) exitWith {false};
private _magAmmoCounts = [];
// Get count of rounds in magazines
{
_x params ["_xMag", "_xTurret", "_xAmmo"];
if ((_xMag == _magazine) && {_xTurret isEqualTo _turretPath}) then {
_magAmmoCounts pushBack _xAmmo;
};
} forEach (magazinesAllTurrets _vehicle);
TRACE_1("",_magAmmoCounts);
// Select maximum
(selectMax _magAmmoCounts) > _ammoCount

View File

@ -0,0 +1,43 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror, johnb43
* Reloads a vehicles turret to a new magazine.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* None
*
* Example:
* [vehicle player, player] call ace_reload_fnc_swapTurretMagazine
*
* Public: No
*/
params ["_vehicle", "_unit"];
TRACE_2("swapTurretMagazine",_vehicle,_unit);
private _turretPath = _vehicle unitTurret _unit;
(weaponState [_vehicle, _turretPath]) params ["_weapon", "_muzzle", "", "_magazine"];
TRACE_3("",_weapon,_magazine,typeOf _vehicle);
private _magazinesAllTurrets = [];
// Get magazines that are of the correct type; Exclude empty mags
{
_x params ["_xMag", "_xTurret", "_xAmmo"];
if ((_xMag == _magazine) && {_xTurret isEqualTo _turretPath} && {_xAmmo > 0}) then {
_magazinesAllTurrets pushBack _x;
};
} forEach (magazinesAllTurrets _vehicle);
// Get count of rounds in magazines, then select maximum
private _magAmmoCounts = _magazinesAllTurrets apply {_x select 2};
private _mag = _magazinesAllTurrets select (_magAmmoCounts find (selectMax _magAmmoCounts));
TRACE_2("",_magAmmoCounts,_mag);
_unit action ["loadMagazine", _vehicle, _unit, _mag select 4, _mag select 3, _weapon, _muzzle];