diff --git a/Nasal/radar/radar-system.nas b/Nasal/radar/radar-system.nas index f0f6752f..9b77a0c4 100644 --- a/Nasal/radar/radar-system.nas +++ b/Nasal/radar/radar-system.nas @@ -908,8 +908,16 @@ var AIContact = { # This is for inaccurate radar locking of surface targets with TGP. if (me.virt != nil) return me.virt; me.virt = {parents: [me, AIContact, Contact]}; - me.virtCoord = me.getCoord(); - me.virtCoord.set_xyz(me.virtCoord.x()+rand()*spheric_dist_m*2-spheric_dist_m,me.virtCoord.y()+rand()*spheric_dist_m*2-spheric_dist_m,me.virtCoord.z()+rand()*spheric_dist_m*2-spheric_dist_m); + me.virtCoord = me.getLastCoord(); + if (me.virtCoord == nil) { + me.virtCoord = me.getCoord(); + } + me.virt.rx = rand()*spheric_dist_m*2-spheric_dist_m; + me.virt.ry = rand()*spheric_dist_m*2-spheric_dist_m; + me.virt.rz = rand()*spheric_dist_m*2-spheric_dist_m; + me.virt.r = spheric_dist_m != 0; + me.virt.lastBleep = me.getLastBlep(); + me.virtCoord.set_xyz(me.virtCoord.x()+me.virt.rx,me.virtCoord.y()+me.virt.ry,me.virtCoord.z()+me.virt.rz; me.virt.elevpick = geo.elevation(me.virtCoord.lat(),me.virtCoord.lon()); if (spheric_dist_m != 0 and me.virt.elevpick != nil) me.virtCoord.set_alt(me.virt.elevpick);# TODO: Not convinced this is the place for the 1m offset since both missiles and radar subtract 1m from targetdistance, but for slanted picking with undulations its still good idea to not place it at the base. me.virt.coord = me.virtCoord; @@ -921,6 +929,17 @@ var AIContact = { return me.virt; }; me.virt.getCoord = func { + if (me.virt.lastBleep != me.getLastBlep()) { + # we have a new blep, calculate the offset coord for it + me.virtCoord = me.getLastCoord(); + if (me.virtCoord != nil) { + me.virtCoord.set_xyz(me.virtCoord.x()+me.virt.rx,me.virtCoord.y()+me.virt.ry,me.virtCoord.z()+me.virt.rz; + me.virt.elevpick = geo.elevation(me.virtCoord.lat(),me.virtCoord.lon()); + if (me.virt.r and me.virt.elevpick != nil) me.virtCoord.set_alt(me.virt.elevpick);# TODO + me.virt.coord = me.virtCoord; + } + me.virt.lastBleep = me.getLastBlep(); + } return me.virt.coord; }; me.virt.isVirtual = func {