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

Artillery Tables - Add FUNC(doArtilleryFire) #9259

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
39f200b
fix belt linking issues
LinkIsGrim Jun 30, 2023
78800be
fix unloading to units with full inventory
LinkIsGrim Jun 30, 2023
01dffca
progress bar text changes
LinkIsGrim Jun 30, 2023
aca90fb
this took way too long
LinkIsGrim Jul 1, 2023
f3c393f
fix TRACE
LinkIsGrim Jul 1, 2023
76a2076
cache nearby ammo sources
LinkIsGrim Jul 1, 2023
5d62ab4
fix undefined variable
LinkIsGrim Jul 2, 2023
b4a0771
add csw override
LinkIsGrim Jul 2, 2023
9fe3f84
Update docs/wiki/framework/crew-served-weapons-framework.md
LinkIsGrim Jul 3, 2023
d9466e7
Merge remote-tracking branch 'upstream' into mk6-ammo-handling-indepe…
LinkIsGrim Jul 7, 2023
3b42998
Merge remote-tracking branch 'upstream' into csw-fix-belt-linking
LinkIsGrim Jul 12, 2023
d00c9ca
all the things
LinkIsGrim Jul 13, 2023
c96a9da
remove unnecessary change
LinkIsGrim Jul 13, 2023
c46dc33
_staticWeapon > _vehicle, StaticWeapon > CSW
LinkIsGrim Jul 13, 2023
6c2a8a2
add container property
LinkIsGrim Jul 13, 2023
ed44c0d
more headers
LinkIsGrim Jul 13, 2023
aa8fff3
fix case sensitivy, move container creation
LinkIsGrim Jul 13, 2023
4b92ef2
remove systemChat
LinkIsGrim Jul 13, 2023
e5a9fad
add check for invalid proxyWeapon
LinkIsGrim Jul 13, 2023
ddf1f11
remove stupid
LinkIsGrim Jul 13, 2023
17156d5
missing semicolon
LinkIsGrim Jul 13, 2023
078857b
add getAvailableAmmo
LinkIsGrim Jul 13, 2023
05d29c7
Merge branch 'mk6-ammo-handling-independent' of https://github.com/Sa…
LinkIsGrim Jul 13, 2023
6774da0
fix mk6 mortar?
LinkIsGrim Jul 13, 2023
1be677d
add disabled check
LinkIsGrim Jul 13, 2023
73bc331
function header
LinkIsGrim Jul 13, 2023
cafe1f4
compile cache
LinkIsGrim Jul 13, 2023
7647123
add forcedMag and ai_unloadMagazines
LinkIsGrim Jul 13, 2023
4e8c69e
make public
LinkIsGrim Jul 13, 2023
c3909b6
doArtilleryFire
LinkIsGrim Jul 13, 2023
bf05afc
Merge branch 'csw-fix-belt-linking' into artillerytables-doArtilleryFire
LinkIsGrim Jul 13, 2023
676924f
better loop
LinkIsGrim Jul 13, 2023
cbb9312
add mapgrid pos
LinkIsGrim Jul 13, 2023
354ab78
add csw override
LinkIsGrim Jul 2, 2023
8636c07
Update docs/wiki/framework/crew-served-weapons-framework.md
LinkIsGrim Jul 3, 2023
ef90520
remove stupid
LinkIsGrim Jul 13, 2023
64b6817
fix mk6 mortar?
LinkIsGrim Jul 13, 2023
3248424
add disabled check
LinkIsGrim Jul 13, 2023
121c1a4
doArtilleryFire
LinkIsGrim Jul 13, 2023
ad96397
better loop
LinkIsGrim Jul 13, 2023
29567ce
add mapgrid pos
LinkIsGrim Jul 13, 2023
70cb3b9
Merge branch 'artillerytables-doArtilleryFire' of https://github.com/…
LinkIsGrim Jul 13, 2023
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: 1 addition & 0 deletions addons/artillerytables/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TRACE_1("prep",_this);

PREP(doArtilleryFire);
PREP(firedEH);
PREP(interactMenuOpened);
PREP(rangeTableOpen);
Expand Down
92 changes: 92 additions & 0 deletions addons/artillerytables/functions/fnc_doArtilleryFire.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim, mharris001
* Wrapper for engine doArtilleryFire, fires barrage one round at a time.
* Handles CSW magazines.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Target <OBJECT, STRING or POSITION AGL>
* 2: Spread in meters
* 3: Magazine Type <STRING>
* 4: Rounds to fire <NUMBER>
*
* Return Value:
* Barrage Started <BOOL>
*
* Example:
* [cursorObject] call ace_artillerytables_fnc_doArtilleryFire
*
* Public: Yes
*/
params [["_vehicle", objNull, [objNull]], ["_position", [0, 0, 0], [[], objNull, ""], 3], ["_spread", 0, [0]], ["_magazine", "", [""]], ["_rounds", 0, [0]]];

if (isNull _vehicle || {_rounds isEqualTo 0} || {_magazine isEqualTo ""} || {!(_vehicle turretLocal [0])}) exitWith {false};

if (_position isEqualType objNull) then {
_position = ASLtoAGL getPosASL _position;
};

if (_position isEqualType "") then {
_position = [_position, true] call CBA_fnc_mapGridToPos;
};

private _usingCSW = false;
if ((typeOf _vehicle) in GVAR(initializedStaticTypes)) then {
if (["ace_csw"] call EFUNC(common,isModLoaded)) then {
_usingCSW = EGVAR(csw,ammoHandling) > 0;
};
if (["ace_mk6mortar"] call EFUNC(common,isModLoaded) && {_vehicle isKindOf "StaticMortar"}) then {
_usingCSW = EGVAR(mk6mortar,useAmmoHandling);
};
_usingCSW = _usingCSW && {_vehicle getVariable [QEGVAR(csw,assemblyMode), 3] isNotEqualTo 0}
};

if (_usingCSW && {EGVAR(csw,ammoHandling) < 2}) exitWith {false};

private _vehicleMagazine = _magazine;
if (_usingCSW) then {
private _isCarryMag = isClass (configFile >> QEGVAR(csw,groups) >> _magazine);
if (_isCarryMag) then {
_vehicle setVariable [QEGVAR(csw,forcedMag), _magazine, true];
_vehicleMagazine = [_vehicle, [0], _magazine] call EFUNC(csw,reload_getVehicleMagazine);
} else {
_vehicle setVariable [QEGVAR(csw,forcedMag), [_magazine] call EFUNC(csw,getCarryMagazine), true];
};

if !(_vehicleMagazine in (getArtilleryAmmo [_vehicle])) then {
// TODO: use public functions for this
private _currentMagazine = currentMagazine _vehicle;
private _currentCarryMagazine = [_currentMagazine] call EFUNC(csw,getCarryMagazine);
[_vehicle, [0], _currentCarryMagazine, _currentMagazine, _vehicle] call EFUNC(csw,reload_handleRemoveTurretMag);
[_vehicle, gunner _vehicle, "", true] call EFUNC(csw,ai_reload);
};
};

// Needs to be config case
_vehicleMagazine = configName (configFile >> "CfgMagazines" >> _vehicleMagazine);
if (_vehicleMagazine isEqualTo "") exitWith {false};

if ((_vehicle getArtilleryETA [_position, _vehicleMagazine]) isEqualTo -1) exitWith {false};

_vehicle doWatch _position;

[{
params ["_vehicle", "_position", "_spread", "_magazine", "_roundsLeft", "_lastFired"];
if (CBA_missionTime - _lastFired > 30) exitWith {true};

if (unitReady _vehicle) then {
_vehicle doArtilleryFire [[_position, _spread] call CBA_fnc_randPos, _magazine, 1];
_this set [4, _roundsLeft - 1];
_this set [5, CBA_missionTime];
};

if (_rounds <= 0 || {!alive _vehicle} || {!alive (gunner _vehicle)}) exitWith {
[{_this doWatch objNull}, _vehicle, 5] call CBA_fnc_waitAndExecute;
_vehicle setVariable [QEGVAR(csw,forcedMag), nil, true];
true
};
false
}, {}, [_vehicle, _position, _spread, _vehicleMagazine, _rounds, CBA_missionTime]] call CBA_fnc_waitUntilAndExecute;

true
5 changes: 5 additions & 0 deletions addons/csw/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ PREP(assemble_pickupWeapon);
PREP(canGetIn);
PREP(getIn);

PREP(compatibleMagazines);
PREP(getAvailableAmmo);
PREP(getCarryMagazine);
PREP(getNearbySources);
PREP(getSourceCompatibleMagazines);
PREP(proxyWeapon);

PREP(reload_actionsLoad);
Expand All @@ -32,6 +36,7 @@ PREP(reload_handleAddTurretMag);
PREP(reload_handleRemoveTurretMag);
PREP(reload_handleReturnAmmo);
PREP(reload_loadMagazine);
PREP(unloadMagazines);

PREP(staticWeaponInit);
PREP(staticWeaponInit_unloadExtraMags);
2 changes: 0 additions & 2 deletions addons/csw/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "script_component.hpp"

GVAR(vehicleMagCache) = createHashMap;

["CBA_settingsInitialized", {
TRACE_3("settingsInit",GVAR(defaultAssemblyMode),GVAR(handleExtraMagazines),GVAR(ammoHandling));
["StaticWeapon", "init", LINKFUNC(staticWeaponInit), true, [], true] call CBA_fnc_addClassEventHandler;
Expand Down
4 changes: 3 additions & 1 deletion addons/csw/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ PREP_RECOMPILE_END;
#include "initSettings.sqf"

GVAR(initializedStaticTypes) = [];
GVAR(vehicleMagCache) = createHashMap;
GVAR(compatibleMagsCache) = createHashMap;
GVAR(compatibleVehicleMagsCache) = createHashMap;

ADDON = true;

2 changes: 1 addition & 1 deletion addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Helper function for ace_rearm; Gets magazines that should be loaded by csw
*
* Arguments:
* 0: Vehicle <OBJECT>
* 0: CSW <OBJECT>
* 1: Specific Turret or pass bool to check all turrets <ARRAY><BOOL>(default: true)
*
* Return Value:
Expand Down
11 changes: 6 additions & 5 deletions addons/csw/functions/fnc_ai_handleFired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
* Public: No
*/

params ["_staticWeapon", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
TRACE_8("firedEH:",_staticWeapon,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile,_gunner);
params ["_vehicle", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
TRACE_8("firedEH:",_vehicle,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile,_gunner);

if ((!local _gunner) || {[_gunner] call EFUNC(common,isPlayer)}) exitWith {};
if (someAmmo _staticWeapon) exitWith {};
if (someAmmo _vehicle) exitWith {};
if (_vehicle getVariable [QGVAR(disabled), false]) exitWith {};

TRACE_2("need ammo",someAmmo _staticWeapon,magazinesAllTurrets _staticWeapon);
TRACE_2("need ammo",someAmmo _vehicle,magazinesAllTurrets _vehicle);

[_staticWeapon, _gunner, _weapon, _magazine] call FUNC(ai_reload);
[_vehicle, _gunner, _weapon] call FUNC(ai_reload);
22 changes: 15 additions & 7 deletions addons/csw/functions/fnc_ai_handleGetIn.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: Grim
* Handles AI GetIn on an empty weapon
* Author: LinkIsGrim
* Handles AI GetIn on an empty CSW
*
* Arguments:
* GetIn EH
Expand All @@ -11,12 +11,20 @@
*
* Public: No
*/
params ["_staticWeapon", "_role", "_gunner"];
TRACE_3("getInEH:",_staticWeapon,_role,_gunner);
params ["_vehicle", "_role", "_gunner", "_turret"];
TRACE_3("getInEH:",_vehicle,_role,_gunner);

if ((!local _gunner) || {[_gunner] call EFUNC(common,isPlayer)}) exitWith {};
if (someAmmo _staticWeapon) exitWith {};
if (someAmmo _vehicle) exitWith {};
if (_vehicle getVariable [QGVAR(disabled), false]) exitWith {};

TRACE_2("need ammo",someAmmo _staticWeapon,magazinesAllTurrets _staticWeapon);
// turret can be empty when AI is forcefully moved to the vehicle
if (_turret isEqualTo []) then {
_turret = (assignedVehicleRole _gunner) select 1;
};

[_staticWeapon, _gunner, currentWeapon _staticWeapon] call FUNC(ai_reload);
// this doesn't handle multi-weapon turrets, need a "turretWeapon" event or a PFH to do that
private _weapon = (_vehicle weaponsTurret _turret) select 0;
TRACE_4("need ammo",someAmmo _vehicle,magazinesAllTurrets _vehicle,_turret,_weapon);

[_vehicle, _gunner, _weapon] call FUNC(ai_reload);
100 changes: 34 additions & 66 deletions addons/csw/functions/fnc_ai_reload.sqf
Original file line number Diff line number Diff line change
@@ -1,95 +1,63 @@
#include "script_component.hpp"
/*
* Author: PabstMirror, modified by Grim
* Author: PabstMirror, LinkIsGrim
* Handles AI reloading
*
* Arguments:
* 0: Static Weapon <OBJECT>
* 0: CSW <OBJECT>
* 1: Gunner <OBJECT>
* 2: Weapon <STRING>
* 3: Magazine <STRING> (default: "")
* 2: Skip reload time <BOOL> (default: false)
*
* Return Value:
* None
*
* Public: No
*/
params ["_staticWeapon", "_gunner", "_weapon", ["_magazine", ""]];
params ["_vehicle", "_gunner", ["_instantReload", false]];
TRACE_3("AI reload",_vehicle,_gunner,_instantReload);

private _turretPath = [_gunner] call EFUNC(common,getTurretIndex);
private _reloadSource = objNull;
private _reloadMag = "";
private _reloadNeededAmmo = -1;
private _loadableMagazines = [_vehicle, _gunner, true] call FUNC(reload_getLoadableMagazines);
if (_loadableMagazines isEqualTo []) exitWith {TRACE_1("could not find reloadable mag",_vehicle)};

private _cfgMagGroups = configFile >> QGVAR(groups);
// API, to be used by artillerytables
private _forcedMag = _vehicle getVariable [QGVAR(forcedMag), ""];

private _nearSupplies = [_gunner] + ((_staticWeapon nearSupplies 10) select {
isNull (group _x) ||
{!([_x] call EFUNC(common,isPlayer)) && {[side group _gunner, side group _x] call BIS_fnc_sideIsFriendly}}
});
// If this is called while CSW has ammo, unload mags in gunner's turret
if (someAmmo _vehicle) then {[_vehicle, [_gunner] call EFUNC(common,getTurretIndex)] call FUNC(unloadMagazines)};

// Find if there is anything we can reload with
private _bestAmmo = 0;
private _magazineInfo = [];
{
scopeName "findSource";
private _xSource = _x;

private _cswMagazines = [];
{
_cswMagazines pushBackUnique _x;
} forEach ((magazineCargo _xSource) select {isClass (_cfgMagGroups >> _x)});
TRACE_2("",_xSource,_cswMagazines);

private _compatibleMags = [_weapon] call CBA_fnc_compatibleMagazines;
if (_magazine != "") then {
_compatibleMags insert [0, [_magazine]];
_x params ["_xMag", "", "", "", "", "_ammo"];
if (_forcedMag isNotEqualTo "" && {_xMag != _forcedMag}) then {continue};
if (_ammo > _bestAmmo) then {
_bestAmmo = _ammo;
_magazineInfo = _x;
};
} forEach _loadableMagazines;

{
private _xWeaponMag = _x;
{
if ((getNumber (_cfgMagGroups >> _x >> _xWeaponMag)) == 1) then {
private _loadInfo = [_staticWeapon, _turretPath, _x, _xSource] call FUNC(reload_canLoadMagazine);
if (_loadInfo select 0) then {
_reloadMag = _x;
_reloadSource = _xSource;
_reloadNeededAmmo = _loadInfo select 2;
TRACE_3("found mag",_reloadMag,_reloadSource,_x);
breakOut "findSource";
};
};
} forEach _cswMagazines;
} forEach _compatibleMags;
} forEach _nearSupplies;
if (_reloadMag == "") exitWith {TRACE_1("could not find mag",_reloadMag);};

// Figure out what we can add from the magazines we have
private _bestAmmoToSend = -1;
{
_x params ["_xMag", "_xAmmo"];
TRACE_2("",_xMag,_xAmmo);
if (_xMag == _reloadMag) then {
if ((_bestAmmoToSend == -1) || {(_xAmmo > _bestAmmoToSend) && {_xAmmo <= _reloadNeededAmmo}}) then {
_bestAmmoToSend = _xAmmo;
};
};
} forEach (if (_reloadSource isKindOf "CAManBase") then {magazinesAmmo _reloadSource} else {magazinesAmmoCargo _reloadSource});
TRACE_4("",_reloadSource,_reloadMag,_reloadNeededAmmo,_bestAmmoToSend);
if (_bestAmmoToSend == -1) exitWith {ERROR("No ammo");};
if (_magazineInfo isEqualTo []) exitWith {};
_magazineInfo params ["_carryMag", "_turretPath", "_loadInfo", "_magSource", "", "_ammo"];

// Remove the mag from the source
[_reloadSource, _reloadMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
[_magSource, _carryMag, _ammo] call EFUNC(common,removeSpecificMagazine);

// AI never returns ammo and removes the magazine before reloading, so we can skip distance and weaponHolder checks
private _eventParams = [_vehicle, _turretPath, objNull, _carryMag, _ammo, _gunner];

private _timeToLoad = 1;
if (!isNull(configOf _staticWeapon >> QUOTE(ADDON) >> "ammoLoadTime")) then {
_timeToLoad = getNumber(configOf _staticWeapon >> QUOTE(ADDON) >> "ammoLoadTime");
if (_instantReload) exitWith {
TRACE_1("calling addTurretMag event: instant AI reload",_this);
[QGVAR(addTurretMag), _eventParams] call CBA_fnc_globalEvent;
};

private _timeToLoad = GET_NUMBER(configOf _vehicle >> QUOTE(ADDON) >> "ammoLoadTime", 1);

TRACE_1("Reloading in progress",_timeToLoad);
[{
params ["_staticWeapon", "_turretPath", "_gunner", "_reloadMag", "_bestAmmoToSend"];
if ((!alive _staticWeapon) || {!alive _gunner} || {(_staticWeapon distance _gunner) > 10}) exitWith {TRACE_1("invalid state",_this);};
params ["_vehicle", "", "", "", "", "_gunner"];
if !(alive _vehicle && {alive _gunner}) exitWith {TRACE_2("invalid state",alive _vehicle,alive _gunner);};

// Reload the static weapon
TRACE_5("calling addTurretMag event",_staticWeapon,_turretPath,_gunner,_reloadMag,_bestAmmoToSend);
TRACE_1("calling addTurretMag event: AI reload",_this);
[QGVAR(addTurretMag), _this] call CBA_fnc_globalEvent;
}, [_staticWeapon, _turretPath, _gunner, _reloadMag, _bestAmmoToSend], _timeToLoad] call CBA_fnc_waitAndExecute;
}, _eventParams, _timeToLoad] call CBA_fnc_waitAndExecute;
11 changes: 5 additions & 6 deletions addons/csw/functions/fnc_assemble_canPickupWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* If the CSW is mounted or in use this will not allow you to dismount the weapon
*
* Arguments:
* 0: Static Weapon <OBJECT>
* 0: CSW <OBJECT>
*
* Return Value:
* Can Dismount <BOOL>
Expand All @@ -15,12 +15,11 @@
* Public: No
*/

params ["_staticWeapon"];
params ["_vehicle"];

// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default]
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_staticWeapon getVariable [QGVAR(assemblyMode), 3]);
private _notCrewed = (crew _staticWeapon) isEqualTo [];
private _deadCrew = !(alive (gunner _staticWeapon)); // need to eject body???
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_vehicle getVariable [QGVAR(assemblyMode), 3]);
private _notCrewed = (crew _vehicle) isEqualTo [];
private _deadCrew = !(alive (gunner _vehicle)); // need to eject body???

_assemblyMode && {_notCrewed || _deadCrew}

Loading