diff --git a/addons/fcs/functions/fnc_firedEH.sqf b/addons/fcs/functions/fnc_firedEH.sqf index 698a9bef22..31fe38335d 100644 --- a/addons/fcs/functions/fnc_firedEH.sqf +++ b/addons/fcs/functions/fnc_firedEH.sqf @@ -12,7 +12,7 @@ #include "script_component.hpp" -private ["_vehicle", "_weapon", "_ammo", "_magazine", "_projectile","_velocityCorrection"]; +private ["_vehicle", "_weapon", "_ammo", "_magazine", "_projectile", "_sumVelocity"]; _vehicle = _this select 0; _weapon = _this select 1; @@ -43,12 +43,8 @@ _offset = 0; }; } forEach _FCSMagazines; -// Correct velocity for weapons that have initVelocity -// @todo: Take into account negative initVelocities -_velocityCorrection = (vectorMagnitude velocity _projectile) - - getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); -[_projectile, (_vehicle getVariable format ["%1_%2", QGVAR(Azimuth), _turret]), _offset, -_velocityCorrection] call EFUNC(common,changeProjectileDirection); +[_projectile, (_vehicle getVariable format ["%1_%2", QGVAR(Azimuth), _turret]), _offset, 0] call EFUNC(common,changeProjectileDirection); // Remove the platform velocity if( (vectorMagnitude velocity _vehicle) > 2) then { diff --git a/addons/fcs/functions/fnc_keyUp.sqf b/addons/fcs/functions/fnc_keyUp.sqf index 433053178b..a7bf8defe5 100644 --- a/addons/fcs/functions/fnc_keyUp.sqf +++ b/addons/fcs/functions/fnc_keyUp.sqf @@ -12,7 +12,7 @@ #include "script_component.hpp" -private ["_vehicle", "_turret", "_turretConfig", "_distance", "_magazines", "_showHint", "_playSound"]; +private ["_vehicle", "_turret", "_turretConfig", "_distance", "_weapons", "_magazines", "_showHint", "_playSound"]; _vehicle = _this select 0; _turret = _this select 1; @@ -21,6 +21,7 @@ _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call E _distance = call FUNC(getRange); +_weapons = _vehicle weaponsTurret _turret; _magazines = _vehicle magazinesTurret _turret; if (_distance == 0) then { @@ -31,9 +32,9 @@ if (_distance == 0) then { ] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision }; -private ["_weaponDirection", "_angleTarget"]; - -_weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets +private ["_weapon", "_weaponDirection", "_angleTarget"]; +_weapon = _vehicle currentWeaponTurret _turret; +_weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then { _weaponDirection = eyeDirection _vehicle; @@ -55,7 +56,7 @@ if (!(isNil QGVAR(backgroundCalculation)) and {!(scriptDone GVAR(backgroundCalcu terminate GVAR(backgroundCalculation); }; -private "_movingAzimuth"; +private ["_movingAzimuth", "_posTarget", "_velocityTarget"]; // MOVING TARGETS _movingAzimuth = 0; @@ -72,7 +73,7 @@ if (time - GVAR(time) > 1 and GVAR(time) != -1 and count _this < 3) then { ((_posTarget select 2) - (GVAR(position) select 2)) / (time - GVAR(time)) ]; - private ["_magazineType", "_ammoType", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep"]; + private ["_magazineType", "_ammoType", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep", "_initSpeedCoef", "_velocityMagnitude"]; // estimate time to target _magazineType = _vehicle currentMagazineTurret _turret; @@ -82,6 +83,14 @@ if (time - GVAR(time) > 1 and GVAR(time) != -1 and count _this < 3) then { _timeToLive = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "timeToLive"); _simulationStep = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "simulationStep"); + _initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed"); + if (_initSpeedCoef < 0) then { + _initSpeed = _initSpeed * -_initSpeedCoef; + }; + if (_initSpeedCoef > 0) then { + _initSpeed = _initSpeedCoef; + }; + if (_simulationStep != 0) then { private ["_posX", "_velocityX", "_velocityY", "_timeToTarget"]; @@ -138,21 +147,43 @@ _FCSMagazines = []; _FCSElevation = []; { - private "_ammoType"; - - _ammoType = getText (configFile >> "CfgMagazines" >> _x >> "ammo"); + private ["_magazine", "_ammoType"]; + _magazine = _x; + _ammoType = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); if !(getText (configFile >> "CfgAmmo" >> _ammoType >> "simulation") == "shotMissile") then { private ["_maxElev", "_initSpeed", "_airFriction", "_offset"]; _maxElev = getNumber (_turretConfig >> "maxElev"); - _initSpeed = getNumber (configFile >> "CfgMagazines" >> _x >> "initSpeed"); + _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "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; + }; + } forEach _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; + }; + }; + } forEach _weapons; + _offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance]; _offset = parseNumber _offset; - _FCSMagazines = _FCSMagazines + [_x]; + _FCSMagazines = _FCSMagazines + [_magazine]; _FCSElevation = _FCSElevation + [_offset]; }; } forEach _magazines;