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
00023 StringID RemapOldStringID(StringID s)
00024 {
00025 switch (s) {
00026 case 0x0006: return STR_SV_EMPTY;
00027 case 0x7000: return STR_SV_UNNAMED;
00028 case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
00029 case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
00030 case 0x8864: return STR_SV_TRAIN_NAME;
00031 case 0x902B: return STR_SV_ROAD_VEHICLE_NAME;
00032 case 0x9830: return STR_SV_SHIP_NAME;
00033 case 0xA02F: return STR_SV_AIRCRAFT_NAME;
00034
00035 default:
00036 if (IsInsideMM(s, 0x300F, 0x3030)) {
00037 return s - 0x300F + STR_SV_STNAME;
00038 } else {
00039 return s;
00040 }
00041 }
00042 }
00043
00045 char *_old_name_array = NULL;
00046
00054 char *CopyFromOldName(StringID id)
00055 {
00056
00057 if (GB(id, 11, 5) != 15) return NULL;
00058
00059 if (IsSavegameVersionBefore(37)) {
00060
00061
00062 char tmp[128];
00063 uint offs = _savegame_type == SGT_TTO ? 24 * GB(id, 0, 8) : 32 * GB(id, 0, 9);
00064 const char *strfrom = &_old_name_array[offs];
00065 char *strto = tmp;
00066
00067 for (; *strfrom != '\0'; strfrom++) {
00068 WChar c = (byte)*strfrom;
00069
00070
00071 switch (c) {
00072 case 0xA4: c = 0x20AC; break;
00073 case 0xA6: c = 0x0160; break;
00074 case 0xA8: c = 0x0161; break;
00075 case 0xB4: c = 0x017D; break;
00076 case 0xB8: c = 0x017E; break;
00077 case 0xBC: c = 0x0152; break;
00078 case 0xBD: c = 0x0153; break;
00079 case 0xBE: c = 0x0178; break;
00080 default: break;
00081 }
00082
00083
00084 if (strto + Utf8CharLen(c) > lastof(tmp)) break;
00085
00086 strto += Utf8Encode(strto, c);
00087 }
00088
00089
00090 *strto = '\0';
00091
00092 return strdup(tmp);
00093 } else {
00094
00095 return strdup(&_old_name_array[32 * GB(id, 0, 9)]);
00096 }
00097 }
00098
00103 void ResetOldNames()
00104 {
00105 free(_old_name_array);
00106 _old_name_array = NULL;
00107 }
00108
00112 void InitializeOldNames()
00113 {
00114 free(_old_name_array);
00115 _old_name_array = CallocT<char>(512 * 32);
00116 }
00117
00118 static void Load_NAME()
00119 {
00120 int index;
00121
00122 while ((index = SlIterateArray()) != -1) {
00123 SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8);
00124 }
00125 }
00126
00127 extern const ChunkHandler _name_chunk_handlers[] = {
00128 { 'NAME', NULL, Load_NAME, NULL, NULL, CH_ARRAY | CH_LAST},
00129 };