openttd.c
author celestar
Wed, 27 Dec 2006 12:38:02 +0000
changeset 5385 3868f2e6db9b
parent 5380 8ea58542b6e0
child 5425 69d019397b5c
permissions -rw-r--r--
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
db48cf29b983 (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
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1314
diff changeset
     4
#include "string.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     5
#include "table/strings.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1296
diff changeset
     6
#include "debug.h"
2171
60334c9ca477 (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
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 2147
diff changeset
     8
#include "saveload.h"
1309
4403a69da4f8 (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1301
diff changeset
     9
#include "strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 659
diff changeset
    10
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1199
diff changeset
    11
#include "tile.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3121
diff changeset
    12
#include "void_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#define VARDEF
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
    15
#include "openttd.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    16
#include "bridge_map.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2162
diff changeset
    17
#include "functions.h"
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
    18
#include "mixer.h"
1349
15979a2e9001 (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
    19
#include "spritecache.h"
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
    20
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "gfx.h"
2340
e18ef06bc59a (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
    22
#include "gfxinit.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "station.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    25
#include "station_map.h"
3558
9a3e12615b1c (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
    26
#include "town_map.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    27
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
#include "sound.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
#include "hal.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
#include "airport.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 123
diff changeset
    42
#include "console.h"
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    43
#include "screenshot.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
    44
#include "network.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
    45
#include "signs.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1310
diff changeset
    46
#include "depot.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
    47
#include "waypoint.h"
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
    48
#include "ai/ai.h"
2855
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2848
diff changeset
    49
#include "train.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
    50
#include "yapf/yapf.h"
3889
3aa611a80ff1 (svn r4945) Fix (r3726): make -t command line option (set starting date/year) work again
rubidium
parents: 3765
diff changeset
    51
#include "settings.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
    52
#include "genworld.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4260
diff changeset
    53
#include "date.h"
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    54
#include "clear_map.h"
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
    55
#include "fontcache.h"
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
    56
#include "newgrf_config.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    58
#include "bridge_map.h"
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    59
#include "clear_map.h"
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    60
#include "rail_map.h"
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    61
#include "road_map.h"
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    62
#include "water_map.h"
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    63
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    66
void CallLandscapeTick(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    67
void IncreaseDate(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    68
void DoPaletteAnimations(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    69
void MusicLoop(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    70
void ResetMusic(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    71
void InitializeStations(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
    72
void DeleteAllPlayerStations(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
extern void DoStartupNewPlayer(bool is_ai);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
extern void ShowOSErrorBox(const char *buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
1436
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    78
/* TODO: usrerror() for errors which are not of an internal nature but
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    79
 * caused by the user, i.e. missing files or fatal configuration errors.
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    80
 * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    81
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
    82
void CDECL error(const char *s, ...)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    83
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	char buf[512];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    86
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	va_start(va, s);
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
    88
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	va_end(va);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
    90
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	ShowOSErrorBox(buf);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    92
	if (_video_driver != NULL) _video_driver->stop();
0
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
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	exit(1);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
void CDECL ShowInfoF(const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	va_start(va, str);
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   103
	vsnprintf(buf, lengthof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	va_end(va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
1310
99c921090356 (svn r1814) Let ReadFileToMem() return void* (instead of byte*) because we don't know what the caller wants to do with the data
tron
parents: 1309
diff changeset
   109
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
   110
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	FILE *in;
1105
597b9e7955b5 (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   112
	byte *mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	size_t len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	in = fopen(filename, "rb");
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   116
	if (in == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	fseek(in, 0, SEEK_END);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	len = ftell(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	fseek(in, 0, SEEK_SET);
1105
597b9e7955b5 (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   121
	if (len > maxsize || (mem = malloc(len + 1)) == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	}
1105
597b9e7955b5 (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   125
	mem[len] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	if (fread(mem, len, 1, in) != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		free(mem);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	*lenp = len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	return mem;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   137
static void showhelp(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
{
4840
a76d40e0aea4 (svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents: 4830
diff changeset
   139
	extern const char _openttd_revision[];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	char buf[4096], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   142
	p = buf;
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   143
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   144
	p += snprintf(p, lengthof(buf), "OpenTTD %s\n", _openttd_revision);
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   145
	p = strecpy(p,
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   146
		"\n"
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   147
		"\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		"Command line options:\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   149
		"  -v drv              = Set video driver (see below)\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   150
		"  -s drv              = Set sound driver (see below)\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   151
		"  -m drv              = Set music driver (see below)\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   152
		"  -r res              = Set resolution (for instance 800x600)\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   153
		"  -h                  = Display this help text\n"
4285
19cb745c694e (svn r5915) -Cleanup: some variables were named *_date while they were only holding years; rename these variables to match this.
rubidium
parents: 4277
diff changeset
   154
		"  -t year             = Set starting year\n"
1440
08722492ee27 (svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents: 1436
diff changeset
   155
		"  -d [[fac=]lvl[,...]]= Debug mode\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   156
		"  -e                  = Start Editor\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   157
		"  -g [savegame]       = Start new/save game immediately\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   158
		"  -G seed             = Set random seed\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   159
		"  -n [ip#player:port] = Start networkgame\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   160
		"  -D                  = Start dedicated server\n"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   161
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   162
		"  -f                  = Fork into the background (dedicated only)\n"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   163
#endif
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   164
		"  -i                  = Force to use the DOS palette\n"
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   165
		"                          (use this if you see a lot of pink)\n"
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   166
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n"
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   167
		"\n",
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   168
		lastof(buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   171
	p = GetDriverList(p, lastof(buf));
0
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
	ShowInfo(buf);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	char *opt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	int numleft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	char **argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	const char *options;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	char *cont;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
} MyGetOptData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
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
   186
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	md->numleft = argc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	md->argv = argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	md->options = options;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
static int MyGetOpt(MyGetOptData *md)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	char *s,*r,*t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   197
	s = md->cont;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   198
	if (s != NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		goto md_continue_here;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   201
	for (;;) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   202
		if (--md->numleft < 0) return -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		s = *md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
		if (*s == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
md_continue_here:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
			s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
			if (*s != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
				// Found argument, try to locate it in options.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
				if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
					// ERROR!
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
					return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
				if (r[1] == ':') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
					// 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
   216
					if (!*(t = s + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
						// 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
   218
						if (--md->numleft < 0 || *(t = *md->argv) == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
							// Check if item is optional?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
							if (r[2] != ':')
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
								return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
							md->numleft++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
							t = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
						} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
							md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
					md->opt = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
					md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
					return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
				md->opt = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
				md->cont = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
				return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
			// This is currently not supported.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
			return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   244
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
   245
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	char *t = strchr(s, 'x');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	if (t == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
		ShowInfoF("Invalid resolution '%s'", s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
1764
e72cee59c273 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   252
	res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
e72cee59c273 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   253
	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
   254
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   256
static void InitializeDynamicVariables(void)
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   257
{
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   258
	/* Dynamic stuff needs to be initialized somewhere... */
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   259
	_town_sort     = NULL;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   260
	_industry_sort = NULL;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   261
}
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   262
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   263
static void UnInitializeDynamicVariables(void)
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   264
{
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   265
	/* Dynamic stuff needs to be free'd somewhere... */
4983
b261a5850aa1 (svn r6986) Use the pool macros for the Town pool
tron
parents: 4980
diff changeset
   266
	CleanPool(&_Town_pool);
4976
2e3d5e8ec510 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4972
diff changeset
   267
	CleanPool(&_Industry_pool);
4980
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4979
diff changeset
   268
	CleanPool(&_Station_pool);
4972
c7f92c6b74e4 (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4912
diff changeset
   269
	CleanPool(&_Vehicle_pool);
4979
a85ffde44778 (svn r6982) Use the pool macros for the Sign pool
tron
parents: 4977
diff changeset
   270
	CleanPool(&_Sign_pool);
4977
c5dd04c706bc (svn r6980) Use the pool macros for the Order pool
tron
parents: 4976
diff changeset
   271
	CleanPool(&_Order_pool);
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   272
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   273
	free((void*)_town_sort);
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   274
	free((void*)_industry_sort);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   275
}
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   276
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   277
static void UnInitializeGame(void)
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   278
{
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   279
	UnInitWindowSystem();
1482
80e315adc3bd (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
   280
80e315adc3bd (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
   281
	free(_config_file);
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   282
}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   283
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   284
static void LoadIntroGame(void)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   285
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   286
	char filename[256];
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   287
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   288
	_game_mode = GM_MENU;
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   289
	CLRBITS(_display_opt, DO_TRANS_BUILDINGS); // don't make buildings transparent in intro
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   290
	_opt_ptr = &_opt_newgame;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   291
	ResetGRFConfig(false);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   292
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   293
	// Setup main window
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   294
	ResetWindowSystem();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   295
	SetupColorsAndInitialWindow();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   296
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   297
	// Generate a world.
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5228
diff changeset
   298
	snprintf(filename, lengthof(filename), "%sopntitle.dat",  _paths.data_dir);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   299
#if defined SECOND_DATA_DIR
921
d4831de060b6 (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   300
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5228
diff changeset
   301
		snprintf(filename, lengthof(filename), "%sopntitle.dat",  _paths.second_data_dir);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   302
	}
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 557
diff changeset
   303
#endif
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   304
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   305
		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   306
		WaitTillGeneratedWorld();
921
d4831de060b6 (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   307
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   308
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   309
	_pause = 0;
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   310
	SetLocalPlayer(0);
4336
1e9ab68b9287 (svn r6037) -Fix: never allow scrolling the map in the main menu (scroll-settings weren't reset if switched to mainmenu)
truelight
parents: 4328
diff changeset
   311
	/* Make sure you can't scroll in the menu */
1e9ab68b9287 (svn r6037) -Fix: never allow scrolling the map in the main menu (scroll-settings weren't reset if switched to mainmenu)
truelight
parents: 4328
diff changeset
   312
	_scrolling_viewport = 0;
1e9ab68b9287 (svn r6037) -Fix: never allow scrolling the map in the main menu (scroll-settings weren't reset if switched to mainmenu)
truelight
parents: 4328
diff changeset
   313
	_cursor.fix_at = false;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   314
	MarkWholeScreenDirty();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   315
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   316
	// Play main theme
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   317
	if (_music_driver->is_song_playing()) ResetMusic();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   318
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   319
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   320
#if defined(UNIX) && !defined(__MORPHOS__)
774
bb9ec520a1b1 (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
   321
extern void DedicatedFork(void);
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   322
#endif
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   323
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   324
int ttd_main(int argc, char *argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	MyGetOptData mgo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	int i;
1010
977aafc6b8e3 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents: 1009
diff changeset
   328
	const char *optformat;
469
d8c423a7a5f0 (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   329
	char musicdriver[16], sounddriver[16], videodriver[16];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	int resolution[2] = {0,0};
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4285
diff changeset
   331
	Year startyear = INVALID_YEAR;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   332
	uint generation_seed = GENERATE_NEW_SEED;
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   333
	bool dedicated = false;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   334
	bool network   = false;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   335
	char *network_conn = NULL;
1406
f5da270a654f (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   336
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	_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
   341
	_switch_mode_errorstr = INVALID_STRING_ID;
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   342
	_dedicated_forks = false;
1482
80e315adc3bd (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
   343
	_config_file = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   345
	// The last param of the following function means this:
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   346
	//   a letter means: it accepts that param (e.g.: -h)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   347
	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   348
	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
4854
151cdb683187 (svn r6780) -Codechange: Remove GPMI leftovers (-b impersonisation of AI in MP).
Darkvater
parents: 4850
diff changeset
   349
	optformat = "m:s:v:hDn::eit:d::r:g::G:c:"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   350
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   351
		"f"
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   352
#endif
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   353
	;
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   354
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   355
	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	while ((i = MyGetOpt(&mgo)) != -1) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   357
		switch (i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		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
   359
		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
   360
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   361
		case 'D':
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   362
			strcpy(musicdriver, "null");
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   363
			strcpy(sounddriver, "null");
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   364
			strcpy(videodriver, "dedicated");
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   365
			dedicated = true;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   366
			break;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   367
		case 'f': _dedicated_forks = true; break;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   368
		case 'n':
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   369
			network = true;
3059
1726615b3ddd (svn r3648) - Fix typo in r3647, don't ask me how it got there s/_/./
Darkvater
parents: 3058
diff changeset
   370
			network_conn = mgo.opt; // optional IP parameter, NULL if unset
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   371
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		case 'r': ParseResolution(resolution, mgo.opt); break;
4285
19cb745c694e (svn r5915) -Cleanup: some variables were named *_date while they were only holding years; rename these variables to match this.
rubidium
parents: 4277
diff changeset
   373
		case 't': startyear = atoi(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		case 'd': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
#if defined(WIN32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
				CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
#endif
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   378
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
		case 'e': _switch_mode = SM_EDITOR; break;
614
b96f987dbf80 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 561
diff changeset
   381
		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
   382
		case 'g':
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   383
			if (mgo.opt != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
				strcpy(_file_to_saveload.name, mgo.opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
				_switch_mode = SM_LOAD;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   386
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
				_switch_mode = SM_NEWGAME;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   388
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
			break;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   390
		case 'G': generation_seed = atoi(mgo.opt); break;
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   391
		case 'c': _config_file = strdup(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
		case -2:
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 1993
diff changeset
   393
		case 'h':
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			showhelp();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
			return 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	DeterminePaths();
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 959
diff changeset
   400
	CheckExternalFiles();
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   401
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   402
#if defined(UNIX) && !defined(__MORPHOS__)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   403
	// We must fork here, or we'll end up without some resources we need (like sockets)
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   404
	if (_dedicated_forks)
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   405
		DedicatedFork();
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   406
#endif
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   407
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	LoadFromConfig();
1688
af2bb9bcb2ed (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
   409
	CheckConfig();
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
   410
	LoadFromHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	// override config?
469
d8c423a7a5f0 (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   413
	if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
d8c423a7a5f0 (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   414
	if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
d8c423a7a5f0 (svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents: 430
diff changeset
   415
	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
   416
	if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4285
diff changeset
   417
	if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   418
	if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   420
	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   421
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	// enumerate language files
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	InitializeLanguagePacks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	// initialize screenshot formats
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	InitializeScreenshotFormats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   428
	// initialize airport state machines
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   429
	InitializeAirports();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   430
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   431
	/* initialize all variables that are allocated dynamically */
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   432
	InitializeDynamicVariables();
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   433
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   434
	/* start the AI */
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   435
	AI_Initialize();
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   436
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	// Sample catalogue
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   438
	DEBUG(misc, 1, "Loading sound effects...");
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   439
	MxInitialize(11025);
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   440
	SoundInitialize("sample.cat");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
   442
	/* Initialize FreeType */
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
   443
	InitFreeType();
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
   444
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	// This must be done early, since functions use the InvalidateWindow* calls
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   446
	InitWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
5166
f653f2e5384d (svn r7273) -Fix (r7250): Initialise game palette before driver initialisation. This fixes a 'black screen' problem with fullscreen with the win32 video driver.
peter1138
parents: 5155
diff changeset
   448
	/* Initialize game palette */
f653f2e5384d (svn r7273) -Fix (r7250): Initialise game palette before driver initialisation. This fixes a 'black screen' problem with fullscreen with the win32 video driver.
peter1138
parents: 5155
diff changeset
   449
	GfxInitPalettes();
f653f2e5384d (svn r7273) -Fix (r7250): Initialise game palette before driver initialisation. This fixes a 'black screen' problem with fullscreen with the win32 video driver.
peter1138
parents: 5155
diff changeset
   450
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   451
	DEBUG(driver, 1, "Loading drivers...");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	LoadDriver(SOUND_DRIVER, _ini_sounddriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2498
diff changeset
   455
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
3678
696a32fc8a5d (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   457
	// restore saved music volume
696a32fc8a5d (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   458
	_music_driver->set_volume(msf.music_vol);
696a32fc8a5d (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   459
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   460
	NetworkStartUp(); // initialize network-core
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   461
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   462
	ScanNewGRFFiles();
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   463
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   464
	_opt_ptr = &_opt_newgame;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   465
	ResetGRFConfig(false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   466
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   467
	/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   468
	if (_opt_newgame.diff_level == 9) SetDifficultyLevel(0, &_opt_newgame);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   470
	/* Make sure _patches is filled with _patches_newgame if we switch to a game directly */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   471
	if (_switch_mode != SM_NONE) {
5024
5e98bf731469 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   472
		_opt = _opt_newgame;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   473
		UpdatePatches();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   474
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
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();
3312
d28f88dc5587 (svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents: 3274
diff changeset
   478
	_cursor.in_window = true;
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1243
diff changeset
   479
	InitializeGUI();
644
cd687cdec701 (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents: 630
diff changeset
   480
	IConsoleCmdExec("exec scripts/autoexec.scr 0");
656
e3e435079efa (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents: 644
diff changeset
   481
2828
342f02f7c0d4 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   482
	GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   483
	WaitTillGeneratedWorld();
1268
bcbbc18f5c3e (svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents: 1267
diff changeset
   484
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   485
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   486
	if (network && _network_available) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   487
		if (network_conn != NULL) {
1329
6988419aa6f0 (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   488
			const char *port = NULL;
6988419aa6f0 (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   489
			const char *player = NULL;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   490
			uint16 rport;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   491
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   492
			rport = NETWORK_DEFAULT_PORT;
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   493
			_network_playas = PLAYER_NEW_COMPANY;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   494
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   495
			ParseConnectionString(&player, &port, network_conn);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   496
4861
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   497
			if (player != NULL) {
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   498
				_network_playas = atoi(player);
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   499
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   500
				if (_network_playas != PLAYER_SPECTATOR) {
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   501
					_network_playas--;
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   502
					if (!IsValidPlayer(_network_playas)) return false;
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   503
				}
4861
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   504
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   505
			if (port != NULL) rport = atoi(port);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   506
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   507
			LoadIntroGame();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   508
			_switch_mode = SM_NONE;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   509
			NetworkClientConnectGame(network_conn, rport);
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1105
diff changeset
   510
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   511
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   512
#endif /* ENABLE_NETWORK */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   513
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2204
diff changeset
   514
	_video_driver->main_loop();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   515
2285
410dedcf46d1 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2234
diff changeset
   516
	WaitTillSaved();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   517
	IConsoleFree();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   519
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	_video_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	_music_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	_sound_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	SaveToConfig();
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
   526
	SaveToHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   528
	// uninitialize airport state machines
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   529
	UnInitializeAirports();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   531
	/* uninitialize variables that are allocated dynamic */
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   532
	UnInitializeDynamicVariables();
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   533
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   534
	/* stop the AI */
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   535
	AI_Uninitialize();
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   536
1036
8a82ce28b724 (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   537
	/* Close all and any open filehandles */
8a82ce28b724 (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   538
	FioCloseAll();
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   539
	UnInitializeGame();
1036
8a82ce28b724 (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   540
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   544
void HandleExitGameRequest(void)
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   545
{
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   546
	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   547
		_exit_game = true;
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   548
	} else if (_patches.autosave_on_exit) {
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   549
		DoExitSave();
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   550
		_exit_game = true;
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   551
	} else {
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   552
		AskExitGame();
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   553
	}
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   554
}
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   555
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   556
2380
392bba57462d (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
/** Mutex so that only one thread can communicate with the main program
392bba57462d (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
 * at any given time */
4323
ae32c5fab67b (svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with
truelight
parents: 4300
diff changeset
   559
static ThreadMsg _message = MSG_OTTD_NO_MESSAGE;
2380
392bba57462d (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
4323
ae32c5fab67b (svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with
truelight
parents: 4300
diff changeset
   561
static inline void OTTD_ReleaseMutex(void) {_message = MSG_OTTD_NO_MESSAGE;}
2380
392bba57462d (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
static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;}
392bba57462d (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
392bba57462d (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
/** Called by running thread to execute some action in the main game.
392bba57462d (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
 * It will stall as long as the mutex is not freed (handled) by the game */
392bba57462d (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
void OTTD_SendThreadMessage(ThreadMsg msg)
392bba57462d (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
{
2383
7589e75b873a (svn r2909) Game would hang where the autosave_on_exit was activated.
Darkvater
parents: 2380
diff changeset
   568
	if (_exit_game) return;
4323
ae32c5fab67b (svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with
truelight
parents: 4300
diff changeset
   569
	while (_message != MSG_OTTD_NO_MESSAGE) CSleep(10);
2380
392bba57462d (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
392bba57462d (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
	_message = msg;
392bba57462d (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
}
392bba57462d (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
392bba57462d (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
   574
392bba57462d (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
   575
/** Handle the user-messages sent to us
392bba57462d (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
   576
 * @param message message sent
392bba57462d (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
   577
 */
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   578
static void ProcessSentMessage(ThreadMsg message)
2380
392bba57462d (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
   579
{
392bba57462d (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
   580
	switch (message) {
392bba57462d (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
   581
		case MSG_OTTD_SAVETHREAD_DONE:  SaveFileDone(); break;
392bba57462d (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
   582
		case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break;
392bba57462d (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
   583
		default: NOT_REACHED();
392bba57462d (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
   584
	}
392bba57462d (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
   585
392bba57462d (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
   586
	OTTD_ReleaseMutex(); // release mutex so that other threads, messages can be handled
392bba57462d (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
   587
}
392bba57462d (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
   588
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
static void ShowScreenshotResult(bool b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	if (b) {
2055
4926ed1a7562 (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
   592
		SetDParamStr(0, _screenshot_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
		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
   594
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
		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
   596
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
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
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   600
static void MakeNewGameDone(void)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   601
{
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   602
	/* In a dedicated server, the server does not play */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   603
	if (_network_dedicated) {
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   604
		SetLocalPlayer(PLAYER_SPECTATOR);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   605
		return;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   606
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   607
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   608
	/* Create a single player */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   609
	DoStartupNewPlayer(false);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   610
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   611
	SetLocalPlayer(0);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   612
	_current_player = _local_player;
4661
89c3cbba9846 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4603
diff changeset
   613
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   614
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   615
	SettingsDisableElrail(_patches.disable_elrails);
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   616
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   617
	MarkWholeScreenDirty();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   618
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   619
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   620
static void MakeNewGame(bool from_heightmap)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   624
	ResetGRFConfig(true);
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   625
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   626
	GenerateWorldSetCallback(&MakeNewGameDone);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   627
	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   628
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   630
static void MakeNewEditorWorldDone(void)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   631
{
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   632
	SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   637
static void MakeNewEditorWorld(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	_game_mode = GM_EDITOR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   641
	ResetGRFConfig(true);
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   642
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   643
	GenerateWorldSetCallback(&MakeNewEditorWorldDone);
2828
342f02f7c0d4 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   644
	GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   647
void StartupPlayers(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   648
void StartupDisasters(void);
3891
ca6cdf4f79bf (svn r4947) - Fix [FS#145]: Starting scenarios did not adhere to local difficulty settings
Darkvater
parents: 3889
diff changeset
   649
extern void StartupEconomy(void);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 115
diff changeset
   650
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   651
/**
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   652
 * Start Scenario starts a new game based on a scenario.
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   653
 * Eg 'New Game' --> select a preset scenario
1501
0fc808b4e375 (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
   654
 * This starts a scenario based on your current difficulty settings
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   655
 */
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   656
static void StartScenario(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	// invalid type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	if (_file_to_saveload.mode == SL_INVALID) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   662
		DEBUG(sl, 0, "Savegame is obsolete or invalid format: '%s'", _file_to_saveload.name);
2749
c9312a4a1efe (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   663
		ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
		_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   668
	// Reinitialize windows
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   669
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   673
	ResetGRFConfig(true);
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   674
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	// Load game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	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
   677
		LoadIntroGame();
2749
c9312a4a1efe (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   678
		ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
1501
0fc808b4e375 (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
   681
	_opt_ptr = &_opt;
5024
5e98bf731469 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   682
	_opt_ptr->diff = _opt_newgame.diff;
1501
0fc808b4e375 (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
   683
	_opt.diff_level = _opt_newgame.diff_level;
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   684
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   685
	// Inititalize data
3891
ca6cdf4f79bf (svn r4947) - Fix [FS#145]: Starting scenarios did not adhere to local difficulty settings
Darkvater
parents: 3889
diff changeset
   686
	StartupEconomy();
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   687
	StartupPlayers();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   688
	StartupEngines();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   689
	StartupDisasters();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   690
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   691
	SetLocalPlayer(0);
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   692
	_current_player = _local_player;
4661
89c3cbba9846 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4603
diff changeset
   693
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	MarkWholeScreenDirty();
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
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   698
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
   699
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	byte ogm = _game_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	_game_mode = newgm;
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   703
	switch (SaveOrLoad(filename, mode)) {
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   704
		case SL_OK: return true;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   705
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   706
		case SL_REINIT:
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   707
			switch (ogm) {
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   708
				case GM_MENU:   LoadIntroGame();      break;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   709
				case GM_EDITOR: MakeNewEditorWorld(); break;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   710
				default:        MakeNewGame(false);   break;
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   711
			}
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   712
			return false;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   713
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   714
		default:
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   715
			_game_mode = ogm;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   716
			return false;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   717
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   720
void SwitchMode(int new_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   722
#ifdef ENABLE_NETWORK
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   723
	// If we are saving something, the network stays in his current state
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   724
	if (new_mode != SM_SAVE) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   725
		// If the network is active, make it not-active
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   726
		if (_networking) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   727
			if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   728
				NetworkReboot();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   729
				NetworkUDPClose();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   730
			} else {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   731
				NetworkDisconnect();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   732
				NetworkUDPClose();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   733
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   734
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   735
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   736
		// If we are a server, we restart the server
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   737
		if (_is_network_server) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   738
			// But not if we are going to the menu
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   739
			if (new_mode != SM_MENU) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   740
				NetworkServerStart();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   741
			} else {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   742
				// This client no longer wants to be a network-server
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   743
				_is_network_server = false;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   744
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   745
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   746
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   747
#endif /* ENABLE_NETWORK */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   748
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   749
	switch (new_mode) {
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   750
	case SM_EDITOR: /* Switch to scenario editor */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		MakeNewEditorWorld();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   754
	case SM_NEWGAME: /* New Game --> 'Random game' */
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   755
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   756
		if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   757
			snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   758
		}
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   759
#endif /* ENABLE_NETWORK */
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   760
		MakeNewGame(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   763
	case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   764
#ifdef ENABLE_NETWORK
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   765
		if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   766
			snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   767
		}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   768
#endif /* ENABLE_NETWORK */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   769
		StartScenario();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   770
		break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   771
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   772
	case SM_LOAD: { /* Load game, Play Scenario */
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   773
		_opt_ptr = &_opt;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   774
		ResetGRFConfig(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
942
75270ad564be (svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents: 929
diff changeset
   777
			LoadIntroGame();
2749
c9312a4a1efe (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   778
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
		} else {
5197
2b3a2494b2e1 (svn r7312) -Fix: When loading a game from a dedicated server the local player global variable was
Darkvater
parents: 5170
diff changeset
   780
			/* Update the local player for a loaded game. It is either always
2b3a2494b2e1 (svn r7312) -Fix: When loading a game from a dedicated server the local player global variable was
Darkvater
parents: 5170
diff changeset
   781
			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   782
			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   784
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   785
			if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   786
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   787
			}
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   788
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   793
	case SM_START_HEIGHTMAP: /* Load a heightmap and start a new game from it */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   794
#ifdef ENABLE_NETWORK
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   795
		if (_network_server) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   796
			snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   797
		}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   798
#endif /* ENABLE_NETWORK */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   799
		MakeNewGame(true);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   800
		break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   801
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   802
	case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   803
		SetLocalPlayer(OWNER_NONE);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   804
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   805
		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   806
		MarkWholeScreenDirty();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   807
		break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   808
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   809
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
2634
0df9396b0067 (svn r3176) Use proper types, not some variants of int
tron
parents: 2631
diff changeset
   810
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
4260
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   811
			Player *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   813
			_opt_ptr = &_opt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   815
			SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
			_generating_world = true;
4260
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   817
			/* Delete all players */
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   818
			FOR_ALL_PLAYERS(p) {
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   819
				if (p->is_active) {
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4840
diff changeset
   820
					ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
4260
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   821
					p->is_active = false;
c638c6441121 (svn r5886) -Fix [FS#273]: Incomplete removal of player owned property due to lack of money.
Darkvater
parents: 4184
diff changeset
   822
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
			_generating_world = false;
4537
635b2f792ff9 (svn r6366) -Fix (FS#324): when opening a scenario, the date was set 1920 years into the future.
rubidium
parents: 4536
diff changeset
   825
			_patches_newgame.starting_year = _cur_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
			// delete all stations owned by a player
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			DeleteAllPlayerStations();
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   828
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   830
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   834
	case SM_MENU: /* Switch to game intro menu */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		LoadIntroGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   838
	case SM_SAVE: /* Save game */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   839
		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
   840
			ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   841
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			DeleteWindowById(WC_SAVELOAD, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   843
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   846
	case SM_GENRANDLAND: /* Generate random land within scenario editor */
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
   847
		SetLocalPlayer(OWNER_NONE);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   848
		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
		// XXX: set date
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   853
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   854
	if (_switch_mode_errorstr != INVALID_STRING_ID) {
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   855
		ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   856
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
// State controlling game loop.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
// The state must not be changed from anywhere
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
// but here.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
// That check is enforced in DoCommand.
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   864
void StateGameLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
{
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   866
	// 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
   867
	if (_pause) return;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   868
	if (IsGeneratingWorld()) return;
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   869
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	if (_game_mode == GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
		NewsLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	} else {
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   877
		// All these actions has to be done from OWNER_NONE
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   878
		//  for multiplayer compatibility
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2469
diff changeset
   879
		PlayerID p = _current_player;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   880
		_current_player = OWNER_NONE;
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   881
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
		AnimateAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
		IncreaseDate();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   888
		AI_RunGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
		NewsLoop();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   892
		_current_player = p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   896
static void DoAutosave(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	char buf[200];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   899
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4840
diff changeset
   900
	if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1927
diff changeset
   901
		const Player *p = GetPlayer(_local_player);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
   902
		char* s = buf;
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
   903
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5228
diff changeset
   904
		s += snprintf(buf, lengthof(buf), "%s%s", _paths.autosave_dir, PATHSEP);
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   905
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   906
		SetDParam(0, p->name_1);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   907
		SetDParam(1, p->name_2);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   908
		SetDParam(2, _date);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
   909
		s = GetString(s, STR_4004, lastof(buf));
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
   910
		strecpy(s, ".sav", lastof(buf));
2672
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   911
	} else { /* generate a savegame name and number according to _patches.max_num_autosaves */
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5228
diff changeset
   912
		snprintf(buf, lengthof(buf), "%s%sautosave%d.sav", _paths.autosave_dir, PATHSEP, _autosave_ctr);
2672
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   913
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   914
		_autosave_ctr++;
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   915
		if (_autosave_ctr >= _patches.max_num_autosaves) {
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   916
			// we reached the limit for numbers of autosaves. We will start over
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   917
			_autosave_ctr = 0;
35122f8a44ab (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   918
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   921
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	if (SaveOrLoad(buf, SL_SAVE) != SL_OK)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
1397
fa8539dcab46 (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
static void ScrollMainViewport(int x, int y)
fa8539dcab46 (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
{
4536
d532b2611952 (svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents: 4502
diff changeset
   928
	if (_game_mode != GM_MENU) {
1397
fa8539dcab46 (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
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
fa8539dcab46 (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
		assert(w);
fa8539dcab46 (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
fa8539dcab46 (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
		WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
fa8539dcab46 (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
		WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
fa8539dcab46 (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
	}
fa8539dcab46 (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
}
fa8539dcab46 (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
fa8539dcab46 (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
static const int8 scrollamt[16][2] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   938
	{ 0,  0},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   939
	{-2,  0}, //  1 : left
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   940
	{ 0, -2}, //  2 : up
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   941
	{-2, -1}, //  3 : left + up
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   942
	{ 2,  0}, //  4 : right
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   943
	{ 0,  0}, //  5 : left + right
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   944
	{ 2, -1}, //  6 : right + up
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   945
	{ 0, -2}, //  7 : left + right + up = up
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   946
	{ 0  ,2}, //  8 : down
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   947
	{-2  ,1}, //  9 : down+left
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   948
	{ 0,  0}, // 10 : impossible
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   949
	{-2,  0}, // 11 : left + up + down = left
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   950
	{ 2,  1}, // 12 : down+right
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   951
	{ 0,  2}, // 13 : left + right + down = down
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   952
	{ 0, -2}, // 14 : left + right + up = up
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
   953
	{ 0,  0}, // 15 : impossible
1397
fa8539dcab46 (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
   954
};
fa8539dcab46 (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
   955
fa8539dcab46 (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
   956
static void HandleKeyScrolling(void)
fa8539dcab46 (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
   957
{
fa8539dcab46 (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
   958
	if (_dirkeys && !_no_scroll) {
fa8539dcab46 (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
   959
		int factor = _shift_pressed ? 50 : 10;
fa8539dcab46 (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
   960
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
fa8539dcab46 (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
   961
	}
fa8539dcab46 (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
   962
}
1199
198a8aad2fe9 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   963
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
   964
void GameLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
{
2380
392bba57462d (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
   966
	ThreadMsg message;
392bba57462d (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
   967
392bba57462d (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
   968
	if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message);
0
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
	// autosave game?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	if (_do_autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
		_do_autosave = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
		DoAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
		RedrawAutosave();
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
1199
198a8aad2fe9 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   977
	// handle scrolling of the main window
4502
02543104c12a (svn r6287) -Codechange: Remove a redundant check
tron
parents: 4383
diff changeset
   978
	HandleKeyScrolling();
1199
198a8aad2fe9 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
   979
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	// make a screenshot?
4184
541f819f2125 (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4171
diff changeset
   981
	if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	// switch game mode?
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   984
	if (_switch_mode != SM_NONE) {
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   985
		SwitchMode(_switch_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
		_switch_mode = SM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	IncreaseSpriteLRU();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	InteractiveRandom();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   992
	if (_scroller_click_timeout > 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
		_scroller_click_timeout -= 3;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   994
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
		_scroller_click_timeout = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   996
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	_caret_timer += 3;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   999
	_timer_counter += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	CursorTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1002
#ifdef ENABLE_NETWORK
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1003
	// Check for UDP stuff
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
  1004
	if (_network_available) NetworkUDPGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
  1006
	if (_networking && !IsGeneratingWorld()) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1007
		// Multiplayer
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1008
		NetworkGameLoop();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1009
	} else {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1010
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1011
			// This means that we want to reconnect to the last host
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1012
			// We do this here, because it means that the network is really closed
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1013
			NetworkClientConnectGame(_network_last_host, _network_last_port);
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1014
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1015
		// Singleplayer
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
  1016
		StateGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1018
#else
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1019
	StateGameLoop();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1020
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1022
	if (!_pause && _display_opt & DO_FULL_ANIMATION) DoPaletteAnimations();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1024
	if (!_pause || _cheats.build_in_pause.value) MoveAllTextEffects();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
1570
c9b6cf44ce53 (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
  1026
	InputLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
1608
70a3c1a6576d (svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents: 1570
diff changeset
  1028
	MusicLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1036
diff changeset
  1031
void BeforeSaveGame(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1033
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1035
	if (w != NULL) {
2643
f1fec6d1559a (svn r3185) const
tron
parents: 2641
diff changeset
  1036
		_saved_scrollpos_x = WP(w, const vp_d).scrollpos_x;
f1fec6d1559a (svn r3185) const
tron
parents: 2641
diff changeset
  1037
		_saved_scrollpos_y = WP(w, const vp_d).scrollpos_y;
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1038
		_saved_scrollpos_zoom = w->viewport->zoom;
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1039
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1042
static void ConvertTownOwner(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1044
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
863
6a1444534f62 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 861
diff changeset
  1046
	for (tile = 0; tile != MapSize(); tile++) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1047
		switch (GetTileType(tile)) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1048
			case MP_STREET:
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1049
				if (IsLevelCrossing(tile) && GetCrossingRoadOwner(tile) & 0x80) {
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1050
					SetCrossingRoadOwner(tile, OWNER_TOWN);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1051
				}
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1052
				/* FALLTHROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1054
			case MP_TUNNELBRIDGE:
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1055
				if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1056
				break;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1057
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3984
diff changeset
  1058
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
// before savegame version 4, the name of the company determined if it existed
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1064
static void CheckIsPlayerActive(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1066
	Player *p;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1067
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	FOR_ALL_PLAYERS(p) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1069
		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
  1070
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1073
// since savegame version 4.1, exclusive transport rights are stored at towns
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1074
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
  1075
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1076
	Town *t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1077
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1078
	FOR_ALL_TOWNS(t) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1079
		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
  1080
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1081
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  1082
	/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1083
	 *   could be implemented this way:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1084
	 * 1.) Go through all stations
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1085
	 *     Build an array town_blocked[ town_id ][ player_id ]
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1086
	 *     that stores if at least one station in that town is blocked for a player
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1087
	 * 2.) Go through that array, if you find a town that is not blocked for
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1088
	 *     one player, but for all others, then give him exclusivity.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1089
	 */
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1090
}
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1091
2756
52f8927b9542 (svn r3301) One more static
tron
parents: 2754
diff changeset
  1092
static const byte convert_currency[] = {
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1093
	 0,  1, 12,  8,  3,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1094
	10, 14, 19,  4,  5,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1095
	 9, 11, 13,  6, 17,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1096
	16, 22, 21,  7, 15,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1097
	18,  2, 20, };
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1098
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1099
// since savegame version 4.2 the currencies are arranged differently
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1100
static void UpdateCurrencies(void)
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1101
{
768
c833f6f2742d (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
  1102
	_opt.currency = convert_currency[_opt.currency];
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1103
}
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1104
1181
3cbae3ef2590 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1105
/* Up to revision 1413 the invisible tiles at the southern border have not been
3cbae3ef2590 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1106
 * MP_VOID, even though they should have. This is fixed by this function
3cbae3ef2590 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1107
 */
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1108
static void UpdateVoidTiles(void)
929
19096353d35c (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1109
{
959
e6a3bbda610f (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 950
diff changeset
  1110
	uint i;
1181
3cbae3ef2590 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1111
3075
fd64f71655eb (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1112
	for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX());
fd64f71655eb (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1113
	for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i);
929
19096353d35c (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1114
}
19096353d35c (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1115
1165
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1116
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255)
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1117
static void UpdateSignOwner(void)
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1118
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1119
	Sign *si;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1120
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1121
	FOR_ALL_SIGNS(si) si->owner = OWNER_NONE;
1165
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1122
}
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1123
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1124
extern void UpdateOldAircraft( void );
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1125
extern void UpdateOilRig( void );
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1127
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1128
static inline RailType UpdateRailType(RailType rt, RailType min)
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1129
{
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1130
	return rt >= min ? (RailType)(rt + 1): rt;
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1131
}
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1132
2808
8ece7af41664 (svn r3356) - Remove unused parameter of AfterLoadGame().
peter1138
parents: 2805
diff changeset
  1133
bool AfterLoadGame(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
	ViewPort *vp;
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1137
	Player *p;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
  1138
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
	// in version 2.1 of the savegame, town owner was unified.
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1140
	if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1142
	// from version 4.1 of the savegame, exclusive rights are stored at towns
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1143
	if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1144
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1145
	// from version 4.2 of the savegame, currencies are in a different order
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1146
	if (CheckSavegameVersionOldStyle(4, 2)) UpdateCurrencies();
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1147
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1148
	// from version 6.1 of the savegame, signs have an "owner"
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1149
	if (CheckSavegameVersionOldStyle(6, 1)) UpdateSignOwner();
1165
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1150
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1151
	/* In old version there seems to be a problem that water is owned by
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1152
	    OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1153
	    (4.3) version, so I just check when versions are older, and then
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1154
	    walk through the whole map.. */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1155
	if (CheckSavegameVersionOldStyle(4, 3)) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1977
diff changeset
  1156
		TileIndex tile = TileXY(0, 0);
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1157
		uint w = MapSizeX();
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1158
		uint h = MapSizeY();
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1159
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1160
		BEGIN_TILE_LOOP(tile_cur, w, h, tile)
1901
03bf9bf99319 (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
  1161
			if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS)
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  1162
				SetTileOwner(tile_cur, OWNER_WATER);
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1163
		END_TILE_LOOP(tile_cur, w, h, tile)
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1164
	}
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1165
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	// convert road side to my format.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	if (_opt.road_side) _opt.road_side = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1169
	/* Check all NewGRFs are present */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1170
	if (!IsGoodGRFConfigList()) return false;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1171
5340
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1172
	/* Update current year
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1173
	 * must be done before loading sprites as some newgrfs check it */
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1174
	SetDate(_date);
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1175
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	// Load the sprites
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	GfxLoadSprites();
5155
a479ef9c16a5 (svn r7250) -Codechange: Shuffle sprite loading and character width caching around a bit. This reduces the number of times the sprites are loaded from 5 to 2, just for the intro game.
peter1138
parents: 5116
diff changeset
  1178
	LoadStringWidthTable();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
2814
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1180
	/* Connect front and rear engines of multiheaded trains and converts
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1181
	 * subtype to the new format */
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1182
	if (CheckSavegameVersionOldStyle(17, 1)) ConvertOldMultiheadToNew();
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1183
2928
1a352063cdde (svn r3484) -fix: fixed issue in last commit where loading savegame versions 18 and 19 didn't init the multiheaded engine pointers
bjarni
parents: 2916
diff changeset
  1184
	/* Connect front and rear engines of multiheaded trains */
1a352063cdde (svn r3484) -fix: fixed issue in last commit where loading savegame versions 18 and 19 didn't init the multiheaded engine pointers
bjarni
parents: 2916
diff changeset
  1185
	ConnectMultiheadedTrains();
2855
56c39efde08a (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2848
diff changeset
  1186
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
	// reinit the landscape variables (landscape might have changed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	InitializeLandscapeVariables(true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1189
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	// Update all vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
	AfterLoadVehicles();
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1192
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1193
	// Update all waypoints
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1194
	if (CheckSavegameVersion(12)) FixOldWaypoints();
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1195
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1196
	UpdateAllWaypointSigns();
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1197
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	// in version 2.2 of the savegame, we have new airports
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1199
	if (CheckSavegameVersionOldStyle(2, 2)) UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	UpdateAllStationVirtCoord();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	// Setup town coords
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
	AfterLoadTown();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
	UpdateAllSignVirtCoords();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	// make sure there is a town in the game
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1208
	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
  1209
		_error_message = STR_NO_TOWN_IN_SCENARIO;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	// Initialize windows
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
  1214
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	w = FindWindowById(WC_MAIN_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	WP(w,vp_d).scrollpos_x = _saved_scrollpos_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	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
  1221
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	vp->zoom = _saved_scrollpos_zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	vp->virtual_width = vp->width << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	vp->virtual_height = vp->height << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1227
	// in version 4.1 of the savegame, is_active was introduced to determine
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	// if a player does exist, rather then checking name_1
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1229
	if (CheckSavegameVersionOldStyle(4, 1)) CheckIsPlayerActive();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1230
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1231
	// the void tiles on the southern border used to belong to a wrong class (pre 4.3).
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1232
	if (CheckSavegameVersionOldStyle(4, 3)) UpdateVoidTiles();
929
19096353d35c (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1233
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1234
	// If Load Scenario / New (Scenario) Game is used,
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1235
	//  a player does not exist yet. So create one here.
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1236
	// 1 exeption: network-games. Those can have 0 players
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1237
	//   But this exeption is not true for network_servers!
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1238
	if (!_players[0].is_active && (!_networking || (_networking && _network_server)))
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1239
		DoStartupNewPlayer(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
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
  1241
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1244
	// In 5.1, Oilrigs have been moved (again)
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1245
	if (CheckSavegameVersionOldStyle(5, 1)) UpdateOilRig();
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 942
diff changeset
  1246
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1247
	/* In version 6.1 we put the town index in the map-array. To do this, we need
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1248
	 *  to use m2 (16bit big), so we need to clean m2, and that is where this is
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1249
	 *  all about ;) */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1250
	if (CheckSavegameVersionOldStyle(6, 1)) {
1264
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1251
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
3983
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1252
			switch (GetTileType(tile)) {
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1253
				case MP_HOUSE:
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1254
					_m[tile].m4 = _m[tile].m2;
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1255
					SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1256
					break;
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1257
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1258
				case MP_STREET:
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1259
					_m[tile].m4 |= (_m[tile].m2 << 4);
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1260
					if (IsTileOwner(tile, OWNER_TOWN)) {
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1261
						SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1262
					} else {
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1263
						SetTownIndex(tile, 0);
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1264
					}
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1265
					break;
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1266
0f815283e04b (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3977
diff changeset
  1267
				default: break;
1264
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1268
			}
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1269
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1270
	}
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1271
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1272
	/* From version 9.0, we update the max passengers of a town (was sometimes negative
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1273
	 *  before that. */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1274
	if (CheckSavegameVersion(9)) {
1377
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1275
		Town *t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1276
		FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
1377
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1277
	}
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1278
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1279
	/* From version 16.0, we included autorenew on engines, which are now saved, but
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1280
	 *  of course, we do need to initialize them for older savegames. */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1281
	if (CheckSavegameVersion(16)) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1282
		FOR_ALL_PLAYERS(p) {
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1283
			p->engine_renew_list   = NULL;
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1284
			p->engine_renew        = false;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1285
			p->engine_renew_months = -6;
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1286
			p->engine_renew_money  = 100000;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1287
		}
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1288
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1289
		/* When loading a game, _local_player is not yet set to the correct value.
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1290
		 * However, in a dedicated server we are a spectator, so nothing needs to
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1291
		 * happen. In case we are not a dedicated server, the local player always
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1292
		 * becomes player 0, unless we are in the scenario editor where all the
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1293
		 * players are 'invalid'.
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1294
		 */
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1295
		if (!_network_dedicated && IsValidPlayer(0)) {
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1296
			p = GetPlayer(0);
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1297
			p->engine_renew        = _patches.autorenew;
2322
32c18dd9a9f1 (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
  1298
			p->engine_renew_months = _patches.autorenew_months;
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5352
diff changeset
  1299
			p->engine_renew_money  = _patches.autorenew_money;
2322
32c18dd9a9f1 (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
  1300
		}
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1301
	}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1302
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1303
	if (CheckSavegameVersion(42)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1304
		TileIndex map_end = MapSize();
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1305
		TileIndex tile;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1306
		Vehicle* v;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1307
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1308
		for (tile = 0; tile != map_end; tile++) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1309
			if (MayHaveBridgeAbove(tile)) ClearBridgeMiddle(tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1310
			if (IsBridgeTile(tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1311
				if (HASBIT(_m[tile].m5, 6)) { // middle part
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1312
					Axis axis = (Axis)GB(_m[tile].m5, 0, 1);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1313
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1314
					if (HASBIT(_m[tile].m5, 5)) { // transport route under bridge?
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1315
						if (GB(_m[tile].m5, 3, 2) == TRANSPORT_RAIL) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1316
							MakeRailNormal(
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1317
								tile,
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1318
								GetTileOwner(tile),
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1319
								axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1320
								GetRailType(tile)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1321
							);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1322
						} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1323
							TownID town = IsTileOwner(tile, OWNER_TOWN) ? ClosestTownFromTile(tile, (uint)-1)->index : 0;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1324
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1325
							MakeRoadNormal(
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1326
								tile,
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1327
								GetTileOwner(tile),
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1328
								axis == AXIS_X ? ROAD_Y : ROAD_X,
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1329
								town
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1330
							);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1331
						}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1332
					} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1333
						if (GB(_m[tile].m5, 3, 2) == 0) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1334
							MakeClear(tile, CLEAR_GRASS, 3);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1335
						} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1336
							MakeCanal(tile, GetTileOwner(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1337
						}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1338
					}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1339
					SetBridgeMiddle(tile, axis);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1340
				} else { // ramp
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1341
					Axis axis = (Axis)GB(_m[tile].m5, 0, 1);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1342
					uint north_south = GB(_m[tile].m5, 5, 1);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1343
					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1344
					TransportType type = (TransportType)GB(_m[tile].m5, 1, 2);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1345
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1346
					_m[tile].m5 = 1 << 7 | type << 2 | dir;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1347
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1348
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1349
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1350
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1351
		FOR_ALL_VEHICLES(v) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1352
			if (v->type != VEH_Train && v->type != VEH_Road) continue;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1353
			if (IsBridgeTile(v->tile)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1354
				DiagDirection dir = GetBridgeRampDirection(v->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1355
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1356
				if (dir != DirToDiagDir(v->direction)) continue;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1357
				switch (dir) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1358
					default: NOT_REACHED();
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1359
					case DIAGDIR_NE: if ((v->x_pos & 0xF) !=  0)            continue; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1360
					case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1361
					case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1362
					case DIAGDIR_NW: if ((v->y_pos & 0xF) !=  0)            continue; break;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1363
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1364
			} else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1365
				v->tile = GetNorthernBridgeEnd(v->tile);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1366
			} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1367
				continue;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1368
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1369
			if (v->type == VEH_Train) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1370
				v->u.rail.track = 0x40;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1371
			} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1372
				v->u.road.state = 0xFF;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1373
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1374
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1375
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1376
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1377
	/* Elrails got added in rev 24 */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1378
	if (CheckSavegameVersion(24)) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1379
		Vehicle *v;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1380
		uint i;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1381
		TileIndex t;
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1382
		RailType min_rail = RAILTYPE_ELECTRIC;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1383
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1384
		for (i = 0; i < lengthof(_engines); i++) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1385
			Engine *e = GetEngine(i);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1386
			if (e->type == VEH_Train &&
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1387
					(e->railtype != RAILTYPE_RAIL || RailVehInfo(i)->engclass == 2)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1388
				e->railtype++;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1389
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1390
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1391
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1392
		FOR_ALL_VEHICLES(v) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1393
			if (v->type == VEH_Train) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1394
				RailType rt = GetEngine(v->engine_type)->railtype;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1395
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1396
				v->u.rail.railtype = rt;
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1397
				if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1398
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1399
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1400
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1401
		/* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1402
		for (t = 0; t < MapSize(); t++) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1403
			switch (GetTileType(t)) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1404
				case MP_RAILWAY:
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1405
					SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1406
					break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1407
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1408
				case MP_STREET:
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1409
					if (IsLevelCrossing(t)) {
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1410
						SetRailTypeCrossing(t, UpdateRailType(GetRailTypeCrossing(t), min_rail));
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1411
					}
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1412
					break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1413
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1414
				case MP_STATION:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1415
					if (IsRailwayStation(t)) {
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1416
						SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1417
					}
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1418
					break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1419
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1420
				case MP_TUNNELBRIDGE:
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1421
					if (IsTunnel(t)) {
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1422
						if (GetTunnelTransportType(t) == TRANSPORT_RAIL) {
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1423
							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1424
						}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1425
					} else {
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1426
						if (GetBridgeTransportType(t) == TRANSPORT_RAIL) {
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1427
							SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1428
						}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1429
					}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1430
					break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1431
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1432
				default:
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1433
					break;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1434
			}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1435
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1436
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1437
		FOR_ALL_VEHICLES(v) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1438
			if (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1439
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1440
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1441
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3312
diff changeset
  1442
2805
29e2b43a1e20 (svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents: 2769
diff changeset
  1443
	/* In version 16.1 of the savegame a player can decide if trains, which get
29e2b43a1e20 (svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents: 2769
diff changeset
  1444
	 * replaced, shall keep their old length. In all prior versions, just default
29e2b43a1e20 (svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents: 2769
diff changeset
  1445
	 * to false */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1446
	if (CheckSavegameVersionOldStyle(16, 1)) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1447
		FOR_ALL_PLAYERS(p) p->renew_keep_length = false;
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1448
	}
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1449
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1450
	/* In version 17, ground type is moved from m2 to m4 for depots and
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1451
	 * waypoints to make way for storing the index in m2. The custom graphics
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1452
	 * id which was stored in m4 is now saved as a grf/id reference in the
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1453
	 * waypoint struct. */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1454
	if (CheckSavegameVersion(17)) {
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1455
		Waypoint *wp;
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1456
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1457
		FOR_ALL_WAYPOINTS(wp) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1458
			if (wp->deleted == 0) {
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1459
				const StationSpec *statspec = NULL;
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1460
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1461
				if (HASBIT(_m[wp->xy].m3, 4))
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1462
					statspec = GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1463
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1464
				if (statspec != NULL) {
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1465
					wp->stat_id = _m[wp->xy].m4 + 1;
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1466
					wp->grfid = statspec->grfid;
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1467
					wp->localidx = statspec->localidx;
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1468
				} else {
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1469
					// No custom graphics set, so set to default.
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1470
					wp->stat_id = 0;
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1471
					wp->grfid = 0;
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1472
					wp->localidx = 0;
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1473
				}
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1474
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1475
				// Move ground type bits from m2 to m4.
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1476
				_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1477
				// Store waypoint index in the tile.
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1478
				_m[wp->xy].m2 = wp->index;
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1479
			}
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1480
		}
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1481
	} else {
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1482
		/* As of version 17, we recalculate the custom graphic ID of waypoints
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1483
		 * from the GRF ID / station index. */
5350
7564e1c8f5dd (svn r7521) -Codechange: Rename UpdateAllWaypointCustomGraphics to AfterLoadWaypoints to be more conforming with other such functions.
Darkvater
parents: 5340
diff changeset
  1484
		AfterLoadWaypoints();
2670
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1485
	}
f2d6a8424e3e (svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents: 2649
diff changeset
  1486
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1487
	/* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1488
	 *  room for PBS. Now in version 21 move it back :P. */
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1489
	if (CheckSavegameVersion(21) && !CheckSavegameVersion(15)) {
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1490
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1491
			if (IsTileType(tile, MP_RAILWAY)) {
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1492
				if (HasSignals(tile)) {
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1493
					// convert PBS signals to combo-signals
3984
812dac315975 (svn r5173) Use map manipulation functions instead of SB()
tron
parents: 3983
diff changeset
  1494
					if (HASBIT(_m[tile].m4, 2)) SetSignalType(tile, SIGTYPE_COMBO);
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1495
3984
812dac315975 (svn r5173) Use map manipulation functions instead of SB()
tron
parents: 3983
diff changeset
  1496
					// move the signal variant back
812dac315975 (svn r5173) Use map manipulation functions instead of SB()
tron
parents: 3983
diff changeset
  1497
					SetSignalVariant(tile, HASBIT(_m[tile].m4, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1498
					CLRBIT(_m[tile].m4, 3);
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1499
				}
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1500
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1501
				// Clear PBS reservation on track
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1502
				if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1503
					SB(_m[tile].m4, 4, 4, 0);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1504
				} else {
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1505
					CLRBIT(_m[tile].m3, 6);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1506
				}
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1507
			}
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1508
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1509
			// Clear PBS reservation on crossing
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1510
			if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile))
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1511
				CLRBIT(_m[tile].m5, 0);
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1512
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1513
			// Clear PBS reservation on station
2929
b91e62748919 (svn r3485) - [Post-PBS]: when reverting PBS and removing station-tile reservations a station can of course not be a crossing as well. Thanks glx.
Darkvater
parents: 2928
diff changeset
  1514
			if (IsTileType(tile, MP_STATION))
2916
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1515
				CLRBIT(_m[tile].m3, 6);
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1516
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1517
	}
b687477adcba (svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents: 2899
diff changeset
  1518
3121
72fb0554f9f1 (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1519
	if (CheckSavegameVersion(22))  UpdatePatches();
72fb0554f9f1 (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1520
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1521
	if (CheckSavegameVersion(25)) {
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1522
		Vehicle *v;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1523
		FOR_ALL_VEHICLES(v) {
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1524
			if (v->type == VEH_Road) {
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1525
				v->vehstatus &= ~0x40;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1526
				v->u.road.slot = NULL;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1527
				v->u.road.slot_age = 0;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1528
			}
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1529
		}
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1530
	}
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1531
3580
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1532
	if (CheckSavegameVersion(26)) {
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1533
		Station *st;
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1534
		FOR_ALL_STATIONS(st) {
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1535
			st->last_vehicle_type = VEH_Invalid;
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1536
		}
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1537
	}
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1538
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1539
	YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1540
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
  1541
	if (CheckSavegameVersion(34)) FOR_ALL_PLAYERS(p) ResetPlayerLivery(p);
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
  1542
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1543
	FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1544
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1545
	if (!CheckSavegameVersion(27)) AfterLoadStations();
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1546
4574
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1547
	{
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1548
		/* Set up the engine count for all players */
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1549
		Player *players[MAX_PLAYERS];
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1550
		int i;
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1551
		const Vehicle *v;
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1552
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1553
		for (i = 0; i < MAX_PLAYERS; i++) players[i] = GetPlayer(i);
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1554
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1555
		FOR_ALL_VEHICLES(v) {
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1556
			if (!IsEngineCountable(v)) continue;
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1557
			players[v->owner]->num_engines[v->engine_type]++;
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1558
		}
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1559
	}
61a17f80cfb9 (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1560
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1561
	/* Time starts at 0 instead of 1920.
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1562
	 * Account for this in older games by adding an offset */
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1563
	if (CheckSavegameVersion(31)) {
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1564
		Station *st;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1565
		Waypoint *wp;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1566
		Engine *e;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1567
		Player *player;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1568
		Industry *i;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1569
		Vehicle *v;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1570
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1571
		_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
4383
f1e2d6c7527e (svn r6136) -Fix: _cur_year wasn't converting when reading pre-31 savegames, causing nasty desyncs
truelight
parents: 4349
diff changeset
  1572
		_cur_year += ORIGINAL_BASE_YEAR;
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1573
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1574
		FOR_ALL_STATIONS(st)    st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1575
		FOR_ALL_WAYPOINTS(wp)   wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1576
		FOR_ALL_ENGINES(e)      e->intro_date  += DAYS_TILL_ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1577
		FOR_ALL_PLAYERS(player) player->inaugurated_year += ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1578
		FOR_ALL_INDUSTRIES(i)   i->last_prod_year        += ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1579
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1580
		FOR_ALL_VEHICLES(v) {
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1581
			v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1582
			v->build_year += ORIGINAL_BASE_YEAR;
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1583
		}
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1584
	}
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1585
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1586
	/* From 32 on we save the industry who made the farmland.
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1587
	 *  To give this prettyness to old savegames, we remove all farmfields and
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1588
	 *  plant new ones. */
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1589
	if (CheckSavegameVersion(32)) {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1590
		Industry *i;
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1591
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1592
		BEGIN_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0) {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1593
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS)) {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1594
				MakeClear(tile_cur, CLEAR_GRASS, 3);
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1595
			}
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1596
		} END_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0)
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1597
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1598
		FOR_ALL_INDUSTRIES(i) {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1599
			uint j;
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1600
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1601
			if (i->type == IT_FARM || i->type == IT_FARM_2) {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1602
				for (j = 0; j != 50; j++) PlantRandomFarmField(i);
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1603
			}
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1604
		}
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1605
	}
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1606
4712
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1607
	/* Setting no refit flags to all orders in savegames from before refit in orders were added */
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1608
	if (CheckSavegameVersion(36)) {
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1609
		Order *order;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1610
		Vehicle *v;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1611
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1612
		FOR_ALL_ORDERS(order) {
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1613
			order->refit_cargo   = CT_NO_REFIT;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1614
			order->refit_subtype = CT_NO_REFIT;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1615
		}
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1616
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1617
		FOR_ALL_VEHICLES(v) {
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1618
			v->current_order.refit_cargo   = CT_NO_REFIT;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1619
			v->current_order.refit_subtype = CT_NO_REFIT;
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1620
		}
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1621
	}
4335ad42e163 (svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents: 4661
diff changeset
  1622
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
  1623
	if (CheckSavegameVersion(37)) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
  1624
		ConvertNameArray();
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
  1625
	}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5024
diff changeset
  1626
5314
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5313
diff changeset
  1627
	/* from version 38 we have optional elrails, since we cannot know the
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5313
diff changeset
  1628
	 * preference of a user, let elrails enabled; it can be disabled manually */
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  1629
	if (CheckSavegameVersion(38)) {
5314
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5313
diff changeset
  1630
		_patches.disable_elrails = false; // enable elrails
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5313
diff changeset
  1631
		/* do the same as when elrails were enabled/disabled manually just now */
fda2b099eec5 (svn r7470) -Codechange: Leave elrails enabled after loading old (pre-optional) and very old (pre-elrails) games. Let the user manually disable if if undesired.
Darkvater
parents: 5313
diff changeset
  1632
		SettingsDisableElrail(_patches.disable_elrails);
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  1633
	}
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  1634
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
}
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1637
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1638
/** Reload all NewGRF files during a running game. This is a cut-down
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1639
 * version of AfterLoadGame().
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1640
 * XXX - We need to reset the vehicle position hash because with a non-empty
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1641
 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles()
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1642
 * to recalculate vehicle data as some NewGRF vehicle sets could have been
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1643
 * removed or added and changed statistics */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1644
void ReloadNewGRFData(void)
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1645
{
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1646
	/* reload grf data */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1647
	GfxLoadSprites();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1648
	LoadStringWidthTable();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1649
	/* reload vehicles */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1650
	ResetVehiclePosHash();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1651
	AfterLoadVehicles();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1652
	/* update station and waypoint graphics */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1653
	AfterLoadWaypoints();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1654
	AfterLoadStations();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1655
	/* redraw the whole screen */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1656
	MarkWholeScreenDirty();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  1657
}