Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../string_func.h"
00014 #include "saveload_internal.h"
00015
00016 #include "table/strings.h"
00017
00018 static const int NUM_OLD_STRINGS = 512;
00019 static const int LEN_OLD_STRINGS = 32;
00020 static const int LEN_OLD_STRINGS_TTO = 24;
00021
00027 StringID RemapOldStringID(StringID s)
00028 {
00029 switch (s) {
00030 case 0x0006: return STR_SV_EMPTY;
00031 case 0x7000: return STR_SV_UNNAMED;
00032 case 0x70E4: return SPECSTR_COMPANY_NAME_START;
00033 case 0x70E9: return SPECSTR_COMPANY_NAME_START;
00034 case 0x8864: return STR_SV_TRAIN_NAME;
00035 case 0x902B: return STR_SV_ROAD_VEHICLE_NAME;
00036 case 0x9830: return STR_SV_SHIP_NAME;
00037 case 0xA02F: return STR_SV_AIRCRAFT_NAME;
00038
00039 default:
00040 if (IsInsideMM(s, 0x300F, 0x3030)) {
00041 return s - 0x300F + STR_SV_STNAME;
00042 } else {
00043 return s;
00044 }
00045 }
00046 }
00047
00049 char *_old_name_array = NULL;
00050
00058 char *CopyFromOldName(StringID id)
00059 {
00060
00061 if (GB(id, 11, 5) != 15) return NULL;
00062
00063 if (IsSavegameVersionBefore(37)) {
00064
00065 char tmp[LEN_OLD_STRINGS * MAX_CHAR_LENGTH];
00066 uint offs = _savegame_type == SGT_TTO ? LEN_OLD_STRINGS_TTO * GB(id, 0, 8) : LEN_OLD_STRINGS * GB(id, 0, 9);
00067 const char *strfrom = &_old_name_array[offs];
00068 char *strto = tmp;
00069
00070 for (; *strfrom != '\0'; strfrom++) {
00071 WChar c = (byte)*strfrom;
00072
00073
00074 switch (c) {
00075 case 0xA4: c = 0x20AC; break;
00076 case 0xA6: c = 0x0160; break;
00077 case 0xA8: c = 0x0161; break;
00078 case 0xB4: c = 0x017D; break;
00079 case 0xB8: c = 0x017E; break;
00080 case 0xBC: c = 0x0152; break;
00081 case 0xBD: c = 0x0153; break;
00082 case 0xBE: c = 0x0178; break;
00083 default: break;
00084 }
00085
00086
00087 if (strto + Utf8CharLen(c) > lastof(tmp)) break;
00088
00089 strto += Utf8Encode(strto, c);
00090 }
00091
00092
00093 *strto = '\0';
00094
00095 return strdup(tmp);
00096 } else {
00097
00098 return strdup(&_old_name_array[LEN_OLD_STRINGS * GB(id, 0, 9)]);
00099 }
00100 }
00101
00106 void ResetOldNames()
00107 {
00108 free(_old_name_array);
00109 _old_name_array = NULL;
00110 }
00111
00115 void InitializeOldNames()
00116 {
00117 free(_old_name_array);
00118 _old_name_array = CallocT<char>(NUM_OLD_STRINGS * LEN_OLD_STRINGS);
00119 }
00120
00124 static void Load_NAME()
00125 {
00126 int index;
00127
00128 while ((index = SlIterateArray()) != -1) {
00129 if (index >= NUM_OLD_STRINGS) SlErrorCorrupt("Invalid old name index");
00130 if (SlGetFieldLength() > (uint)LEN_OLD_STRINGS) SlErrorCorrupt("Invalid old name length");
00131
00132 SlArray(&_old_name_array[LEN_OLD_STRINGS * index], SlGetFieldLength(), SLE_UINT8);
00133
00134 _old_name_array[LEN_OLD_STRINGS * index + LEN_OLD_STRINGS - 1] = '\0';
00135 }
00136 }
00137
00139 extern const ChunkHandler _name_chunk_handlers[] = {
00140 { 'NAME', NULL, Load_NAME, NULL, NULL, CH_ARRAY | CH_LAST},
00141 };