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