It doesn’t.
The operator can feed it identification data on targets presumed friendly that then, assuming everything goes right, are not engaged.
Only in Hollywood is that system anywhere near perfect – in reality even the most sophisticated systems are “dumb” to the point that SAMs are not used when friendly aircraft are in the same bit of airspace.
Iran Air Flight 655 for a sad recent example: a USN cruiser shooting down a civilian airliner due to being unable to tell it apart from fighters that could have lounched from the same airport.
Latest Answers