annotate ttd.c @ 656:02ef48b4628c draft

(svn r1090) -Fix: Made the _openttd_revision variable global, and with that hopefully killed the windows-revision problem. If WITH_REV is defined, for both Windows as *nix system _openttd_revision is filled with normal info, else _openttd_revision is set to 'norev000' -Fix: Small possible server-crash
author truelight <truelight@openttd.org>
date Tue, 14 Dec 2004 20:27:00 +0000
parents ade31604520f
children edb5d6d4f00a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1 #include "stdafx.h"
507
9dcc34b8887e (svn r815) Include strings.h only in the files which need it.
tron <tron@openttd.org>
parents: 497
diff changeset
2 #include "table/strings.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
3
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
4 #define VARDEF
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
5 #include "ttd.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
6 #include "gfx.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
7 #include "gui.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
8 #include "station.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
9 #include "vehicle.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
10 #include "viewport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
11 #include "window.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
12 #include "player.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
13 #include "command.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
14 #include "town.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
15 #include "industry.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
16 #include "news.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
17 #include "engine.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
18 #include "sound.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
19 #include "economy.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
20 #include "fileio.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
21 #include "hal.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
22 #include "airport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
23 #include "saveload.h"
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
24 #include "ai.h"
126
127be480312c (svn r127) New feature: ingame console. (sign_de)
dominik <dominik@openttd.org>
parents: 123
diff changeset
25 #include "console.h"
430
7817370c8abe (svn r631) Merge r440, r444, r485, r630 to trunk:
tron <tron@openttd.org>
parents: 410
diff changeset
26 #include "screenshot.h"
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
27 #include "network.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
28
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
29 #include <stdarg.h>
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
30
656
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
31 /* Define the _openttd_revision tag if it is not defined */
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
32 #ifndef WITH_REV
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
33 const char _openttd_revision[] = "norev000";
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
34 #endif
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
35
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
36 void GameLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
37
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
38 void IncreaseSpriteLRU();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
39 void InitializeGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
40 void GenerateWorld(int mode);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
41 void CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
42 void IncreaseDate();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
43 void RunOtherPlayersLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
44 void DoPaletteAnimations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
45 void MusicLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
46 void ResetMusic();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
47 void InitializeStations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
48 void DeleteAllPlayerStations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
49
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
50 extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
51 extern void DoStartupNewPlayer(bool is_ai);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
52 extern void UpdateAllSignVirtCoords();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
53 extern void ShowOSErrorBox(const char *buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
54
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
55 void redsq_debug(int tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
56 bool LoadSavegame(const char *filename);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
57
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
58 extern void HalGameLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
59
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
60 uint32 _pixels_redrawn;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
61 bool _dbg_screen_rect;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
62 bool disable_computer; // We should get ride of this thing.. is only used for a debug-cheat
223
f5f5d6e51c92 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater <darkvater@openttd.org>
parents: 222
diff changeset
63 static byte _os_version = 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
64
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
65 void CDECL error(const char *s, ...) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
66 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
67 char buf[512];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
68 va_start(va, s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
69 vsprintf(buf, s, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
70 va_end(va);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
71
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
72 ShowOSErrorBox(buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
73 if (_video_driver)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
74 _video_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
75
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
76 assert(0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
77 exit(1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
78 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
79
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
80 void CDECL debug(const char *s, ...)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
81 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
82 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
83 char buf[1024];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
84 va_start(va, s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
85 vsprintf(buf, s, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
86 va_end(va);
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
87 fprintf(stderr, "dbg: %s\n", buf);
126
127be480312c (svn r127) New feature: ingame console. (sign_de)
dominik <dominik@openttd.org>
parents: 123
diff changeset
88 IConsoleDebug((byte *) &buf);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
89 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
90
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
91 void CDECL ShowInfoF(const char *str, ...)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
92 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
93 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
94 char buf[1024];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
95 va_start(va, str);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
96 vsprintf(buf, str, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
97 va_end(va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
98 ShowInfo(buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
99 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
100
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
101 char * CDECL str_fmt(const char *str, ...)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
102 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
103 char buf[4096];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
104 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
105 int len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
106 char *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
107
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
108 va_start(va, str);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
109 len = vsprintf(buf, str, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
110 va_end(va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
111 p = malloc(len + 1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
112 if (p)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
113 memcpy(p, buf, len + 1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
114 return p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
115 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
116
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
117
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
118 // NULL midi driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
119 static char *NullMidiStart(char **parm) { return NULL; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
120 static void NullMidiStop() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
121 static void NullMidiPlaySong(const char *filename) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
122 static void NullMidiStopSong() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
123 static bool NullMidiIsSongPlaying() { return true; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
124 static void NullMidiSetVolume(byte vol) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
125
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
126 const HalMusicDriver _null_music_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
127 NullMidiStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
128 NullMidiStop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
129 NullMidiPlaySong,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
130 NullMidiStopSong,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
131 NullMidiIsSongPlaying,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
132 NullMidiSetVolume,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
133 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
134
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
135 // NULL video driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
136 static void *_null_video_mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
137 static const char *NullVideoStart(char **parm) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
138 _screen.width = _screen.pitch = _cur_resolution[0];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
139 _screen.height = _cur_resolution[1];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
140 _null_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
141 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
142 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
143 static void NullVideoStop() { free(_null_video_mem); }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
144 static void NullVideoMakeDirty(int left, int top, int width, int height) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
145 static int NullVideoMainLoop() {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
146 int i = 1000;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
147 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
148 GameLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
149 _screen.dst_ptr = _null_video_mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
150 UpdateWindows();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
151 } while (--i);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
152 return ML_QUIT;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
153 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
154
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
155 static bool NullVideoChangeRes(int w, int h) { return false; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
156
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
157
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
158 const HalVideoDriver _null_video_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
159 NullVideoStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
160 NullVideoStop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
161 NullVideoMakeDirty,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
162 NullVideoMainLoop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
163 NullVideoChangeRes,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
164 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
165
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
166 // NULL sound driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
167 static char *NullSoundStart(char **parm) { return NULL; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
168 static void NullSoundStop() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
169 const HalSoundDriver _null_sound_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
170 NullSoundStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
171 NullSoundStop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
172 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
173
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
174 enum {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
175 DF_PRIORITY_MASK = 0xf,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
176 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
177
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
178 typedef struct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
179 const DriverDesc *descs;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
180 const char *name;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
181 void *var;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
182 } DriverClass;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
183
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
184 static DriverClass _driver_classes[] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
185 {_video_driver_descs, "video", &_video_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
186 {_sound_driver_descs, "sound", &_sound_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
187 {_music_driver_descs, "music", &_music_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
188 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
189
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
190 static const DriverDesc *GetDriverByName(const DriverDesc *dd, const char *name)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
191 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
192 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
193 if (!strcmp(dd->name, name))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
194 return dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
195 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
196 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
197 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
198
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
199 static const DriverDesc *ChooseDefaultDriver(const DriverDesc *dd)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
200 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
201 const DriverDesc *best = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
202 int best_pri = -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
203 do {
223
f5f5d6e51c92 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater <darkvater@openttd.org>
parents: 222
diff changeset
204 if ((int)(dd->flags&DF_PRIORITY_MASK) > best_pri && _os_version >= (byte)dd->flags) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
205 best_pri = dd->flags&DF_PRIORITY_MASK;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
206 best = dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
207 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
208 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
209 return best;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
210 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
211
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
212 void ttd_strlcpy(char *dst, const char *src, size_t len)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
213 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
214 assert(len > 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
215 while (--len && *src)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
216 *dst++=*src++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
217 *dst = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
218 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
219
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
220 char *strecpy(char *dst, const char *src)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
221 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
222 while ( (*dst++ = *src++) != 0) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
223 return dst - 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
224 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
225
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
226 byte *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
227 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
228 FILE *in;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
229 void *mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
230 size_t len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
231
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
232 in = fopen(filename, "rb");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
233 if (in == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
234 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
235
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
236 fseek(in, 0, SEEK_END);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
237 len = ftell(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
238 fseek(in, 0, SEEK_SET);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
239 if (len > maxsize || (mem=(byte*)malloc(len + 1)) == NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
240 fclose(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
241 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
242 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
243 ((byte*)mem)[len] = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
244 if (fread(mem, len, 1, in) != 1) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
245 fclose(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
246 free(mem);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
247 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
248 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
249 fclose(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
250
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
251 *lenp = len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
252 return mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
253 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
254
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
255 void LoadDriver(int driver, const char *name)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
256 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
257 const DriverClass *dc = &_driver_classes[driver];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
258 const DriverDesc *dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
259 const void **var;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
260 const void *drv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
261 const char *err;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
262 char *parm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
263 char buffer[256];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
264 char *parms[32];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
265
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
266 parms[0] = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
267
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
268 if (!*name) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
269 dd = ChooseDefaultDriver(dc->descs);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
270 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
271 // Extract the driver name and put parameter list in parm
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
272 ttd_strlcpy(buffer, name, sizeof(buffer));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
273 parm = strchr(buffer, ':');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
274 if (parm) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
275 int np = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
276 // Tokenize the parm.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
277 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
278 *parm++ = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
279 if (np < lengthof(parms) - 1)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
280 parms[np++] = parm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
281 while (*parm != 0 && *parm != ',')
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
282 parm++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
283 } while (*parm == ',');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
284 parms[np] = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
285 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
286 dd = GetDriverByName(dc->descs, buffer);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
287 if (dd == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
288 error("No such %s driver: %s\n", dc->name, buffer);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
289 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
290 var = dc->var;
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 213
diff changeset
291 if (*var != NULL) ((const HalCommonDriver*)*var)->stop();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
292 *var = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
293 drv = dd->drv;
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 213
diff changeset
294 if ((err=((const HalCommonDriver*)drv)->start(parms)) != NULL)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
295 error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
296 *var = drv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
297 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
298
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
299 static void showhelp()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
300 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
301 char buf[4096], *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
302 const DriverClass *dc = _driver_classes;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
303 const DriverDesc *dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
304 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
305
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
306 p = strecpy(buf,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
307 "Command line options:\n"
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
308 " -v drv = Set video driver (see below)\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
309 " -s drv = Set sound driver (see below)\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
310 " -m drv = Set music driver (see below)\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
311 " -r res = Set resolution (for instance 800x600)\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
312 " -h = Display this help text\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
313 " -t date = Set starting date\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
314 " -d [dbg] = Debug mode\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
315 " -l lng = Select Language\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
316 " -e = Start Editor\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
317 " -g [savegame] = Start new/save game immediately\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
318 " -G seed = Set random seed\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
319 " -n [ip#player:port] = Start networkgame\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
320 " -D = Start dedicated server\n"
614
96f116271012 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik <dominik@openttd.org>
parents: 561
diff changeset
321 " -i = Force to use the DOS palette (use this if you see a lot of pink)\n"
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
322 " -p #player = Player as #player (deprecated) (network only)\n"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
323 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
324
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
325 for(i=0; i!=lengthof(_driver_classes); i++,dc++) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
326 p += sprintf(p, "List of %s drivers:\n", dc->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
327 dd = dc->descs;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
328 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
329 p += sprintf(p, "%10s: %s\n", dd->name, dd->longname);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
330 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
331 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
332
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
333 ShowInfo(buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
334 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
335
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
336
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
337 char *GetDriverParam(char **parm, const char *name)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
338 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
339 char *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
340 int len = strlen(name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
341 while ((p = *parm++) != NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
342 if (!strncmp(p,name,len)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
343 if (p[len] == '=') return p + len + 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
344 if (p[len] == 0) return p + len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
345 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
346 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
347 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
348 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
349
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
350 bool GetDriverParamBool(char **parm, const char *name)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
351 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
352 char *p = GetDriverParam(parm, name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
353 return p != NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
354 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
355
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
356 int GetDriverParamInt(char **parm, const char *name, int def)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
357 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
358 char *p = GetDriverParam(parm, name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
359 return p != NULL ? atoi(p) : def;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
360 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
361
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
362 typedef struct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
363 char *opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
364 int numleft;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
365 char **argv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
366 const char *options;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
367 char *cont;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
368 } MyGetOptData;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
369
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
370 static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
371 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
372 md->cont = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
373 md->numleft = argc;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
374 md->argv = argv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
375 md->options = options;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
376 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
377
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
378 static int MyGetOpt(MyGetOptData *md)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
379 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
380 char *s,*r,*t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
381
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
382 if ((s=md->cont) != NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
383 goto md_continue_here;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
384
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
385 while(true) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
386 if (--md->numleft < 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
387 return -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
388
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
389 s = *md->argv++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
390 if (*s == '-') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
391 md_continue_here:;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
392 s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
393 if (*s != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
394 // Found argument, try to locate it in options.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
395 if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
396 // ERROR!
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
397 return -2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
398 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
399 if (r[1] == ':') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
400 // Item wants an argument. Check if the argument follows, or if it comes as a separate arg.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
401 if (!*(t = s + 1)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
402 // It comes as a separate arg. Check if out of args?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
403 if (--md->numleft < 0 || *(t = *md->argv) == '-') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
404 // Check if item is optional?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
405 if (r[2] != ':')
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
406 return -2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
407 md->numleft++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
408 t = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
409 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
410 md->argv++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
411 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
412 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
413 md->opt = t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
414 md->cont = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
415 return *s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
416 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
417 md->opt = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
418 md->cont = s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
419 return *s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
420 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
421 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
422 // This is currently not supported.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
423 return -2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
424 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
425 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
426 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
427
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
428 void SetDebugString(const char *s)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
429 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
430 int v;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
431 char *end;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
432 const char *t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
433 int *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
434
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
435 // global debugging level?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
436 if (*s >= '0' && *s <= '9') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
437 v = strtoul(s, &end, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
438 s = end;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
439
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
440 _debug_spritecache_level = v;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
441 _debug_misc_level = v;
65
1c2cba90e3bf (svn r66) -Fix Station list updated on station deletion/station rename
darkvater <darkvater@openttd.org>
parents: 8
diff changeset
442 _debug_grf_level = v;
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 67
diff changeset
443 _debug_ai_level = v;
185
628f1aa53b04 (svn r186) -Add: debug 'net' for network debug (sign_de)
truelight <truelight@openttd.org>
parents: 172
diff changeset
444 _debug_net_level = v;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
445 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
446
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
447 // individual levels
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
448 for(;;) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
449 // skip delimiters
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
450 while (*s == ' ' || *s == ',' || *s == '\t') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
451 if (*s == 0) break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
452
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
453 t = s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
454 while (*s >= 'a' && *s <= 'z') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
455
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
456 #define IS_LVL(x) (s - t == sizeof(x)-1 && !memcmp(t, x, sizeof(x)-1))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
457 // check debugging levels
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
458 if IS_LVL("misc") p = &_debug_misc_level;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
459 else if IS_LVL("spritecache") p = &_debug_spritecache_level;
65
1c2cba90e3bf (svn r66) -Fix Station list updated on station deletion/station rename
darkvater <darkvater@openttd.org>
parents: 8
diff changeset
460 else if IS_LVL("grf") p = &_debug_grf_level;
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 67
diff changeset
461 else if IS_LVL("ai") p = &_debug_ai_level;
185
628f1aa53b04 (svn r186) -Add: debug 'net' for network debug (sign_de)
truelight <truelight@openttd.org>
parents: 172
diff changeset
462 else if IS_LVL("net") p = &_debug_net_level;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
463 else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
464 ShowInfoF("Unknown debug level '%.*s'", s-t, t);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
465 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
466 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
467 #undef IS_LVL
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
468 if (*s == '=') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
469 v = strtoul(s, &end, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
470 s = end;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
471 if (p) *p = v;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
472 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
473 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
474
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
475 void ParseResolution(int res[2], char *s)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
476 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
477 char *t = strchr(s, 'x');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
478 if (t == NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
479 ShowInfoF("Invalid resolution '%s'", s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
480 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
481 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
482
310
2f87c450cadc (svn r316) -Fix: not +7 (Tron)
darkvater <darkvater@openttd.org>
parents: 309
diff changeset
483 res[0] = strtoul(s, NULL, 0);
2f87c450cadc (svn r316) -Fix: not +7 (Tron)
darkvater <darkvater@openttd.org>
parents: 309
diff changeset
484 res[1] = strtoul(t + 1, NULL, 0);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
485 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
486
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
487 void LoadIntroGame()
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
488 {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
489 char filename[256];
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
490 _game_mode = GM_MENU;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
491 _display_opt &= ~DO_TRANS_BUILDINGS; // don't make buildings transparent in intro
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
492
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
493 _opt_mod_ptr = &_new_opt;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
494 GfxLoadSprites();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
495 LoadStringWidthTable();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
496
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
497 // Setup main window
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
498 InitWindowSystem();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
499 SetupColorsAndInitialWindow();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
500
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
501 // Generate a world.
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
502 sprintf(filename, "%sopntitle.dat", _path.data_dir);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
503 if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
561
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
504 #if defined SECOND_DATA_DIR
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
505 {
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
506 sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
507 if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
508 #endif
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
509 GenerateWorld(1); // if failed loading, make empty world.
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
510 #if defined SECOND_DATA_DIR
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
511 }
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
512 #endif
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
513 _opt.currency = _new_opt.currency;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
514
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
515 _pause = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
516 _local_player = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
517 MarkWholeScreenDirty();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
518
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
519 // Play main theme
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
520 if (_music_driver->is_song_playing()) ResetMusic();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
521 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
522
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
523 int ttd_main(int argc, char* argv[])
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
524 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
525 MyGetOptData mgo;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
526 int i;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
527 bool network = false;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
528 char *network_conn = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
529 char *language = NULL;
469
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
530 char musicdriver[16], sounddriver[16], videodriver[16];
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
531 int resolution[2] = {0,0};
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
532 uint startdate = -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
533 musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
534
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
535 _game_mode = GM_MENU;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
536 _switch_mode = SM_MENU;
172
21871e50dfac (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater <darkvater@openttd.org>
parents: 168
diff changeset
537 _switch_mode_errorstr = INVALID_STRING_ID;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
538
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
539 // The last param of the following function means this:
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
540 // a letter means: it accepts that param (e.g.: -h)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
541 // a ':' behind it means: it need a param (e.g.: -m<driver>)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
542 // a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
543 MyGetOptInit(&mgo, argc-1, argv+1, "m:s:v:hDn::l:eit:d::r:g::G:p:");
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
544 while ((i = MyGetOpt(&mgo)) != -1) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
545 switch(i) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
546 case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
547 case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
548 case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
549 case 'D': {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
550 sprintf(musicdriver,"null");
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
551 sprintf(sounddriver,"null");
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
552 sprintf(videodriver,"dedicated");
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
553 } break;
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
554 case 'n': {
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
555 network = true;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
556 if (mgo.opt)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
557 // Optional, you can give an IP
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
558 network_conn = mgo.opt;
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
559 else
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
560 network_conn = NULL;
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
561 } break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
562 case 'r': ParseResolution(resolution, mgo.opt); break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
563 case 'l': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
564 language = mgo.opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
565 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
566 case 't': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
567 startdate = atoi(mgo.opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
568 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
569 case 'd': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
570 #if defined(WIN32)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
571 CreateConsole();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
572 #endif
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
573 if (mgo.opt)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
574 SetDebugString(mgo.opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
575 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
576 case 'e': _switch_mode = SM_EDITOR; break;
614
96f116271012 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik <dominik@openttd.org>
parents: 561
diff changeset
577 case 'i': _use_dos_palette = true; break;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
578 case 'g':
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
579 if (mgo.opt) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
580 strcpy(_file_to_saveload.name, mgo.opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
581 _switch_mode = SM_LOAD;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
582 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
583 _switch_mode = SM_NEWGAME;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
584 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
585 case 'G':
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
586 _random_seeds[0][0] = atoi(mgo.opt);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
587 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
588 case 'p': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
589 int i = atoi(mgo.opt);
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
590 // Play as an other player in network games
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
591 if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
592 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
593 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
594 case -2:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
595 case 'h':
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
596 showhelp();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
597 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
598 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
599 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
600
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
601 DeterminePaths();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
602 LoadFromConfig();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
603
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
604 // override config?
469
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
605 if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
606 if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
607 if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
608 if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
609 if (startdate != -1) _patches.starting_date = startdate;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
610
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
611 // enumerate language files
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
612 InitializeLanguagePacks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
613
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
614 // initialize screenshot formats
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
615 InitializeScreenshotFormats();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
616
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
617 // initialize airport state machines
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
618 InitializeAirports();
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
619
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
620 // Sample catalogue
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
621 DEBUG(misc, 1) ("Loading sound effects...");
223
f5f5d6e51c92 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater <darkvater@openttd.org>
parents: 222
diff changeset
622 _os_version = GetOSVersion();
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
623 MxInitialize(11025, "sample.cat");
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
624
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
625 // This must be done early, since functions use the InvalidateWindow* calls
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
626 InitWindowSystem();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
627
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
628 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
629 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
630
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
631 DEBUG(misc, 1) ("Loading drivers...");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
632 LoadDriver(SOUND_DRIVER, _ini_sounddriver);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
633 LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
634 LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
635 MusicLoop();
168
76ede0c80f43 (svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater <darkvater@openttd.org>
parents: 152
diff changeset
636 _savegame_sort_order = 1; // default sorting of savegames is by date, newest first
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
637
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
638 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
639 // initialize network-core
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
640 NetworkStartUp();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
641 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
642
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
643 // Default difficulty level
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
644 _opt_mod_ptr = &_new_opt;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
645
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
646 // ugly hack, if diff_level is 9, it means we got no setting from the config file, so we load the default settings.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
647 if (_opt_mod_ptr->diff_level == 9)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
648 SetDifficultyLevel(0, _opt_mod_ptr);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
649
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
650 // initialize the ingame console
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
651 IConsoleInit();
644
ade31604520f (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik <dominik@openttd.org>
parents: 630
diff changeset
652 IConsoleCmdExec("exec scripts/autoexec.scr 0");
656
02ef48b4628c (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight <truelight@openttd.org>
parents: 644
diff changeset
653
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
654 InitPlayerRandoms();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
655
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
656 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
657 if ((network) && (_network_available)) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
658 if (network_conn != NULL) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
659 const byte *port = NULL;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
660 const byte *player = NULL;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
661 uint16 rport;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
662
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
663 rport = NETWORK_DEFAULT_PORT;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
664
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
665 ParseConnectionString(&player, &port, network_conn);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
666
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
667 if (player != NULL) _network_playas = atoi(player);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
668 if (port != NULL) rport = atoi(port);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
669
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
670 LoadIntroGame();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
671 _switch_mode = SM_NONE;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
672 NetworkClientConnectGame(network_conn, rport);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
673 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
674 // NetworkCoreConnectGame("auto", _network_server_port);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
675 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
676 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
677 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
678
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
679 while (_video_driver->main_loop() == ML_SWITCHDRIVER) {}
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
680
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
681 IConsoleFree();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
682
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
683 #ifdef ENABLE_NETWORK
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
684 if (_network_available) {
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
685 // Shut down the network and close any open connections
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
686 NetworkDisconnect();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
687 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
688 NetworkShutDown();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
689 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
690 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
691
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
692 _video_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
693 _music_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
694 _sound_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
695
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
696 SaveToConfig();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
697
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
698 // uninitialize airport state machines
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
699 UnInitializeAirports();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
700
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
701 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
702 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
703
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
704 static void ShowScreenshotResult(bool b)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
705 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
706 if (b) {
534
6de858608a45 (svn r901) Small step in the process to clean up the DPARAM mess:
tron <tron@openttd.org>
parents: 507
diff changeset
707 SetDParam(0, STR_SPEC_SCREENSHOT_NAME);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
708 ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
709 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
710 ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
711 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
712
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
713 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
714
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
715 void MakeNewGame()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
716 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
717 _game_mode = GM_NORMAL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
718
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
719 // Copy in game options
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
720 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
721 memcpy(&_opt, &_new_opt, sizeof(_opt));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
722
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
723 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
724
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
725 // Reinitialize windows
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
726 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
727 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
728
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
729 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
730
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
731 // Randomize world
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
732 GenerateWorld(0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
733
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
734 // In a dedicated server, the server does not play
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
735 if (_network_dedicated) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
736 _local_player = OWNER_SPECTATOR;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
737 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
738 // Create a single player
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
739 DoStartupNewPlayer(false);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
740
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
741 _local_player = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
742 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
743
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
744 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
745 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
746
410
e165d1275350 (svn r607) -Patch: [ 985102 ] static cleanup
tron <tron@openttd.org>
parents: 310
diff changeset
747 static void MakeNewEditorWorld()
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
748 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
749 _game_mode = GM_EDITOR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
750
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
751 // Copy in game options
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
752 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
753 memcpy(&_opt, &_new_opt, sizeof(_opt));
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
754
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
755 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
756
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
757 // Re-init the windowing system
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
758 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
759
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
760 // Create toolbars
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
761 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
762
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
763 // Startup the game system
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
764 GenerateWorld(1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
765
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
766 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
767 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
768 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
769
116
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
770 void StartupPlayers();
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
771 void StartupDisasters();
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
772
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
773 void StartScenario()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
774 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
775 _game_mode = GM_NORMAL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
776
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
777 // invalid type
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
778 if (_file_to_saveload.mode == SL_INVALID) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
779 printf("Savegame is obsolete or invalid format: %s\n", _file_to_saveload.name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
780 ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
781 _game_mode = GM_MENU;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
782 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
783 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
784
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
785 // Copy in game options
295
734ec1ea885f (svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik <dominik@openttd.org>
parents: 239
diff changeset
786 // Removed copying of game options when using "new game". --dominik
734ec1ea885f (svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik <dominik@openttd.org>
parents: 239
diff changeset
787 // _opt_mod_ptr = &_opt;
734ec1ea885f (svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik <dominik@openttd.org>
parents: 239
diff changeset
788 // memcpy(&_opt, &_new_opt, sizeof(_opt));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
789
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
790 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
791
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
792 // Reinitialize windows
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
793 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
794 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
795
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
796 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
797
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
798 // Load game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
799 if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
800 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
801 ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
802 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
803
115
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
804 // Inititalize data
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
805 StartupPlayers();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
806 StartupEngines();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
807 StartupDisasters();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
808
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
809 // When starting a scenario, is it really a load..
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
810 // and in AfterLoad a player is started when it is
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
811 // a scenario.. so we do not need it here.
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
812 // DoStartupNewPlayer(false);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
813
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
814 _local_player = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
815
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
816 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
817 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
818
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
819 bool SafeSaveOrLoad(const char *filename, int mode, int newgm)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
820 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
821 byte ogm = _game_mode;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
822 int r;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
823
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
824 _game_mode = newgm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
825 r = SaveOrLoad(filename, mode);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
826 if (r == SL_REINIT) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
827 if (ogm == GM_MENU)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
828 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
829 else if (ogm == GM_EDITOR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
830 MakeNewEditorWorld();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
831 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
832 MakeNewGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
833 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
834 } else if (r != SL_OK) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
835 _game_mode = ogm;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
836 return false;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
837 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
838 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
839 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
840
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
841 void SwitchMode(int new_mode)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
842 {
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
843 _in_state_game_loop = true;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
844
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
845 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
846 // If we are saving something, the network stays in his current state
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
847 if (new_mode != SM_SAVE) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
848 // If the network is active, make it not-active
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
849 if (_networking) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
850 if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
851 NetworkReboot();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
852 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
853 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
854 NetworkDisconnect();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
855 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
856 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
857 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
858
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
859 // If we are a server, we restart the server
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
860 if (_is_network_server) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
861 // But not if we are going to the menu
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
862 if (new_mode != SM_MENU) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
863 NetworkServerStart();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
864 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
865 // This client no longer wants to be a network-server
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
866 _is_network_server = false;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
867 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
868 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
869 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
870 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
871
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
872 switch(new_mode) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
873 case SM_EDITOR: // Switch to scenario editor
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
874 MakeNewEditorWorld();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
875 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
876
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
877 case SM_NEWGAME:
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
878 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
879 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
880 snprintf(_network_game_info.map_name, 40, "Random");
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
881 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
882 MakeNewGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
883 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
884
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
885 case SM_START_SCENARIO:
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
886 StartScenario();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
887 break;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
888
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
889 normal_load:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
890 case SM_LOAD: { // Load game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
891
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
892 _error_message = INVALID_STRING_ID;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
893 if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
894 ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
895 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
896 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
897 _local_player = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
898 DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
899 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
900 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
901 snprintf(_network_game_info.map_name, 40, "Loaded game");
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
902 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
903 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
904 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
905 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
906
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
907 case SM_LOAD_SCENARIO: {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
908 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
909
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
910 if (_game_mode == GM_MENU) goto normal_load;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
911
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
912 if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
913 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
914
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
915 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
916 _generating_world = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
917 // delete all players.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
918 for(i=0; i != MAX_PLAYERS; i++) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
919 ChangeOwnershipOfPlayerItems(i, 0xff);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
920 _players[i].is_active = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
921 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
922 _generating_world = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
923 // delete all stations owned by a player
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
924 DeleteAllPlayerStations();
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
925
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
926 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
927 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
928 snprintf(_network_game_info.map_name, 40, "Loaded scenario");
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
929 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
930 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
931 ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
932
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
933 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
934 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
935
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
936
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
937 case SM_MENU: // Switch to game menu
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
938 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
939 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
940
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
941 case SM_SAVE: // Save game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
942 if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
943 ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
944 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
945 DeleteWindowById(WC_SAVELOAD, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
946 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
947
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
948 case SM_GENRANDLAND:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
949 GenerateWorld(2);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
950 // XXX: set date
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
951 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
952 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
953 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
954 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
955
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
956 if (_switch_mode_errorstr!=INVALID_STRING_ID)
172
21871e50dfac (svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater <darkvater@openttd.org>
parents: 168
diff changeset
957 ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
958
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
959 _in_state_game_loop = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
960 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
961
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
962
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
963 // State controlling game loop.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
964 // The state must not be changed from anywhere
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
965 // but here.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
966 // That check is enforced in DoCommand.
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
967 void StateGameLoop()
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
968 {
213
be54ec0c899d (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater <darkvater@openttd.org>
parents: 208
diff changeset
969 // dont execute the state loop during pause
be54ec0c899d (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater <darkvater@openttd.org>
parents: 208
diff changeset
970 if (_pause) return;
be54ec0c899d (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater <darkvater@openttd.org>
parents: 208
diff changeset
971
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
972 _in_state_game_loop = true;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
973 // _frame_counter is increased somewhere else when in network-mode
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
974 // Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
975 // Should that not be deleted? If so, the next 2 lines can also be deleted
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
976 if (!_networking)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
977 _frame_counter++;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
978
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
979 if (_savedump_path[0] && (uint)_frame_counter >= _savedump_first && (uint)(_frame_counter -_savedump_first) % _savedump_freq == 0 ) {
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
980 char buf[100];
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
981 sprintf(buf, "%s%.5d.sav", _savedump_path, _frame_counter);
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
982 SaveOrLoad(buf, SL_SAVE);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
983 if ((uint)_frame_counter >= _savedump_last) exit(1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
984 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
985
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
986 if (_game_mode == GM_EDITOR) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
987 RunTileLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
988 CallVehicleTicks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
989 CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
990 CallWindowTickEvent();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
991 NewsLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
992 } else {
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
993 // All these actions has to be done from OWNER_NONE
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
994 // for multiplayer compatibility
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
995 uint p = _current_player;
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
996 _current_player = OWNER_NONE;
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
997
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
998 AnimateAnimatedTiles();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
999 IncreaseDate();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1000 RunTileLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1001 CallVehicleTicks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1002 CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1003
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1004 // To bad the AI does not work in multiplayer, because states are not saved
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1005 // perfectly
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1006 if (!disable_computer && !_networking)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1007 RunOtherPlayersLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1008
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1009 CallWindowTickEvent();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1010 NewsLoop();
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1011 _current_player = p;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1012 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1013
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1014 _in_state_game_loop = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1015 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1016
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1017 static void DoAutosave()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1018 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1019 char buf[200];
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1020
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
1021 if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1022 Player *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1023 char *s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1024 sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1025 p = DEREF_PLAYER(_local_player);
534
6de858608a45 (svn r901) Small step in the process to clean up the DPARAM mess:
tron <tron@openttd.org>
parents: 507
diff changeset
1026 SetDParam(0, p->name_1);
6de858608a45 (svn r901) Small step in the process to clean up the DPARAM mess:
tron <tron@openttd.org>
parents: 507
diff changeset
1027 SetDParam(1, p->name_2);
6de858608a45 (svn r901) Small step in the process to clean up the DPARAM mess:
tron <tron@openttd.org>
parents: 507
diff changeset
1028 SetDParam(2, _date);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1029 s= (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP) - 1, STR_4004);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1030 strcpy(s, ".sav");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1031 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1032 int n = _autosave_ctr;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1033 _autosave_ctr = (_autosave_ctr + 1) & 15;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1034 sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1035 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1036
557
4814c34ea3bb (svn r959) -Fix: fix previous typo for workaround of braindead MSVC6 (Tron)
darkvater <darkvater@openttd.org>
parents: 543
diff changeset
1037 DEBUG(misc, 2) ("Autosaving to %s", buf);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1038 if (SaveOrLoad(buf, SL_SAVE) != SL_OK)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1039 ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1040 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1041
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1042 void GameLoop()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1043 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1044 int m;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1045
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1046 // autosave game?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1047 if (_do_autosave) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1048 _do_autosave = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1049 DoAutosave();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1050 RedrawAutosave();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1051 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1052
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1053 // make a screenshot?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1054 if ((m=_make_screenshot) != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1055 _make_screenshot = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1056 switch(m) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1057 case 1: // make small screenshot
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1058 UndrawMouseCursor();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1059 ShowScreenshotResult(MakeScreenshot());
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1060 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1061 case 2: // make large screenshot
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1062 ShowScreenshotResult(MakeWorldScreenshot(-(TILE_X_MAX)*32, 0, TILE_X_MAX*32 + (TILE_X_MAX)*32, TILES_Y * 32, 0));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1063 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1064 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1065 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1066
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1067 // switch game mode?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1068 if ((m=_switch_mode) != SM_NONE) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1069 _switch_mode = SM_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1070 SwitchMode(m);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1071 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1072
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1073 IncreaseSpriteLRU();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1074 InteractiveRandom();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1075
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1076 if (_scroller_click_timeout > 3)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1077 _scroller_click_timeout -= 3;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1078 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1079 _scroller_click_timeout = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1080
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1081 _caret_timer += 3;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1082 _timer_counter+=8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1083 CursorTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1084
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1085 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1086 // Check for UDP stuff
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1087 NetworkUDPGameLoop();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1088
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1089 if (_networking) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1090 // Multiplayer
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1091 NetworkGameLoop();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1092 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1093 if (_network_reconnect > 0 && --_network_reconnect == 0) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1094 // This means that we want to reconnect to the last host
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1095 // We do this here, because it means that the network is really closed
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1096 NetworkClientConnectGame(_network_last_host, _network_last_port);
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1097 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1098 // Singleplayer
213
be54ec0c899d (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater <darkvater@openttd.org>
parents: 208
diff changeset
1099 StateGameLoop();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1100 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1101 #else
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1102 StateGameLoop();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1103 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1104
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1105 if (!_pause && _display_opt&DO_FULL_ANIMATION)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1106 DoPaletteAnimations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1107
67
6d9a0bd86770 (svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater <darkvater@openttd.org>
parents: 65
diff changeset
1108 if (!_pause || _cheats.build_in_pause.value)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1109 MoveAllTextEffects();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1110
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1111 MouseLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1112
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1113 if (_game_mode != GM_MENU)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1114 MusicLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1115 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1116
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1117 void BeforeSaveGame()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1118 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1119 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1120
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1121 _saved_scrollpos_x = WP(w,vp_d).scrollpos_x;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1122 _saved_scrollpos_y = WP(w,vp_d).scrollpos_y;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1123 _saved_scrollpos_zoom = w->viewport->zoom;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1124 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1125
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1126 void ConvertTownOwner()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1127 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1128 uint tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1129
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1130 for(tile=0; tile!=TILES_X * TILES_Y; tile++) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1131 if (IS_TILETYPE(tile, MP_STREET)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1132 if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1133 _map3_lo[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1134
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1135 if (_map_owner[tile] & 0x80)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1136 _map_owner[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1137 } else if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1138 if (_map_owner[tile] & 0x80)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1139 _map_owner[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1140 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1141 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1142 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1143
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1144 // before savegame version 4, the name of the company determined if it existed
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1145 void CheckIsPlayerActive()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1146 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1147 Player *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1148 FOR_ALL_PLAYERS(p) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1149 if (p->name_1 != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1150 p->is_active = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1151 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1152 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1153 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1154
121
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1155 // since savegame version 4.1, exclusive transport rights are stored at towns
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1156 void UpdateExclusiveRights()
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1157 {
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1158 Town *t;
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1159 FOR_ALL_TOWNS(t) if (t->xy != 0) {
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1160 t->exclusivity=(byte)-1;
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1161 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1162
123
6fe58757668c (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik <dominik@openttd.org>
parents: 121
diff changeset
1163 /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
121
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1164 could be implemented this way:
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1165 1.) Go through all stations
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1166 Build an array town_blocked[ town_id ][ player_id ]
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1167 that stores if at least one station in that town is blocked for a player
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1168 2.) Go through that array, if you find a town that is not blocked for
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1169 one player, but for all others, then give him exclusivity.
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1170 */
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1171 }
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1172
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1173 extern void UpdateOldAircraft();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1174
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1175 bool AfterLoadGame(uint version)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1176 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1177 Window *w;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1178 ViewPort *vp;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1179
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1180 // in version 2.1 of the savegame, town owner was unified.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1181 if (version <= 0x200) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1182 ConvertTownOwner();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1183 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1184
121
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1185 // from version 4.1 of the savegame, exclusive rights are stored at towns
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1186 if (version <= 0x400) {
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1187 UpdateExclusiveRights();
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1188 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1189
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1190 // convert road side to my format.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1191 if (_opt.road_side) _opt.road_side = 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1192
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1193 // Load the sprites
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1194 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1195
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1196 // Update current year
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1197 SetDate(_date);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1198
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1199 // reinit the landscape variables (landscape might have changed)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1200 InitializeLandscapeVariables(true);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1201
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1202 // Update all vehicles
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1203 AfterLoadVehicles();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1204 // in version 2.2 of the savegame, we have new airports
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1205 if (version <= 0x201) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1206 UpdateOldAircraft();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1207 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1208
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1209 UpdateAllStationVirtCoord();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1210
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1211 // Setup town coords
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1212 AfterLoadTown();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1213 UpdateAllSignVirtCoords();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1214
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1215 // make sure there is a town in the game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1216 if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1217 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1218 _error_message = STR_NO_TOWN_IN_SCENARIO;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1219 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1220 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1221
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1222 // Initialize windows
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1223 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1224 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1225
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1226 w = FindWindowById(WC_MAIN_WINDOW, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1227
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1228 WP(w,vp_d).scrollpos_x = _saved_scrollpos_x;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1229 WP(w,vp_d).scrollpos_y = _saved_scrollpos_y;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1230
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1231 vp = w->viewport;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1232 vp->zoom = _saved_scrollpos_zoom;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1233 vp->virtual_width = vp->width << vp->zoom;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1234 vp->virtual_height = vp->height << vp->zoom;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1235
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1236
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1237 // in version 4.0 of the savegame, is_active was introduced to determine
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1238 // if a player does exist, rather then checking name_1
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1239 if (version <= 0x400) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1240 CheckIsPlayerActive();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1241 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1242
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1243 // If Load Scenario / New (Scenario) Game is used,
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
1244 // a player does not exist yet. So create one here.
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1245 // 1 exeption: network-games. Those can have 0 players
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1246 // But this exeption is not true for network_servers!
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1247 if (!_players[0].is_active && (!_networking || (_networking && _network_server)))
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
1248 DoStartupNewPlayer(false);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1249
152
2bc5f40a3dfe (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater <darkvater@openttd.org>
parents: 139
diff changeset
1250 DoZoomInOutWindow(ZOOM_NONE, w); // update button status
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1251 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1252
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1253 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1254 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1255
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1256
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1257 void DebugProc(int i)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1258 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1259 switch(i) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1260 case 0:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1261 *(byte*)0 = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1262 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1263 case 1:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1264 DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1265 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1266 case 2:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1267 UpdateAllStationVirtCoord();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1268 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1269 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1270 }