diff --git a/addons/fcs/XEH_preInit.sqf b/addons/fcs/XEH_preInit.sqf index 2bcda4f464..c3fa171adf 100644 --- a/addons/fcs/XEH_preInit.sqf +++ b/addons/fcs/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(adjustRange); +PREP(calculateSolution); PREP(canResetFCS); PREP(canUseFCS); PREP(canUseRangefinder); diff --git a/addons/fcs/functions/fnc_calculateSolution.sqf b/addons/fcs/functions/fnc_calculateSolution.sqf new file mode 100644 index 0000000000..04ea13ed9a --- /dev/null +++ b/addons/fcs/functions/fnc_calculateSolution.sqf @@ -0,0 +1,71 @@ +/* + * Author: VKing + * Calculate FCS solution + * + * Arguments: + * 0: Vehicle + * 1: Turret + * 2: Target distance + * 3: Azimuth offset + * + * Return value: + * None + * + * Public: No + */ +#include "script_component.hpp" +params ["_vehicle","_turret","_distance","_angleTarget"]; + +private _FCSMagazines = []; +private _FCSElevation = []; +private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath); + +{ + private _magazine = _x; + private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); + + if !(getText (configFile >> "CfgAmmo" >> _ammo >> "simulation") == "shotMissile") then { + private _maxElev = getNumber (_turretConfig >> "maxElev"); + private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); + private _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction"); + + { + private ["_weapon", "_muzzles", "_weaponMagazines", "_muzzleMagazines"]; + _weapon = _x; + _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles"); + _weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"); + + { + if (_x != "this") then { + _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines"); + _weaponMagazines append _muzzleMagazines; + }; + false + } count _muzzles; + + if (_magazine in _weaponMagazines) exitWith { + private _initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed"); + + if (_initSpeedCoef < 0) then { + _initSpeed = _initSpeed * -_initSpeedCoef; + }; + + if (_initSpeedCoef > 0) then { + _initSpeed = _initSpeedCoef; + }; + }; + false + } count (_vehicle weaponsTurret _turret); + + private _offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance]; + _offset = parseNumber _offset; + + _FCSMagazines pushBack _magazine; + _FCSElevation pushBack _offset; + }; + false +} count (_vehicle magazinesTurret _turret); + +[_vehicle, format ["%1_%2", QGVAR(Distance), _turret], _distance] call EFUNC(common,setVariablePublic); +[_vehicle, format ["%1_%2", QGVAR(Magazines), _turret], _FCSMagazines] call EFUNC(common,setVariablePublic); +[_vehicle, format ["%1_%2", QGVAR(Elevation), _turret], _FCSElevation] call EFUNC(common,setVariablePublic); diff --git a/addons/fcs/functions/fnc_keyDown.sqf b/addons/fcs/functions/fnc_keyDown.sqf index 1e955ef2e3..ffa86509d5 100644 --- a/addons/fcs/functions/fnc_keyDown.sqf +++ b/addons/fcs/functions/fnc_keyDown.sqf @@ -41,3 +41,5 @@ if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turr }; GVAR(Position) = (getPosASL _vehicle) vectorAdd (_weaponDirection vectorMultiply _distance); + +[_vehicle,_turret,_distance,0] call FUNC(calculateSolution); diff --git a/addons/fcs/functions/fnc_keyUp.sqf b/addons/fcs/functions/fnc_keyUp.sqf index 637798b5fd..00d220247d 100644 --- a/addons/fcs/functions/fnc_keyUp.sqf +++ b/addons/fcs/functions/fnc_keyUp.sqf @@ -27,6 +27,7 @@ if (isNil "_distance") then { ] call FUNC(getRange); }; +// MOVING TARGETS private _weapon = _vehicle currentWeaponTurret _turret; private _weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets @@ -40,7 +41,6 @@ if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turr private _angleTarget = asin (_weaponDirection select 2); -// MOVING TARGETS private _movingAzimuth = 0; if (ACE_time - GVAR(time) > 1 && GVAR(time) != -1 && isNil {_this select 2}) then { @@ -56,13 +56,17 @@ if (ACE_time - GVAR(time) > 1 && GVAR(time) != -1 && isNil {_this select 2}) the private _timeToLive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "timeToLive"); private _simulationStep = getNumber (configFile >> "CfgAmmo" >> _ammo >> "simulationStep"); private _initSpeedCoef = getNumber (configFile >> "CfgWeapons" >> _weapon >> "initSpeed"); + private _simulationType = getNumber (configFile >> "CfgAmmo" >> _ammo >> "simulation"); - if (_initSpeedCoef < 0) then { - _initSpeed = _initSpeed * - _initSpeedCoef; - }; + // More BIS fix + if (_simulationType == "shotBullet") then { + if (_initSpeedCoef < 0) then { + _initSpeed = _initSpeed * - _initSpeedCoef; + }; - if (_initSpeedCoef > 0) then { - _initSpeed = _initSpeedCoef; + if (_initSpeedCoef > 0) then { + _initSpeed = _initSpeedCoef; + }; }; if (_simulationStep != 0) then { @@ -105,61 +109,11 @@ if (_viewDiff != 0) then { _FCSAzimuth = (atan (_distance / _viewDiff) - (abs _viewDiff / _viewDiff) * 90) + _movingAzimuth; }; -// CALCULATE OFFSET -private _FCSMagazines = []; -private _FCSElevation = []; - -{ - private _magazine = _x; - private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); - - if !(getText (configFile >> "CfgAmmo" >> _ammo >> "simulation") == "shotMissile") then { - private _maxElev = getNumber (_turretConfig >> "maxElev"); - private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); - private _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction"); - - { - private ["_weapon", "_muzzles", "_weaponMagazines", "_muzzleMagazines"]; - _weapon = _x; - _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles"); - _weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines"); - - { - if (_x != "this") then { - _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines"); - _weaponMagazines append _muzzleMagazines; - }; - false - } count _muzzles; - - if (_magazine in _weaponMagazines) exitWith { - _initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed"); - - if (_initSpeedCoef < 0) then { - _initSpeed = _initSpeed * -_initSpeedCoef; - }; - - if (_initSpeedCoef > 0) then { - _initSpeed = _initSpeedCoef; - }; - }; - false - } count (_vehicle weaponsTurret _turret); - - private _offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance]; - _offset = parseNumber _offset; - - _FCSMagazines pushBack _magazine; - _FCSElevation pushBack _offset; - }; - false -} count (_vehicle magazinesTurret _turret); - -[_vehicle, format ["%1_%2", QGVAR(Distance), _turret], _distance] call EFUNC(common,setVariablePublic); -[_vehicle, format ["%1_%2", QGVAR(Magazines), _turret], _FCSMagazines] call EFUNC(common,setVariablePublic); -[_vehicle, format ["%1_%2", QGVAR(Elevation), _turret], _FCSElevation] call EFUNC(common,setVariablePublic); [_vehicle, format ["%1_%2", QGVAR(Azimuth), _turret], _FCSAzimuth] call EFUNC(common,setVariablePublic); +// CALCULATE SOLUTION +[_vehicle,_turret,_distance,_angleTarget] call FUNC(calculateSolution); + if (_playSound) then { playSound "ACE_Sound_Click"; };