Also, is this the right way to ensure that a unit will automatically kill another? It seems to be working but I wanted to double check:
You should set the hp of the unit you wish to kill to 0 (or less). That is, if you want the defender to lose, set
Code:
defender.damage = defender.type.hitpoints
before you return false
What would I need to do if I wanted to make it so that a particular unit would do better against other units (say, automatically do at least 5 damage?) while I don't really "need" this for Boudicca I could see it being very useful elsewhere.
In the combatResolution.firstRound function, check if certain conditions apply. If so, add some damage.
Suppose we have 2 functions, one that determines if a unit type is a 'tank', and another that determines if a square has an anti-tank gun on it, regardless of whether the defender
is the anti-tank gun. If both conditions are met, we want to do 5 damage to the tank before anything else happens. Thus,
Code:
function combatResolution.firstRound(defaultResolutionFunction,defender,attacker)
if isTank(attacker.type) and hasAntiTankGun?(defender.location) then
attacker.damage = attacker.damage+5
end
return true
end
If the attacker's damage exceeds its hitpoints due to this event, then the 'every round' function will 'catch' that and return false before combat starts.
If not mistaken, you should civ.deleteUnit(attacker or defender) before returning false, as not to have any surprise ?
I wouldn't use deleteUnit within the combat resolution event. I haven't tried it, but I suspect that nothing good can come of it. To ensure that the correct unit dies, set that unit's damage so that it the unit has at most 0 hp. (And, ensure the 'surviving' unit has at least 1 hp.)
Also, shouldn't you rather return as default situation "defaultResolutionFunction(attacker, defender)" ?
In the template, there are 2 functions. One that activates only on the first round of combat, and one that activates during every round of combat, including the first. If
both those functions return true on the first round of combat, then combat proceeds. For subsequent rounds, the 'first round of combat' function is not checked. The everyRound function is the one that returns defaultResolutionFunction(defender,attacker) by default.
This separation serves two purposes. The first is that there are certain things that it only makes sense to check once (such as the anti tank gun example I gave above). The second is that even if no harm is done doing certain things over and over again, the checks might slow down combat. For example, in OTR, we have a lot of automatic loss checks, and it is possible (though I haven't checked) that a noticeable delay might occur if they happened every round of combat.
I'm not quite sure I understand the delay mechanism just yet but I think that's one thing we'll definitely want an example for. How would I add a delay of, say, 3 turns to the Caledonii Revolt happening?