Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11091) put specialists into the cityrep dynamically
Home

[Freeciv-Dev] (PR#11091) put specialists into the cityrep dynamically

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11091) put specialists into the cityrep dynamically
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Nov 2004 15:55:33 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch changes the city report fields to be ruleset-specific:

- The number of city report fields is dynamic.  This means no static 
data may use this value.

- There are a bunch of "fixed" fields in an array in cityrepdata.c.

- When rulesets are received new fields are added.  These new fields 
include a field for each specialist type.  The only problem here is that 
the fields may not be properly sorted.

- Option values in .civclientrc are loaded only after the rulesets are 
received (just like worklists).

jason

Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.39
diff -u -r1.39 cityrepdata.c
--- client/cityrepdata.c        30 Sep 2004 17:14:37 -0000      1.39
+++ client/cityrepdata.c        19 Nov 2004 23:55:10 -0000
@@ -37,7 +37,8 @@
  is handled later.
 *************************************************************************/
 
-static const char *cr_entry_cityname(const struct city *pcity)
+static const char *cr_entry_cityname(const struct city *pcity,
+                                    const void *data)
 {
   /* We used to truncate the name to 14 bytes.  This should not be needed
    * in any modern GUI library and may give an invalid string if a
@@ -45,14 +46,16 @@
   return pcity->name;
 }
 
-static const char *cr_entry_size(const struct city *pcity)
+static const char *cr_entry_size(const struct city *pcity,
+                                const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%2d", pcity->size);
   return buf;
 }
 
-static const char *cr_entry_hstate_concise(const struct city *pcity)
+static const char *cr_entry_hstate_concise(const struct city *pcity,
+                                          const void *data)
 {
   static char buf[4];
   my_snprintf(buf, sizeof(buf), "%s", (city_celebrating(pcity) ? "*" :
@@ -60,7 +63,8 @@
   return buf;
 }
 
-static const char *cr_entry_hstate_verbose(const struct city *pcity)
+static const char *cr_entry_hstate_verbose(const struct city *pcity,
+                                          const void *data)
 {
   static char buf[16];
   my_snprintf(buf, sizeof(buf), "%s",
@@ -70,7 +74,8 @@
   return buf;
 }
 
-static const char *cr_entry_workers(const struct city *pcity)
+static const char *cr_entry_workers(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[32];
   my_snprintf(buf, sizeof(buf), "%d/%d/%d/%d", pcity->ppl_happy[4],
@@ -79,61 +84,57 @@
   return buf;
 }
 
-static const char *cr_entry_happy(const struct city *pcity)
+static const char *cr_entry_happy(const struct city *pcity,
+                                 const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_happy[4]);
   return buf;
 }
 
-static const char *cr_entry_content(const struct city *pcity)
+static const char *cr_entry_content(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_content[4]);
   return buf;
 }
 
-static const char *cr_entry_unhappy(const struct city *pcity)
+static const char *cr_entry_unhappy(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_unhappy[4]);
   return buf;
 }
 
-static const char *cr_entry_angry(const struct city *pcity)
+static const char *cr_entry_angry(const struct city *pcity,
+                                 const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_angry[4]);
   return buf;
 }
 
-static const char *cr_entry_specialists(const struct city *pcity)
+static const char *cr_entry_specialists(const struct city *pcity,
+                                       const void *data)
 {
   return specialists_string(pcity->specialists);
 }
 
-static const char *cr_entry_entertainers(const struct city *pcity)
+static const char *cr_entry_specialist(const struct city *pcity,
+                                      const void *data)
 {
   static char buf[8];
-  my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_ELVIS]);
-  return buf;
-}
-
-static const char *cr_entry_scientists(const struct city *pcity)
-{
-  static char buf[8];
-  my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_SCIENTIST]);
-  return buf;
-}
+  const struct specialist *sp_data = data;
+  Specialist_type_id sp = sp_data - game.rgame.specialists;
 
-static const char *cr_entry_taxmen(const struct city *pcity)
-{
-  static char buf[8];
-  my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_TAXMAN]);
+  my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[sp]);
   return buf;
 }
 
-static const char *cr_entry_attack(const struct city *pcity)
+static const char *cr_entry_attack(const struct city *pcity,
+                                  const void *data)
 {
   static char buf[32];
   int attack_best[4] = {-1, -1, -1, -1}, i;
@@ -165,7 +166,8 @@
   return buf;
 }
 
-static const char *cr_entry_defense(const struct city *pcity)
+static const char *cr_entry_defense(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[32];
   int defense_best[4] = {-1, -1, -1, -1}, i;
@@ -197,7 +199,8 @@
   return buf;
 }
 
-static const char *cr_entry_supported(const struct city *pcity)
+static const char *cr_entry_supported(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[8];
   int num_supported = 0;
@@ -211,7 +214,8 @@
   return buf;
 }
 
-static const char *cr_entry_present(const struct city *pcity)
+static const char *cr_entry_present(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[8];
   int num_present = 0;
@@ -225,7 +229,8 @@
   return buf;
 }
 
-static const char *cr_entry_resources(const struct city *pcity)
+static const char *cr_entry_resources(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[32];
   my_snprintf(buf, sizeof(buf), "%d/%d/%d",
@@ -235,7 +240,8 @@
   return buf;
 }
 
-static const char *cr_entry_foodplus(const struct city *pcity)
+static const char *cr_entry_foodplus(const struct city *pcity,
+                                    const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d",
@@ -243,7 +249,8 @@
   return buf;
 }
 
-static const char *cr_entry_prodplus(const struct city *pcity)
+static const char *cr_entry_prodplus(const struct city *pcity,
+                                    const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d",
@@ -251,7 +258,8 @@
   return buf;
 }
 
-static const char *cr_entry_tradeplus(const struct city *pcity)
+static const char *cr_entry_tradeplus(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d",
@@ -259,7 +267,8 @@
   return buf;
 }
 
-static const char *cr_entry_output(const struct city *pcity)
+static const char *cr_entry_output(const struct city *pcity,
+                                  const void *data)
 {
   static char buf[32];
   int goldie;
@@ -273,7 +282,8 @@
   return buf;
 }
 
-static const char *cr_entry_gold(const struct city *pcity)
+static const char *cr_entry_gold(const struct city *pcity,
+                                const void *data)
 {
   static char buf[8];
   int income = city_gold_surplus(pcity, pcity->tax_total);
@@ -285,7 +295,8 @@
   return buf;
 }
 
-static const char *cr_entry_luxury(const struct city *pcity)
+static const char *cr_entry_luxury(const struct city *pcity,
+                                  const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d",
@@ -293,7 +304,8 @@
   return buf;
 }
 
-static const char *cr_entry_science(const struct city *pcity)
+static const char *cr_entry_science(const struct city *pcity,
+                                   const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d",
@@ -301,7 +313,8 @@
   return buf;
 }
 
-static const char *cr_entry_food(const struct city *pcity)
+static const char *cr_entry_food(const struct city *pcity,
+                                const void *data)
 {
   static char buf[32];
   my_snprintf(buf, sizeof(buf), "%d/%d",
@@ -310,7 +323,8 @@
   return buf;
 }
 
-static const char *cr_entry_growturns(const struct city *pcity)
+static const char *cr_entry_growturns(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[8];
   int turns = city_turns_to_grow(pcity);
@@ -324,21 +338,24 @@
   return buf;
 }
 
-static const char *cr_entry_pollution(const struct city *pcity)
+static const char *cr_entry_pollution(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d", pcity->pollution);
   return buf;
 }
 
-static const char *cr_entry_num_trade(const struct city *pcity)
+static const char *cr_entry_num_trade(const struct city *pcity,
+                                     const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%d", city_num_trade_routes(pcity));
   return buf;
 }
 
-static const char *cr_entry_building(const struct city *pcity)
+static const char *cr_entry_building(const struct city *pcity,
+                                    const void *data)
 {
   static char buf[128];
   const char *from_worklist =
@@ -378,21 +395,24 @@
   return buf;
 }
 
-static const char *cr_entry_corruption(const struct city *pcity)
+static const char *cr_entry_corruption(const struct city *pcity,
+                                      const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d", pcity->corruption);
   return buf;
 }
 
-static const char *cr_entry_waste(const struct city *pcity)
+static const char *cr_entry_waste(const struct city *pcity,
+                                 const void *data)
 {
   static char buf[8];
   my_snprintf(buf, sizeof(buf), "%3d", pcity->shield_waste);
   return buf;
 }
 
-static const char *cr_entry_cma(const struct city *pcity)
+static const char *cr_entry_cma(const struct city *pcity,
+                               const void *data)
 {
   return cmafec_get_short_descr_of_city(pcity);
 }
@@ -407,93 +427,87 @@
 /* This generates the function name and the tagname: */
 #define FUNC_TAG(var)  cr_entry_##var, #var 
 
-struct city_report_spec city_report_specs[] = {
+static const struct city_report_spec base_city_report_specs[] = {
   { TRUE, -15, 0, NULL,  N_("?city:Name"),      N_("City Name"),
-                                      FUNC_TAG(cityname) },
+    NULL, FUNC_TAG(cityname) },
   { TRUE, 2, 1, NULL,  N_("?size:Sz"),        N_("Size"),
-                                      FUNC_TAG(size) },
+    NULL, FUNC_TAG(size) },
   { TRUE,  -8, 1, NULL,  N_("State"),     N_("Rapture/Peace/Disorder"),
-                                      FUNC_TAG(hstate_verbose) },
+    NULL, FUNC_TAG(hstate_verbose) },
   { FALSE,  1, 1, NULL,  NULL,            N_("Concise *=Rapture, X=Disorder"),
-                                      FUNC_TAG(hstate_concise) },
+    NULL, FUNC_TAG(hstate_concise) },
   { TRUE, 10, 1, N_("Workers"),
     N_("?happy/content/unhappy/angry:H/C/U/A"),
     N_("Workers: Happy, Content, Unhappy, Angry"),
-    FUNC_TAG(workers) },
+    NULL, FUNC_TAG(workers) },
   { FALSE, 2, 1, NULL, N_("?Happy workers:H"), N_("Workers: Happy"),
-    FUNC_TAG(happy) },
+    NULL, FUNC_TAG(happy) },
   { FALSE, 2, 1, NULL, N_("?Content workers:C"), N_("Workers: Content"),
-    FUNC_TAG(content) },
+    NULL, FUNC_TAG(content) },
   { FALSE, 2, 1, NULL, N_("?Unhappy workers:U"), N_("Workers: Unhappy"),
-    FUNC_TAG(unhappy) },
+    NULL, FUNC_TAG(unhappy) },
   { FALSE, 2, 1, NULL, N_("?Angry workers:A"), N_("Workers: Angry"),
-    FUNC_TAG(angry) },
+    NULL, FUNC_TAG(angry) },
   { FALSE, 7, 1, N_("Special"),
     N_("?entertainers/scientists/taxmen:E/S/T"),
     N_("Entertainers, Scientists, Taxmen"),
-    FUNC_TAG(specialists) },
-  { FALSE, 2, 1, NULL, N_("?Entertainers:E"), N_("Entertainers"),
-    FUNC_TAG(entertainers) },
-  { FALSE, 2, 1, NULL, N_("?Scientists:S"), N_("Scientists"),
-    FUNC_TAG(scientists) },
-  { FALSE, 2, 1, NULL, N_("?Taxmen:T"), N_("Taxmen"),
-    FUNC_TAG(taxmen) },
+    NULL, FUNC_TAG(specialists) },
   { FALSE, 8, 1, N_("Best"), N_("attack"),
-    N_("Best attacking units"), FUNC_TAG(attack)},
+    N_("Best attacking units"), NULL, FUNC_TAG(attack)},
   { FALSE, 8, 1, N_("Best"), N_("defense"),
-    N_("Best defending units"), FUNC_TAG(defense)},
+    N_("Best defending units"), NULL, FUNC_TAG(defense)},
   { FALSE, 2, 1, N_("Units"), N_("?Supported (units):Sup"),
-    N_("Number of units supported"), FUNC_TAG(supported) },
+    N_("Number of units supported"), NULL, FUNC_TAG(supported) },
   { FALSE, 2, 1, N_("Units"), N_("?Present (units):Prs"),
-    N_("Number of units present"), FUNC_TAG(present) },
+    N_("Number of units present"), NULL, FUNC_TAG(present) },
 
   { TRUE,  10, 1, N_("Surplus"), N_("?food/prod/trade:F/P/T"),
                                  N_("Surplus: Food, Production, Trade"),
-                                      FUNC_TAG(resources) },
+    NULL, FUNC_TAG(resources) },
   { FALSE, 3, 1, NULL, N_("?Food surplus:F+"), N_("Surplus: Food"),
-    FUNC_TAG(foodplus) },
+    NULL, FUNC_TAG(foodplus) },
   { FALSE, 3, 1, NULL, N_("?Production surplus:P+"),
-    N_("Surplus: Production"), FUNC_TAG(prodplus) },
+    N_("Surplus: Production"), NULL, FUNC_TAG(prodplus) },
   { FALSE, 3, 1, NULL, N_("?Trade surplus:T+"), N_("Surplus: Trade"),
-    FUNC_TAG(tradeplus) },
+    NULL, FUNC_TAG(tradeplus) },
   { TRUE,  10, 1, N_("Economy"), N_("?gold/lux/sci:G/L/S"),
                                  N_("Economy: Gold, Luxuries, Science"),
-                                      FUNC_TAG(output) },
+    NULL, FUNC_TAG(output) },
   { FALSE, 3, 1, NULL, N_("?Gold:G"), N_("Economy: Gold"),
-    FUNC_TAG(gold) },
+    NULL, FUNC_TAG(gold) },
   { FALSE, 3, 1, NULL, N_("?Luxury:L"), N_("Economy: Luxury"),
-    FUNC_TAG(luxury) },
+    NULL, FUNC_TAG(luxury) },
   { FALSE, 3, 1, NULL, N_("?Science:S"), N_("Economy: Science"),
-    FUNC_TAG(science) },
+    NULL, FUNC_TAG(science) },
   { FALSE,  1, 1, N_("?trade_routes:n"), N_("?trade_routes:T"),
                                          N_("Number of Trade Routes"),
-                                      FUNC_TAG(num_trade) },
+    NULL, FUNC_TAG(num_trade) },
   { TRUE,   7, 1, N_("Food"), N_("Stock"), N_("Food Stock"),
-                                      FUNC_TAG(food) },
+    NULL, FUNC_TAG(food) },
   { FALSE,  3, 1, NULL, N_("?pollution:Pol"),        N_("Pollution"),
-                                      FUNC_TAG(pollution) },
+    NULL, FUNC_TAG(pollution) },
   { FALSE,  4, 1, N_("Grow"), N_("Turns"), N_("Turns until growth/famine"),
-    FUNC_TAG(growturns) },
+    NULL, FUNC_TAG(growturns) },
   { FALSE,  3, 1, NULL, N_("?corruption:Cor"),        N_("Corruption"),
-                                      FUNC_TAG(corruption) },
-  { FALSE,  3, 1, NULL, N_("?waste:Was"), N_("Waste"), FUNC_TAG(waste) },
+    NULL, FUNC_TAG(corruption) },
+  { FALSE,  3, 1, NULL, N_("?waste:Was"), N_("Waste"),
+    NULL, FUNC_TAG(waste) },
   { TRUE,  15, 1, NULL, N_("CMA"),           N_("City Management Agent"),
-                                      FUNC_TAG(cma) },
+    NULL, FUNC_TAG(cma) },
   { TRUE,   0, 1, N_("Currently Building"), N_("(Stock,Target,Turns,Buy)"),
                                             N_("Currently Building"),
-                                      FUNC_TAG(building) }
+    NULL, FUNC_TAG(building) }
 };
 
-#if 0
-const int num_report_cols = ARRAY_SIZE(city_report_specs);
-#endif
+struct city_report_spec *city_report_specs;
+static int num_creport_cols;
 
 /******************************************************************
 Some simple wrappers:
 ******************************************************************/
 int num_city_report_spec(void)
 {
-  return NUM_CREPORT_COLS;
+  return num_creport_cols;
 }
 bool *city_report_spec_show_ptr(int i)
 {
@@ -509,11 +523,18 @@
   pre-translate the fields (to make things easier on the GUI
   writers).  Should be called before the GUI starts up.
 ******************************************************************/
-void init_city_report_data(void)
+void init_city_report_game_data(void)
 {
   int i;
 
-  for (i = 0; i < NUM_CREPORT_COLS; i++) {
+  num_creport_cols = ARRAY_SIZE(base_city_report_specs) + SP_COUNT;
+  city_report_specs
+    = fc_realloc(city_report_specs,
+                num_creport_cols * sizeof(*city_report_specs));
+  memcpy(city_report_specs, base_city_report_specs,
+        sizeof(base_city_report_specs));
+
+  for (i = 0; i < ARRAY_SIZE(base_city_report_specs); i++) {
     struct city_report_spec* p = &city_report_specs[i];
 
     if (p->title1) {
@@ -525,7 +546,26 @@
     p->explanation = _(p->explanation);
   }
 
-  assert(NUM_CREPORT_COLS == ARRAY_SIZE(city_report_specs));
+  specialist_type_iterate(sp) {
+    struct city_report_spec *p = &city_report_specs[i];
+    static char explanation[SP_COUNT][128];
+
+    p->show = FALSE;
+    p->width = 2;
+    p->space = 1;
+    p->title1 = Q_("?specialist:Spec:");
+    p->title2 = _(game.rgame.specialists[sp].name);
+    my_snprintf(explanation[sp], sizeof(explanation[sp]),
+               _("Specialists: %s"), p->title2);
+    p->explanation = explanation[sp];
+    p->data = &game.rgame.specialists[sp];
+    p->func = cr_entry_specialist;
+    p->tagname = game.rgame.specialists[sp].name;
+
+    i++;
+  } specialist_type_iterate_end;
+
+  assert(NUM_CREPORT_COLS == ARRAY_SIZE(base_city_report_specs) + SP_COUNT);
 }
 
 /**********************************************************************
Index: client/cityrepdata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.h,v
retrieving revision 1.12
diff -u -r1.12 cityrepdata.h
--- client/cityrepdata.h        30 Sep 2004 17:14:37 -0000      1.12
+++ client/cityrepdata.h        19 Nov 2004 23:55:10 -0000
@@ -18,7 +18,7 @@
 #include "fc_types.h"
 
 /* Number of city report columns: have to set this manually now... */
-#define NUM_CREPORT_COLS 33
+#define NUM_CREPORT_COLS (num_city_report_spec())
 
 struct city_report_spec {
   bool show;                   /* modify this to customize */
@@ -27,11 +27,12 @@
   const char *title1;          /* already translated or NULL */
   const char *title2;          /* already translated or NULL */
   const char *explanation;     /* already translated */ 
-  const char *(*func)(const struct city *);
+  void *data;
+  const char *(*func)(const struct city * pcity, const void *data);
   const char *tagname;         /* for save_options */
 };
 
-extern struct city_report_spec city_report_specs[];
+extern struct city_report_spec *city_report_specs;
 
 /* Use tagname rather than index for load/save, because later
    additions won't necessarily be at the end.
@@ -58,7 +59,7 @@
 bool *city_report_spec_show_ptr(int i);
 const char *city_report_spec_tagname(int i);
 
-void init_city_report_data(void);
+void init_city_report_game_data(void);
 
 int cityrepfield_compare(const char *field1, const char *field2);
 
Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.197.2.6
diff -u -r1.197.2.6 civclient.c
--- client/civclient.c  19 Nov 2004 01:32:42 -0000      1.197.2.6
+++ client/civclient.c  19 Nov 2004 23:55:10 -0000
@@ -283,7 +283,6 @@
   my_init_network();
   chatline_common_init();
   init_messages_where();
-  init_city_report_data();
   init_player_dlg_common();
   settable_options_init();
 
@@ -473,6 +472,7 @@
     client_state=newstate;
 
     if (client_state == CLIENT_GAME_RUNNING_STATE) {
+      init_city_report_game_data();
       load_ruleset_specific_options();
       create_event(NULL, E_GAME_START, _("Game started."));
       precalc_tech_data();
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.103.2.1
diff -u -r1.103.2.1 options.c
--- client/options.c    9 Oct 2004 16:00:37 -0000       1.103.2.1
+++ client/options.c    19 Nov 2004 23:55:10 -0000
@@ -475,11 +475,6 @@
       secfile_lookup_int_default(&sf, messages_where[i],
                                 "%s.message_where_%02d", prefix, i);
   }
-  for (i = 1; i < num_city_report_spec(); i++) {
-    bool *ip = city_report_spec_show_ptr(i);
-    *ip = secfile_lookup_bool_default(&sf, *ip, "%s.city_report_%s", prefix,
-                                    city_report_spec_tagname(i));
-  }
   
   for(i = 1; i < num_player_dlg_columns; i++) {
     bool *show = &(player_dlg_columns[i].show);
@@ -532,6 +527,14 @@
                          &(game.player_ptr->worklists[i]));
   }
 
+  /* Load city report columns (which include some ruleset data). */
+  for (i = 1; i < num_city_report_spec(); i++) {
+    bool *ip = city_report_spec_show_ptr(i);
+
+    *ip = secfile_lookup_bool_default(&sf, *ip, "client.city_report_%s",
+                                    city_report_spec_tagname(i));
+  }
+
   section_file_free(&sf);
 }
 
Index: client/gui-gtk/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v
retrieving revision 1.86
diff -u -r1.86 cityrep.c
--- client/gui-gtk/cityrep.c    29 Sep 2004 02:24:20 -0000      1.86
+++ client/gui-gtk/cityrep.c    19 Nov 2004 23:55:10 -0000
@@ -57,7 +57,7 @@
 
 /******************************************************************/
 static GtkWidget *config_shell;
-static GtkWidget *config_toggle[NUM_CREPORT_COLS];
+static GtkWidget **config_toggle;
 
 static void create_city_report_config_dialog(void);
 static void popup_city_report_config_dialog(void);
@@ -142,7 +142,8 @@
     buf[i][0]='\0';
     if(!spec->show) continue;
 
-    my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width), (spec->func)(pcity));
+    my_snprintf(buf[i], n, "%*s", NEG_VAL(spec->width),
+               (spec->func)(pcity, spec->data));
   }
 }
 
@@ -588,8 +589,8 @@
 *****************************************************************/
 static void create_city_report_dialog(bool make_modal)
 {
-  static char *titles  [NUM_CREPORT_COLS];
-  static char  buf     [NUM_CREPORT_COLS][64];
+  static char **titles;
+  static char (*buf)[64];
 
   GtkWidget *close_command, *scrolled;
   int        i;
@@ -602,9 +603,11 @@
 
   gtk_window_set_title(GTK_WINDOW(city_dialog_shell),_("Cities"));
 
-  for (i=0;i<NUM_CREPORT_COLS;i++)
-    titles[i]=buf[i];
-
+  buf = fc_realloc(buf, NUM_CREPORT_COLS * sizeof(buf[0]));
+  titles = fc_realloc(titles, NUM_CREPORT_COLS * sizeof(titles[0]));
+  for (i = 0; i < NUM_CREPORT_COLS; i++) {
+    titles[i] = buf[i];
+  }
   get_city_table_header(titles, sizeof(buf[0]));
 
   city_list = gtk_clist_new_with_titles(NUM_CREPORT_COLS,titles);
@@ -1432,6 +1435,8 @@
   gtk_widget_show(vbox);
   gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, FALSE, 0);
 
+  config_toggle = fc_realloc(config_toggle,
+                            NUM_CREPORT_COLS * sizeof(*config_toggle));
   for(i=1, spec=city_report_specs+i; i<NUM_CREPORT_COLS; i++, spec++) {
     if (i == NUM_CREPORT_COLS / 2 + 1) {
       vbox = gtk_vbox_new(FALSE, 0);
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.63.2.2
diff -u -r1.63.2.2 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        31 Oct 2004 20:50:03 -0000      1.63.2.2
+++ client/gui-gtk-2.0/cityrep.c        19 Nov 2004 23:55:11 -0000
@@ -138,7 +138,7 @@
 /****************************************************************
  Return text line for the column headers for the city report
 *****************************************************************/
-static void get_city_table_header(char *text[], int n)
+static void get_city_table_header(char **text, int n)
 {
   struct city_report_spec *spec;
   int i;
@@ -728,7 +728,8 @@
   g_value_unset(&value);
 
   sp = &city_report_specs[n];
-  my_snprintf(buf, sizeof(buf), "%*s", NEG_VAL(sp->width), (sp->func)(pcity));
+  my_snprintf(buf, sizeof(buf), "%*s", NEG_VAL(sp->width),
+             (sp->func)(pcity, sp->data));
 
   g_value_init(&value, G_TYPE_STRING);
   g_value_set_string(&value, buf);
@@ -760,8 +761,10 @@
   g_value_unset(&value);
 
   sp = &city_report_specs[n];
-  my_snprintf(buf1, sizeof(buf1), "%*s",NEG_VAL(sp->width),(sp->func)(pcity1));
-  my_snprintf(buf2, sizeof(buf2), "%*s",NEG_VAL(sp->width),(sp->func)(pcity2));
+  my_snprintf(buf1, sizeof(buf1), "%*s", NEG_VAL(sp->width),
+             (sp->func)(pcity1, sp->data));
+  my_snprintf(buf2, sizeof(buf2), "%*s", NEG_VAL(sp->width),
+             (sp->func)(pcity2, sp->data));
 
   return strcmp(buf1, buf2);
 }
@@ -771,13 +774,13 @@
 *****************************************************************/
 static void create_city_report_dialog(bool make_modal)
 {
-  static char *titles [NUM_CREPORT_COLS];
-  static char  buf    [NUM_CREPORT_COLS][64];
+  static char **titles;
+  static char (*buf)[64];
   struct city_report_spec *spec;
 
   GtkWidget *w, *sw, *menubar;
   int i;
-  
+
   gui_dialog_new(&city_dialog_shell, GTK_NOTEBOOK(top_notebook));
   gui_dialog_set_title(city_dialog_shell, _("Cities"));
 
@@ -811,9 +814,11 @@
                                  GTK_RESPONSE_CLOSE);
 
   /* tree view */
-  for (i=0; i<NUM_CREPORT_COLS; i++)
+  buf = fc_realloc(buf, NUM_CREPORT_COLS * sizeof(buf[0]));
+  titles = fc_realloc(titles, NUM_CREPORT_COLS * sizeof(titles[0]));
+  for (i = 0; i < NUM_CREPORT_COLS; i++) {
     titles[i] = buf[i];
-
+  }
   get_city_table_header(titles, sizeof(buf[0]));
 
   city_model = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_INT);
Index: client/gui-xaw/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/cityrep.c,v
retrieving revision 1.58
diff -u -r1.58 cityrep.c
--- client/gui-xaw/cityrep.c    30 Sep 2004 22:16:41 -0000      1.58
+++ client/gui-xaw/cityrep.c    19 Nov 2004 23:55:11 -0000
@@ -62,7 +62,7 @@
 
 /******************************************************************/
 static Widget config_shell;
-static Widget config_toggle[NUM_CREPORT_COLS];
+static Widget *config_toggle;
 
 void create_city_report_config_dialog(void);
 void popup_city_report_config_dialog(void);
@@ -125,7 +125,8 @@
     if(spec->space>0)
       cat_snprintf(text, n, "%*s", spec->space, " ");
 
-    cat_snprintf(text, n, "%*s", spec->width, (spec->func)(pcity));
+    cat_snprintf(text, n, "%*s", spec->width,
+                (spec->func)(pcity, spec->data));
   }
 }
 
@@ -693,6 +694,8 @@
                                             labelWidgetClass, 
                                             config_form, NULL));
 
+  config_toggle = fc_realloc(config_toggle,
+                            NUM_CREPORT_COLS * sizeof(*config_toggle));
   for(i=1, spec=city_report_specs+i; i<NUM_CREPORT_COLS; i++, spec++) {
     my_snprintf(buf, sizeof(buf), "%-32s", spec->explanation);
     above = (i==1)?config_label:config_optlabel;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.152.2.2
diff -u -r1.152.2.2 game.h
--- common/game.h       4 Nov 2004 06:20:32 -0000       1.152.2.2
+++ common/game.h       19 Nov 2004 23:55:11 -0000
@@ -192,7 +192,7 @@
 
   /* values from game.ruleset */
   struct {
-    struct {
+    struct specialist {
       char name[MAX_LEN_NAME];
       int min_size, bonus;
     } specialists[SP_COUNT];

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11091) put specialists into the cityrep dynamically, Jason Short <=