Well, the CvCityStrategyAI::ChooseProduction function is used bor each city to determine what it should build (unit, building or wonder). The function is huge so I'll roll out the investigation results in turns. The first step is:
1) AI operates using operations - tasks it decides to do. These tasks are:
AI_OPERATION_CITY_CLOSE_DEFENSE,
AI_OPERATION_RAPID_RESPONSE,
AI_OPERATION_BASIC_CITY_ATTACK,
AI_OPERATION_DESTROY_BARBARIAN_CAMP,
AI_OPERATION_FOUND_CITY,
AI_OPERATION_PILLAGE_ENEMY,
AI_OPERATION_SNEAK_CITY_ATTACK,
AI_OPERATION_SMALL_CITY_ATTACK,
AI_OPERATION_MERCHANT_DELEGATION,
AI_OPERATION_NAVAL_BOMBARDMENT,
AI_OPERATION_NAVAL_SUPERIORITY,
AI_OPERATION_COLONIZE,
AI_OPERATION_QUICK_COLONIZE,
AI_OPERATION_NAVAL_ATTACK,
AI_OPERATION_NAVAL_SNEAK_ATTACK,
AI_OPERATION_CITY_STATE_ATTACK,
AI_OPERATION_CITY_STATE_NAVAL_ATTACK,
AI_OPERATION_NUKE_ATTACK,
AI_OPERATION_PURE_NAVAL_CITY_ATTACK,
This is the 1st thing AI checks when looking what to build. It checks what type of unit it needs from the following list:
UNITAI_UNKNOWN, // we don't know what to do with these units
UNITAI_SETTLE, // these are Settlers
UNITAI_WORKER, // these are Builders
UNITAI_ATTACK, // use these to attack other units
UNITAI_CITY_BOMBARD, // use these to attack cities
UNITAI_FAST_ATTACK, // use these to pillage enemy improvements and attack barbarians
UNITAI_DEFENSE, // these are units that are mainly in the floating defense force
UNITAI_COUNTER, // these are counter-units to specific other units - these will likely need more logic in building and using
UNITAI_RANGED, // units with ranged attacks
UNITAI_CITY_SPECIAL, // more AA???
UNITAI_EXPLORE, // scouts, etc.
UNITAI_ARTIST, // great person
UNITAI_SCIENTIST, // great person
UNITAI_GENERAL, // great person
UNITAI_MERCHANT, // great person
UNITAI_ENGINEER, // great person
UNITAI_ICBM, // nuke
UNITAI_WORKER_SEA, // work boats
UNITAI_ATTACK_SEA, // naval melee units
UNITAI_RESERVE_SEA, // naval units used defensively
UNITAI_ESCORT_SEA, // naval units tasked to defend embarked units
UNITAI_EXPLORE_SEA, // naval units used for scouting
UNITAI_ASSAULT_SEA, // naval ranged units
UNITAI_SETTLER_SEA, // UNUSED in Civ 5
UNITAI_CARRIER_SEA, // aircraft carrier
UNITAI_MISSILE_CARRIER_SEA, // missile carrier
UNITAI_PIRATE_SEA, // avast, ye
UNITAI_ATTACK_AIR, // bombers
UNITAI_DEFENSE_AIR, // fighters
UNITAI_CARRIER_AIR, // planes on boats
UNITAI_MISSILE_AIR, // cruise missiles
UNITAI_PARADROP, // paratrooper
UNITAI_SPACESHIP_PART, // spaceship part that needs to be taken to capital
UNITAI_TREASURE, // treasure to return to your capital
UNITAI_PROPHET, // great person
UNITAI_MISSIONARY, // missionary
UNITAI_INQUISITOR, // inquisitor
UNITAI_ADMIRAL, // admiral
It browses through all units that the city can build that match the type and add it to the list. At this point each unit that the city can build has a Weight value which from my understanding is a combination of Leader flavors, Unit flavors and the City Strategy Flavor (so LEADER_FLAVOR_RECON*UNIT_FLAVOR_RECON*CITY_STRATEGY_RECON + LEADER_FLAVOR_OFFENSE*UNIT_FLAVOR_OFFENSE*CITY_STRATEGY_RECON...) <- I might be wrong about this as this part of code is not that clear but that is my understanding.
Now the weight vector is reweighted to include the turn cost. After that it's sorted descending and the first unit from the list is taken.
Ok, enough for now. I will continue the explaining some other day. Finished at line 792.