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