code cleanup fcs

This commit is contained in:
commy2 2015-12-10 16:00:14 +01:00
parent 48e9a257f7
commit 077b9827e8
19 changed files with 263 additions and 289 deletions

View File

@ -1,3 +1,4 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
@ -6,7 +7,7 @@ class Extended_PreInit_EventHandlers {
class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE(call COMPILE_FILE(XEH_clientInit));
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};

View File

@ -26,7 +26,7 @@ class CfgVehicles {
class ACE_SelfActions {
class ResetFCS {
displayName = CSTRING(ResetFCS);
condition = QUOTE(call FUNC(canResetFCS));
condition = QUOTE(_player call FUNC(canResetFCS));
statement = QUOTE([ARR_2(vehicle _player,[_player] call DEFUNC(common,getTurretIndex))] call DFUNC(reset););
showDisabled = 0;
priority = 1;
@ -39,7 +39,7 @@ class CfgVehicles {
class ACE_SelfActions {
class ResetFCS {
displayName = CSTRING(ResetFCS);
condition = QUOTE(call FUNC(canResetFCS));
condition = QUOTE(_player call FUNC(canResetFCS));
statement = QUOTE([ARR_2(vehicle _player,[_player] call DEFUNC(common,getTurretIndex))] call DFUNC(reset););
showDisabled = 0;
priority = 1;
@ -321,9 +321,13 @@ class CfgVehicles {
discreteDistance[] = {};
discreteDistanceInitIndex = 0;
/*class Turrets: Turrets {
class CommanderOptics: CommanderOptics {};
};*/
class Turrets: Turrets {
class CommanderOptics: CommanderOptics {
GVAR(Enabled) = 1;
discreteDistance[] = {};
discreteDistanceInitIndex = 0;
};
};
};
};
};
@ -346,9 +350,13 @@ class CfgVehicles {
discreteDistance[] = {};
discreteDistanceInitIndex = 0;
/*class Turrets: Turrets {
class CommanderOptics: CommanderOptics {};
};*/
class Turrets: Turrets {
class CommanderOptics: CommanderOptics {
GVAR(Enabled) = 1;
discreteDistance[] = {};
discreteDistanceInitIndex = 0;
};
};
};
};
};
@ -362,6 +370,8 @@ class CfgVehicles {
class Turrets: Turrets {
class CommanderOptics: CommanderOptics {
GVAR(Enabled) = 1;
discreteDistance[] = {};
discreteDistanceInitIndex = 0;
};
};
};

View File

@ -16,4 +16,4 @@ if (!hasInterface) exitWith {};
}] call EFUNC(common,addEventHandler);
// Register event for global updates
[QGVAR(forceUpdate), FUNC(onForceUpdate)] call EFUNC(common,addEventHandler);
[QGVAR(forceUpdate), {ACE_player call FUNC(onForceUpdate)}] call EFUNC(common,addEventHandler);

View File

@ -14,6 +14,7 @@ PREP(onForceUpdate);
PREP(keyDown);
PREP(keyUp);
PREP(reset);
PREP(updateRangeHUD);
PREP(vehicleInit);
ADDON = true;

View File

@ -1,29 +1,27 @@
/*
* Author: KoffeinFlummi
*
* Adjusts the currently zeroed distance.
*
* Arguments:
* 0: The vehicle in question
* 1: The amount to add to the distance (can be negative)
* 0: The vehicle in question <OBJECT>
* 1: The Turrets that the Vehicle has <ARRAY>
* 2: The amount to add to the distance (can be negative) <NUMMBER>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_turret", "_delta", "_turretConfig", "_min", "_max", "_distance"];
params ["_vehicle", "_turret", "_delta"];
_vehicle = _this select 0;
_turret = _this select 1;
_delta = _this select 2;
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
_turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
private _min = getNumber (_turretConfig >> QGVAR(MinDistance));
private _max = getNumber (_turretConfig >> QGVAR(MaxDistance));
_min = getNumber (_turretConfig >> QGVAR(MinDistance));
_max = getNumber (_turretConfig >> QGVAR(MaxDistance));
_distance = _vehicle getVariable [format ["%1_%2", QGVAR(Distance), _turret], _min];
private _distance = _vehicle getVariable [format ["%1_%2", QGVAR(Distance), _turret], _min];
_distance = _distance + _delta;
_distance = _distance min _max;

View File

@ -1,15 +1,17 @@
/*
* Author: KoffeinFlummi
*
* Called from config. Can player reset FCS?
*
* Argument:
* Nothing
*
* Return value:
* Boolean (Bool)
* Return Value:
* Boolean <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
count ((vehicle ACE_player) getVariable [format ["%1_%2", QGVAR(Magazines), [ACE_player] call EFUNC(common,getTurretIndex)], []]) > 1
params ["_unit"];
count ((vehicle _unit) getVariable [format ["%1_%2", QGVAR(Magazines), [_unit] call EFUNC(common,getTurretIndex)], []]) > 1 // return

View File

@ -1,16 +1,16 @@
/*
* Author: commy2
*
* Called from config. Returns true if the player is a gunner and the players current vehicle has a FCS.
*
* Argument:
* Nothing
* Arguments:
* None
*
* Return value:
* Boolean (Bool)
* Return Value:
* Boolean <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
getNumber ([configFile >> "CfgVehicles" >> typeOf vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex)] call EFUNC(common,getTurretConfigPath) >> QGVAR(Enabled)) == 1
&& {cameraView == "GUNNER"}
&& {cameraView == "GUNNER"} // return

View File

@ -1,16 +1,16 @@
/*
* Author: commy2
*
* Returns true if the laser distance measurement can be read from the engine.
*
* Argument:
* Nothing
* Arguments:
* None
*
* Return value:
* Boolean (Bool)
* Return Value:
* Boolean <BOOL>
*
* Public: No
*/
#include "script_component.hpp"
!isNull ((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151)
&& {cameraView == "GUNNER"}
&& {cameraView == "GUNNER"} // return

View File

@ -1,6 +1,5 @@
/*
* Author: KoffeinFlummi
*
* Adjusts the direction of a shell.
*
* Arguments:
@ -8,58 +7,48 @@
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_weapon", "_ammo", "_magazine", "_projectile", "_sumVelocity"];
params ["_vehicle", "_weapon", "", "", "_ammo", "_magazine", "_projectile"];
_vehicle = _this select 0;
_weapon = _this select 1;
_ammo = _this select 4;
_magazine = _this select 5;
_projectile = _this select 6;
private ["_gunner", "_turret"];
_gunner = [_vehicle, _weapon] call EFUNC(common,getGunner);
_turret = [_gunner] call EFUNC(common,getTurretIndex);
private _gunner = [_vehicle, _weapon] call EFUNC(common,getGunner);
private _turret = _gunner call EFUNC(common,getTurretIndex);
// Exit if the unit isn't a player
if !([_gunner] call EFUNC(common,isPlayer)) exitWith {};
private ["_FCSMagazines", "_FCSElevation", "_offset"];
_FCSMagazines = _vehicle getVariable [(format ["%1_%2", QGVAR(Magazines), _turret]), []];
_FCSElevation = _vehicle getVariable format ["%1_%2", QGVAR(Elevation), _turret];
private _FCSMagazines = _vehicle getVariable [format ["%1_%2", QGVAR(Magazines), _turret], []];
private _FCSElevation = _vehicle getVariable format ["%1_%2", QGVAR(Elevation), _turret];
if !(_magazine in _FCSMagazines) exitWith {};
// GET ELEVATION OFFSET OF CURRENT MAGAZINE
_offset = 0;
private _offset = 0;
{
if (_x == _magazine) exitWith {
_offset = _FCSElevation select _forEachIndex;
};
} forEach _FCSMagazines;
[_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 {
_sumVelocity = (velocity _projectile) vectorDiff (velocity _vehicle);
if (vectorMagnitude velocity _vehicle > 2) then {
private _sumVelocity = (velocity _projectile) vectorDiff (velocity _vehicle);
_projectile setVelocity _sumVelocity;
};
// Air burst missile
// handle locally only
if (!local _gunner) exitWith {};
if (getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(Airburst)) == 1) then {
private "_zeroing";
_zeroing = _vehicle getVariable [format ["%1_%2", QGVAR(Distance), _turret], currentZeroing _vehicle];
private _zeroing = _vehicle getVariable [format ["%1_%2", QGVAR(Distance), _turret], currentZeroing _vehicle];
if (_zeroing < 50) exitWith {};
if (_zeroing > 1500) exitWith {};

View File

@ -1,91 +1,82 @@
/*
* Author: KoffeinFlummi
*
* Calculates the angle offset necessary to hit the current target.
*
* Arguments:
* 0: distance to target in meters
* 1: current angle of the turret
* 2: maximum elevation of the turret
* 3: initSpeed of the projectile
* 4: airFriction of the projectile
* 5: maximum timeToLive of the projectile
* 6: simulationStep of the projectile
* 0: distance to target in meters <NUMBER>
* 1: current angle of the turret <NUMBER>
* 2: maximum elevation of the turret <NUMBER>
* 3: initSpeed of the projectile <NUMBER>
* 4: airFriction of the projectile <NUMBER>
* 5: maximum timeToLive of the projectile <NUMBER>
* 6: simulationStep of the projectile <NUMBER>
*
* Return Value:
* offset from the current angle necessary to hit the target
* offset from the current angle necessary to hit the target <NUMBER>
*
* Public: No
*/
#include "script_component.hpp"
#define PRECISION 0.1
private ["_distance", "_angleTarget", "_maxElev", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep", "_angle1", "_angle2", "_it2", "_f1", "_f2", "_temp", "_it1", "_angle"];
_distance = _this select 0;
_angleTarget = _this select 1;
_maxElev = _this select 2;
_initSpeed = _this select 3;
_airFriction = _this select 4;
_timeToLive = _this select 5;
_simulationStep = _this select 6;
params ["_distance", "_angleTarget", "_maxElev", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep"];
if (_simulationStep == 0) exitWith {_angleTarget};
FUNC(traceBullet) = {
private ["_distance", "_angleTarget", "_maxElev", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep", "_angle", "_posTargetX", "_posTargetY", "_posX", "_posY", "_velocityX", "_velocityY", "_velocityMagnitude", "_i"];
_distance = _this select 0;
_angleTarget = _this select 1;
_maxElev = _this select 2;
_initSpeed = _this select 3;
_airFriction = _this select 4;
_timeToLive = _this select 5;
_simulationStep = _this select 6;
_angle = _this select 7;
private _fnc_traceBullet = {
params ["_distance", "_angleTarget", "_maxElev", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep", "_angle"];
_angle = _angle - _angleTarget;
_angleTarget = 0;
_posTargetX = (cos _angleTarget) * _distance;
_posTargetY = (sin _angleTarget) * _distance;
private _posTargetX = (cos _angleTarget) * _distance;
private _posTargetY = (sin _angleTarget) * _distance;
_posX = 0;
_posY = 0;
private _posX = 0;
private _posY = 0;
_velocityX = (cos _angle) * _initSpeed;
_velocityY = (sin _angle) * _initSpeed;
private _velocityX = (cos _angle) * _initSpeed;
private _velocityY = (sin _angle) * _initSpeed;
// trace the path of the bullet
for "_i" from 1 to ((floor (_timeToLive / _simulationStep)) + 1) do {
_velocityMagnitude = sqrt (_velocityX^2 + _velocityY^2);
private _velocityMagnitude = sqrt (_velocityX^2 + _velocityY^2);
_velocityX = _velocityX + _simulationStep * (_velocityX * _velocityMagnitude * _airFriction);
_velocityY = _velocityY + _simulationStep * (_velocityY * _velocityMagnitude * _airFriction - 9.81);
_posX = _posX + _velocityX * _simulationStep;
_posY = _posY + _velocityY * _simulationStep;
if (_posX >= _posTargetX) exitWith {}; // bullet passed the target
};
_posY - _posTargetY
};
if ((_this + [_maxElev]) call FUNC(traceBullet) < 0) exitWith {_maxElev - _angleTarget};
private _data = [_distance, _angleTarget, _maxElev, _initSpeed, _airFriction, _timeToLive, _simulationStep, _maxElev];
if (_data call _fnc_traceBullet < 0) exitWith {_maxElev - _angleTarget};
// Newton Method / Secand Method
_angle1 = _angleTarget;
_angle2 = _maxElev;
_it2 = 0;
_f1 = (_this + [_angle1]) call FUNC(traceBullet);
private _angle1 = _angleTarget;
private _angle2 = _maxElev;
private _it2 = 0;
_data set [7, _maxElev];
private _f1 = _data call _fnc_traceBullet;
if (abs _f1 <= PRECISION) exitWith {0};
while {abs _f1 > PRECISION} do {
_data set [7, _angle2];
private _f2 = _data call _fnc_traceBullet;
if ((abs _f1) <= PRECISION) exitWith {0};
while {(abs _f1) > PRECISION} do {
_f2 = (_this + [_angle2]) call FUNC(traceBullet);
_temp = _angle2-_f2*(_angle2-_angle1)/(_f2-_f1);
_angle1 = _angle2;
_angle2 = _temp;
_f1 = _f2;
_it2 = _it2+1;
};
//player globalChat format ["it1: %1 | _angle1: %2 | it2: %3 | _angle2: %4",_it1, _angle-_angleTarget, _it2, _angle2-_angleTarget];
_angle2 = _angle2 - _f2 * (_angle2 - _angle1) / (_f2 - _f1);
_angle=_angle2;
_angle - _angleTarget
_f1 = _f2;
_it2 = _it2 + 1;
};
_angle2 - _angleTarget

View File

@ -1,23 +1,18 @@
/*
* Author: commy2
*
* Read laser distance measurement from engine and update compatible info elements.
* Read laser distance measurement from engine.
*
* Argument:
* Nothing
* None
*
* Return value:
* Measured distance (Number)
* Measured distance <NUMBER>
*
* Public: No
*/
#include "script_component.hpp"
private ["_dlgRangefinder", "_range"];
disableSerialization;
_dlgRangefinder = uiNamespace getVariable ["ACE_dlgRangefinder", displayNull];
private _dlgRangefinder = uiNamespace getVariable ["ACE_dlgRangefinder", displayNull];
_range = ctrlText (_dlgRangefinder displayCtrl 151);
(_dlgRangefinder displayCtrl 1713151) ctrlSetText _range;
parseNumber _range
parseNumber ctrlText (_dlgRangefinder displayCtrl 151);

View File

@ -1,21 +1,32 @@
// by commy2
/*
* Author: commy2
* Handle Air burst ammunition. Called from per frame handler.
*
* Arguments:
* -
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_projectile", "_zeroing", "_position", "_subMunition"];
_vehicle = _this select 0 select 0;
_projectile = _this select 0 select 1;
_zeroing = _this select 0 select 2;
(_this select 0) params ["_vehicle", "_projectile", "_zeroing"];
// remove pfh if the projectile died before arriving
if (isNull _projectile || {!alive _projectile}) exitWith {
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
// wait if not there
if (_projectile distance _vehicle < _zeroing) exitWith {};
_position = getPosATL _projectile;
// explode
private _position = getPosATL _projectile;
private _subMunition = createVehicle ["ACE_B_35mm_ABM_Helper", _position, [], 0, "FLY"];
_subMunition = createVehicle ["ACE_B_35mm_ABM_Helper", _position, [], 0, "FLY"];
_subMunition setPosATL _position;
_subMunition setVelocity [0, 0, -10];

View File

@ -1,23 +1,22 @@
/*
* Author: KoffeinFlummi
*
* Starts watching the target for sideways correction.
*
* Arguments:
* 0: Vehicle
* 0: Vehicle <OBJECT>
* 1: Turret <ARRAY>
*
* Return Value:
* none
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_turret", "_distance", "_weaponDirection"];
params ["_vehicle", "_turret"];
_vehicle = _this select 0;
_turret = _this select 1;
_distance = call FUNC(getRange);
private _distance = call FUNC(getRange);
call (updateRangeHUD);
if !(!GVAR(enabled) && FUNC(canUseFCS)) exitWith {};
@ -28,7 +27,7 @@ if (_distance == 0) then {
_distance = [5, 5000, 0] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision
};
_weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets
private _weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets
if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then {
_weaponDirection = eyeDirection _vehicle;
@ -38,8 +37,4 @@ if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turr
_weaponDirection = [1,0,0];
};
GVAR(Position) = [
(getPos _vehicle select 0) + _distance * (_weaponDirection select 0),
(getPos _vehicle select 1) + _distance * (_weaponDirection select 1),
(getPos _vehicle select 2) + _distance * (_weaponDirection select 2)
];
GVAR(Position) = (getPosASL _vehicle) vectorAdd (_weaponDirection vectorMultiply _distance);

View File

@ -1,40 +1,38 @@
/*
* Author: KoffeinFlummi
*
* Calculates the offsets for all weapons needed to hit the current target.
*
* Arguments:
* 0: The vehicle
* 0: Vehicle <OBJECT>
* 1: Turret <ARRAY>
*
* Return Value:
* none
* None
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_turret", "_turretConfig", "_distance", "_weapons", "_magazines", "_showHint", "_playSound", "_i"];
params ["_vehicle", "_turret", "_distance", ["_showHint", false], ["_playSound", true]];
_vehicle = _this select 0;
_turret = _this select 1;
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
_turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
call (updateRangeHUD);
_distance = call FUNC(getRange);
if (isNil "_distance") then {
_distance = call FUNC(getRange);
_weapons = _vehicle weaponsTurret _turret;
_magazines = _vehicle magazinesTurret _turret;
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
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
};
};
private ["_weapon", "_weaponDirection", "_angleTarget"];
_weapon = _vehicle currentWeaponTurret _turret;
_weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets
private _weapon = _vehicle currentWeaponTurret _turret;
private _weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets
if (_turret isEqualTo ([_vehicle] call EFUNC(common,getTurretCommander))) then {
_weaponDirection = eyeDirection _vehicle;
@ -44,176 +42,139 @@ if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turr
_weaponDirection = [1,0,0];
};
_angleTarget = asin (_weaponDirection select 2);
if (count _this > 2) then {
if((_this select 2) > -1) then {
_distance = _this select 2;
};
};
if (!(isNil QGVAR(backgroundCalculation)) and {!(scriptDone GVAR(backgroundCalculation))}) then {
terminate GVAR(backgroundCalculation);
};
private ["_movingAzimuth", "_posTarget", "_velocityTarget"];
private _angleTarget = asin (_weaponDirection select 2);
// MOVING TARGETS
_movingAzimuth = 0;
if (ACE_time - GVAR(time) > 1 and GVAR(time) != -1 and count _this < 3) then {
// calculate speed of target
_posTarget = [
(getPos _vehicle select 0) + _distance * (_weaponDirection select 0),
(getPos _vehicle select 1) + _distance * (_weaponDirection select 1),
(getPos _vehicle select 2) + _distance * (_weaponDirection select 2)
];
_velocityTarget = [
((_posTarget select 0) - (GVAR(position) select 0)) / (ACE_time - GVAR(time)),
((_posTarget select 1) - (GVAR(position) select 1)) / (ACE_time - GVAR(time)),
((_posTarget select 2) - (GVAR(position) select 2)) / (ACE_time - GVAR(time))
];
private _movingAzimuth = 0;
private ["_magazineType", "_ammoType", "_initSpeed", "_airFriction", "_timeToLive", "_simulationStep", "_initSpeedCoef", "_velocityMagnitude"];
if (ACE_time - GVAR(time) > 1 && GVAR(time) != -1 && isNil {_this select 2}) then {
// calculate speed of target
private _posTarget = (getPosASL _vehicle) vectorAdd (_weaponDirection vectorMultiply _distance);
private _velocityTarget = (_posTarget vectorDiff GVAR(position)) vectorMultiply (1 / (ACE_time - GVAR(time)));
// estimate time to target
_magazineType = _vehicle currentMagazineTurret _turret;
_ammoType = getText (configFile >> "CfgMagazines" >> _magazineType >> "ammo");
_initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazineType >> "initSpeed");
_airFriction = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "airFriction");
_timeToLive = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "timeToLive");
_simulationStep = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "simulationStep");
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");
_initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed");
if (_initSpeedCoef < 0) then {
_initSpeed = _initSpeed * -_initSpeedCoef;
_initSpeed = _initSpeed * - _initSpeedCoef;
};
if (_initSpeedCoef > 0) then {
_initSpeed = _initSpeedCoef;
};
if (_simulationStep != 0) then {
private ["_posX", "_velocityX", "_velocityY", "_timeToTarget"];
private _posX = 0;
private _velocityX = _initSpeed;
private _velocityY = 0;
private _timeToTarget = 0;
_posX = 0;
_velocityX = _initSpeed;
_velocityY = 0;
_timeToTarget = 0;
for "_i" from 1 to ((floor (_timeToLive / _simulationStep)) + 1) do {
for "_i" from 1 to (floor (_timeToLive / _simulationStep) + 1) do {
_posX = _posX + _velocityX * _simulationStep;
if (_posX >= _distance) exitWith { // bullet passed the target
_timeToTarget = _i * _simulationStep;
};
_velocityMagnitude = sqrt (_velocityX^2 + _velocityY^2);
private _velocityMagnitude = sqrt (_velocityX ^ 2 + _velocityY ^ 2);
_velocityX = _velocityX + _velocityX * _velocityMagnitude * _airFriction * _simulationStep;
_velocityY = _velocityY + _velocityY * _velocityMagnitude * _airFriction * _simulationStep - 9.81 * _simulationStep;
};
private ["_posArrival", "_dirArrival"];
// calculate offsets
_posArrival = [
(_posTarget select 0) + (_velocityTarget select 0) * _timeToTarget,
(_posTarget select 1) + (_velocityTarget select 1) * _timeToTarget,
(_posTarget select 2) + (_velocityTarget select 2) * _timeToTarget
];
_dirArrival = [
((_posArrival select 0) - (getPos _vehicle select 0)) / (_posArrival distance (getPos _vehicle)),
((_posArrival select 1) - (getPos _vehicle select 1)) / (_posArrival distance (getPos _vehicle)),
((_posArrival select 2) - (getPos _vehicle select 2)) / (_posArrival distance (getPos _vehicle))
];
private _posArrival = _posTarget vectorAdd (_velocityTarget vectorMultiply _timeToTarget);
private _dirArrival = (_posArrival vectorDiff getPosASL _vehicle) vectorMultiply (1 / (_posArrival vectorDistance getPosASL _vehicle));
_movingAzimuth = ((_dirArrival select 0) atan2 (_dirArrival select 1)) - ((_weaponDirection select 0) atan2 (_weaponDirection select 1));
_angleTarget = asin (_dirArrival select 2);
_distance = floor (_posArrival distance (getPos _vehicle));
_distance = floor (_posArrival distance (getPosASL _vehicle));
};
};
GVAR(enabled) = false;
GVAR(time) = -1;
private ["_viewDiff", "_FCSAzimuth", "_FCSMagazines", "_FCSElevation"];
// CALCULATE AZIMUTH CORRECTION
_viewDiff = _vehicle getVariable format ["%1_%2", QGVAR(ViewDiff), _turret];
_FCSAzimuth = _movingAzimuth;
private _viewDiff = _vehicle getVariable format ["%1_%2", QGVAR(ViewDiff), _turret];
private _FCSAzimuth = _movingAzimuth;
if (_viewDiff != 0) then {
_FCSAzimuth = (atan (_distance / _viewDiff) - (abs _viewDiff / _viewDiff) * 90) + _movingAzimuth;
};
// CALCULATE OFFSET
_FCSMagazines = [];
_FCSElevation = [];
private _FCSMagazines = [];
private _FCSElevation = [];
{
private ["_magazine", "_ammoType"];
_magazine = _x;
_ammoType = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo");
private _magazine = _x;
private _ammo = 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" >> _magazine >> "initSpeed");
_airFriction = getNumber (configFile >> "CfgAmmo" >> _ammoType >> "airFriction");
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;
};
} forEach _muzzles;
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;
};
};
} forEach _weapons;
false
} count (_vehicle weaponsTurret _turret);
_offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance];
private _offset = "ace_fcs" callExtension format ["%1,%2,%3,%4", _initSpeed, _airFriction, _angleTarget, _distance];
_offset = parseNumber _offset;
_FCSMagazines = _FCSMagazines + [_magazine];
_FCSElevation = _FCSElevation + [_offset];
_FCSMagazines pushBack _magazine;
_FCSElevation pushBack _offset;
};
} forEach _magazines;
false
} count (_vehicle magazinesTurret _turret);
[_vehicle, format ["%1_%2", QGVAR(Distance), _turret], _distance] call EFUNC(common,setVariablePublic);
[_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);
[_vehicle, format ["%1_%2", QGVAR(Azimuth), _turret], _FCSAzimuth] call EFUNC(common,setVariablePublic);
_showHint = false;
if( (count _this) > 3) then {
_showHint = _this select 3;
};
_playSound = true;
if( (count _this) > 3) then {
_playSound = _this select 4;
};
if(_playSound) then {
if (_playSound) then {
playSound "ACE_Sound_Click";
};
if(_showHint) then {
if (_showHint) then {
[format ["%1: %2", localize LSTRING(ZeroedTo), _distance]] call EFUNC(common,displayTextStructured);
};
//Update the hud's distance display to the new value or "----" if out of range
//(10m fudge because of EFUNC(common,getTargetDistance))
if ((_distance + 10) >= (getNumber (_turretConfig >> QGVAR(MaxDistance)))) then {
if (_distance + 10 >= getNumber (_turretConfig >> QGVAR(MaxDistance))) then {
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText "----";
} else {
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber);

View File

@ -1,7 +1,13 @@
#include "script_component.hpp"
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
params ["_unit"];
private _vehicle = vehicle _unit;
if !([_unit, _vehicle, []] call EFUNC(common,canInteractWith)) exitWith {false};
if !((!GVAR(enabled) && FUNC(canUseFCS)) || FUNC(canUseRangefinder)) exitWith {false};
[vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex), -1, false] call FUNC(keyDown);
[vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex), -1, false, false] call FUNC(keyUp);
private _turret = _unit call EFUNC(common,getTurretIndex);
[_vehicle, _turret, -1, false] call FUNC(keyDown);
[_vehicle, _turret, -1, false, false] call FUNC(keyUp);

View File

@ -1,21 +1,19 @@
/*
* Author: KoffeinFlummi
*
* Resets the FCS to default.
*
* Arguments:
* 0: Vehicle
* 0: Vehicle <OBJECT>
* 1: Turret <ARRAY>
*
* Return Value:
* none
*
* Public: No
*/
#include "script_component.hpp"
private ["_vehicle", "_turret"];
_vehicle = _this select 0;
_turret = _this select 1;
params ["_vehicle", "_turret"];
[_vehicle, format ["%1_%2", QGVAR(Distance), _turret], 0] call EFUNC(common,setVariablePublic);
[_vehicle, format ["%1_%2", QGVAR(Magazines), _turret], []] call EFUNC(common,setVariablePublic);

View File

@ -0,0 +1,18 @@
/*
* Author: commy2
* Update compatible info elements.
*
* Argument:
* None
*
* Return value:
* None
*
* Public: No
*/
#include "script_component.hpp"
disableSerialization;
private _dlgRangefinder = uiNamespace getVariable ["ACE_dlgRangefinder", displayNull];
(_dlgRangefinder displayCtrl 1713151) ctrlSetText ctrlText (_dlgRangefinder displayCtrl 151);

View File

@ -1,6 +1,5 @@
/*
* Author: KoffeinFlummi, commy2
*
* Checks if a vehicle is equipped with an FCS and if so, adds the fired event handler. Execute on server.
*
* Arguments:
@ -8,17 +7,15 @@
*
* Return Value:
* none
*
* Public: No
*/
#include "script_component.hpp"
private "_vehicle";
_vehicle = _this select 0;
params ["_vehicle"];
{
private "_turretConfig";
_turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _x] call EFUNC(common,getTurretConfigPath);
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _x] call EFUNC(common,getTurretConfigPath);
if (getNumber (_turretConfig >> QGVAR(Enabled)) == 1) then {
_vehicle setVariable [format ["%1_%2", QGVAR(Distance), _x], 0, true];
@ -42,4 +39,5 @@ _vehicle = _this select 0;
_vehicle setVariable [format ["%1_%2", QGVAR(ViewDiff), _x], 0, true];
};
};
} forEach allTurrets _vehicle;
false
} count allTurrets _vehicle;

View File

@ -28,7 +28,7 @@
[vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex)] call FUNC(keyUp);
false
},
[15, [false, false, false]], false] call cba_fnc_addKeybind; //Tab Key
[15, [false, false, false]], false] call CBA_fnc_addKeybind; //Tab Key
["ACE3 Vehicles", QGVAR(adjustRangeUp), localize LSTRING(AdjustRangeUp),
{
@ -42,7 +42,7 @@
true
},
{false},
[201, [false, false, false]], false] call cba_fnc_addKeybind; //PageUp Key
[201, [false, false, false]], false] call CBA_fnc_addKeybind; //PageUp Key
["ACE3 Vehicles", QGVAR(adjustRangDown), localize LSTRING(AdjustRangeDown),
{
@ -56,4 +56,4 @@
true
},
{false},
[209, [false, false, false]], false] call cba_fnc_addKeybind; //PageDown Key
[209, [false, false, false]], false] call CBA_fnc_addKeybind; //PageDown Key