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