The reason why the king tries to import/export is because it happens to all AI controlled players. Looking closely at it, it turns out that natives will do this too. It could be a good idea to skip this for natives as they can have quote a lot of cities and no transports meaning they spend time setting up something, which will never be used and it will do that every turn. 2071 and possibly M:C can have native transports in the future. However RaR might benefit from this discovery. I will have to look into that to tell if it boosts enough to make it worth the needed testing and stuff like that.
As the king is basically just another AI it will likely handle units similar to other AI controlled players and the coding part of your idea isn't king related as such, but more when and where to place extra units and when to remove them. Assuming he isn't at war with anybody he will attack pirates only, though it's likely he will attack your own pirate ships as well as they are foreign to the king. We can argue if that is a feature or a bug.
I'm still wondering how to set up AI traderoutes. Export to Europe appears to be ok. The issue is the yields consumed locally.
Right now for each non-sold yieldtype it loops all cities to find the best target for imports. The best one is the one where a single unit can produce the most yields with the selected yield as input. It doesn't consider how many units can have that profession and it doesn't look like rebel production bonus is applied either. If more than one city is the best in this case, then it picks the one with the highest population. If more than one has the highest population of those, then it picks the one the civ gained first (time from founding or conquering). All cities then export that yield to that single city.
I'm thinking of setting export and feeder on all yields (except special ones like YIELD_FOOD). It will then turn import on and off automatically according to how much is stored and threshold. The threshold should then be:
- Yield needed by building being constructed
- Yield consumed by units in city * X (possibly potential consuming)
- Yields sold domestically * X
Now the question is what X should be in each line and how well it would work. It would likely be a good idea to keep some "best city" code to prefer blacksmith's shop over blacksmith's house.
From what I can tell this would scale to many cities much better than the vanilla code. For instance right now if the best city is on planet A, then all cities on planet B will end up stockpiling that yield. With this modification both planets will have domestic transports and domestic consumption.
Also it allows more yields to be transported with fewer special rules. Lumber can easily be moved to cities without forest even without special rules. I don't think it's even transported right now. This would make non-forest cities much better for the AI.
Certain yields should be stored even without a need. Food should be maintained at 50% of growth threshold to allow cities, which survives on imported food, tools should always be at least 50 to allow pioneers etc.
Ideas are welcome on how this should work. Right now I'm investigating what the AI should do. Figuring out how to code it and get proper performance is postponed until I have a clear goal of what it should do.
At some point I will also have to look at how the AI picks professions in a city. Cities should start producing more of yields needed by other cities to make a better overall production/consume for all cities combined.
I added terrain textures for Aquatic Planets; Planets mapscript doesn't yet generate them but they're working well when tested with the editor. I added the Space terrain textures for Coast and Ocean, but they're obscured by waves since they're still water terrains.
I don't think we should worry about stuff like waves in space at this point. It might be a trivial thing to solve later on and it's just a graphical thing. The focus should really be to make the game playable, then such glitches can be dealt with. Maybe the solution is to make a new space domain and not remove waves at all from water domain. Time will tell once we get that far.