[Freeciv-Dev] (PR#12747) better text for the goal in the science report
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12747 >
Currently it just tells the number of steps. With this patch it also
tells the number of bulbs required and number of turns. This is
something I've wanted for a while but with the techtree it's even more
useful (since you can change between goals so easily).
-jason
? client/foo
? client/gui-gtk-2.0/foo
Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.31
diff -u -r1.31 text.c
--- client/text.c 5 Apr 2005 09:24:29 -0000 1.31
+++ client/text.c 9 Apr 2005 18:02:02 -0000
@@ -403,14 +403,12 @@
}
/****************************************************************************
- Returns the text to display in the science dialog.
+ Return total expected bulbs.
****************************************************************************/
-const char *science_dialog_text(void)
+static int get_bulbs_per_turn(int *pours, int *ptheirs)
{
- int turns_to_advance;
struct player *plr = game.player_ptr;
int ours = 0, theirs = 0;
- INIT;
/* Sum up science */
players_iterate(pplayer) {
@@ -425,6 +423,27 @@
}
} players_iterate_end;
+ if (pours) {
+ *pours = ours;
+ }
+ if (ptheirs) {
+ *ptheirs = theirs;
+ }
+ return ours + theirs;
+}
+
+/****************************************************************************
+ Returns the text to display in the science dialog.
+****************************************************************************/
+const char *science_dialog_text(void)
+{
+ int turns_to_advance;
+ struct player *plr = game.player_ptr;
+ int ours, theirs;
+ INIT;
+
+ get_bulbs_per_turn(&ours, &theirs);
+
if (ours == 0 && theirs == 0) {
add(_("Progress: no research"));
RETURN;
@@ -449,6 +468,39 @@
}
/****************************************************************************
+ Set the science-goal-label text as if we're researching the given goal.
+****************************************************************************/
+const char *get_science_goal_text(Tech_Type_id goal)
+{
+ int steps = num_unknown_techs_for_goal(game.player_ptr, goal);
+ int bulbs = total_bulbs_required_for_goal(game.player_ptr, goal);
+ int bulbs_needed = bulbs, turns;
+ int perturn = get_bulbs_per_turn(NULL, NULL);
+ char buf1[256], buf2[256], buf3[256];
+ INIT;
+
+ if (is_tech_a_req_for_goal(game.player_ptr,
+ game.player_ptr->research->researching, goal)) {
+ bulbs_needed -= game.player_ptr->research->bulbs_researched;
+ }
+
+ my_snprintf(buf1, sizeof(buf1),
+ PL_("%d step", "%d steps", steps), steps);
+ my_snprintf(buf2, sizeof(buf2),
+ PL_("%d bulb", "%d bulbs", bulbs), bulbs);
+ if (perturn > 0) {
+ turns = (bulbs_needed + perturn - 1) / perturn;
+ my_snprintf(buf3, sizeof(buf3),
+ PL_("%d turn", "%d turns", turns), turns);
+ } else {
+ my_snprintf(buf3, sizeof(buf3), _("never"));
+ }
+ add_line("(%s - %s - %s)", buf1, buf2, buf3);
+
+ RETURN;
+}
+
+/****************************************************************************
Return the text for the label on the info panel. (This is traditionally
shown to the left of the mapview.)
****************************************************************************/
Index: client/text.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.h,v
retrieving revision 1.9
diff -u -r1.9 text.h
--- client/text.h 17 Dec 2004 09:13:54 -0000 1.9
+++ client/text.h 9 Apr 2005 18:02:02 -0000
@@ -26,6 +26,7 @@
const char *get_nearest_city_text(struct city *pcity, int sq_dist);
const char *unit_description(struct unit *punit);
const char *science_dialog_text(void);
+const char *get_science_goal_text(Tech_Type_id goal);
const char *get_info_label_text(void);
const char *get_bulb_tooltip(void);
const char *get_global_warming_tooltip(void);
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.82
diff -u -r1.82 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c 6 Apr 2005 17:36:15 -0000 1.82
+++ client/gui-gtk-2.0/repodlgs.c 9 Apr 2005 18:02:02 -0000
@@ -307,7 +307,6 @@
*****************************************************************/
void science_goal_callback(GtkWidget *widget, gpointer data)
{
- char text[512];
size_t to = (size_t) data;
if (GTK_TOGGLE_BUTTON(science_help_toggle)->active) {
@@ -317,11 +316,8 @@
science_dialog_update();
}
else {
- int steps = num_unknown_techs_for_goal(game.player_ptr, to);
- my_snprintf(text, sizeof(text),
- PL_("(%d step)", "(%d steps)", steps), steps);
- gtk_label_set_text(GTK_LABEL(science_goal_label), text);
-
+ gtk_label_set_text(GTK_LABEL(science_goal_label),
+ get_science_goal_text(to));
dsend_packet_player_tech_goal(&aconnection, to);
}
}
@@ -391,7 +387,6 @@
GtkWidget *item;
GList *sorting_list = NULL, *it;
gdouble pct;
- int steps;
GtkSizeGroup *group1, *group2;
if (is_report_dialogs_frozen()) {
@@ -512,11 +507,8 @@
gtk_widget_set_sensitive(science_goal_menu_button,
can_client_issue_orders());
- steps = num_unknown_techs_for_goal(game.player_ptr,
- game.player_ptr->ai.tech_goal);
- my_snprintf(text, sizeof(text), PL_("(%d step)", "(%d steps)", steps),
- steps);
- gtk_label_set_text(GTK_LABEL(science_goal_label), text);
+ gtk_label_set_text(GTK_LABEL(science_goal_label),
+ get_science_goal_text(game.player_ptr->ai.tech_goal));
if (game.player_ptr->ai.tech_goal == A_UNSET) {
item = gtk_menu_item_new_with_label(get_tech_name(game.player_ptr,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12747) better text for the goal in the science report,
Jason Short <=
|
|