Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12926) output_type structure
Home

[Freeciv-Dev] (PR#12926) output_type structure

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12926) output_type structure
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 28 Apr 2005 11:38:09 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12926 >

For further gen-output work we need an output_type structure.  This
patch adds it.  It's pretty straightforward.

-jason

Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.333
diff -u -r1.333 city.c
--- common/city.c       28 Apr 2005 03:47:55 -0000      1.333
+++ common/city.c       28 Apr 2005 18:36:57 -0000
@@ -41,7 +41,18 @@
 struct citystyle *city_styles = NULL;
 
 int city_tiles;
+
+/* One day these values may be read in from the ruleset.  In the meantime
+ * they're just an easy way to access information about each output type. */
 const Output_type_id num_output_types = O_LAST;
+struct output_type output_types[O_LAST] = {
+  {O_FOOD, "Food", "food"},
+  {O_SHIELD, "Shield", "shield"},
+  {O_TRADE, "Trade", "trade"},
+  {O_GOLD, "Gold", "gold"},
+  {O_LUXURY, "Luxury", "luxury"},
+  {O_SCIENCE, "Science", "science"}
+};
 
 /**************************************************************************
   Return TRUE if the given city coordinate pair is "valid"; that is, if it
@@ -223,24 +234,11 @@
 *****************************************************************************/
 const char *get_output_identifier(Output_type_id output)
 {
-  switch (output) {
-  case O_FOOD:
-    return "food";
-  case O_SHIELD:
-    return "shield";
-  case O_TRADE:
-    return "trade";
-  case O_GOLD:
-    return "gold";
-  case O_LUXURY:
-    return "luxury";
-  case O_SCIENCE:
-    return "science";
-  case O_LAST:
-    break;
+  if (output < 0 || output >= O_LAST) {
+    assert(0);
+    return NULL;
   }
-  die("Unknown output type in get_output_id: %d", output);
-  return NULL;
+  return output_types[output].id;
 }
 
 /****************************************************************************
@@ -249,24 +247,11 @@
 *****************************************************************************/
 const char *get_output_name(Output_type_id output)
 {
-  switch (output) {
-  case O_FOOD:
-    return _("Food");
-  case O_SHIELD:
-    return _("Shield");
-  case O_TRADE:
-    return _("Trade");
-  case O_GOLD:
-    return _("Gold");
-  case O_LUXURY:
-    return _("Luxury");
-  case O_SCIENCE:
-    return _("Science");
-  case O_LAST:
-    break;
+  if (output < 0 || output >= O_LAST) {
+    assert(0);
+    return NULL;
   }
-  die("Unknown output type in get_output_name: %d", output);
-  return NULL;
+  return _(output_types[output].name);
 }
 
 /**************************************************************************
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.207
diff -u -r1.207 city.h
--- common/city.h       26 Apr 2005 05:23:58 -0000      1.207
+++ common/city.h       28 Apr 2005 18:36:57 -0000
@@ -136,6 +136,12 @@
 }
 
 
+struct output_type {
+  int index;
+  const char *name; /* Untranslated name */
+  const char *id; /* Identifier string (for rulesets, etc.) */
+};
+
 enum choice_type { CT_NONE = 0, CT_BUILDING = 0, CT_NONMIL, CT_ATTACKER,
                    CT_DEFENDER, CT_LAST };
 
@@ -326,6 +332,7 @@
 
 extern struct citystyle *city_styles;
 extern const Output_type_id num_output_types;
+extern struct output_type output_types[];
 
 /* get 'struct city_list' and related functions: */
 #define SPECLIST_TAG city
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.20
diff -u -r1.20 fc_types.h
--- common/fc_types.h   26 Apr 2005 05:23:58 -0000      1.20
+++ common/fc_types.h   28 Apr 2005 18:36:57 -0000
@@ -35,7 +35,7 @@
 #define MAX_LEN_VET_SHORT_NAME 8
 #define MAX_VET_LEVELS 10
 
-enum output_type {
+enum output_type_id {
   O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
 };
 #define O_COUNT num_output_types
@@ -45,7 +45,7 @@
 typedef int Terrain_type_id;
 typedef int Specialist_type_id;
 typedef int Impr_Type_id;
-typedef enum output_type Output_type_id;
+typedef enum output_type_id Output_type_id;
 typedef enum unit_activity Activity_type_id;
 typedef int Nation_Type_id;
 typedef int Team_Type_id;
@@ -56,6 +56,7 @@
 struct player;
 struct tile;
 struct unit;
+struct output_type;
 
 /* Changing these will break network compatibility. */
 #define SP_MAX 20

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12926) output_type structure, Jason Short <=