annotate ttd.c @ 1035:3edb35954288 draft

(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
author tron <tron@openttd.org>
date Sun, 16 Jan 2005 11:24:58 +0000
parents 3746ce51f251
children b2b382908480
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"
679
21e658645b32 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron <tron@openttd.org>
parents: 659
diff changeset
3 #include "map.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
4
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
5 #define VARDEF
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
6 #include "ttd.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
7 #include "gfx.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
8 #include "gui.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
9 #include "station.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
10 #include "vehicle.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
11 #include "viewport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
12 #include "window.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
13 #include "player.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
14 #include "command.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
15 #include "town.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
16 #include "industry.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
17 #include "news.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
18 #include "engine.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
19 #include "sound.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
20 #include "economy.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
21 #include "fileio.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
22 #include "hal.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
23 #include "airport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
24 #include "saveload.h"
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
25 #include "ai.h"
126
127be480312c (svn r127) New feature: ingame console. (sign_de)
dominik <dominik@openttd.org>
parents: 123
diff changeset
26 #include "console.h"
430
7817370c8abe (svn r631) Merge r440, r444, r485, r630 to trunk:
tron <tron@openttd.org>
parents: 410
diff changeset
27 #include "screenshot.h"
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
28 #include "network.h"
988
fa15528bb00a (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight <truelight@openttd.org>
parents: 983
diff changeset
29 #include "signs.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
30
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
31 #include <stdarg.h>
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
32
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
33 void IncreaseSpriteLRU();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
34 void GenerateWorld(int mode);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
35 void CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
36 void IncreaseDate();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
37 void RunOtherPlayersLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
38 void DoPaletteAnimations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
39 void MusicLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
40 void ResetMusic();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
41 void InitializeStations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
42 void DeleteAllPlayerStations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
43
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
44 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
45 extern void DoStartupNewPlayer(bool is_ai);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
46 extern void ShowOSErrorBox(const char *buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
47
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
48 void redsq_debug(int tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
49 bool LoadSavegame(const char *filename);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
50
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
51 extern void HalGameLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
52
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
53 uint32 _pixels_redrawn;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
54 bool _dbg_screen_rect;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
55 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
56 static byte _os_version = 0;
0
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 void CDECL error(const char *s, ...) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
59 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
60 char buf[512];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
61 va_start(va, s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
62 vsprintf(buf, s, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
63 va_end(va);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
64
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
65 ShowOSErrorBox(buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
66 if (_video_driver)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
67 _video_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
68
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
69 assert(0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
70 exit(1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
71 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
72
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
73 void CDECL debug(const char *s, ...)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
74 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
75 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
76 char buf[1024];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
77 va_start(va, s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
78 vsprintf(buf, s, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
79 va_end(va);
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
80 fprintf(stderr, "dbg: %s\n", buf);
126
127be480312c (svn r127) New feature: ingame console. (sign_de)
dominik <dominik@openttd.org>
parents: 123
diff changeset
81 IConsoleDebug((byte *) &buf);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
82 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
83
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
84 void CDECL ShowInfoF(const char *str, ...)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
85 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
86 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
87 char buf[1024];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
88 va_start(va, str);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
89 vsprintf(buf, str, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
90 va_end(va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
91 ShowInfo(buf);
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
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
94 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
95 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
96 char buf[4096];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
97 va_list va;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
98 int len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
99 char *p;
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 va_start(va, str);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
102 len = vsprintf(buf, str, va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
103 va_end(va);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
104 p = malloc(len + 1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
105 if (p)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
106 memcpy(p, buf, len + 1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
107 return p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
108 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
109
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
110
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
111 // NULL midi driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
112 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
113 static void NullMidiStop() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
114 static void NullMidiPlaySong(const char *filename) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
115 static void NullMidiStopSong() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
116 static bool NullMidiIsSongPlaying() { return true; }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
117 static void NullMidiSetVolume(byte vol) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
118
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
119 const HalMusicDriver _null_music_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
120 NullMidiStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
121 NullMidiStop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
122 NullMidiPlaySong,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
123 NullMidiStopSong,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
124 NullMidiIsSongPlaying,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
125 NullMidiSetVolume,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
126 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
127
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
128 // NULL video driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
129 static void *_null_video_mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
130 static const char *NullVideoStart(char **parm) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
131 _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
132 _screen.height = _cur_resolution[1];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
133 _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
134 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
135 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
136 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
137 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
138 static int NullVideoMainLoop() {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
139 int i = 1000;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
140 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
141 GameLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
142 _screen.dst_ptr = _null_video_mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
143 UpdateWindows();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
144 } while (--i);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
145 return ML_QUIT;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
146 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
147
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
148 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
149
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
150
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
151 const HalVideoDriver _null_video_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
152 NullVideoStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
153 NullVideoStop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
154 NullVideoMakeDirty,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
155 NullVideoMainLoop,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
156 NullVideoChangeRes,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
157 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
158
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
159 // NULL sound driver
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
160 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
161 static void NullSoundStop() {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
162 const HalSoundDriver _null_sound_driver = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
163 NullSoundStart,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
164 NullSoundStop,
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
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
167 enum {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
168 DF_PRIORITY_MASK = 0xf,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
169 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
170
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
171 typedef struct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
172 const DriverDesc *descs;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
173 const char *name;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
174 void *var;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
175 } DriverClass;
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 static DriverClass _driver_classes[] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
178 {_video_driver_descs, "video", &_video_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
179 {_sound_driver_descs, "sound", &_sound_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
180 {_music_driver_descs, "music", &_music_driver},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
181 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
182
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
183 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
184 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
185 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
186 if (!strcmp(dd->name, name))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
187 return dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
188 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
189 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
190 }
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 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
193 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
194 const DriverDesc *best = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
195 int best_pri = -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
196 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
197 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
198 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
199 best = 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 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
202 return best;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
203 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
204
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
205 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
206 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
207 assert(len > 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
208 while (--len && *src)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
209 *dst++=*src++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
210 *dst = 0;
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
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
213 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
214 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
215 while ( (*dst++ = *src++) != 0) {}
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
216 return dst - 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
217 }
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 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
220 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
221 FILE *in;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
222 void *mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
223 size_t len;
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 in = fopen(filename, "rb");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
226 if (in == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
227 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
228
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
229 fseek(in, 0, SEEK_END);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
230 len = ftell(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
231 fseek(in, 0, SEEK_SET);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
232 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
233 fclose(in);
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 ((byte*)mem)[len] = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
237 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
238 fclose(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
239 free(mem);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
240 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
241 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
242 fclose(in);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
243
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
244 *lenp = len;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
245 return mem;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
246 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
247
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
248 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
249 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
250 const DriverClass *dc = &_driver_classes[driver];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
251 const DriverDesc *dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
252 const void **var;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
253 const void *drv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
254 const char *err;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
255 char *parm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
256 char buffer[256];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
257 char *parms[32];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
258
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
259 parms[0] = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
260
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
261 if (!*name) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
262 dd = ChooseDefaultDriver(dc->descs);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
263 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
264 // 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
265 ttd_strlcpy(buffer, name, sizeof(buffer));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
266 parm = strchr(buffer, ':');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
267 if (parm) {
959
ca7c19a004cc (svn r1451) Fix some of the signed/unsigned comparison warnings
tron <tron@openttd.org>
parents: 950
diff changeset
268 uint np = 0;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
269 // Tokenize the parm.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
270 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
271 *parm++ = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
272 if (np < lengthof(parms) - 1)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
273 parms[np++] = parm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
274 while (*parm != 0 && *parm != ',')
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
275 parm++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
276 } while (*parm == ',');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
277 parms[np] = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
278 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
279 dd = GetDriverByName(dc->descs, buffer);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
280 if (dd == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
281 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
282 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
283 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
284 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
285 *var = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
286 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
287 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
288 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
289 *var = drv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
290 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
291
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
292 static void showhelp()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
293 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
294 char buf[4096], *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
295 const DriverClass *dc = _driver_classes;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
296 const DriverDesc *dd;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
297 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
298
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
299 p = strecpy(buf,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
300 "Command line options:\n"
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
301 " -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
302 " -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
303 " -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
304 " -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
305 " -h = Display this help text\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
306 " -t date = Set starting date\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
307 " -d [dbg] = Debug mode\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
308 " -l lng = Select Language\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
309 " -e = Start Editor\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
310 " -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
311 " -G seed = Set random seed\n"
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
312 " -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
313 " -D = Start dedicated server\n"
770
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
314 #if !defined(__MORPHOS__) && !defined(__AMIGA__)
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
315 " -f = Fork into the background (dedicated only)\n"
770
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
316 #endif
614
96f116271012 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik <dominik@openttd.org>
parents: 561
diff changeset
317 " -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
318 " -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
319 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
320
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
321 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
322 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
323 dd = dc->descs;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
324 do {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
325 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
326 } while ((++dd)->name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
327 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
328
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
329 ShowInfo(buf);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
330 }
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 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
334 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
335 char *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
336 int len = strlen(name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
337 while ((p = *parm++) != NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
338 if (!strncmp(p,name,len)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
339 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
340 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
341 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
342 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
343 return NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
344 }
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 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
347 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
348 char *p = GetDriverParam(parm, name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
349 return p != NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
350 }
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 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
353 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
354 char *p = GetDriverParam(parm, name);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
355 return p != NULL ? atoi(p) : def;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
356 }
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 typedef struct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
359 char *opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
360 int numleft;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
361 char **argv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
362 const char *options;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
363 char *cont;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
364 } MyGetOptData;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
365
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
366 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
367 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
368 md->cont = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
369 md->numleft = argc;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
370 md->argv = argv;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
371 md->options = options;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
372 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
373
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
374 static int MyGetOpt(MyGetOptData *md)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
375 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
376 char *s,*r,*t;
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 if ((s=md->cont) != NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
379 goto md_continue_here;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
380
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
381 while(true) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
382 if (--md->numleft < 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
383 return -1;
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 s = *md->argv++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
386 if (*s == '-') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
387 md_continue_here:;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
388 s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
389 if (*s != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
390 // 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
391 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
392 // ERROR!
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
393 return -2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
394 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
395 if (r[1] == ':') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
396 // 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
397 if (!*(t = s + 1)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
398 // 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
399 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
400 // Check if item is optional?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
401 if (r[2] != ':')
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
402 return -2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
403 md->numleft++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
404 t = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
405 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
406 md->argv++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
407 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
408 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
409 md->opt = t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
410 md->cont = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
411 return *s;
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 = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
414 md->cont = s;
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 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
418 // This is currently not supported.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
419 return -2;
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 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
422 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
423
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
424 void SetDebugString(const char *s)
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 int v;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
427 char *end;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
428 const char *t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
429 int *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
430
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
431 // global debugging level?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
432 if (*s >= '0' && *s <= '9') {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
433 v = strtoul(s, &end, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
434 s = end;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
435
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
436 _debug_spritecache_level = v;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
437 _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
438 _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
439 _debug_ai_level = v;
185
628f1aa53b04 (svn r186) -Add: debug 'net' for network debug (sign_de)
truelight <truelight@openttd.org>
parents: 172
diff changeset
440 _debug_net_level = v;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
441 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
442
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
443 // individual levels
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
444 for(;;) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
445 // skip delimiters
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
446 while (*s == ' ' || *s == ',' || *s == '\t') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
447 if (*s == 0) break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
448
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
449 t = s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
450 while (*s >= 'a' && *s <= 'z') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
451
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
452 #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
453 // check debugging levels
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
454 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
455 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
456 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
457 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
458 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
459 else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
460 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
461 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
462 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
463 #undef IS_LVL
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
464 if (*s == '=') s++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
465 v = strtoul(s, &end, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
466 s = end;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
467 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
468 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
469 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
470
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
471 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
472 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
473 char *t = strchr(s, 'x');
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
474 if (t == NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
475 ShowInfoF("Invalid resolution '%s'", s);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
476 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
477 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
478
310
2f87c450cadc (svn r316) -Fix: not +7 (Tron)
darkvater <darkvater@openttd.org>
parents: 309
diff changeset
479 res[0] = strtoul(s, NULL, 0);
2f87c450cadc (svn r316) -Fix: not +7 (Tron)
darkvater <darkvater@openttd.org>
parents: 309
diff changeset
480 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
481 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
482
919
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
483 static void InitializeDynamicVariables(void)
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
484 {
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
485 /* Dynamic stuff needs to be initialized somewhere... */
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
486 _stations_size = lengthof(_stations);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
487 _station_sort = NULL;
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
488
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
489 _vehicles_size = lengthof(_vehicles);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
490 _vehicle_sort = NULL;
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
491
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
492 _towns_size = lengthof(_towns);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
493 _town_sort = NULL;
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
494
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
495 _industries_size = lengthof(_industries);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
496 _industry_sort = NULL;
988
fa15528bb00a (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight <truelight@openttd.org>
parents: 983
diff changeset
497
fa15528bb00a (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight <truelight@openttd.org>
parents: 983
diff changeset
498 _sign_size = lengthof(_sign_list);
1024
fc72cf555e80 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight <truelight@openttd.org>
parents: 1010
diff changeset
499 _orders_size = lengthof(_orders);
919
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
500 }
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
501
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
502 static void UnInitializeDynamicVariables(void)
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
503 {
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
504 /* Dynamic stuff needs to be free'd somewhere... */
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
505 free(_station_sort);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
506
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
507 free(_vehicle_sort);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
508
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
509 free(_town_sort);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
510
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
511 free(_industry_sort);
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
512 }
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
513
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
514
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
515 void LoadIntroGame()
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
516 {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
517 char filename[256];
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
518 _game_mode = GM_MENU;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
519 _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
520
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
521 _opt_mod_ptr = &_new_opt;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
522 GfxLoadSprites();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
523 LoadStringWidthTable();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
524
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
525 // Setup main window
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
526 InitWindowSystem();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
527 SetupColorsAndInitialWindow();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
528
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
529 // Generate a world.
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
530 sprintf(filename, "%sopntitle.dat", _path.data_dir);
921
471320499c64 (svn r1409) Simplify some preprocessor magic
tron <tron@openttd.org>
parents: 919
diff changeset
531 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
532 #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
533 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
534 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
535 #endif
f8558ecccbb9 (svn r970) Added 2nd data path for all non-windows OSes
bjarni <bjarni@openttd.org>
parents: 557
diff changeset
536 GenerateWorld(1); // if failed loading, make empty world.
921
471320499c64 (svn r1409) Simplify some preprocessor magic
tron <tron@openttd.org>
parents: 919
diff changeset
537 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
538 _opt.currency = _new_opt.currency;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
539
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
540 _pause = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
541 _local_player = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
542 MarkWholeScreenDirty();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
544 // Play main theme
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
545 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
546 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
547
774
d283468242cb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater <darkvater@openttd.org>
parents: 770
diff changeset
548 extern void DedicatedFork(void);
961
8ca2991f893e (svn r1453) Feature: MD5 hash check for TTD files
dominik <dominik@openttd.org>
parents: 959
diff changeset
549 extern void CheckExternalFiles();
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
550
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
551 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
552 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
553 MyGetOptData mgo;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
554 int i;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
555 bool network = false;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
556 char *network_conn = NULL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
557 char *language = NULL;
1010
a77da54c28d1 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron <tron@openttd.org>
parents: 1009
diff changeset
558 const char *optformat;
469
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
559 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
560 int resolution[2] = {0,0};
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
561 uint startdate = -1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
562 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
563
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
564 _game_mode = GM_MENU;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
565 _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
566 _switch_mode_errorstr = INVALID_STRING_ID;
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
567 _dedicated_forks = false;
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
568 _dedicated_enabled = false;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
569
1027
3746ce51f251 (svn r1528) -Fix: forgot to init a variable
truelight <truelight@openttd.org>
parents: 1024
diff changeset
570 _redirect_console_to_client = 0;
3746ce51f251 (svn r1528) -Fix: forgot to init a variable
truelight <truelight@openttd.org>
parents: 1024
diff changeset
571
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
572 // 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
573 // 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
574 // 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
575 // a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
770
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
576 #if !defined(__MORPHOS__) && !defined(__AMIGA__)
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
577 optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:";
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
578 #else
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
579 optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:"; // no fork option
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
580 #endif
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
581
e2136854b991 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni <bjarni@openttd.org>
parents: 768
diff changeset
582 MyGetOptInit(&mgo, argc-1, argv+1, optformat);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
583 while ((i = MyGetOpt(&mgo)) != -1) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
584 switch(i) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
585 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
586 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
587 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
588 case 'D': {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
589 sprintf(musicdriver,"null");
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
590 sprintf(sounddriver,"null");
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
591 sprintf(videodriver,"dedicated");
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
592 _dedicated_enabled = true;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
593 } break;
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
594 case 'f': {
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
595 _dedicated_forks = true;
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
596 }; break;
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
597 case 'n': {
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
598 network = true;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
599 if (mgo.opt)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
600 // 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
601 network_conn = mgo.opt;
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
602 else
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
603 network_conn = NULL;
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
604 } break;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
605 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
606 case 'l': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
607 language = mgo.opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
608 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
609 case 't': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
610 startdate = atoi(mgo.opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
611 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
612 case 'd': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
613 #if defined(WIN32)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
614 CreateConsole();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
615 #endif
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
616 if (mgo.opt)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
617 SetDebugString(mgo.opt);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
618 } break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
619 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
620 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
621 case 'g':
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
622 if (mgo.opt) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
623 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
624 _switch_mode = SM_LOAD;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
625 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
626 _switch_mode = SM_NEWGAME;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
627 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
628 case 'G':
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
629 _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
630 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
631 case 'p': {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
632 int i = atoi(mgo.opt);
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
633 // 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
634 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
635 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
636 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
637 case -2:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
638 case 'h':
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
639 showhelp();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
640 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
641 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
642 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
643
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
644 DeterminePaths();
961
8ca2991f893e (svn r1453) Feature: MD5 hash check for TTD files
dominik <dominik@openttd.org>
parents: 959
diff changeset
645 CheckExternalFiles();
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
646
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
647 #ifdef UNIX
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
648 // We must fork here, or we'll end up without some resources we need (like sockets)
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
649 if (_dedicated_forks)
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
650 DedicatedFork();
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
651 #endif
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
652
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
653 LoadFromConfig();
983
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
654 LoadFromHighScore();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
655
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
656 // override config?
469
23664f1bc31a (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight <truelight@openttd.org>
parents: 430
diff changeset
657 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
658 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
659 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
660 if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
990
260f35dbc97f (svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight <truelight@openttd.org>
parents: 988
diff changeset
661 if (startdate != (uint)-1) _patches.starting_date = startdate;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
662
704
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
663 if (_dedicated_forks && !_dedicated_enabled)
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
664 _dedicated_forks = false;
9d04cd8592f0 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight <truelight@openttd.org>
parents: 679
diff changeset
665
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
666 // enumerate language files
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
667 InitializeLanguagePacks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
668
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
669 // initialize screenshot formats
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
670 InitializeScreenshotFormats();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
671
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
672 // initialize airport state machines
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
673 InitializeAirports();
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
674
919
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
675 /* initialize all variables that are allocated dynamically */
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
676 InitializeDynamicVariables();
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
677
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
678 // Sample catalogue
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
679 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
680 _os_version = GetOSVersion();
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
681 MxInitialize(11025, "sample.cat");
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
682
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
683 // 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
684 InitWindowSystem();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
685
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
686 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
687 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
688
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
689 DEBUG(misc, 1) ("Loading drivers...");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
690 LoadDriver(SOUND_DRIVER, _ini_sounddriver);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
691 LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
692 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
693 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
694 _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
695
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
696 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
697 // initialize network-core
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
698 NetworkStartUp();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
699 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
700
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
701 // Default difficulty level
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
702 _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
703
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
704 // 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
705 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
706 SetDifficultyLevel(0, _opt_mod_ptr);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
707
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
708 // initialize the ingame console
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
709 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
710 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
711
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
712 InitPlayerRandoms();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
713
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
714 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
715 if ((network) && (_network_available)) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
716 if (network_conn != NULL) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
717 const byte *port = NULL;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
718 const byte *player = NULL;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
719 uint16 rport;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
720
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
721 rport = NETWORK_DEFAULT_PORT;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
722
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
723 ParseConnectionString(&player, &port, network_conn);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
724
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
725 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
726 if (port != NULL) rport = atoi(port);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
727
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
728 LoadIntroGame();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
729 _switch_mode = SM_NONE;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
730 NetworkClientConnectGame(network_conn, rport);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
731 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
732 // NetworkCoreConnectGame("auto", _network_server_port);
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
733 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
734 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
735 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
736
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
737 while (_video_driver->main_loop() == ML_SWITCHDRIVER) {}
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
738
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
739 IConsoleFree();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
740
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
741 #ifdef ENABLE_NETWORK
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
742 if (_network_available) {
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
743 // 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
744 NetworkDisconnect();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
745 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
746 NetworkShutDown();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
747 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
748 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
749
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
750 _video_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
751 _music_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
752 _sound_driver->stop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
753
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
754 SaveToConfig();
983
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
755 SaveToHighScore();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
756
105
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
757 // uninitialize airport state machines
b328f67e6928 (svn r106) New network core (by sign_de)
dominik <dominik@openttd.org>
parents: 96
diff changeset
758 UnInitializeAirports();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
759
919
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
760 /* uninitialize variables that are allocated dynamic */
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
761 UnInitializeDynamicVariables();
a2d3299a67ee (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight <truelight@openttd.org>
parents: 865
diff changeset
762
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
763 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
764 }
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 static void ShowScreenshotResult(bool b)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
767 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
768 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
769 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
770 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
771 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
772 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
773 }
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 }
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 void MakeNewGame()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
778 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
779 _game_mode = GM_NORMAL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
780
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
781 // Copy in game options
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
782 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
783 memcpy(&_opt, &_new_opt, sizeof(_opt));
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 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
786
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
787 // Reinitialize windows
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
788 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
789 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
790
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
791 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
792
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
793 // Randomize world
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
794 GenerateWorld(0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
795
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
796 // 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
797 if (_network_dedicated) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
798 _local_player = OWNER_SPECTATOR;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
799 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
800 // Create a single player
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
801 DoStartupNewPlayer(false);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
802
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
803 _local_player = 0;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
804 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
805
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
806 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
807 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
808
410
e165d1275350 (svn r607) -Patch: [ 985102 ] static cleanup
tron <tron@openttd.org>
parents: 310
diff changeset
809 static void MakeNewEditorWorld()
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
810 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
811 _game_mode = GM_EDITOR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
812
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
813 // Copy in game options
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
814 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
815 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
816
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
817 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
818
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
819 // Re-init the windowing system
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
820 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
821
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
822 // Create toolbars
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
823 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
824
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
825 // Startup the game system
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
826 GenerateWorld(1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
827
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
828 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
829 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
830 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
831
116
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
832 void StartupPlayers();
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
833 void StartupDisasters();
3761257cf350 (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik <dominik@openttd.org>
parents: 115
diff changeset
834
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
835 void StartScenario()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
836 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
837 _game_mode = GM_NORMAL;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
838
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
839 // invalid type
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
840 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
841 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
842 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
843 _game_mode = GM_MENU;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
844 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
845 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
846
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
847 // 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
848 // 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
849 // _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
850 // 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
851
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
852 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
853
136
b1efd00ffd88 (svn r137) Fix: console sometime didn't open (sign_de)
dominik <dominik@openttd.org>
parents: 126
diff changeset
854 // Reinitialize windows
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
855 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
856 LoadStringWidthTable();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
857
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
858 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
859
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
860 // Load game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
861 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
862 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
863 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
864 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
865
115
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
866 // Inititalize data
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
867 StartupPlayers();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
868 StartupEngines();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
869 StartupDisasters();
59ed6be0fe29 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik <dominik@openttd.org>
parents: 105
diff changeset
870
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
871 // When starting a scenario, is it really a load..
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
872 // 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
873 // a scenario.. so we do not need it here.
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
874 // DoStartupNewPlayer(false);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
875
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
876 _local_player = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
877
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
878 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
879 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
880
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
881 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
882 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
883 byte ogm = _game_mode;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
884 int r;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
885
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
886 _game_mode = newgm;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
887 r = SaveOrLoad(filename, mode);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
888 if (r == SL_REINIT) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
889 if (ogm == GM_MENU)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
890 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
891 else if (ogm == GM_EDITOR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
892 MakeNewEditorWorld();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
893 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
894 MakeNewGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
895 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
896 } else if (r != SL_OK) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
897 _game_mode = ogm;
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
898 return false;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
899 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
900 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
901 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
902
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
903 void SwitchMode(int new_mode)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
904 {
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
905 _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
906
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
907 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
908 // 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
909 if (new_mode != SM_SAVE) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
910 // 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
911 if (_networking) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
912 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
913 NetworkReboot();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
914 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
915 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
916 NetworkDisconnect();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
917 NetworkUDPClose();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
918 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
919 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
920
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
921 // 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
922 if (_is_network_server) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
923 // 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
924 if (new_mode != SM_MENU) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
925 NetworkServerStart();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
926 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
927 // 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
928 _is_network_server = false;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
929 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
930 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
931 }
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
932 #endif /* ENABLE_NETWORK */
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
933
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
934 switch(new_mode) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
935 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
936 MakeNewEditorWorld();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
937 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
938
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
939 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
940 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
941 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
942 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
943 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
944 MakeNewGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
945 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
946
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
947 case SM_START_SCENARIO:
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
948 StartScenario();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
949 break;
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
950
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
951 normal_load:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
952 case SM_LOAD: { // Load game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
953
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
954 _error_message = INVALID_STRING_ID;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
955 if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
942
6bc1b8107253 (svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight <truelight@openttd.org>
parents: 929
diff changeset
956 LoadIntroGame();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
957 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
958 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
959 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
960 _local_player = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
961 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
962 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
963 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
964 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
965 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
966 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
967 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
968 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
969
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
970 case SM_LOAD_SCENARIO: {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
971 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
972
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
973 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
974
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
975 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
976 _opt_mod_ptr = &_opt;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
977
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
978 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
979 _generating_world = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
980 // delete all players.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
981 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
982 ChangeOwnershipOfPlayerItems(i, 0xff);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
983 _players[i].is_active = false;
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 _generating_world = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
986 // 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
987 DeleteAllPlayerStations();
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
988
630
987f52fe5b58 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight <truelight@openttd.org>
parents: 614
diff changeset
989 #ifdef ENABLE_NETWORK
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
990 if (_network_server)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
991 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
992 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
993 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
994 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
995
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
996 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
997 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
998
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
999
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1000 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
1001 LoadIntroGame();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1002 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1003
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1004 case SM_SAVE: // Save game
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1005 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
1006 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
1007 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1008 DeleteWindowById(WC_SAVELOAD, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1009 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1010
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1011 case SM_GENRANDLAND:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1012 GenerateWorld(2);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1013 // XXX: set date
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1014 _local_player = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1015 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1016 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1017 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1018
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1019 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
1020 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
1021
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1022 _in_state_game_loop = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1023 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1024
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1025
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1026 // State controlling game loop.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1027 // 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
1028 // but here.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1029 // 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
1030 void StateGameLoop()
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1031 {
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
1032 // 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
1033 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
1034
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1035 _in_state_game_loop = true;
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1036 // _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
1037 // 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
1038 // 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
1039 if (!_networking)
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1040 _frame_counter++;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1041
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1042 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
1043 char buf[100];
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1044 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
1045 SaveOrLoad(buf, SL_SAVE);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1046 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
1047 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1048
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1049 if (_game_mode == GM_EDITOR) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1050 RunTileLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1051 CallVehicleTicks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1052 CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1053 CallWindowTickEvent();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1054 NewsLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1055 } else {
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1056 // All these actions has to be done from OWNER_NONE
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1057 // for multiplayer compatibility
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1058 uint p = _current_player;
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1059 _current_player = OWNER_NONE;
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1060
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1061 AnimateAnimatedTiles();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1062 IncreaseDate();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1063 RunTileLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1064 CallVehicleTicks();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1065 CallLandscapeTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1066
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1067 // 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
1068 // perfectly
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1069 if (!disable_computer && !_networking)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1070 RunOtherPlayersLoop();
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 CallWindowTickEvent();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1073 NewsLoop();
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1074 _current_player = p;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1075 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1076
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1077 _in_state_game_loop = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1078 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1079
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1080 static void DoAutosave()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1081 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1082 char buf[200];
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1083
1
ccd3560f672e (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater <darkvater@openttd.org>
parents: 0
diff changeset
1084 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
1085 Player *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1086 char *s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1087 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
1088 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
1089 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
1090 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
1091 SetDParam(2, _date);
760
760de5382bf1 (svn r1218) Fix: Autosaves go to the correct folder again with keep_all_autosave enabled
dominik <dominik@openttd.org>
parents: 704
diff changeset
1092 s= (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1093 strcpy(s, ".sav");
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1094 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1095 int n = _autosave_ctr;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1096 _autosave_ctr = (_autosave_ctr + 1) & 15;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1097 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
1098 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1099
557
4814c34ea3bb (svn r959) -Fix: fix previous typo for workaround of braindead MSVC6 (Tron)
darkvater <darkvater@openttd.org>
parents: 543
diff changeset
1100 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
1101 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
1102 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
1103 }
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 void GameLoop()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1106 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1107 int m;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1108
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1109 // autosave game?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1110 if (_do_autosave) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1111 _do_autosave = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1112 DoAutosave();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1113 RedrawAutosave();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1114 }
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 // make a screenshot?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1117 if ((m=_make_screenshot) != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1118 _make_screenshot = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1119 switch(m) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1120 case 1: // make small screenshot
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1121 UndrawMouseCursor();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1122 ShowScreenshotResult(MakeScreenshot());
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1123 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1124 case 2: // make large screenshot
863
02426b6f8bf7 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron <tron@openttd.org>
parents: 861
diff changeset
1125 ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, MapSizeY() * 32, 0));
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1126 break;
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 }
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 // switch game mode?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1131 if ((m=_switch_mode) != SM_NONE) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1132 _switch_mode = SM_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1133 SwitchMode(m);
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
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1136 IncreaseSpriteLRU();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1137 InteractiveRandom();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1138
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1139 if (_scroller_click_timeout > 3)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1140 _scroller_click_timeout -= 3;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1141 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1142 _scroller_click_timeout = 0;
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 _caret_timer += 3;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1145 _timer_counter+=8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1146 CursorTick();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1147
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1148 #ifdef ENABLE_NETWORK
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1149 // Check for UDP stuff
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1150 NetworkUDPGameLoop();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1151
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1152 if (_networking) {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1153 // Multiplayer
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1154 NetworkGameLoop();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1155 } else {
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1156 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
1157 // 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
1158 // 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
1159 NetworkClientConnectGame(_network_last_host, _network_last_port);
206
6dcb7c68f9ae (svn r207) -Codechange: randomizer handling
signde <signde@openttd.org>
parents: 193
diff changeset
1160 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1161 // 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
1162 StateGameLoop();
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1163 }
543
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1164 #else
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1165 StateGameLoop();
0bade3c3b8ba (svn r942) -Merged branch/network back into the trunk
truelight <truelight@openttd.org>
parents: 534
diff changeset
1166 #endif /* ENABLE_NETWORK */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1167
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1168 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
1169 DoPaletteAnimations();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1170
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
1171 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
1172 MoveAllTextEffects();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1173
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1174 MouseLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1175
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1176 if (_game_mode != GM_MENU)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1177 MusicLoop();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1178 }
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 void BeforeSaveGame()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1181 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1182 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
1183
983
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
1184 if (w != NULL) {
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
1185 _saved_scrollpos_x = WP(w,vp_d).scrollpos_x;
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
1186 _saved_scrollpos_y = WP(w,vp_d).scrollpos_y;
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
1187 _saved_scrollpos_zoom = w->viewport->zoom;
e681e8f26bf2 (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater <darkvater@openttd.org>
parents: 961
diff changeset
1188 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1189 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1190
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1191 void ConvertTownOwner()
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 uint tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1194
863
02426b6f8bf7 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron <tron@openttd.org>
parents: 861
diff changeset
1195 for (tile = 0; tile != MapSize(); tile++) {
1035
3edb35954288 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron <tron@openttd.org>
parents: 1027
diff changeset
1196 if (IsTileType(tile, MP_STREET)) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1197 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
1198 _map3_lo[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1199
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1200 if (_map_owner[tile] & 0x80)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1201 _map_owner[tile] = OWNER_TOWN;
1035
3edb35954288 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron <tron@openttd.org>
parents: 1027
diff changeset
1202 } else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1203 if (_map_owner[tile] & 0x80)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1204 _map_owner[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1205 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1206 }
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 // 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
1210 void CheckIsPlayerActive()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1211 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1212 Player *p;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1213 FOR_ALL_PLAYERS(p) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1214 if (p->name_1 != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1215 p->is_active = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1216 }
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 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1219
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
1220 // 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
1221 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
1222 {
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1223 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
1224 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
1225 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
1226 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1227
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
1228 /* 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
1229 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
1230 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
1231 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
1232 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
1233 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
1234 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
1235 */
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1236 }
d8006a13f9ea (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik <dominik@openttd.org>
parents: 116
diff changeset
1237
768
3e28c2a764d2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik <dominik@openttd.org>
parents: 762
diff changeset
1238 byte convert_currency[] = {
762
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1239 0, 1, 12, 8, 3,
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1240 10, 14, 19, 4, 5,
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1241 9, 11, 13, 6, 17,
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1242 16, 22, 21, 7, 15,
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1243 18, 2, 20, };
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1244
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1245 // since savegame version 4.2 the currencies are arranged differently
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1246 void UpdateCurrencies()
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1247 {
768
3e28c2a764d2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik <dominik@openttd.org>
parents: 762
diff changeset
1248 _opt.currency = convert_currency[_opt.currency];
762
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1249 }
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1250
929
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1251 // up to revision 1413, the invisible tiles at the southern border have not been MP_VOID
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1252 // even though they should have. This is fixed by this function
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1253 void UpdateVoidTiles()
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1254 {
959
ca7c19a004cc (svn r1451) Fix some of the signed/unsigned comparison warnings
tron <tron@openttd.org>
parents: 950
diff changeset
1255 uint i;
929
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1256 // create void tiles on the border
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1257 for (i = 0; i != MapMaxY(); i++)
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1258 _map_type_and_height[ i * MapSizeX() + MapMaxY() ] = MP_VOID << 4;
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1259 memset(_map_type_and_height + MapMaxY() * MapSizeX(), MP_VOID << 4, MapSizeX());
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1260 }
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1261
950
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1262 extern void UpdateOldAircraft( void );
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1263 extern void UpdateOilRig( void );
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1264
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1265 bool AfterLoadGame(uint version)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1266 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1267 Window *w;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1268 ViewPort *vp;
988
fa15528bb00a (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight <truelight@openttd.org>
parents: 983
diff changeset
1269
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1270 // 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
1271 if (version <= 0x200) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1272 ConvertTownOwner();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1273 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1274
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
1275 // 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
1276 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
1277 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
1278 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1279
762
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1280 // from version 4.2 of the savegame, currencies are in a different order
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1281 if (version <= 0x401) {
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1282 UpdateCurrencies();
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1283 }
e3063f89f4e2 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik <dominik@openttd.org>
parents: 760
diff changeset
1284
831
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1285 /* In old version there seems to be a problem that water is owned by
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1286 OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1287 (0x402) version, so I just check when versions are older, and then
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1288 walk through the whole map.. */
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1289 if (version <= 0x402) {
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1290 TileIndex tile = TILE_XY(0,0);
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1291 uint w = MapSizeX();
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1292 uint h = MapSizeY();
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1293
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1294 BEGIN_TILE_LOOP(tile_cur, w, h, tile)
1035
3edb35954288 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron <tron@openttd.org>
parents: 1027
diff changeset
1295 if (IsTileType(tile_cur, MP_WATER) && _map_owner[tile_cur] >= MAX_PLAYERS)
831
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1296 _map_owner[tile_cur] = OWNER_WATER;
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1297 END_TILE_LOOP(tile_cur, w, h, tile)
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1298 }
3a430e6d2015 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight <truelight@openttd.org>
parents: 802
diff changeset
1299
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1300 // convert road side to my format.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1301 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
1302
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1303 // Load the sprites
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1304 GfxLoadSprites();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1305
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1306 // Update current year
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1307 SetDate(_date);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1308
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1309 // 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
1310 InitializeLandscapeVariables(true);
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1311
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1312 // Update all vehicles
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1313 AfterLoadVehicles();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1314 // 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
1315 if (version <= 0x201) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1316 UpdateOldAircraft();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1317 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1318
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1319 UpdateAllStationVirtCoord();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1320
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1321 // Setup town coords
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1322 AfterLoadTown();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1323 UpdateAllSignVirtCoords();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1324
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1325 // 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
1326 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
1327 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1328 _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
1329 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1330 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1331
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1332 // Initialize windows
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1333 InitWindowSystem();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1334 SetupColorsAndInitialWindow();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1335
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1336 w = FindWindowById(WC_MAIN_WINDOW, 0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1337
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1338 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
1339 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
1340
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1341 vp = w->viewport;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1342 vp->zoom = _saved_scrollpos_zoom;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1343 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
1344 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
1345
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1346
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1347 // 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
1348 // 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
1349 if (version <= 0x400) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1350 CheckIsPlayerActive();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1351 }
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1352
929
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1353 // the void tiles on the southern border used to belong to a wrong class.
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1354 if (version <= 0x402)
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1355 UpdateVoidTiles();
52cd2f236b44 (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik <dominik@openttd.org>
parents: 921
diff changeset
1356
193
d9c55f0bc5ec (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight <truelight@openttd.org>
parents: 185
diff changeset
1357 // If Load Scenario / New (Scenario) Game is used,
139
77a4d5147048 (svn r140) -Fix: Load Scenario fix
truelight <truelight@openttd.org>
parents: 136
diff changeset
1358 // 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
1359 // 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
1360 // 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
1361 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
1362 DoStartupNewPlayer(false);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1363
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
1364 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
1365 MarkWholeScreenDirty();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1366
950
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1367 //In 5.1, Oilrigs have been moved (again)
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1368 if (version <= 0x500) {
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1369 UpdateOilRig();
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1370 }
4731f23c9b89 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar <celestar@openttd.org>
parents: 942
diff changeset
1371
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1372 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1373 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1374
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1375 void DebugProc(int i)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1376 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1377 switch(i) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1378 case 0:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1379 *(byte*)0 = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1380 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1381 case 1:
795
6d8f715f9ce1 (svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight <truelight@openttd.org>
parents: 774
diff changeset
1382 /* Server can not cheat in advertise mode either! */
802
a28b8ef77f12 (svn r1272) -Fix: game compiles again with network disabled
truelight <truelight@openttd.org>
parents: 795
diff changeset
1383 #ifdef ENABLE_NETWORK
795
6d8f715f9ce1 (svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight <truelight@openttd.org>
parents: 774
diff changeset
1384 if (!_networking || !_network_server || !_network_advertise)
802
a28b8ef77f12 (svn r1272) -Fix: game compiles again with network disabled
truelight <truelight@openttd.org>
parents: 795
diff changeset
1385 #endif /* ENABLE_NETWORK */
795
6d8f715f9ce1 (svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight <truelight@openttd.org>
parents: 774
diff changeset
1386 DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1387 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1388 case 2:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1389 UpdateAllStationVirtCoord();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1390 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1391 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1392 }