equal
deleted
inserted
replaced
30 #include "core/endian_func.hpp" |
30 #include "core/endian_func.hpp" |
31 #include "vehicle_base.h" |
31 #include "vehicle_base.h" |
32 #include "autoreplace_base.h" |
32 #include "autoreplace_base.h" |
33 #include "statusbar_gui.h" |
33 #include "statusbar_gui.h" |
34 #include <list> |
34 #include <list> |
|
35 #include "gamelog.h" |
35 |
36 |
36 #include "table/strings.h" |
37 #include "table/strings.h" |
37 |
38 |
38 extern const uint16 SAVEGAME_VERSION = 97; |
39 extern const uint16 SAVEGAME_VERSION = 98; |
39 |
40 |
40 SavegameType _savegame_type; ///< type of savegame we are loading |
41 SavegameType _savegame_type; ///< type of savegame we are loading |
41 |
42 |
42 uint32 _ttdp_version; ///< version of TTDP savegame (if applicable) |
43 uint32 _ttdp_version; ///< version of TTDP savegame (if applicable) |
43 uint16 _sl_version; ///< the major savegame version identifier |
44 uint16 _sl_version; ///< the major savegame version identifier |
763 * Calculate the size of an object. |
764 * Calculate the size of an object. |
764 * @param object to be measured |
765 * @param object to be measured |
765 * @param sld The SaveLoad description of the object so we know how to manipulate it |
766 * @param sld The SaveLoad description of the object so we know how to manipulate it |
766 * @return size of given objetc |
767 * @return size of given objetc |
767 */ |
768 */ |
768 static size_t SlCalcObjLength(const void *object, const SaveLoad *sld) |
769 size_t SlCalcObjLength(const void *object, const SaveLoad *sld) |
769 { |
770 { |
770 size_t length = 0; |
771 size_t length = 0; |
771 |
772 |
772 /* Need to determine the length and write a length tag. */ |
773 /* Need to determine the length and write a length tag. */ |
773 for (; sld->cmd != SL_END; sld++) { |
774 for (; sld->cmd != SL_END; sld++) { |
1284 /******************************************* |
1285 /******************************************* |
1285 ************* END OF CODE ***************** |
1286 ************* END OF CODE ***************** |
1286 *******************************************/ |
1287 *******************************************/ |
1287 |
1288 |
1288 /* these define the chunks */ |
1289 /* these define the chunks */ |
|
1290 extern const ChunkHandler _gamelog_chunk_handlers[]; |
1289 extern const ChunkHandler _misc_chunk_handlers[]; |
1291 extern const ChunkHandler _misc_chunk_handlers[]; |
1290 extern const ChunkHandler _name_chunk_handlers[]; |
1292 extern const ChunkHandler _name_chunk_handlers[]; |
1291 extern const ChunkHandler _cheat_chunk_handlers[] ; |
1293 extern const ChunkHandler _cheat_chunk_handlers[] ; |
1292 extern const ChunkHandler _setting_chunk_handlers[]; |
1294 extern const ChunkHandler _setting_chunk_handlers[]; |
1293 extern const ChunkHandler _player_chunk_handlers[]; |
1295 extern const ChunkHandler _player_chunk_handlers[]; |
1305 extern const ChunkHandler _newgrf_chunk_handlers[]; |
1307 extern const ChunkHandler _newgrf_chunk_handlers[]; |
1306 extern const ChunkHandler _group_chunk_handlers[]; |
1308 extern const ChunkHandler _group_chunk_handlers[]; |
1307 extern const ChunkHandler _cargopacket_chunk_handlers[]; |
1309 extern const ChunkHandler _cargopacket_chunk_handlers[]; |
1308 |
1310 |
1309 static const ChunkHandler * const _chunk_handlers[] = { |
1311 static const ChunkHandler * const _chunk_handlers[] = { |
|
1312 _gamelog_chunk_handlers, |
1310 _misc_chunk_handlers, |
1313 _misc_chunk_handlers, |
1311 _name_chunk_handlers, |
1314 _name_chunk_handlers, |
1312 _cheat_chunk_handlers, |
1315 _cheat_chunk_handlers, |
1313 _setting_chunk_handlers, |
1316 _setting_chunk_handlers, |
1314 _veh_chunk_handlers, |
1317 _veh_chunk_handlers, |
1641 _next_offs = 0; |
1644 _next_offs = 0; |
1642 |
1645 |
1643 /* Load a TTDLX or TTDPatch game */ |
1646 /* Load a TTDLX or TTDPatch game */ |
1644 if (mode == SL_OLD_LOAD) { |
1647 if (mode == SL_OLD_LOAD) { |
1645 InitializeGame(256, 256, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused |
1648 InitializeGame(256, 256, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused |
|
1649 GamelogReset(); |
1646 if (!LoadOldSaveGame(filename)) return SL_REINIT; |
1650 if (!LoadOldSaveGame(filename)) return SL_REINIT; |
1647 _sl_version = 0; |
1651 _sl_version = 0; |
1648 _sl_minor_version = 0; |
1652 _sl_minor_version = 0; |
1649 if (!AfterLoadGame()) return SL_REINIT; |
1653 GamelogStartAction(GLAT_LOAD); |
|
1654 if (!AfterLoadGame()) { |
|
1655 GamelogStopAction(); |
|
1656 return SL_REINIT; |
|
1657 } |
|
1658 GamelogStopAction(); |
1650 return SL_OK; |
1659 return SL_OK; |
1651 } |
1660 } |
1652 |
1661 |
1653 _sl.excpt_uninit = NULL; |
1662 _sl.excpt_uninit = NULL; |
1654 try { |
1663 try { |
1755 /* Old maps were hardcoded to 256x256 and thus did not contain |
1764 /* Old maps were hardcoded to 256x256 and thus did not contain |
1756 * any mapsize information. Pre-initialize to 256x256 to not to |
1765 * any mapsize information. Pre-initialize to 256x256 to not to |
1757 * confuse old games */ |
1766 * confuse old games */ |
1758 InitializeGame(256, 256, true); |
1767 InitializeGame(256, 256, true); |
1759 |
1768 |
|
1769 GamelogReset(); |
|
1770 |
1760 SlLoadChunks(); |
1771 SlLoadChunks(); |
1761 fmt->uninit_read(); |
1772 fmt->uninit_read(); |
1762 fclose(_sl.fh); |
1773 fclose(_sl.fh); |
1763 |
1774 |
|
1775 GamelogStartAction(GLAT_LOAD); |
|
1776 |
1764 _savegame_type = SGT_OTTD; |
1777 _savegame_type = SGT_OTTD; |
1765 |
1778 |
1766 /* After loading fix up savegame for any internal changes that |
1779 /* After loading fix up savegame for any internal changes that |
1767 * might've occured since then. If it fails, load back the old game */ |
1780 * might've occured since then. If it fails, load back the old game */ |
1768 if (!AfterLoadGame()) return SL_REINIT; |
1781 if (!AfterLoadGame()) { |
|
1782 GamelogStopAction(); |
|
1783 return SL_REINIT; |
|
1784 } |
|
1785 |
|
1786 GamelogStopAction(); |
1769 } |
1787 } |
1770 |
1788 |
1771 return SL_OK; |
1789 return SL_OK; |
1772 } |
1790 } |
1773 catch (...) { |
1791 catch (...) { |