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

[Freeciv-Dev] (PR#9392) new text function get_happiness_wonders

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9392) new text function get_happiness_wonders
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 14 Jul 2004 21:19:38 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch adds a new function get_happiness_wonders to text.c. This
creates the string used to describe the effect of wonders 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.

This corresponds very closesly to the get_happiness_buildings patch in
PR#9365.

jason

Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.6
diff -u -r1.6 text.c
--- client/text.c       15 Jul 2004 03:45:12 -0000      1.6
+++ client/text.c       15 Jul 2004 04:13:40 -0000
@@ -745,3 +745,42 @@
 
   RETURN;
 }
+
+/****************************************************************************
+  Get the text describing wonders that affect happiness.
+****************************************************************************/
+const char *get_happiness_wonders(const struct city *pcity)
+{
+  int faces = 0;
+  INIT;
+
+  add_line(_("Wonders: "));
+
+  if (city_affected_by_wonder(pcity, B_HANGING)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_HANGING));
+  }
+  if (city_affected_by_wonder(pcity, B_BACH)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_BACH));
+  }
+  /* hack for eliminating gtk_set_line_wrap() -mck */
+  if (faces > 1) {
+    /* sizeof("Wonders: ") */
+    add(_("\n              "));
+  }
+  if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_SHAKESPEARE));
+  }
+  if (city_affected_by_wonder(pcity, B_CURE)) {
+    faces++;
+    add(_("%s. "), get_improvement_name(B_CURE));
+  }
+
+  if (faces == 0) {
+    add(_("None. "));
+  }
+
+  RETURN;
+}
Index: client/text.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.h,v
retrieving revision 1.3
diff -u -r1.3 text.h
--- client/text.h       15 Jul 2004 03:45:12 -0000      1.3
+++ client/text.h       15 Jul 2004 04:13:40 -0000
@@ -40,5 +40,6 @@
 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);
+const char *get_happiness_wonders(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.17
diff -u -r1.17 happiness.c
--- client/gui-gtk/happiness.c  15 Jul 2004 03:45:12 -0000      1.17
+++ client/gui-gtk/happiness.c  15 Jul 2004 04:13:40 -0000
@@ -327,54 +327,8 @@
 static void happiness_dialog_update_wonders(struct happiness_dialog
                                            *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-
-  my_snprintf(bptr, nleft, _("Wonders: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_affected_by_wonder(pcity, B_HANGING)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_HANGING));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_BACH)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_BACH));
-    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 > 1) {
-    /* sizeof("Wonders: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_CURE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CURE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-  }
-
-  gtk_set_label(pdialog->hlabels[WONDERS], buf);
+  gtk_set_label(pdialog->hlabels[WONDERS],
+               get_happiness_wonders(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.14
diff -u -r1.14 happiness.c
--- client/gui-gtk-2.0/happiness.c      15 Jul 2004 03:45:12 -0000      1.14
+++ client/gui-gtk-2.0/happiness.c      15 Jul 2004 04:13:40 -0000
@@ -321,54 +321,8 @@
 static void happiness_dialog_update_wonders(struct happiness_dialog
                                            *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-
-  my_snprintf(bptr, nleft, _("Wonders: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_affected_by_wonder(pcity, B_HANGING)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_HANGING));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_BACH)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_BACH));
-    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 > 1) {
-    /* sizeof("Wonders: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_CURE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CURE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-  }
-
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[WONDERS]), buf);
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[WONDERS]),
+                    get_happiness_wonders(pdialog->pcity));
 }
 
 /**************************************************************************
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.77
diff -u -r1.77 citydlg.c
--- client/gui-mui/citydlg.c    15 Jul 2004 03:45:12 -0000      1.77
+++ client/gui-mui/citydlg.c    15 Jul 2004 04:13:41 -0000
@@ -2275,53 +2275,8 @@
   settext(pdialog->happiness_citizen_text[3], buf);
 
   /* WONDERS */
-  faces = 0;
-  bptr = buf;
-  nleft = sizeof(buf);
-
-  my_snprintf(bptr, nleft, _("Wonders: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_affected_by_wonder(pcity, B_HANGING)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_HANGING));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_BACH)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_BACH));
-    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 > 1) {
-    /* sizeof("Wonders: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_CURE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CURE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-  }
-
-  settext(pdialog->happiness_citizen_text[4], buf);
+  settext(pdialog->happiness_citizen_text[4],
+         get_happiness_wonders(pcity));
 
   /* the citizen's */
   for(i=0;i<5;i++)
Index: client/gui-win32/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/happiness.c,v
retrieving revision 1.7
diff -u -r1.7 happiness.c
--- client/gui-win32/happiness.c        15 Jul 2004 03:45:12 -0000      1.7
+++ client/gui-win32/happiness.c        15 Jul 2004 04:13:41 -0000
@@ -279,53 +279,8 @@
 static void happiness_dialog_update_wonders(struct happiness_dlg
                                             *pdialog)
 {
-  int faces = 0;
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-
-  my_snprintf(bptr, nleft, _("Wonders: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (city_affected_by_wonder(pcity, B_HANGING)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_HANGING));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_BACH)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_BACH));
-    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 > 1) {
-    /* sizeof("Wonders: ") */
-    my_snprintf(bptr, nleft, _("\n              "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-  if (city_affected_by_wonder(pcity, B_CURE)) {
-    faces++;
-    my_snprintf(bptr, nleft, get_improvement_name(B_CURE));
-    bptr = end_of_strn(bptr, &nleft);
-    my_snprintf(bptr, nleft, _(". "));
-    bptr = end_of_strn(bptr, &nleft);
-  }
-
-  if (faces == 0) {
-    my_snprintf(bptr, nleft, _("None. "));
-  }
-  SetWindowText(pdialog->mod_label[WONDERS], buf);
+  SetWindowText(pdialog->mod_label[WONDERS],
+               get_happiness_wonders(pdialog->pcity));
 }
 
 /**************************************************************************

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