@Charles555nc, I just look a quick look at the code that handles that kind of thing.. and it does look a bit problematic. The AI does know to move ships out of cities that are in danger, but apparently it does not know to not move the ships back into the cities. It looks like I'll have to rewrite another one of the original functions to fix this.
@En_Dotter, I think that's probably a good idea, but I don't really want to make Free Religion any stronger than it already is; and so I'm not sure if adding new xml values and so on would be worth it. (From a balance point of view, I think pacifism is the only one that's a bit on the weak side; and Free Religion is the main one that would benefit from having higher spread of other religions...) Anyway, so far I'm pretty happy with how the new formula I've been testing with. So I'll just leave it at that for the time being, and then consider adding new variables later on.
The new version is coming along nicely. Once again, I've found a bunch of problems in the way corporations are handled by the AI. Corporations are fairly complex things for the AI - they need the right tech and the right great people, and the right resources, and then they need to build the execs at the right times to spread to the right cities, with the right civics, and so on...; and the original code was quite bad. So anyway, I've fixed a few corporation related problems -- and some other AI stuff; and the religion thing is going well.