I doubt that human targeting will ever be unnecessary for the simple reason that humans are tricky bastards. If both players know how the targeting mechanism works, the one at the receiving end of pillar of flames will always use this knowledge to his advantage and keep the other player from hitting what the other player wants to hit.
If we want to make a *really* good targeting logic (and even that could still be abused by the victim), we'd need to take a lot of context into account. First of all: what is the attacking side's current agenda? Are we defending a town? Are we besieging a town? Are we just hunting down this hero to deny the other side a strong unit? This is a very difficult subject so I propose to ignore this for now. Again, if we want the AI to use these spells well eventually, we will need to build this kind of reasoning algorithm.
So, a simpler approach: as someone's already pointed out, merely counting enemy units is insufficient. We need to add strengths, factor in magic resistance, and we also need to be aware of how much damage we can still inflict on these units.
Off the top of my head in pseudo code:
Code:
maxDmg = spell.getMaxDamage() # the max amount of damage the spell can do; that is, iDamageLimit from CIV4SpellInfos.xml
highestValue = 0
for plot in targetablePlots:
stack = targetablePlot.getUnits()
plotScore = 0
for unit in stack:
curHP = unit.getCurrentHitpoints()
resistanceFactor = unit.getResistance(spell.getDamageType()) # multiplied by some factor to get
# 0 for magic immune < resFac < 1 for no resistances
unitValue = (curHP * unit.getFullStrength()) - (maxDmg * unit.getFullStrength())
unitValue *= resistanceFactor
plotScore += unitValue
if plotScore > highestValue:
highestValue = plotScore
targetPlot = plot
Again, this ignores current strategic context and other questions such as "will we have units around to finish the enemy off or will they just sit in their city and heal the damage unharassed", but I think this would already be a good deal better than the current implementation. Obviously someone who knows the actual names of the method would have to implement this
