Author: jtn
Date: Tue Jun 24 01:02:34 2014
New Revision: 25251

URL: http://svn.gna.org/viewcvs/freeciv?rev=25251&view=rev
Log:
Only reduce fractional movement points to lowest terms for display when
talking about rulesets and unit types in the abstract; when talking
about a specific unit, don't reduce, to avoid confusing changes as a
unit moves.

Requested by Marko Lindqvist (cazfi@gna).

See gna bug #22194.

Modified:
    branches/S2_5/client/gui-gtk-2.0/helpdlg.c
    branches/S2_5/client/gui-gtk-3.0/helpdlg.c
    branches/S2_5/client/gui-qt/dialogs.cpp
    branches/S2_5/client/gui-sdl/citydlg.c
    branches/S2_5/client/gui-sdl/dialogs.c
    branches/S2_5/client/gui-sdl/helpdlg.c
    branches/S2_5/client/gui-sdl/mapview.c
    branches/S2_5/client/gui-sdl/wldlg.c
    branches/S2_5/client/gui-xaw/helpdlg.c
    branches/S2_5/client/helpdata.c
    branches/S2_5/common/movement.c
    branches/S2_5/common/movement.h
    branches/S2_5/common/unit.c
    branches/S2_5/common/unittype.c

Modified: branches/S2_5/client/gui-gtk-2.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/helpdlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/helpdlg.c  (original)
+++ branches/S2_5/client/gui-gtk-2.0/helpdlg.c  Tue Jun 24 01:02:34 2014
@@ -856,7 +856,7 @@
     gtk_label_set_text(GTK_LABEL(help_ulabel[0][4]), buf);
     sprintf(buf, "%d", utype->defense_strength);
     gtk_label_set_text(GTK_LABEL(help_ulabel[1][1]), buf);
-    sprintf(buf, "%s", move_points_text(utype->move_rate, NULL, NULL, FALSE));
+    sprintf(buf, "%s", move_points_text(utype->move_rate, TRUE));
     gtk_label_set_text(GTK_LABEL(help_ulabel[1][4]), buf);
     sprintf(buf, "%d", utype->firepower);
     gtk_label_set_text(GTK_LABEL(help_ulabel[2][1]), buf);

Modified: branches/S2_5/client/gui-gtk-3.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/helpdlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/helpdlg.c  (original)
+++ branches/S2_5/client/gui-gtk-3.0/helpdlg.c  Tue Jun 24 01:02:34 2014
@@ -877,7 +877,7 @@
     gtk_label_set_text(GTK_LABEL(help_ulabel[0][4]), buf);
     sprintf(buf, "%d", utype->defense_strength);
     gtk_label_set_text(GTK_LABEL(help_ulabel[1][1]), buf);
-    sprintf(buf, "%s", move_points_text(utype->move_rate, NULL, NULL, FALSE));
+    sprintf(buf, "%s", move_points_text(utype->move_rate, TRUE));
     gtk_label_set_text(GTK_LABEL(help_ulabel[1][4]), buf);
     sprintf(buf, "%d", utype->firepower);
     gtk_label_set_text(GTK_LABEL(help_ulabel[2][1]), buf);

Modified: branches/S2_5/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/dialogs.cpp?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/dialogs.cpp     (original)
+++ branches/S2_5/client/gui-qt/dialogs.cpp     Tue Jun 24 01:02:34 2014
@@ -1792,10 +1792,9 @@
     }
 
     if (utype_fuel(unit_type(punit))) {
-      str = QString(move_points_text
-                   ((rate * f) + punit->moves_left, NULL, NULL, false));
+      str = QString(move_points_text((rate * f) + punit->moves_left, false));
     } else {
-      str = QString(move_points_text(punit->moves_left, NULL, NULL, false));
+      str = QString(move_points_text(punit->moves_left, false));
     }
     /* TRANS: MP = Movement points */
     str = QString(_("MP:")) + str;

Modified: branches/S2_5/client/gui-sdl/citydlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/citydlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/citydlg.c      (original)
+++ branches/S2_5/client/gui-sdl/citydlg.c      Tue Jun 24 01:02:34 2014
@@ -725,7 +725,7 @@
                 utype_name_translation(pUType),
                 pUType->attack_strength,
                 pUType->defense_strength,
-                move_points_text(pUType->move_rate, NULL, NULL, FALSE),
+                move_points_text(pUType->move_rate, FALSE),
                 (vetname != NULL ? "\n" : ""),
                 (vetname != NULL ? vetname : ""),
                 unit_activity_text(pUnit),

Modified: branches/S2_5/client/gui-sdl/dialogs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/dialogs.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/dialogs.c      (original)
+++ branches/S2_5/client/gui-sdl/dialogs.c      Tue Jun 24 01:02:34 2014
@@ -1116,7 +1116,7 @@
                   utype_name_translation(pUnitType),
                   pUnitType->attack_strength,
                   pUnitType->defense_strength,
-                  move_points_text(pUnitType->move_rate, NULL, NULL, FALSE),
+                  move_points_text(pUnitType->move_rate, FALSE),
                   unit_activity_text(pUnit));
     } else {
       int att_chance, def_chance;
@@ -1127,7 +1127,7 @@
                   utype_name_translation(pUnitType),
                   pUnitType->attack_strength,
                   pUnitType->defense_strength,
-                  move_points_text(pUnitType->move_rate, NULL, NULL, FALSE),
+                  move_points_text(pUnitType->move_rate, FALSE),
                   pUnitType->firepower,
                   (pUnit->hp * 100 / pUnitType->hp + 9) / 10);
 
@@ -1869,7 +1869,7 @@
                       utype_name_translation(pUnitType),
                       pUnitType->attack_strength,
                       pUnitType->defense_strength,
-                      move_points_text(pUnitType->move_rate, NULL, NULL, 
FALSE),
+                      move_points_text(pUnitType->move_rate, FALSE),
                       unit_activity_text(pUnit));
 
          create_active_iconlabel(pBuf, pWindow->dst, pStr,
@@ -1887,7 +1887,7 @@
                       utype_name_translation(pUnitType),
                       pUnitType->attack_strength,
                       pUnitType->defense_strength,
-                      move_points_text(pUnitType->move_rate, NULL, NULL, 
FALSE),
+                      move_points_text(pUnitType->move_rate, FALSE),
                       pUnitType->firepower,
                       ((pUnit->hp * 100) / pUnitType->hp));
 
@@ -1988,7 +1988,7 @@
                       utype_name_translation(pUnitType),
                       pUnitType->attack_strength,
                       pUnitType->defense_strength,
-                      move_points_text(pUnitType->move_rate, NULL, NULL, 
FALSE),
+                      move_points_text(pUnitType->move_rate, FALSE),
                       unit_activity_text(pUnit));
 
          create_active_iconlabel(pBuf, pWindow->dst, pStr,
@@ -2015,7 +2015,7 @@
                       utype_name_translation(pUnitType),
                       pUnitType->attack_strength,
                       pUnitType->defense_strength,
-                      move_points_text(pUnitType->move_rate, NULL, NULL, 
FALSE),
+                      move_points_text(pUnitType->move_rate, FALSE),
                       pUnitType->firepower,
                       ((pUnit->hp * 100) / pUnitType->hp));
 

Modified: branches/S2_5/client/gui-sdl/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/helpdlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/helpdlg.c      (original)
+++ branches/S2_5/client/gui-sdl/helpdlg.c      Tue Jun 24 01:02:34 2014
@@ -783,8 +783,7 @@
     cat_snprintf(buf, sizeof(buf), "\n%s %d %s %d %s %s\n%s %d %s %d %s %d",
               _("Attack:"), pUnitType->attack_strength,
               _("Defense:"), pUnitType->defense_strength,
-              _("Move:"), move_points_text(pUnitType->move_rate,
-                                           NULL, NULL, FALSE),
+              _("Move:"), move_points_text(pUnitType->move_rate, TRUE),
               _("Vision:"), pUnitType->vision_radius_sq,
               _("FirePower:"), pUnitType->firepower,
               _("Hitpoints:"), pUnitType->hp);

Modified: branches/S2_5/client/gui-sdl/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/mapview.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/mapview.c      (original)
+++ branches/S2_5/client/gui-sdl/mapview.c      Tue Jun 24 01:02:34 2014
@@ -772,7 +772,7 @@
                       utype_name_translation(pUType),
                       pUType->attack_strength,
                       pUType->defense_strength,
-                      move_points_text(pUType->move_rate, NULL, NULL, FALSE),
+                      move_points_text(pUType->move_rate, FALSE),
                       (vetname != NULL ? "\n" : ""),
                       (vetname != NULL ? vetname : ""),
                       unit_activity_text(aunit),

Modified: branches/S2_5/client/gui-sdl/wldlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/wldlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/wldlg.c        (original)
+++ branches/S2_5/client/gui-sdl/wldlg.c        Tue Jun 24 01:02:34 2014
@@ -1522,7 +1522,7 @@
                    _("(%d/%d/%s)\n%d/%d %s\nnever"),
                    pUnit->attack_strength,
                     pUnit->defense_strength,
-                    move_points_text(pUnit->move_rate, NULL, NULL, FALSE),
+                    move_points_text(pUnit->move_rate, TRUE),
                    pCity->shield_stock, utype_build_shield_cost(un),
                    PL_("shield","shields", utype_build_shield_cost(un)));
         } else {
@@ -1530,7 +1530,7 @@
                    _("(%d/%d/%s)\n%d/%d %s\n%d %s"),
                    pUnit->attack_strength,
                     pUnit->defense_strength,
-                    move_points_text(pUnit->move_rate, NULL, NULL, FALSE),
+                    move_points_text(pUnit->move_rate, TRUE),
                    pCity->shield_stock, utype_build_shield_cost(un), 
                    PL_("shield","shields", utype_build_shield_cost(un)),
                    turns, PL_("turn", "turns", turns));
@@ -1540,7 +1540,7 @@
                    _("(%d/%d/%s)\n%d %s"),
                    pUnit->attack_strength,
                     pUnit->defense_strength,
-                    move_points_text(pUnit->move_rate, NULL, NULL, FALSE),
+                    move_points_text(pUnit->move_rate, TRUE),
                    utype_build_shield_cost(un),
                    PL_("shield","shields", utype_build_shield_cost(un)));
       }

Modified: branches/S2_5/client/gui-xaw/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-xaw/helpdlg.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/gui-xaw/helpdlg.c      (original)
+++ branches/S2_5/client/gui-xaw/helpdlg.c      Tue Jun 24 01:02:34 2014
@@ -848,8 +848,7 @@
     xaw_set_label(help_unit_attack_data, buf);
     sprintf(buf, "%d ", punittype->defense_strength);
     xaw_set_label(help_unit_def_data, buf);
-    sprintf(buf, "%s ", move_points_text(punittype->move_rate,
-                                         NULL, NULL, FALSE));
+    sprintf(buf, "%s ", move_points_text(punittype->move_rate, TRUE));
     xaw_set_label(help_unit_move_data, buf);
     sprintf(buf, "%d ", punittype->firepower);
     xaw_set_label(help_unit_fp_data, buf);

Modified: branches/S2_5/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/helpdata.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/client/helpdata.c     (original)
+++ branches/S2_5/client/helpdata.c     Tue Jun 24 01:02:34 2014
@@ -177,7 +177,7 @@
           name, MAX(0, 25 - (int)get_internal_string_length(name)), "",
           level->power_fact,
           /* e.g. "-    ", "+ 1/3", "+ 1    ", "+ 2 2/3" */
-          move_points_text(level->move_bonus, "+ ", "-", TRUE));
+          move_points_text_full(level->move_bonus, TRUE, "+ ", "-", TRUE));
     }
     return TRUE;
   }
@@ -2557,8 +2557,7 @@
                   * fractional part. */
                  _("* Ignores terrain effects (moving costs at most %s MP "
                    "per tile).\n"),
-                 move_points_text(terrain_control.igter_cost,
-                                  NULL, NULL, FALSE));
+                 move_points_text(terrain_control.igter_cost, TRUE));
   }
   if (utype_has_flag(utype, UTYF_IGZOC)) {
     CATLSTR(buf, bufsz, _("* Ignores zones of control.\n"));
@@ -3106,7 +3105,7 @@
                   * fractional part. */
                  _("* Movement cost along %s is %s MP.\n"),
                  road_name_translation(proad),
-                 move_points_text(proad->move_cost, NULL, NULL, FALSE));
+                 move_points_text(proad->move_cost, TRUE));
   }
 
   if (!proad->buildable) {

Modified: branches/S2_5/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/common/movement.c     (original)
+++ branches/S2_5/common/movement.c     Tue Jun 24 01:02:34 2014
@@ -635,24 +635,28 @@
 /****************************************************************************
   Render positive movement points as text, including fractional movement
   points, scaled by SINGLE_MOVE. Returns a pointer to a static buffer.
+  'reduce' is whether fractional movement points should be reduced to
+    lowest terms (this might be confusing in some cases).
   'prefix' is a string put in front of all numeric output.
   'none' is the string to display in place of the integer part if no
-  movement points (or NULL to just say 0).
+    movement points (or NULL to just say 0).
   'align' controls whether this is for a fixed-width table, in which case
-  padding spaces will be included to make all such strings line up when
-  right-aligned.
-****************************************************************************/
-const char *move_points_text(int mp, const char *prefix, const char *none,
-                             bool align)
+    padding spaces will be included to make all such strings line up when
+    right-aligned.
+****************************************************************************/
+const char *move_points_text_full(int mp, bool reduce, const char *prefix,
+                                  const char *none, bool align)
 {
   static struct astring str = ASTRING_INIT;
   int pad1, pad2;
 
   if (align && SINGLE_MOVE > 1) {
+    /* Align to worst-case denominator even if we might be reducing to
+     * lowest terms, as other entries in a table might not reduce */
     pad1 = move_points_denomlen;      /* numerator or denominator */
     pad2 = move_points_denomlen*2+2;  /* everything right of integer part */
   } else {
-    /* If no fractional part, no need for alignment even if requested */
+    /* If no possible fractional part, alignment unneeded even if requested */
     pad1 = pad2 = 0;
   }
   if (!prefix) {
@@ -669,28 +673,45 @@
     /* Integer move points */
     astr_add(&str, "%s%d%*s", prefix, mp / SINGLE_MOVE, pad2, "");
   } else {
-    /* Fractional part; reduce to lowest terms */
-    int gcd = mp;
+    /* Fractional part */
+    int cancel;
+
     fc_assert(SINGLE_MOVE > 1);
-    {
+    if (reduce) {
+      /* Reduce to lowest terms */
+      int gcd = mp;
       /* Calculate greatest common divisor with Euclid's algorithm */
       int b = SINGLE_MOVE;
+
       while (b != 0) {
         int t = b;
         b = gcd % b;
         gcd = t;
       }
+      cancel = gcd;
+    } else {
+      /* No cancellation */
+      cancel = 1;
     }
     if (mp < SINGLE_MOVE) {
       /* Fractional move points */
       astr_add(&str, "%s%*d/%*d", prefix,
-               pad1, (mp % SINGLE_MOVE) / gcd, pad1, SINGLE_MOVE / gcd);
+               pad1, (mp % SINGLE_MOVE) / cancel, pad1, SINGLE_MOVE / cancel);
     } else {
       /* Integer + fractional move points */
       astr_add(&str,
                "%s%d %*d/%*d", prefix, mp / SINGLE_MOVE,
-               pad1, (mp % SINGLE_MOVE) / gcd, pad1, SINGLE_MOVE / gcd);
+               pad1, (mp % SINGLE_MOVE) / cancel, pad1, SINGLE_MOVE / cancel);
     }
   }
   return astr_str(&str);
 }
+
+/****************************************************************************
+  Simple version of move_points_text_full() -- render positive movement
+  points as text without any prefix or alignment.
+****************************************************************************/
+const char *move_points_text(int mp, bool reduce)
+{
+  return move_points_text_full(mp, reduce, NULL, NULL, FALSE);
+}

Modified: branches/S2_5/common/movement.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.h?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/common/movement.h     (original)
+++ branches/S2_5/common/movement.h     Tue Jun 24 01:02:34 2014
@@ -98,8 +98,9 @@
 struct unit *transport_from_tile(struct unit *punit, struct tile *ptile);
 
 void init_move_fragments(void);
-const char *move_points_text(int mp, const char *prefix, const char *none,
-                             bool align);
+const char *move_points_text_full(int mp, bool reduce, const char *prefix,
+                                  const char *none, bool align);
+const char *move_points_text(int mp, bool reduce);
 
 #ifdef __cplusplus
 }

Modified: branches/S2_5/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unit.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/common/unit.c (original)
+++ branches/S2_5/common/unit.c Tue Jun 24 01:02:34 2014
@@ -1513,13 +1513,12 @@
       /* Add in two parts as move_points_text() returns ptr to static
        * End result: "Moves: (fuel)moves_left" */
       astr_add_line(astr, "%s: (%s)", _("Moves"),
-                    move_points_text((rate * f) + punit->moves_left,
-                                     NULL, NULL, FALSE));
+                    move_points_text((rate * f) + punit->moves_left, FALSE));
       astr_add(astr, "%s",
-               move_points_text(punit->moves_left, NULL, NULL, FALSE));
+               move_points_text(punit->moves_left, FALSE));
     } else {
       astr_add_line(astr, "%s: %s", _("Moves"),
-                    move_points_text(punit->moves_left, NULL, NULL, FALSE));
+                    move_points_text(punit->moves_left, FALSE));
     }
     return;
   case ACTIVITY_POLLUTION:

Modified: branches/S2_5/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unittype.c?rev=25251&r1=25250&r2=25251&view=diff
==============================================================================
--- branches/S2_5/common/unittype.c     (original)
+++ branches/S2_5/common/unittype.c     Tue Jun 24 01:02:34 2014
@@ -387,11 +387,11 @@
   fc_snprintf(buffer, sizeof(buffer), "%d/%d/%s",
               punittype->attack_strength,
               punittype->defense_strength,
-              move_points_text(punittype->move_rate, NULL, NULL, FALSE));
+              move_points_text(punittype->move_rate, TRUE));
   if (utype_fuel(punittype)) {
     cat_snprintf(buffer, sizeof(buffer), "(%s)",
                  move_points_text(punittype->move_rate * utype_fuel(punittype),
-                                  NULL, NULL, FALSE));
+                                  TRUE));
   }
   return buffer;
 }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to