Currently the rule is very simple: any AI will attack the first enemy ground object it sees. "See" is defined as visual sight or the sensors on any ground attack weapon that extends visual range. If the AI sees both air defense and non-air-defense targets it will attack the air defense targets first.
There needs to be some thought put into how to make this more sophisticated.
I saw this earlier this week when my B-25 and 3 wingmen were flying to attack an airfield.
On the way we went past some coastal Flak positions and the wingmen went off to engage the flak.
Wingmen can already be ordered to attack ground or air defence targets, is there a way they could be ordered to go weapons tight on ground targets, whilst still allowing them to
engage A2A on incoming bandits approaching the formation. ...... basically some sort of air to air 'Defensive fire only' mode.