It is most likely possible to force the AI to reserve the gold for the executives (incidently, it's not just rush buying that's causing problems, I did try reserving gold, but then the AI spent it on unit upgrades). I've been reluctant to do that. The problem with forcing it to reserve gold for executives is it makes the assumption that spreading a corporation is preferable to rushing/upgrading. And that's an entirely situational call. I can think of dozens of scenarios where rushing/upgrading is the preferable choice to make. So the solution can't simply be "always reserve gold for executives". That means we have to get into valuation, which is where the real difficulty starts. How do you judge whether it's more valuable to rush a building or spread a corporation?
Bh
Ah, the way I had understood it, there was little hope to program the AI to reserve money for executives. I understand your reluctance to do that as it could result in worse AI behaviour.
Maybe we can come up with some relatively smart guidelines for the AI. We can criticise eachothers guidelines until they are somewhat reasonable. We don't have to go for perfection, just something that works reasonable and isn't too complicated. The more complicated the guidelines, the more likely there is some loophole we forget about.
The most expensive part of spreading a corporation domestically is the investment of hammers in the corporate executive. If you spend that many hammers into something, then you should get something back for it. So whenever the AI decides to build an executive, then it should be used as quickly as possible. Whenever the decision is made to build an executive, the decision to actually use the executive and thus reserve money to use the executive should be implicit. If you don't plan to reserve money for the executive, then you shouldn't even build it.
Ok, here is a very crude and simple guideline which is open for criticism:
AI is at peace:
Rule 1: Only build executives as long as you have less than 5 available or in production (set the AI corporate unit cap at 5 for all of its combined executives).
Rule 2: calculate the value of creating a corporate office:
value (domestic office) = Food*3 + hammer*2 + commerce (gold or science)*1 + culture/3 + 8 (if you have the headquarters) - (value already present competing corporate office +5)
value (foreign office) = 8 (if you have the headquarters and no other competing corporate office of which you have the headquarters exists)
Value domestic is calculated when number of executives build and under construction is smaller or equal to the number of domestic cities without the corporate office. Otherwise it is 0. Value foreign is calculated if there is a foreign city to which the corporation can be spread.
Generate a random number between 5 and 20. When this number is smaller than the value of the corporate office (foreign or domestic), then build an executive.
Or use this value in another way to see whether it is desirable to create a corporate executive or build something else. Other constructions are probably also valued in some way.
Rule 3: Reserve enough money to create a number of corporate offices equal to the number of executives available. The amount of money needed is dependent on the whether the corporations should be spread domestically or foreign and whether another competing corporation is present, so ideally the corporate executive should be build with a predetermined use. (just like units are often created with offensive or defensive purposes) That way the cost of their use could be calculated and the correct amount of money could be reserved.
When at war:
When losing don't build executives.
When winning:
Rule 1 with a cap of 2 instead of 5.
Rule 2 with a random number between 15 and 50 instead of 5 and 20.
Rule 3 with the exception if a city is under threat of capture and cash rushing a unit or upgrading a unit in the city is possible.
Ok, it must be apparent that I don't know how the code looks like. Still, it might spark some thoughts among others and might be a stepping stone.
The main point is that if you decide to build the executive, then you should use it since the hammer investment is the largest investment in creating a corporate office. Whenever you decide to create a corporate executive the value of the corporate office should be such that you're willing to reserve money for it.