Summoned, hè? Then were are my sacrifices!? ... Jesting.
Missions over more than one province use a scoring function to determine the best province to attack. AA capability in the province decreases the score, target availability increases it.
I have not yet investigated the code in detail, but there is a bug I should fix one of these days in that only constructed building sizes - but not current (e.g. partially destroyed from previous runs) sizes - are used for scoring in some of the missions (e.g. Industrial Bombardment correctly checks for current IC, but Installation Strike only checks for potential levels of affected buildings).
The algorithm goes about like this:
Code:
ourUnit = unitWithMission // the unit that is checking whether to fly its mission and where to
score = lowerBound(typeof(score))
target = null // will be the province targeted when the unit actually departs
list<province> targetList = scopeOfMission // all the provinces selected in the mission scope
randomTarget = random(integral numbers) modulo targetList.size // generally NOT a uniform distribution
randomTargetProvince = null
for(province in targetList)
--randomTarget
if(not canTarget(province))
continue
else
if(randomTarget == 0)
randomTargetProvince = targetList[randomTarget]
risk = simulateCombatWithRandomHostileUnit(ourUnit, province) // heuristic: "what if any hostile air unit would engage us here";
// might pick 4 interceptors, might pick 4 transport planes
check = addPotentialDamageSubtractPotentialLosses(risk, province) // factoring in #targets, sum(AA), etc.
check /= 2 + numberOfDivisionsAttackingToday(province) + ourUnit.size // reducing attractiveness of provinces targeted by other units
if(check > score) // always true on the first pass
score = check
target = province
if(target == null && randomTargetProvince != null) // score is not significant, so we choose randomly
target = randomTargetProvince
if(target != null)
sendUnit(ourUnit, province) // actually makes the unit fly its mission
numberOfDivisionsAttackingToday(province) += ourUnit.size
Note that the score originally began at 0.f, until I adjusted it to quick&dirty(TM) fix the installation strike issue. As you can see, for single province targets, a random province cannot be picked due to wrong order of the decrement of randomTarget. As the risk assessment already introduces a random component, I decided against a fix by putting that decrement at the end and instead fixed the score to
always produce a tangible result.
All the air missions have roughly this shape, it is almost impossible to spot differences on the fly (hè). One of my eventual goals here is to drastically cut down on redundancy as per the
DRY principle, and at that point it will be sensible to further tweak the algorithm. I intend to open a feedback tread on that matter, once we have actually reached a situation wherein we can apply such feedback.