civ editor11
Ruler
They should add this into Better AI. It would help them with one of their problems with units just piling onto the player. Making it almost impossible to defend efficiently.
It's out!It seems we have to wait until it comes out of the moderation queue![]()
Yes - at least I setup some scenario's with WorldBuilder to check which unit would be picked to defend in different situations. I haven't played through an entire game with it yet though.Thanks
Did you test it?
I'd read some posts regarding that, so did take a look at it. I don't really see a problem with the way it's implemented though - it only factors in Defender's first strikes if the attacker is NOT immune. It also factors in Attacker's first strikes if the defender IS immune (as a positive).The other area of the bestdefender code which is problematic IMO is that units with many first strikes will get picked to defend in battles at very bad odds when other better units are available. Since highly promoted drill units will usually have at least 10 or 17 xp then it's likely this mod will help the problem of drill IV units dying off to units which are immune to first strikes when cheaper units are available to defend. For example, a drill IV longbow will unfortunately defend against a Flanking 2 knight (immune to first strikes) instead of an umpromoted longbow.
I'd read some posts regarding that, so did take a look at it. I don't really see a problem with the way it's implemented though - it only factors in Defender's first strikes if the attacker is NOT immune. It also factors in Attacker's first strikes if the defender IS immune (as a positive).
In either case, it works out to a bonus to your Ranking (how good a defender you'll be) of 8%/first strike and 4%/chance of first strike. (That's based on a COMBAT_DAMAGE xml setting of 20).
In your example, assuming no other promotions, the drill IV longbow and the unpromoted longbow would be considered equally good defenders. Which then goes to the 'tie-breaker' - something called 'Unit Cycle', which I haven't looked into, but my guess is it's the order in which the units were produced. So since the drill IV longbow has probably been around longer (in order to gain all that experience), it gets picked as defender. With my mod of course, that extra experience would make it considered more valuable, hence would only be picked if the attacker was really weak.
Now, for when first strikes are factored in, whether that 8%/strike+4%/chance is reasonable or not is a judgement call. I could add a setting to allow you to adjust that ...
You're right, I'd forgotten about the +10% vs mounted. I'm a bit torn on applying a negative adjustment though - while I agree that if a D4 unit can't use their first strikes, it's a big waste, it's also true that they must have gained a lot of experience (to get that D4). And that experience (with my mod) would already make them less likely to defend. So does it need a double adjustment?I'm not sure that you noticed but a D4 longbow also gets the +10% vs. mounted, so it is technically better than the unpromoted longbow at defending, but my problem is that the main utility of a D4 unit is his first strikes and defending when none of them can be used is a massive waste. I would be tempted to apply a very slight negative weight per first strike that can't be used due to the enemy being immune.
Very true - I agree the Ranking adjustments for First Strikes should take into account the actual damage that could be done, instead of just the XML setting.In its current implementation, the main problem is usually with damaged units that have first strikes. Because of the way first strikes affect the ranking these units end up high on the list when they shouldn't be. Perhaps a solution would be to reduce the boost per first strike in a way proportional to the damage the defender has. After all, a units hitpower is reduced when it's damaged so the first strikes really are of lesser value anyway.
I agree that it doesn't quite feel right to go and apply a negative effect to unusable first strikes because you could then ask the question where do you draw the line? Other 50% bonuses etc.? But do keep in mind that it's not quite as bad as that because first strikes, like combat promotions, are very general promotions and work against every unit class. Also, units with large specific bonuses (e.g. spearmen) tend to have lower strengths so they are rarely picked as a best defender when that bonus is not in effect unless they really are almost the only unit left on the tile.
Ah ... but 'Best' for this battle? Or 'Best' in the larger picture? Sometimes the 'Best' unit to defend is the one you can most afford to lose - so that your stronger units can live to fight another day - maybe when the odds are more in their favor.I disagree. The function's name and purpose is to, literally, pick the best defender. You don't need to apply a negative effect to first strikes, just make them not factor into the best defender choices when the attacker is immune to first strikes. After all, why shouldn't it always pick the best defender? The promotions that benefit certain unit classes shouldn't even take effect in the decision for best defender unless it affects the unit that's attacking. Otherwise, it wouldn't be the best defender.
I disagree. The function's name and purpose is to, literally, pick the best defender. You don't need to apply a negative effect to first strikes, just make them not factor into the best defender choices when the attacker is immune to first strikes. After all, why shouldn't it always pick the best defender? The promotions that benefit certain unit classes shouldn't even take effect in the decision for best defender unless it affects the unit that's attacking. Otherwise, it wouldn't be the best defender.
Ah ... but 'Best' for this battle? Or 'Best' in the larger picture? Sometimes the 'Best' unit to defend is the one you can most afford to lose - so that your stronger units can live to fight another day - maybe when the odds are more in their favor.
Anyway, thinking about it some more, I do agree with NOT applying negative adjustments for bonuses/promotions that don't apply. I think that's really factored in already - whether in weaker strength or more experience (hence more valuable).
What I am planning to do is actually something mentioned in that post by DanF5771 - replace the entire Ranking calculation with the actual combat odds. That way, we can be sure first strikes will get factored in appropriately, since it's using the actual chance of winning the battle. I'll still leave my 'more valuable' check in (with flags of course, so if someone just wants the combat odds change they could do that), but I'll need to consider how best to apply it.
The bad news though is my laptop just crashedso I have no dev environment at the moment - it may be a few days (or more ...) before I can work on this.
Defender Strength Odds without FS Odds with FS Estimated odds
5 991 987 973
8 751 700 694
10 500 432 432
12 272 219 235
15 99 73 85
20 9 5 7
You're both right - I hadn't really looked at the combatOdds before, but now that I do, it would take quite a bit longer to run.
The real problem with First Strikes, is the affect varies according to the difference in strength. If you're equally strong, the affect is 13.6% (so not that far off the 16% currently used). If you're a bit stronger though, the affect goes up - if you're a bit weaker, the affect goes down (considerably! even at 90% of attacker's strength, you're FS is only worth an extra 8.3%).
(((Dstr / (Dstr + max(Dstr + Astr)) * 2) ^ 5) * 0.136)
In the code of course, I'll be applying the formula to the Ranking (not the odds), but the affect is the same. Also, I simply look at how many more FS's a unit has, treating chances as 1/2 a FS (has a small impact on odds, but not a lot).
e.g: Defender has 4-7 FS's, Attacker has 2-3 (taking immunity into account of course)
Treated as Defender 5.5, Attacker 2.5
Treated as Defender 3, Attacker none
You're right, I am going to have to look at this further. Rather than looking how much a FS increases the odds, I need to look at how much I need to increase the strength by to get an equivalent affect ...You have to be careful with this kind of analysis as there is a huge effect of the discrete mechanics of the combat odds. For instance, a unit of strength 10.01 has odds of 62,36% to beat a strength 10 unit, while a strength 10 unit has 50% odds (no first strikes). This of course doesn't mean that a 0.01% jump in strength will in general have an effect of 2*12.36%.
These effects are less prominent with first strikes but still exist.
Sorry - that should've been max(Dstr,Astr).What do you mean with max(Dstr + Astr)?
The Ranking is pretty much just the Defender's current strength. That's taking into account any damage, fortification bonuses, Defender unit bonuses/promotions, Attacker unit bonuses/promotions (as a negative). It's the same calculation used when actually resolving combat (as well as computing the odds).Is the ranking based on the combat odds? Are the multipliers from other promotions also based on the effect that these promotions have on the combat odds? Is the effect of a combat 1 promotion on the combat odds similar to the effect of a combat 1 promotion on the ranking? If the ranking has little to do with the effect of these promotions on combat odds, then a multiplier based on the effect of first strikes on the odds won't work well compared to the effects of other promotions.
Sorry - that should've been max(Dstr,Astr).
The Ranking is pretty much just the Defender's current strength. That's taking into account any damage, fortification bonuses, Defender unit bonuses/promotions, Attacker unit bonuses/promotions (as a negative). It's the same calculation used when actually resolving combat (as well as computing the odds).
It does do some manipulation to the Ranking after that:
If it's a 'World Class' unit, it cuts the ranking in half (I have a flag to remove this, since the basic intent of it is taken care of in my 'more valuable' calculation). The fact that this exists actually shows that they had at least the idea of protecting more valuable units, but just implemented with very limited scope. (In fact, there are NO world class units in BtS, so it doesn't actually apply at all).
It also reduce the ranking if the unit is carrying other units. That's based on (Asset Value of unit) / (Asset value of unit + sum(Asset value of carried units))
And other than that there's just the First Strikes adjustment that we're looking at now. That's basically if defender has FS's and attacker is NOT immune, then increase Ranking by 16%/FS+8%/chanceFS.
And if attacker has FS's and defender IS immune, increase Ranking again (another multiplication) by 16%/FS+8%/chanceFS.
You're right the effect is less prominent. Adding or removing first strikes cannot cause the well-known "jump points" like other combat modifiers can. Really this should make it easier to take into account the effect of first strikes.This of course doesn't mean that a 0.01% jump in strength will in general have an effect of 2*12.36%.
These effects are less prominent with first strikes but still exist.
The Ranking is pretty much just the Defender's current strength. That's taking into account any damage, fortification bonuses, Defender unit bonuses/promotions, Attacker unit bonuses/promotions (as a negative). It's the same calculation used when actually resolving combat (as well as computing the odds).
I don't have that program set up at the moment but if necessary I could dig a bit to find it. I had set it up at the time so that it could output combat odds as a function of one of the variables (e.g. number of first strikes or HP of the attacker), with everything else held constant. It might be useful if we want to look fairly quantitatively at how first strikes affect combat odds in a range of circumstances.Maybe PieceofMind can do some significant number of comparisons with his combat calculator.