Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9365) new text function get_happiness_buildings
Home

[Freeciv-Dev] (PR#9365) new text function get_happiness_buildings

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9365) new text function get_happiness_buildings
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxx>
Date: Tue, 13 Jul 2004 01:28:58 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9365 >

This patch adds a new function get_happiness_buildings to text.c.  This 
creates the string used to describe the effect of buildings that 
increase happiness.  The exact same string is used in several clients.

In theory the clients should show the improvement graphics the way 
gui-sdl does.  This will require something a little bit more 
complicated.  But for now I just want to simplify the current code.

gui-gtk, gui-win32, and gui-mui are supported but only gui-gtk-2.0 is 
tested.

jason

Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.5
diff -u -r1.5 text.c
--- client/text.c       25 Jun 2004 23:35:55 -0000      1.5
+++ client/text.c       13 Jul 2004 08:26:30 -0000
@@ -704,3 +704,44 @@
           textyear(game.year));
   RETURN;
 }
+
+/****************************************************************************
+  Get the text describing buildings that effect happiness.
+****************************************************************************/
+const char *get_happiness_buildings(const struct city *pcity)
+{
+  int faces = 0;
+  struct government *g = get_gov_pcity(pcity);
+  INIT;
+
+  add_line(_("Buildings: "));
+  if (city_got_building(pcity, B_TEMPLE)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_TEMPLE));
+  }
+  if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_COURTHOUSE));
+  }
+  if (city_got_building(pcity, B_COLOSSEUM)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_COLOSSEUM));
+  }
+  if (faces > 2) {
+    /* Hack to get wrapping right. */
+    add(_("\n              "));
+  }
+  if (city_got_effect(pcity, B_CATHEDRAL)) {
+    faces++;
+    add("%s", get_improvement_name(B_CATHEDRAL));
+    if (!city_got_building(pcity, B_CATHEDRAL)) {
+      add(_("(%s)"), get_improvement_name(B_MICHELANGELO));
+    }
+    add(_(". "));
+  }
+  if (faces == 0) {
+    add(_("None. "));
+  }
+
+  RETURN;
+}
Index: client/text.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.h,v
retrieving revision 1.2
diff -u -r1.2 text.h
--- client/text.h       25 Apr 2004 18:30:00 -0000      1.2
+++ client/text.h       13 Jul 2004 08:26:30 -0000
@@ -39,5 +39,6 @@
 const char *format_duration(int duration);
 const char *get_ping_time_text(struct player *pplayer);
 const char *get_report_title(const char *report_name);
+const char *get_happiness_buildings(const struct city *pcity);
 
 #endif /* FC__TEXT_H */
Index: client/gui-gtk/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/happiness.c,v
retrieving revision 1.16
diff -u -r1.16 happiness.c
--- client/gui-gtk/happiness.c  10 Jul 2004 18:48:18 -0000      1.16
+++ client/gui-gtk/happiness.c  13 Jul 2004 08:26:30 -0000
@@ -24,6 +24,7 @@
 #include "mem.h"
 #include "support.h"
 
+#include "text.h"
 #include "tilespec.h"
 
 #include "graphics.h"
@@ -275,64 +276,8 @@
 static void happiness_dialog_update_buildings(struct happiness_dialog
                                              *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-  struct government *g = get_gov_pcity(pcity);
-
-  my_snprintf(bptr, nleft, _("Buildings: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_got_building(pcity, B_TEMPLE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COLOSSEUM)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  /* hack for eliminating gtk_set_line_wrap() -mck */
-  if (faces > 2) {
-    /* sizeof("Buildings: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_effect(pcity, B_CATHEDRAL)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL));
-    bptr = end_of_strn(bptr, &nleft);
-    if (!city_got_building(pcity, B_CATHEDRAL)) {
-      my_snprintf(bptr, nleft, _("("));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, _(")"));
-      bptr = end_of_strn(bptr, &nleft);
-    }
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  gtk_set_label(pdialog->hlabels[BUILDINGS], buf);
+  gtk_set_label(pdialog->hlabels[BUILDINGS],
+               get_happiness_buildings(pdialog->pcity));
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/happiness.c,v
retrieving revision 1.13
diff -u -r1.13 happiness.c
--- client/gui-gtk-2.0/happiness.c      10 Jul 2004 18:48:18 -0000      1.13
+++ client/gui-gtk-2.0/happiness.c      13 Jul 2004 08:26:30 -0000
@@ -24,12 +24,14 @@
 #include "mem.h"
 #include "support.h"
 
+#include "text.h"
+#include "tilespec.h"
+
 #include "graphics.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
 #include "happiness.h"
 #include "mapview.h"
-#include "tilespec.h"
 
 /* semi-arbitrary number that controls the width of the happiness widget */
 #define HAPPINESS_PIX_WIDTH 23
@@ -268,64 +270,8 @@
 static void happiness_dialog_update_buildings(struct happiness_dialog
                                              *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-  struct government *g = get_gov_pcity(pcity);
-
-  my_snprintf(bptr, nleft, _("Buildings: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_got_building(pcity, B_TEMPLE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COLOSSEUM)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  /* hack for eliminating gtk_set_line_wrap() -mck */
-  if (faces > 2) {
-    /* sizeof("Buildings: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_effect(pcity, B_CATHEDRAL)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL));
-    bptr = end_of_strn(bptr, &nleft);
-    if (!city_got_building(pcity, B_CATHEDRAL)) {
-      my_snprintf(bptr, nleft, _("("));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, _(")"));
-      bptr = end_of_strn(bptr, &nleft);
-    }
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[BUILDINGS]), buf);
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[BUILDINGS]),
+                    get_happiness_buildings(pdialog->pcity));
 }
 
 /**************************************************************************
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.76
diff -u -r1.76 citydlg.c
--- client/gui-mui/citydlg.c    10 Jul 2004 18:48:18 -0000      1.76
+++ client/gui-mui/citydlg.c    13 Jul 2004 08:26:31 -0000
@@ -39,6 +39,8 @@
 #include "player.h"
 #include "shared.h"
 
+#include "text.h"
+
 #include "cityrep.h"
 #include "clinet.h"
 #include "cma_fec.h"
@@ -2243,61 +2245,8 @@
 
 
   /* BUILDINGS */
-  faces = 0;
-  bptr = buf;
-  nleft = sizeof(buf);
-  my_snprintf(bptr, nleft, _("Buildings: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_got_building(pcity, B_TEMPLE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COLOSSEUM)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  /* hack for eliminating gtk_set_line_wrap() -mck */
-  if (faces > 2) {
-    /* sizeof("Buildings: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_effect(pcity, B_CATHEDRAL)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL));
-    bptr = end_of_strn(bptr, &nleft);
-    if (!city_got_building(pcity, B_CATHEDRAL)) {
-      my_snprintf(bptr, nleft, _("("));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, _(")"));
-      bptr = end_of_strn(bptr, &nleft);
-    }
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  settext(pdialog->happiness_citizen_text[2], buf);
+  settext(pdialog->happiness_citizen_text[2],
+         get_happiness_buildings(pcity));
 
 
   /* UNITS */
Index: client/gui-win32/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/happiness.c,v
retrieving revision 1.6
diff -u -r1.6 happiness.c
--- client/gui-win32/happiness.c        10 Jul 2004 18:48:18 -0000      1.6
+++ client/gui-win32/happiness.c        13 Jul 2004 08:26:31 -0000
@@ -25,11 +25,13 @@
 #include "mem.h"
 #include "support.h"
 
+#include "text.h"
+#include "tilespec.h"
+
 #include "graphics.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
 #include "happiness.h"
-#include "tilespec.h"
 
 #define HAPPINESS_PIX_WIDTH 23
 
@@ -227,64 +229,8 @@
 static void happiness_dialog_update_buildings(struct happiness_dlg
                                               *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-  struct government *g = get_gov_pcity(pcity);
-
-  my_snprintf(bptr, nleft, _("Buildings: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_got_building(pcity, B_TEMPLE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COURTHOUSE) && g->corruption_level == 0) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_building(pcity, B_COLOSSEUM)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  /* hack for eliminating gtk_set_line_wrap() -mck */
-  if (faces > 2) {
-    /* sizeof("Buildings: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_got_effect(pcity, B_CATHEDRAL)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL));
-    bptr = end_of_strn(bptr, &nleft);
-    if (!city_got_building(pcity, B_CATHEDRAL)) {
-      my_snprintf(bptr, nleft, _("("));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO));
-      bptr = end_of_strn(bptr, &nleft);
-      my_snprintf(bptr, nleft, _(")"));
-      bptr = end_of_strn(bptr, &nleft);
-    }
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  SetWindowText(pdialog->mod_label[BUILDINGS], buf);
+  SetWindowText(pdialog->mod_label[BUILDINGS],
+               get_happiness_buildings(pdialog->pcity));
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9365) new text function get_happiness_buildings, Jason Dorje Short <=