Trying to figure out all the possible contingencies that could happen in a game as complex as Aurora, and the possible consequences of them all is quite a daunting task, for very little gain in the end.
Yes, I have spent the last two evenings doing nothing but optimise the AI code that decides when a ship reloads missiles
It is surprising how many factors have to be considered to make a decision that at first glance would seem to be trivial. There can be multiple ships in an AI fleet, only some of which are missile-armed, and different ships have different values in terms of whether the fleet can accomplish its missions, which means reloading some ships is more urgent than others, plus the presence, proximity and capability of hostile units can change the decision and also the location of the reload point versus the ship's current location. The current amount of ordnance vs maximum possible is also a factor. I've also had to handle the situation where a ship is firing from a location in which it can simultaneously reload to make sure it doesn't just fire a single missile as soon as it arrives in the magazine (because reloading now takes time).
Consider that relatively minor decision vs all the other decisions that the AI has to make and you get an idea of the scale of the AI programming task
Have you considered breaking the actual AI logic out into text files that the specific code calls when a decision is needed? ie when magazines are empty call ai_missile_reload.txt and then breaking the actual logic out into that file (like Space Empires did around version 3) though I suspect that would cause a performance hit it would make tweaking the ai easier
The AI is too integrated into everything else for it to be separated into a standalone file. For example, each ship AI checks its own status with a variety of parameters (fuel, ordnance, damage, ability to perform primary mission, etc). For ordnance for example, there are five statuses. Ordnance Not Needed, Fully Loaded, Reload Required, Urgent Reload Required and Empty. Each fleet AI then checks the status of its constituent ships and makes a determination at the fleet level for each status, which is different for the whole fleet vs any key element ships. So the ordnance status of a key element ship is more important than an escort and the number of ships with lower ordnance statuses has an impact too. The Race AI will take account of the fleet status when deciding how to deploy the ships within the Empire and the System AI will use the status when deciding how to deploy the fleets assigned to it by the Race AI.
The code that checks for fleets needing a reload occurs in three places, depending on the urgency of other tasks. So in some situations a fleet with a status of Reload Required might be sent to reload, although perhaps not if there are hostile ships in the system, depending on the threat posed by those ships (threat is assessed at a system level and for each grouping of hostile ships). The level of threat required to overcome an Urgent Reload Required status is different than for Reload Required, so the AI may sent urgent status fleets for reload, then assign other available forces to deal with the threats (or run away from them) and then check for reload status fleets that were not required to deal with threats, etc.
When a reload decision is made, the Population AIs check their own missiles available and the System and Race AIs try to match up ships needing particular missile types with those missiles available at population, taking into account demand so that sufficient missiles are available at a population for the ships en route to reload. Some ships may be sent further away if a population doesn't have sufficient missiles to meet local demand.
With those type of interactions, you can't really create a standalone script file because the reload isn't a standalone decision.