author | tron |
Sat, 05 Feb 2005 14:18:25 +0000 | |
changeset 1296 | 28cbaedf9f93 |
parent 1295 | 5dc810674581 |
child 1299 | 0a6510cc889b |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
2 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
659
diff
changeset
|
3 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1199
diff
changeset
|
4 |
#include "tile.h" |
0 | 5 |
|
6 |
#define VARDEF |
|
7 |
#include "ttd.h" |
|
8 |
#include "gfx.h" |
|
9 |
#include "gui.h" |
|
10 |
#include "station.h" |
|
11 |
#include "vehicle.h" |
|
12 |
#include "viewport.h" |
|
13 |
#include "window.h" |
|
14 |
#include "player.h" |
|
15 |
#include "command.h" |
|
16 |
#include "town.h" |
|
17 |
#include "industry.h" |
|
18 |
#include "news.h" |
|
19 |
#include "engine.h" |
|
20 |
#include "sound.h" |
|
21 |
#include "economy.h" |
|
22 |
#include "fileio.h" |
|
23 |
#include "hal.h" |
|
24 |
#include "airport.h" |
|
25 |
#include "saveload.h" |
|
139 | 26 |
#include "ai.h" |
126 | 27 |
#include "console.h" |
430 | 28 |
#include "screenshot.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
29 |
#include "network.h" |
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
30 |
#include "signs.h" |
0 | 31 |
|
32 |
#include <stdarg.h> |
|
33 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
34 |
void IncreaseSpriteLRU(void); |
1218 | 35 |
void GenerateWorld(int mode, uint log_x, uint log_y); |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
36 |
void CallLandscapeTick(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
37 |
void IncreaseDate(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
38 |
void RunOtherPlayersLoop(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
39 |
void DoPaletteAnimations(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
40 |
void MusicLoop(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
41 |
void ResetMusic(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
42 |
void InitializeStations(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
43 |
void DeleteAllPlayerStations(void); |
0 | 44 |
|
45 |
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); |
|
46 |
extern void DoStartupNewPlayer(bool is_ai); |
|
47 |
extern void ShowOSErrorBox(const char *buf); |
|
48 |
||
49 |
void redsq_debug(int tile); |
|
50 |
bool LoadSavegame(const char *filename); |
|
51 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
52 |
extern void HalGameLoop(void); |
0 | 53 |
|
54 |
uint32 _pixels_redrawn; |
|
55 |
bool _dbg_screen_rect; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
56 |
bool disable_computer; // We should get ride of this thing.. is only used for a debug-cheat |
223
0e5cc5a65df6
(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
parents:
222
diff
changeset
|
57 |
static byte _os_version = 0; |
0 | 58 |
|
59 |
void CDECL error(const char *s, ...) { |
|
60 |
va_list va; |
|
61 |
char buf[512]; |
|
62 |
va_start(va, s); |
|
63 |
vsprintf(buf, s, va); |
|
64 |
va_end(va); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
65 |
|
0 | 66 |
ShowOSErrorBox(buf); |
67 |
if (_video_driver) |
|
68 |
_video_driver->stop(); |
|
69 |
||
70 |
assert(0); |
|
71 |
exit(1); |
|
72 |
} |
|
73 |
||
74 |
void CDECL debug(const char *s, ...) |
|
75 |
{ |
|
76 |
va_list va; |
|
77 |
char buf[1024]; |
|
78 |
va_start(va, s); |
|
79 |
vsprintf(buf, s, va); |
|
80 |
va_end(va); |
|
139 | 81 |
fprintf(stderr, "dbg: %s\n", buf); |
1105 | 82 |
IConsoleDebug(buf); |
0 | 83 |
} |
84 |
||
85 |
void CDECL ShowInfoF(const char *str, ...) |
|
86 |
{ |
|
87 |
va_list va; |
|
88 |
char buf[1024]; |
|
89 |
va_start(va, str); |
|
90 |
vsprintf(buf, str, va); |
|
91 |
va_end(va); |
|
92 |
ShowInfo(buf); |
|
93 |
} |
|
94 |
||
95 |
char * CDECL str_fmt(const char *str, ...) |
|
96 |
{ |
|
97 |
char buf[4096]; |
|
98 |
va_list va; |
|
99 |
int len; |
|
100 |
char *p; |
|
101 |
||
102 |
va_start(va, str); |
|
103 |
len = vsprintf(buf, str, va); |
|
104 |
va_end(va); |
|
105 |
p = malloc(len + 1); |
|
106 |
if (p) |
|
107 |
memcpy(p, buf, len + 1); |
|
108 |
return p; |
|
109 |
} |
|
110 |
||
111 |
||
112 |
// NULL midi driver |
|
113 |
static char *NullMidiStart(char **parm) { return NULL; } |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
114 |
static void NullMidiStop(void) {} |
0 | 115 |
static void NullMidiPlaySong(const char *filename) {} |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
116 |
static void NullMidiStopSong(void) {} |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
117 |
static bool NullMidiIsSongPlaying(void) { return true; } |
0 | 118 |
static void NullMidiSetVolume(byte vol) {} |
119 |
||
120 |
const HalMusicDriver _null_music_driver = { |
|
121 |
NullMidiStart, |
|
122 |
NullMidiStop, |
|
123 |
NullMidiPlaySong, |
|
124 |
NullMidiStopSong, |
|
125 |
NullMidiIsSongPlaying, |
|
126 |
NullMidiSetVolume, |
|
127 |
}; |
|
128 |
||
129 |
// NULL video driver |
|
130 |
static void *_null_video_mem; |
|
131 |
static const char *NullVideoStart(char **parm) { |
|
132 |
_screen.width = _screen.pitch = _cur_resolution[0]; |
|
133 |
_screen.height = _cur_resolution[1]; |
|
134 |
_null_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]); |
|
135 |
return NULL; |
|
136 |
} |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
137 |
static void NullVideoStop(void) { free(_null_video_mem); } |
0 | 138 |
static void NullVideoMakeDirty(int left, int top, int width, int height) {} |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
139 |
static int NullVideoMainLoop(void) |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
140 |
{ |
0 | 141 |
int i = 1000; |
142 |
do { |
|
143 |
GameLoop(); |
|
144 |
_screen.dst_ptr = _null_video_mem; |
|
145 |
UpdateWindows(); |
|
146 |
} while (--i); |
|
147 |
return ML_QUIT; |
|
148 |
} |
|
149 |
||
150 |
static bool NullVideoChangeRes(int w, int h) { return false; } |
|
151 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
152 |
|
0 | 153 |
const HalVideoDriver _null_video_driver = { |
154 |
NullVideoStart, |
|
155 |
NullVideoStop, |
|
156 |
NullVideoMakeDirty, |
|
157 |
NullVideoMainLoop, |
|
158 |
NullVideoChangeRes, |
|
159 |
}; |
|
160 |
||
161 |
// NULL sound driver |
|
162 |
static char *NullSoundStart(char **parm) { return NULL; } |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
163 |
static void NullSoundStop(void) {} |
0 | 164 |
const HalSoundDriver _null_sound_driver = { |
165 |
NullSoundStart, |
|
166 |
NullSoundStop, |
|
167 |
}; |
|
168 |
||
169 |
enum { |
|
170 |
DF_PRIORITY_MASK = 0xf, |
|
171 |
}; |
|
172 |
||
173 |
typedef struct { |
|
174 |
const DriverDesc *descs; |
|
175 |
const char *name; |
|
176 |
void *var; |
|
177 |
} DriverClass; |
|
178 |
||
179 |
static DriverClass _driver_classes[] = { |
|
180 |
{_video_driver_descs, "video", &_video_driver}, |
|
181 |
{_sound_driver_descs, "sound", &_sound_driver}, |
|
182 |
{_music_driver_descs, "music", &_music_driver}, |
|
183 |
}; |
|
184 |
||
185 |
static const DriverDesc *GetDriverByName(const DriverDesc *dd, const char *name) |
|
186 |
{ |
|
187 |
do { |
|
188 |
if (!strcmp(dd->name, name)) |
|
189 |
return dd; |
|
190 |
} while ((++dd)->name); |
|
191 |
return NULL; |
|
192 |
} |
|
193 |
||
194 |
static const DriverDesc *ChooseDefaultDriver(const DriverDesc *dd) |
|
195 |
{ |
|
196 |
const DriverDesc *best = NULL; |
|
197 |
int best_pri = -1; |
|
198 |
do { |
|
223
0e5cc5a65df6
(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
parents:
222
diff
changeset
|
199 |
if ((int)(dd->flags&DF_PRIORITY_MASK) > best_pri && _os_version >= (byte)dd->flags) { |
0 | 200 |
best_pri = dd->flags&DF_PRIORITY_MASK; |
201 |
best = dd; |
|
202 |
} |
|
203 |
} while ((++dd)->name); |
|
204 |
return best; |
|
205 |
} |
|
206 |
||
1115
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
207 |
void ttd_strlcpy(char *dst, const char *src, size_t size) |
0 | 208 |
{ |
1115
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
209 |
assert(size > 0); |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
210 |
while (--size > 0 && *src != '\0') *dst++ = *src++; |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
211 |
*dst = '\0'; |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
212 |
} |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
213 |
|
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
214 |
void ttd_strlcat(char *dst, const char *src, size_t size) |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
215 |
{ |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
216 |
assert(size > 0); |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
217 |
for (; size > 0 && *dst != '\0'; --size, ++dst) {} |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
218 |
assert(size > 0); |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
219 |
while (--size > 0 && *src != '\0') *dst++ = *src++; |
36d85d14d44b
(svn r1616) Introduce ttd_strlcat() and use it to de-uglify some piece of code in misc_cmd.
tron
parents:
1109
diff
changeset
|
220 |
*dst = '\0'; |
0 | 221 |
} |
222 |
||
1095 | 223 |
static char *strecpy(char *dst, const char *src) |
0 | 224 |
{ |
225 |
while ( (*dst++ = *src++) != 0) {} |
|
226 |
return dst - 1; |
|
227 |
} |
|
228 |
||
229 |
byte *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) |
|
230 |
{ |
|
231 |
FILE *in; |
|
1105 | 232 |
byte *mem; |
0 | 233 |
size_t len; |
234 |
||
235 |
in = fopen(filename, "rb"); |
|
236 |
if (in == NULL) |
|
237 |
return NULL; |
|
238 |
||
239 |
fseek(in, 0, SEEK_END); |
|
240 |
len = ftell(in); |
|
241 |
fseek(in, 0, SEEK_SET); |
|
1105 | 242 |
if (len > maxsize || (mem = malloc(len + 1)) == NULL) { |
0 | 243 |
fclose(in); |
244 |
return NULL; |
|
245 |
} |
|
1105 | 246 |
mem[len] = 0; |
0 | 247 |
if (fread(mem, len, 1, in) != 1) { |
248 |
fclose(in); |
|
249 |
free(mem); |
|
250 |
return NULL; |
|
251 |
} |
|
252 |
fclose(in); |
|
253 |
||
254 |
*lenp = len; |
|
255 |
return mem; |
|
256 |
} |
|
257 |
||
258 |
void LoadDriver(int driver, const char *name) |
|
259 |
{ |
|
260 |
const DriverClass *dc = &_driver_classes[driver]; |
|
261 |
const DriverDesc *dd; |
|
262 |
const void **var; |
|
263 |
const void *drv; |
|
264 |
const char *err; |
|
265 |
char *parm; |
|
266 |
char buffer[256]; |
|
267 |
char *parms[32]; |
|
268 |
||
269 |
parms[0] = NULL; |
|
270 |
||
271 |
if (!*name) { |
|
272 |
dd = ChooseDefaultDriver(dc->descs); |
|
273 |
} else { |
|
274 |
// Extract the driver name and put parameter list in parm |
|
275 |
ttd_strlcpy(buffer, name, sizeof(buffer)); |
|
276 |
parm = strchr(buffer, ':'); |
|
277 |
if (parm) { |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
950
diff
changeset
|
278 |
uint np = 0; |
0 | 279 |
// Tokenize the parm. |
280 |
do { |
|
281 |
*parm++ = 0; |
|
282 |
if (np < lengthof(parms) - 1) |
|
283 |
parms[np++] = parm; |
|
284 |
while (*parm != 0 && *parm != ',') |
|
285 |
parm++; |
|
286 |
} while (*parm == ','); |
|
287 |
parms[np] = NULL; |
|
288 |
} |
|
289 |
dd = GetDriverByName(dc->descs, buffer); |
|
290 |
if (dd == NULL) |
|
291 |
error("No such %s driver: %s\n", dc->name, buffer); |
|
292 |
} |
|
293 |
var = dc->var; |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
213
diff
changeset
|
294 |
if (*var != NULL) ((const HalCommonDriver*)*var)->stop(); |
0 | 295 |
*var = NULL; |
296 |
drv = dd->drv; |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
213
diff
changeset
|
297 |
if ((err=((const HalCommonDriver*)drv)->start(parms)) != NULL) |
0 | 298 |
error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err); |
299 |
*var = drv; |
|
300 |
} |
|
301 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
302 |
static void showhelp(void) |
0 | 303 |
{ |
304 |
char buf[4096], *p; |
|
305 |
const DriverClass *dc = _driver_classes; |
|
306 |
const DriverDesc *dd; |
|
307 |
int i; |
|
308 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
309 |
p = strecpy(buf, |
0 | 310 |
"Command line options:\n" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
311 |
" -v drv = Set video driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
312 |
" -s drv = Set sound driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
313 |
" -m drv = Set music driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
314 |
" -r res = Set resolution (for instance 800x600)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
315 |
" -h = Display this help text\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
316 |
" -t date = Set starting date\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
317 |
" -d [dbg] = Debug mode\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
318 |
" -l lng = Select Language\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
319 |
" -e = Start Editor\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
320 |
" -g [savegame] = Start new/save game immediately\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
321 |
" -G seed = Set random seed\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
322 |
" -n [ip#player:port] = Start networkgame\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
323 |
" -D = Start dedicated server\n" |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
324 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
325 |
" -f = Fork into the background (dedicated only)\n" |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
326 |
#endif |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
561
diff
changeset
|
327 |
" -i = Force to use the DOS palette (use this if you see a lot of pink)\n" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
328 |
" -p #player = Player as #player (deprecated) (network only)\n" |
0 | 329 |
); |
330 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
331 |
for(i=0; i!=lengthof(_driver_classes); i++,dc++) { |
0 | 332 |
p += sprintf(p, "List of %s drivers:\n", dc->name); |
333 |
dd = dc->descs; |
|
334 |
do { |
|
335 |
p += sprintf(p, "%10s: %s\n", dd->name, dd->longname); |
|
336 |
} while ((++dd)->name); |
|
337 |
} |
|
338 |
||
339 |
ShowInfo(buf); |
|
340 |
} |
|
341 |
||
342 |
||
343 |
char *GetDriverParam(char **parm, const char *name) |
|
344 |
{ |
|
345 |
char *p; |
|
346 |
int len = strlen(name); |
|
347 |
while ((p = *parm++) != NULL) { |
|
348 |
if (!strncmp(p,name,len)) { |
|
349 |
if (p[len] == '=') return p + len + 1; |
|
350 |
if (p[len] == 0) return p + len; |
|
351 |
} |
|
352 |
} |
|
353 |
return NULL; |
|
354 |
} |
|
355 |
||
356 |
bool GetDriverParamBool(char **parm, const char *name) |
|
357 |
{ |
|
358 |
char *p = GetDriverParam(parm, name); |
|
359 |
return p != NULL; |
|
360 |
} |
|
361 |
||
362 |
int GetDriverParamInt(char **parm, const char *name, int def) |
|
363 |
{ |
|
364 |
char *p = GetDriverParam(parm, name); |
|
365 |
return p != NULL ? atoi(p) : def; |
|
366 |
} |
|
367 |
||
368 |
typedef struct { |
|
369 |
char *opt; |
|
370 |
int numleft; |
|
371 |
char **argv; |
|
372 |
const char *options; |
|
373 |
char *cont; |
|
374 |
} MyGetOptData; |
|
375 |
||
376 |
static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options) |
|
377 |
{ |
|
378 |
md->cont = NULL; |
|
379 |
md->numleft = argc; |
|
380 |
md->argv = argv; |
|
381 |
md->options = options; |
|
382 |
} |
|
383 |
||
384 |
static int MyGetOpt(MyGetOptData *md) |
|
385 |
{ |
|
386 |
char *s,*r,*t; |
|
387 |
||
388 |
if ((s=md->cont) != NULL) |
|
389 |
goto md_continue_here; |
|
390 |
||
391 |
while(true) { |
|
392 |
if (--md->numleft < 0) |
|
393 |
return -1; |
|
394 |
||
395 |
s = *md->argv++; |
|
396 |
if (*s == '-') { |
|
397 |
md_continue_here:; |
|
398 |
s++; |
|
399 |
if (*s != 0) { |
|
400 |
// Found argument, try to locate it in options. |
|
401 |
if (*s == ':' || (r = strchr(md->options, *s)) == NULL) { |
|
402 |
// ERROR! |
|
403 |
return -2; |
|
404 |
} |
|
405 |
if (r[1] == ':') { |
|
406 |
// Item wants an argument. Check if the argument follows, or if it comes as a separate arg. |
|
407 |
if (!*(t = s + 1)) { |
|
408 |
// It comes as a separate arg. Check if out of args? |
|
409 |
if (--md->numleft < 0 || *(t = *md->argv) == '-') { |
|
410 |
// Check if item is optional? |
|
411 |
if (r[2] != ':') |
|
412 |
return -2; |
|
413 |
md->numleft++; |
|
414 |
t = NULL; |
|
415 |
} else { |
|
416 |
md->argv++; |
|
417 |
} |
|
418 |
} |
|
419 |
md->opt = t; |
|
420 |
md->cont = NULL; |
|
421 |
return *s; |
|
422 |
} |
|
423 |
md->opt = NULL; |
|
424 |
md->cont = s; |
|
425 |
return *s; |
|
426 |
} |
|
427 |
} else { |
|
428 |
// This is currently not supported. |
|
429 |
return -2; |
|
430 |
} |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
void SetDebugString(const char *s) |
|
435 |
{ |
|
436 |
int v; |
|
437 |
char *end; |
|
438 |
const char *t; |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
439 |
|
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
440 |
typedef struct DebugLevel { |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
441 |
const char* name; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
442 |
int* level; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
443 |
} DebugLevel; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
444 |
|
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
445 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
446 |
static const DebugLevel debug_level[] = { |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
447 |
DEBUG_LEVEL(ai), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
448 |
DEBUG_LEVEL(grf), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
449 |
DEBUG_LEVEL(map), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
450 |
DEBUG_LEVEL(misc), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
451 |
DEBUG_LEVEL(ms), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
452 |
DEBUG_LEVEL(net), |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
453 |
DEBUG_LEVEL(spritecache) |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
454 |
}; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
455 |
#undef DEBUG_LEVEL |
0 | 456 |
|
457 |
// global debugging level? |
|
458 |
if (*s >= '0' && *s <= '9') { |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
459 |
const DebugLevel *i; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
460 |
|
0 | 461 |
v = strtoul(s, &end, 0); |
462 |
s = end; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
463 |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
464 |
for (i = debug_level; i != endof(debug_level); ++i) |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
465 |
*i->level = v; |
0 | 466 |
} |
467 |
||
468 |
// individual levels |
|
469 |
for(;;) { |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
470 |
const DebugLevel *i; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
471 |
int *p; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
472 |
|
0 | 473 |
// skip delimiters |
474 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
475 |
if (*s == 0) break; |
|
476 |
||
477 |
t = s; |
|
478 |
while (*s >= 'a' && *s <= 'z') s++; |
|
479 |
||
480 |
// check debugging levels |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
481 |
p = NULL; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
482 |
for (i = debug_level; i != endof(debug_level); ++i) |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
483 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
484 |
p = i->level; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
485 |
break; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
486 |
} |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
487 |
|
0 | 488 |
if (*s == '=') s++; |
489 |
v = strtoul(s, &end, 0); |
|
490 |
s = end; |
|
1296
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
491 |
if (p != NULL) |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
492 |
*p = v; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
493 |
else { |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
494 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
495 |
return; |
28cbaedf9f93
(svn r1800) Make adding new debug categories to the command line parser easier
tron
parents:
1295
diff
changeset
|
496 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
497 |
} |
0 | 498 |
} |
499 |
||
1095 | 500 |
static void ParseResolution(int res[2], char *s) |
0 | 501 |
{ |
502 |
char *t = strchr(s, 'x'); |
|
503 |
if (t == NULL) { |
|
504 |
ShowInfoF("Invalid resolution '%s'", s); |
|
505 |
return; |
|
506 |
} |
|
507 |
||
310 | 508 |
res[0] = strtoul(s, NULL, 0); |
509 |
res[1] = strtoul(t + 1, NULL, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
510 |
} |
0 | 511 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
512 |
static void InitializeDynamicVariables(void) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
513 |
{ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
514 |
/* Dynamic stuff needs to be initialized somewhere... */ |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
515 |
_orders_size = lengthof(_orders); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
516 |
|
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
517 |
_station_sort = NULL; |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
518 |
_vehicle_sort = NULL; |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
519 |
_town_sort = NULL; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
520 |
_industry_sort = NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
521 |
} |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
522 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
523 |
static void UnInitializeDynamicVariables(void) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
524 |
{ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
525 |
/* Dynamic stuff needs to be free'd somewhere... */ |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1246
diff
changeset
|
526 |
CleanPool(&_town_pool); |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
527 |
CleanPool(&_industry_pool); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1268
diff
changeset
|
528 |
CleanPool(&_station_pool); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
529 |
CleanPool(&_vehicle_pool); |
1283
b9569cc0644f
(svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents:
1279
diff
changeset
|
530 |
CleanPool(&_sign_pool); |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1246
diff
changeset
|
531 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
532 |
free(_station_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
533 |
free(_vehicle_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
534 |
free(_town_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
535 |
free(_industry_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
536 |
} |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
537 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
538 |
|
1095 | 539 |
static void LoadIntroGame(void) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
540 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
541 |
char filename[256]; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
542 |
_game_mode = GM_MENU; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
543 |
_display_opt &= ~DO_TRANS_BUILDINGS; // don't make buildings transparent in intro |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
544 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
545 |
_opt_mod_ptr = &_new_opt; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
546 |
GfxLoadSprites(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
547 |
LoadStringWidthTable(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
548 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
549 |
// Setup main window |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
550 |
InitWindowSystem(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
551 |
SetupColorsAndInitialWindow(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
552 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
553 |
// Generate a world. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
554 |
sprintf(filename, "%sopntitle.dat", _path.data_dir); |
921 | 555 |
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
556 |
#if defined SECOND_DATA_DIR |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
557 |
sprintf(filename, "%sopntitle.dat", _path.second_data_dir); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
558 |
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
559 |
#endif |
1218 | 560 |
GenerateWorld(1, 6, 6); // if failed loading, make empty world. |
921 | 561 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
562 |
_opt.currency = _new_opt.currency; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
563 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
564 |
_pause = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
565 |
_local_player = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
566 |
MarkWholeScreenDirty(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
567 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
568 |
// Play main theme |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
569 |
if (_music_driver->is_song_playing()) ResetMusic(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
570 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
571 |
|
774
258c11431acb
(svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents:
770
diff
changeset
|
572 |
extern void DedicatedFork(void); |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
573 |
extern void CheckExternalFiles(void); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
574 |
|
0 | 575 |
int ttd_main(int argc, char* argv[]) |
576 |
{ |
|
577 |
MyGetOptData mgo; |
|
578 |
int i; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
579 |
bool network = false; |
0 | 580 |
char *network_conn = NULL; |
581 |
char *language = NULL; |
|
1010
17470a8e5eb7
(svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents:
1009
diff
changeset
|
582 |
const char *optformat; |
469
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
583 |
char musicdriver[16], sounddriver[16], videodriver[16]; |
0 | 584 |
int resolution[2] = {0,0}; |
585 |
uint startdate = -1; |
|
586 |
musicdriver[0] = sounddriver[0] = videodriver[0] = 0; |
|
587 |
||
588 |
_game_mode = GM_MENU; |
|
589 |
_switch_mode = SM_MENU; |
|
172
8d8b3383470d
(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
parents:
168
diff
changeset
|
590 |
_switch_mode_errorstr = INVALID_STRING_ID; |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
591 |
_dedicated_forks = false; |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
592 |
_dedicated_enabled = false; |
0 | 593 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
594 |
// The last param of the following function means this: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
595 |
// a letter means: it accepts that param (e.g.: -h) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
596 |
// a ':' behind it means: it need a param (e.g.: -m<driver>) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
597 |
// a '::' behind it means: it can optional have a param (e.g.: -d<debug>) |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
598 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
599 |
optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:"; |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
600 |
#else |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
601 |
optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:"; // no fork option |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
602 |
#endif |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
603 |
|
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
604 |
MyGetOptInit(&mgo, argc-1, argv+1, optformat); |
0 | 605 |
while ((i = MyGetOpt(&mgo)) != -1) { |
606 |
switch(i) { |
|
607 |
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break; |
|
608 |
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break; |
|
609 |
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
610 |
case 'D': { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
611 |
sprintf(musicdriver,"null"); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
612 |
sprintf(sounddriver,"null"); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
613 |
sprintf(videodriver,"dedicated"); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
614 |
_dedicated_enabled = true; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
615 |
} break; |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
616 |
case 'f': { |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
617 |
_dedicated_forks = true; |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
618 |
}; break; |
1 | 619 |
case 'n': { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
620 |
network = true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
621 |
if (mgo.opt) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
622 |
// Optional, you can give an IP |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
623 |
network_conn = mgo.opt; |
1 | 624 |
else |
625 |
network_conn = NULL; |
|
626 |
} break; |
|
0 | 627 |
case 'r': ParseResolution(resolution, mgo.opt); break; |
628 |
case 'l': { |
|
629 |
language = mgo.opt; |
|
630 |
} break; |
|
631 |
case 't': { |
|
632 |
startdate = atoi(mgo.opt); |
|
633 |
} break; |
|
634 |
case 'd': { |
|
635 |
#if defined(WIN32) |
|
636 |
CreateConsole(); |
|
637 |
#endif |
|
638 |
if (mgo.opt) |
|
639 |
SetDebugString(mgo.opt); |
|
640 |
} break; |
|
641 |
case 'e': _switch_mode = SM_EDITOR; break; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
561
diff
changeset
|
642 |
case 'i': _use_dos_palette = true; break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
643 |
case 'g': |
0 | 644 |
if (mgo.opt) { |
645 |
strcpy(_file_to_saveload.name, mgo.opt); |
|
646 |
_switch_mode = SM_LOAD; |
|
647 |
} else |
|
648 |
_switch_mode = SM_NEWGAME; |
|
649 |
break; |
|
650 |
case 'G': |
|
206 | 651 |
_random_seeds[0][0] = atoi(mgo.opt); |
0 | 652 |
break; |
653 |
case 'p': { |
|
654 |
int i = atoi(mgo.opt); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
655 |
// Play as an other player in network games |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
656 |
if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i; |
0 | 657 |
break; |
658 |
} |
|
659 |
case -2: |
|
660 |
case 'h': |
|
661 |
showhelp(); |
|
662 |
return 0; |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
DeterminePaths(); |
|
961 | 667 |
CheckExternalFiles(); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
668 |
|
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
669 |
#ifdef UNIX |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
670 |
// We must fork here, or we'll end up without some resources we need (like sockets) |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
671 |
if (_dedicated_forks) |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
672 |
DedicatedFork(); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
673 |
#endif |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
674 |
|
0 | 675 |
LoadFromConfig(); |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
676 |
LoadFromHighScore(); |
0 | 677 |
|
678 |
// override config? |
|
469
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
679 |
if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); |
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
680 |
if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); |
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
681 |
if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); |
0 | 682 |
if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } |
990
5cbf62b64f36
(svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight
parents:
988
diff
changeset
|
683 |
if (startdate != (uint)-1) _patches.starting_date = startdate; |
0 | 684 |
|
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
685 |
if (_dedicated_forks && !_dedicated_enabled) |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
686 |
_dedicated_forks = false; |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
687 |
|
0 | 688 |
// enumerate language files |
689 |
InitializeLanguagePacks(); |
|
690 |
||
691 |
// initialize screenshot formats |
|
692 |
InitializeScreenshotFormats(); |
|
693 |
||
105 | 694 |
// initialize airport state machines |
695 |
InitializeAirports(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
696 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
697 |
/* initialize all variables that are allocated dynamically */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
698 |
InitializeDynamicVariables(); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
699 |
|
0 | 700 |
// Sample catalogue |
701 |
DEBUG(misc, 1) ("Loading sound effects..."); |
|
223
0e5cc5a65df6
(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
parents:
222
diff
changeset
|
702 |
_os_version = GetOSVersion(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
703 |
MxInitialize(11025, "sample.cat"); |
0 | 704 |
|
705 |
// This must be done early, since functions use the InvalidateWindow* calls |
|
139 | 706 |
InitWindowSystem(); |
0 | 707 |
|
708 |
GfxLoadSprites(); |
|
709 |
LoadStringWidthTable(); |
|
710 |
||
711 |
DEBUG(misc, 1) ("Loading drivers..."); |
|
712 |
LoadDriver(SOUND_DRIVER, _ini_sounddriver); |
|
713 |
LoadDriver(MUSIC_DRIVER, _ini_musicdriver); |
|
714 |
LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads |
|
715 |
MusicLoop(); |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
152
diff
changeset
|
716 |
_savegame_sort_order = 1; // default sorting of savegames is by date, newest first |
0 | 717 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
718 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
719 |
// initialize network-core |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
720 |
NetworkStartUp(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
721 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
722 |
|
0 | 723 |
// Default difficulty level |
724 |
_opt_mod_ptr = &_new_opt; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
725 |
|
0 | 726 |
// ugly hack, if diff_level is 9, it means we got no setting from the config file, so we load the default settings. |
727 |
if (_opt_mod_ptr->diff_level == 9) |
|
728 |
SetDifficultyLevel(0, _opt_mod_ptr); |
|
729 |
||
139 | 730 |
// initialize the ingame console |
731 |
IConsoleInit(); |
|
1246
45f15251412b
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1243
diff
changeset
|
732 |
InitializeGUI(); |
644
e833509107ad
(svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents:
630
diff
changeset
|
733 |
IConsoleCmdExec("exec scripts/autoexec.scr 0"); |
656
01540e6c0fed
(svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents:
644
diff
changeset
|
734 |
|
206 | 735 |
InitPlayerRandoms(); |
0 | 736 |
|
1268
306ebfea663a
(svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents:
1267
diff
changeset
|
737 |
GenerateWorld(1, 6, 6); // Make the viewport initialization happy |
306ebfea663a
(svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents:
1267
diff
changeset
|
738 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
739 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
740 |
if ((network) && (_network_available)) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
741 |
if (network_conn != NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
742 |
const byte *port = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
743 |
const byte *player = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
744 |
uint16 rport; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
745 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
746 |
rport = NETWORK_DEFAULT_PORT; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
747 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
748 |
ParseConnectionString(&player, &port, network_conn); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
749 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
750 |
if (player != NULL) _network_playas = atoi(player); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
751 |
if (port != NULL) rport = atoi(port); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
752 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
753 |
LoadIntroGame(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
754 |
_switch_mode = SM_NONE; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
755 |
NetworkClientConnectGame(network_conn, rport); |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1105
diff
changeset
|
756 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
757 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
758 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
759 |
|
0 | 760 |
while (_video_driver->main_loop() == ML_SWITCHDRIVER) {} |
139 | 761 |
|
762 |
IConsoleFree(); |
|
0 | 763 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
764 |
#ifdef ENABLE_NETWORK |
105 | 765 |
if (_network_available) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
766 |
// Shut down the network and close any open connections |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
767 |
NetworkDisconnect(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
768 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
769 |
NetworkShutDown(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
770 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
771 |
#endif /* ENABLE_NETWORK */ |
0 | 772 |
|
773 |
_video_driver->stop(); |
|
774 |
_music_driver->stop(); |
|
775 |
_sound_driver->stop(); |
|
776 |
||
777 |
SaveToConfig(); |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
778 |
SaveToHighScore(); |
0 | 779 |
|
105 | 780 |
// uninitialize airport state machines |
781 |
UnInitializeAirports(); |
|
0 | 782 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
783 |
/* uninitialize variables that are allocated dynamic */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
784 |
UnInitializeDynamicVariables(); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
785 |
|
1036
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
786 |
/* Close all and any open filehandles */ |
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
787 |
FioCloseAll(); |
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
788 |
|
0 | 789 |
return 0; |
790 |
} |
|
791 |
||
792 |
static void ShowScreenshotResult(bool b) |
|
793 |
{ |
|
794 |
if (b) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
795 |
SetDParam(0, STR_SPEC_SCREENSHOT_NAME); |
0 | 796 |
ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0); |
797 |
} else { |
|
798 |
ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0); |
|
799 |
} |
|
800 |
||
801 |
} |
|
802 |
||
1095 | 803 |
static void MakeNewGame(void) |
0 | 804 |
{ |
805 |
_game_mode = GM_NORMAL; |
|
806 |
||
807 |
// Copy in game options |
|
808 |
_opt_mod_ptr = &_opt; |
|
809 |
memcpy(&_opt, &_new_opt, sizeof(_opt)); |
|
810 |
||
811 |
GfxLoadSprites(); |
|
812 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
813 |
// Reinitialize windows |
0 | 814 |
InitWindowSystem(); |
815 |
LoadStringWidthTable(); |
|
816 |
||
817 |
SetupColorsAndInitialWindow(); |
|
818 |
||
819 |
// Randomize world |
|
1218 | 820 |
GenerateWorld(0, _patches.map_x, _patches.map_y); |
0 | 821 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
822 |
// In a dedicated server, the server does not play |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
823 |
if (_network_dedicated) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
824 |
_local_player = OWNER_SPECTATOR; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
825 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
826 |
// Create a single player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
827 |
DoStartupNewPlayer(false); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
828 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
829 |
_local_player = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
830 |
} |
0 | 831 |
|
832 |
MarkWholeScreenDirty(); |
|
833 |
} |
|
834 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
835 |
static void MakeNewEditorWorld(void) |
0 | 836 |
{ |
837 |
_game_mode = GM_EDITOR; |
|
838 |
||
839 |
// Copy in game options |
|
840 |
_opt_mod_ptr = &_opt; |
|
841 |
memcpy(&_opt, &_new_opt, sizeof(_opt)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
842 |
|
0 | 843 |
GfxLoadSprites(); |
844 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
845 |
// Re-init the windowing system |
0 | 846 |
InitWindowSystem(); |
847 |
||
848 |
// Create toolbars |
|
849 |
SetupColorsAndInitialWindow(); |
|
850 |
||
851 |
// Startup the game system |
|
1218 | 852 |
GenerateWorld(1, _patches.map_x, _patches.map_y); |
0 | 853 |
|
854 |
_local_player = OWNER_NONE; |
|
855 |
MarkWholeScreenDirty(); |
|
856 |
} |
|
857 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
858 |
void StartupPlayers(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
859 |
void StartupDisasters(void); |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
115
diff
changeset
|
860 |
|
1095 | 861 |
static void StartScenario(void) |
0 | 862 |
{ |
863 |
_game_mode = GM_NORMAL; |
|
864 |
||
865 |
// invalid type |
|
866 |
if (_file_to_saveload.mode == SL_INVALID) { |
|
867 |
printf("Savegame is obsolete or invalid format: %s\n", _file_to_saveload.name); |
|
868 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
869 |
_game_mode = GM_MENU; |
|
870 |
return; |
|
871 |
} |
|
872 |
||
873 |
// Copy in game options |
|
295
f3fe541a0fe4
(svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik
parents:
239
diff
changeset
|
874 |
// Removed copying of game options when using "new game". --dominik |
f3fe541a0fe4
(svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik
parents:
239
diff
changeset
|
875 |
// _opt_mod_ptr = &_opt; |
f3fe541a0fe4
(svn r301) Fix: game options (like drive side) are not taken from the scenario when using 'new game' command
dominik
parents:
239
diff
changeset
|
876 |
// memcpy(&_opt, &_new_opt, sizeof(_opt)); |
0 | 877 |
|
878 |
GfxLoadSprites(); |
|
879 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
880 |
// Reinitialize windows |
0 | 881 |
InitWindowSystem(); |
882 |
LoadStringWidthTable(); |
|
883 |
||
884 |
SetupColorsAndInitialWindow(); |
|
885 |
||
886 |
// Load game |
|
887 |
if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) { |
|
888 |
LoadIntroGame(); |
|
889 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
890 |
} |
|
891 |
||
115
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
892 |
// Inititalize data |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
893 |
StartupPlayers(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
894 |
StartupEngines(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
895 |
StartupDisasters(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
896 |
|
139 | 897 |
// When starting a scenario, is it really a load.. |
898 |
// and in AfterLoad a player is started when it is |
|
899 |
// a scenario.. so we do not need it here. |
|
900 |
// DoStartupNewPlayer(false); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
901 |
|
0 | 902 |
_local_player = 0; |
903 |
||
904 |
MarkWholeScreenDirty(); |
|
905 |
} |
|
906 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
907 |
bool SafeSaveOrLoad(const char *filename, int mode, int newgm) |
0 | 908 |
{ |
909 |
byte ogm = _game_mode; |
|
910 |
int r; |
|
911 |
||
912 |
_game_mode = newgm; |
|
913 |
r = SaveOrLoad(filename, mode); |
|
914 |
if (r == SL_REINIT) { |
|
915 |
if (ogm == GM_MENU) |
|
916 |
LoadIntroGame(); |
|
917 |
else if (ogm == GM_EDITOR) |
|
918 |
MakeNewEditorWorld(); |
|
919 |
else |
|
920 |
MakeNewGame(); |
|
921 |
return false; |
|
922 |
} else if (r != SL_OK) { |
|
923 |
_game_mode = ogm; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
924 |
return false; |
0 | 925 |
} else |
926 |
return true; |
|
927 |
} |
|
928 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
929 |
void SwitchMode(int new_mode) |
0 | 930 |
{ |
139 | 931 |
_in_state_game_loop = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
932 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
933 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
934 |
// If we are saving something, the network stays in his current state |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
935 |
if (new_mode != SM_SAVE) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
936 |
// If the network is active, make it not-active |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
937 |
if (_networking) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
938 |
if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
939 |
NetworkReboot(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
940 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
941 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
942 |
NetworkDisconnect(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
943 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
944 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
945 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
946 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
947 |
// If we are a server, we restart the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
948 |
if (_is_network_server) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
949 |
// But not if we are going to the menu |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
950 |
if (new_mode != SM_MENU) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
951 |
NetworkServerStart(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
952 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
953 |
// This client no longer wants to be a network-server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
954 |
_is_network_server = false; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
955 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
956 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
957 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
958 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
959 |
|
0 | 960 |
switch(new_mode) { |
961 |
case SM_EDITOR: // Switch to scenario editor |
|
962 |
MakeNewEditorWorld(); |
|
963 |
break; |
|
964 |
||
965 |
case SM_NEWGAME: |
|
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
966 |
#ifdef ENABLE_NETWORK |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
967 |
if (_network_server) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
968 |
snprintf(_network_game_info.map_name, 40, "Random"); |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
969 |
#endif /* ENABLE_NETWORK */ |
0 | 970 |
MakeNewGame(); |
971 |
break; |
|
972 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
973 |
case SM_START_SCENARIO: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
974 |
StartScenario(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
975 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
976 |
|
0 | 977 |
normal_load: |
978 |
case SM_LOAD: { // Load game |
|
979 |
||
980 |
_error_message = INVALID_STRING_ID; |
|
981 |
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) { |
|
942
31f28eedd2b8
(svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents:
929
diff
changeset
|
982 |
LoadIntroGame(); |
0 | 983 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
984 |
} else { |
|
985 |
_opt_mod_ptr = &_opt; |
|
986 |
_local_player = 0; |
|
987 |
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog) |
|
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
988 |
#ifdef ENABLE_NETWORK |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
989 |
if (_network_server) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
990 |
snprintf(_network_game_info.map_name, 40, "Loaded game"); |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
991 |
#endif /* ENABLE_NETWORK */ |
0 | 992 |
} |
993 |
break; |
|
994 |
} |
|
995 |
||
996 |
case SM_LOAD_SCENARIO: { |
|
997 |
int i; |
|
998 |
||
999 |
if (_game_mode == GM_MENU) goto normal_load; |
|
1000 |
||
1001 |
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) { |
|
1002 |
_opt_mod_ptr = &_opt; |
|
1003 |
||
1004 |
_local_player = OWNER_NONE; |
|
1005 |
_generating_world = true; |
|
1006 |
// delete all players. |
|
1007 |
for(i=0; i != MAX_PLAYERS; i++) { |
|
1008 |
ChangeOwnershipOfPlayerItems(i, 0xff); |
|
1009 |
_players[i].is_active = false; |
|
1010 |
} |
|
1011 |
_generating_world = false; |
|
1012 |
// delete all stations owned by a player |
|
1013 |
DeleteAllPlayerStations(); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1014 |
|
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
1015 |
#ifdef ENABLE_NETWORK |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1016 |
if (_network_server) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1017 |
snprintf(_network_game_info.map_name, 40, "Loaded scenario"); |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
1018 |
#endif /* ENABLE_NETWORK */ |
0 | 1019 |
} else |
1020 |
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
1021 |
||
1022 |
break; |
|
1023 |
} |
|
1024 |
||
1025 |
||
1026 |
case SM_MENU: // Switch to game menu |
|
1027 |
LoadIntroGame(); |
|
1028 |
break; |
|
1029 |
||
1030 |
case SM_SAVE: // Save game |
|
1031 |
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) |
|
1032 |
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0); |
|
1033 |
else |
|
1034 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
1035 |
break; |
|
1036 |
||
1037 |
case SM_GENRANDLAND: |
|
1218 | 1038 |
GenerateWorld(2, _patches.map_x, _patches.map_y); |
0 | 1039 |
// XXX: set date |
1040 |
_local_player = OWNER_NONE; |
|
1041 |
MarkWholeScreenDirty(); |
|
1042 |
break; |
|
1043 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1044 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1045 |
if (_switch_mode_errorstr!=INVALID_STRING_ID) |
172
8d8b3383470d
(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
parents:
168
diff
changeset
|
1046 |
ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0); |
0 | 1047 |
|
1048 |
_in_state_game_loop = false; |
|
1049 |
} |
|
1050 |
||
1051 |
||
1052 |
// State controlling game loop. |
|
1053 |
// The state must not be changed from anywhere |
|
1054 |
// but here. |
|
1055 |
// That check is enforced in DoCommand. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
1056 |
void StateGameLoop(void) |
0 | 1057 |
{ |
213
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
1058 |
// dont execute the state loop during pause |
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
1059 |
if (_pause) return; |
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
1060 |
|
0 | 1061 |
_in_state_game_loop = true; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1062 |
// _frame_counter is increased somewhere else when in network-mode |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1063 |
// Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1064 |
// Should that not be deleted? If so, the next 2 lines can also be deleted |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1065 |
if (!_networking) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1066 |
_frame_counter++; |
0 | 1067 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1068 |
if (_savedump_path[0] && (uint)_frame_counter >= _savedump_first && (uint)(_frame_counter -_savedump_first) % _savedump_freq == 0 ) { |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1069 |
char buf[100]; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1070 |
sprintf(buf, "%s%.5d.sav", _savedump_path, _frame_counter); |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1071 |
SaveOrLoad(buf, SL_SAVE); |
0 | 1072 |
if ((uint)_frame_counter >= _savedump_last) exit(1); |
1073 |
} |
|
1074 |
||
1075 |
if (_game_mode == GM_EDITOR) { |
|
1076 |
RunTileLoop(); |
|
1077 |
CallVehicleTicks(); |
|
1078 |
CallLandscapeTick(); |
|
1079 |
CallWindowTickEvent(); |
|
1080 |
NewsLoop(); |
|
1081 |
} else { |
|
206 | 1082 |
// All these actions has to be done from OWNER_NONE |
1083 |
// for multiplayer compatibility |
|
1084 |
uint p = _current_player; |
|
1085 |
_current_player = OWNER_NONE; |
|
1086 |
||
0 | 1087 |
AnimateAnimatedTiles(); |
1088 |
IncreaseDate(); |
|
1089 |
RunTileLoop(); |
|
1090 |
CallVehicleTicks(); |
|
1091 |
CallLandscapeTick(); |
|
1092 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1093 |
// To bad the AI does not work in multiplayer, because states are not saved |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1094 |
// perfectly |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1095 |
if (!disable_computer && !_networking) |
0 | 1096 |
RunOtherPlayersLoop(); |
1097 |
||
1098 |
CallWindowTickEvent(); |
|
1099 |
NewsLoop(); |
|
206 | 1100 |
_current_player = p; |
0 | 1101 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1102 |
|
0 | 1103 |
_in_state_game_loop = false; |
1104 |
} |
|
1105 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
1106 |
static void DoAutosave(void) |
0 | 1107 |
{ |
1108 |
char buf[200]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1109 |
|
1 | 1110 |
if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) { |
0 | 1111 |
Player *p; |
1112 |
char *s; |
|
1113 |
sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP); |
|
1114 |
p = DEREF_PLAYER(_local_player); |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1115 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1116 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1117 |
SetDParam(2, _date); |
760
f659cca20dac
(svn r1218) Fix: Autosaves go to the correct folder again with keep_all_autosave enabled
dominik
parents:
704
diff
changeset
|
1118 |
s= (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004); |
0 | 1119 |
strcpy(s, ".sav"); |
1120 |
} else { |
|
1121 |
int n = _autosave_ctr; |
|
1122 |
_autosave_ctr = (_autosave_ctr + 1) & 15; |
|
1123 |
sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n); |
|
1124 |
} |
|
1125 |
||
557
8540788a827e
(svn r959) -Fix: fix previous typo for workaround of braindead MSVC6 (Tron)
darkvater
parents:
543
diff
changeset
|
1126 |
DEBUG(misc, 2) ("Autosaving to %s", buf); |
0 | 1127 |
if (SaveOrLoad(buf, SL_SAVE) != SL_OK) |
1128 |
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0); |
|
1129 |
} |
|
1130 |
||
1199
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
1131 |
extern void HandleKeyScrolling(void); |
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
1132 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
1133 |
void GameLoop(void) |
0 | 1134 |
{ |
1135 |
int m; |
|
1136 |
||
1137 |
// autosave game? |
|
1138 |
if (_do_autosave) { |
|
1139 |
_do_autosave = false; |
|
1140 |
DoAutosave(); |
|
1141 |
RedrawAutosave(); |
|
1142 |
} |
|
1143 |
||
1199
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
1144 |
// handle scrolling of the main window |
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
1145 |
if (_dirkeys) HandleKeyScrolling(); |
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
1146 |
|
0 | 1147 |
// make a screenshot? |
1148 |
if ((m=_make_screenshot) != 0) { |
|
1149 |
_make_screenshot = 0; |
|
1150 |
switch(m) { |
|
1151 |
case 1: // make small screenshot |
|
1152 |
UndrawMouseCursor(); |
|
1153 |
ShowScreenshotResult(MakeScreenshot()); |
|
1154 |
break; |
|
1155 |
case 2: // make large screenshot |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
861
diff
changeset
|
1156 |
ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, MapSizeY() * 32, 0)); |
0 | 1157 |
break; |
1158 |
} |
|
1159 |
} |
|
1160 |
||
1161 |
// switch game mode? |
|
1162 |
if ((m=_switch_mode) != SM_NONE) { |
|
1163 |
_switch_mode = SM_NONE; |
|
1164 |
SwitchMode(m); |
|
1165 |
} |
|
1166 |
||
1167 |
IncreaseSpriteLRU(); |
|
1168 |
InteractiveRandom(); |
|
1169 |
||
1170 |
if (_scroller_click_timeout > 3) |
|
1171 |
_scroller_click_timeout -= 3; |
|
1172 |
else |
|
1173 |
_scroller_click_timeout = 0; |
|
1174 |
||
1175 |
_caret_timer += 3; |
|
1176 |
_timer_counter+=8; |
|
1177 |
CursorTick(); |
|
1178 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1179 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1180 |
// Check for UDP stuff |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1181 |
NetworkUDPGameLoop(); |
0 | 1182 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1183 |
if (_networking) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1184 |
// Multiplayer |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1185 |
NetworkGameLoop(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1186 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1187 |
if (_network_reconnect > 0 && --_network_reconnect == 0) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1188 |
// This means that we want to reconnect to the last host |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1189 |
// We do this here, because it means that the network is really closed |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1190 |
NetworkClientConnectGame(_network_last_host, _network_last_port); |
206 | 1191 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1192 |
// Singleplayer |
213
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
1193 |
StateGameLoop(); |
0 | 1194 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1195 |
#else |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1196 |
StateGameLoop(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1197 |
#endif /* ENABLE_NETWORK */ |
0 | 1198 |
|
1199 |
if (!_pause && _display_opt&DO_FULL_ANIMATION) |
|
1200 |
DoPaletteAnimations(); |
|
1201 |
||
67
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
65
diff
changeset
|
1202 |
if (!_pause || _cheats.build_in_pause.value) |
0 | 1203 |
MoveAllTextEffects(); |
1204 |
||
1205 |
MouseLoop(); |
|
1206 |
||
1207 |
if (_game_mode != GM_MENU) |
|
1208 |
MusicLoop(); |
|
1209 |
} |
|
1210 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
1211 |
void BeforeSaveGame(void) |
0 | 1212 |
{ |
1213 |
Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
|
1214 |
||
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
1215 |
if (w != NULL) { |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
1216 |
_saved_scrollpos_x = WP(w,vp_d).scrollpos_x; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
1217 |
_saved_scrollpos_y = WP(w,vp_d).scrollpos_y; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
1218 |
_saved_scrollpos_zoom = w->viewport->zoom; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
1219 |
} |
0 | 1220 |
} |
1221 |
||
1095 | 1222 |
static void ConvertTownOwner(void) |
0 | 1223 |
{ |
1224 |
uint tile; |
|
1225 |
||
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
861
diff
changeset
|
1226 |
for (tile = 0; tile != MapSize(); tile++) { |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1027
diff
changeset
|
1227 |
if (IsTileType(tile, MP_STREET)) { |
0 | 1228 |
if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80) |
1229 |
_map3_lo[tile] = OWNER_TOWN; |
|
1230 |
||
1231 |
if (_map_owner[tile] & 0x80) |
|
1232 |
_map_owner[tile] = OWNER_TOWN; |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1027
diff
changeset
|
1233 |
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1234 |
if (_map_owner[tile] & 0x80) |
1235 |
_map_owner[tile] = OWNER_TOWN; |
|
1236 |
} |
|
1237 |
} |
|
1238 |
} |
|
1239 |
||
1240 |
// before savegame version 4, the name of the company determined if it existed |
|
1095 | 1241 |
static void CheckIsPlayerActive(void) |
0 | 1242 |
{ |
1243 |
Player *p; |
|
1244 |
FOR_ALL_PLAYERS(p) { |
|
1245 |
if (p->name_1 != 0) { |
|
1246 |
p->is_active = true; |
|
1247 |
} |
|
1248 |
} |
|
1249 |
} |
|
1250 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1251 |
// since savegame version 4.1, exclusive transport rights are stored at towns |
1095 | 1252 |
static void UpdateExclusiveRights(void) |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1253 |
{ |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1254 |
Town *t; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1255 |
FOR_ALL_TOWNS(t) if (t->xy != 0) { |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1256 |
t->exclusivity=(byte)-1; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1257 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1258 |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
1259 |
/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1260 |
could be implemented this way: |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1261 |
1.) Go through all stations |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1262 |
Build an array town_blocked[ town_id ][ player_id ] |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1263 |
that stores if at least one station in that town is blocked for a player |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1264 |
2.) Go through that array, if you find a town that is not blocked for |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1265 |
one player, but for all others, then give him exclusivity. |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1266 |
*/ |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1267 |
} |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1268 |
|
768
deb40d3554a2
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
1269 |
byte convert_currency[] = { |
762
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1270 |
0, 1, 12, 8, 3, |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1271 |
10, 14, 19, 4, 5, |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1272 |
9, 11, 13, 6, 17, |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1273 |
16, 22, 21, 7, 15, |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1274 |
18, 2, 20, }; |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1275 |
|
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1276 |
// since savegame version 4.2 the currencies are arranged differently |
1095 | 1277 |
static void UpdateCurrencies(void) |
762
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1278 |
{ |
768
deb40d3554a2
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
1279 |
_opt.currency = convert_currency[_opt.currency]; |
762
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1280 |
} |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1281 |
|
1181
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1282 |
/* Up to revision 1413 the invisible tiles at the southern border have not been |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1283 |
* MP_VOID, even though they should have. This is fixed by this function |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1284 |
*/ |
1095 | 1285 |
static void UpdateVoidTiles(void) |
929
1a071a06af3f
(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
parents:
921
diff
changeset
|
1286 |
{ |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
950
diff
changeset
|
1287 |
uint i; |
1181
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1288 |
|
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1289 |
for (i = 0; i < MapMaxY(); ++i) |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1290 |
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID); |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1291 |
for (i = 0; i < MapSizeX(); ++i) |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1292 |
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID); |
929
1a071a06af3f
(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
parents:
921
diff
changeset
|
1293 |
} |
1a071a06af3f
(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
parents:
921
diff
changeset
|
1294 |
|
1165
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1295 |
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1296 |
static void UpdateSignOwner(void) |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1297 |
{ |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1298 |
SignStruct *ss; |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1299 |
FOR_ALL_SIGNS(ss) { |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1300 |
ss->owner = OWNER_NONE; // no owner |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1301 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1302 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1303 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1304 |
extern void UpdateOldAircraft( void ); |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1305 |
extern void UpdateOilRig( void ); |
0 | 1306 |
|
1307 |
bool AfterLoadGame(uint version) |
|
1308 |
{ |
|
1309 |
Window *w; |
|
1310 |
ViewPort *vp; |
|
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
1311 |
|
0 | 1312 |
// in version 2.1 of the savegame, town owner was unified. |
1313 |
if (version <= 0x200) { |
|
1314 |
ConvertTownOwner(); |
|
1315 |
} |
|
1316 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1317 |
// from version 4.1 of the savegame, exclusive rights are stored at towns |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1318 |
if (version <= 0x400) { |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1319 |
UpdateExclusiveRights(); |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1320 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1321 |
|
762
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1322 |
// from version 4.2 of the savegame, currencies are in a different order |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1323 |
if (version <= 0x401) { |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1324 |
UpdateCurrencies(); |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1325 |
} |
7afe6c8554cb
(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
parents:
760
diff
changeset
|
1326 |
|
1165
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1327 |
// from version 6.0 of the savegame, signs have an "owner" |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1328 |
if (version <= 0x600) { |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1329 |
UpdateSignOwner(); |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1330 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1331 |
|
831
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1332 |
/* In old version there seems to be a problem that water is owned by |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1333 |
OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1334 |
(0x402) version, so I just check when versions are older, and then |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1335 |
walk through the whole map.. */ |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1336 |
if (version <= 0x402) { |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1337 |
TileIndex tile = TILE_XY(0,0); |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1338 |
uint w = MapSizeX(); |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1339 |
uint h = MapSizeY(); |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1340 |
|
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1341 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1027
diff
changeset
|
1342 |
if (IsTileType(tile_cur, MP_WATER) && _map_owner[tile_cur] >= MAX_PLAYERS) |
831
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1343 |
_map_owner[tile_cur] = OWNER_WATER; |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1344 |
END_TILE_LOOP(tile_cur, w, h, tile) |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1345 |
} |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1346 |
|
0 | 1347 |
// convert road side to my format. |
1348 |
if (_opt.road_side) _opt.road_side = 1; |
|
1349 |
||
1350 |
// Load the sprites |
|
1351 |
GfxLoadSprites(); |
|
1352 |
||
1353 |
// Update current year |
|
1354 |
SetDate(_date); |
|
1355 |
||
1356 |
// reinit the landscape variables (landscape might have changed) |
|
1357 |
InitializeLandscapeVariables(true); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1358 |
|
0 | 1359 |
// Update all vehicles |
1360 |
AfterLoadVehicles(); |
|
1361 |
// in version 2.2 of the savegame, we have new airports |
|
1362 |
if (version <= 0x201) { |
|
1363 |
UpdateOldAircraft(); |
|
1364 |
} |
|
1365 |
||
1366 |
UpdateAllStationVirtCoord(); |
|
1367 |
||
1368 |
// Setup town coords |
|
1369 |
AfterLoadTown(); |
|
1370 |
UpdateAllSignVirtCoords(); |
|
1371 |
||
1372 |
// make sure there is a town in the game |
|
1373 |
if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) |
|
1374 |
{ |
|
1375 |
_error_message = STR_NO_TOWN_IN_SCENARIO; |
|
1376 |
return false; |
|
1377 |
} |
|
1378 |
||
1379 |
// Initialize windows |
|
1380 |
InitWindowSystem(); |
|
1381 |
SetupColorsAndInitialWindow(); |
|
1382 |
||
1383 |
w = FindWindowById(WC_MAIN_WINDOW, 0); |
|
1384 |
||
1385 |
WP(w,vp_d).scrollpos_x = _saved_scrollpos_x; |
|
1386 |
WP(w,vp_d).scrollpos_y = _saved_scrollpos_y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1387 |
|
0 | 1388 |
vp = w->viewport; |
1389 |
vp->zoom = _saved_scrollpos_zoom; |
|
1390 |
vp->virtual_width = vp->width << vp->zoom; |
|
1391 |
vp->virtual_height = vp->height << vp->zoom; |
|
1392 |
||
1393 |
||
1394 |
// in version 4.0 of the savegame, is_active was introduced to determine |
|
1395 |
// if a player does exist, rather then checking name_1 |
|
1396 |
if (version <= 0x400) { |
|
1397 |
CheckIsPlayerActive(); |
|
1398 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1399 |
|
929
1a071a06af3f
(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
parents:
921
diff
changeset
|
1400 |
// the void tiles on the southern border used to belong to a wrong class. |
1a071a06af3f
(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
parents:
921
diff
changeset
|
1401 |
if (version <= 0x402) |
1a071a06af3f
(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
parents:
921
diff
changeset
|
1402 |
UpdateVoidTiles(); |
1a071a06af3f
(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
parents:
921
diff
changeset
|
1403 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1404 |
// If Load Scenario / New (Scenario) Game is used, |
139 | 1405 |
// a player does not exist yet. So create one here. |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1406 |
// 1 exeption: network-games. Those can have 0 players |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1407 |
// But this exeption is not true for network_servers! |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1408 |
if (!_players[0].is_active && (!_networking || (_networking && _network_server))) |
139 | 1409 |
DoStartupNewPlayer(false); |
0 | 1410 |
|
152
c3964b43943e
(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
parents:
139
diff
changeset
|
1411 |
DoZoomInOutWindow(ZOOM_NONE, w); // update button status |
0 | 1412 |
MarkWholeScreenDirty(); |
1413 |
||
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1414 |
//In 5.1, Oilrigs have been moved (again) |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1415 |
if (version <= 0x500) { |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1416 |
UpdateOilRig(); |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1417 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1418 |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1419 |
if (version <= 0x600) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1420 |
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1421 |
if (IsTileType(tile, MP_HOUSE)) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1422 |
_map3_hi[tile] = _map2[tile]; |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1423 |
//XXX magic |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1424 |
SetTileType(tile, MP_VOID); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1425 |
_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index; |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1426 |
SetTileType(tile, MP_HOUSE); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1427 |
} else if (IsTileType(tile, MP_STREET)) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1428 |
//XXX magic |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1429 |
SetTileType(tile, MP_VOID); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1430 |
_map3_hi[tile] |= (_map2[tile] << 4); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1431 |
if ( _map_owner[tile] == OWNER_TOWN) |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1432 |
_map2[tile] = ClosestTownFromTile(tile,(uint)-1)->index; |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1433 |
else |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1434 |
_map2[tile] = 0; |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1435 |
SetTileType(tile, MP_STREET); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1436 |
} |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1437 |
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1438 |
} |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1439 |
|
0 | 1440 |
return true; |
1441 |
} |
|
1442 |
||
1443 |
void DebugProc(int i) |
|
1444 |
{ |
|
1445 |
switch(i) { |
|
1446 |
case 0: |
|
1447 |
*(byte*)0 = 0; |
|
1448 |
break; |
|
1449 |
case 1: |
|
795
5fd56cf5b6e3
(svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight
parents:
774
diff
changeset
|
1450 |
/* Server can not cheat in advertise mode either! */ |
802
754d2d245efc
(svn r1272) -Fix: game compiles again with network disabled
truelight
parents:
795
diff
changeset
|
1451 |
#ifdef ENABLE_NETWORK |
795
5fd56cf5b6e3
(svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight
parents:
774
diff
changeset
|
1452 |
if (!_networking || !_network_server || !_network_advertise) |
802
754d2d245efc
(svn r1272) -Fix: game compiles again with network disabled
truelight
parents:
795
diff
changeset
|
1453 |
#endif /* ENABLE_NETWORK */ |
795
5fd56cf5b6e3
(svn r1265) -Fix: the server can also no longer use the money cheat if the
truelight
parents:
774
diff
changeset
|
1454 |
DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT); |
0 | 1455 |
break; |
1456 |
case 2: |
|
1457 |
UpdateAllStationVirtCoord(); |
|
1458 |
break; |
|
1459 |
} |
|
1460 |
} |