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

trunk revision 12972
S2_1 revision 12973

As S2_1 required a number of trivial changes, here's the final patch for
the record (after 12972, making 12973).  In particular, where translated
strings already exist, they are painstakingly maintained.

Index: server/generator/mapgen.c
===================================================================
--- server/generator/mapgen.c   (revision 12972)
+++ server/generator/mapgen.c   (working copy)
@@ -303,8 +303,8 @@
 **************************************************************************/
 static struct terrain *pick_ocean(int depth)
 {
-  /* FIXME: get_flag_terrain may return NULL if there is no match. */
-  struct terrain *best_terrain = get_flag_terrain(TER_OCEANIC);
+  /* FIXME: pick_terrain_by_flag may return NULL if there is no match. */
+  struct terrain *best_terrain = pick_terrain_by_flag(TER_OCEANIC);
   int best_match = abs(depth - best_terrain->property[MG_OCEAN_DEPTH]);
 
   terrain_type_iterate(pterrain) {
@@ -980,9 +980,9 @@
 
            if (!terrain_has_flag(pterrain, TER_CAN_HAVE_RIVER)) {
              /* We have to change the terrain to put a river here. */
-             /* FIXME: get_flag_terrain may return NULL
+             /* FIXME: pick_terrain_by_flag may return NULL
               * if there is no match. */
-             pterrain = get_flag_terrain(TER_CAN_HAVE_RIVER);
+             pterrain = pick_terrain_by_flag(TER_CAN_HAVE_RIVER);
              tile_set_terrain(tile1, pterrain);
            }
            tile_set_special(tile1, S_RIVER);
@@ -1109,7 +1109,7 @@
 
   terrain_type_iterate(pterrain) {
     freelog(loglevel, "%20s : %4d %d%%  ",
-           get_name(pterrain), terrain_count[pterrain->index],
+           pterrain->name_rule, terrain_count[pterrain->index],
            (terrain_count[pterrain->index] * 100 + 50) / total);
   } terrain_type_iterate_end;
 }
Index: server/scripting/api_gen.c
===================================================================
--- server/scripting/api_gen.c  (revision 12972)
+++ server/scripting/api_gen.c  (working copy)
@@ -550,14 +550,14 @@
  return 1;
 }
 
-/* get function: name_orig of class  Terrain */
-static int tolua_get_Terrain_Terrain_name_orig(lua_State* tolua_S)
+/* get function: name_rule of class  Terrain */
+static int tolua_get_Terrain_Terrain_name_rule(lua_State* tolua_S)
 {
   Terrain* self = (Terrain*)  tolua_tousertype(tolua_S,1,0);
 #ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 
'name_orig'",NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 
'name_rule'",NULL);
 #endif
- tolua_pushstring(tolua_S,(const char*)self->name_orig);
+ tolua_pushstring(tolua_S,(const char*)self->name_rule);
  return 1;
 }
 
@@ -1616,7 +1616,7 @@
  tolua_endmodule(tolua_S);
  tolua_cclass(tolua_S,"Terrain","Terrain","",NULL);
  tolua_beginmodule(tolua_S,"Terrain");
- tolua_variable(tolua_S,"name",tolua_get_Terrain_Terrain_name_orig,NULL);
+ tolua_variable(tolua_S,"name",tolua_get_Terrain_Terrain_name_rule,NULL);
  tolua_endmodule(tolua_S);
  
tolua_function(tolua_S,"methods_player_num_cities",tolua_api_methods_player_num_cities00);
  
tolua_function(tolua_S,"methods_player_num_units",tolua_api_methods_player_num_units00);
Index: server/scripting/api.pkg
===================================================================
--- server/scripting/api.pkg    (revision 12972)
+++ server/scripting/api.pkg    (working copy)
@@ -100,7 +100,7 @@
 };
 
 struct Terrain {
-  const char *name_orig @ name;
+  const char *name_rule @ name;
 };
 
 
Index: server/scripting/api_find.c
===================================================================
--- server/scripting/api_find.c (revision 12972)
+++ server/scripting/api_find.c (working copy)
@@ -147,15 +147,15 @@
 **************************************************************************/
 Terrain *api_find_terrain(int terrain_id)
 {
-  return get_terrain(terrain_id);
+  return get_terrain_by_number(terrain_id);
 }
 
 /**************************************************************************
-  Return the tech type with the given name_orig.
+  Return the terrain with the given name_orig.
 **************************************************************************/
 Terrain *api_find_terrain_by_name(const char *name_orig)
 {
-  struct terrain *pterrain = get_terrain_by_name(name_orig);
+  struct terrain *pterrain = get_terrain_by_rule_name(name_orig);
 
   return pterrain;
 }
Index: server/cityturn.c
===================================================================
--- server/cityturn.c   (revision 12972)
+++ server/cityturn.c   (working copy)
@@ -770,7 +770,7 @@
                                 "%s terrain is required.  Postponing..."),
                               pcity->name,
                               get_impr_name_ex(pcity, building->index),
-                              get_name(preq->source.value.terrain));
+                              
terrain_name_translation(preq->source.value.terrain));
              script_signal_emit("building_cant_be_built", 3,
                                 API_TYPE_BUILDING_TYPE, building,
                                 API_TYPE_CITY, pcity,
Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 12972)
+++ server/ruleset.c    (working copy)
@@ -613,7 +613,7 @@
 }
 
 /**************************************************************************
-  Look up a terrain name in the tile_types array and return its index.
+  Look up a rule (original) terrain name and return its pointer.
 **************************************************************************/
 static struct terrain *lookup_terrain(char *name, struct terrain *tthis)
 {
@@ -624,15 +624,16 @@
     return (tthis);
   }
 
+  /* get_terrain_by_rule_name plus error */
   terrain_type_iterate(pterrain) {
-    if (0 == strcmp(name, pterrain->name)) {
+    if (0 == strcmp(name, pterrain->name_rule)) {
       return pterrain;
     }
   } terrain_type_iterate_end;
 
   /* TRANS: message for an obscure ruleset error. */
   freelog(LOG_ERROR, _("Unknown terrain %s in entry %s."),
-         name, tthis->name);
+         name, tthis->name_rule);
   return T_NONE;
 }
 
@@ -1396,11 +1397,11 @@
     char *name = secfile_lookup_str(file, "%s.name",
                                    sec[pterrain->index]);
 
-    name_strlcpy(pterrain->name_orig, name);
-    if (0 == strcmp(pterrain->name_orig, "unused")) {
-      pterrain->name_orig[0] = '\0';
+    name_strlcpy(pterrain->name_rule, name);
+    if (0 == strcmp(pterrain->name_rule, "unused")) {
+      pterrain->name_rule[0] = '\0';
     }
-    pterrain->name = pterrain->name_orig;
+    pterrain->name_translated = NULL;
   } terrain_type_iterate_end;
 
   free(sec);
@@ -1412,11 +1413,11 @@
     char *name = secfile_lookup_str(file, "%s.name",
                                    sec[presource->index]);
 
-    name_strlcpy(presource->name_orig, name);
-    if (0 == strcmp(presource->name_orig, "unused")) {
-      presource->name_orig[0] = '\0';
+    name_strlcpy(presource->name_rule, name);
+    if (0 == strcmp(presource->name_rule, "unused")) {
+      presource->name_rule[0] = '\0';
     }
-    presource->name = NULL;
+    presource->name_translated = NULL;
   } resource_type_iterate_end;
 
   free(sec);
@@ -1500,21 +1501,27 @@
 
     pterrain->identifier
       = secfile_lookup_str(file, "%s.identifier", tsec[i])[0];
+    if ('\0' == pterrain->identifier) {
+      /* TRANS: message for an obscure ruleset error. */
+      freelog(LOG_FATAL, _("[%s] missing identifier."),
+               tsec[i]);
+      exit(EXIT_FAILURE);
+    }
+    if (UNKNOWN_TERRAIN_IDENTIFIER == pterrain->identifier) {
+      /* TRANS: message for an obscure ruleset error. */
+      freelog(LOG_FATAL, _("'%c' cannot be used as a terrain identifier;"
+               " it is reserved."),
+               pterrain->identifier);
+      exit(EXIT_FAILURE);
+    }
     for (j = T_FIRST; j < i; j++) {
-      if (pterrain->identifier == get_terrain(j)->identifier) {
-       freelog(LOG_FATAL,
-               /* TRANS: message for an obscure ruleset error. */
-               _("Terrains %s and %s have the same identifier."),
-               pterrain->name, get_terrain(j)->name);
+      if (pterrain->identifier == get_terrain_by_number(j)->identifier) {
+       /* TRANS: message for an obscure ruleset error. */
+       freelog(LOG_FATAL, _("Terrains %s and %s have the same identifier."),
+               pterrain->name_rule, get_terrain_by_number(j)->name_rule);
        exit(EXIT_FAILURE);
       }
     }
-    if (pterrain->identifier == UNKNOWN_TERRAIN_IDENTIFIER) {
-      /* TRANS: message for an obscure ruleset error. */
-      freelog(LOG_FATAL, _("'%c' cannot be used as a terrain identifier; "
-                          "it is reserved."), UNKNOWN_TERRAIN_IDENTIFIER);
-      exit(EXIT_FAILURE);
-    }
 
     pterrain->movement_cost
       = secfile_lookup_int(file, "%s.movement_cost", tsec[i]);
@@ -1531,9 +1538,11 @@
     pterrain->resources = fc_calloc(nval + 1,
                                    sizeof(*pterrain->resources));
     for (j = 0; j < nval; j++) {
-      pterrain->resources[j] = get_resource_by_name_orig(res[j]);
+      pterrain->resources[j] = get_resource_by_rule_name(res[j]);
       if (!pterrain->resources[j]) {
-       freelog(LOG_FATAL, "Could not find resource \"%s\".", res[j]);
+       /* TRANS: message for an obscure ruleset error. */
+       freelog(LOG_FATAL, _("[%s] could not find resource \"%s\"."),
+               tsec[i], res[j]);
        exit(EXIT_FAILURE);
       }
     }
@@ -1597,7 +1606,7 @@
       if (flag == TER_LAST) {
        /* TRANS: message for an obscure ruleset error. */
        freelog(LOG_FATAL, _("Terrain %s has unknown flag %s"),
-               pterrain->name, sval);
+               pterrain->name_rule, sval);
        exit(EXIT_FAILURE);
       } else {
        BV_SET(pterrain->flags, flag);
@@ -1625,7 +1634,6 @@
   resource_type_iterate(presource) {
     const int i = presource->index;
 
-    presource->name = Q_(presource->name_orig);
     output_type_iterate (o) {
       presource->output[o] =
          secfile_lookup_int_default(file, 0, "%s.%s", rsec[i],
@@ -1638,17 +1646,24 @@
 
     presource->identifier
       = secfile_lookup_str(file, "%s.identifier", rsec[i])[0];
-    if (presource->identifier == RESOURCE_NULL_IDENTIFIER) {
-      freelog(LOG_FATAL, "Resource %s can't have '%c' as an identifier,"
-             " it is reserved.", presource->name, presource->identifier);
+    if ('\0' == presource->identifier) {
+      /* TRANS: message for an obscure ruleset error. */
+      freelog(LOG_FATAL, _("[%s] missing identifier."),
+               rsec[i]);
       exit(EXIT_FAILURE);
     }
+    if (RESOURCE_NULL_IDENTIFIER == presource->identifier) {
+      /* TRANS: message for an obscure ruleset error. */
+      freelog(LOG_FATAL, _("[%s] cannot use '%c' as an identifier;"
+               " it is reserved."),
+               rsec[i], presource->identifier);
+      exit(EXIT_FAILURE);
+    }
     for (j = 0; j < i; j++) {
-      if (presource->identifier == get_resource(j)->identifier) {
-       freelog(LOG_FATAL,
-               /* TRANS: message for an obscure ruleset error. */
-               _("Resources %s and %s have the same identifier."),
-               presource->name, get_resource(j)->name);
+      if (presource->identifier == get_resource_by_number(j)->identifier) {
+       /* TRANS: message for an obscure ruleset error. */
+       freelog(LOG_FATAL, _("Resources %s and %s have the same identifier."),
+               presource->name_rule, get_resource_by_number(j)->name_rule);
        exit(EXIT_FAILURE);
       }
     }
@@ -1956,7 +1971,7 @@
                * However this is not a problem because we take care of rivers
                * separately.
                */
-             if (mystrcasecmp(name, pterrain->name) == 0) {
+             if (0 == mystrcasecmp(name, pterrain->name_rule)) {
                city_names[j].terrain[pterrain->index] = setting;
                handled = TRUE;
                break;
@@ -2777,7 +2792,7 @@
 
     packet.id = i;
 
-    sz_strlcpy(packet.name_orig, pterrain->name_orig);
+    sz_strlcpy(packet.name_orig, pterrain->name_rule);
     sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
     sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
 
@@ -2839,7 +2854,7 @@
 
     packet.id = i;
 
-    sz_strlcpy(packet.name_orig, presource->name_orig);
+    sz_strlcpy(packet.name_orig, presource->name_rule);
     sz_strlcpy(packet.graphic_str, presource->graphic_str);
     sz_strlcpy(packet.graphic_alt, presource->graphic_alt);
 
Index: server/unittools.c
===================================================================
--- server/unittools.c  (revision 12972)
+++ server/unittools.c  (working copy)
@@ -2118,7 +2118,8 @@
   if (!is_native_terrain(punit, map_get_player_tile(ptile, pplayer)->terrain)) 
{
     notify_player(pplayer, ptile, E_BAD_COMMAND,
                      _("This unit cannot paradrop into %s."),
-                       get_name(map_get_player_tile(ptile, pplayer)->terrain));
+                     terrain_name_translation(
+                        map_get_player_tile(ptile, pplayer)->terrain));
     return FALSE;
   }
 
@@ -2149,7 +2150,8 @@
     notify_player(pplayer, ptile, E_UNIT_LOST,
                      _("Your %s paradropped into the %s "
                        "and was lost."),
-                     unit_type(punit)->name, get_name(ptile->terrain));
+                     unit_type(punit)->name,
+                     terrain_name_translation(ptile->terrain));
     server_remove_unit(punit);
     return TRUE;
   }
Index: server/sanitycheck.c
===================================================================
--- server/sanitycheck.c        (revision 12972)
+++ server/sanitycheck.c        (working copy)
@@ -49,8 +49,8 @@
     if (!(check)) {                                                    \
       freelog(LOG_ERROR, "Failed sanity check at %s (%d, %d): "                
\
               "%s (%s:%d)", ptile->city ? ptile->city->name            \
-              : get_name(ptile->terrain), ptile->x, ptile->y, #check,  \
-              __FILE__,__LINE__);                                      \
+              : ptile->terrain->name_rule, ptile->x, ptile->y,         \
+              #check, __FILE__,__LINE__);                              \
     }                                                                  \
   } while(0)
 
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 12972)
+++ server/savegame.c   (working copy)
@@ -249,6 +249,7 @@
 ****************************************************************************/
 static struct terrain *char2terrain(char ch)
 {
+  /* get_terrain_by_identifier plus fatal error */
   if (ch == UNKNOWN_TERRAIN_IDENTIFIER) {
     return T_UNKNOWN;
   }
@@ -3992,7 +3993,7 @@
       if (!ferry && !can_unit_exist_at_tile(punit, punit->tile)) {
         freelog(LOG_ERROR, _("Removing %s's unferried %s in %s at (%d, %d)"),
                 pplayer->name, unit_name(punit->type),
-                get_name(punit->tile->terrain),
+                terrain_name_translation(punit->tile->terrain),
                 TILE_XY(punit->tile));
         bounce_unit(punit, TRUE);
       }
Index: common/combat.c
===================================================================
--- common/combat.c     (revision 12972)
+++ common/combat.c     (working copy)
@@ -604,7 +604,7 @@
             " units) on %s at (%d,%d). ", unit_owner(attacker)->name,
             unit_type(attacker)->name, unit_owner(punit)->name,
             unit_type(punit)->name, unit_list_size(ptile->units), 
-            get_name(ptile->terrain), ptile->x, ptile->y);
+            terrain_name_translation(ptile->terrain), ptile->x, ptile->y);
   }
 
   return bestdef;
Index: common/tile.c
===================================================================
--- common/tile.c       (revision 12972)
+++ common/tile.c       (working copy)
@@ -441,14 +441,14 @@
   static char s[256];
   bool first;
 
-  sz_strlcpy(s, ptile->terrain->name);
+  sz_strlcpy(s, terrain_name_translation(ptile->terrain));
   if (tile_has_special(ptile, S_RIVER)) {
     sz_strlcat(s, "/");
     sz_strlcat(s, get_special_name(S_RIVER));
   }
 
   if (ptile->resource) {
-    cat_snprintf(s, sizeof(s), " (%s)", ptile->resource->name);
+    cat_snprintf(s, sizeof(s), " (%s)", 
resource_name_translation(ptile->resource));
   }
 
   first = TRUE;
Index: common/terrain.c
===================================================================
--- common/terrain.c    (revision 12972)
+++ common/terrain.c    (working copy)
@@ -64,9 +64,26 @@
 }
 
 /****************************************************************************
+  Return the terrain type matching the identifier, or T_UNKNOWN if none 
matches.
+****************************************************************************/
+struct terrain *get_terrain_by_identifier(const char identifier)
+{
+  if (UNKNOWN_TERRAIN_IDENTIFIER == identifier) {
+    return T_UNKNOWN;
+  }
+  terrain_type_iterate(pterrain) {
+    if (pterrain->identifier == identifier) {
+      return pterrain;
+    }
+  } terrain_type_iterate_end;
+
+  return T_UNKNOWN;
+}
+
+/****************************************************************************
   Return the terrain for the given terrain index.
 ****************************************************************************/
-struct terrain *get_terrain(Terrain_type_id type)
+struct terrain *get_terrain_by_number(Terrain_type_id type)
 {
   if (type < 0 || type >= game.control.terrain_count) {
     /* This isn't an error; some T_UNKNOWN callers depend on it. */
@@ -78,10 +95,10 @@
 /****************************************************************************
   Return the terrain type matching the name, or T_UNKNOWN if none matches.
 ****************************************************************************/
-struct terrain *get_terrain_by_name(const char *name)
+struct terrain *get_terrain_by_rule_name(const char *name)
 {
   terrain_type_iterate(pterrain) {
-    if (0 == strcmp(pterrain->name, name)) {
+    if (0 == strcmp(pterrain->name_rule, name)) {
       return pterrain;
     }
   } terrain_type_iterate_end;
@@ -90,12 +107,31 @@
 }
 
 /****************************************************************************
-  Return the name of the terrain.
+  Return the terrain type matching the name, or T_UNKNOWN if none matches.
 ****************************************************************************/
-const char *get_name(const struct terrain *pterrain)
+struct terrain *get_terrain_by_translated_name(const char *name)
 {
+  terrain_type_iterate(pterrain) {
+    if (0 == strcmp(terrain_name_translation(pterrain), name)) {
+      return pterrain;
+    }
+  } terrain_type_iterate_end;
+
+  return T_UNKNOWN;
+}
+
+/****************************************************************************
+  Return the translated name of the terrain.
+****************************************************************************/
+const char *terrain_name_translation(struct terrain *pterrain)
+{
   SANITY_CHECK_TERRAIN(pterrain);
-  return pterrain->name;
+  if (NULL == pterrain->name_translated) {
+    /* delayed (unified) translation */
+    pterrain->name_translated = ('\0' == pterrain->name_rule[0])
+                          ? pterrain->name_rule : Q_(pterrain->name_rule);
+  }
+  return pterrain->name_translated;
 }
 
 /****************************************************************************
@@ -131,8 +167,9 @@
 /****************************************************************************
   Return a random terrain that has the specified flag.  Returns T_UNKNOWN if
   there is no matching terrain.
+  FIXME: currently called only by mapgen.c, move there and check error.
 ****************************************************************************/
-struct terrain *get_flag_terrain(enum terrain_flag_id flag)
+struct terrain *pick_terrain_by_flag(enum terrain_flag_id flag)
 {
   bool has_flag[T_COUNT];
   int count = 0;
@@ -153,7 +190,7 @@
     }
   } terrain_type_iterate_end;
 
-  die("Reached end of get_flag_terrain!");
+  die("Reached end of pick_terrain_by_flag!");
   return T_UNKNOWN;
 }
 
@@ -171,7 +208,7 @@
 /****************************************************************************
   Return the resource for the given resource index.
 ****************************************************************************/
-struct resource *get_resource(Resource_type_id type)
+struct resource *get_resource_by_number(Resource_type_id type)
 {
   if (type < 0 || type >= game.control.resource_count) {
     /* This isn't an error; some callers depend on it. */
@@ -183,10 +220,10 @@
 /****************************************************************************
   Return the resource type matching the name, or T_UNKNOWN if none matches.
 ****************************************************************************/
-struct resource *get_resource_by_name_orig(const char *name_orig)
+struct resource *get_resource_by_rule_name(const char *name_orig)
 {
   resource_type_iterate(presource) {
-    if (0 == strcmp(presource->name_orig, name_orig)) {
+    if (0 == strcmp(presource->name_rule, name_orig)) {
       return presource;
     }
   } resource_type_iterate_end;
@@ -194,7 +231,20 @@
   return NULL;
 }
 
+/****************************************************************************
+  Return the translated name of the resource.
+****************************************************************************/
+const char *resource_name_translation(const struct resource *presource)
+{
+  if (NULL == presource->name_translated) {
+    /* delayed (unified) translation, ignore warning */
+    presource->name_translated = ('\0' == presource->name_rule[0])
+                          ? presource->name_rule : Q_(presource->name_rule);
+  }
+  return presource->name_translated;
+}
 
+
 /****************************************************************************
   This iterator behaves like adjc_iterate or cardinal_adjc_iterate depending
   on the value of card_only.
Index: common/terrain.h
===================================================================
--- common/terrain.h    (revision 12972)
+++ common/terrain.h    (working copy)
@@ -99,13 +99,14 @@
  */
 struct terrain {
   int index;
-  const char *name; /* Translated string - doesn't need freeing. */
-  char name_orig[MAX_LEN_NAME];        /* untranslated copy */
-  char graphic_str[MAX_LEN_NAME];
-  char graphic_alt[MAX_LEN_NAME];
+  const char *name_translated;         /* string doesn't need freeing */
+  char name_rule[MAX_LEN_NAME];                /* original name for 
comparisons */
+  char graphic_str[MAX_LEN_NAME];      /* add tile_ prefix */
+  char graphic_alt[MAX_LEN_NAME];      /* TODO: retire, never used! */
 
-  /* Server-only. */
   char identifier; /* Single-character identifier used in savegames. */
+#define WATER_TERRAIN_IDENTIFIER ' '
+#define GLACIER_TERRAIN_IDENTIFIER 'a'
 #define UNKNOWN_TERRAIN_IDENTIFIER 'u'
 
   int movement_cost;
@@ -154,12 +155,12 @@
 
 struct resource {
   int index;
-  const char *name; /* Translated string - doesn't need freeing. */
-  char name_orig[MAX_LEN_NAME];
+  const char *name_translated;         /* string doesn't need freeing */
+  char name_rule[MAX_LEN_NAME];                /* original name for 
comparisons */
+  char graphic_str[MAX_LEN_NAME];
+  char graphic_alt[MAX_LEN_NAME];
   char identifier; /* server-only, same as terrain->identifier */
   int output[O_MAX]; /* Amount added by this resource. */
-  char graphic_str[MAX_LEN_NAME];
-  char graphic_alt[MAX_LEN_NAME];
 };
 
 #define RESOURCE_NULL_IDENTIFIER ' '
@@ -173,16 +174,19 @@
 void terrains_init(void);
 
 /* General terrain accessor functions. */
-struct terrain *get_terrain(Terrain_type_id type);
-struct terrain *get_terrain_by_name(const char *name);
-const char *get_name(const struct terrain *pterrain);
+struct terrain *get_terrain_by_identifier(const char identifier);
+struct terrain *get_terrain_by_number(Terrain_type_id type);
+struct terrain *get_terrain_by_rule_name(const char *name);
+struct terrain *get_terrain_by_translated_name(const char *name);
+const char *terrain_name_translation(struct terrain *pterrain);
 enum terrain_flag_id terrain_flag_from_str(const char *s);
 #define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
-struct terrain *get_flag_terrain(enum terrain_flag_id flag);
+struct terrain *pick_terrain_by_flag(enum terrain_flag_id flag);
 void terrains_free(void);
 
-struct resource *get_resource(Resource_type_id id);
-struct resource *get_resource_by_name_orig(const char *name);
+struct resource *get_resource_by_number(Resource_type_id id);
+struct resource *get_resource_by_rule_name(const char *name);
+const char *resource_name_translation(const struct resource *presource);
 
 /* Functions to operate on a general terrain type. */
 bool is_terrain_near_tile(const struct tile *ptile,
@@ -237,7 +241,7 @@
   Terrain_type_id _index;                                                  \
                                                                            \
   for (_index = T_FIRST; _index < T_COUNT; _index++) {                     \
-    struct terrain *pterrain = get_terrain(_index);
+    struct terrain *pterrain = get_terrain_by_number(_index);
     
 
 #define terrain_type_iterate_end                                            \
@@ -249,7 +253,7 @@
   Resource_type_id _index;                                                 \
                                                                            \
   for (_index = R_FIRST; _index < R_COUNT; _index++) {                     \
-    struct resource *presource = get_resource(_index);
+    struct resource *presource = get_resource_by_number(_index);
     
 
 #define resource_type_iterate_end                                           \
Index: common/game.c
===================================================================
--- common/game.c       (revision 12972)
+++ common/game.c       (working copy)
@@ -603,16 +603,9 @@
     tthis->name = Q_(tthis->name_orig);
   } impr_type_iterate_end;
 
-  terrain_type_iterate(tthis) {
-    tthis->name = ((strcmp(tthis->name_orig, "") != 0)
-                          ? Q_(tthis->name_orig) : "");
-  } terrain_type_iterate_end;
+  /* terrain_name_translation now handled in terrain.c */
+  /* resource_name_translation now handled in terrain.c */
 
-  resource_type_iterate (tthis) {
-    tthis->name = (*(tthis->name_orig)) ? Q_(tthis->name_orig) : "";
-  } resource_type_iterate_end;
-
-
   government_iterate(tthis) {
     int j;
 
Index: common/requirements.c
===================================================================
--- common/requirements.c       (revision 12972)
+++ common/requirements.c       (working copy)
@@ -128,7 +128,7 @@
     }
     break;
   case REQ_TERRAIN:
-    source.value.terrain = get_terrain_by_name(value);
+    source.value.terrain = get_terrain_by_rule_name(value);
     if (source.value.terrain != T_UNKNOWN) {
       return source;
     }
@@ -209,7 +209,7 @@
     source.value.special = value;
     return source;
   case REQ_TERRAIN:
-    source.value.terrain = get_terrain(value);
+    source.value.terrain = get_terrain_by_number(value);
     return source;
   case REQ_NATION:
     source.value.nation = get_nation_by_idx(value);
@@ -1014,7 +1014,7 @@
     mystrlcat(buf, get_special_name(psource->value.special), bufsz);
     break;
   case REQ_TERRAIN:
-    mystrlcat(buf, get_name(psource->value.terrain), bufsz);
+    mystrlcat(buf, terrain_name_translation(psource->value.terrain), bufsz);
     break;
   case REQ_NATION:
     mystrlcat(buf, get_nation_name(psource->value.nation), bufsz);
Index: manual/civmanual.c
===================================================================
--- manual/civmanual.c  (revision 12972)
+++ manual/civmanual.c  (working copy)
@@ -228,13 +228,13 @@
       terrain_type_iterate(pterrain) {
         const struct resource **r;
 
-        if (pterrain->name[0] == '\0') {
+        if ('\0' == pterrain->name_rule[0]) {
           /* Must be a disabled piece of terrain */
           continue;
         }
 
         fprintf(doc, "<tr><td>" IMAGE_BEGIN "%s" IMAGE_END "</td><td>%s</td>",
-                pterrain->graphic_str, get_name(pterrain));
+                pterrain->graphic_str, terrain_name_translation(pterrain));
         fprintf(doc, "<td>%d/%d/%d</td>\n",
                 pterrain->output[O_FOOD], pterrain->output[O_SHIELD],
                 pterrain->output[O_TRADE]);
@@ -243,8 +243,11 @@
         for (r = pterrain->resources; *r; r++) {
           fprintf(doc, "<tr><td>" IMAGE_BEGIN "%s" IMAGE_END "</td><td>%s</td>"
                   "<td align=\"right\">%d/%d/%d</td></tr>\n",
-                  (*r)->graphic_str, (*r)->name, (*r)->output[O_FOOD],
-                  (*r)->output[O_SHIELD], (*r)->output[O_TRADE]);
+                  (*r)->graphic_str,
+                  resource_name_translation(*r),
+                  (*r)->output[O_FOOD],
+                  (*r)->output[O_SHIELD],
+                  (*r)->output[O_TRADE]);
         }
         fprintf(doc, "</table></td>\n");
 
@@ -259,7 +262,8 @@
           fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
         } else {
           fprintf(doc, "<tr><td>%s</td><td align=\"right\">(%d)</td></tr>\n",
-                  get_name(pterrain->irrigation_result), 
pterrain->irrigation_time);
+                  terrain_name_translation(pterrain->irrigation_result),
+                  pterrain->irrigation_time);
         }
         if (pterrain->mining_result == pterrain) {
           fprintf(doc, "<tr><td>+%d P</td><td 
align=\"right\">(%d)</td></tr>\n",
@@ -268,12 +272,14 @@
           fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
         } else {
           fprintf(doc, "<tr><td>%s</td><td align=\"right\">(%d)</td></tr>\n",
-                  get_name(pterrain->mining_result), pterrain->mining_time);
+                  terrain_name_translation(pterrain->mining_result),
+                  pterrain->mining_time);
         }
         fprintf(doc, "<tr><td>+%d T</td><td align=\"right\">(%d)</td></tr>\n",
                 pterrain->road_trade_incr, pterrain->road_time);
         fprintf(doc, "<tr><td>%s</td><td 
align=\"right\">(%d)</td></tr>\n</table></td>\n",
-                get_name(pterrain->transform_result), 
pterrain->transform_time);
+                terrain_name_translation(pterrain->transform_result),
+                pterrain->transform_time);
 
         fprintf(doc, "<td align=\"center\">%d / %d / %d / %d / 
%d</td></tr>\n\n",
                 pterrain->airbase_time, pterrain->fortress_time, 
pterrain->rail_time,
Index: client/colors_common.c
===================================================================
--- client/colors_common.c      (revision 12972)
+++ client/colors_common.c      (working copy)
@@ -172,12 +172,12 @@
                                const struct terrain *pterrain)
 {
   struct rgbcolor *rgb
-    = hash_lookup_data(colors->terrain_hash, pterrain->name_orig);
+    = hash_lookup_data(colors->terrain_hash, pterrain->name_rule);
 
   if (rgb) {
     colors->terrain_colors[pterrain->index] = *rgb;
   } else {
-    freelog(LOG_ERROR, "No color for terrain '%s'", pterrain->name);
+    freelog(LOG_ERROR, "No color for terrain '%s'", pterrain->name_rule);
     /* Fallback: the color remains black. */
   }
 }
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
--- client/gui-gtk-2.0/helpdlg.c        (revision 12972)
+++ client/gui-gtk-2.0/helpdlg.c        (working copy)
@@ -1050,7 +1050,7 @@
       const struct resource **r;
 
       for (r = pterrain->resources; *r; r++) {
-       sprintf (buf + strlen (buf), " %s,", _((*r)->name));
+       sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
       }
       buf[strlen (buf) - 1] = '.';
     } else {
@@ -1080,7 +1080,7 @@
       }
     } else if (pterrain->irrigation_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->irrigation_result->name,
+             terrain_name_translation(pterrain->irrigation_result),
              pterrain->irrigation_time);
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[2][4]), buf);
@@ -1094,14 +1094,14 @@
       }
     } else if (pterrain->mining_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->mining_result->name,
+             terrain_name_translation(pterrain->mining_result),
              pterrain->mining_time);
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[3][1]), buf);
 
     if (pterrain->transform_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->transform_result->name,
+             terrain_name_translation(pterrain->transform_result),
              pterrain->transform_time);
     } else {
       strcpy(buf, "n/a");
@@ -1174,7 +1174,7 @@
     help_update_tech(pitem, top, find_tech_by_name(top));
     break;
   case HELP_TERRAIN:
-    help_update_terrain(pitem, top, get_terrain_by_name(top));
+    help_update_terrain(pitem, top, get_terrain_by_translated_name(top));
     break;
   case HELP_GOVERNMENT:
     help_update_government(pitem, top, find_government_by_name(top));
Index: client/gui-xaw/helpdlg.c
===================================================================
--- client/gui-xaw/helpdlg.c    (revision 12972)
+++ client/gui-xaw/helpdlg.c    (working copy)
@@ -981,7 +981,7 @@
     if (*(pterrain->resources)) {
       const struct resource **r;
       for (r = pterrain->resources; *r; r++) {
-       sprintf (buf + strlen (buf), " %s,", _((*r)->name));
+       sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
       }
       buf[strlen (buf) - 1] = '.';
     } else {
@@ -1010,7 +1010,7 @@
       }
     } else if (pterrain->irrigation_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->irrigation_result->name,
+             terrain_name_translation(pterrain->irrigation_result),
              pterrain->irrigation_time);
     }
     xaw_set_label(help_terrain_irrigation_result_time_data, buf);
@@ -1024,14 +1024,14 @@
       }
     } else if (pterrain->mining_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->mining_result->name,
+             terrain_name_translation(pterrain->mining_result),
              pterrain->mining_time);
     }
     xaw_set_label (help_terrain_mining_result_time_data, buf);
 
     if (pterrain->transform_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->transform_result->name,
+             terrain_name_translation(pterrain->transform_result),
              pterrain->transform_time);
     } else {
       strcpy(buf, _("n/a"));
@@ -1091,7 +1091,7 @@
     help_update_tech(pitem, top, find_tech_by_name(top));
     break;
   case HELP_TERRAIN:
-    help_update_terrain(pitem, top, get_terrain_by_name(top));
+    help_update_terrain(pitem, top, get_terrain_by_translated_name(top));
     break;
   case HELP_GOVERNMENT:
     help_update_government(pitem, top, find_government_by_name(top));
Index: client/gui-win32/helpdlg.c
===================================================================
--- client/gui-win32/helpdlg.c  (revision 12972)
+++ client/gui-win32/helpdlg.c  (working copy)
@@ -577,7 +577,7 @@
     if (*(pterrain->resources)) {
       const struct resource **r;
       for (r = pterrain->resources; *r; r++) {
-       sprintf (buf + strlen (buf), " %s,", _((*r)->name));
+       sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
       }
       buf[strlen (buf) - 1] = '.';
     } else {
@@ -607,7 +607,7 @@
       }
     } else if (pterrain->irrigation_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->irrigation_result->name,
+             terrain_name_translation(pterrain->irrigation_result),
              pterrain->irrigation_time);
     }
     SetWindowText(help_tlabel[2][4], buf);
@@ -621,14 +621,14 @@
       }
     } else if (pterrain->mining_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->mining_result->name,
+             terrain_name_translation(pterrain->mining_result),
              pterrain->mining_time);
     }
     SetWindowText(help_tlabel[3][1], buf);
 
     if (pterrain->transform_result != T_NONE) {
       sprintf(buf, "%s / %d",
-             pterrain->transform_result->name,
+             terrain_name_translation(pterrain->transform_result),
              pterrain->transform_time);
     } else {
       strcpy(buf, _("n/a"));
@@ -880,7 +880,7 @@
     help_update_tech(pitem, top, find_tech_by_name(top));
     break;
   case HELP_TERRAIN:
-    help_update_terrain(pitem, top, get_terrain_by_name(top));
+    help_update_terrain(pitem, top, get_terrain_by_translated_name(top));
     break;
   case HELP_GOVERNMENT:
     help_update_government(pitem, top, find_government_by_name(top));
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 12972)
+++ client/packhand.c   (working copy)
@@ -1958,7 +1958,7 @@
 
   if (!ptile->terrain || ptile->terrain->index != packet->type) {
     tile_changed = TRUE;
-    ptile->terrain = get_terrain(packet->type);
+    ptile->terrain = get_terrain_by_number(packet->type);
   }
   for (spe = 0; spe < S_LAST; spe++) {
     if (packet->special[spe]) {
@@ -1974,7 +1974,7 @@
     }
   }
 
-  ptile->resource = get_resource(packet->resource);
+  ptile->resource = get_resource_by_number(packet->resource);
   if (packet->owner == MAP_TILE_OWNER_NULL) {
     if (ptile->owner) {
       ptile->owner = NULL;
@@ -2332,7 +2332,7 @@
 **************************************************************************/
 void handle_ruleset_terrain(struct packet_ruleset_terrain *p)
 {
-  struct terrain *pterrain = get_terrain(p->id);
+  struct terrain *pterrain = get_terrain_by_number(p->id);
   int j;
 
   if (!pterrain) {
@@ -2342,8 +2342,8 @@
     return;
   }
 
-  sz_strlcpy(pterrain->name_orig, p->name_orig);
-  pterrain->name = Q_(pterrain->name_orig); /* See translate_data_names */
+  sz_strlcpy(pterrain->name_rule, p->name_orig);
+  pterrain->name_translated = NULL;    /* terrain.c terrain_name_translation */
   sz_strlcpy(pterrain->graphic_str, p->graphic_str);
   sz_strlcpy(pterrain->graphic_alt, p->graphic_alt);
   pterrain->movement_cost = p->movement_cost;
@@ -2356,23 +2356,23 @@
   pterrain->resources = fc_calloc(p->num_resources + 1,
                                  sizeof(*pterrain->resources));
   for (j = 0; j < p->num_resources; j++) {
-    pterrain->resources[j] = get_resource(p->resources[j]);
+    pterrain->resources[j] = get_resource_by_number(p->resources[j]);
     if (!pterrain->resources[j]) {
       freelog(LOG_ERROR, "Mismatched resource for terrain %s.",
-             pterrain->name_orig);
+             pterrain->name_rule);
     }
   }
   pterrain->resources[p->num_resources] = NULL;
 
   pterrain->road_time = p->road_time;
   pterrain->road_trade_incr = p->road_trade_incr;
-  pterrain->irrigation_result = get_terrain(p->irrigation_result);
+  pterrain->irrigation_result = get_terrain_by_number(p->irrigation_result);
   pterrain->irrigation_food_incr = p->irrigation_food_incr;
   pterrain->irrigation_time = p->irrigation_time;
-  pterrain->mining_result = get_terrain(p->mining_result);
+  pterrain->mining_result = get_terrain_by_number(p->mining_result);
   pterrain->mining_shield_incr = p->mining_shield_incr;
   pterrain->mining_time = p->mining_time;
-  pterrain->transform_result = get_terrain(p->transform_result);
+  pterrain->transform_result = get_terrain_by_number(p->transform_result);
   pterrain->transform_time = p->transform_time;
   pterrain->rail_time = p->rail_time;
   pterrain->airbase_time = p->airbase_time;
@@ -2392,7 +2392,7 @@
 ****************************************************************************/
 void handle_ruleset_resource(struct packet_ruleset_resource *p)
 {
-  struct resource *presource = get_resource(p->id);
+  struct resource *presource = get_resource_by_number(p->id);
 
   if (!presource) {
     freelog(LOG_ERROR,
@@ -2401,8 +2401,8 @@
     return;
   }
 
-  sz_strlcpy(presource->name_orig, p->name_orig);
-  presource->name = Q_(presource->name_orig);
+  sz_strlcpy(presource->name_rule, p->name_orig);
+  presource->name_translated = NULL;   /* terrain.c resource_name_translation 
*/
   sz_strlcpy(presource->graphic_str, p->graphic_str);
   sz_strlcpy(presource->graphic_alt, p->graphic_alt);
 
Index: client/helpdata.c
===================================================================
--- client/helpdata.c   (revision 12972)
+++ client/helpdata.c   (working copy)
@@ -122,24 +122,24 @@
     strcat(outbuf, "---------------------------------------------------"
           "------------\n");
     terrain_type_iterate(pterrain) {
-      if (*(pterrain->name) != '\0') {
+      if ('\0' != pterrain->name_rule[0]) {
        outbuf = strchr(outbuf, '\0');
        sprintf(outbuf,
                "%-10s %3d    %3d %-10s %3d %-10s %3d %-10s\n",
-               pterrain->name,
+               terrain_name_translation(pterrain),
                pterrain->road_time,
                pterrain->irrigation_time,
                ((pterrain->irrigation_result == pterrain
                  || pterrain->irrigation_result == T_NONE) ? ""
-                : pterrain->irrigation_result->name),
+                : terrain_name_translation(pterrain->irrigation_result)),
                pterrain->mining_time,
                ((pterrain->mining_result == pterrain
                  || pterrain->mining_result == T_NONE) ? ""
-                : pterrain->mining_result->name),
+                : terrain_name_translation(pterrain->mining_result)),
                pterrain->transform_time,
                ((pterrain->transform_result == pterrain
                 || pterrain->transform_result == T_NONE) ? ""
-                : pterrain->transform_result->name));
+                : terrain_name_translation(pterrain->transform_result)));
       }
     } terrain_type_iterate_end;
     strcat(outbuf, "\n");
@@ -180,7 +180,7 @@
     return;
   case REQ_TERRAIN:
     cat_snprintf(buf, bufsz, _("Requires the %s terrain.\n\n"),
-                get_name(req->source.value.terrain));
+                terrain_name_translation(req->source.value.terrain));
     return;
   case REQ_NATION:
     cat_snprintf(buf, bufsz, _("Requires the %s nation.\n\n"),
@@ -392,10 +392,10 @@
          } tech_type_iterate_end;
        } else if (current_type == HELP_TERRAIN) {
          terrain_type_iterate(pterrain) {
-           if (*(pterrain->name) != '\0') {
+           if ('\0' != pterrain->name_rule[0]) {
              pitem = new_help_item(current_type);
              my_snprintf(name, sizeof(name), " %s",
-                         pterrain->name);
+                         terrain_name_translation(pterrain));
              pitem->topic = mystrdup(name);
              pitem->text = mystrdup("");
              help_list_append(category_nodes, pitem);
Index: client/gui-mui/helpdlg.c
===================================================================
--- client/gui-mui/helpdlg.c    (revision 12972)
+++ client/gui-mui/helpdlg.c    (working copy)
@@ -1007,7 +1007,7 @@
     break;
 
   case HELP_TERRAIN:
-    help_update_terrain(pitem, top, get_terrain_by_name(top));
+    help_update_terrain(pitem, top, get_terrain_by_translated_name(top));
     break;
 
   case HELP_GOVERNMENT:
Index: client/tilespec.c
===================================================================
--- client/tilespec.c   (revision 12972)
+++ client/tilespec.c   (working copy)
@@ -2577,8 +2577,8 @@
   t->sprites.resource[id]
     = lookup_sprite_tag_alt(t, presource->graphic_str,
                            presource->graphic_alt,
-                           FALSE, "resource_type",
-                           presource->name);
+                           FALSE, "resource",
+                           presource->name_rule);
 }
 
 
@@ -2594,7 +2594,7 @@
   char buffer1[MAX_LEN_NAME + 20];
   int i, l;
   
-  if (pterrain->name[0] == '\0') {
+  if ('\0' == pterrain->name_rule[0]) {
     return;
   }
 
@@ -2603,8 +2603,9 @@
     draw = hash_lookup_data(t->terrain_hash, pterrain->graphic_alt);
     if (!draw) {
       freelog(LOG_FATAL, "No graphics %s or %s for %s terrain.",
-             pterrain->graphic_str, pterrain->graphic_alt,
-             pterrain->name);
+             pterrain->graphic_str,
+             pterrain->graphic_alt,
+             pterrain->name_rule);
       exit(EXIT_FAILURE);
     }
   }
@@ -2639,9 +2640,9 @@
        for (i = 0; i < t->num_index_cardinal; i++) {
          my_snprintf(buffer1, sizeof(buffer1),
                      "t.%s_%s", draw->name, cardinal_index_str(t, i));
-         draw->layer[l].match[i] = lookup_sprite_tag_alt(t, buffer1, "", TRUE,
-                                                         "tile_type",
-                                                         pterrain->name);
+         draw->layer[l].match[i] =
+           lookup_sprite_tag_alt(t, buffer1, "", TRUE, "whole cell terrain",
+                                                         pterrain->name_rule);
        }
        draw->layer[l].base.p[0] = draw->layer[l].match[0];
        break;
@@ -2671,8 +2672,8 @@
                          (value >> 1) & 1,
                          (value >> 2) & 1);
              draw->layer[l].cells[i]
-               = lookup_sprite_tag_alt(t, buffer1, "", TRUE, "tile_type",
-                                       pterrain->name);
+               = lookup_sprite_tag_alt(t, buffer1, "", TRUE, "same cell 
terrain",
+                                       pterrain->name_rule);
              break;
            case MATCH_FULL:
              {
@@ -2747,8 +2748,8 @@
        }
        my_snprintf(buffer1, sizeof(buffer1), "t.%s1", draw->name);
        draw->layer[l].base.p[0]
-         = lookup_sprite_tag_alt(t, buffer1, "", FALSE, "tile_type",
-                                 pterrain->name);
+         = lookup_sprite_tag_alt(t, buffer1, "", TRUE, "base terrain",
+                                 pterrain->name_rule);
        break;
       }
     }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to