AI routine for "caravan units", which are modded units whose purpose is to be disbanded for shields -- This is like the custom unit AI for pop units, only for modded units that add shields instead of pop points. To be considered a caravan unit (the name comes from Civ 2), a unit must use the terraform AI strategy, have no worker actions enabled, have the ability to disband, and have zero attack, defense, & bombard strengths. The AI will move such units to an appropriate city and disband them for shields. The AI logic is relatively simple, it tries to get the full shield value from disbanding, prioritizes less corrupt cities when disbanding into infrastructure, and is smart enough not to try to disband into wonders.
Caravans, that's very interesting.
Unfortunately, this raises many questions in my curious mind.
If a caravan costs 100 shields and a city is only 99 (or 24 at a transfer ratio of 75%) shields short of completing a building, does that mean that the AI will not decide to use the caravan to speed up production at that moment and will instead send the caravan elsewhere? When is the decision made on how to use a caravan? I am referring to cases where, before the caravan arrives at its destination to speed up production, the building may already be nearing completion and will therefore not meet this condition ("it tries to get the
full shield value from disbanding,"). If the condition is not met, will the caravan wait in the city or leave for another location, if one exists?
If they use a
terraform AI strategy, does that mean they will respond to threats by hiding in the city like ordinary workers? Are they able to assign a defensive escort to themselves like artillery?
It does not, my main concern was just getting the full disband value of the unit. I programmed it to avoid disbanding into buildings in highly corrupt cities since I thought that otherwise the AI would waste its caravan units on the stupid infrastructure projects it tends to start in worthless cities. It's true, though, that that means the AI loses out on the option of using caravans as a way to build things in highly corrupt cities despite their corruption. I don't see any easy way to solve that without second guessing all of the AI's production choices.
What should the desired behavior be? If I created a test scenario with 20 cities in a row. On one side, the capital city with no corruption, and on the other side, the city with the highest level of corruption. All cities are connected by railroad. Then I would create 200 caravans. Let's assume that all cities are building something that can be accelerated by a caravan.
What behavior can we expect from the caravans?
If the
optimal number of cities is 10, to how many cities will the AI never send a caravan? Or rather, what percentage of corruption is classified as
highly corrupt cities? In my opinion, the AI should strive to transform peripheral cities, which are only a burden on thriving cities. And the sooner it manages to eradicate corruption, the better and more effective the AI will be.
Does their location matter?
If I place all the caravans in
one place, will they all go to speed up construction in one city, and once the building is finished, will they go to speed up construction in another place, or will each caravan go to a different destination to speed up construction?
Will this behavior change if I place 10 caravans in
each city? Or if the cities are only
connected by roads, or
not connected at all?
In the case of islands, are they able to use
transport ships (In the case where the caravan has a special action
Load) or
airports (In the case where the caravan has a special action Airlift)?
Are caravans immediately assigned tasks, or can they be kept in reserve (caravan escrow amount = 1 per 5 cities)?
These caravans in reserve should be specifically focused on accelerating the construction of buildings that reduce corruption in cities with high levels of corruption. Is it so difficult for AI to recognize that a city has high levels of corruption and
therefore designate it as a city that needs caravan assistance when it builds a building that reduces corruption?
During wars, these caravans should again be primarily intended as assistance for military and cultural buildings for cities close to enemies, as
@Predator145 pointed out. But here I am definitely getting into territory that should be covered by Lua, where one would customize something like caravan priorities and which buildings (or rather the effects of buildings) and cities to search for.
If I had two types of caravans, the first type
requiring support and the second not, would the AI be able to primarily assign tasks to caravans that require support in order to get rid of them as quickly as possible (for cases where it has too many units and has to pay for them) and keep the caravans that
don't require support in reserve?
I also considered connecting caravans with locally generated resources. For example, steel produced locally in a city factory could be transported by a caravan to another city for local use only. Upon arriving at the destination city and attempting to enter it, a table of options (
Enter the city;
Import steel) would appear with resources produced (only if any exist) in the caravan's city of origin that are lacking in the destination city. After the connection was established, the caravan would of course disappear as used and steel would be available in both cities. For simplicity, this connection would be unlimited in time. The flow of steel to the second city (or other cities) would only
temporarily stop if the factory in the first city stopped producing steel due to a disruption in the production chain or if the trade network was disrupted. The connection would be
permanently interrupted by the destruction or sale of the steel factory, or by changing the nationality of the city of Import or Export. I guess
the PROBLEM would be that the caravan would have to remember the city where it was manufactured and what resources are locally generated in that city in order for this micro-trade connection to be successfully implemented. Also, the fact that a local resource is imported (shared) somewhere must be remembered somewhere. Yes, I consider this whole point to be highly challenging and therefore more like something from the world of dreams, but
I can't help but ask about its feasibility?
When I wrote the unit AI for caravans, I had in mind that they would be autoproduced from wonders. I didn't think of them as a way to transfer shields, so the AI's mostly just concerned with getting their full value immediately. I don't think it makes sense to use carvans to transfer shields since you lose 75% along the way. I can't imagine ever wanting to do that. Although, that 75% loss is something that could easily be changed.
I can imagine that
one type of caravan would be produced automatically by the wonder. Such a unit would cost, say, 400 shields, so at 75% it would give 100 shields as aid. However, another wonder could allow the construction of a
second type of caravan, which would cost, say, 50 shields and would also give 50 shields as aid, thus ignoring 75%. Is it true that the number of shields also tells the AI how much to value a given unit? If so, the loss of a caravan worth 400 shields during the war would be far more painful in the eyes of the AI than its actual value as aid.