Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] (PR#3376) print exact number of points is science dialog
Home

[Freeciv-Dev] (PR#3376) print exact number of points is science dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ggracian@xxxxxxx
Subject: [Freeciv-Dev] (PR#3376) print exact number of points is science dialog
From: "jjc@xxxxxxxxxxxxxxxxxx" <jjc@xxxxxxxxxxxxxxxxxx>
Date: Fri, 5 Sep 2003 13:48:15 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch was originally submitted 2003 Feb 10.  

This patch adds a display of the number of tech points per turn in 
the gtk and gtk2 science dialogs.  Now science dialog says things like:
Research speed: 20 turns/advance (14 bulbs/turn)
This saves you from having to add up all the bulbs manually in the city
dialog. 

This patch adds a new function tech_bulbs_per_turn that returns the total 
number of tech bulbs that are generated by a player in one turn.  It then
uses that in tech_turns_to_advance and in the science dialog gui code.

The original patch's function tech_points_per_turn did not work correctly
if there was no science output (also it was called points, not bulbs).  

The patch attached below adds the gtk2 client support, it adds proper 
pluralization for the bulbs/turn, and it fixes the problem with returning 
incorrect information when the science output is 0.

I believe that this patch should be applied to cvs as it adds useful
functionality that I have looked for in freeciv.

-- 
Josh Cogliati


Index: client/gui-gtk/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v
retrieving revision 1.72
diff -U9 -r1.72 repodlgs.c
--- client/gui-gtk/repodlgs.c   2003/07/29 15:16:31     1.72
+++ client/gui-gtk/repodlgs.c   2003/09/05 20:21:27
@@ -359,30 +359,35 @@
 {
   if(science_dialog_shell) {
   char text[512];
   int i, j, hist;
   static char *row     [1];
   GtkWidget *item;
   GList *sorting_list = NULL;
   gfloat pct;
   int turns_to_advance;
+  int bulbs_per_turn;
   int steps;
 
   if(is_report_dialogs_frozen()) return;
 
   turns_to_advance = tech_turns_to_advance(game.player_ptr);
+  bulbs_per_turn = tech_bulbs_per_turn(game.player_ptr);
   if (turns_to_advance == FC_INFINITY) {
     my_snprintf(text, sizeof(text), _("Research speed: no research"));
   } else {
     my_snprintf(text, sizeof(text),
-               PL_("Research speed: %d turn/advance",
-                   "Research speed: %d turns/advance", turns_to_advance),
-               turns_to_advance);
+               PL_("Research speed: %d turn/advance (%d bulbs/turn)",
+                   PL_("Research speed: %d turns/advance (%d bulb/turn)", 
+                       "Research speed: %d turns/advance (%d bulbs/turn)",
+                       bulbs_per_turn),
+                   turns_to_advance),
+               turns_to_advance, bulbs_per_turn);
   }
 
   gtk_set_label(science_label, text);
 
   for (i=0; i<4; i++) {
     gtk_clist_freeze(GTK_CLIST(science_list[i]));
     gtk_clist_clear(GTK_CLIST(science_list[i]));
   }
 
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.33
diff -U9 -r1.33 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       2003/07/29 15:16:31     1.33
+++ client/gui-gtk-2.0/repodlgs.c       2003/09/05 20:21:38
@@ -364,30 +364,35 @@
 void science_dialog_update(void)
 {
   if(science_dialog_shell) {
   char text[512];
   int i, j, hist;
   GtkWidget *item;
   GList *sorting_list = NULL;
   gdouble pct;
   int turns_to_advance;
+  int bulbs_per_turn;
   int steps;
 
   if(is_report_dialogs_frozen()) return;
 
   turns_to_advance = tech_turns_to_advance(game.player_ptr);
+  bulbs_per_turn = tech_bulbs_per_turn(game.player_ptr);
   if (turns_to_advance == FC_INFINITY) {
     my_snprintf(text, sizeof(text), _("Research speed: no research"));
   } else {
     my_snprintf(text, sizeof(text),
-               PL_("Research speed: %d turn/advance",
-                   "Research speed: %d turns/advance", turns_to_advance),
-               turns_to_advance);
+               PL_("Research speed: %d turn/advance (%d bulbs/turn)",
+                   PL_("Research speed: %d turns/advance (%d bulb/turn)", 
+                       "Research speed: %d turns/advance (%d bulbs/turn)",
+                       bulbs_per_turn),
+                   turns_to_advance),
+               turns_to_advance, bulbs_per_turn);
   }
 
   gtk_set_label(science_label, text);
 
   for (i=0; i<4; i++) {
     gtk_list_store_clear(science_model[i]);
   }
 
   /* collect all researched techs in sorting_list */
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.68
diff -U9 -r1.68 tech.c
--- common/tech.c       2003/08/11 02:24:03     1.68
+++ common/tech.c       2003/09/05 20:21:44
@@ -327,30 +327,42 @@
 }
 
 /**************************************************************************
  Returns number of turns to advance (assuming current state of
  civilization).
 **************************************************************************/
 int tech_turns_to_advance(struct player *pplayer)
 {
   /* The number of bulbs the civilization produces every turn. */
-  int current_output = 0;
-
-  city_list_iterate(pplayer->cities, pcity) {
-    current_output += pcity->science_total;
-  } city_list_iterate_end;
+  int current_output = tech_bulbs_per_turn(pplayer);
 
   if (current_output <= 0) {
     return FC_INFINITY;
   }
 
   return ((total_bulbs_required(pplayer) + current_output - 1)
          / current_output);
+}
+
+/**************************************************************************
+ Returns number of bulbs per turn (assuming current state of
+ civilization).
+**************************************************************************/
+int tech_bulbs_per_turn(struct player *pplayer)
+{
+  /* The number of bulbs the civilization produces every turn. */
+  int current_output = 0;
+
+  city_list_iterate(pplayer->cities, pcity) {
+    current_output += pcity->science_total;
+  } city_list_iterate_end;
+
+  return (current_output);
 }
 
 /**************************************************************************
   Returns the number of bulbs which are required to finished the
   currently researched tech denoted by
   pplayer->research.researching. This is _NOT_ the number of bulbs
   which are left to get the advance. Use the term
   "total_bulbs_required(pplayer) - pplayer->research.bulbs_researched"
   if you want this.
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.42
diff -U9 -r1.42 tech.h
--- common/tech.h       2003/08/11 02:24:03     1.42
+++ common/tech.h       2003/09/05 20:21:46
@@ -116,18 +116,19 @@
 bool tech_is_available(struct player *pplayer, Tech_Type_id id);
 bool tech_exists(Tech_Type_id id);
 Tech_Type_id find_tech_by_name(const char *s);
 
 bool tech_flag(Tech_Type_id tech, enum tech_flag_id flag);
 enum tech_flag_id tech_flag_from_str(const char *s);
 Tech_Type_id find_tech_by_flag(int index, enum tech_flag_id flag);
 
 int tech_turns_to_advance(struct player *pplayer);
+int tech_bulbs_per_turn(struct player *pplayer);
 
 int total_bulbs_required(struct player *pplayer);
 int base_total_bulbs_required(struct player *pplayer,Tech_Type_id tech);
 bool techs_have_fixed_costs(void);
 
 int num_unknown_techs_for_goal(struct player *pplayer, Tech_Type_id goal);
 int total_bulbs_required_for_goal(struct player *pplayer, Tech_Type_id goal);
 bool is_tech_a_req_for_goal(struct player *pplayer, Tech_Type_id tech,
                           Tech_Type_id goal);

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