35 #include "player_base.h" |
35 #include "player_base.h" |
36 #include "fios.h" |
36 #include "fios.h" |
37 #include "settings_type.h" |
37 #include "settings_type.h" |
38 #include "video/video_driver.hpp" |
38 #include "video/video_driver.hpp" |
39 #include "engine_func.h" |
39 #include "engine_func.h" |
|
40 #include "saveload.h" |
40 |
41 |
41 #include "table/strings.h" |
42 #include "table/strings.h" |
42 #include "table/control_codes.h" |
43 #include "table/control_codes.h" |
43 |
44 |
44 DynamicLanguages _dynlang; |
45 DynamicLanguages _dynlang; |
1043 } |
1044 } |
1044 |
1045 |
1045 |
1046 |
1046 static char *StationGetSpecialString(char *buff, int x, const char* last) |
1047 static char *StationGetSpecialString(char *buff, int x, const char* last) |
1047 { |
1048 { |
1048 if ((x & 0x01) && (buff + Utf8CharLen(SCC_TRAIN) < last)) buff += Utf8Encode(buff, SCC_TRAIN); |
1049 if ((x & FACIL_TRAIN) && (buff + Utf8CharLen(SCC_TRAIN) < last)) buff += Utf8Encode(buff, SCC_TRAIN); |
1049 if ((x & 0x02) && (buff + Utf8CharLen(SCC_LORRY) < last)) buff += Utf8Encode(buff, SCC_LORRY); |
1050 if ((x & FACIL_TRUCK_STOP) && (buff + Utf8CharLen(SCC_LORRY) < last)) buff += Utf8Encode(buff, SCC_LORRY); |
1050 if ((x & 0x04) && (buff + Utf8CharLen(SCC_BUS) < last)) buff += Utf8Encode(buff, SCC_BUS); |
1051 if ((x & FACIL_BUS_STOP) && (buff + Utf8CharLen(SCC_BUS) < last)) buff += Utf8Encode(buff, SCC_BUS); |
1051 if ((x & 0x08) && (buff + Utf8CharLen(SCC_PLANE) < last)) buff += Utf8Encode(buff, SCC_PLANE); |
1052 if ((x & FACIL_AIRPORT) && (buff + Utf8CharLen(SCC_PLANE) < last)) buff += Utf8Encode(buff, SCC_PLANE); |
1052 if ((x & 0x10) && (buff + Utf8CharLen(SCC_SHIP) < last)) buff += Utf8Encode(buff, SCC_SHIP); |
1053 if ((x & FACIL_DOCK) && (buff + Utf8CharLen(SCC_SHIP) < last)) buff += Utf8Encode(buff, SCC_SHIP); |
1053 *buff = '\0'; |
1054 *buff = '\0'; |
1054 return buff; |
1055 return buff; |
1055 } |
1056 } |
1056 |
1057 |
1057 static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last) |
1058 static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last) |
1224 |
1225 |
1225 assert(0); |
1226 assert(0); |
1226 return NULL; |
1227 return NULL; |
1227 } |
1228 } |
1228 |
1229 |
1229 /** |
|
1230 * remap a string ID from the old format to the new format |
|
1231 * @param s StringID that requires remapping |
|
1232 * @return translated ID*/ |
|
1233 StringID RemapOldStringID(StringID s) |
|
1234 { |
|
1235 switch (s) { |
|
1236 case 0x0006: return STR_SV_EMPTY; |
|
1237 case 0x7000: return STR_SV_UNNAMED; |
|
1238 case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1239 case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1240 case 0x8864: return STR_SV_TRAIN_NAME; |
|
1241 case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1242 case 0x9830: return STR_SV_SHIP_NAME; |
|
1243 case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1244 |
|
1245 default: |
|
1246 if (IsInsideMM(s, 0x300F, 0x3030)) { |
|
1247 return s - 0x300F + STR_SV_STNAME; |
|
1248 } else { |
|
1249 return s; |
|
1250 } |
|
1251 } |
|
1252 } |
|
1253 |
|
1254 #ifdef ENABLE_NETWORK |
1230 #ifdef ENABLE_NETWORK |
1255 extern void SortNetworkLanguages(); |
1231 extern void SortNetworkLanguages(); |
1256 #else /* ENABLE_NETWORK */ |
1232 #else /* ENABLE_NETWORK */ |
1257 static inline void SortNetworkLanguages() {} |
1233 static inline void SortNetworkLanguages() {} |
1258 #endif /* ENABLE_NETWORK */ |
1234 #endif /* ENABLE_NETWORK */ |
1546 } |
1524 } |
1547 } |
1525 } |
1548 } |
1526 } |
1549 } |
1527 } |
1550 } |
1528 } |
|
1529 |
|
1530 |
|
1531 /* --- Handling of saving/loading string IDs from old savegames --- */ |
|
1532 |
|
1533 /** |
|
1534 * Remap a string ID from the old format to the new format |
|
1535 * @param s StringID that requires remapping |
|
1536 * @return translated ID |
|
1537 */ |
|
1538 StringID RemapOldStringID(StringID s) |
|
1539 { |
|
1540 switch (s) { |
|
1541 case 0x0006: return STR_SV_EMPTY; |
|
1542 case 0x7000: return STR_SV_UNNAMED; |
|
1543 case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1544 case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1545 case 0x8864: return STR_SV_TRAIN_NAME; |
|
1546 case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1547 case 0x9830: return STR_SV_SHIP_NAME; |
|
1548 case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1549 |
|
1550 default: |
|
1551 if (IsInsideMM(s, 0x300F, 0x3030)) { |
|
1552 return s - 0x300F + STR_SV_STNAME; |
|
1553 } else { |
|
1554 return s; |
|
1555 } |
|
1556 } |
|
1557 } |
|
1558 |
|
1559 /** Location to load the old names to. */ |
|
1560 char *_old_name_array = NULL; |
|
1561 |
|
1562 /** |
|
1563 * Copy and convert old custom names to UTF-8. |
|
1564 * They were all stored in a 512 by 32 long string array and are |
|
1565 * now stored with stations, waypoints and other places with names. |
|
1566 * @param id the StringID of the custom name to clone. |
|
1567 * @return the clones custom name. |
|
1568 */ |
|
1569 char *CopyFromOldName(StringID id) |
|
1570 { |
|
1571 /* Is this name an (old) custom name? */ |
|
1572 if (GB(id, 11, 5) != 15) return NULL; |
|
1573 |
|
1574 if (CheckSavegameVersion(37)) { |
|
1575 /* Old names were 32 characters long, so 128 characters should be |
|
1576 * plenty to allow for expansion when converted to UTF-8. */ |
|
1577 char tmp[128]; |
|
1578 const char *strfrom = &_old_name_array[32 * GB(id, 0, 9)]; |
|
1579 char *strto = tmp; |
|
1580 |
|
1581 for (; *strfrom != '\0'; strfrom++) { |
|
1582 WChar c = (byte)*strfrom; |
|
1583 |
|
1584 /* Map from non-ISO8859-15 characters to UTF-8. */ |
|
1585 switch (c) { |
|
1586 case 0xA4: c = 0x20AC; break; // Euro |
|
1587 case 0xA6: c = 0x0160; break; // S with caron |
|
1588 case 0xA8: c = 0x0161; break; // s with caron |
|
1589 case 0xB4: c = 0x017D; break; // Z with caron |
|
1590 case 0xB8: c = 0x017E; break; // z with caron |
|
1591 case 0xBC: c = 0x0152; break; // OE ligature |
|
1592 case 0xBD: c = 0x0153; break; // oe ligature |
|
1593 case 0xBE: c = 0x0178; break; // Y with diaresis |
|
1594 default: break; |
|
1595 } |
|
1596 |
|
1597 /* Check character will fit into our buffer. */ |
|
1598 if (strto + Utf8CharLen(c) > lastof(tmp)) break; |
|
1599 |
|
1600 strto += Utf8Encode(strto, c); |
|
1601 } |
|
1602 |
|
1603 /* Terminate the new string and copy it back to the name array */ |
|
1604 *strto = '\0'; |
|
1605 |
|
1606 return strdup(tmp); |
|
1607 } else { |
|
1608 /* Name will already be in UTF-8. */ |
|
1609 return strdup(&_old_name_array[32 * GB(id, 0, 9)]); |
|
1610 } |
|
1611 } |
|
1612 |
|
1613 /** |
|
1614 * Free the memory of the old names array. |
|
1615 * Should be called once the old names have all been converted. |
|
1616 */ |
|
1617 void ResetOldNames() |
|
1618 { |
|
1619 free(_old_name_array); |
|
1620 _old_name_array = NULL; |
|
1621 } |
|
1622 |
|
1623 /** |
|
1624 * Initialize the old names table memory. |
|
1625 */ |
|
1626 void InitializeOldNames() |
|
1627 { |
|
1628 free(_old_name_array); |
|
1629 _old_name_array = CallocT<char>(512 * 32); |
|
1630 } |
|
1631 |
|
1632 static void Load_NAME() |
|
1633 { |
|
1634 int index; |
|
1635 |
|
1636 while ((index = SlIterateArray()) != -1) { |
|
1637 SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8); |
|
1638 } |
|
1639 } |
|
1640 |
|
1641 extern const ChunkHandler _name_chunk_handlers[] = { |
|
1642 { 'NAME', NULL, Load_NAME, CH_ARRAY | CH_LAST}, |
|
1643 }; |