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

[Freeciv-Dev] (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] (PR#13917) fix attack/defense percents in tile popup
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 7 Sep 2005 15:06:58 -0700
Reply-to: bugs@xxxxxxxxxxx

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

If you have a focus unit and do a tile popup, you are given attack and 
defense success percentages for that tile.  However these are chosen 
only from the "visible" unit.  This is clearly a bug (I think it's in RT 
somewhere) and causes me to occasionally make mistakes.

This patch fixes it by looping over all units on the tile to find the 
best (lowest) attack and defense chances.

-jason

Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.90
diff -p -u -r1.90 advdiplomacy.c
--- ai/advdiplomacy.c   5 Sep 2005 04:21:54 -0000       1.90
+++ ai/advdiplomacy.c   7 Sep 2005 22:04:58 -0000
@@ -271,7 +271,7 @@ static int ai_goldequiv_clause(struct pl
   case CLAUSE_CEASEFIRE:
     /* Don't do anything in away mode */
     if (ai_handicap(pplayer, H_AWAY)) {
-      notify(aplayer, _("*%s (AI)* In away mode AI can't sign such a treaty"),
+      notify(aplayer, _("*%s (AI)* In away mode AI can't sign such a treaty."),
              pplayer->name);
       worth = -BIG_NUMBER;
       break;
@@ -281,7 +281,7 @@ static int ai_goldequiv_clause(struct pl
      * ceasefire. */
     if (adip->is_allied_with_enemy
         && pclause->type != CLAUSE_CEASEFIRE) {
-      notify(aplayer, _("*%s (AI)* First break alliance with %s, %s"),
+      notify(aplayer, _("*%s (AI)* First break alliance with %s, %s."),
              pplayer->name, adip->is_allied_with_enemy->name,
              aplayer->name);
       worth = -BIG_NUMBER;
@@ -306,12 +306,12 @@ static int ai_goldequiv_clause(struct pl
       struct player_diplstate *ds = &pplayer->diplstates[aplayer->player_no];
 
       if (!pplayers_non_attack(pplayer, aplayer)) {
-        notify(aplayer, _("*%s (AI)* Let us first cease hostilies, %s"),
+        notify(aplayer, _("*%s (AI)* Let us first cease hostilies, %s."),
                pplayer->name, aplayer->name);
         worth = -BIG_NUMBER;
       } else if (ds->type == DS_CEASEFIRE && ds->turns_left > 2) {
         notify(aplayer, _("*%s (AI)* I wish to see you keep the current "
-               "ceasefire first, %s"), pplayer->name, aplayer->name);
+               "ceasefire first, %s."), pplayer->name, aplayer->name);
         worth = -BIG_NUMBER;
       } else if (adip->countdown >= 0 && adip->countdown < -1) {
         worth = -BIG_NUMBER; /* but say nothing */
@@ -332,7 +332,7 @@ static int ai_goldequiv_clause(struct pl
       }
       if (pplayer->ai.love[aplayer->player_no] < MAX_AI_LOVE / 10) {
         notify(aplayer, _("*%s (AI)* I simply do not trust you with an "
-               "alliance yet, %s"), pplayer->name, aplayer->name);
+               "alliance yet, %s."), pplayer->name, aplayer->name);
         worth = -BIG_NUMBER;
       }
       DIPLO_LOG(LOG_DIPL, pplayer, aplayer, "ally clause worth %d", worth);
@@ -1048,7 +1048,7 @@ static void ai_go_to_war(struct player *
     adip->countdown = -20;
     break;
   case WAR_REASON_NONE:
-    notify(target, _("*%s (AI)* Peace in ... some other time"),
+    notify(target, _("*%s (AI)* Peace in ... some other time."),
            pplayer->name);
     adip->countdown = -10;
     break;
@@ -1418,7 +1418,7 @@ void ai_diplomacy_actions(struct player 
       switch (adip->ally_patience--) {
         case 0:
           notify(aplayer, _("*%s (AI)* Greetings our most trustworthy "
-                 "ally, we call upon you to destroy our enemy, %s"), 
+                 "ally. We call upon you to destroy our enemy, %s."), 
                  pplayer->name, target->name);
           break;
         case -1:
@@ -1429,7 +1429,7 @@ void ai_diplomacy_actions(struct player 
         case -2:
           notify(aplayer, _("*%s (AI)* Dishonoured one, we made a pact of "
                  "alliance, and yet you remain at peace with our mortal "
-                 "enemy, %s! This is unacceptable, our alliance is no "
+                 "enemy, %s! This is unacceptable; our alliance is no "
                  "more!"), pplayer->name, target->name);
           DIPLO_LOG(LOG_DIPL2, pplayer, aplayer, "breaking useless alliance");
          /* to peace */
@@ -1484,7 +1484,7 @@ void ai_diplomacy_actions(struct player 
       ai_diplomacy_suggest(pplayer, aplayer, CLAUSE_CEASEFIRE, 0);
       adip->asked_about_ceasefire = !aplayer->ai.control ? 9 : 0;
       notify(aplayer, _("*%s (AI)* we grow weary of this constant "
-             "bloodshed, may we suggest a cessation of hostilities?"), 
+             "bloodshed. May we suggest a cessation of hostilities?"), 
              pplayer->name);
       break;
     default:
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       7 Sep 2005 22:04:58 -0000
@@ -201,18 +201,28 @@ 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;
+    {
+      int att_chance = FC_INFINITY, def_chance = FC_INFINITY;
+      bool found = FALSE;
+      struct unit *pfocus = get_unit_in_focus();
+
+      unit_list_iterate(ptile->units, tile_unit) {
+       if (tile_unit->owner != pfocus->owner) {
+         int att = unit_win_chance(pfocus, tile_unit) * 100;
+         int def = (1.0 - unit_win_chance(tile_unit, pfocus)) * 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);  
       }
     }
 
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.347
diff -p -u -r1.347 citytools.c
--- server/citytools.c  5 Sep 2005 15:55:46 -0000       1.347
+++ server/citytools.c  7 Sep 2005 22:05:00 -0000
@@ -1242,26 +1242,46 @@ void handle_unit_enter_city(struct unit 
   cplayer->economic.gold -= coins;
   send_player_info(cplayer, cplayer);
   if (pcity->original != pplayer) {
-    notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
-                    _("You conquer %s, your lootings accumulate"
-                      " to %d gold!"), 
-                    pcity->name, coins);
-    notify_player(cplayer, pcity->tile, E_CITY_LOST, 
-                    _("%s conquered %s and looted %d gold"
-                      " from the city."),
-                    pplayer->name, pcity->name, coins);
+    if (coins > 0) {
+      notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
+                   PL_("You conquer %s; your lootings accumulate"
+                       " to %d gold!",
+                       "You conquer %s; your lootings accumulate"
+                       " to %d gold!", coins), 
+                   pcity->name, coins);
+      notify_player(cplayer, pcity->tile, E_CITY_LOST, 
+                   PL_("%s conquered %s and looted %d gold"
+                       " from the city.",
+                       "%s conquered %s and looted %d gold"
+                       " from the city.", coins),
+                   pplayer->name, pcity->name, coins);
+    } else {
+      notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
+                   _("You conquer %s"), pcity->name);
+      notify_player(cplayer, pcity->tile, E_CITY_LOST, 
+                   _("%s conquered %s."), pplayer->name, pcity->name);
+    }
     gamelog(GAMELOG_LOSECITY, city_owner(pcity), pplayer, pcity, "conquered");
   } else {
-    notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
-                    _("You have liberated %s!"
-                      " Lootings accumulate to %d gold."),
-                    pcity->name, coins);
-    
-    notify_player(cplayer, pcity->tile, E_CITY_LOST, 
-                    _("%s liberated %s and looted %d gold"
-                      " from the city."),
-                    pplayer->name, pcity->name, coins);
-
+    if (coins > 0) {
+      notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
+                   PL_("You have liberated %s!"
+                       " Lootings accumulate to %d gold.",
+                       "You have liberated %s!"
+                       " Lootings accumulate to %d gold.", coins),
+                   pcity->name, coins);
+      notify_player(cplayer, pcity->tile, E_CITY_LOST, 
+                   PL_("%s liberated %s and looted %d gold"
+                       " from the city.",
+                       "%s liberated %s and looted %d gold"
+                       " from the city.", coins),
+                   pplayer->name, pcity->name, coins);
+    } else {
+      notify_player(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
+                   _("You have liberated %s!"), pcity->name);
+      notify_player(cplayer, pcity->tile, E_CITY_LOST, 
+                   _("%s liberated %s."), pplayer->name, pcity->name);
+    }
     gamelog(GAMELOG_LOSECITY, city_owner(pcity), pplayer, pcity, "liberated");
   }
 
Index: server/techtools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/techtools.c,v
retrieving revision 1.23
diff -p -u -r1.23 techtools.c
--- server/techtools.c  5 Sep 2005 04:21:55 -0000       1.23
+++ server/techtools.c  7 Sep 2005 22:05:01 -0000
@@ -357,8 +357,8 @@ void found_new_tech(struct player *plr, 
 
     if (choose_goal_tech(plr)) {
       notify_team(plr, NULL, E_TECH_LEARNED,
-                      _("Learned %s.  "
-                        "Our scientists focus on %s, goal is %s."),
+                      _("Learned %s. "
+                        "Our scientists focus on %s; goal is %s."),
                       get_tech_name(plr, tech_found),
                       get_tech_name(plr, research->researching),
                       get_tech_name(plr, research->tech_goal));

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13917) fix attack/defense percents in tile popup, Jason Short <=