Iustus
King
In my present game, I did notice a large stack of longbowmen with city defense upgrades accompanying a huge attack stack of the AI. The total number of units used in the attack must have been something like 60-80 (split in several stacks). But there were about 20 city defense upgraded longbowmen units in the attack stacks and also about 10 pikemen (who are also better used defensively in general with a few to defend the attack stack). I'm happy to say that artillery (hwacha's and trebuchets) and macemen were the largest part of the stack.
You cannot tell what the longbowmen are meant to be doing just by looking at their upgrades. You need to be using chipotle mode (or go into worldbuilder and check each unit individually with edit unit). What you are looking for is the unit's "UnitAI".
The main unit AI used for defending cities is "UNITAI_CITY_DEFENSE", or "city defense" in shorthand. Most display areas under chipotle will display the full unit AI name, but I shortened the names some in the ctrl-key hover over stacks display, so that it would fit all on one line.
This spoiler shows all the UnitAIs (and the shorthand I used for the ctrl hover case).
Spoiler :
case UNITAI_UNKNOWN: szString = L"unknown"; break;
case UNITAI_ANIMAL: szString = L"animal"; break;
case UNITAI_SETTLE: szString = L"settle"; break;
case UNITAI_WORKER: szString = L"worker"; break;
case UNITAI_ATTACK: szString = L"attack"; break;
case UNITAI_ATTACK_CITY: szString = L"attack city"; break;
case UNITAI_COLLATERAL: szString = L"collateral"; break;
case UNITAI_PILLAGE: szString = L"pillage"; break;
case UNITAI_RESERVE: szString = L"reserve"; break;
case UNITAI_COUNTER: szString = L"counter"; break;
case UNITAI_CITY_DEFENSE: szString = L"city defense"; break;
case UNITAI_CITY_COUNTER: szString = L"city counter"; break;
case UNITAI_CITY_SPECIAL: szString = L"city special"; break;
case UNITAI_EXPLORE: szString = L"explore"; break;
case UNITAI_MISSIONARY: szString = L"missionary"; break;
case UNITAI_PROPHET: szString = L"prophet"; break;
case UNITAI_ARTIST: szString = L"artist"; break;
case UNITAI_SCIENTIST: szString = L"scientist"; break;
case UNITAI_GENERAL: szString = L"general"; break;
case UNITAI_MERCHANT: szString = L"merchant"; break;
case UNITAI_ENGINEER: szString = L"engineer"; break;
case UNITAI_SPY: szString = L"spy"; break;
case UNITAI_ICBM: szString = L"icbm"; break;
case UNITAI_WORKER_SEA: szString = L"worker sea"; break;
case UNITAI_ATTACK_SEA: szString = L"attack sea"; break;
case UNITAI_RESERVE_SEA: szString = L"reserve sea"; break;
case UNITAI_ESCORT_SEA: szString = L"escort sea"; break;
case UNITAI_EXPLORE_SEA: szString = L"explore sea"; break;
case UNITAI_ASSAULT_SEA: szString = L"assault sea"; break;
case UNITAI_SETTLER_SEA: szString = L"settler sea"; break;
case UNITAI_MISSIONARY_SEA: szString = L"missionary sea"; break;
case UNITAI_SPY_SEA: szString = L"spy sea"; break;
case UNITAI_CARRIER_SEA: szString = L"carrier sea"; break;
case UNITAI_ATTACK_AIR: szString = L"attack air"; break;
case UNITAI_DEFENSE_AIR: szString = L"defense air"; break;
case UNITAI_CARRIER_AIR: szString = L"carrier air"; break;
The UnitAI for a unit is the single most important thing to determining what actions the unit will take. With a few exceptions, once built, a unit never changes its unit ai. So a warrior built with an AI of explorer, will always remain an explorer, always doing exploring actions. Now, a warrior built with a unit ai of attack (the default for a warrior), may also perform exploring actions, when it has nothing better to do, but it is still primarily an attack unit. Each unit ai has its own set of orders of what to do.
For example, a city defense unit does this:
Spoiler :
- check to see if it should attack out of city
- check to see if it is needed to stay in the city for defense
- check to see if a settler group needs it for protection
- check to see if a settler on a transport that needs it for protection
- check to see if it can airlift to a city that needs it for protection
- check to see if there is a city we can path to that needs us to guard it
- check to see if there is an attack city group we can join (with less than 3 city defenders in it)
- retreat to the nearest city
- retreat to safe location
- skip turn
while a city attack unit does this
Spoiler :
- if it is solo, in its city, and has damage, heal
- if it is in city it just captured, remove all non-city attack units from the group (dropping them off in the captured city potentially)
- check to see if any city within one turn needs this stack for defense
- combine groups with any other city attack groups on the same plot
- attack any enemy city one turn away if power threshold is 250%
- bombard any enemy city in range
- attack any enemy city one turn away if power threshold is 100%
- combine with any city attack groups up to 2 turns away
- heal (possibly splitting group) any units at least 70% damaged
- if in local territory, load assault force on transport if one exists
- if in local territory, and enough units are headed to combine with this group (comparing the sizes of the two), and there is danger about, wait for those units
- attack adjacent city if odds are 30% or better
- if does collateral damage, attack any adjacent stacks of at least 3 units if odds are 45% or better
- attack any adjacent unit if odds are 60% or better
- heal any units that are at least 50% damaged
- if not at war with owner of current plot, heal if any damage at all
- if not at war with owner of current plot, and group is size 1, retreat to our closest city
- if this unit has a defensive bonus, check to see if there is a city in danger we need to guard
- if we are size one, check any city attack group within 10 turns, to see if we can join it
- if this stack is large enough, attempt to target an enemy city and send this stack to it
- heal if any units are damaged
- move to a staging city
- target a barbarian city
- airlift to a forward area
- retreat to closest city
- retreat to safety
- skip turn
Each UnitAI has its own list of actions it attempts. Once it is succesful finding something to do, it does not check lower down on the list.
Note, it is entirely possible to have, say, two longbows, both with city defense promotions, but one with a UnitAI of City Defense, and a second with a UnitAI of City Attack. These UnitAIs will determine the course of action those units take, more than anything else.
This is why I display the UnitAI under chipotle when you ctrl hover over a group. It is the UnitAI of the group leader that determines what the whole group will do (for the most part). An example of an exception of this, is when a city attack group captures a city, then it splits all the units off of its group which do not have the city attack AI. Note however, that its entirely possible that those units will immediately decide to rejoin the group, that is acceptible, but they are first given the chance to decide to defend a city.
It is groups, not individual units, that are counted to determine how many defenders a city has. This is why city defenders are never grouped when they are on city defense.
As far as when the build will be posted, the answer is when it is ready. I know that is not what you want to hear, but that is the best answer I can give you. No point in posting the build until that fix is in.

-Iustus