diff -r eee46cb39750 -r b39bc69bb2f2 src/strings.cpp --- a/src/strings.cpp Wed Jan 09 18:11:12 2008 +0000 +++ b/src/strings.cpp Sun Feb 03 20:17:54 2008 +0000 @@ -5,7 +5,6 @@ #include "stdafx.h" #include "openttd.h" #include "currency.h" -#include "table/strings.h" #include "namegen.h" #include "station.h" #include "town.h" @@ -15,7 +14,6 @@ #include "industry.h" #include "variables.h" #include "newgrf_text.h" -#include "table/control_codes.h" #include "music.h" #include "industry.h" #include "fileio.h" @@ -34,9 +32,14 @@ #include "date_func.h" #include "vehicle_base.h" #include "string_func.h" +#include "player_func.h" +#include "player_base.h" +#include "fios.h" +#include "settings_type.h" +#include "video/video_driver.hpp" -/* for opendir/readdir/closedir */ -# include "fios.h" +#include "table/strings.h" +#include "table/control_codes.h" DynamicLanguages _dynlang; char _userstring[128]; @@ -101,9 +104,14 @@ * the indices will be reused. */ static int _bind_index; -static const char *GetStringPtr(StringID string) +const char *GetStringPtr(StringID string) { - return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; + switch (GB(string, 11, 5)) { + case 28: return GetGRFStringPtr(GB(string, 0, 11)); + case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800); + case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000); + default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; + } } /** The highest 8 bits of string contain the "case index". @@ -122,7 +130,6 @@ uint index = GB(string, 0, 11); uint tab = GB(string, 11, 5); - char buff[512]; switch (tab) { case 4: @@ -136,8 +143,8 @@ break; case 15: - /* User defined name */ - return GetName(buffr, index, last); + /* Old table for custom names. This is no longer used */ + error("Incorrect conversion of custom name string."); case 26: /* Include string within newgrf text (format code 81) */ @@ -148,16 +155,13 @@ break; case 28: - GetGRFString(buff, index, lastof(buff)); - return FormatString(buffr, buff, argv, 0, last); + return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last); case 29: - GetGRFString(buff, index + 0x800, lastof(buff)); - return FormatString(buffr, buff, argv, 0, last); + return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last); case 30: - GetGRFString(buff, index + 0x1000, lastof(buff)); - return FormatString(buffr, buff, argv, 0, last); + return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last); case 31: /* dynamic strings. These are NOT to be passed through the formatter, @@ -693,8 +697,7 @@ } case SCC_GENDER_LIST: { // {G 0 Der Die Das} - char buffr[512]; - const char *s = GetStringWithArgs(buffr, argv_orig[(byte)*str++], argv, last); // contains the string that determines gender. + const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. int len; int gender = 0; if (s != NULL) { @@ -819,17 +822,20 @@ break; case SCC_WAYPOINT_NAME: { // {WAYPOINT} - int64 temp[2]; Waypoint *wp = GetWaypoint(GetInt32(&argv)); - StringID str; - if (wp->string != STR_NULL) { - str = wp->string; + + if (!wp->IsValid()) { // waypoint doesn't exist anymore + buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last); + } else if (wp->name != NULL) { + buff = strecpy(buff, wp->name, last); } else { + int64 temp[2]; temp[0] = wp->town_index; temp[1] = wp->town_cn + 1; - str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; + StringID str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; + + buff = GetStringWithArgs(buff, str, temp, last); } - buff = GetStringWithArgs(buff, str, temp, last); break; } @@ -838,6 +844,8 @@ if (!st->IsValid()) { // station doesn't exist anymore buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last); + } else if (st->name != NULL) { + buff = strecpy(buff, st->name, last); } else { int64 temp[3]; temp[0] = STR_TOWN; @@ -857,7 +865,9 @@ temp[0] = t->townnameparts; uint32 grfid = t->townnamegrfid; - if (grfid == 0) { + if (t->name != NULL) { + buff = strecpy(buff, t->name, last); + } else if (grfid == 0) { /* Original town name */ buff = GetStringWithArgs(buff, t->townnametype, temp, last); } else { @@ -875,44 +885,75 @@ case SCC_GROUP_NAME: { // {GROUP} const Group *g = GetGroup(GetInt32(&argv)); - int64 args[1]; assert(g->IsValid()); - args[0] = g->index; - buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : STR_GROUP_NAME_FORMAT, args, last); + if (g->name != NULL) { + buff = strecpy(buff, g->name, last); + } else { + int64 args[1]; + args[0] = g->index; + buff = GetStringWithArgs(buff, STR_GROUP_NAME_FORMAT, args, last); + } break; } case SCC_ENGINE_NAME: { // {ENGINE} EngineID engine = (EngineID)GetInt32(&argv); + const Engine *e = GetEngine(engine); - buff = GetString(buff, GetCustomEngineName(engine), last); + if (e->name != NULL) { + buff = strecpy(buff, e->name, last); + } else { + buff = GetStringWithArgs(buff, EngInfo(engine)->string_id, NULL, last); + } break; } case SCC_VEHICLE_NAME: { // {VEHICLE} const Vehicle *v = GetVehicle(GetInt32(&argv)); - int64 args[1]; - args[0] = v->unitnumber; + if (v->name != NULL) { + buff = strecpy(buff, v->name, last); + } else { + int64 args[1]; + args[0] = v->unitnumber; - buff = GetStringWithArgs(buff, v->string_id, args, last); + StringID str; + switch (v->type) { + default: NOT_REACHED(); + case VEH_TRAIN: str = STR_SV_TRAIN_NAME; break; + case VEH_ROAD: str = STR_SV_ROADVEH_NAME; break; + case VEH_SHIP: str = STR_SV_SHIP_NAME; break; + case VEH_AIRCRAFT: str = STR_SV_AIRCRAFT_NAME; break; + } + + buff = GetStringWithArgs(buff, str, args, last); + } break; } case SCC_SIGN_NAME: { // {SIGN} const Sign *si = GetSign(GetInt32(&argv)); - buff = GetString(buff, si->str, last); + if (si->name != NULL) { + buff = strecpy(buff, si->name, last); + } else { + buff = GetStringWithArgs(buff, STR_280A_SIGN, NULL, last); + } break; } case SCC_COMPANY_NAME: { // {COMPANY} const Player *p = GetPlayer((PlayerID)GetInt32(&argv)); - int64 args[1]; - args[0] = p->name_2; - buff = GetStringWithArgs(buff, p->name_1, args, last); + + if (p->name != NULL) { + buff = strecpy(buff, p->name, last); + } else { + int64 args[1]; + args[0] = p->name_2; + buff = GetStringWithArgs(buff, p->name_1, args, last); + } break; } @@ -930,9 +971,14 @@ case SCC_PLAYER_NAME: { // {PLAYERNAME} const Player *p = GetPlayer((PlayerID)GetInt32(&argv)); - int64 args[1]; - args[0] = p->president_name_2; - buff = GetStringWithArgs(buff, p->president_name_1, args, last); + + if (p->president_name != NULL) { + buff = strecpy(buff, p->president_name, last); + } else { + int64 args[1]; + args[0] = p->president_name_2; + buff = GetStringWithArgs(buff, p->president_name_1, args, last); + } break; } @@ -1183,7 +1229,6 @@ #else /* ENABLE_NETWORK */ static inline void SortNetworkLanguages() {} #endif /* ENABLE_NETWORK */ -extern void SortTownGeneratorNames(); bool ReadLanguagePack(int lang_index) { @@ -1241,7 +1286,6 @@ _dynlang.curr = lang_index; SetCurrentGrfLangID(_langpack->isocode); SortNetworkLanguages(); - SortTownGeneratorNames(); return true; } @@ -1273,14 +1317,6 @@ } #endif /* !(defined(WIN32) || defined(__APPLE__)) */ -static int CDECL LanguageCompareFunc(const void *a, const void *b) -{ - const Language *cmp1 = (const Language*)a; - const Language *cmp2 = (const Language*)b; - - return strcmp(cmp1->file, cmp2->file); -} - int CDECL StringIDSorter(const void *a, const void *b) { const StringID va = *(const StringID*)a; @@ -1387,9 +1423,6 @@ } if (language_count == 0) error("No available language packs (invalid versions?)"); - /* Sort the language names alphabetically */ - qsort(files, language_count, sizeof(Language), LanguageCompareFunc); - /* Acquire the locale of the current system */ const char *lang = GetCurrentLocale("LC_MESSAGES"); if (lang == NULL) lang = "en_GB"; @@ -1408,7 +1441,6 @@ dl->ent[dl->num].file = files[i].file; dl->ent[dl->num].name = strdup(hdr.name); - dl->dropdown[dl->num] = SPECSTR_LANGUAGE_START + dl->num; /* We are trying to find a default language. The priority is by * configuration file, local environment and last, if nothing found, @@ -1424,8 +1456,6 @@ dl->num++; } - /* Terminate the dropdown list */ - dl->dropdown[dl->num] = INVALID_STRING_ID; if (dl->num == 0) error("Invalid version of language packs");