-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> --------- Co-authored-by: LinkIsGrim <[email protected]> Co-authored-by: Grim <[email protected]>
- Loading branch information
1 parent
244bee4
commit 8de0740
Showing
7 changed files
with
176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
PREP(canCheckAmmo); | ||
PREP(canCheckAmmoSelf); | ||
PREP(canSwapTurretMagazine); | ||
PREP(getAmmoToLinkBelt); | ||
PREP(checkAmmo); | ||
PREP(displayAmmo); | ||
PREP(onTake); | ||
PREP(startLinkingBelt); | ||
PREP(swapTurretMagazine); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; |