openttd.c
author tron
Wed, 16 Nov 2005 08:35:26 +0000
changeset 2649 7cd504bd4e51
parent 2644 6f699b15c531
child 2670 34970983ef08
permissions -rw-r--r--
(svn r3191) Move declaration and definition of _dbg_screen_rect to a place where it somewhat makes sense and wrap them in #ifdef _DEBUG
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1317
f382f1b439c7 (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
     4
#include "string.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     5
#include "table/strings.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1296
diff changeset
     6
#include "debug.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
     7
#include "driver.h"
2162
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 2147
diff changeset
     8
#include "saveload.h"
1309
dab90d4cbf2d (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
     9
#include "strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 659
diff changeset
    10
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1199
diff changeset
    11
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#define VARDEF
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
    14
#include "openttd.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2162
diff changeset
    15
#include "functions.h"
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
    16
#include "mixer.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1329
diff changeset
    17
#include "spritecache.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "gfx.h"
2340
0a9f3eeccb96 (svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents: 2322
diff changeset
    19
#include "gfxinit.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
#include "sound.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
#include "hal.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
#include "airport.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 123
diff changeset
    36
#include "console.h"
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    37
#include "screenshot.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    38
#include "network.h"
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
    39
#include "signs.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1310
diff changeset
    40
#include "depot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
    41
#include "waypoint.h"
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
    42
#include "ai/ai.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
2033
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
    46
#ifdef GPMI
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
    47
#include <gpmi.h>
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
    48
#include <gpmi/packages/paths.h>
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
    49
#endif /* GPMI */
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
    50
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
    51
void GenerateWorld(int mode, uint size_x, uint size_y);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    52
void CallLandscapeTick(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    53
void IncreaseDate(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    54
void DoPaletteAnimations(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    55
void MusicLoop(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    56
void ResetMusic(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    57
void InitializeStations(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    58
void DeleteAllPlayerStations(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
extern void DoStartupNewPlayer(bool is_ai);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
extern void ShowOSErrorBox(const char *buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
1436
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    64
/* TODO: usrerror() for errors which are not of an internal nature but
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    65
 * caused by the user, i.e. missing files or fatal configuration errors.
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    66
 * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    67
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    68
void CDECL error(const char* s, ...)
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    69
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	char buf[512];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    72
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	va_start(va, s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	vsprintf(buf, s, va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	va_end(va);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
    76
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	ShowOSErrorBox(buf);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    78
	if (_video_driver != NULL) _video_driver->stop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
void CDECL ShowInfoF(const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	va_start(va, str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	vsprintf(buf, str, va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	va_end(va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
1310
85cde2193afc (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
    95
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	FILE *in;
1105
b3003b14e45c (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
    98
	byte *mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	size_t len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	in = fopen(filename, "rb");
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   102
	if (in == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	fseek(in, 0, SEEK_END);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	len = ftell(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	fseek(in, 0, SEEK_SET);
1105
b3003b14e45c (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   107
	if (len > maxsize || (mem = malloc(len + 1)) == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	}
1105
b3003b14e45c (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   111
	mem[len] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	if (fread(mem, len, 1, in) != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		free(mem);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
	fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	*lenp = len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	return mem;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   123
static void showhelp(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	char buf[4096], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   127
	p = strecpy(buf,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		"Command line options:\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   129
		"  -v drv              = Set video driver (see below)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   130
		"  -s drv              = Set sound driver (see below)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   131
		"  -m drv              = Set music driver (see below)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   132
		"  -r res              = Set resolution (for instance 800x600)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   133
		"  -h                  = Display this help text\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   134
		"  -t date             = Set starting date\n"
1440
2eb4dd1e0465 (svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents: 1436
diff changeset
   135
		"  -d [[fac=]lvl[,...]]= Debug mode\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   136
		"  -l lng              = Select Language\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   137
		"  -e                  = Start Editor\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   138
		"  -g [savegame]       = Start new/save game immediately\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   139
		"  -G seed             = Set random seed\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   140
		"  -n [ip#player:port] = Start networkgame\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   141
		"  -D                  = Start dedicated server\n"
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   142
		#if !defined(__MORPHOS__) && !defined(__AMIGA__)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   143
		"  -f                  = Fork into the background (dedicated only)\n"
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   144
		#endif
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 561
diff changeset
   145
		"  -i                  = Force to use the DOS palette (use this if you see a lot of pink)\n"
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   146
		"  -p #player          = Player as #player (deprecated) (network only)\n"
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   147
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n",
1317
f382f1b439c7 (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
   148
		lastof(buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
   151
	GetDriverList(p);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	char *opt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	int numleft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	char **argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	const char *options;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	char *cont;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
} MyGetOptData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	md->numleft = argc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	md->argv = argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	md->options = options;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
static int MyGetOpt(MyGetOptData *md)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	char *s,*r,*t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   177
	s = md->cont;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   178
	if (s != NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
		goto md_continue_here;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   181
	for (;;) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   182
		if (--md->numleft < 0) return -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
		s = *md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
		if (*s == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
md_continue_here:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
			s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
			if (*s != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
				// Found argument, try to locate it in options.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
				if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
					// ERROR!
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
					return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
				if (r[1] == ':') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
					// Item wants an argument. Check if the argument follows, or if it comes as a separate arg.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
					if (!*(t = s + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
						// It comes as a separate arg. Check if out of args?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
						if (--md->numleft < 0 || *(t = *md->argv) == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
							// Check if item is optional?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
							if (r[2] != ':')
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
								return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
							md->numleft++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
							t = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
						} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
							md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
					md->opt = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
					md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
					return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
				md->opt = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
				md->cont = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
				return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
			// This is currently not supported.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
			return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2526
diff changeset
   224
static void ParseResolution(int res[2], const char* s)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	char *t = strchr(s, 'x');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	if (t == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
		ShowInfoF("Invalid resolution '%s'", s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
1764
a976570cdbd9 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   232
	res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
a976570cdbd9 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   233
	res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   234
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   236
static void InitializeDynamicVariables(void)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   237
{
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   238
	/* Dynamic stuff needs to be initialized somewhere... */
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   239
	_station_sort  = NULL;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   240
	_vehicle_sort  = NULL;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   241
	_town_sort     = NULL;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   242
	_industry_sort = NULL;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   243
}
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   244
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   245
static void UnInitializeDynamicVariables(void)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   246
{
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   247
	/* Dynamic stuff needs to be free'd somewhere... */
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   248
	CleanPool(&_town_pool);
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   249
	CleanPool(&_industry_pool);
1272
d3e09adb7736 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1268
diff changeset
   250
	CleanPool(&_station_pool);
1279
4f83fbde72de (svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents: 1272
diff changeset
   251
	CleanPool(&_vehicle_pool);
1283
b9569cc0644f (svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents: 1279
diff changeset
   252
	CleanPool(&_sign_pool);
1314
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1313
diff changeset
   253
	CleanPool(&_order_pool);
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   254
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   255
	free(_station_sort);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   256
	free(_vehicle_sort);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   257
	free(_town_sort);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   258
	free(_industry_sort);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   259
}
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   260
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   261
static void UnInitializeGame(void)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   262
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   263
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   264
	UnInitNewgrEngines();
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   265
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   266
	free(_config_file);
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   267
}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   268
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   269
static void LoadIntroGame(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   270
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   271
	char filename[256];
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   272
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   273
	_game_mode = GM_MENU;
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   274
	CLRBITS(_display_opt, DO_TRANS_BUILDINGS); // don't make buildings transparent in intro
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   275
	_opt_ptr = &_opt_newgame;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   276
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   277
	GfxLoadSprites();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   278
	LoadStringWidthTable();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   279
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   280
	// Setup main window
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   281
	ResetWindowSystem();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   282
	SetupColorsAndInitialWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   283
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   284
	// Generate a world.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   285
	sprintf(filename, "%sopntitle.dat",  _path.data_dir);
921
1884bb89c8dc (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   286
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 557
diff changeset
   287
#if defined SECOND_DATA_DIR
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 557
diff changeset
   288
		sprintf(filename, "%sopntitle.dat",  _path.second_data_dir);
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 557
diff changeset
   289
		if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 557
diff changeset
   290
#endif
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   291
			GenerateWorld(1, 64, 64); // if failed loading, make empty world.
921
1884bb89c8dc (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   292
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   293
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   294
	_pause = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   295
	_local_player = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   296
	MarkWholeScreenDirty();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   297
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   298
	// Play main theme
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   299
	if (_music_driver->is_song_playing()) ResetMusic();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   300
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   301
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   302
#if defined(UNIX) && !defined(__MORPHOS__)
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
   303
extern void DedicatedFork(void);
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   304
#endif
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   305
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
int ttd_main(int argc, char* argv[])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	MyGetOptData mgo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	int i;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   310
	bool network = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	char *network_conn = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	char *language = NULL;
1010
17470a8e5eb7 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents: 1009
diff changeset
   313
	const char *optformat;
469
d26f0e5705dc (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   314
	char musicdriver[16], sounddriver[16], videodriver[16];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	int resolution[2] = {0,0};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	uint startdate = -1;
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   317
	bool dedicated;
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   318
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
	_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	_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
   323
	_switch_mode_errorstr = INVALID_STRING_ID;
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   324
	_dedicated_forks = false;
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   325
	dedicated = false;
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   326
	_config_file = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   328
	// The last param of the following function means this:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   329
	//   a letter means: it accepts that param (e.g.: -h)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   330
	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   331
	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
1478
00b0798b34d5 (svn r1982) -Fix: also windows has no 'fork' option
truelight
parents: 1474
diff changeset
   332
	#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   333
		optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:c:";
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   334
	#else
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   335
		optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:c:"; // no fork option
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   336
	#endif
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   337
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   338
	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	while ((i = MyGetOpt(&mgo)) != -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
		switch(i) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
		case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
		case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   344
		case 'D': {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   345
				strcpy(musicdriver, "null");
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   346
				strcpy(sounddriver, "null");
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   347
				strcpy(videodriver, "dedicated");
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   348
				dedicated = true;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   349
			} break;
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   350
		case 'f': {
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   351
				_dedicated_forks = true;
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   352
			}; break;
1
0ea1e0a5c4df (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater
parents: 0
diff changeset
   353
		case 'n': {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   354
				network = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   355
				if (mgo.opt)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   356
					// Optional, you can give an IP
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   357
					network_conn = mgo.opt;
1
0ea1e0a5c4df (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater
parents: 0
diff changeset
   358
				else
0ea1e0a5c4df (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater
parents: 0
diff changeset
   359
					network_conn = NULL;
0ea1e0a5c4df (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater
parents: 0
diff changeset
   360
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		case 'r': ParseResolution(resolution, mgo.opt); break;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   362
		case 'l': language = mgo.opt; break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   363
		case 't': startdate = atoi(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
		case 'd': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
#if defined(WIN32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
				CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
#endif
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   368
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		case 'e': _switch_mode = SM_EDITOR; break;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 561
diff changeset
   371
		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
   372
		case 'g':
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   373
			if (mgo.opt != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
				strcpy(_file_to_saveload.name, mgo.opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
				_switch_mode = SM_LOAD;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
				_switch_mode = SM_NEWGAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
		case 'G':
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   380
			_random_seeds[0][0] = atoi(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
		case 'p': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
			int i = atoi(mgo.opt);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   384
			// Play as an other player in network games
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   385
			if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		}
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   388
		case 'c':
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   389
			_config_file = strdup(mgo.opt);
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   390
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
		case -2:
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1993
diff changeset
   392
		case 'h':
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
			showhelp();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	DeterminePaths();
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 959
diff changeset
   399
	CheckExternalFiles();
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   400
2033
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   401
#ifdef GPMI
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   402
	/* Set the debug proc */
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   403
	gpmi_debug_proc    = &gpmi_debug_openttd;
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   404
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   405
	/* Initialize GPMI */
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   406
	gpmi_init();
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   407
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   408
	/* Add our paths so we can find our own packages */
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   409
	gpmi_path_append(&gpmi_path_modules, "gpmi/modules");
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   410
	gpmi_path_append(&gpmi_path_packages, "gpmi/packages");
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   411
#endif /* GPMI */
1eb15b79b6f3 (svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents: 2026
diff changeset
   412
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   413
#if defined(UNIX) && !defined(__MORPHOS__)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   414
	// We must fork here, or we'll end up without some resources we need (like sockets)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   415
	if (_dedicated_forks)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   416
		DedicatedFork();
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   417
#endif
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   418
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	LoadFromConfig();
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1608
diff changeset
   420
	CheckConfig();
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
   421
	LoadFromHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	// override config?
469
d26f0e5705dc (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   424
	if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
d26f0e5705dc (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   425
	if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
d26f0e5705dc (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   426
	if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
990
5cbf62b64f36 (svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight
parents: 988
diff changeset
   428
	if (startdate != (uint)-1) _patches.starting_date = startdate;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   430
	if (_dedicated_forks && !dedicated)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   431
		_dedicated_forks = false;
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   432
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	// enumerate language files
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	InitializeLanguagePacks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
	// initialize screenshot formats
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	InitializeScreenshotFormats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   439
	// initialize airport state machines
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   440
	InitializeAirports();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   441
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   442
	/* initialize all variables that are allocated dynamically */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   443
	InitializeDynamicVariables();
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   444
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   445
	/* start the AI */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   446
	AI_Initialize();
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   447
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	// Sample catalogue
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	DEBUG(misc, 1) ("Loading sound effects...");
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   450
	MxInitialize(11025);
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   451
	SoundInitialize("sample.cat");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	// This must be done early, since functions use the InvalidateWindow* calls
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   454
	InitWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	GfxLoadSprites();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	LoadStringWidthTable();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	DEBUG(misc, 1) ("Loading drivers...");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
	LoadDriver(SOUND_DRIVER, _ini_sounddriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2498
diff changeset
   463
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   465
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   466
	// initialize network-core
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   467
	NetworkStartUp();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   468
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   469
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   470
	_opt_ptr = &_opt_newgame;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   471
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   472
	/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   473
	if (_opt_newgame.diff_level == 9)
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   474
		SetDifficultyLevel(0, &_opt_newgame);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   476
	// initialize the ingame console
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   477
	IConsoleInit();
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1243
diff changeset
   478
	InitializeGUI();
644
e833509107ad (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents: 630
diff changeset
   479
	IConsoleCmdExec("exec scripts/autoexec.scr 0");
656
01540e6c0fed (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents: 644
diff changeset
   480
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   481
	GenerateWorld(1, 64, 64); // Make the viewport initialization happy
1268
306ebfea663a (svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents: 1267
diff changeset
   482
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   483
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   484
	if ((network) && (_network_available)) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   485
		if (network_conn != NULL) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   486
			const char *port = NULL;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   487
			const char *player = NULL;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   488
			uint16 rport;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   489
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   490
			rport = NETWORK_DEFAULT_PORT;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   491
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   492
			ParseConnectionString(&player, &port, network_conn);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   493
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   494
			if (player != NULL) _network_playas = atoi(player);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   495
			if (port != NULL) rport = atoi(port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   496
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   497
			LoadIntroGame();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   498
			_switch_mode = SM_NONE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   499
			NetworkClientConnectGame(network_conn, rport);
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1105
diff changeset
   500
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   501
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   502
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   503
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2204
diff changeset
   504
	_video_driver->main_loop();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   505
2285
3193cbd1ba88 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2234
diff changeset
   506
	WaitTillSaved();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   507
	IConsoleFree();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   509
#ifdef ENABLE_NETWORK
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   510
	if (_network_available) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   511
		// Shut down the network and close any open connections
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   512
		NetworkDisconnect();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   513
		NetworkUDPClose();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   514
		NetworkShutDown();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   515
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   516
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	_video_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	_music_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	_sound_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	SaveToConfig();
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
   523
	SaveToHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   525
	// uninitialize airport state machines
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   526
	UnInitializeAirports();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   528
	/* uninitialize variables that are allocated dynamic */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   529
	UnInitializeDynamicVariables();
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   530
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   531
	/* stop the AI */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   532
	AI_Uninitialize();
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   533
1036
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   534
	/* Close all and any open filehandles */
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   535
	FioCloseAll();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   536
	UnInitializeGame();
1036
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   537
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   541
/** Mutex so that only one thread can communicate with the main program
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   542
 * at any given time */
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   543
static ThreadMsg _message = 0;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   544
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   545
static inline void OTTD_ReleaseMutex(void) {_message = 0;}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   546
static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   547
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   548
/** Called by running thread to execute some action in the main game.
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   549
 * It will stall as long as the mutex is not freed (handled) by the game */
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   550
void OTTD_SendThreadMessage(ThreadMsg msg)
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   551
{
2383
80ff60d10aed (svn r2909) Game would hang where the autosave_on_exit was activated.
Darkvater
parents: 2380
diff changeset
   552
	if (_exit_game) return;
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   553
	while (_message != 0) CSleep(10);
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   554
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   555
	_message = msg;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   556
}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   557
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   558
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   559
/** Handle the user-messages sent to us
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   560
 * @param message message sent
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   561
 */
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   562
void ProcessSentMessage(ThreadMsg message)
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   563
{
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   564
	switch (message) {
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   565
		case MSG_OTTD_SAVETHREAD_START: SaveFileStart(); break;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   566
		case MSG_OTTD_SAVETHREAD_DONE:  SaveFileDone(); break;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   567
		case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   568
		default: NOT_REACHED();
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   569
	}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   570
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   571
	OTTD_ReleaseMutex(); // release mutex so that other threads, messages can be handled
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   572
}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   573
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
static void ShowScreenshotResult(bool b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	if (b) {
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2051
diff changeset
   577
		SetDParamStr(0, _screenshot_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   585
static void MakeNewGame(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	// Copy in game options
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   590
	_opt_ptr = &_opt;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   591
	memcpy(_opt_ptr, &_opt_newgame, sizeof(*_opt_ptr));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	GfxLoadSprites();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   595
	// Reinitialize windows
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   596
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
	LoadStringWidthTable();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	// Randomize world
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   602
	GenerateWorld(0, 1<<_patches.map_x, 1<<_patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   604
	// In a dedicated server, the server does not play
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   605
	if (_network_dedicated) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   606
		_local_player = OWNER_SPECTATOR;
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1993
diff changeset
   607
	} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   608
		// Create a single player
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   609
		DoStartupNewPlayer(false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   610
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   611
		_local_player = 0;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   612
		_current_player = _local_player;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   613
		DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_REPLACE_VEHICLE);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   614
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   619
static void MakeNewEditorWorld(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	_game_mode = GM_EDITOR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	// Copy in game options
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   624
	_opt_ptr = &_opt;
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   625
	memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   626
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	GfxLoadSprites();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   629
	// Re-init the windowing system
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   630
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	// Create toolbars
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	// Startup the game system
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   636
	GenerateWorld(1, 1 << _patches.map_x, 1 << _patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	_local_player = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   642
void StartupPlayers(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   643
void StartupDisasters(void);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 115
diff changeset
   644
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   645
/**
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   646
 * Start Scenario starts a new game based on a scenario.
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   647
 * Eg 'New Game' --> select a preset scenario
1501
0faec0f792b0 (svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents: 1500
diff changeset
   648
 * This starts a scenario based on your current difficulty settings
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   649
 */
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   650
static void StartScenario(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	// invalid type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	if (_file_to_saveload.mode == SL_INVALID) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
		printf("Savegame is obsolete or invalid format: %s\n", _file_to_saveload.name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
		ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
		_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	GfxLoadSprites();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   664
	// Reinitialize windows
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   665
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	LoadStringWidthTable();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	// Load game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		LoadIntroGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
		ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
1501
0faec0f792b0 (svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents: 1500
diff changeset
   676
	_opt_ptr = &_opt;
0faec0f792b0 (svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents: 1500
diff changeset
   677
	memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(GameDifficulty));
0faec0f792b0 (svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents: 1500
diff changeset
   678
	_opt.diff_level = _opt_newgame.diff_level;
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   679
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   680
	// Inititalize data
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   681
	StartupPlayers();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   682
	StartupEngines();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   683
	StartupDisasters();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   684
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	_local_player = 0;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   686
	_current_player = _local_player;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   687
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_REPLACE_VEHICLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   692
bool SafeSaveOrLoad(const char *filename, int mode, int newgm)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	byte ogm = _game_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	_game_mode = newgm;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	r = SaveOrLoad(filename, mode);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	if (r == SL_REINIT) {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2620
diff changeset
   700
		switch (ogm) {
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2620
diff changeset
   701
			case GM_MENU:   LoadIntroGame();      break;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2620
diff changeset
   702
			case GM_EDITOR: MakeNewEditorWorld(); break;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2620
diff changeset
   703
			default:        MakeNewGame();        break;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2620
diff changeset
   704
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	} else if (r != SL_OK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
		_game_mode = ogm;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   708
		return false;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   709
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   711
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   714
void SwitchMode(int new_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
{
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   716
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   717
	// If we are saving something, the network stays in his current state
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   718
	if (new_mode != SM_SAVE) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   719
		// If the network is active, make it not-active
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   720
		if (_networking) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   721
			if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   722
				NetworkReboot();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   723
				NetworkUDPClose();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   724
			} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   725
				NetworkDisconnect();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   726
				NetworkUDPClose();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   727
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   728
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   729
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   730
		// If we are a server, we restart the server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   731
		if (_is_network_server) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   732
			// But not if we are going to the menu
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   733
			if (new_mode != SM_MENU) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   734
				NetworkServerStart();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   735
			} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   736
				// This client no longer wants to be a network-server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   737
				_is_network_server = false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   738
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   739
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   740
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   741
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   742
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   743
	switch (new_mode) {
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   744
	case SM_EDITOR: /* Switch to scenario editor */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		MakeNewEditorWorld();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   748
	case SM_NEWGAME: /* New Game --> 'Random game' */
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   749
#ifdef ENABLE_NETWORK
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   750
		if (_network_server)
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   751
			snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "Random Map");
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   752
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
		MakeNewGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   756
	case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   757
		#ifdef ENABLE_NETWORK
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   758
			if (_network_server)
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   759
				snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   760
		#endif /* ENABLE_NETWORK */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   761
		StartScenario();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   762
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   763
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   764
	case SM_LOAD: { /* Load game, Play Scenario */
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   765
		_opt_ptr = &_opt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
		_error_message = INVALID_STRING_ID;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
942
31f28eedd2b8 (svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents: 929
diff changeset
   769
			LoadIntroGame();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
			ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
			_local_player = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   774
#ifdef ENABLE_NETWORK
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   775
			if (_network_server)
2100
868d62687c9a (svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents: 2096
diff changeset
   776
				snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   777
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   782
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
2634
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
   783
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
   784
			PlayerID i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   786
			_opt_ptr = &_opt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
			_local_player = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
			_generating_world = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
			// delete all players.
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   791
			for (i = 0; i != MAX_PLAYERS; i++) {
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2437
diff changeset
   792
				ChangeOwnershipOfPlayerItems(i, OWNER_SPECTATOR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
				_players[i].is_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
			_generating_world = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
			// delete all stations owned by a player
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
			DeleteAllPlayerStations();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   798
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   800
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   805
	case SM_MENU: /* Switch to game intro menu */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
		LoadIntroGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   809
	case SM_SAVE: /* Save game */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   810
		if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
			ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   812
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
			DeleteWindowById(WC_SAVELOAD, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   814
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   817
	case SM_GENRANDLAND: /* Generate random land within scenario editor */
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   818
		GenerateWorld(2, 1<<_patches.map_x, 1<<_patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		// XXX: set date
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
		_local_player = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   824
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   825
	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
   826
		ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
// State controlling game loop.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
// The state must not be changed from anywhere
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
// but here.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
// That check is enforced in DoCommand.
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   834
void StateGameLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
{
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   836
	// 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
   837
	if (_pause) return;
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   838
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   839
	// _frame_counter is increased somewhere else when in network-mode
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   840
	//  Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   841
	//    Should that not be deleted? If so, the next 2 lines can also be deleted
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   842
	if (!_networking) _frame_counter++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   844
	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
   845
		char buf[100];
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   846
		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
   847
		SaveOrLoad(buf, SL_SAVE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		if ((uint)_frame_counter >= _savedump_last) exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
	if (_game_mode == GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
		NewsLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	} else {
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   858
		// All these actions has to be done from OWNER_NONE
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   859
		//  for multiplayer compatibility
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2469
diff changeset
   860
		PlayerID p = _current_player;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   861
		_current_player = OWNER_NONE;
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   862
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
		AnimateAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
		IncreaseDate();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   869
		AI_RunGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
		NewsLoop();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   873
		_current_player = p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   877
static void DoAutosave(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	char buf[200];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   880
1
0ea1e0a5c4df (svn r2) -Fix [993829] UDP Fixes (lucaspiller)
darkvater
parents: 0
diff changeset
   881
	if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1927
diff changeset
   882
		const Player *p = GetPlayer(_local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
		char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
		sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   885
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   886
		SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   887
		SetDParam(1, p->name_2);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   888
		SetDParam(2, _date);
2644
6f699b15c531 (svn r3186) Unnecessary casts and truncation
tron
parents: 2643
diff changeset
   889
		s = GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
		strcpy(s, ".sav");
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   891
	} else { /* Save a maximum of 15 autosaves */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
		int n = _autosave_ctr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
		_autosave_ctr = (_autosave_ctr + 1) & 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
		sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
557
8540788a827e (svn r959) -Fix: fix previous typo for workaround of braindead MSVC6 (Tron)
darkvater
parents: 543
diff changeset
   897
	DEBUG(misc, 2) ("Autosaving to %s", buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	if (SaveOrLoad(buf, SL_SAVE) != SL_OK)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   902
static void ScrollMainViewport(int x, int y)
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   903
{
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   904
	if (_game_mode != GM_MENU) {
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   905
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   906
		assert(w);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   907
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   908
		WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   909
		WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   910
	}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   911
}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   912
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   913
static const int8 scrollamt[16][2] = {
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   914
	{ 0, 0},
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   915
	{-2, 0}, // 1:left
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   916
	{ 0,-2}, // 2:up
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   917
	{-2,-1}, // 3:left + up
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   918
	{ 2, 0}, // 4:right
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   919
	{ 0, 0}, // 5:left + right
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   920
	{ 2,-1}, // 6:right + up
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   921
	{ 0,-2}, // 7:left + right + up = up
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   922
	{ 0 ,2}, // 8:down
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   923
	{-2 ,1}, // 9:down+left
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   924
	{ 0, 0}, // 10:impossible
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   925
	{-2, 0}, // 11:left + up + down = left
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   926
	{ 2, 1}, // 12:down+right
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   927
	{ 0, 2}, // 13:left + right + down = down
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   928
	{ 0,-2}, // 14:left + right + up = up
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   929
	{ 0, 0}, // 15:impossible
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   930
};
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   931
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   932
static void HandleKeyScrolling(void)
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   933
{
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   934
	if (_dirkeys && !_no_scroll) {
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   935
		int factor = _shift_pressed ? 50 : 10;
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   936
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   937
	}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
   938
}
1199
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   939
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   940
void GameLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	int m;
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   943
	ThreadMsg message;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   944
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   945
	if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	// autosave game?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	if (_do_autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		_do_autosave = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		DoAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
		RedrawAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
1199
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   954
	// handle scrolling of the main window
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   955
	if (_dirkeys) HandleKeyScrolling();
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   956
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	// make a screenshot?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	if ((m=_make_screenshot) != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
		_make_screenshot = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
		switch(m) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
		case 1: // make small screenshot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
			UndrawMouseCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
			ShowScreenshotResult(MakeScreenshot());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
		case 2: // make large screenshot
2437
e3e2fe024267 (svn r2963) Fix: calculate proportions of non-square giant screenshot correctly.
peter1138
parents: 2395
diff changeset
   966
			ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * TILE_PIXELS, 0, (MapMaxX() + MapMaxY()) * TILE_PIXELS, (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1, 0));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	// switch game mode?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
	if ((m=_switch_mode) != SM_NONE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
		_switch_mode = SM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
		SwitchMode(m);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	IncreaseSpriteLRU();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	InteractiveRandom();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   980
	if (_scroller_click_timeout > 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
		_scroller_click_timeout -= 3;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   982
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
		_scroller_click_timeout = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   984
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	_caret_timer += 3;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   987
	_timer_counter += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
	CursorTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   990
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   991
	// Check for UDP stuff
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   992
	NetworkUDPGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   994
	if (_networking) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   995
		// Multiplayer
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   996
		NetworkGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   997
	} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   998
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   999
			// This means that we want to reconnect to the last host
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1000
			// We do this here, because it means that the network is really closed
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1001
			NetworkClientConnectGame(_network_last_host, _network_last_port);
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1002
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1003
		// Singleplayer
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
  1004
		StateGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1006
#else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1007
	StateGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1008
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1010
	if (!_pause && _display_opt & DO_FULL_ANIMATION) DoPaletteAnimations();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1012
	if (!_pause || _cheats.build_in_pause.value) MoveAllTextEffects();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1542
diff changeset
  1014
	InputLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
1608
074dff2e4890 (svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents: 1570
diff changeset
  1016
	MusicLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
  1019
void BeforeSaveGame(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
{
2643
735ef1e7884b (svn r3185) const
tron
parents: 2641
diff changeset
  1021
	const Window* w = FindWindowById(WC_MAIN_WINDOW, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1023
	if (w != NULL) {
2643
735ef1e7884b (svn r3185) const
tron
parents: 2641
diff changeset
  1024
		_saved_scrollpos_x = WP(w, const vp_d).scrollpos_x;
735ef1e7884b (svn r3185) const
tron
parents: 2641
diff changeset
  1025
		_saved_scrollpos_y = WP(w, const vp_d).scrollpos_y;
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1026
		_saved_scrollpos_zoom = w->viewport->zoom;
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1027
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1030
static void ConvertTownOwner(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1032
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 861
diff changeset
  1034
	for (tile = 0; tile != MapSize(); tile++) {
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1027
diff changeset
  1035
		if (IsTileType(tile, MP_STREET)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1036
			if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80) _m[tile].m3 = OWNER_TOWN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2340
diff changeset
  1038
			if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1027
diff changeset
  1039
		} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2340
diff changeset
  1040
			if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
// before savegame version 4, the name of the company determined if it existed
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1046
static void CheckIsPlayerActive(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1048
	Player* p;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1049
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	FOR_ALL_PLAYERS(p) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1051
		if (p->name_1 != 0) p->is_active = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1055
// since savegame version 4.1, exclusive transport rights are stored at towns
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1056
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
  1057
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1058
	Town* t;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1059
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1060
	FOR_ALL_TOWNS(t) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1061
		if (t->xy != 0) t->exclusivity = (byte)-1;
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1062
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1063
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  1064
	/* 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
  1065
			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
  1066
			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
  1067
					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
  1068
				 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
  1069
			2.) Go through that array, if you find a town that is not blocked for
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1993
diff changeset
  1070
					one player, but for all others, then give him exclusivity.
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1071
	*/
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1072
}
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1073
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
  1074
const byte convert_currency[] = {
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1075
	 0,  1, 12,  8,  3,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1076
	10, 14, 19,  4,  5,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1077
	 9, 11, 13,  6, 17,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1078
	16, 22, 21,  7, 15,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1079
	18,  2, 20, };
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1080
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1081
// since savegame version 4.2 the currencies are arranged differently
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1082
static void UpdateCurrencies(void)
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1083
{
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
  1084
	_opt.currency = convert_currency[_opt.currency];
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1085
}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1086
1181
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1087
/* Up to revision 1413 the invisible tiles at the southern border have not been
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1088
 * MP_VOID, even though they should have. This is fixed by this function
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1089
 */
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1090
static void UpdateVoidTiles(void)
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1091
{
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 950
diff changeset
  1092
	uint i;
1181
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1093
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1094
	for (i = 0; i < MapMaxY(); ++i)
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1095
		SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID);
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1096
	for (i = 0; i < MapSizeX(); ++i)
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1097
		SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID);
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1098
}
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1099
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1100
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255)
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1101
static void UpdateSignOwner(void)
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1102
{
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1103
	SignStruct *ss;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1104
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1105
	FOR_ALL_SIGNS(ss) ss->owner = OWNER_NONE;
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1106
}
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1107
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1108
extern void UpdateOldAircraft( void );
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1109
extern void UpdateOilRig( void );
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
bool AfterLoadGame(uint version)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	ViewPort *vp;
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1115
	Player *p;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
  1116
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	// in version 2.1 of the savegame, town owner was unified.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1118
	if (version <= 0x200) ConvertTownOwner();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1120
	// from version 4.1 of the savegame, exclusive rights are stored at towns
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1121
	if (version <= 0x400) UpdateExclusiveRights();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1122
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1123
	// from version 4.2 of the savegame, currencies are in a different order
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1124
	if (version <= 0x401) UpdateCurrencies();
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1125
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1126
	// from version 6.0 of the savegame, signs have an "owner"
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1127
	if (version <= 0x600) UpdateSignOwner();
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1128
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1129
	/* In old version there seems to be a problem that water is owned by
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1130
	    OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1131
	    (0x402) version, so I just check when versions are older, and then
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1132
	    walk through the whole map.. */
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1133
	if (version <= 0x402) {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1977
diff changeset
  1134
		TileIndex tile = TileXY(0, 0);
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1135
		uint w = MapSizeX();
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1136
		uint h = MapSizeY();
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1137
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1138
		BEGIN_TILE_LOOP(tile_cur, w, h, tile)
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1139
			if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS)
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1140
				SetTileOwner(tile_cur, OWNER_WATER);
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1141
		END_TILE_LOOP(tile_cur, w, h, tile)
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1142
	}
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1143
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	// convert road side to my format.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	if (_opt.road_side) _opt.road_side = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	// Load the sprites
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	GfxLoadSprites();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	// Update current year
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	SetDate(_date);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	// reinit the landscape variables (landscape might have changed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	InitializeLandscapeVariables(true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1155
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	// Update all vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	AfterLoadVehicles();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1158
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1159
	// Update all waypoints
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1160
	if (version < 0x0C00) FixOldWaypoints();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1161
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1162
	UpdateAllWaypointSigns();
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1163
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	// in version 2.2 of the savegame, we have new airports
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1165
	if (version <= 0x201) UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	UpdateAllStationVirtCoord();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
	// Setup town coords
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	AfterLoadTown();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	UpdateAllSignVirtCoords();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	// make sure there is a town in the game
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1174
	if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
		_error_message = STR_NO_TOWN_IN_SCENARIO;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	// Initialize windows
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
  1180
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
	w = FindWindowById(WC_MAIN_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	WP(w,vp_d).scrollpos_x = _saved_scrollpos_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
	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
  1187
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	vp->zoom = _saved_scrollpos_zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	vp->virtual_width = vp->width << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
	vp->virtual_height = vp->height << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
	// in version 4.0 of the savegame, is_active was introduced to determine
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
	// if a player does exist, rather then checking name_1
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1195
	if (version <= 0x400) CheckIsPlayerActive();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1196
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1197
	// the void tiles on the southern border used to belong to a wrong class.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1198
	if (version <= 0x402) UpdateVoidTiles();
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1199
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1200
	// If Load Scenario / New (Scenario) Game is used,
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1201
	//  a player does not exist yet. So create one here.
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1202
	// 1 exeption: network-games. Those can have 0 players
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1203
	//   But this exeption is not true for network_servers!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1204
	if (!_players[0].is_active && (!_networking || (_networking && _network_server)))
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1205
		DoStartupNewPlayer(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
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
  1207
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1210
	//In 5.1, Oilrigs have been moved (again)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1211
	if (version <= 0x500) UpdateOilRig();
950
1f6546ea35a3 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1212
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1213
	if (version <= 0x600) {
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1214
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1215
			if (IsTileType(tile, MP_HOUSE)) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1216
				_m[tile].m4 = _m[tile].m2;
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1217
				//XXX magic
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1218
				SetTileType(tile, MP_VOID);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1219
				_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1220
				SetTileType(tile, MP_HOUSE);
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1221
			} else if (IsTileType(tile, MP_STREET)) {
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1222
				//XXX magic
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1223
				_m[tile].m4 |= (_m[tile].m2 << 4);
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1224
				if (IsTileOwner(tile, OWNER_TOWN)) {
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1225
					SetTileType(tile, MP_VOID);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1226
					_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1227
					SetTileType(tile, MP_STREET);
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1228
				} else {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1229
					_m[tile].m2 = 0;
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1230
				}
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1231
			}
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1232
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1233
	}
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1234
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1235
	if (version < 0x900) {
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1236
		Town *t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1237
		FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1238
	}
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1239
1993
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1240
	if (version < 0xF00) {
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1241
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1242
			if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_m[tile].m4, 2)) {
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1243
				CLRBIT(_m[tile].m4, 2);
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2033
diff changeset
  1244
				SETBIT(_m[tile].m4, 3);
1993
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1245
			}
2620
7bdf0d5c0638 (svn r3158) - PBS: [ 1252192 ] Fix an assertion failure due to possible junk data in pre-PBS savegames. This will not correct pre-PBS savegames loaded and saved since PBS was introduced. (thanks glx)
peter1138
parents: 2617
diff changeset
  1246
			// Clear possible junk data in PBS bits.
7bdf0d5c0638 (svn r3158) - PBS: [ 1252192 ] Fix an assertion failure due to possible junk data in pre-PBS savegames. This will not correct pre-PBS savegames loaded and saved since PBS was introduced. (thanks glx)
peter1138
parents: 2617
diff changeset
  1247
			if (IsTileType(tile, MP_RAILWAY) && !HASBIT(_m[tile].m5, 7))
7bdf0d5c0638 (svn r3158) - PBS: [ 1252192 ] Fix an assertion failure due to possible junk data in pre-PBS savegames. This will not correct pre-PBS savegames loaded and saved since PBS was introduced. (thanks glx)
peter1138
parents: 2617
diff changeset
  1248
				SB(_m[tile].m4, 4, 4, 0);
1993
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1249
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1250
	}
7410864cfac8 (svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents: 1981
diff changeset
  1251
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1252
	if (version < 0x1000) {
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1253
		FOR_ALL_PLAYERS(p) {
2634
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
  1254
			EngineID i;
16334e1a4862 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
  1255
2572
f3ab5cadbdc5 (svn r3109) Replace two occurrences of '256' with TOTAL_NUM_ENGINES
peter1138
parents: 2548
diff changeset
  1256
			for (i = 0; i < TOTAL_NUM_ENGINES; i++) {
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1257
				p->engine_replacement[i] = INVALID_ENGINE;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1258
			}
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1259
			p->engine_renew = false;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1260
			p->engine_renew_months = -6;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1261
			p->engine_renew_money = 100000;
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1262
		}
2322
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1263
		if (_local_player < MAX_PLAYERS) {
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1264
			// Set the human controlled player to the patch settings
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1265
			// Scenario editor do not have any companies
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1266
			p = GetPlayer(_local_player);
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1267
			p->engine_renew = _patches.autorenew;
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1268
			p->engine_renew_months = _patches.autorenew_months;
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1269
			p->engine_renew_money = _patches.autorenew_money;
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1270
		}
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1271
	}
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1272
2617
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1273
	/* In version 16.1 of the savegame, trains became aware of station lengths
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1274
		need to initialized to the invalid state
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1275
		players needs to set renew_keep_length too */
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1276
	if (version < 0x1001) {
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1277
		Vehicle *v;
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1278
		FOR_ALL_PLAYERS(p) {
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1279
			p->renew_keep_length = false;
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1280
		}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1281
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1282
		FOR_ALL_VEHICLES(v) {
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1283
			if (v->type == VEH_Train) {
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1284
				v->u.rail.shortest_platform[0] = 255;
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1285
				v->u.rail.shortest_platform[1] = 0;
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1286
			}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1287
		}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1288
	}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1289
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1290
	FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1291
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
}