<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39383 >
While trying to debug some of my terrain changes, it was frustrating that some error messages had empty (missing/blank) fields. Numerous messages tried to insert a translated name into log messages that are not translated. (I'm running without translation, so it shows up badly here.) So, I spent all day figuring out some problems, and found a few others! For example, the req_ Terrain Mountains probably didn't work for foreign languages, because the test compared the translated terrain name against a list that is always in ruleset (original) language. Tests were wildly inconsistent, sometimes testing against original, others against translated. I made them *all* against original. Translated names are now only accessed via a central function. (The function existed, but not everybody used it.) My solution was to rename the "name" field to name_translated (how it was actually used in most places), and rename name_orig to name_original. That allowed me to find all the uses. For the same reason, I renamed the accessor functions, so that future programmers will be more aware of the actual purpose (or less confused). I found some error messages that could be reworded to be identical, with different parameters, that should ease translation a little. Also, I found that there were many places that terrain and tiles were confused (such as calling terrain "tile_type"). That will take more time to unravel. Compiles, runs here, needs more testing.
Index: server/generator/mapgen.c =================================================================== --- server/generator/mapgen.c (revision 12970) +++ 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_original, terrain_count[pterrain->index], (terrain_count[pterrain->index] * 100 + 50) / total); } terrain_type_iterate_end; } Index: server/scripting/api.pkg =================================================================== --- server/scripting/api.pkg (revision 12970) +++ server/scripting/api.pkg (working copy) @@ -100,7 +100,7 @@ }; struct Terrain { - const char *name_orig @ name; + const char *name_original @ name; }; Index: server/scripting/api_find.c =================================================================== --- server/scripting/api_find.c (revision 12970) +++ 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_original_name(name_orig); return pterrain; } Index: server/citytools.c =================================================================== --- server/citytools.c (revision 12970) +++ server/citytools.c (working copy) @@ -1097,7 +1097,7 @@ _("Moved %s out of disbanded city %s " "since it cannot stay on %s."), unit_type(punit)->name, pcity->name, - get_name(tile_get_terrain(ptile))); + terrain_name_translation(tile_get_terrain(ptile))); break; } } Index: server/cityturn.c =================================================================== --- server/cityturn.c (revision 12970) +++ server/cityturn.c (working copy) @@ -817,7 +817,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 12970) +++ server/ruleset.c (working copy) @@ -637,7 +637,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 index. **************************************************************************/ static struct terrain *lookup_terrain(char *name, struct terrain *tthis) { @@ -648,15 +648,16 @@ return (tthis); } + /* get_terrain_by_original_name */ terrain_type_iterate(pterrain) { - if (0 == strcmp(name, pterrain->name)) { + if (0 == strcmp(name, pterrain->name_original)) { 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); + freelog(LOG_ERROR, _("\"%s\" has unknown terrain \"%s\"."), + tthis->name_original, name); return T_NONE; } @@ -1493,11 +1494,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_original, name); + if (0 == strcmp(pterrain->name_original, "unused")) { + pterrain->name_original[0] = '\0'; } - pterrain->name = pterrain->name_orig; + pterrain->name_translated = pterrain->name_original; } terrain_type_iterate_end; free(sec); @@ -1509,11 +1510,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_original, name); + if (0 == strcmp(presource->name_original, "unused")) { + presource->name_original[0] = '\0'; } - presource->name = NULL; + presource->name_translated = NULL; } resource_type_iterate_end; free(sec); @@ -1619,21 +1620,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, _("[%s] cannot use '%c' as an identifier;" + " it is reserved."), + tsec[i], 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, _("[%s] has the same identifier as \"%s\"."), + tsec[i], get_terrain_by_number(j)->name_original); 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]); @@ -1650,9 +1657,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_original_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); } } @@ -1715,8 +1724,8 @@ if (flag == TER_LAST) { /* TRANS: message for an obscure ruleset error. */ - freelog(LOG_FATAL, _("Terrain %s has unknown flag %s"), - pterrain->name, sval); + freelog(LOG_FATAL, _("[%s] has unknown flag \"%s\"."), + tsec[i], sval); exit(EXIT_FAILURE); } else { BV_SET(pterrain->flags, flag); @@ -1744,16 +1753,16 @@ if (!class) { /* TRANS: message for an obscure ruleset error. */ - freelog(LOG_FATAL, _("Terrain %s is native to unknown unit class %s"), - pterrain->name, slist[j]); + freelog(LOG_FATAL, _("[%s] is native to unknown unit class \"%s\"."), + tsec[i], slist[j]); exit(EXIT_FAILURE); } else if (is_ocean(pterrain) && class->move_type == LAND_MOVING) { - freelog(LOG_FATAL, _("Oceanic terrain %s is native to land units."), - pterrain->name); + freelog(LOG_FATAL, _("Oceanic [%s] is native to land units."), + tsec[i]); exit(EXIT_FAILURE); } else if (!is_ocean(pterrain) && class->move_type == SEA_MOVING) { - freelog(LOG_FATAL, _("Non oceanic terrain %s is native to sea units."), - pterrain->name); + freelog(LOG_FATAL, _("Non-oceanic [%s] is native to sea units."), + tsec[i]); exit(EXIT_FAILURE); } else { BV_SET(pterrain->native_to, class->id); @@ -1769,7 +1778,7 @@ resource_type_iterate(presource) { const int i = presource->index; - presource->name = Q_(presource->name_orig); + presource->name_translated = Q_(presource->name_original); output_type_iterate (o) { presource->output[o] = secfile_lookup_int_default(file, 0, "%s.%s", rsec[i], @@ -1782,17 +1791,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, _("[%s] has the same identifier as \"%s\"."), + rsec[i], get_resource_by_number(j)->name_original); exit(EXIT_FAILURE); } } @@ -2175,7 +2191,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_original)) { city_names[j].terrain[pterrain->index] = setting; handled = TRUE; break; @@ -3047,7 +3067,7 @@ packet.id = i; packet.native_to = pterrain->native_to; - sz_strlcpy(packet.name_orig, pterrain->name_orig); + sz_strlcpy(packet.name_orig, pterrain->name_original); sz_strlcpy(packet.graphic_str, pterrain->graphic_str); sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt); @@ -3109,7 +3129,7 @@ packet.id = i; - sz_strlcpy(packet.name_orig, presource->name_orig); + sz_strlcpy(packet.name_orig, presource->name_original); sz_strlcpy(packet.graphic_str, presource->graphic_str); sz_strlcpy(packet.graphic_alt, presource->graphic_alt); Index: server/edithand.c =================================================================== --- server/edithand.c (revision 12970) +++ server/edithand.c (working copy) @@ -71,8 +71,8 @@ bv_special special) { struct tile *ptile = map_pos_to_tile(x, y); - struct terrain *pterrain = get_terrain(terrain), *old_terrain; - struct resource *presource = get_resource(resource); + struct terrain *pterrain = get_terrain_by_number(terrain), *old_terrain; + struct resource *presource = get_resource_by_number(resource); if (!can_conn_edit(pc) || !ptile || !pterrain) { return; Index: server/unittools.c =================================================================== --- server/unittools.c (revision 12970) +++ server/unittools.c (working copy) @@ -2159,7 +2159,8 @@ map_get_player_tile(ptile, pplayer)->special)) { 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; } @@ -2190,7 +2191,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 12970) +++ 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_original, ptile->x, ptile->y, \ + #check, __FILE__,__LINE__); \ } \ } while(0) Index: server/unithand.c =================================================================== --- server/unithand.c (revision 12970) +++ server/unithand.c (working copy) @@ -1066,7 +1066,7 @@ } else { notify_player(pplayer, punit->tile, E_BAD_COMMAND, _("Unit cannot perform diplomatic action from %s."), - get_name(punit->tile->terrain)); + terrain_name_translation(punit->tile->terrain)); } return FALSE; } Index: server/savegame.c =================================================================== --- server/savegame.c (revision 12970) +++ server/savegame.c (working copy) @@ -249,6 +249,7 @@ ****************************************************************************/ static struct terrain *char2terrain(char ch) { + /* essentially get_terrain_by_identifier plus fatal error */ if (ch == UNKNOWN_TERRAIN_IDENTIFIER) { return T_UNKNOWN; } @@ -4058,7 +4084,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 12970) +++ common/combat.c (working copy) @@ -603,7 +603,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 12970) +++ common/tile.c (working copy) @@ -563,14 +563,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 12970) +++ common/terrain.c (working copy) @@ -67,9 +67,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. */ @@ -81,10 +98,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_original_name(const char *name) { terrain_type_iterate(pterrain) { - if (0 == strcmp(pterrain->name, name)) { + if (0 == strcmp(pterrain->name_original, name)) { return pterrain; } } terrain_type_iterate_end; @@ -93,12 +110,26 @@ } /**************************************************************************** - 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(pterrain->name_translated, name)) { + return pterrain; + } + } terrain_type_iterate_end; + + return T_UNKNOWN; +} + +/**************************************************************************** + Return the translated name of the terrain. +****************************************************************************/ +const char *terrain_name_translation(const struct terrain *pterrain) +{ SANITY_CHECK_TERRAIN(pterrain); - return pterrain->name; + return pterrain->name_translated; } /**************************************************************************** @@ -133,8 +164,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; @@ -155,7 +187,7 @@ } } terrain_type_iterate_end; - die("Reached end of get_flag_terrain!"); + die("Reached end of pick_terrain_by_flag!"); return T_UNKNOWN; } @@ -173,7 +205,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. */ @@ -185,10 +217,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_original_name(const char *name_orig) { resource_type_iterate(presource) { - if (0 == strcmp(presource->name_orig, name_orig)) { + if (0 == strcmp(presource->name_original, name_orig)) { return presource; } } resource_type_iterate_end; @@ -196,7 +228,15 @@ return NULL; } +/**************************************************************************** + Return the translated name of the resource. +****************************************************************************/ +const char *resource_name_translation(const struct resource *presource) +{ + 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 12970) +++ common/terrain.h (working copy) @@ -118,13 +118,23 @@ */ 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_original[MAX_LEN_NAME]; /* untranslated copy */ + 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 LAKE_TERRAIN_IDENTIFIER '+' +#define SEA_TERRAIN_IDENTIFIER '-' +#define COAST_TERRAIN_IDENTIFIER '.' +#define SHELF_TERRAIN_IDENTIFIER ',' +#define FLOOR_TERRAIN_IDENTIFIER ':' +#define TRENCH_TERRAIN_IDENTIFIER ';' +#define RIDGE_TERRAIN_IDENTIFIER '^' +#define VENT_TERRAIN_IDENTIFIER '!' +#define GLACIER_TERRAIN_IDENTIFIER 'a' #define UNKNOWN_TERRAIN_IDENTIFIER 'u' int movement_cost; @@ -175,12 +185,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_original[MAX_LEN_NAME]; /* untranslated copy */ + 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 ' ' @@ -194,16 +204,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_original_name(const char *name); +struct terrain *get_terrain_by_translated_name(const char *name); +const char *terrain_name_translation(const 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_original_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, @@ -267,7 +280,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 \ @@ -279,7 +292,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 12970) +++ common/game.c (working copy) @@ -647,12 +647,13 @@ } impr_type_iterate_end; terrain_type_iterate(tthis) { - tthis->name = ((strcmp(tthis->name_orig, "") != 0) - ? Q_(tthis->name_orig) : ""); + tthis->name_translated = ((strcmp(tthis->name_original, "") != 0) + ? Q_(tthis->name_original) : ""); } terrain_type_iterate_end; resource_type_iterate (tthis) { - tthis->name = (*(tthis->name_orig)) ? Q_(tthis->name_orig) : ""; + tthis->name_translated = (*(tthis->name_original)) + ? Q_(tthis->name_original) : ""; } resource_type_iterate_end; Index: common/requirements.c =================================================================== --- common/requirements.c (revision 12970) +++ common/requirements.c (working copy) @@ -130,7 +130,7 @@ } break; case REQ_TERRAIN: - source.value.terrain = get_terrain_by_name(value); + source.value.terrain = get_terrain_by_original_name(value); if (source.value.terrain != T_UNKNOWN) { return source; } @@ -223,7 +223,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); @@ -1089,7 +1089,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 12970) +++ 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_original[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 12970) +++ 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_original); 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_original); /* Fallback: the color remains black. */ } } Index: client/gui-gtk-2.0/editdlg.c =================================================================== --- client/gui-gtk-2.0/editdlg.c (revision 12970) +++ client/gui-gtk-2.0/editdlg.c (working copy) @@ -177,7 +177,7 @@ assert(paint >= 0 && paint < EPAINT_LAST); switch(paint){ case EPAINT_TERRAIN: - editor_set_selected_terrain(get_terrain(terrains[id].paint)); + editor_set_selected_terrain(get_terrain_by_number(terrains[id].paint)); break; case EPAINT_SPECIAL: editor_set_selected_special(specials[id].paint); @@ -186,7 +186,7 @@ if (id == 0) { editor_set_selected_resource(NULL); } else { - editor_set_selected_resource(get_resource(resources[id - 1].paint)); + editor_set_selected_resource(get_resource_by_number(resources[id - 1].paint)); } break; case EPAINT_LAST: @@ -311,7 +311,7 @@ switch(i) { case EPAINT_TERRAIN: item->paint = j; - item->name = get_terrain(item->paint)->name; + item->name = terrain_name_translation(get_terrain_by_number(item->paint)); break; case EPAINT_SPECIAL: if (!item->name) { @@ -323,7 +323,7 @@ if (j == 0) { item->name = _("None"); } else { - item->name = get_resource(item->paint - 1)->name; + item->name = resource_name_translation(get_resource_by_number(item->paint - 1)); } break; } @@ -352,7 +352,7 @@ } } - editor_set_selected_terrain(get_terrain(terrains[0].paint)); + editor_set_selected_terrain(get_terrain_by_number(terrains[0].paint)); gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 5); gtk_widget_show_all(vbox); Index: client/gui-gtk-2.0/helpdlg.c =================================================================== --- client/gui-gtk-2.0/helpdlg.c (revision 12970) +++ client/gui-gtk-2.0/helpdlg.c (working copy) @@ -1046,7 +1046,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 { @@ -1076,7 +1076,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); @@ -1090,14 +1090,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"); @@ -1170,7 +1170,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 12970) +++ client/gui-xaw/helpdlg.c (working copy) @@ -986,7 +986,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 { @@ -1015,7 +1015,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); @@ -1029,14 +1029,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")); @@ -1096,7 +1096,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 12970) +++ 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")); @@ -891,7 +891,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 12970) +++ client/packhand.c (working copy) @@ -1956,7 +1956,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]) { @@ -1982,7 +1982,7 @@ tile_changed = TRUE; } - 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; @@ -2374,7 +2374,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) { @@ -2385,8 +2385,8 @@ } pterrain->native_to = p->native_to; - sz_strlcpy(pterrain->name_orig, p->name_orig); - pterrain->name = Q_(pterrain->name_orig); /* See translate_data_names */ + sz_strlcpy(pterrain->name_original, p->name_orig); + pterrain->name_translated = Q_(pterrain->name_original); /* See translate_data_names */ sz_strlcpy(pterrain->graphic_str, p->graphic_str); sz_strlcpy(pterrain->graphic_alt, p->graphic_alt); pterrain->movement_cost = p->movement_cost; @@ -2399,23 +2399,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_original); } } 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; @@ -2435,7 +2435,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, @@ -2444,8 +2444,8 @@ return; } - sz_strlcpy(presource->name_orig, p->name_orig); - presource->name = Q_(presource->name_orig); + sz_strlcpy(presource->name_original, p->name_orig); + presource->name_translated = Q_(presource->name_original); sz_strlcpy(presource->graphic_str, p->graphic_str); sz_strlcpy(presource->graphic_alt, p->graphic_alt); Index: client/helpdata.c =================================================================== --- client/helpdata.c (revision 12970) +++ client/helpdata.c (working copy) @@ -122,24 +122,24 @@ strcat(outbuf, "---------------------------------------------------" "------------\n"); terrain_type_iterate(pterrain) { - if (*(pterrain->name) != '\0') { + if ('\0' != pterrain->name_original[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"), @@ -400,10 +400,10 @@ } tech_type_iterate_end; } else if (current_type == HELP_TERRAIN) { terrain_type_iterate(pterrain) { - if (*(pterrain->name) != '\0') { + if ('\0' != pterrain->name_original[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 12970) +++ 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 12970) +++ client/tilespec.c (working copy) @@ -2588,8 +2588,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_original); } /**************************************************************************** @@ -2665,7 +2665,7 @@ char buffer1[MAX_LEN_NAME + 20]; int i, l; - if (pterrain->name[0] == '\0') { + if ('\0' == pterrain->name_original[0]) { return; } @@ -2673,9 +2673,10 @@ if (!draw) { 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); + freelog(LOG_FATAL, "Terrain %s: no graphics \"%s\" or \"%s\".", + pterrain->name_original, + pterrain->graphic_str, + pterrain->graphic_alt); exit(EXIT_FAILURE); } } @@ -2712,8 +2713,8 @@ "t.l%d.%s_%s", l, draw->name, cardinal_index_str(t, i)); draw->layer[l].match[i] = lookup_sprite_tag_alt(t, buffer1, "", TRUE, - "tile_type", - pterrain->name); + "single cell terrain", + pterrain->name_original); } break; case CELL_RECT: @@ -2743,8 +2744,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, "boolean cell terrain", + pterrain->name_original); break; case MATCH_FULL: { @@ -2839,8 +2840,8 @@ my_snprintf(buffer1, sizeof(buffer1), "t.l%d.%s1", l, draw->name); sprite_vector_reserve(&draw->layer[l].base, 1); draw->layer[l].base.p[0] - = lookup_sprite_tag_alt(t, buffer1, "", TRUE, "tile_type", - pterrain->name); + = lookup_sprite_tag_alt(t, buffer1, "", TRUE, "terrain", + pterrain->name_original); } for (dir = 0; dir < 4; dir++) {
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev