1
0
Fork 0

RadarDist : Fixed a problem onboard radar happens automatically when you are in range of an mp gamer that uses "OpenRadar" by 5H1N0B1

This commit is contained in:
BARANGER Emmanuel 2014-01-05 21:23:18 +01:00
parent 6bc7983431
commit b9f0dd0466

View file

@ -45,159 +45,159 @@ var FT2M = 0.3048;
var NM2KM = 1.852; var NM2KM = 1.852;
var my_maxrange = func(a) { var my_maxrange = func(a) {
max_range = 0; max_range = 0;
radar_range = 0; radar_range = 0;
radar_area = 0; radar_area = 0;
acname = aircraftData[a] or 0; acname = aircraftData[a] or 0;
if ( acname ) { if ( acname ) {
have_radar = radarData[acname][4]; have_radar = radarData[acname][4];
if ( have_radar != "none" and have_radar != "unknown") { if ( have_radar != "none" and have_radar != "unknown") {
radar_area = radarData[acname][7]; radar_area = radarData[acname][7];
radar_range = radarData[acname][5]; radar_range = radarData[acname][5];
if ( radar_area > 0 ) { max_range = radar_range / radar_area } if ( radar_area > 0 ) { max_range = radar_range / radar_area }
} }
} }
return( max_range ); return( max_range );
} }
var get_ecm_type_num = func(a) { var get_ecm_type_num = func(a) {
acname = aircraftData[a] or 0; acname = aircraftData[a] or 0;
var num = 0; var num = 0;
if ( acname ) { if ( acname ) {
num = radarData[acname][8]; num = radarData[acname][8];
} }
return( num ); return( num );
} }
var get_aircraft_name = func( t ) { var get_aircraft_name = func( t ) {
# Get the multiplayer aircraft name. # Get the multiplayer aircraft name.
mpnode_string = t; mpnode_string = t;
mpnode = props.globals.getNode(mpnode_string); mpnode = props.globals.getNode(mpnode_string);
if ( find("tanker", mpnode_string) > 0 ) { if ( find("tanker", mpnode_string) > 0 ) {
cutname = "KC135"; cutname = "KC135";
} else { } else {
mpname_node_string = mpnode_string ~ "/sim/model/path"; mpname_node_string = mpnode_string ~ "/sim/model/path";
mpname_node = props.globals.getNode(mpname_node_string); mpname_node = props.globals.getNode(mpname_node_string);
if (mpname_node == nil) { return(0) } if (mpname_node == nil) { return(0) }
var mpname = mpname_node.getValue(); var mpname = mpname_node.getValue();
if (mpname == nil) { return(0) } if (mpname == nil) { return(0) }
splitname = split("/", mpname); splitname = split("/", mpname);
cutname = splitname[1]; #
# cutname = splitname[1];
#
# **** by 5H1N0B1 05/01/2014
# Fixed a problem onboard radar happens automatically when you are in range of an mp gamer that uses "OpenRadar"
#
cutname = splitname[size(splitname)-1];
} }
return( cutname ); return( cutname );
} }
var radis = func(t, my_radarcorr) { var radis = func(t, my_radarcorr) {
cutname = get_aircraft_name(t); cutname = get_aircraft_name(t);
# Calculate the rcs detection range, # Calculate the rcs detection range,
# if aircraft is not found in list, 0 (generic) will be used. # if aircraft is not found in list, 0 (generic) will be used.
acname = aircraftData[cutname]; acname = aircraftData[cutname];
if ( acname == nil ) { acname = 0 } if ( acname == nil ) { acname = 0 }
rcs_4r = radarData[acname][3]; rcs_4r = radarData[acname][3];
# Add a correction factor for altitude, as lower alt means # Add a correction factor for altitude, as lower alt means
# shorter radar distance (due to air turbulence). # shorter radar distance (due to air turbulence).
alt_corr = 1; alt_corr = 1;
alt_ac = mpnode.getNode("position/altitude-ft").getValue(); alt_ac = mpnode.getNode("position/altitude-ft").getValue();
if (alt_ac <= 1000) { if (alt_ac <= 1000) {
alt_corr = 0.6; alt_corr = 0.6;
} elsif ((alt_ac > 1000) and (alt_ac <= 5000)) { } elsif ((alt_ac > 1000) and (alt_ac <= 5000)) {
alt_corr = 0.8; alt_corr = 0.8;
} }
# Add a correction factor for altitude AGL. Skip if AI tanker. # Add a correction factor for altitude AGL. Skip if AI tanker.
agl_corr = 1; agl_corr = 1;
if ( find("tanker", t) == 0 ) { if ( find("tanker", t) == 0 ) {
mp_lon = mpnode.getNode("position/longitude-deg").getValue(); mp_lon = mpnode.getNode("position/longitude-deg").getValue();
pos_elev = geo.elevation(mp_lat, mp_lon); pos_elev = geo.elevation(mp_lat, mp_lon);
if (pos_elev != nil) { if (pos_elev != nil) {
mp_agl = alt_ac - ( pos_elev / FT2M ); mp_agl = alt_ac - ( pos_elev / FT2M );
if (mp_agl <= 40) { if (mp_agl <= 40) {
agl_corr = 0.03; agl_corr = 0.03;
} elsif ((mp_agl > 40) and (mp_agl <= 80)) { } elsif ((mp_agl > 40) and (mp_agl <= 80)) {
agl_corr = 0.07; agl_corr = 0.07;
} elsif ((mp_agl > 80) and (mp_agl <= 120)) { } elsif ((mp_agl > 80) and (mp_agl <= 120)) {
agl_corr = 0.25; agl_corr = 0.25;
} elsif ((mp_agl > 120) and (mp_agl <= 300)) { } elsif ((mp_agl > 120) and (mp_agl <= 300)) {
agl_corr = 0.4; agl_corr = 0.4;
} elsif ((mp_agl > 300) and (mp_agl <= 600)) { } elsif ((mp_agl > 300) and (mp_agl <= 600)) {
agl_corr = 0.7; agl_corr = 0.7;
} elsif ((mp_agl > 600) and (mp_agl <= 1000)) { } elsif ((mp_agl > 600) and (mp_agl <= 1000)) {
agl_corr = 0.85; agl_corr = 0.85;
} }
} }
} }
# Calculate the detection distance for this multiplayer. # Calculate the detection distance for this multiplayer.
det_range = my_radarcorr * rcs_4r * alt_corr * agl_corr / NM2KM; det_range = my_radarcorr * rcs_4r * alt_corr * agl_corr / NM2KM;
# Compare if aircraft is in detection range and return. # Compare if aircraft is in detection range and return.
act_range = mpnode.getNode("radar/range-nm").getValue() or 500; act_range = mpnode.getNode("radar/range-nm").getValue() or 500;
if (det_range >= act_range) { if (det_range >= act_range) {
return(1); return(1);
} }
return(0); return(0);
} }
var radar_horizon = func(our_alt_ft, target_alt_ft) { var radar_horizon = func(our_alt_ft, target_alt_ft) {
if (our_alt_ft < 0 or our_alt_ft == nil) { our_alt_ft = 0 } if (our_alt_ft < 0 or our_alt_ft == nil) { our_alt_ft = 0 }
if (target_alt_ft < 0 or target_alt_ft == nil) { target_alt_ft = 0 } if (target_alt_ft < 0 or target_alt_ft == nil) { target_alt_ft = 0 }
return( 2.2 * ( math.sqrt(our_alt_ft * FT2M) + math.sqrt(target_alt_ft * FT2M) ) ); return( 2.2 * ( math.sqrt(our_alt_ft * FT2M) + math.sqrt(target_alt_ft * FT2M) ) );
} }
var load_data = func { var load_data = func {
# a) converts aircraft model name to lookup (index) number in aircraftData{}. # a) converts aircraft model name to lookup (index) number in aircraftData{}.
# b) appends ordered list of data into radarData[], # b) appends ordered list of data into radarData[],
# data is: # data is:
# - acname (the index number) # - acname (the index number)
# - the first (if several) aircraft model name corresponding to this type, # - the first (if several) aircraft model name corresponding to this type,
# - RCS(m2), # - RCS(m2),
# - 4th root of RCS, # - 4th root of RCS,
# - radar type, # - radar type,
# - max. radar range(km), # - max. radar range(km),
# - max. radar range target seize(RCS)m2, # - max. radar range target seize(RCS)m2,
# - 4th root of radar RCS. # - 4th root of radar RCS.
var data_node = props.globals.getNode("instrumentation/radar-performance/data"); var data_node = props.globals.getNode("instrumentation/radar-performance/data");
var aircraft_types = data_node.getChildren(); var aircraft_types = data_node.getChildren();
foreach( var t; aircraft_types ) { foreach( var t; aircraft_types ) {
var index = t.getIndex(); var index = t.getIndex();
var aircraft_names = t.getChildren(); var aircraft_names = t.getChildren();
foreach( var n; aircraft_names) { foreach( var n; aircraft_names) {
if ( n.getName() == "name") { if ( n.getName() == "name") {
aircraftData[n.getValue()] = index; aircraftData[n.getValue()] = index;
} }
} }
var t_list = [ var t_list = [
index, index,
t.getNode("name[0]").getValue(), t.getNode("name[0]").getValue(),
t.getNode("rcs-sq-meter").getValue(), t.getNode("rcs-sq-meter").getValue(),
t.getNode("rcs-4th-root").getValue(), t.getNode("rcs-4th-root").getValue(),
t.getNode("radar-type").getValue(), t.getNode("radar-type").getValue(),
t.getNode("max-radar-rng-km").getValue(), t.getNode("max-radar-rng-km").getValue(),
t.getNode("max-target-sq-meter").getValue(), t.getNode("max-target-sq-meter").getValue(),
t.getNode("max-target-4th-root").getValue(), t.getNode("max-target-4th-root").getValue(),
t.getNode("ecm-type-num").getValue() t.getNode("ecm-type-num").getValue()
]; ];
append(radarData, t_list); append(radarData, t_list);
} }
} }
var launched = 0; var launched = 0;
var init = func { var init = func {
if (! launched) { if (! launched) {
print("Initializing Radar Data"); print("Initializing Radar Data");
io.read_properties(data_path, props.globals); io.read_properties(data_path, props.globals);
load_data(); load_data();
launched = 1; launched = 1;
} }
} }