From bb49272afd2def05cca36bd4702fc411438a17c2 Mon Sep 17 00:00:00 2001 From: oOKexOo Date: Thu, 6 Sep 2018 01:09:43 +0200 Subject: [PATCH 1/4] Handle VLS --- .../fn_FireSupportArtilleryFireMission.sqf | 144 ++++++++++++------ 1 file changed, 98 insertions(+), 46 deletions(-) diff --git a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf index 7574bafc..8c42bb78 100644 --- a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf +++ b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf @@ -11,15 +11,6 @@ private ["_objects","_guns","_rounds","_ammo","_targetPos", "_artilleryAmmoDispl _objects = nearestObjects [(_this select 0), ["All"], 150, true]; -// Filter for artillery -private _filteredObjects = []; -{ - _ammo = getArtilleryAmmo [_x]; - if (count _ammo > 0) then { _filteredObjects pushBack _x; }; - -} forEach _objects; - - /** * Group by type. The structure of batteries is * [ @@ -29,27 +20,37 @@ private _filteredObjects = []; */ private _batteries = []; { - private _type = getText(configfile >> "CfgVehicles" >> (typeOf _x) >> "displayName"); - private _alreadyContained = count (_batteries select {_x find _type > -1}) > 0; - - if (!_alreadyContained) then + if (_x isKindOf "B_Ship_MRLS_01_base_F") then { - _ammo = getArtilleryAmmo [_x]; - _batteries pushBack [_type, [_x], _ammo]; + // handle VLS + _ammo = magazines _x; } else { - private _unit = _x; + _ammo = getArtilleryAmmo [_x]; + }; + if (count _ammo > 0) then + { + private _type = getText(configfile >> "CfgVehicles" >> (typeOf _x) >> "displayName"); + private _alreadyContained = count (_batteries select {_x find _type > -1}) > 0; + + if (!_alreadyContained) then { - private _battery = _x; - private _units = _battery select 1; - private _unitType = getText (configfile >> "CfgVehicles" >> (typeOf _unit) >> "displayName"); + _batteries pushBack [_type, [_x], _ammo]; + } + else + { + private _unit = _x; + { + private _battery = _x; + private _units = _battery select 1; + private _unitType = getText (configfile >> "CfgVehicles" >> (typeOf _unit) >> "displayName"); - if (_unitType == (_battery select 0)) then { _units pushBack _unit }; - } forEach _batteries; + if (_unitType == (_battery select 0)) then { _units pushBack _unit }; + } forEach _batteries; + }; }; - -} forEach _filteredObjects; +} forEach _objects; // pick battery if (_batteries isEqualTo []) exitWith { [localize "STR_AMAE_NO_NEARBY_ARTILLERY_UNITS"] call Ares_fnc_ShowZeusMessage; }; @@ -68,16 +69,17 @@ private _mode = _pickBatteryResult select 1; // Pick fire mission details private _fireMission = nil; -private _units = _battery select 1; -private _artilleryAmmo = _battery select 2; - -_artilleryAmmoDisplayName = (_battery select 2) apply {getText (configFile >> "CfgMagazines" >> _x >> "displayName")}; +_battery params ["", "_units", "_artilleryAmmo"]; +private _firstUnit = _units param [0, objNull]; +private _isVLS = _firstUnit isKindOf "B_Ship_MRLS_01_base_F"; +private _artilleryAmmoDisplayName = _artilleryAmmo apply {getText (configFile >> "CfgMagazines" >> _x >> "displayName")}; private _numberOfGuns = []; { _numberOfGuns pushBack (str (_forEachIndex + 1)); } forEach _units; +private _selectedTarget = objNull; if (_mode == 0) then { private _allTargetsUnsorted = allMissionObjects "Achilles_Create_Universal_Target_Module"; @@ -108,12 +110,19 @@ if (_mode == 0) then private _targetChooseAlgorithm = _pickFireMissionResult select 3; // Make sure we only consider targets that are in range. - private _targetsInRange = _allTargets select {(position _x) inRangeOfArtillery [[_units select 0], _ammo]}; - + private _targetsInRange = if (_isVLS) then + { + _allTargets + } + else + { + _allTargets select {(position _x) inRangeOfArtillery [[_units select 0], _ammo]} + }; + if (count _targetsInRange > 0) then { // Choose a target to fire at - private _selectedTarget = switch (_targetChooseAlgorithm) do + _selectedTarget = switch (_targetChooseAlgorithm) do { case 0: // Random { @@ -162,26 +171,69 @@ if (_mode == 0) then if (isNil "_targetPos") exitWith {[localize "STR_AMAE_NO_TARGET_IN_RANGE"] call Ares_fnc_ShowZeusMessage; playSound "FD_Start_F"}; +private _roundEta = 99999; // Generate a list of the actual units to fire. -private _gunsToFire = []; -for "_i" from 1 to _guns do +private _gunsToFire = _units select [0, _guns]; +if (_isVLS) then { - _gunsToFire pushBack (_units select (_i - 1)); -}; - -// Get the ETA and exit if any one of the guns can't reach the target. -private _roundEta = 99999; + // handle VLS + private _weaponClass = (weapons _firstUnit) param [0,""]; + private _missileClass = getText (configfile >> "CfgMagazines" >> _ammo >> "ammo"); + private _missileMaxSpeed = getNumber (configfile >> "CfgAmmo" >> _missileClass >> "maxSpeed"); + private _reloadTime = getNumber (configFile >> "cfgWeapons" >> _weaponClass >> "reloadTime"); + private _magazineReloadTime = (1.3*getNumber (configfile >> "CfgWeapons" >> _weaponClass >> "magazineReloadTime")); + systemChat str [_reloadTime, _magazineReloadTime]; + _roundEta = _roundEta min ((_targetPos distance _firstUnit) / _missileMaxSpeed); + { + [_x, _weaponClass, _ammo, _rounds, _roundEta, _reloadTime, _magazineReloadTime, _targetPos, _selectedTarget, _precision] spawn + { + params ["_unit", "_weaponClass", "_ammo", "_rounds", "_roundEta", "_reloadTime", "_magazineReloadTime", "_targetPos", "_selectedTarget", "_precision"]; + // switch the magazine if needed + if (_unit currentMagazineTurret [0] != _ammo) then + { + [_unit, [[0], _weaponClass, _ammo]] remoteExecCall ["loadMagazine", _unit]; + sleep _magazineReloadTime; + }; + // create and reveal the target + private _theta = random 360; + private _deviation = [sin _theta, cos _theta, 0] vectorMultiply (random _precision); + private _target = (createGroup sideLogic) createUnit ["module_f", _targetPos vectorAdd _deviation, [], 0, "CAN_COLLIDE"]; + systemChat str [_target, position _target]; + if !(isNull _selectedTarget) then + { + _target attachTo [_selectedTarget, _deviation]; + }; + [side _unit, [_target, (1.3*_roundEta max 10) + _reloadTime*_rounds]] remoteExecCall ["reportRemoteTarget", _unit]; + // fire the rounds + for "_i" from 1 to _rounds do + { + [_unit, [gunner _unit, _weaponClass, 0]] remoteExecCall ["setWeaponReloadingTime", _unit]; + [_unit, [_target]] remoteExecCall ["fireAtTarget", _unit]; + sleep _reloadTime; + }; + sleep (1.3*_roundEta max 10); + detach _target; + deleteVehicle _target; + }; + } forEach _gunsToFire; +} +else { - _roundEta = _roundEta min (_x getArtilleryETA [_targetPos, _ammo]); -} forEach _gunsToFire; -if (_roundEta == -1) exitWith { [localize "STR_AMAE_NO_TARGET_IN_RANGE"] call Ares_fnc_ShowZeusMessage; }; + // handle artillery -// Fire the guns -{ - private _theta = random 360; - private _deviation = [sin _theta, cos _theta, 0] vectorMultiply (random _precision); - [_x, [_targetPos vectorAdd _deviation, _ammo, _rounds]] remoteExecCall ["commandArtilleryFire", _x]; -} forEach _gunsToFire; + // Get the ETA and exit if any one of the guns can't reach the target. + { + _roundEta = _roundEta min (_x getArtilleryETA [_targetPos, _ammo]); + } forEach _gunsToFire; + if (_roundEta == -1) exitWith { [localize "STR_AMAE_NO_TARGET_IN_RANGE"] call Ares_fnc_ShowZeusMessage; }; + + // Fire the guns + { + private _theta = random 360; + private _deviation = [sin _theta, cos _theta, 0] vectorMultiply (random _precision); + [_x, [_targetPos vectorAdd _deviation, _ammo, _rounds]] remoteExecCall ["commandArtilleryFire", _x]; + } forEach _gunsToFire; +}; [localize "STR_AMAE_FIRE_ROUNDS_AND_ETA", _rounds, _ammoSelectedDisplayName, _roundEta] call Ares_fnc_ShowZeusMessage; From e7210963143d0f193c076a7bd8fb4999c8be7257 Mon Sep 17 00:00:00 2001 From: oOKexOo Date: Mon, 17 Sep 2018 20:49:16 +0200 Subject: [PATCH 2/4] Remove loggers --- .../functions/fn_FireSupportArtilleryFireMission.sqf | 2 -- 1 file changed, 2 deletions(-) diff --git a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf index 8c42bb78..0cb6ca3d 100644 --- a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf +++ b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf @@ -182,7 +182,6 @@ if (_isVLS) then private _missileMaxSpeed = getNumber (configfile >> "CfgAmmo" >> _missileClass >> "maxSpeed"); private _reloadTime = getNumber (configFile >> "cfgWeapons" >> _weaponClass >> "reloadTime"); private _magazineReloadTime = (1.3*getNumber (configfile >> "CfgWeapons" >> _weaponClass >> "magazineReloadTime")); - systemChat str [_reloadTime, _magazineReloadTime]; _roundEta = _roundEta min ((_targetPos distance _firstUnit) / _missileMaxSpeed); { [_x, _weaponClass, _ammo, _rounds, _roundEta, _reloadTime, _magazineReloadTime, _targetPos, _selectedTarget, _precision] spawn @@ -198,7 +197,6 @@ if (_isVLS) then private _theta = random 360; private _deviation = [sin _theta, cos _theta, 0] vectorMultiply (random _precision); private _target = (createGroup sideLogic) createUnit ["module_f", _targetPos vectorAdd _deviation, [], 0, "CAN_COLLIDE"]; - systemChat str [_target, position _target]; if !(isNull _selectedTarget) then { _target attachTo [_selectedTarget, _deviation]; From 10e0604cc5785cc960a3c0e8adae3d14938e2ab1 Mon Sep 17 00:00:00 2001 From: oOKexOo Date: Thu, 20 Sep 2018 21:52:34 +0200 Subject: [PATCH 3/4] Address CreepPork's glorious review --- .../functions/fn_FireSupportArtilleryFireMission.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf index 0cb6ca3d..0b904969 100644 --- a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf +++ b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf @@ -201,7 +201,7 @@ if (_isVLS) then { _target attachTo [_selectedTarget, _deviation]; }; - [side _unit, [_target, (1.3*_roundEta max 10) + _reloadTime*_rounds]] remoteExecCall ["reportRemoteTarget", _unit]; + [side _unit, [_target, ((1.3 * _roundEta) max 10) + _reloadTime*_rounds]] remoteExecCall ["reportRemoteTarget", _unit]; // fire the rounds for "_i" from 1 to _rounds do { @@ -209,7 +209,7 @@ if (_isVLS) then [_unit, [_target]] remoteExecCall ["fireAtTarget", _unit]; sleep _reloadTime; }; - sleep (1.3*_roundEta max 10); + sleep ((1.3 * _roundEta) max 10); detach _target; deleteVehicle _target; }; From 03eae0b2c6f9fc94aedf5ff83334a67bafadd2e1 Mon Sep 17 00:00:00 2001 From: oOKexOo Date: Sat, 22 Sep 2018 00:15:50 +0200 Subject: [PATCH 4/4] Use underscore for unused variable --- .../functions/fn_FireSupportArtilleryFireMission.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf index 0b904969..53f7c47d 100644 --- a/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf +++ b/@AresModAchillesExpansion/addons/modules_f_ares/FireSupport/functions/fn_FireSupportArtilleryFireMission.sqf @@ -69,7 +69,7 @@ private _mode = _pickBatteryResult select 1; // Pick fire mission details private _fireMission = nil; -_battery params ["", "_units", "_artilleryAmmo"]; +_battery params ["_", "_units", "_artilleryAmmo"]; private _firstUnit = _units param [0, objNull]; private _isVLS = _firstUnit isKindOf "B_Ship_MRLS_01_base_F"; private _artilleryAmmoDisplayName = _artilleryAmmo apply {getText (configFile >> "CfgMagazines" >> _x >> "displayName")};