1
0
mirror of https://github.com/acemod/ACE3.git synced 2024-08-30 18:23:18 +00:00

Merge pull request from acemod/fcs_rewriteRangeFunctions

Cleaning up the FCS code
This commit is contained in:
Thomas Kooi 2016-02-04 19:39:32 +01:00
commit 6cf02bd06b
5 changed files with 140 additions and 85 deletions

@ -3,6 +3,7 @@
ADDON = false;
PREP(adjustRange);
PREP(calculateSolution);
PREP(canResetFCS);
PREP(canUseFCS);
PREP(canUseRangefinder);

@ -0,0 +1,77 @@
/*
* 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");
private _bulletSimulation = getText (configFile >> "CfgAmmo" >> _ammo >> "simulation");
if !(_bulletSimulation == "shotMissile") then {
private _maxElev = getNumber (_turretConfig >> "maxElev");
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
private _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction");
{
private _weapon = _x;
private _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
private _weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
{
if (_x != "this") then {
_weaponMagazines append getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
};
false
} count _muzzles;
// Fix the `in` operator being case sensitive and BI fucking up the spelling of their own classnames
private _weaponMagazinesCheck = [];
{
_weaponMagazinesCheck pushBack (toLower _x);
} forEach _weaponMagazines;
// Another BIS fix: ShotBullet simulation uses weapon initSpeed, others ignore it
if (toLower _magazine in _weaponMagazinesCheck && {_bulletSimulation == "shotBullet"}) 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);

@ -3,7 +3,10 @@
* Read laser distance measurement from engine.
*
* Argument:
* None
* 0: Measurement Accuracy (default: 1) <NUMBER>
* 1: Maximum measure distance (default: 5000) <NUMBER>
* 2: Minimum measure distance (default: 0) <NUMBER>
* 3: Blank display on range error (default: false) <BOOL>
*
* Return value:
* Measured distance <NUMBER>
@ -12,7 +15,34 @@
*/
#include "script_component.hpp"
params [["_accuracy",1], ["_maxDistance",5000], ["_minDistance",0], ["_blank",false]];
disableSerialization;
private _dlgRangefinder = uiNamespace getVariable ["ACE_dlgRangefinder", displayNull];
parseNumber ctrlText (_dlgRangefinder displayCtrl 151);
private _distance = parseNumber ctrlText (_dlgRangefinder displayCtrl 151);
if (_distance == 0) then {
_distance = _this call EFUNC(common,getTargetDistance);
} else {
// Is distance out of bound?
_distance = _distance min _maxDistance;
_distance = _distance max _minDistance;
// If don't let accuracy be less than 1
_accuracy = _accuracy max 1;
_distance = (round (_distance/_accuracy)) * _accuracy;
};
// Change the display if the range is out of bounds
if (_distance >= _maxDistance || _distance <= _minDistance) then {
if (_blank) then {
(_dlgRangefinder displayCtrl 1713151) ctrlSetText "----";
} else {
(_dlgRangefinder displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber) + "*";
};
} else {
(_dlgRangefinder displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber);
};
_distance

@ -15,17 +15,22 @@
params ["_vehicle", "_turret"];
private _distance = call FUNC(getRange);
call FUNC(updateRangeHUD);
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
// Update display for infantry rangefinders
if (_vehicle == ACE_player) exitWith {[5,5500,25,true] call FUNC(getRange)};
private _distance = [
getNumber (_turretConfig >> QGVAR(DistanceInterval)),
getNumber (_turretConfig >> QGVAR(MaxDistance)),
getNumber (_turretConfig >> QGVAR(MinDistance))
] call FUNC(getRange);
if !(!GVAR(enabled) && FUNC(canUseFCS)) exitWith {};
GVAR(Enabled) = true;
GVAR(time) = ACE_time;
if (_distance == 0) then {
_distance = [5, 5000, 0] call EFUNC(common,getTargetDistance); // maximum distance: 5000m, 5m precision
};
private _weaponDirection = _vehicle weaponDirection (_vehicle currentWeaponTurret _turret); // @todo doesn't work for sub turrets
@ -38,3 +43,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);

@ -17,20 +17,15 @@ params ["_vehicle", "_turret", "_distance", ["_showHint", false], ["_playSound",
private _turretConfig = [configFile >> "CfgVehicles" >> typeOf _vehicle, _turret] call EFUNC(common,getTurretConfigPath);
call FUNC(updateRangeHUD);
if (isNil "_distance") then {
_distance = call FUNC(getRange);
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
};
_distance = [
getNumber (_turretConfig >> QGVAR(DistanceInterval)),
getNumber (_turretConfig >> QGVAR(MaxDistance)),
getNumber (_turretConfig >> QGVAR(MinDistance))
] call FUNC(getRange);
};
// MOVING TARGETS
private _weapon = _vehicle currentWeaponTurret _turret;
private _weaponDirection = _vehicle weaponDirection _weapon; // @todo doesn't work for sub turrets
@ -44,7 +39,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 {
@ -60,13 +54,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 = getText (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 {
@ -109,61 +107,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";
};
@ -171,11 +119,3 @@ if (_playSound) 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 {
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText "----";
} else {
((uiNamespace getVariable ["ACE_dlgRangefinder", displayNull]) displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber);
};