ACE3/addons/fcs/functions/fnc_getRange.sqf

52 lines
1.5 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
2015-12-10 15:00:14 +00:00
* Read laser distance measurement from engine.
*
* Argument:
* 0: Measurement Accuracy (default: 1) <NUMBER>
* 1: Maximum measure distance (default: 5000) <NUMBER>
* 2: Minimum measure distance (default: 0) <NUMBER>
2016-01-21 13:44:23 +00:00
* 3: Blank display on range error (default: false) <BOOL>
*
* Return value:
2015-12-10 15:00:14 +00:00
* Measured distance <NUMBER>
*
* Public: No
*/
#include "script_component.hpp"
2016-01-21 13:44:23 +00:00
params [["_accuracy",1], ["_maxDistance",5000], ["_minDistance",0], ["_blank",false]];
disableSerialization;
2015-12-10 15:00:14 +00:00
private _dlgRangefinder = uiNamespace getVariable ["ACE_dlgRangefinder", displayNull];
private _distance = parseNumber ctrlText (_dlgRangefinder displayCtrl 151);
2016-01-20 14:51:07 +00:00
if (_distance == 0) then {
_distance = _this call EFUNC(common,getTargetDistance);
} else {
if (_distance > _maxDistance) then {
_distance = _maxDistance;
};
if (_distance < _minDistance) then {
_distance = _minDistance;
};
_accuracy = if(_accuracy < 1) then {1} else {_accuracy};
_distance = (round (_distance/_accuracy)) * _accuracy;
};
2016-01-21 13:44:23 +00:00
// Change the display if the range is out of bounds
if (_distance >= _maxDistance || _distance <= _minDistance) then {
if (_blank) then {
(_dlgRangefinder displayCtrl 1713151) ctrlSetText "----";
} else {
2016-01-21 13:44:23 +00:00
(_dlgRangefinder displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber) + "*";
};
2016-01-21 13:44:23 +00:00
} else {
(_dlgRangefinder displayCtrl 1713151) ctrlSetText ([_distance, 4, 0] call CBA_fnc_formatNumber);
};
_distance