@ -27,7 +27,7 @@ var mlw_max=getprop("payload/d-config/mlw_max"); #
var auto_flare_caller = getprop("payload/d-config/auto_flare_caller"); # If damage.nas should detect flare releases, or if function is called from somewhere in aircraft
"3M9": [96, 125.00,0,0],# 3M9M3 Missile used with 2K12/SA-6
"5V28V": [97, 478.00,0,0],# Missile used with S-200D/SA-5
"AIM-9X": [98, 20.80,0,0],
"5V27": [99, 150.00,0,0],
"AGM-65G": [100, 150.00,1,0],
"R-23R": [99, 55.00,0,0],# mig23 fox 1
"5V27": [100, 150.00,0,0],# Missile used with SA-3/S-125
# Max id is 180
};
var AIR_RADAR = "air";
@ -184,29 +186,33 @@ var radar_signatures = {
"m2000-5B": AIR_RADAR,
"MiG-21bis": AIR_RADAR,
"MiG-21MF-75": AIR_RADAR,
"Mig-23MLD": AIR_RADAR,
"MiG-29": AIR_RADAR,
"SU-27": AIR_RADAR,
"EC-137R": AIR_RADAR,
"E-3R": AIR_RADAR,
"E-3": AIR_RADAR,
"RC-137R": AIR_RADAR,
"E-8R": AIR_RADAR,
"EC-137D": AIR_RADAR,
"Mig-28": AIR_RADAR,
"SA-6": "gnd-06",#Air radar tone chosen so that there is at least some lock tone until asset-specific is created
"SA-6": "gnd-06",
"s-200": "gnd-05",
"ZSU-23-4M": "gnd-23",
"S-75": "gnd-02",
"buk-m2": "gnd-11",
"buk-m2": "gnd-17",
"s-300": "gnd-20",
"MIM104D": "gnd-p2",
"missile_frigate": "gnd-nk",
"fleet": "gnd-nk",
"SA-3": "gnd-p2",
};
var id2warhead = [];
var launched = {};# callsign: elapsed-sec
var approached = {};# callsign: uniqueID
var heavy_smoke = [61,62,63,65,92,96,97,99];
var heavy_smoke = [61,62,63,65,92,96,97,100];
var k = keys(warheads);
@ -310,7 +316,7 @@ var DamageRecipient =
var radarOn = bits.test(notification.Flags, 0);
var thrustOn = bits.test(notification.Flags, 1);
var CWIOn = bits.test(notification.Flags, 2);
var index = notification.SecondaryKind-21;
var index = DamageRecipient.emesaryID2typeID(notification.SecondaryKind);
var typ = id2warhead[index];
if (notification.Kind == MOVE) {
@ -404,6 +410,7 @@ var DamageRecipient =
setprop("payload/armament/MAW-active", 1);# resets every 1 seconds
} elsif (CWIOn) {
setprop("payload/armament/MAW-semiactive", 1);# resets every 1 seconds
if (notification.Callsign != nil) setprop("payload/armament/MAW-semiactive-callsign", notification.Callsign);# resets every 1 seconds
}
MAW_elapsed = elapsed;
var appr = approached[notification.Callsign~notification.UniqueIdentity];
@ -412,8 +419,8 @@ var DamageRecipient =
#printf("Missile Approach Warning from %03d degrees.", bearing);
damageLog.push(sprintf("Missile Approach Warning from %03d degrees from %s.", bearing, notification.Callsign));
if (rwr_to_screen) screen.log.write(sprintf("Missile Approach Warning from %03d degrees.", bearing), 1,0.5,0);# temporary till someone models a RWR in RIO seat
# getUnique() - Used when comparing 2 targets to each other and determining if they are the same target.
# isValid() - If this target is valid
# getElevation()
# get_bearing()
# get_Callsign()
# get_range()
# getElevation() - Pitch to target from launch vehicle
# get_bearing() - Bearing to target from launch vehicle
# get_Callsign()
# get_range() - NM
# get_Coord()
# get_altitude()
# get_altitude() - FT
# get_Pitch()
# get_Speed()
# get_heading()
# get_uBody()
# get_vBody()
# get_wBody()
# get_uBody() - Body velocities in ft/s. Forward component.
# get_vBody() - Right component
# get_wBody() - Down component
# getLastGroundTrackBlep() - Used for sample guidance
# getFlareNode() - Used for flares.
# getChaffNode() - Used for chaff.
# isPainted() - Tells if this target is still being radar tracked by the launch platform, only used in semi-radar guided missiles.
# isLaserPainted() - Tells if this target is still being tracked by the launch platform, only used by laser guided ordnance.
# isRadiating(coord) - Tell if anti-radiation missile is hit by radiation from target. coord is the weapon position.
# isCommandActive()
# isSpikingMe() - Tells if the target is STT locked on launch platform.
# isCommandActive() - If surface based launcher is still tracking (command guidance) or have a search blep (TVM) on target.
# isVirtual() - Tells if the target is just a position, and should not be considered for damage.
# get_closure_rate() - closure rate in kt
# get_closure_rate() - closure rate in kt to launch platform
var AIM = {
lowestETA: nil,
@ -312,6 +305,8 @@ var AIM = {
m.radarZ = getprop(m.nodeString~"FCS-z"); # In future I will add direction to it also, for now its center gimbal is along -x axis.
m.expand_min = getprop(m.nodeString~"expand-min-fire-range"); # Bool. Default false. If min fire range should expand with closing rate. Mainly use this for A/A missiles.
me.redux = me.guidance == "semi-radar" or me.guidance == "command" or me.guidance == "tvm"?(me.gnd_launch?0.5:0.75):1;
me.chaffChance = (1-me.chaffResistance)*me.redux;
me.chaffLock = rand() < (me.chaffChance - (me.chaffChance * 0.5 * me.aspectDeg));# 50% less chance to be fooled if front aspect
me.chaffLock = rand() < (me.chaffChance - (me.chaffChance * 0.70 * me.aspectDeg));# 70% less chance to be fooled if front aspect
if (me.chaffLock) {
me.printStats(me.type~": Missile locked on chaff from "~me.callsign);
@ -3337,7 +3391,7 @@ var AIM = {
},
checkForLOS: func () {
if (pickingMethod and me.guidance != "gps" and me.guidance != "gps-laser" and me.guidance != "unguided" and me.guidance != "inertial" and me.guidance != "sample") {
if (me.guidance != "gps" and me.guidance != "gps-laser" and me.guidance != "unguided" and me.guidance != "inertial" and me.guidance != "sample") {
me.printStats(me.type~": Passed minimum speed for guiding after %.1f seconds. Target %d%% inside view.", me.life_time, me.normFOV*100);
}
}
if (me.chaffLock and (me.guidance == "command" or me.guidance == "semi-radar" or me.guidance == "tvm") and (me.life_time - me.chaffLockTime) > (me.gnd_launch?4:6)) {
if (me.guidance == "gps" or me.guidance == "inertial" or me.guidance == "sample") {
# To make sure deviation_deg is updated in midflight function.
if (me.chaffLock and (me.guidance == "command" or me.guidance == "semi-radar" or me.guidance == "tvm") and (me.life_time - me.chaffLockTime) > (me.gnd_launch?4:8)) {
if (me.ready_standby_time != 0 and getprop("sim/time/elapsed-sec") > (me.ready_standby_time+me.ready_time)) {
me.curr_time = getprop("sim/time/elapsed-sec");
me.consumeBattery(me.curr_time);
if (me.ready_standby_time != 0 and me.hasPowerEnough() and ((!me.powerOnRequired and me.curr_time > (me.ready_standby_time+me.ready_time)) or (me.powerOnRequired and (me.powerOn and me.curr_time > me.power_on_time + me.ready_time)))) {
me.status = MISSILE_SEARCH;
me.search();
return;
@ -4752,6 +4833,7 @@ var AIM = {
if (deltaSec.getValue()==0) {
settimer(func me.search(), 0.5);
}
me.printCode("In search()");
if (me.deleted) {
return;
} elsif ( me.status == MISSILE_FLYING ) {
@ -4765,13 +4847,21 @@ var AIM = {
#me.trackWeak = 1;
me.standby();
return;
} elsif (me.powerOnRequired and (!me.powerOn or (me.powerOnBatteryTime > 0 and me.powerAvailable < me.powerOnBatteryTime * 0.05))) {
me.coord3.set_alt(coord1.alt()-me.d12*0.5);# this will increase the area of the triangle so that rounding errors dont get in the way.
me.d13 = coord1.alt()-me.coord3.alt();
if (me.d12 == 0) {
# on top of each other, maybe rounding error..
return 0;
}
me.coord3 = geo.Coord.new(coord1);
me.coord3.set_alt(coord1.alt()-me.d12*5);# this will increase the area of the triangle so that rounding errors dont get in the way. Changed to 5 May 2023, which gives more presision than 0.5 when c1 and c2 are very close.
me.d13 = coord1.alt()-me.coord3.alt();
me.d32 = me.coord3.direct_distance_to(coord2);
if (math.abs(me.d13)+me.d32 < me.d12) {
# rounding errors somewhere..one triangle side is longer than other 2 sides combined.
@ -479,4 +479,4 @@ var unitTest = {
printf("These two should be the same %s = %s",Math.format(aircraft),Math.format(aircraft2));