I'll play around with the code tonight. Do you know where the 'action point' is for a contact being 'targeted' without being engaged? 
 
 At the risk of TMI or redundant info.
 
 Yeah I figured the point of that code (eventually) was to try to figure out which contacts are targeted by whom and to not attack ones that already are being targeted by someone else.  Thing is you can't use targetedBy for that reliably, without another check because many units will auto generate targeting (but not engage\ or engage yet) for many contacts.  So targetedBy sometimes is more just "Who's available" when not paired with anything else, and last i recall it doesn't let you know who are tagged primary and who are secondary. Now ... you could turn some of that off with AI_EvaluateTargets_enabled and AI_DeterminePrimaryTarget_enabled on a per-unit bases to aid you if you are using your own AI where your attack orders will all be mostly issued manually\via code for the unit(s) involved but I'm not sure it'll actually help here. 
 
 .firedOn on the underlying contacts unit wrapper will show the unitguid of the firing unit, and .firingAt on the otherside\"friendly" side unit wrapper will have the contactguid for that sides entry for the contact being fired on. This can help narrow down who's actually engaged but it's not perfect either, as a unit could have things allocated or be 'engaging' but not yet fired anything. Unit.condition and Unit.unitstate can hint as well at engagement, but that doesn't always apply depending on different circumstances (like no mission involved).  Additionally you can scan a side's 'Weapon' units, you can then easily see both the contact who it was fired at and the shooter unit who fired it. That however doesn't necessarily mean the shooter is still shooting\engaged with it, though it often does mean that, what it does allow is you to decided if enough munitions are already inbound too a contact to consider it already engaged.
 
 
 Let's take an example where 
 Rhino1 and Rhino2 are two f-22 who for the sake of argument have weapons hold and AI stuff left untouched, are set on manual speed and altitude to just loop around in an area where two H-6K's are doing the same, there is a bigbird-d radar near by and f-22's are radiating as well so contacts are aquired  in matter seconds, no missions are involved.
 To keep things simple the guids involved will be
 H-6K #1 unitguid: CUSTOM-H6K0000000001 bluecontactguid: CONTAC-BLUE000000001
 H-6K #2 unitguid: CUSTOM-H6K0000000002 bluecontactguid: CONTAC-BLUE000000002
 F-22 #1 unitguid: CUSTOM-F220000000001 
 F-22 #2 unitguid: CUSTOM-F220000000002 
 AIM-260 #1 (launched by f-22#1) guid: CUSTOM-AIM000FF2201 redcontactguid: CONTAC-RED0000000001
 
 After a few seconds the H-6's will be contacts and both f-22's will have targeting solutions but not fired because doctrine. 
 Grabbing Blue's contacts will show the following for both the H-6K's contact wrapper targetedBy.
 { 0 = 'CUSTOM-F220000000001', 1 = 'CUSTOM-F220000000002' }
 
 Now let's say you via the gui (or lua) tell F-22#1 to fire 1 AIM-260 at H-6K #1, let pretend it's close or just beyond max range, or a turn has to be completed first so that it takes say 5\10 more seconds to fire while already being allocated.
 
 Before it fires...nothing will change, nobody knows from what I know is available in lua that f-22#1 is about to or wants to fire on H6K#1.
 Now after it fires within a second or two things will look like this from Blue's perspective.
 
 bluecontactguid:CONTAC-BLUE000000001 
 targetedBy: { 0 = 'CUSTOM-F220000000001', 1 = 'CUSTOM-F220000000002', 2 = 'CUSTOM-AIM000FF2201' }
 .firedOn: nil - it doesn't know\doesn't apply.
 
 bluecontactguid:CONTAC-BLUE000000002  (unchanged)
 .targetedBy: { 0 = 'CUSTOM-F220000000001', 1 = 'CUSTOM-F220000000002' }
 
 F22#1 unit wrapper:
 .firingAt: {0 = 'CONTAC-BLUE000000001'}
 
 H6K#1 unit wrapper: (least till it see's incoming missile):
 .targetedBy: { 0 = 'CUSTOM-F220000000001', 1 = 'CUSTOM-F220000000002', 2 = 'CUSTOM-AIM000FF2201' }
 .firedOn: {0 = 'CUSTOM-F220000000001'} - but the contacts underlying unit wrapper knows who the real unit who fired at it is.
 
 
 Aim260 unitguid:CUSTOM-AIM000FF2201 's unitwrapper:
 .weapons: {contact=(contact wrapper for: CONTAC-BLUE000000001), shooter=(unitwrapper for: CUSTOM-F220000000001)}
 .firingAt: nil
 .firedOn:nil
 
 If we were evaluating if f-22 #2 should be ordered to fire on either contact we could determine that looking up firedOn on each contacts actual unit, if anything exists then it's been fired on and it will tell you how many shooters by the number of entries, and whom by the contents of those entries (ie can check for self). But you don't know how weapons have been fire, just whom has\had fired.
 Alternatively we could just run though all weapons who's contact.guid match those whom were targetable +1 to a weapon counter, or +1 to a counter per shooter guid too for that matter.  Any way we could see F-22#1 already shot 1 missile at H-6K#1 and determine not to attack him right now, but when it comes to H-6k#2 we would qualify him as available.
 
 I could maybe work up a little demo if this is just confusing, probably not till weekend though.  
 I had stopped some tinkering in this area because of the lack of a an un-engage in Lua was frustrating the hell out of me but now that it's been added and couple other enhancements lately I should get back to tinkering.