--- a/src/openttd.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/openttd.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -64,7 +64,7 @@
#include "newgrf_commons.h"
#include "player_face.h"
#include "group.h"
-#include "blitter/blitter.hpp"
+#include "blitter/factory.hpp"
#include "bridge_map.h"
#include "clear_map.h"
@@ -86,7 +86,7 @@
extern Player* DoStartupNewPlayer(bool is_ai);
extern void ShowOSErrorBox(const char *buf);
-const char *_default_blitter = "8bpp-optimzed";
+const char *_default_blitter = "8bpp-optimized";
/* TODO: usrerror() for errors which are not of an internal nature but
* caused by the user, i.e. missing files or fatal configuration errors.
@@ -312,8 +312,6 @@
static void LoadIntroGame()
{
- char filename[256];
-
_game_mode = GM_MENU;
/* Clear transparency options */
@@ -326,14 +324,8 @@
ResetWindowSystem();
SetupColorsAndInitialWindow();
- /* Generate a world. */
- snprintf(filename, lengthof(filename), "%sopntitle.dat", _paths.data_dir);
-#if defined SECOND_DATA_DIR
- if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
- snprintf(filename, lengthof(filename), "%sopntitle.dat", _paths.second_data_dir);
- }
-#endif
- if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
+ /* Load the default opening screen savegame */
+ if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
WaitTillGeneratedWorld();
}
@@ -402,6 +394,7 @@
strcpy(musicdriver, "null");
strcpy(sounddriver, "null");
strcpy(videodriver, "dedicated");
+ strcpy(blitter, "null");
dedicated = true;
if (mgo.opt != NULL) {
/* Use the existing method for parsing (openttd -n).
@@ -474,6 +467,11 @@
if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed;
+ /* The width and height must be at least 1 pixel, this
+ * way all internal drawing routines work correctly. */
+ if (_cur_resolution[0] == 0) _cur_resolution[0] = 1;
+ if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
+
#if defined(ENABLE_NETWORK)
if (dedicated_host) snprintf(_network_server_bind_ip_host, NETWORK_HOSTNAME_LENGTH, "%s", dedicated_host);
if (dedicated_port) _network_server_port = dedicated_port;
@@ -754,7 +752,7 @@
ResetGRFConfig(true);
/* Load game */
- if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) {
+ if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, SCENARIO_DIR) != SL_OK) {
LoadIntroGame();
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
}
@@ -776,12 +774,20 @@
MarkWholeScreenDirty();
}
-bool SafeSaveOrLoad(const char *filename, int mode, int newgm)
+/** Load the specified savegame but on error do different things.
+ * If loading fails due to corrupt savegame, bad version, etc. go back to
+ * a previous correct state. In the menu for example load the intro game again.
+ * @param filename file to be loaded
+ * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
+ * @param newgm switch to this mode of loading fails due to some unknown error
+ * @param subdir default directory to look for filename, set to 0 if not needed */
+bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir)
{
byte ogm = _game_mode;
_game_mode = newgm;
- switch (SaveOrLoad(filename, mode)) {
+ assert(mode == SL_LOAD || mode == SL_OLD_LOAD);
+ switch (SaveOrLoad(filename, mode, subdir)) {
case SL_OK: return true;
case SL_REINIT:
@@ -854,7 +860,7 @@
_opt_ptr = &_opt;
ResetGRFConfig(true);
- if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
+ if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
LoadIntroGame();
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
} else {
@@ -888,7 +894,7 @@
break;
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
- if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
+ if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
_opt_ptr = &_opt;
SetLocalPlayer(OWNER_NONE);
@@ -904,7 +910,7 @@
break;
case SM_SAVE: /* Save game */
- if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) {
+ if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
} else {
DeleteWindowById(WC_SAVELOAD, 0);
@@ -961,9 +967,11 @@
}
}
+/** Create an autosave. The default name is "autosave#.sav". However with
+ * the patch setting 'keep_all_autosave' the name defaults to company-name + date */
static void DoAutosave()
{
- char buf[200];
+ char buf[MAX_PATH];
#if defined(PSP)
/* Autosaving in networking is too time expensive for the PSP */
@@ -973,27 +981,21 @@
if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
const Player *p = GetPlayer(_local_player);
- char* s = buf;
-
- s += snprintf(buf, lengthof(buf), "%s%s", _paths.autosave_dir, PATHSEP);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
SetDParam(2, _date);
- s = GetString(s, STR_4004, lastof(buf));
- strecpy(s, ".sav", lastof(buf));
- } else { // generate a savegame name and number according to _patches.max_num_autosaves
- snprintf(buf, lengthof(buf), "%s%sautosave%d.sav", _paths.autosave_dir, PATHSEP, _autosave_ctr);
+ GetString(buf, STR_4004, lastof(buf));
+ ttd_strlcpy(buf, ".sav", sizeof(buf));
+ } else {
+ /* generate a savegame name and number according to _patches.max_num_autosaves */
+ snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
- _autosave_ctr++;
- if (_autosave_ctr >= _patches.max_num_autosaves) {
- /* we reached the limit for numbers of autosaves. We will start over */
- _autosave_ctr = 0;
- }
+ if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0;
}
DEBUG(sl, 2, "Autosaving to '%s'", buf);
- if (SaveOrLoad(buf, SL_SAVE) != SL_OK)
+ if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK)
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
}
@@ -1300,7 +1302,7 @@
WP(w,vp_d).dest_scrollpos_y = _saved_scrollpos_y;
vp = w->viewport;
- vp->zoom = _saved_scrollpos_zoom;
+ vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);