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: Mon, 22 Nov 2004 15:53:19 -0800
Reply-to: rt@xxxxxxxxxxx

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

Here is a new patch.

I solved translation issues by adding translation markers to
cities.ruleset.  Size issues are solved by adding a short_name for the
specialist.  Aside from the changed order of the cityrep fields, the
behavior under the current ruleset should be pretty much unchanged.

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        22 Nov 2004 23:47:36 -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:S");
+    p->title2 = Q_(game.rgame.specialists[sp].short_name);
+    my_snprintf(explanation[sp], sizeof(explanation[sp]),
+               _("Specialists: %s"), _(game.rgame.specialists[sp].name));
+    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        22 Nov 2004 23:47:36 -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.205
diff -u -r1.205 civclient.c
--- client/civclient.c  22 Nov 2004 19:24:18 -0000      1.205
+++ client/civclient.c  22 Nov 2004 23:47:36 -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();
 
@@ -476,6 +475,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.106
diff -u -r1.106 options.c
--- client/options.c    17 Nov 2004 19:21:13 -0000      1.106
+++ client/options.c    22 Nov 2004 23:47:37 -0000
@@ -478,11 +478,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);
@@ -535,6 +530,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/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.422
diff -u -r1.422 packhand.c
--- client/packhand.c   22 Nov 2004 19:31:30 -0000      1.422
+++ client/packhand.c   22 Nov 2004 23:47:37 -0000
@@ -2636,6 +2636,23 @@
 
   specialist_type_iterate(sp) {
     sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
+    if (has_capability("short_spec", aconnection.capability)) {
+      sz_strlcpy(game.rgame.specialists[sp].short_name,
+                packet->specialist_short_name[sp]);
+    } else {
+      switch (sp) {
+      case SP_ELVIS:
+       sz_strlcpy(game.rgame.specialists[sp].short_name, N_("?Elvis:E"));
+       break;
+      case SP_TAXMAN:
+       sz_strlcpy(game.rgame.specialists[sp].short_name, N_("?Taxman:T"));
+       break;
+      case SP_SCIENTIST:
+       sz_strlcpy(game.rgame.specialists[sp].short_name,
+                  N_("?Scientist:S"));
+       break;
+      }
+    }
     game.rgame.specialists[sp].min_size = packet->specialist_min_size[sp];
     game.rgame.specialists[sp].bonus = packet->specialist_bonus[sp];
   } specialist_type_iterate_end;
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    22 Nov 2004 23:47:37 -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.65
diff -u -r1.65 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        31 Oct 2004 20:45:54 -0000      1.65
+++ client/gui-gtk-2.0/cityrep.c        22 Nov 2004 23:47:38 -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    22 Nov 2004 23:47:38 -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/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.195
diff -u -r1.195 capstr.c
--- common/capstr.c     16 Nov 2004 18:09:46 -0000      1.195
+++ common/capstr.c     22 Nov 2004 23:47:38 -0000
@@ -83,6 +83,8 @@
  *
  * "username_info" means that the username is sent in the player_info packet
  *
+ * "short_spec" means that specialists have short names in the ruleset
+ *
  *   - No new manditory capabilities can be added to the release branch; doing
  *     so would break network capability of supposedly "compatible" releases.
  *
@@ -90,7 +92,8 @@
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+2.0 connecting conn_ping_info username_info new_hack"
+#define CAPABILITY "+2.0 connecting conn_ping_info username_info new_hack " \
+                   "short_spec"
 
 void init_our_capability(void)
 {
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.158
diff -u -r1.158 game.h
--- common/game.h       22 Nov 2004 19:24:19 -0000      1.158
+++ common/game.h       22 Nov 2004 23:47:38 -0000
@@ -193,8 +193,9 @@
 
   /* values from game.ruleset */
   struct {
-    struct {
+    struct specialist {
       char name[MAX_LEN_NAME];
+      char short_name[MAX_LEN_NAME];
       int min_size, bonus;
     } specialists[SP_COUNT];
 #define DEFAULT_SPECIALIST SP_ELVIS
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.59
diff -u -r1.59 packets.def
--- common/packets.def  16 Nov 2004 18:09:46 -0000      1.59
+++ common/packets.def  22 Nov 2004 23:47:38 -0000
@@ -972,6 +972,7 @@
 
 PACKET_RULESET_GAME=97;sc,lsend
   STRING specialist_name[SP_COUNT][MAX_LEN_NAME];
+  STRING specialist_short_name[SP_COUNT][MAX_LEN_NAME]; add-cap(short_spec)
   UINT8 specialist_min_size[SP_COUNT];
   UINT8 specialist_bonus[SP_COUNT];
   BOOL changable_tax;
Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.11
diff -u -r1.11 cities.ruleset
--- data/default/cities.ruleset 9 Jun 2004 04:39:13 -0000       1.11
+++ data/default/cities.ruleset 22 Nov 2004 23:47:38 -0000
@@ -22,11 +22,14 @@
 [specialist]
 
 ; Changing the order or names of specialists will break things
-types = "elvis", "scientist", "taxman"
+types = _("elvis"), _("scientist"), _("taxman")
+elvis_short_name = _("?Elvis:E")
 elvis_min_size = 0
 elvis_base_bonus = 2
+scientist_short_name = _("?Scientist:S")
 scientist_min_size = 5
 scientist_base_bonus = 3
+taxman_short_name = _("?Taxman:T")
 taxman_min_size = 5
 taxman_base_bonus = 3
 
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.200
diff -u -r1.200 ruleset.c
--- server/ruleset.c    17 Nov 2004 19:21:14 -0000      1.200
+++ server/ruleset.c    22 Nov 2004 23:47:39 -0000
@@ -2553,9 +2553,13 @@
   }
 
   for (i = 0; i < nval; i++) {
-    const char *name = specialist_names[i];
+    const char *name = specialist_names[i], *short_name;
 
     sz_strlcpy(game.rgame.specialists[i].name, name);
+    short_name
+      = secfile_lookup_str_default(file, name,
+                                  "specialist.%s_short_name", name);
+    sz_strlcpy(game.rgame.specialists[i].short_name, short_name);
     game.rgame.specialists[i].min_size
       = secfile_lookup_int(file, "specialist.%s_min_size", name);
     game.rgame.specialists[i].bonus
@@ -3150,6 +3154,8 @@
 
   specialist_type_iterate(sp) {
     sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
+    sz_strlcpy(misc_p.specialist_short_name[sp],
+              game.rgame.specialists[sp].short_name);
     misc_p.specialist_min_size[sp] = game.rgame.specialists[sp].min_size;
     misc_p.specialist_bonus[sp] = game.rgame.specialists[sp].bonus;
   } specialist_type_iterate_end;

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