Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] Re: (PR#13917) fix attack/defense percents in tile popup
Home

[Freeciv-Dev] Re: (PR#13917) fix attack/defense percents in tile popup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13917) fix attack/defense percents in tile popup
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 7 Sep 2005 21:54:04 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13917 >

And, there was a bug in the patch itself.  This patch fixes the bug and 
includes only the correct (client) bits.

-jason


Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.50
diff -p -u -r1.50 text.c
--- client/text.c       25 Aug 2005 20:36:12 -0000      1.50
+++ client/text.c       8 Sep 2005 04:51:16 -0000
@@ -57,6 +57,7 @@ const char *popup_info_text(struct tile 
   const char *activity_text;
   struct city *pcity = ptile->city;
   struct unit *punit = find_visible_unit(ptile);
+  struct unit *pfocus_unit = get_unit_in_focus();
   const char *diplo_nation_plural_adjectives[DS_LAST] =
     {Q_("?nation:Neutral"), Q_("?nation:Hostile"),
      "" /* unused, DS_CEASEFIRE*/,
@@ -115,7 +116,6 @@ const char *popup_info_text(struct tile 
      * borders are in use). */
     struct player *owner = city_owner(pcity);
     struct player_diplstate *ds = game.player_ptr->diplstates;
-    struct unit *apunit;
 
     if (owner == game.player_ptr){
       /* TRANS: "City: Warsaw (Polish)" */
@@ -144,10 +144,10 @@ const char *popup_info_text(struct tile 
       astr_add(&str, " %s", _("with City Walls"));
     }
 
-    if ((apunit = get_unit_in_focus())) {
-      struct city *hcity = find_city_by_id(apunit->homecity);
+    if (pfocus_unit) {
+      struct city *hcity = find_city_by_id(pfocus_unit->homecity);
 
-      if (unit_flag(apunit, F_TRADE_ROUTE)
+      if (unit_flag(pfocus_unit, F_TRADE_ROUTE)
          && can_cities_trade(hcity, pcity)
          && can_establish_trade_route(hcity, pcity)) {
        /* TRANS: "Trade from Warsaw: 5" */
@@ -201,18 +201,27 @@ const char *popup_info_text(struct tile 
       }
     }
 
-    if (owner != game.player_ptr){
-      struct unit *apunit;
-      if ((apunit = get_unit_in_focus())) {
-       /* chance to win when active unit is attacking the selected unit */
-       int att_chance = unit_win_chance(apunit, punit) * 100;
-       
-       /* chance to win when selected unit is attacking the active unit */
-       int def_chance = (1.0 - unit_win_chance(punit, apunit)) * 100;
+    if (pfocus_unit) {
+      int att_chance = FC_INFINITY, def_chance = FC_INFINITY;
+      bool found = FALSE;
+
+      unit_list_iterate(ptile->units, tile_unit) {
+       if (tile_unit->owner != pfocus_unit->owner) {
+         int att = unit_win_chance(pfocus_unit, tile_unit) * 100;
+         int def = (1.0 - unit_win_chance(tile_unit, pfocus_unit)) * 100;
+
+         found = TRUE;
+
+         /* Presumably the best attacker and defender will be used. */
+         att_chance = MIN(att, att_chance);
+         def_chance = MIN(def, def_chance);
+       }
+      } unit_list_iterate_end;
 
+      if (found) {
        /* TRANS: "Chance to win: A:95% D:46%" */
        astr_add_line(&str, _("Chance to win: A:%d%% D:%d%%"),
-                     att_chance, def_chance);
+                     att_chance, def_chance);  
       }
     }
 

[Prev in Thread] Current Thread [Next in Thread]