ACE3/addons/fcs/functions/fnc_getRange.sqf

52 lines
1.5 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: commy2
2015-12-10 15:00:14 +00:00
* Read laser distance measurement from engine.
*
2016-06-18 09:50:41 +00:00
* Arguments:
* 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>
*
2016-06-18 09:50:41 +00:00
* Return Value:
2015-12-10 15:00:14 +00:00
* Measured distance <NUMBER>
*
* Example:
* [5, 6, 7, true] call ace_fcs_fnc_getRange
*
2015-12-10 15:00:14 +00:00
* Public: No
*/
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 {
2016-01-21 14:01:41 +00:00
// Is distance out of bound?
_distance = _distance min _maxDistance;
_distance = _distance max _minDistance;
2016-01-21 14:01:41 +00:00
// If don't let accuracy be less than 1
_accuracy = _accuracy max 1;
_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