Author: sveinung
Date: Mon Nov  7 13:42:27 2016
New Revision: 34432

autoattack: have the best attacker go first.

A unit will only auto attack if its probability of success is above a
certain threshold. The threshold is currently 90% if the unit is the last
defender in a city and 25% otherwise.

A unit's probability of success against a target can depend on target
specific factors. One example of target relative unit strength is how the
classic ruleset gives a defense bonus to Pikemen when attacked by Horsemen.

Up unit now the potential attacker with the *worst* odds (above the
threshold) have attacked first.
 * saved the stronger units for more worthy potential future enemies.
   (Thanks to Jacob Nevins <jtn> for noticing.)
 * made it harder to lure strong enemy units out of the way by using
   sacrificial units. (A regular attack may, depending on the occupychance
   server setting, make the attacker move after victory is achieved)
 * made it possible to exploit target relative unit strength by moving a
   unit a strong unit in a unit stack is weak against next to the tile.
 * increased the probability of the auto attacker losing and dying.
 * decreased the probability of a follow up attack (target weakness can
   increase the probability of victory enough to have it pass the threshold)

Make the potential attacker with the *best* odds attack first.
 * makes it possible to waste a strong unit's attacks by sending weak units
   against it. (Assuming a more or less global ranking of attack strength.)
 * makes it possible to lure away strong units by using sacrificial units.
   (Assuming a more or less global ranking of attack strength.)
 * target specific factors are exploited to the autoattacker's advantage.
   This beats the advantage of the old system because attacker unit strength
   can depend on the target unit.
 * reduces the probability of the auto attacker dying during the attack.
 * increases the probability of a second auto attacker finishing of the
   target if the first auto attacker fails.

See patch #7942


Modified: trunk/server/unittools.c
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Mon Nov  7 13:42:27 2016
@@ -3052,8 +3052,13 @@
     /* The units have a different number of recursive transporters. */
     return unit_transport_depth(q1unit) - unit_transport_depth(p1unit);
   } else {
-    /* Assume the worst. */
-    return action_prob_cmp_pessimist((*p1)->prob, (*q1)->prob);
+    /* Put the units with the highest probability of success first. The up
+     * side of this is that units with bonuses against the victim attacks
+     * before other units. The downside is that strong units can be lead
+     * away by sacrificial units. */
+    return (-1
+            /* Assume the worst. */
+            * action_prob_cmp_pessimist((*p1)->prob, (*q1)->prob));
@@ -3097,7 +3102,8 @@
     } unit_list_iterate_end;
   } adjc_iterate_end;
-  /* The unit list is now sorted according to win chance against punit */
+  /* Sort the potential attackers from highest to lowest success
+   * probability. */
   if (autoattack_prob_list_size(autoattack) >= 2) {
     autoattack_prob_list_sort(autoattack, &compare_units);

Freeciv-commits mailing list

Reply via email to