strings_sl.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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   /* Is this name an (old) custom name? */
00057   if (GB(id, 11, 5) != 15) return NULL;
00058 
00059   if (CheckSavegameVersion(37)) {
00060     /* Old names were 24/32 characters long, so 128 characters should be
00061      * plenty to allow for expansion when converted to UTF-8. */
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       /* Map from non-ISO8859-15 characters to UTF-8. */
00071       switch (c) {
00072         case 0xA4: c = 0x20AC; break; // Euro
00073         case 0xA6: c = 0x0160; break; // S with caron
00074         case 0xA8: c = 0x0161; break; // s with caron
00075         case 0xB4: c = 0x017D; break; // Z with caron
00076         case 0xB8: c = 0x017E; break; // z with caron
00077         case 0xBC: c = 0x0152; break; // OE ligature
00078         case 0xBD: c = 0x0153; break; // oe ligature
00079         case 0xBE: c = 0x0178; break; // Y with diaresis
00080         default: break;
00081       }
00082 
00083       /* Check character will fit into our buffer. */
00084       if (strto + Utf8CharLen(c) > lastof(tmp)) break;
00085 
00086       strto += Utf8Encode(strto, c);
00087     }
00088 
00089     /* Terminate the new string and copy it back to the name array */
00090     *strto = '\0';
00091 
00092     return strdup(tmp);
00093   } else {
00094     /* Name will already be in UTF-8. */
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); // 200 * 24 would be enough for TTO savegames
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, CH_ARRAY | CH_LAST},
00129 };

Generated on Sat Dec 26 20:06:04 2009 for OpenTTD by  doxygen 1.5.6