URL:
  <http://gna.org/patch/?1144>

                 Summary: Incorrect handling of poison attack when suggesting
best attack in user interface
                 Project: Battle for Wesnoth
            Submitted by: crab
            Submitted on: Friday 03/27/2009 at 20:01
                Priority: 3 - Low
                  Status: In Progress
                 Privacy: Public
             Assigned to: crab
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

   1.
      When assasin attack a goblin, the game thinks that his melee attack is
better that his ranged.
   2.
      This happens because of a bug in evaluation code - the presence of
poison on assasin's ranged attacks actually decreases chances to use it.
   3.
       
   4.
      in GDB, in src/actions.cpp, just before returning from evaluation code
which compares assasin's ranged attack (A) and assasin's melee attack (B)
   5.
      ===
   6.
      // Does combat A give us a better result than combat B?
   7.
      bool battle_context::better_combat(const combatant &us_a, const
combatant &them_a,
   8.
                      const combatant &us_b, const combatant &them_b,
   9.
                      double harm_weight)
  10.
      {
  11.
              double a, b;
  12.
       
  13.
              // Compare: P(we kill them) - P(they kill us).
  14.
              a = them_a.hp_dist[0] - us_a.hp_dist[0] * harm_weight;
  15.
              b = them_b.hp_dist[0] - us_b.hp_dist[0] * harm_weight;
  16.
              if (a - b < -0.01)
  17.
                      return false;
  18.
              if (a - b > 0.01)
  19.
                      return true;
  20.
       
  21.
              // Add poison to calculations
  22.
              double poison_a_us = (us_a.poisoned) *
game_config::poison_amount;
  23.
              double poison_a_them = (them_a.poisoned) *
game_config::poison_amount;
  24.
              double poison_b_us = (us_b.poisoned) *
game_config::poison_amount;
  25.
              double poison_b_them = (them_b.poisoned) *
game_config::poison_amount;
  26.
              // Compare: damage to them - damage to us (average_hp replaces
-damage)
  27.
              a = (us_a.average_hp()-poison_a_us)*harm_weight -
(them_a.average_hp()-poison_a_them);
  28.
              b = (us_b.average_hp()-poison_b_us)*harm_weight -
(them_b.average_hp()-poison_b_them);
  29.
             if (a - b < -0.01)
  30.
                      return false;
  31.
              if (a - b > 0.01)
  32.
                      return true;
  33.
       
  34.
              // All else equal: go for most damage.
  35.
              return them_a.average_hp() < them_b.average_hp();
  36.
      }
  37.
       
  38.
      ===
  39.
      (gdb) print poison_b_them
  40.
      $17 = 0
  41.
      (gdb) print poison_a_us
  42.
      $18 = 0
  43.
      (gdb) print poison_a_them
  44.
      $19 = 7.4879999999999995
  45.
      (gdb) print poison_b_us
  46.
      $20 = 0
  47.
      (gdb) print poison_b_them
  48.
      $21 = 0
  49.
      (gdb) print a
  50.
      $22 = -8.6880000000000024
  51.
      (gdb) print b
  52.
      $23 = -6.3500000000000014
  53.
       
  54.
      It is a sign error. That bonus of +7.4 (instead of -7.4 from the poison
turned "a" from a good attack with +13 to a bad attack with
"-8.6880000000000024"
  55.
       
  56.
      Proposed patch:
  57.
      ==========================================
  58.
      --- actions.cpp (revision 34146)
  59.
      +++ actions.cpp (working copy)
  60.
       -532,8 +532,8 @@
  61.
              double poison_b_us = (us_b.poisoned) *
game_config::poison_amount;
  62.
              double poison_b_them = (them_b.poisoned) *
game_config::poison_amount;
  63.
              // Compare: damage to them - damage to us (average_hp replaces
-damage)
  64.
      -       a = (us_a.average_hp()+poison_a_us)*harm_weight -
(them_a.average_hp()+poison_a_them);
  65.
      -       b = (us_b.average_hp()+poison_b_us)*harm_weight -
(them_b.average_hp()+poison_b_them);
  66.
      +       a = (us_a.average_hp()-poison_a_us)*harm_weight -
(them_a.average_hp()-poison_a_them);
  67.
      +       b = (us_b.average_hp()-poison_b_us)*harm_weight -
(them_b.average_hp()-poison_b_them);
  68.
              if (a - b < -0.01)
  69.
                      return false;
  70.
              if (a - b > 0.01)




    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?1144>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to