2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi
|
|
|
|
* Calculates the offsets for all weapons needed to hit the current target.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-12-10 15:00:14 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
|
|
|
* 1: Turret <ARRAY>
|
2015-01-11 16:42:31 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-12-10 15:00:14 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-11 16:42:31 +00:00
|
|
|
*/
|
2015-01-12 10:02:44 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
params ["_vehicle", "_turret", "_distance", ["_showHint", false], ["_playSound", true]];
|
2015-02-04 02:20:55 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
|
2015-02-04 02:20:55 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
call (updateRangeHUD);
|
2015-01-13 21:51:02 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
if (isNil "_distance") then {
|
|
|
|
_distance = call FUNC(getRange);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
if (_distance == 0) then {
|
|
|
|
_distance = [
|
|
|
|
getNumber (_turretConfig >> QGVAR(DistanceInterval)),
|
|
|
|
getNumber (_turretConfig >> QGVAR(MaxDistance)),
|
|
|
|
getNumber (_turretConfig >> QGVAR(MinDistance))
|
|
|
|
] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision
|
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
private _weapon = _vehicle currentWeaponTurret _turret;
|
|
|
|
private _weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets
|
2015-02-11 19:59:41 +00:00
|
|
|
|
2015-03-25 22:03:45 +00:00
|
|
|
if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then {
|
2015-02-11 19:59:41 +00:00
|
|
|
_weaponDirection = eyeDirection _vehicle;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turrets
|
|
|
|
_weaponDirection = [1,0,0];
|
|
|
|
};
|
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
private _angleTarget = asin (_weaponDirection select 2);
|
2015-02-03 22:03:43 +00:00
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
// MOVING TARGETS
|
2015-12-10 15:00:14 +00:00
|
|
|
private _movingAzimuth = 0;
|
|
|
|
|
|
|
|
if (ACE_time - GVAR(time) > 1 && GVAR(time) != -1 && isNil {_this select 2}) then {
|
2015-01-14 20:07:41 +00:00
|
|
|
// calculate speed of target
|
2015-12-10 15:00:14 +00:00
|
|
|
private _posTarget = (getPosASL _vehicle) vectorAdd (_weaponDirection vectorMultiply _distance);
|
|
|
|
private _velocityTarget = (_posTarget vectorDiff GVAR(position)) vectorMultiply (1 / (ACE_time - GVAR(time)));
|
2015-02-03 22:03:43 +00:00
|
|
|
|
2015-10-21 20:52:21 +00:00
|
|
|
// estimate time to target
|
2015-12-10 15:00:14 +00:00
|
|
|
private _magazine = _vehicle currentMagazineTurret _turret;
|
|
|
|
private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo");
|
|
|
|
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
|
|
|
|
private _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction");
|
|
|
|
private _timeToLive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "timeToLive");
|
|
|
|
private _simulationStep = getNumber (configFile >> "CfgAmmo" >> _ammo >> "simulationStep");
|
|
|
|
private _initSpeedCoef = getNumber (configFile >> "CfgWeapons" >> _weapon >> "initSpeed");
|
|
|
|
|
2015-05-01 14:02:34 +00:00
|
|
|
if (_initSpeedCoef < 0) then {
|
2015-12-10 15:00:14 +00:00
|
|
|
_initSpeed = _initSpeed * - _initSpeedCoef;
|
2015-05-01 14:02:34 +00:00
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-05-01 16:55:44 +00:00
|
|
|
if (_initSpeedCoef > 0) then {
|
|
|
|
_initSpeed = _initSpeedCoef;
|
|
|
|
};
|
2015-10-21 20:17:28 +00:00
|
|
|
|
2015-01-14 20:07:41 +00:00
|
|
|
if (_simulationStep != 0) then {
|
2015-12-10 15:00:14 +00:00
|
|
|
private _posX = 0;
|
|
|
|
private _velocityX = _initSpeed;
|
|
|
|
private _velocityY = 0;
|
|
|
|
private _timeToTarget = 0;
|
2015-02-03 22:03:43 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
for "_i" from 1 to (floor (_timeToLive / _simulationStep) + 1) do {
|
2015-01-14 20:07:41 +00:00
|
|
|
_posX = _posX + _velocityX * _simulationStep;
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-01-14 20:07:41 +00:00
|
|
|
if (_posX >= _distance) exitWith { // bullet passed the target
|
|
|
|
_timeToTarget = _i * _simulationStep;
|
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
|
|
|
|
private _velocityMagnitude = sqrt (_velocityX ^ 2 + _velocityY ^ 2);
|
|
|
|
|
2015-01-14 20:07:41 +00:00
|
|
|
_velocityX = _velocityX + _velocityX * _velocityMagnitude * _airFriction * _simulationStep;
|
|
|
|
_velocityY = _velocityY + _velocityY * _velocityMagnitude * _airFriction * _simulationStep - 9.81 * _simulationStep;
|
|
|
|
};
|
|
|
|
|
|
|
|
// calculate offsets
|
2015-12-10 15:00:14 +00:00
|
|
|
private _posArrival = _posTarget vectorAdd (_velocityTarget vectorMultiply _timeToTarget);
|
|
|
|
private _dirArrival = (_posArrival vectorDiff getPosASL _vehicle) vectorMultiply (1 / (_posArrival vectorDistance getPosASL _vehicle));
|
2015-01-14 20:07:41 +00:00
|
|
|
|
|
|
|
_movingAzimuth = ((_dirArrival select 0) atan2 (_dirArrival select 1)) - ((_weaponDirection select 0) atan2 (_weaponDirection select 1));
|
|
|
|
_angleTarget = asin (_dirArrival select 2);
|
2015-12-10 15:00:14 +00:00
|
|
|
_distance = floor (_posArrival distance (getPosASL _vehicle));
|
2015-01-14 20:07:41 +00:00
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-01-12 10:02:44 +00:00
|
|
|
GVAR(enabled) = false;
|
2015-10-21 20:17:28 +00:00
|
|
|
GVAR(time) = -1;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
// CALCULATE AZIMUTH CORRECTION
|
2015-12-10 15:00:14 +00:00
|
|
|
private _viewDiff = _vehicle getVariable format ["%1_%2", QGVAR(ViewDiff), _turret];
|
|
|
|
private _FCSAzimuth = _movingAzimuth;
|
2015-02-03 22:03:43 +00:00
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
if (_viewDiff != 0) then {
|
2015-01-14 20:07:41 +00:00
|
|
|
_FCSAzimuth = (atan (_distance / _viewDiff) - (abs _viewDiff / _viewDiff) * 90) + _movingAzimuth;
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2015-01-16 23:09:19 +00:00
|
|
|
// CALCULATE OFFSET
|
2015-12-10 15:00:14 +00:00
|
|
|
private _FCSMagazines = [];
|
|
|
|
private _FCSElevation = [];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-01-16 23:09:19 +00:00
|
|
|
{
|
2015-12-10 15:00:14 +00:00
|
|
|
private _magazine = _x;
|
|
|
|
private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo");
|
2015-02-03 22:03:43 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
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");
|
2015-10-21 20:17:28 +00:00
|
|
|
|
2015-05-01 15:39:38 +00:00
|
|
|
{
|
|
|
|
private ["_weapon", "_muzzles", "_weaponMagazines", "_muzzleMagazines"];
|
|
|
|
_weapon = _x;
|
|
|
|
_muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
|
|
|
|
_weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-05-01 15:39:38 +00:00
|
|
|
{
|
|
|
|
if (_x != "this") then {
|
|
|
|
_muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
|
|
|
|
_weaponMagazines append _muzzleMagazines;
|
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
false
|
|
|
|
} count _muzzles;
|
|
|
|
|
2015-05-01 15:39:38 +00:00
|
|
|
if (_magazine in _weaponMagazines) exitWith {
|
|
|
|
_initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed");
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-05-01 15:39:38 +00:00
|
|
|
if (_initSpeedCoef < 0) then {
|
|
|
|
_initSpeed = _initSpeed * -_initSpeedCoef;
|
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
|
2015-05-01 16:55:44 +00:00
|
|
|
if (_initSpeedCoef > 0) then {
|
|
|
|
_initSpeed = _initSpeedCoef;
|
|
|
|
};
|
2015-05-01 15:39:38 +00:00
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
false
|
|
|
|
} count (_vehicle weaponsTurret _turret);
|
2015-10-21 20:17:28 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
private _offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance];
|
2015-01-16 23:09:19 +00:00
|
|
|
_offset = parseNumber _offset;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
_FCSMagazines pushBack _magazine;
|
|
|
|
_FCSElevation pushBack _offset;
|
2015-01-16 23:09:19 +00:00
|
|
|
};
|
2015-12-10 15:00:14 +00:00
|
|
|
false
|
|
|
|
} count (_vehicle magazinesTurret _turret);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
[_vehicle, format ["%1_%2", QGVAR(Distance), _turret], _distance] call EFUNC(common,setVariablePublic);
|
2015-02-14 04:05:02 +00:00
|
|
|
[_vehicle, format ["%1_%2", QGVAR(Magazines), _turret], _FCSMagazines] call EFUNC(common,setVariablePublic);
|
|
|
|
[_vehicle, format ["%1_%2", QGVAR(Elevation), _turret], _FCSElevation] call EFUNC(common,setVariablePublic);
|
2015-12-10 15:00:14 +00:00
|
|
|
[_vehicle, format ["%1_%2", QGVAR(Azimuth), _turret], _FCSAzimuth] call EFUNC(common,setVariablePublic);
|
2015-04-06 21:57:07 +00:00
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
if (_playSound) then {
|
2015-04-06 21:57:07 +00:00
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
};
|
|
|
|
|
2015-12-10 15:00:14 +00:00
|
|
|
if (_showHint) then {
|
2015-05-28 19:59:04 +00:00
|
|
|
[format ["%1: %2", localize LSTRING(ZeroedTo), _distance]] call EFUNC(common,displayTextStructured);
|
2015-10-21 20:17:28 +00:00
|
|
|
};
|
2015-11-13 08:57:06 +00:00
|
|
|
|
|
|
|
//Update the hud's distance display to the new value or "----" if out of range
|
|
|
|
//(10m fudge because of EFUNC(common,getTargetDistance))
|
2015-12-10 15:00:14 +00:00
|
|
|
if (_distance + 10 >= getNumber (_turretConfig >> QGVAR(MaxDistance))) then {
|
2015-11-13 08:57:06 +00:00
|
|
|
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText "----";
|
|
|
|
} else {
|
|
|
|
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber);
|
|
|
|
};
|