equal
deleted
inserted
replaced
1559 * handled. It opens the savegame, selects format and checks versions |
1559 * handled. It opens the savegame, selects format and checks versions |
1560 * @param filename The name of the savegame being created/loaded |
1560 * @param filename The name of the savegame being created/loaded |
1561 * @param mode Save or load. Load can also be a TTD(Patch) game. Use SL_LOAD, SL_OLD_LOAD or SL_SAVE |
1561 * @param mode Save or load. Load can also be a TTD(Patch) game. Use SL_LOAD, SL_OLD_LOAD or SL_SAVE |
1562 * @return Return the results of the action. SL_OK, SL_ERROR or SL_REINIT ("unload" the game) |
1562 * @return Return the results of the action. SL_OK, SL_ERROR or SL_REINIT ("unload" the game) |
1563 */ |
1563 */ |
1564 SaveOrLoadResult SaveOrLoad(const char *filename, int mode) |
1564 SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb) |
1565 { |
1565 { |
1566 uint32 hdr[2]; |
1566 uint32 hdr[2]; |
1567 const SaveLoadFormat *fmt; |
1567 const SaveLoadFormat *fmt; |
1568 |
1568 |
1569 /* An instance of saving is already active, so don't go saving again */ |
1569 /* An instance of saving is already active, so don't go saving again */ |
1581 _sl_version = 0; |
1581 _sl_version = 0; |
1582 AfterLoadGame(); |
1582 AfterLoadGame(); |
1583 return SL_OK; |
1583 return SL_OK; |
1584 } |
1584 } |
1585 |
1585 |
1586 _sl.fh = (mode == SL_SAVE) ? fopen(filename, "wb") : fopen(filename, "rb"); |
1586 _sl.fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb); |
|
1587 |
|
1588 /* Make it a little easier to load savegames from the console */ |
|
1589 if (_sl.fh == NULL && mode == SL_LOAD) _sl.fh = FioFOpenFile(filename, "rb", SAVE_DIR); |
|
1590 if (_sl.fh == NULL && mode == SL_LOAD) _sl.fh = FioFOpenFile(filename, "rb", BASE_DIR); |
|
1591 |
1587 if (_sl.fh == NULL) { |
1592 if (_sl.fh == NULL) { |
1588 DEBUG(sl, 0, "Cannot open savegame '%s' for saving/loading.", filename); |
1593 DEBUG(sl, 0, "Cannot open savegame '%s' for saving/loading.", filename); |
1589 return SL_ERROR; |
1594 return SL_ERROR; |
1590 } |
1595 } |
1591 |
1596 |
1719 } |
1724 } |
1720 |
1725 |
1721 /** Do a save when exiting the game (patch option) _patches.autosave_on_exit */ |
1726 /** Do a save when exiting the game (patch option) _patches.autosave_on_exit */ |
1722 void DoExitSave() |
1727 void DoExitSave() |
1723 { |
1728 { |
1724 char buf[200]; |
1729 SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR); |
1725 snprintf(buf, sizeof(buf), "%s%sexit.sav", _paths.autosave_dir, PATHSEP); |
|
1726 SaveOrLoad(buf, SL_SAVE); |
|
1727 } |
1730 } |
1728 |
1731 |
1729 #if 0 |
1732 #if 0 |
1730 /** |
1733 /** |
1731 * Function to get the type of the savegame by looking at the file header. |
1734 * Function to get the type of the savegame by looking at the file header. |