src/openttd.cpp
author smatz
Fri, 28 Dec 2007 18:25:30 +0000
changeset 8155 ab1e6353db79
parent 8152 ab21de45f8ab
child 8157 1505def01945
permissions -rw-r--r--
(svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
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
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
     3
/** @file openttd.cpp */
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
     6
#define VARDEF
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
     7
#include "string.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1296
diff changeset
     8
#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
     9
#include "driver.h"
2162
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 2147
diff changeset
    10
#include "saveload.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
    12
#include "openttd.h"
7393
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7370
diff changeset
    13
#include "table/strings.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    14
#include "bridge_map.h"
1496
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
    15
#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
    16
#include "spritecache.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
    17
#include "gfxinit.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "gui.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6451
diff changeset
    19
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "station.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    21
#include "station_map.h"
3558
9a3e12615b1c (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
    22
#include "town_map.h"
3367
a995838e8d85 (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    23
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "viewport.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    25
#include "window_func.h"
8106
e6790dd9e750 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8095
diff changeset
    26
#include "window_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#include "player.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    28
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "sound.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
#include "fileio.h"
8151
4cefeef74c28 (svn r11713) -Codechange: Move some declarations and definitions in a more logical disposition
belugas
parents: 8144
diff changeset
    35
#include "fios.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
#include "airport.h"
6193
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
    37
#include "aircraft.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 123
diff changeset
    38
#include "console.h"
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    39
#include "screenshot.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5436
diff changeset
    40
#include "network/network.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
    41
#include "signs.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1310
diff changeset
    42
#include "depot.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
    43
#include "waypoint.h"
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
    44
#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
    45
#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
    46
#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
    47
#include "settings.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
    48
#include "genworld.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
    49
#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
    50
#include "fontcache.h"
6451
e576c71bfc09 (svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents: 6427
diff changeset
    51
#include "newgrf.h"
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
    52
#include "newgrf_config.h"
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
    53
#include "newgrf_house.h"
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6626
diff changeset
    54
#include "newgrf_commons.h"
7609
b70ffc13652a (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium
parents: 7567
diff changeset
    55
#include "newgrf_storage.h"
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6175
diff changeset
    56
#include "player_face.h"
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6629
diff changeset
    57
#include "group.h"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6935
diff changeset
    58
#include "blitter/factory.hpp"
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
    59
#include "sound/sound_driver.hpp"
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
    60
#include "music/music_driver.hpp"
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
    61
#include "video/video_driver.hpp"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    62
#include "strings_func.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    63
#include "zoom_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    64
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    65
#include "vehicle_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    67
#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
    68
#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
    69
#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
    70
#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
    71
#include "water_map.h"
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
    72
#include "industry_map.h"
6257
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
    73
#include "unmovable_map.h"
7710
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
    74
#include "tree_map.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8082
diff changeset
    75
#include "tunnelbridge_map.h"
8108
b42a0e5c67ef (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8107
diff changeset
    76
#include "void_map.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
    77
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    80
void CallLandscapeTick();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    81
void IncreaseDate();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    82
void DoPaletteAnimations();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    83
void MusicLoop();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
    84
void ResetMusic();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    87
extern Player* DoStartupNewPlayer(bool is_ai);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
extern void ShowOSErrorBox(const char *buf);
7064
81d35e1f3e37 (svn r10329) -Feature [FS#812]: (patch) option to select the "default" rail type when you start a new game or load a game. This is done either static, i.e. rail, electrified rail, monorail and maglev, or dynamic which takes either the first or last available railtype or the railtype that is used most on the map.
rubidium
parents: 7058
diff changeset
    89
extern void SetDefaultRailGui();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
1436
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    91
/* TODO: usrerror() for errors which are not of an internal nature but
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    92
 * caused by the user, i.e. missing files or fatal configuration errors.
ee20dd86ac0d (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    93
 * 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
    94
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
    95
void CDECL error(const char *s, ...)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    96
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	char buf[512];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    99
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	va_start(va, s);
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   101
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	va_end(va);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   103
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	ShowOSErrorBox(buf);
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   105
	if (_video_driver != NULL) _video_driver->Stop();
0
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
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
}
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
void CDECL ShowInfoF(const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	va_start(va, str);
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   116
	vsnprintf(buf, lengthof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
	va_end(va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   122
extern const char _openttd_revision[];
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   123
static void showhelp()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	char buf[4096], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   127
	p = buf;
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   128
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   129
	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
   130
	p = strecpy(p,
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   131
		"\n"
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   132
		"\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		"Command line options:\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   134
		"  -v drv              = Set video driver (see below)\n"
5885
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   135
		"  -s drv              = Set sound driver (see below) (param bufsize,hz)\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   136
		"  -m drv              = Set music driver (see below)\n"
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   137
		"  -b drv              = Set the blitter to use (see below)\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   138
		"  -r res              = Set resolution (for instance 800x600)\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   139
		"  -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
   140
		"  -t year             = Set starting year\n"
1440
08722492ee27 (svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents: 1436
diff changeset
   141
		"  -d [[fac=]lvl[,...]]= Debug mode\n"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   142
		"  -e                  = Start Editor\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   143
		"  -g [savegame]       = Start new/save game immediately\n"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   144
		"  -G seed             = Set random seed\n"
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   145
#if defined(ENABLE_NETWORK)
5425
69d019397b5c (svn r7629) -Fix: the CLI parameter for joining a network game is "-n ip:port#player", not "-n ip#player:port" as the help text suggests.
rubidium
parents: 5385
diff changeset
   146
		"  -n [ip:port#player] = Start networkgame\n"
5508
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   147
		"  -D [ip][:port]      = Start dedicated server\n"
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   148
		"  -l ip[:port]        = Redirect DEBUG()\n"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   149
#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
   150
		"  -f                  = Fork into the background (dedicated only)\n"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   151
#endif
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   152
#endif /* ENABLE_NETWORK */
2831
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   153
		"  -i                  = Force to use the DOS palette\n"
952f77671794 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   154
		"                          (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
   155
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n"
5576
b19c640dfc37 (svn r8013) -Codechange (r6921, rUnknown): Show the error message of corrupt or missing (own) files
Darkvater
parents: 5521
diff changeset
   156
		"  -x                  = Do not automatically save to config file on exit\n",
5170
817550aa5a5f (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   157
		lastof(buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   160
	/* List the drivers */
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   161
	p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   163
	/* List the blitters */
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   164
	p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   165
5723
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   166
	/* ShowInfo put output to stderr, but version information should go
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   167
	 * to stdout; this is the only exception */
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   168
#if !defined(WIN32) && !defined(WIN64)
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   169
	printf("%s\n", buf);
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   170
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	ShowInfo(buf);
5723
748cb24d9340 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5707
diff changeset
   172
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
}
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
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   176
struct MyGetOptData {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	char *opt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	int numleft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	char **argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	const char *options;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   181
	const char *cont;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   183
	MyGetOptData(int argc, char **argv, const char *options)
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   184
	{
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   185
		opt = NULL;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   186
		numleft = argc;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   187
		this->argv = argv;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   188
		this->options = options;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   189
		cont = NULL;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   190
	}
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   191
};
0
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
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   195
	const char *s,*r,*t;
0
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) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   209
				/* Found argument, try to locate it in options. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
				if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   211
					/* ERROR! */
0
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] == ':') {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   215
					/* Item wants an argument. Check if the argument follows, or if it comes as a separate arg. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
					if (!*(t = s + 1)) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   217
						/* It comes as a separate arg. Check if out of args? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
						if (--md->numleft < 0 || *(t = *md->argv) == '-') {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   219
							/* Check if item is optional? */
0
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
					}
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   228
					md->opt = (char*)t;
0
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 {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   237
			/* This is currently not supported. */
0
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
{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   246
	const char *t = strchr(s, 'x');
0
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
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7849
diff changeset
   252
	res[0] = Clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7849
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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   256
static void InitializeDynamicVariables()
919
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;
7152
89373fa66dc5 (svn r10426) -Codechange: Activate the reset of industry/tiles mapping upon initialization or new game.
belugas
parents: 7091
diff changeset
   261
	_industry_mngr.ResetMapping();
89373fa66dc5 (svn r10426) -Codechange: Activate the reset of industry/tiles mapping upon initialization or new game.
belugas
parents: 7091
diff changeset
   262
	_industile_mngr.ResetMapping();
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   263
}
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   264
5659
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   265
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   266
static void UnInitializeGame()
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   267
{
5659
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   268
	UnInitWindowSystem();
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   269
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   270
	/* Uninitialize airport state machines */
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   271
	UnInitializeAirports();
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   272
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   273
	/* Uninitialize variables that are allocated dynamically */
7401
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   274
	_Town_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   275
	_Industry_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   276
	_Station_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   277
	_Vehicle_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   278
	_Sign_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   279
	_Order_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   280
	_Group_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7393
diff changeset
   281
	_CargoPacket_pool.CleanPool();
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   282
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
   283
	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
   284
	free((void*)_industry_sort);
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
   285
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
   286
	free(_config_file);
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   287
}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   288
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   289
static void LoadIntroGame()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   290
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   291
	_game_mode = GM_MENU;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6351
diff changeset
   292
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   293
	_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
   294
	ResetGRFConfig(false);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   295
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   296
	/* Setup main window */
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   297
	ResetWindowSystem();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   298
	SetupColorsAndInitialWindow();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   299
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   300
	/* Load the default opening screen savegame */
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   301
	if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   302
		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
   303
		WaitTillGeneratedWorld();
921
d4831de060b6 (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   304
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   305
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6229
diff changeset
   306
	_pause_game = 0;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   307
	SetLocalPlayer(PLAYER_FIRST);
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
   308
	/* 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
   309
	_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
   310
	_cursor.fix_at = false;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   311
	MarkWholeScreenDirty();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   312
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 8083
diff changeset
   313
	CheckForMissingGlyphsInLoadedLanguagePack();
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 8083
diff changeset
   314
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   315
	/* Play main theme */
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   316
	if (_music_driver->IsSongPlaying()) ResetMusic();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   317
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   318
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   319
#if defined(UNIX) && !defined(__MORPHOS__)
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   320
extern void DedicatedFork();
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   321
#endif
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   322
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   323
int ttd_main(int argc, char *argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	int i;
1010
977aafc6b8e3 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents: 1009
diff changeset
   326
	const char *optformat;
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   327
	char musicdriver[32], sounddriver[32], videodriver[32], blitter[32];
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6486
diff changeset
   328
	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
   329
	Year startyear = INVALID_YEAR;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   330
	uint generation_seed = GENERATE_NEW_SEED;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   331
	bool save_config = true;
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   332
#if defined(ENABLE_NETWORK)
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;
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   336
	char *debuglog_conn = NULL;
5508
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   337
	char *dedicated_host = NULL;
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   338
	uint16 dedicated_port = 0;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   339
#endif /* ENABLE_NETWORK */
1406
f5da270a654f (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   340
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   341
	musicdriver[0] = sounddriver[0] = videodriver[0] = blitter[0] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	_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
   345
	_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
   346
	_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
   347
	_config_file = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   349
	/* The last param of the following function means this:
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   350
	 *   a letter means: it accepts that param (e.g.: -h)
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   351
	 *   a ':' behind it means: it need a param (e.g.: -m<driver>)
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   352
	 *   a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   353
	optformat = "m:s:v:b:hD::n::eit:d::r:g::G:c:xl:"
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   354
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   355
		"f"
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   356
#endif
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   357
	;
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   358
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6486
diff changeset
   359
	MyGetOptData mgo(argc - 1, argv + 1, optformat);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   360
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	while ((i = MyGetOpt(&mgo)) != -1) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   362
		switch (i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		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
   364
		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
   365
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
6852
439563b70fd3 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents: 6770
diff changeset
   366
		case 'b': ttd_strlcpy(blitter, mgo.opt, sizeof(blitter)); break;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   367
#if defined(ENABLE_NETWORK)
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   368
		case 'D':
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   369
			strcpy(musicdriver, "null");
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   370
			strcpy(sounddriver, "null");
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   371
			strcpy(videodriver, "dedicated");
6878
5cefd3ac59c7 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 6867
diff changeset
   372
			strcpy(blitter, "null");
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   373
			dedicated = true;
5885
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   374
			if (mgo.opt != NULL) {
5508
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   375
				/* Use the existing method for parsing (openttd -n).
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   376
				 * However, we do ignore the #player part. */
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   377
				const char *temp = NULL;
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   378
				const char *port = NULL;
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   379
				ParseConnectionString(&temp, &port, mgo.opt);
5885
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   380
				if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt;
5508
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   381
				if (port != NULL) dedicated_port = atoi(port);
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   382
			}
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   383
			break;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   384
		case 'f': _dedicated_forks = true; break;
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   385
		case 'n':
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   386
			network = true;
3059
1726615b3ddd (svn r3648) - Fix typo in r3647, don't ask me how it got there s/_/./
Darkvater
parents: 3058
diff changeset
   387
			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
   388
			break;
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   389
		case 'l':
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   390
			debuglog_conn = mgo.opt;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   391
			break;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   392
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
		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
   394
		case 't': startyear = atoi(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		case 'd': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
#if defined(WIN32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
				CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
#endif
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   399
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		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
   402
		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
   403
		case 'g':
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   404
			if (mgo.opt != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
				strcpy(_file_to_saveload.name, mgo.opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
				_switch_mode = SM_LOAD;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   407
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
				_switch_mode = SM_NEWGAME;
6309
eff5790710ee (svn r9205) -Fix: if you started openttd with '-g' you got the same map every run
truelight
parents: 6304
diff changeset
   409
				/* Give a random map */
eff5790710ee (svn r9205) -Fix: if you started openttd with '-g' you got the same map every run
truelight
parents: 6304
diff changeset
   410
				generation_seed = InteractiveRandom();
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   411
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			break;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   413
		case 'G': generation_seed = atoi(mgo.opt); break;
3058
8363e01ea189 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   414
		case 'c': _config_file = strdup(mgo.opt); break;
5507
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   415
		case 'x': save_config = false; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
		case -2:
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 1993
diff changeset
   417
		case 'h':
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
			showhelp();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
			return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
7408
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7401
diff changeset
   423
#if defined(WINCE) && defined(_DEBUG)
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7401
diff changeset
   424
	/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7401
diff changeset
   425
	SetDebugString("4");
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7401
diff changeset
   426
#endif
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7401
diff changeset
   427
6317
70f4e9e52eb1 (svn r9266) -Codechange: unify the retrieval of the base paths a little more.
rubidium
parents: 6309
diff changeset
   428
	DeterminePaths(argv[0]);
961
e9abf6f087f8 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 959
diff changeset
   429
	CheckExternalFiles();
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   430
2290
bdbb059ddba7 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   431
#if defined(UNIX) && !defined(__MORPHOS__)
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   432
	/* We must fork here, or we'll end up without some resources we need (like sockets) */
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   433
	if (_dedicated_forks)
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   434
		DedicatedFork();
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   435
#endif
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   436
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	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
   438
	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
   439
	LoadFromHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   441
	/* override config? */
5885
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   442
	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   443
	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   444
	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
7567
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   445
	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
5885
28503880e8f3 (svn r8497) -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. Also use the recently introduced StrEmpty().
Darkvater
parents: 5884
diff changeset
   446
	if (resolution[0] != 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
   447
	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
   448
	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
   449
6892
c23b5f195668 (svn r10139) -Fix: all inner parts of OpenTTD assume that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1.
rubidium
parents: 6878
diff changeset
   450
	/* The width and height must be at least 1 pixel, this
c23b5f195668 (svn r10139) -Fix: all inner parts of OpenTTD assume that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1.
rubidium
parents: 6878
diff changeset
   451
	 * way all internal drawing routines work correctly. */
c23b5f195668 (svn r10139) -Fix: all inner parts of OpenTTD assume that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1.
rubidium
parents: 6878
diff changeset
   452
	if (_cur_resolution[0] == 0) _cur_resolution[0] = 1;
c23b5f195668 (svn r10139) -Fix: all inner parts of OpenTTD assume that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1.
rubidium
parents: 6878
diff changeset
   453
	if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
c23b5f195668 (svn r10139) -Fix: all inner parts of OpenTTD assume that the resolution is at least 1 by 1, so force the resolution to be always at least 1 by 1.
rubidium
parents: 6878
diff changeset
   454
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   455
#if defined(ENABLE_NETWORK)
5508
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   456
	if (dedicated_host) snprintf(_network_server_bind_ip_host, NETWORK_HOSTNAME_LENGTH, "%s", dedicated_host);
4b30455aba12 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5507
diff changeset
   457
	if (dedicated_port) _network_server_port = dedicated_port;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   458
	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
5692
bce5374837b0 (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5683
diff changeset
   459
#endif /* ENABLE_NETWORK */
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   460
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   461
	/* enumerate language files */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	InitializeLanguagePacks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   464
	/* initialize screenshot formats */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	InitializeScreenshotFormats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   467
	/* initialize airport state machines */
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   468
	InitializeAirports();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   469
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   470
	/* 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
   471
	InitializeDynamicVariables();
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   472
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   473
	/* start the AI */
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   474
	AI_Initialize();
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   475
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   476
	/* Sample catalogue */
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   477
	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
   478
	MxInitialize(11025);
15d859a626e8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   479
	SoundInitialize("sample.cat");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
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
   481
	/* 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
   482
	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
   483
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   484
	/* This must be done early, since functions use the InvalidateWindow* calls */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   485
	InitWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
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
   487
	/* 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
   488
	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
   489
7567
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   490
	DEBUG(misc, 1, "Loading blitter...");
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   491
	if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL)
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   492
		StrEmpty(_ini_blitter) ?
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   493
			error("Failed to autoprobe blitter") :
ab5661f127f8 (svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
truelight
parents: 7515
diff changeset
   494
			error("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   495
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
   496
	DEBUG(driver, 1, "Loading drivers...");
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   497
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   498
	_sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   499
	if (_sound_driver == NULL) {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   500
		StrEmpty(_ini_sounddriver) ?
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   501
			error("Failed to autoprobe sound driver") :
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   502
			error("Failed to select requested sound driver '%s'", _ini_sounddriver);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   503
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   504
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   505
	_music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   506
	if (_music_driver == NULL) {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   507
		StrEmpty(_ini_musicdriver) ?
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   508
			error("Failed to autoprobe music driver") :
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   509
			error("Failed to select requested music driver '%s'", _ini_musicdriver);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   510
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   511
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   512
	_video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   513
	if (_video_driver == NULL) {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   514
		StrEmpty(_ini_videodriver) ?
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   515
			error("Failed to autoprobe video driver") :
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   516
			error("Failed to select requested video driver '%s'", _ini_videodriver);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   517
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   518
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2498
diff changeset
   519
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
6654
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6643
diff changeset
   520
	/* Initialize the zoom level of the screen to normal */
31d17823506f (svn r9885) -Fix r9846: some last bitshifts with zoom-levels that were forgotten
truelight
parents: 6643
diff changeset
   521
	_screen.zoom = ZOOM_LVL_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   523
	/* restore saved music volume */
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   524
	_music_driver->SetVolume(msf.music_vol);
3678
696a32fc8a5d (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   525
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   526
	NetworkStartUp(); // initialize network-core
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   527
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   528
#if defined(ENABLE_NETWORK)
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   529
	if (debuglog_conn != NULL && _network_available) {
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   530
		const char *not_used = NULL;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   531
		const char *port = NULL;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   532
		uint16 rport;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   533
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   534
		rport = NETWORK_DEFAULT_DEBUGLOG_PORT;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   535
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   536
		ParseConnectionString(&not_used, &port, debuglog_conn);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   537
		if (port != NULL) rport = atoi(port);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   538
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   539
		NetworkStartDebugLog(debuglog_conn, rport);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   540
	}
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   541
#endif /* ENABLE_NETWORK */
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5890
diff changeset
   542
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   543
	ScanNewGRFFiles();
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   544
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   545
	_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
   546
	ResetGRFConfig(false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   547
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   548
	/* 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
   549
	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
   550
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   551
	/* 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
   552
	if (_switch_mode != SM_NONE) {
5024
5e98bf731469 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   553
		_opt = _opt_newgame;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   554
		UpdatePatches();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   555
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   556
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   557
	/* initialize the ingame console */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   558
	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
   559
	_cursor.in_window = true;
1246
eb66ff34348f (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1243
diff changeset
   560
	InitializeGUI();
644
cd687cdec701 (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents: 630
diff changeset
   561
	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
   562
2828
342f02f7c0d4 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   563
	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
   564
	WaitTillGeneratedWorld();
1268
bcbbc18f5c3e (svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents: 1267
diff changeset
   565
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   566
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   567
	if (network && _network_available) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   568
		if (network_conn != NULL) {
1329
6988419aa6f0 (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   569
			const char *port = NULL;
6988419aa6f0 (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   570
			const char *player = NULL;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   571
			uint16 rport;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   572
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   573
			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
   574
			_network_playas = PLAYER_NEW_COMPANY;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   575
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   576
			ParseConnectionString(&player, &port, network_conn);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   577
4861
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   578
			if (player != NULL) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   579
				_network_playas = (PlayerID)atoi(player);
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   580
4880
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   581
				if (_network_playas != PLAYER_SPECTATOR) {
aac84a9dcd03 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   582
					_network_playas--;
4878
4d4f76a898fd (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   583
					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
   584
				}
4861
2119f5d46e41 (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   585
			}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   586
			if (port != NULL) rport = atoi(port);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   587
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   588
			LoadIntroGame();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   589
			_switch_mode = SM_NONE;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   590
			NetworkClientConnectGame(network_conn, rport);
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1105
diff changeset
   591
		}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   592
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   593
#endif /* ENABLE_NETWORK */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   594
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   595
	_video_driver->MainLoop();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   596
2285
410dedcf46d1 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2234
diff changeset
   597
	WaitTillSaved();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   598
	IConsoleFree();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   600
	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
   601
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   602
	_video_driver->Stop();
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   603
	_music_driver->Stop();
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7152
diff changeset
   604
	_sound_driver->Stop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
5507
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   606
	/* only save config if we have to */
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   607
	if (save_config) {
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   608
		SaveToConfig();
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   609
		SaveToHighScore();
02ba56cb4272 (svn r7801) -Feature: add command line option to prevent saving of highscore and configuration on exit and a console command to manually initiate a configuration save (Aloysha).
rubidium
parents: 5475
diff changeset
   610
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
5659
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   612
	/* Reset windowing system and free config file */
573700347887 (svn r8119) -Fix (r8101): Uninitializing windows should be called before freeing dynamic variables as windows could use those variables during cleanup (eg WE_DESTROY calling GetStation(w->window_number).
Darkvater
parents: 5652
diff changeset
   613
	UnInitializeGame();
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   614
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   615
	/* stop the AI */
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   616
	AI_Uninitialize();
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   617
1036
8a82ce28b724 (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   618
	/* 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
   619
	FioCloseAll();
8a82ce28b724 (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   620
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   624
void HandleExitGameRequest()
4548
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   625
{
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   626
	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
   627
		_exit_game = true;
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   628
	} else if (_patches.autosave_on_exit) {
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   629
		DoExitSave();
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   630
		_exit_game = true;
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   631
	} else {
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   632
		AskExitGame();
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   633
	}
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   634
}
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   635
6165e12570bf (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   636
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
   637
/** 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
   638
 * 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
   639
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
   640
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   641
static inline void OTTD_ReleaseMutex() {_message = MSG_OTTD_NO_MESSAGE;}
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   642
static inline ThreadMsg OTTD_PollThreadEvent() {return _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
   643
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
   644
/** 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
   645
 * 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
   646
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
   647
{
2383
7589e75b873a (svn r2909) Game would hang where the autosave_on_exit was activated.
Darkvater
parents: 2380
diff changeset
   648
	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
   649
	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
   650
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
   651
	_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
   652
}
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
   653
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
   654
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
   655
/** 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
   656
 * @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
   657
 */
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   658
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
   659
{
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
   660
	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
   661
		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
   662
		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
   663
		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
   664
	}
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
   665
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
   666
	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
   667
}
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
   668
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
static void ShowScreenshotResult(bool b)
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
	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
   672
		SetDParamStr(0, _screenshot_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
		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
   674
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
		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
   676
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   680
static void MakeNewGameDone()
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   681
{
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   682
	/* 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
   683
	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
   684
		SetLocalPlayer(PLAYER_SPECTATOR);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   685
		return;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   686
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   687
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   688
	/* Create a single player */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   689
	DoStartupNewPlayer(false);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   690
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   691
	SetLocalPlayer(PLAYER_FIRST);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
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);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   694
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   695
	SettingsDisableElrail(_patches.disable_elrails);
7064
81d35e1f3e37 (svn r10329) -Feature [FS#812]: (patch) option to select the "default" rail type when you start a new game or load a game. This is done either static, i.e. rail, electrified rail, monorail and maglev, or dynamic which takes either the first or last available railtype or the railtype that is used most on the map.
rubidium
parents: 7058
diff changeset
   696
	SetDefaultRailGui();
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   697
7998
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   698
	/* We are the server, we start a new player (not dedicated),
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   699
	 * so set the default password *if* needed. */
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   700
	if (_network_server && !StrEmpty(_network_default_company_pass)) {
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   701
		char *password = _network_default_company_pass;
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   702
		NetworkChangeCompanyPassword(1, &password);
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   703
	}
9cf9f9153262 (svn r11556) -Feature: allow setting a default password for new companies in network games.
rubidium
parents: 7981
diff changeset
   704
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   705
	MarkWholeScreenDirty();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   706
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   707
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   708
static void MakeNewGame(bool from_heightmap)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   712
	ResetGRFConfig(true);
6629
eba0ac353e4d (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 6626
diff changeset
   713
	_house_mngr.ResetMapping();
7152
89373fa66dc5 (svn r10426) -Codechange: Activate the reset of industry/tiles mapping upon initialization or new game.
belugas
parents: 7091
diff changeset
   714
	_industile_mngr.ResetMapping();
89373fa66dc5 (svn r10426) -Codechange: Activate the reset of industry/tiles mapping upon initialization or new game.
belugas
parents: 7091
diff changeset
   715
	_industry_mngr.ResetMapping();
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   716
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   717
	GenerateWorldSetCallback(&MakeNewGameDone);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   718
	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
   719
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   721
static void MakeNewEditorWorldDone()
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   722
{
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
   723
	SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   728
static void MakeNewEditorWorld()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	_game_mode = GM_EDITOR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   732
	ResetGRFConfig(true);
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   733
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   734
	GenerateWorldSetCallback(&MakeNewEditorWorldDone);
2828
342f02f7c0d4 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   735
	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
   736
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   738
void StartupPlayers();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   739
void StartupDisasters();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   740
extern void StartupEconomy();
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 115
diff changeset
   741
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   742
/**
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   743
 * Start Scenario starts a new game based on a scenario.
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   744
 * 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
   745
 * This starts a scenario based on your current difficulty settings
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   746
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   747
static void StartScenario()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   751
	/* invalid type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	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
   753
		DEBUG(sl, 0, "Savegame is obsolete or invalid format: '%s'", _file_to_saveload.name);
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   754
		SetDParamStr(0, GetSaveLoadErrorString());
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   755
		ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
		_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   760
	/* Reinitialize windows */
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   761
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
5313
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   765
	ResetGRFConfig(true);
92e5a28568c0 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   766
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   767
	/* Load game */
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   768
	if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, SCENARIO_DIR) != SL_OK) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		LoadIntroGame();
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   770
		SetDParamStr(0, GetSaveLoadErrorString());
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   771
		ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
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
   774
	_opt_ptr = &_opt;
5024
5e98bf731469 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   775
	_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
   776
	_opt.diff_level = _opt_newgame.diff_level;
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   777
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   778
	/* Inititalize data */
3891
ca6cdf4f79bf (svn r4947) - Fix [FS#145]: Starting scenarios did not adhere to local difficulty settings
Darkvater
parents: 3889
diff changeset
   779
	StartupEconomy();
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   780
	StartupPlayers();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   781
	StartupEngines();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   782
	StartupDisasters();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   783
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   784
	SetLocalPlayer(PLAYER_FIRST);
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   785
	_current_player = _local_player;
4661
89c3cbba9846 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4603
diff changeset
   786
	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
   787
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	MarkWholeScreenDirty();
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
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   791
/** Load the specified savegame but on error do different things.
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   792
 * If loading fails due to corrupt savegame, bad version, etc. go back to
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   793
 * a previous correct state. In the menu for example load the intro game again.
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   794
 * @param filename file to be loaded
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   795
 * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   796
 * @param newgm switch to this mode of loading fails due to some unknown error
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   797
 * @param subdir default directory to look for filename, set to 0 if not needed */
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   798
bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	byte ogm = _game_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	_game_mode = newgm;
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   803
	assert(mode == SL_LOAD || mode == SL_OLD_LOAD);
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   804
	switch (SaveOrLoad(filename, mode, subdir)) {
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   805
		case SL_OK: return true;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   806
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   807
		case SL_REINIT:
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   808
			switch (ogm) {
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   809
				case GM_MENU:   LoadIntroGame();      break;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   810
				case GM_EDITOR: MakeNewEditorWorld(); break;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   811
				default:        MakeNewGame(false);   break;
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   812
			}
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   813
			return false;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   814
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   815
		default:
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   816
			_game_mode = ogm;
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   817
			return false;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   818
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   821
void SwitchMode(int new_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   823
#ifdef ENABLE_NETWORK
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   824
	/* If we are saving something, the network stays in his current state */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   825
	if (new_mode != SM_SAVE) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   826
		/* If the network is active, make it not-active */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   827
		if (_networking) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   828
			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
   829
				NetworkReboot();
5619
9f5a7152403a (svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents: 5609
diff changeset
   830
				NetworkUDPCloseAll();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   831
			} else {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   832
				NetworkDisconnect();
5619
9f5a7152403a (svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents: 5609
diff changeset
   833
				NetworkUDPCloseAll();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   834
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   835
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   836
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   837
		/* If we are a server, we restart the server */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   838
		if (_is_network_server) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   839
			/* But not if we are going to the menu */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   840
			if (new_mode != SM_MENU) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   841
				NetworkServerStart();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   842
			} else {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   843
				/* This client no longer wants to be a network-server */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   844
				_is_network_server = false;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   845
			}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   846
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   847
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   848
#endif /* ENABLE_NETWORK */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   849
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   850
	switch (new_mode) {
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   851
	case SM_EDITOR: /* Switch to scenario editor */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		MakeNewEditorWorld();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   855
	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
   856
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   857
		if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   858
			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
   859
		}
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   860
#endif /* ENABLE_NETWORK */
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   861
		MakeNewGame(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   864
	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
   865
#ifdef ENABLE_NETWORK
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   866
		if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   867
			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
   868
		}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   869
#endif /* ENABLE_NETWORK */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   870
		StartScenario();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   871
		break;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   872
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   873
	case SM_LOAD: { /* Load game, Play Scenario */
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   874
		_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
   875
		ResetGRFConfig(true);
8012
5faf4ff3b4d2 (svn r11572) -Fix [FS#1494]: reinitialise windows system before loading a savegame
glx
parents: 7998
diff changeset
   876
		ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
6935
0a2a174d3f6a (svn r10188) -Codechange: make it a little easier to load a savegame from the console:
rubidium
parents: 6929
diff changeset
   878
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
942
75270ad564be (svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents: 929
diff changeset
   879
			LoadIntroGame();
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   880
			SetDParamStr(0, GetSaveLoadErrorString());
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   881
			ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
		} 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
   883
			/* 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
   884
			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   885
			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
8065
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8063
diff changeset
   886
			/* Decrease pause counter (was increased from opening load dialog) */
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8063
diff changeset
   887
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   888
#ifdef ENABLE_NETWORK
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   889
			if (_network_server) {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   890
				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
   891
			}
630
3eb6abf08860 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   892
#endif /* ENABLE_NETWORK */
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
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   897
	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
   898
#ifdef ENABLE_NETWORK
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   899
		if (_network_server) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   900
			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
   901
		}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   902
#endif /* ENABLE_NETWORK */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   903
		MakeNewGame(true);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   904
		break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   905
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   906
	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
   907
		SetLocalPlayer(OWNER_NONE);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   908
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   909
		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
   910
		MarkWholeScreenDirty();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   911
		break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   912
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   913
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
6935
0a2a174d3f6a (svn r10188) -Codechange: make it a little easier to load a savegame from the console:
rubidium
parents: 6929
diff changeset
   914
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   915
			_opt_ptr = &_opt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
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
   917
			SetLocalPlayer(OWNER_NONE);
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
   918
			_patches_newgame.starting_year = _cur_year;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   919
		} else {
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   920
			SetDParamStr(0, GetSaveLoadErrorString());
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   921
			ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   922
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		break;
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
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   926
	case SM_MENU: /* Switch to game intro menu */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
		LoadIntroGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   930
	case SM_SAVE: /* Save game */
8065
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8063
diff changeset
   931
		/* Make network saved games on pause compatible to singleplayer */
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8063
diff changeset
   932
		if (_networking && _pause_game == 1) _pause_game = 2;
6935
0a2a174d3f6a (svn r10188) -Codechange: make it a little easier to load a savegame from the console:
rubidium
parents: 6929
diff changeset
   933
		if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   934
			SetDParamStr(0, GetSaveLoadErrorString());
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
   935
			ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   936
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
			DeleteWindowById(WC_SAVELOAD, 0);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   938
		}
8065
605375063266 (svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents: 8063
diff changeset
   939
		if (_networking && _pause_game == 2) _pause_game = 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   942
	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
   943
		SetLocalPlayer(OWNER_NONE);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   944
		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   945
		/* XXX: set date */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   949
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   950
	if (_switch_mode_errorstr != INVALID_STRING_ID) {
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   951
		ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   952
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   956
/* State controlling game loop.
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   957
 * The state must not be changed from anywhere
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   958
 * but here.
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   959
 * That check is enforced in DoCommand. */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   960
void StateGameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
{
7609
b70ffc13652a (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium
parents: 7567
diff changeset
   962
	ClearStorageChanges(false);
b70ffc13652a (svn r11138) -Codechange: prepare some subsystems for persistent storage for NewGRFs.
rubidium
parents: 7567
diff changeset
   963
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   964
	/* dont execute the state loop during pause */
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6229
diff changeset
   965
	if (_pause_game) return;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   966
	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
   967
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	if (_game_mode == GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
		NewsLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
	} else {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   975
		/* All these actions has to be done from OWNER_NONE
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
   976
		 *  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
   977
		PlayerID p = _current_player;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   978
		_current_player = OWNER_NONE;
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   979
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
		AnimateAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
		IncreaseDate();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
2395
d1629f64d157 (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   986
		AI_RunGameLoop();
0
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
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		NewsLoop();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   990
		_current_player = p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   994
/** Create an autosave. The default name is "autosave#.sav". However with
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   995
 * the patch setting 'keep_all_autosave' the name defaults to company-name + date */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   996
static void DoAutosave()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
{
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
   998
	char buf[MAX_PATH];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   999
5977
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1000
#if defined(PSP)
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1001
	/* Autosaving in networking is too time expensive for the PSP */
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1002
	if (_networking)
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1003
		return;
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1004
#endif /* PSP */
3419c6dfa9ec (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 5959
diff changeset
  1005
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4840
diff changeset
  1006
	if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7036
diff changeset
  1007
		SetDParam(0, _local_player);
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7036
diff changeset
  1008
		SetDParam(1, _date);
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1009
		GetString(buf, STR_4004, lastof(buf));
7414
a5959e1de91b (svn r10807) -Fix [FS#1108]: keep_all_autosaves always got ".sav" as filename, which basically means that it only kept the last autosave.
rubidium
parents: 7408
diff changeset
  1010
		ttd_strlcat(buf, ".sav", lengthof(buf));
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1011
	} else {
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1012
		/* generate a savegame name and number according to _patches.max_num_autosaves */
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1013
		snprintf(buf, sizeof(buf), "autosave%d.sav", _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
  1014
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1015
		if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5376
diff changeset
  1018
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6928
diff changeset
  1019
	if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
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
  1023
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
  1024
{
4536
d532b2611952 (svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents: 4502
diff changeset
  1025
	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
  1026
		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
  1027
		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
  1028
8082
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8065
diff changeset
  1029
		WP(w, vp_d).dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
63240e1bd6cc (svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents: 8065
diff changeset
  1030
		WP(w, vp_d).dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
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
  1031
	}
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
  1032
}
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1033
/**
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1034
 * Describes all the different arrow key combinations the game allows
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1035
 * when it is in scrolling mode.
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1036
 * The real arrow keys are bitwise numbered as
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1037
 * 1 = left
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1038
 * 2 = up
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1039
 * 4 = right
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1040
 * 8 = down
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1041
 */
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
  1042
static const int8 scrollamt[16][2] = {
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1043
	{ 0,  0}, ///<  no key specified
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1044
	{-2,  0}, ///<  1 : left
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1045
	{ 0, -2}, ///<  2 : up
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1046
	{-2, -1}, ///<  3 : left  + up
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1047
	{ 2,  0}, ///<  4 : right
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1048
	{ 0,  0}, ///<  5 : left  + right = nothing
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1049
	{ 2, -1}, ///<  6 : right + up
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1050
	{ 0, -2}, ///<  7 : right + left  + up = up
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1051
	{ 0  ,2}, ///<  8 : down
8063
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1052
	{-2  ,1}, ///<  9 : down  + left
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1053
	{ 0,  0}, ///< 10 : down  + up    = nothing
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1054
	{-2,  0}, ///< 11 : left  + up    +  down = left
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1055
	{ 2,  1}, ///< 12 : down  + right
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1056
	{ 0,  2}, ///< 13 : left  + right +  down = down
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1057
	{ 2,  0}, ///< 14 : right + up    +  down = right
d3fa4e88f087 (svn r11624) -Fix[FS#1530]: An error in the translation of bitset to scroll directions made it so that up-down-right arrow keys did scrolled up, while it should have scrolled right instead. It was initially interpreted as left-right-up.
belugas
parents: 8057
diff changeset
  1058
	{ 0,  0}, ///< 15 : left  + up    +  right + down  = nothing
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
  1059
};
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
  1060
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1061
static void HandleKeyScrolling()
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
  1062
{
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
  1063
	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
  1064
		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
  1065
		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
  1066
	}
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
  1067
}
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
  1068
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1069
void GameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
{
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
  1071
	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
  1072
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
  1073
	if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1075
	/* autosave game? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	if (_do_autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
		_do_autosave = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
		DoAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		RedrawAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1082
	/* handle scrolling of the main window */
4502
02543104c12a (svn r6287) -Codechange: Remove a redundant check
tron
parents: 4383
diff changeset
  1083
	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
  1084
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1085
	/* make a screenshot? */
4184
541f819f2125 (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4171
diff changeset
  1086
	if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1088
	/* switch game mode? */
3024
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1089
	if (_switch_mode != SM_NONE) {
eddcb6307855 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1090
		SwitchMode(_switch_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
		_switch_mode = SM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	IncreaseSpriteLRU();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	InteractiveRandom();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1097
	if (_scroller_click_timeout > 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
		_scroller_click_timeout -= 3;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1099
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		_scroller_click_timeout = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1101
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	_caret_timer += 3;
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7012
diff changeset
  1104
	_palette_animation_counter += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	CursorTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1107
#ifdef ENABLE_NETWORK
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1108
	/* Check for UDP stuff */
4830
668bcb0a30b2 (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
  1109
	if (_network_available) NetworkUDPGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
  1111
	if (_networking && !IsGeneratingWorld()) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1112
		/* Multiplayer */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1113
		NetworkGameLoop();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1114
	} else {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1115
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1116
			/* This means that we want to reconnect to the last host
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1117
			 * We do this here, because it means that the network is really closed */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1118
			NetworkClientConnectGame(_network_last_host, _network_last_port);
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1119
		}
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1120
		/* Singleplayer */
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
  1121
		StateGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1123
#else
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1124
	StateGameLoop();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1125
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1127
	if (!_pause_game && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6229
diff changeset
  1129
	if (!_pause_game || _cheats.build_in_pause.value) MoveAllTextEffects();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
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
  1131
	InputLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
1608
70a3c1a6576d (svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents: 1570
diff changeset
  1133
	MusicLoop();
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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1136
void BeforeSaveGame()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1138
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
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
  1140
	if (w != NULL) {
2643
f1fec6d1559a (svn r3185) const
tron
parents: 2641
diff changeset
  1141
		_saved_scrollpos_x = WP(w, const vp_d).scrollpos_x;
f1fec6d1559a (svn r3185) const
tron
parents: 2641
diff changeset
  1142
		_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
  1143
		_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
  1144
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1147
static void ConvertTownOwner()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1149
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
863
6a1444534f62 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 861
diff changeset
  1151
	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
  1152
		switch (GetTileType(tile)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1153
			case MP_ROAD:
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1154
				if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m4, 7)) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1155
					_m[tile].m4 = OWNER_TOWN;
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
  1156
				}
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
  1157
				/* FALLTHROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
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
  1159
			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
  1160
				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
  1161
				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
  1162
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
  1163
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1168
/* before savegame version 4, the name of the company determined if it existed */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1169
static void CheckIsPlayerActive()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1171
	Player *p;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1172
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	FOR_ALL_PLAYERS(p) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1174
		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
  1175
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1178
/* since savegame version 4.1, exclusive transport rights are stored at towns */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1179
static void UpdateExclusiveRights()
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1180
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1181
	Town *t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1182
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1183
	FOR_ALL_TOWNS(t) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1184
		t->exclusivity = INVALID_PLAYER;
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1185
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1186
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  1187
	/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1188
	 *   could be implemented this way:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1189
	 * 1.) Go through all stations
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1190
	 *     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
  1191
	 *     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
  1192
	 * 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
  1193
	 *     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
  1194
	 */
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1195
}
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1196
2756
52f8927b9542 (svn r3301) One more static
tron
parents: 2754
diff changeset
  1197
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
  1198
	 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
  1199
	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
  1200
	 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
  1201
	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
  1202
	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
  1203
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1204
/* since savegame version 4.2 the currencies are arranged differently */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1205
static void 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
  1206
{
768
c833f6f2742d (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
  1207
	_opt.currency = convert_currency[_opt.currency];
762
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
  1208
}
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
  1209
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
  1210
/* 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
  1211
 * 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
  1212
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1213
static void 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
  1214
{
959
e6a3bbda610f (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 950
diff changeset
  1215
	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
  1216
3075
fd64f71655eb (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1217
	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
  1218
	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
  1219
}
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
  1220
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1221
/* since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1222
static void UpdateSignOwner()
1165
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1223
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1224
	Sign *si;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1225
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1226
	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
  1227
}
8fa7d3e235c6 (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1228
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1229
extern void UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1231
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1232
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
  1233
{
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1234
	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
  1235
}
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1236
7981
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1237
/**
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1238
 * Initialization of the windows and several kinds of caches.
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1239
 * This is not done directly in AfterLoadGame because these
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1240
 * functions require that all saveload conversions have been
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1241
 * done. As people tend to add savegame conversion stuff after
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1242
 * the intialization of the windows and caches quite some bugs
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1243
 * had been made.
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1244
 * Moving this out of there is both cleaner and less bug-prone.
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1245
 *
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1246
 * @return true if everything went according to plan, otherwise false.
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1247
 */
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1248
static bool InitializeWindowsAndCaches()
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1249
{
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1250
	/* Initialize windows */
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1251
	ResetWindowSystem();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1252
	SetupColorsAndInitialWindow();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1253
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1254
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1255
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1256
	WP(w, vp_d).scrollpos_x = _saved_scrollpos_x;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1257
	WP(w, vp_d).scrollpos_y = _saved_scrollpos_y;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1258
	WP(w, vp_d).dest_scrollpos_x = _saved_scrollpos_x;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1259
	WP(w, vp_d).dest_scrollpos_y = _saved_scrollpos_y;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1260
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1261
	ViewPort *vp = w->viewport;
8095
f834186120af (svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents: 8088
diff changeset
  1262
	vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
7981
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1263
	vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1264
	vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1265
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1266
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1267
	MarkWholeScreenDirty();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1268
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1269
	/* Update coordinates of the signs. */
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1270
	UpdateAllStationVirtCoord();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1271
	UpdateAllSignVirtCoords();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1272
	UpdateAllTownVirtCoords();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1273
	UpdateAllWaypointSigns();
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1274
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1275
	/* Recalculate */
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1276
	Group *g;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1277
	FOR_ALL_GROUPS(g) {
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1278
		const Vehicle *v;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1279
		FOR_ALL_VEHICLES(v) {
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1280
			if (!IsEngineCountable(v)) continue;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1281
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1282
			if (v->group_id != g->index || v->type != g->vehicle_type || v->owner != g->owner) continue;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1283
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1284
			g->num_engines[v->engine_type]++;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1285
		}
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1286
	}
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1287
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1288
	/* Set up the engine count for all players */
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1289
	Player *players[MAX_PLAYERS];
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1290
	const Vehicle *v;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1291
8152
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1292
	for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1293
		players[i] = GetPlayer(i);
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1294
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1295
		/* For each player, verify (while loading a scenario) that the inauguration date is the current year and set it
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1296
		 * accordingly if it is not the case.  No need to set it on players that are not been used already,
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1297
		 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1298
		if (_file_to_saveload.filetype == FT_SCENARIO && players[i]->inaugurated_year != MIN_YEAR)
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1299
			players[i]->inaugurated_year = _cur_year;
ab21de45f8ab (svn r11714) -Fix[FS#1569]: Do not allow player inauguration date on scenarios to be bigger than current year.
belugas
parents: 8151
diff changeset
  1300
	}
7981
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1301
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1302
	FOR_ALL_VEHICLES(v) {
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1303
		if (!IsEngineCountable(v)) continue;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1304
		players[v->owner]->num_engines[v->engine_type]++;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1305
	}
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1306
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1307
	return true;
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1308
}
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  1309
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1310
bool AfterLoadGame()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
{
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1312
	TileIndex map_size = MapSize();
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1313
	Player *p;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
  1314
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1315
	/* 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
  1316
	if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1318
	/* 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
  1319
	if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1320
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1321
	/* 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
  1322
	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
  1323
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1324
	/* from version 6.1 of the savegame, signs have an "owner" */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1325
	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
  1326
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1327
	/* 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
  1328
	    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
  1329
	    (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
  1330
	    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
  1331
	if (CheckSavegameVersionOldStyle(4, 3)) {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1332
		for (TileIndex t = 0; t < map_size; t++) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1333
			if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_PLAYERS) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1334
				SetTileOwner(t, OWNER_WATER);
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1335
			}
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1336
		}
831
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1337
	}
d706427d9e23 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1338
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1339
	/* convert road side to my format. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	if (_opt.road_side) _opt.road_side = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5636
diff changeset
  1342
	/* Check if all NewGRFs are present, we are very strict in MP mode */
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6196
diff changeset
  1343
	GRFListCompatibility gcf_res = IsGoodGRFConfigList();
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
  1344
	if (_networking && gcf_res != GLC_ALL_GOOD) {
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
  1345
		SetSaveLoadError(STR_NETWORK_ERR_CLIENT_NEWGRF_MISMATCH);
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
  1346
		return false;
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
  1347
	}
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5636
diff changeset
  1348
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5636
diff changeset
  1349
	switch (gcf_res) {
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6196
diff changeset
  1350
		case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
8013
82001acdb8d0 (svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents: 8012
diff changeset
  1351
		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; _pause_game = (byte)-1; break;
5652
c26cb37e4ef4 (svn r8111) -Fix r8106: silence warnings
glx
parents: 5647
diff changeset
  1352
		default: break;
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5636
diff changeset
  1353
	}
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1354
5340
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1355
	/* Update current year
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1356
	 * 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
  1357
	SetDate(_date);
8e534cd781cc (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1358
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1359
	/* Load the sprites */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
	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
  1361
	LoadStringWidthTable();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
2814
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1363
	/* 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
  1364
	 * subtype to the new format */
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1365
	if (CheckSavegameVersionOldStyle(17, 1)) ConvertOldMultiheadToNew();
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1366
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
  1367
	/* 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
  1368
	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
  1369
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1370
	/* reinit the landscape variables (landscape might have changed) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
	InitializeLandscapeVariables(true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1372
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1373
	/* Update all vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
	AfterLoadVehicles();
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1375
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1376
	/* Update all waypoints */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1377
	if (CheckSavegameVersion(12)) FixOldWaypoints();
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1378
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1379
	/* 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
  1380
	if (CheckSavegameVersionOldStyle(2, 2)) UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	AfterLoadTown();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1384
	/* make sure there is a town in the game */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1385
	if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
7036
f1e26f21aa08 (svn r10300) -Fix [FS#917]: give a better explanation why the loading of a savegame failed and do not crash on loading savegames that were altered by patches or branches.
rubidium
parents: 7018
diff changeset
  1386
		SetSaveLoadError(STR_NO_TOWN_IN_SCENARIO);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1390
	/* in version 4.1 of the savegame, is_active was introduced to determine
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1391
	 * 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
  1392
	if (CheckSavegameVersionOldStyle(4, 1)) CheckIsPlayerActive();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1393
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1394
	/* the void tiles on the southern border used to belong to a wrong class (pre 4.3). */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1395
	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
  1396
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1397
	/* If Load Scenario / New (Scenario) Game is used,
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1398
	 *  a player does not exist yet. So create one here.
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1399
	 * 1 exeption: network-games. Those can have 0 players
6574
d286beed97ae (svn r9785) -Fix (r942, FS#765): only non dedicated servers can't have 0 players
glx
parents: 6560
diff changeset
  1400
	 *   But this exeption is not true for non dedicated network_servers! */
d286beed97ae (svn r9785) -Fix (r942, FS#765): only non dedicated servers can't have 0 players
glx
parents: 6560
diff changeset
  1401
	if (!_players[0].is_active && (!_networking || (_networking && _network_server && !_network_dedicated)))
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1402
		DoStartupNewPlayer(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1404
	if (CheckSavegameVersion(72)) {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1405
		/* Locks/shiplifts in very old savegames had OWNER_WATER as owner */
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1406
		for (TileIndex t = 0; t < MapSize(); t++) {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1407
			switch (GetTileType(t)) {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1408
				default: break;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1409
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1410
				case MP_WATER:
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1411
					if (GetWaterTileType(t) == WATER_TILE_LOCK && GetTileOwner(t) == OWNER_WATER) SetTileOwner(t, OWNER_NONE);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1412
					break;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1413
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1414
				case MP_STATION: {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  1415
					if (HasBit(_m[t].m6, 3)) SetBit(_m[t].m6, 2);
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1416
					StationGfx gfx = GetStationGfx(t);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1417
					StationType st;
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1418
					if (       IsInsideMM(gfx,   0,   8)) { // Railway station
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1419
						st = STATION_RAIL;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1420
						SetStationGfx(t, gfx - 0);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1421
					} else if (IsInsideMM(gfx,   8,  67)) { // Airport
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1422
						st = STATION_AIRPORT;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1423
						SetStationGfx(t, gfx - 8);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1424
					} else if (IsInsideMM(gfx,  67,  71)) { // Truck
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1425
						st = STATION_TRUCK;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1426
						SetStationGfx(t, gfx - 67);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1427
					} else if (IsInsideMM(gfx,  71,  75)) { // Bus
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1428
						st = STATION_BUS;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1429
						SetStationGfx(t, gfx - 71);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1430
					} else if (gfx == 75) {                    // Oil rig
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1431
						st = STATION_OILRIG;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1432
						SetStationGfx(t, gfx - 75);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1433
					} else if (IsInsideMM(gfx,  76,  82)) { // Dock
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1434
						st = STATION_DOCK;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1435
						SetStationGfx(t, gfx - 76);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1436
					} else if (gfx == 82) {                    // Buoy
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1437
						st = STATION_BUOY;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1438
						SetStationGfx(t, gfx - 82);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1439
					} else if (IsInsideMM(gfx,  83, 168)) { // Extended airport
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1440
						st = STATION_AIRPORT;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1441
						SetStationGfx(t, gfx - 83 + 67 - 8);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1442
					} else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1443
						st = STATION_TRUCK;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1444
						SetStationGfx(t, gfx - 168 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7942
diff changeset
  1445
					} else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1446
						st = STATION_BUS;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1447
						SetStationGfx(t, gfx - 170 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1448
					} else {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1449
						return false;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1450
					}
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1451
					SB(_m[t].m6, 3, 3, st);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1452
				} break;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1453
			}
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1454
		}
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1455
	}
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7270
diff changeset
  1456
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1457
	for (TileIndex t = 0; t < map_size; t++) {
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1458
		switch (GetTileType(t)) {
6093
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1459
			case MP_STATION: {
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1460
				Station *st = GetStationByTile(t);
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1461
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1462
				st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1463
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1464
				switch (GetStationType(t)) {
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1465
					case STATION_TRUCK:
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1466
					case STATION_BUS:
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1467
						if (CheckSavegameVersion(6)) {
6093
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1468
							/* From this version on there can be multiple road stops of the
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1469
							 * same type per station. Convert the existing stops to the new
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1470
							 * internal data structure. */
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1471
							RoadStop *rs = new RoadStop(t);
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1472
							if (rs == NULL) error("Too many road stops in savegame");
5879
b3413b837d21 (svn r8477) -Fix
tron
parents: 5848
diff changeset
  1473
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1474
							RoadStop **head =
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1475
								IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1476
							*head = rs;
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1477
						}
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1478
						break;
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1479
5884
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1480
					case STATION_OILRIG: {
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1481
						/* Very old savegames sometimes have phantom oil rigs, i.e.
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1482
						 * an oil rig which got shut down, but not completly removed from
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1483
						 * the map
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1484
						 */
7740
b87fe6440e5a (svn r11277) -Fix (r8498): the check for ghost station (on water industries) always removed station for non-oilrig
glx
parents: 7739
diff changeset
  1485
						TileIndex t1 = TILE_ADDXY(t, 0, 1);
5886
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1486
						if (IsTileType(t1, MP_INDUSTRY) &&
7740
b87fe6440e5a (svn r11277) -Fix (r8498): the check for ghost station (on water industries) always removed station for non-oilrig
glx
parents: 7739
diff changeset
  1487
								GetIndustryGfx(t1) == GFX_OILRIG_1) {
5886
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1488
							/* The internal encoding of oil rigs was changed twice.
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1489
							 * It was 3 (till 2.2) and later 5 (till 5.1).
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1490
							 * Setting it unconditionally does not hurt.
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1491
							 */
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1492
							GetStationByTile(t)->airport_type = AT_OILRIG;
10263c6c4026 (svn r8498) -Fix
tron
parents: 5885
diff changeset
  1493
						} else {
5884
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1494
							DeleteOilRig(t);
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1495
						}
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1496
						break;
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1497
					}
0c9a9c61ca76 (svn r8485) -Fix
tron
parents: 5880
diff changeset
  1498
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1499
					default: break;
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1500
				}
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1501
				break;
6093
d760850df38d (svn r8828) -Fix
tron
parents: 6000
diff changeset
  1502
			}
5880
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1503
702273c0850c (svn r8478) -Fix
tron
parents: 5879
diff changeset
  1504
			default: break;
5879
b3413b837d21 (svn r8477) -Fix
tron
parents: 5848
diff changeset
  1505
		}
b3413b837d21 (svn r8477) -Fix
tron
parents: 5848
diff changeset
  1506
	}
b3413b837d21 (svn r8477) -Fix
tron
parents: 5848
diff changeset
  1507
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1508
	/* 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
  1509
	 *  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
  1510
	 *  all about ;) */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1511
	if (CheckSavegameVersionOldStyle(6, 1)) {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1512
		for (TileIndex t = 0; t < map_size; t++) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1513
			switch (GetTileType(t)) {
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
  1514
				case MP_HOUSE:
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1515
					_m[t].m4 = _m[t].m2;
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1516
					SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
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
  1517
					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
  1518
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1519
				case MP_ROAD:
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1520
					_m[t].m4 |= (_m[t].m2 << 4);
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1521
					if (IsTileOwner(t, OWNER_TOWN)) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1522
						SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
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
  1523
					} else {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1524
						SetTownIndex(t, 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
  1525
					}
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
  1526
					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
  1527
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
  1528
				default: break;
1264
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1529
			}
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1530
		}
1264
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1531
	}
acebb2b01e32 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1532
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1533
	/* 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
  1534
	 *  before that. */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1535
	if (CheckSavegameVersion(9)) {
1377
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1536
		Town *t;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1537
		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
  1538
	}
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1539
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1540
	/* 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
  1541
	 *  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
  1542
	if (CheckSavegameVersion(16)) {
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1543
		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
  1544
			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
  1545
			p->engine_renew        = false;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1546
			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
  1547
			p->engine_renew_money  = 100000;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1548
		}
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
  1549
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
  1550
		/* 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
  1551
		 * 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
  1552
		 * 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
  1553
		 * 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
  1554
		 * 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
  1555
		 */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1556
		if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) {
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1557
			p = GetPlayer(PLAYER_FIRST);
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
  1558
			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
  1559
			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
  1560
			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
  1561
		}
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1562
	}
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1563
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1564
	if (CheckSavegameVersion(48)) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1565
		for (TileIndex t = 0; t < map_size; t++) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1566
			switch (GetTileType(t)) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1567
				case MP_RAILWAY:
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1568
					if (IsPlainRailTile(t)) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1569
						/* Swap ground type and signal type for plain rail tiles, so the
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1570
						 * ground type uses the same bits as for depots and waypoints. */
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1571
						uint tmp = GB(_m[t].m4, 0, 4);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1572
						SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1573
						SB(_m[t].m2, 0, 4, tmp);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1574
					} else if (HasBit(_m[t].m5, 2)) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1575
						/* Split waypoint and depot rail type and remove the subtype. */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1576
						ClrBit(_m[t].m5, 2);
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1577
						ClrBit(_m[t].m5, 6);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1578
					}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1579
					break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1580
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1581
				case MP_ROAD:
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1582
					/* Swap m3 and m4, so the track type for rail crossings is the
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1583
					 * same as for normal rail. */
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1584
					Swap(_m[t].m3, _m[t].m4);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1585
					break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1586
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1587
				default: break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1588
			}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1589
		}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1590
	}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1591
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1592
	if (CheckSavegameVersion(61)) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1593
		/* Added the RoadType */
6738
522ddf421dae (svn r9971) -Fix (r9892, r9958): loading of post-'bridges over "everything"' messed with the railtype of bridges.
rubidium
parents: 6730
diff changeset
  1594
		bool old_bridge = CheckSavegameVersion(42);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1595
		for (TileIndex t = 0; t < map_size; t++) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1596
			switch(GetTileType(t)) {
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1597
				case MP_ROAD:
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1598
					SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1599
					switch (GetRoadTileType(t)) {
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1600
						default: NOT_REACHED();
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1601
						case ROAD_TILE_NORMAL:
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1602
							SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1603
							SB(_m[t].m4, 4, 4, 0);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1604
							SB(_m[t].m6, 2, 4, 0);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1605
							break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1606
						case ROAD_TILE_CROSSING:
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1607
							SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1608
							break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1609
						case ROAD_TILE_DEPOT:    break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1610
					}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1611
					SetRoadTypes(t, ROADTYPES_ROAD);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1612
					break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1613
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1614
				case MP_STATION:
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1615
					if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1616
					break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1617
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1618
				case MP_TUNNELBRIDGE:
6738
522ddf421dae (svn r9971) -Fix (r9892, r9958): loading of post-'bridges over "everything"' messed with the railtype of bridges.
rubidium
parents: 6730
diff changeset
  1619
					/* Middle part of "old" bridges */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1620
					if (old_bridge && IsBridgeTile(t) && HasBit(_m[t].m5, 6)) break;
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8082
diff changeset
  1621
					if ((IsTunnel(t) ? GetTunnelBridgeTransportType(t) : (old_bridge ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t))) == TRANSPORT_ROAD) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1622
						SetRoadTypes(t, ROADTYPES_ROAD);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1623
					}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1624
					break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1625
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1626
				default: break;
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1627
			}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1628
		}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1629
	}
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1630
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1631
	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
  1632
		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
  1633
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1634
		for (TileIndex t = 0; t < map_size; t++) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1635
			if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1636
			if (IsBridgeTile(t)) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1637
				if (HasBit(_m[t].m5, 6)) { // middle part
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1638
					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1639
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1640
					if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1641
						if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1642
							MakeRailNormal(
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1643
								t,
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1644
								GetTileOwner(t),
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1645
								axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1646
								GetRailType(t)
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1647
							);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1648
						} else {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1649
							TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, (uint)-1)->index : 0;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1650
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1651
							MakeRoadNormal(
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1652
								t,
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1653
								axis == AXIS_X ? ROAD_Y : ROAD_X,
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1654
								ROADTYPES_ROAD,
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1655
								town,
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6654
diff changeset
  1656
								GetTileOwner(t), OWNER_NONE, OWNER_NONE
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1657
							);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1658
						}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1659
					} else {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1660
						if (GB(_m[t].m5, 3, 2) == 0) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1661
							MakeClear(t, CLEAR_GRASS, 3);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1662
						} else {
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  1663
							MakeCanal(t, (GetTileOwner(t) == OWNER_WATER) ? OWNER_NONE : GetTileOwner(t));
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1664
						}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1665
					}
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1666
					SetBridgeMiddle(t, axis);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1667
				} else { // ramp
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1668
					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1669
					uint north_south = GB(_m[t].m5, 5, 1);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1670
					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1671
					TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1672
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1673
					_m[t].m5 = 1 << 7 | type << 2 | dir;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1674
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1675
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1676
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1677
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1678
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1679
			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1680
			if (IsBridgeTile(v->tile)) {
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8082
diff changeset
  1681
				DiagDirection dir = GetTunnelBridgeDirection(v->tile);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1682
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1683
				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
  1684
				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
  1685
					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
  1686
					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
  1687
					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
  1688
					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
  1689
					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
  1690
				}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1691
			} 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
  1692
				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
  1693
			} else {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1694
				continue;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1695
			}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1696
			if (v->type == VEH_TRAIN) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1697
				v->u.rail.track = TRACK_BIT_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1698
			} else {
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5986
diff changeset
  1699
				v->u.road.state = RVSB_WORMHOLE;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1700
			}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1701
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1702
	}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
  1703
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
  1704
	/* 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
  1705
	if (CheckSavegameVersion(24)) {
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1706
		Vehicle *v;
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1707
		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
  1708
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
  1709
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1710
			if (v->type == VEH_TRAIN) {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5723
diff changeset
  1711
				RailType rt = RailVehInfo(v->engine_type)->railtype;
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
  1712
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
  1713
				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
  1714
				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
  1715
			}
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
  1716
		}
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
  1717
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
  1718
		/* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1719
		for (TileIndex t = 0; t < map_size; t++) {
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
  1720
			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
  1721
				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
  1722
					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
  1723
					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
  1724
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1725
				case MP_ROAD:
3656
4aecbb417d50 (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1726
					if (IsLevelCrossing(t)) {
6172
e6d7a5b3d63f (svn r8935) -Codechange: unification of track type between road and rail tiles, unification of ground type between normal rail tiles and depots/waypoints and removing the need for RailTileSubType.
rubidium
parents: 6093
diff changeset
  1727
						SetRailType(t, UpdateRailType(GetRailType(t), min_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
  1728
					}
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
  1729
					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
  1730
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
  1731
				case MP_STATION:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1732
					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
  1733
						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
  1734
					}
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
  1735
					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
  1736
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
  1737
				case MP_TUNNELBRIDGE:
8088
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8085
diff changeset
  1738
					if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
92fca5b09665 (svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents: 8085
diff changeset
  1739
						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
  1740
					}
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
  1741
					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
  1742
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
  1743
				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
  1744
					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
  1745
			}
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
  1746
		}
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
  1747
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
  1748
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1749
			if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(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
  1750
		}
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
  1751
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
  1752
	}
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
  1753
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
  1754
	/* 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
  1755
	 * 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
  1756
	 * to false */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1757
	if (CheckSavegameVersionOldStyle(16, 1)) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1758
		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
  1759
	}
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1760
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
  1761
	/* 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
  1762
	 * 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
  1763
	 * 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
  1764
	 * waypoint struct. */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1765
	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
  1766
		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
  1767
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
  1768
		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
  1769
			if (wp->deleted == 0) {
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1770
				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
  1771
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1772
				if (HasBit(_m[wp->xy].m3, 4))
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1773
					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
  1774
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1775
				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
  1776
					wp->stat_id = _m[wp->xy].m4 + 1;
6451
e576c71bfc09 (svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents: 6427
diff changeset
  1777
					wp->grfid = statspec->grffile->grfid;
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1778
					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
  1779
				} else {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1780
					/* No custom graphics set, so set to default. */
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
  1781
					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
  1782
					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
  1783
					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
  1784
				}
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
  1785
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1786
				/* Move ground type bits from m2 to m4. */
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
  1787
				_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1788
				/* Store waypoint index in the tile. */
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
  1789
				_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
  1790
			}
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
  1791
		}
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
  1792
	} 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
  1793
		/* 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
  1794
		 * 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
  1795
		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
  1796
	}
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
  1797
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
  1798
	/* 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
  1799
	 *  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
  1800
	if (CheckSavegameVersion(21) && !CheckSavegameVersion(15)) {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1801
		for (TileIndex t = 0; t < map_size; t++) {
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1802
			switch (GetTileType(t)) {
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1803
				case MP_RAILWAY:
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1804
					if (HasSignals(t)) {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1805
						/* convert PBS signals to combo-signals */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1806
						if (HasBit(_m[t].m2, 2)) SetSignalType(t, TRACK_X, 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
  1807
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1808
						/* move the signal variant back */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1809
						SetSignalVariant(t, TRACK_X, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1810
						ClrBit(_m[t].m2, 3);
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1811
					}
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1812
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1813
					/* Clear PBS reservation on track */
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1814
					if (!IsTileDepotType(t, TRANSPORT_RAIL)) {
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1815
						SB(_m[t].m4, 4, 4, 0);
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1816
					} else {
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1817
						ClrBit(_m[t].m3, 6);
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1818
					}
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1819
					break;
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1820
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7272
diff changeset
  1821
				case MP_ROAD: /* Clear PBS reservation on crossing */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1822
					if (IsLevelCrossing(t)) ClrBit(_m[t].m5, 0);
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1823
					break;
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1824
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6333
diff changeset
  1825
				case MP_STATION: /* Clear PBS reservation on station */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1826
					ClrBit(_m[t].m3, 6);
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1827
					break;
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
  1828
5707
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1829
				default: break;
04bf0603c9fd (svn r8184) if cascade -> switch
tron
parents: 5706
diff changeset
  1830
			}
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1831
		}
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
  1832
	}
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
  1833
3121
72fb0554f9f1 (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1834
	if (CheckSavegameVersion(22))  UpdatePatches();
72fb0554f9f1 (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1835
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1836
	if (CheckSavegameVersion(25)) {
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1837
		Vehicle *v;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1838
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1839
			if (v->type == VEH_ROAD) {
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1840
				v->vehstatus &= ~0x40;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1841
				v->u.road.slot = NULL;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1842
				v->u.road.slot_age = 0;
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1843
			}
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1844
		}
5677
92e3ee10d04c (svn r8137) -Fix (FS#551, r4259, r4320): roadstop->num_vehicles was wrong for savegames with version 24 or lower and do not calculate roadstop->num_vehicles when reading the roadstops as the vehicles might not be loaded at that moment.
rubidium
parents: 5659
diff changeset
  1845
	} else {
92e3ee10d04c (svn r8137) -Fix (FS#551, r4259, r4320): roadstop->num_vehicles was wrong for savegames with version 24 or lower and do not calculate roadstop->num_vehicles when reading the roadstops as the vehicles might not be loaded at that moment.
rubidium
parents: 5659
diff changeset
  1846
		Vehicle *v;
92e3ee10d04c (svn r8137) -Fix (FS#551, r4259, r4320): roadstop->num_vehicles was wrong for savegames with version 24 or lower and do not calculate roadstop->num_vehicles when reading the roadstops as the vehicles might not be loaded at that moment.
rubidium
parents: 5659
diff changeset
  1847
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1848
			if (v->type == VEH_ROAD && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++;
5677
92e3ee10d04c (svn r8137) -Fix (FS#551, r4259, r4320): roadstop->num_vehicles was wrong for savegames with version 24 or lower and do not calculate roadstop->num_vehicles when reading the roadstops as the vehicles might not be loaded at that moment.
rubidium
parents: 5659
diff changeset
  1849
		}
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1850
	}
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1851
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
  1852
	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
  1853
		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
  1854
		FOR_ALL_STATIONS(st) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  1855
			st->last_vehicle_type = VEH_INVALID;
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
  1856
		}
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
  1857
	}
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
  1858
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1859
	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
  1860
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
  1861
	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
  1862
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6661
diff changeset
  1863
	FOR_ALL_PLAYERS(p) {
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6661
diff changeset
  1864
		p->avail_railtypes = GetPlayerRailtypes(p->index);
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6661
diff changeset
  1865
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6661
diff changeset
  1866
	}
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1867
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1868
	if (!CheckSavegameVersion(27)) AfterLoadStations();
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1869
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
  1870
	/* 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
  1871
	 * 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
  1872
	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
  1873
		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
  1874
		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
  1875
		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
  1876
		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
  1877
		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
  1878
		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
  1879
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1880
		_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
  1881
		_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
  1882
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1883
		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
  1884
		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
  1885
		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
  1886
		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
  1887
		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
  1888
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1889
		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
  1890
			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
  1891
			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
  1892
		}
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1893
	}
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1894
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
  1895
	/* 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
  1896
	 *  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
  1897
	 *  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
  1898
	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
  1899
		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
  1900
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1901
		for (TileIndex t = 0; t < map_size; t++) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1902
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1903
				MakeClear(t, CLEAR_GRASS, 3);
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
  1904
			}
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1905
		}
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
  1906
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
  1907
		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
  1908
			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
  1909
6757
385cb1bf2ba9 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 6738
diff changeset
  1910
			if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
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
  1911
				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
  1912
			}
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
  1913
		}
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
  1914
	}
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
  1915
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
  1916
	/* 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
  1917
	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
  1918
		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
  1919
		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
  1920
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
  1921
		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
  1922
			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
  1923
			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
  1924
		}
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
  1925
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
  1926
		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
  1927
			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
  1928
			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
  1929
		}
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
  1930
	}
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
  1931
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
  1932
	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
  1933
		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
  1934
	}
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
  1935
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
  1936
	/* 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
  1937
	 * preference of a user, let elrails enabled; it can be disabled manually */
5848
9cd6f1c79ddb (svn r8422) -Fix
tron
parents: 5823
diff changeset
  1938
	if (CheckSavegameVersion(38)) _patches.disable_elrails = false;
9cd6f1c79ddb (svn r8422) -Fix
tron
parents: 5823
diff changeset
  1939
	/* do the same as when elrails were enabled/disabled manually just now */
9cd6f1c79ddb (svn r8422) -Fix
tron
parents: 5823
diff changeset
  1940
	SettingsDisableElrail(_patches.disable_elrails);
7064
81d35e1f3e37 (svn r10329) -Feature [FS#812]: (patch) option to select the "default" rail type when you start a new game or load a game. This is done either static, i.e. rail, electrified rail, monorail and maglev, or dynamic which takes either the first or last available railtype or the railtype that is used most on the map.
rubidium
parents: 7058
diff changeset
  1941
	SetDefaultRailGui();
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  1942
6333
496dba276c2d (svn r9316) -Fix (r9315): Bump the savegame version for the newhouses merge.
maedhros
parents: 6332
diff changeset
  1943
	/* From version 53, the map array was changed for house tiles to allow
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1944
	 * space for newhouses grf features. A new byte, m7, was also added. */
6333
496dba276c2d (svn r9316) -Fix (r9315): Bump the savegame version for the newhouses merge.
maedhros
parents: 6332
diff changeset
  1945
	if (CheckSavegameVersion(53)) {
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1946
		for (TileIndex t = 0; t < map_size; t++) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1947
			if (IsTileType(t, MP_HOUSE)) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1948
				if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1949
					/* Move the construction stage from m3[7..6] to m5[5..4].
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1950
					 * The construction counter does not have to move. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1951
					SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1952
					SB(_m[t].m3, 6, 2, 0);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1953
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1954
					/* The "house is completed" bit is now in m6[2]. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1955
					SetHouseCompleted(t, false);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1956
				} else {
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1957
					/* The "lift has destination" bit has been moved from
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1958
					 * m5[7] to m7[0]. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1959
					SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1960
					ClrBit(_m[t].m5, 7);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1961
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1962
					/* The "lift is moving" bit has been removed, as it does
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1963
					 * the same job as the "lift has destination" bit. */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  1964
					ClrBit(_m[t].m1, 7);
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1965
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1966
					/* The position of the lift goes from m1[7..0] to m6[7..2],
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1967
					 * making m1 totally free, now. The lift position does not
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1968
					 * have to be a full byte since the maximum value is 36. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1969
					SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1970
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1971
					_m[t].m1 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1972
					_m[t].m3 = 0;
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1973
					SetHouseCompleted(t, true);
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1974
				}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1975
			}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1976
		}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1977
	}
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1978
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1979
	/* Count the buildings after updating the map array. */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1980
	AfterLoadCountBuildings();
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  1981
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1982
	if (CheckSavegameVersion(43)) {
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1983
		for (TileIndex t = 0; t < map_size; t++) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1984
			if (IsTileType(t, MP_INDUSTRY)) {
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1985
				switch (GetIndustryGfx(t)) {
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1986
					case GFX_POWERPLANT_SPARKS:
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1987
						SetIndustryAnimationState(t, GB(_m[t].m1, 2, 5));
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1988
						break;
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1989
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1990
					case GFX_OILWELL_ANIMATED_1:
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1991
					case GFX_OILWELL_ANIMATED_2:
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1992
					case GFX_OILWELL_ANIMATED_3:
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1993
						SetIndustryAnimationState(t, GB(_m[t].m1, 0, 2));
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1994
						break;
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1995
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1996
					case GFX_COAL_MINE_TOWER_ANIMATED:
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1997
					case GFX_COPPER_MINE_TOWER_ANIMATED:
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  1998
					case GFX_GOLD_MINE_TOWER_ANIMATED:
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  1999
						 SetIndustryAnimationState(t, _m[t].m1);
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2000
						 break;
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2001
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2002
					default: /* No animation states to change */
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2003
						break;
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2004
				}
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2005
			}
5706
8521a5a71f1a (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5692
diff changeset
  2006
		}
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2007
	}
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5425
diff changeset
  2008
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2009
	if (CheckSavegameVersion(44)) {
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2010
		Vehicle *v;
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2011
		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2012
		 * 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2013
		 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2014
		 * where this situation exists, the cargo-source information is lost. in this case, we set the source
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2015
		 * to the current tile of the vehicle to prevent excessive profits
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2016
		 */
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2017
		FOR_ALL_VEHICLES(v) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2018
			const CargoList::List *packets = v->cargo.Packets();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2019
			for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2020
				CargoPacket *cp = *it;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2021
				cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : v->tile;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2022
				cp->loaded_at_xy = cp->source_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2023
			}
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2024
			v->cargo.InvalidateCache();
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2025
		}
6304
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2026
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2027
		/* Store position of the station where the goods come from, so there
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2028
		 * are no very high payments when stations get removed. However, if the
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2029
		 * station where the goods came from is already removed, the source
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2030
		 * information is lost. In that case we set it to the position of this
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2031
		 * station */
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2032
		Station *st;
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2033
		FOR_ALL_STATIONS(st) {
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2034
			for (CargoID c = 0; c < NUM_CARGO; c++) {
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2035
				GoodsEntry *ge = &st->goods[c];
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2036
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2037
				const CargoList::List *packets = ge->cargo.Packets();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2038
				for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2039
					CargoPacket *cp = *it;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2040
					cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : st->xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2041
					cp->loaded_at_xy = cp->source_xy;
6304
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2042
				}
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2043
			}
141a1149fdea (svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
peter1138
parents: 6259
diff changeset
  2044
		}
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2045
	}
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5677
diff changeset
  2046
5888
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2047
	if (CheckSavegameVersion(45)) {
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2048
		Vehicle *v;
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2049
		/* Originally just the fact that some cargo had been paid for was
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2050
		 * stored to stop people cheating and cashing in several times. This
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2051
		 * wasn't enough though as it was cleared when the vehicle started
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2052
		 * loading again, even if it didn't actually load anything, so now the
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2053
		 * amount of cargo that has been paid for is stored. */
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2054
		FOR_ALL_VEHICLES(v) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2055
			const CargoList::List *packets = v->cargo.Packets();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2056
			for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2057
				CargoPacket *cp = *it;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2058
				cp->paid_for = HasBit(v->vehicle_flags, 2);
5888
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2059
			}
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  2060
			ClrBit(v->vehicle_flags, 2);
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6937
diff changeset
  2061
			v->cargo.InvalidateCache();
5888
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2062
		}
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2063
	}
6fb161a15a3c (svn r8501) -Fix (r7377) [FS#539]: Keep track of how much cargo has been paid for, so that cargo cannot be paid for more than once.
maedhros
parents: 5886
diff changeset
  2064
5986
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2065
	/* Buoys do now store the owner of the previous water tile, which can never
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2066
	 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2067
	if (CheckSavegameVersion(46)) {
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2068
		Station *st;
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2069
		FOR_ALL_STATIONS(st) {
7788
b4cda59c0e5c (svn r11338) -Fix [FS#1359]: water tiles not at sealevel (i.e. canals) should not be owned by water as that signals normal water.
rubidium
parents: 7740
diff changeset
  2070
			if (st->IsBuoy() && IsTileOwner(st->xy, OWNER_NONE) && TileHeight(st->xy) == 0) SetTileOwner(st->xy, OWNER_WATER);
5986
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2071
		}
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2072
	}
6364a078d30c (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 5977
diff changeset
  2073
6193
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2074
	if (CheckSavegameVersion(50)) {
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2075
		Vehicle *v;
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2076
		/* Aircraft units changed from 8 mph to 1 km/h */
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2077
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6257
diff changeset
  2078
			if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) {
6193
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2079
				const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2080
				v->cur_speed *= 129;
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2081
				v->cur_speed /= 10;
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2082
				v->max_speed = avi->max_speed;
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2083
				v->acceleration = avi->acceleration;
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2084
			}
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2085
		}
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2086
	}
6f20de9e4f1b (svn r8973) -Feature/Codechange: Changed the internal unit for aircraft velocities to from 8mph to 1km/h (peter1138), also give aircraft realsitic velocities (so that 1km/h is 1km/h independent of vehicle type) (peter1138). Introduce a flag to reduce aircraft speed in holding patterns to some realistic velocity. Use this flag for the city airport for the time being and make use of the different entry points for this airport type.
celestar
parents: 6190
diff changeset
  2087
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6175
diff changeset
  2088
	if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face);
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6175
diff changeset
  2089
6257
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2090
	if (CheckSavegameVersion(52)) {
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2091
		for (TileIndex t = 0; t < map_size; t++) {
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2092
			if (IsStatueTile(t)) {
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2093
				_m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index;
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2094
			}
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2095
		}
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2096
	}
5e5a864cacf6 (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6247
diff changeset
  2097
6486
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2098
	/* A patch option containing the proportion of towns that grow twice as
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2099
	 * fast was added in version 54. From version 56 this is now saved in the
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2100
	 * town as cities can be built specifically in the scenario editor. */
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2101
	if (CheckSavegameVersion(56)) {
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2102
		Town *t;
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2103
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2104
		FOR_ALL_TOWNS(t) {
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2105
			if (_patches.larger_towns != 0 && (t->index % _patches.larger_towns) == 0) {
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2106
				t->larger_town = true;
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2107
			}
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2108
		}
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2109
	}
7d2ae0a167fb (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents: 6453
diff changeset
  2110
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2111
	if (CheckSavegameVersion(57)) {
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2112
		Vehicle *v;
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2113
		/* Added a FIFO queue of vehicles loading at stations */
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2114
		FOR_ALL_VEHICLES(v) {
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2115
			if ((v->type != VEH_TRAIN || IsFrontEngine(v)) &&  // for all locs
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2116
					!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2117
					v->current_order.type == OT_LOADING) {         // loading
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2118
				GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
6619
feb55b075339 (svn r9839) -Fix: vehicles in old savegames could leave the station because the changed loading algorithm thought it was already finished.
rubidium
parents: 6591
diff changeset
  2119
feb55b075339 (svn r9839) -Fix: vehicles in old savegames could leave the station because the changed loading algorithm thought it was already finished.
rubidium
parents: 6591
diff changeset
  2120
				/* The loading finished flag is *only* set when actually completely
feb55b075339 (svn r9839) -Fix: vehicles in old savegames could leave the station because the changed loading algorithm thought it was already finished.
rubidium
parents: 6591
diff changeset
  2121
				 * finished. Because the vehicle is loading, it is not finished. */
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  2122
				ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2123
			}
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2124
		}
7475
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2125
	} else if (CheckSavegameVersion(59)) {
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2126
		/* For some reason non-loading vehicles could be in the station's loading vehicle list */
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2127
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2128
		Station *st;
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2129
		FOR_ALL_STATIONS(st) {
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2130
			std::list<Vehicle *>::iterator iter;
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2131
			for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2132
				Vehicle *v = *iter;
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2133
				iter++;
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2134
				if (v->current_order.type != OT_LOADING) st->loading_vehicles.remove(v);
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2135
			}
cd87a7db15bf (svn r10982) -Fix [FS#1162]: some old savegames could be in a state that the current game logic does not like; in the list of vehicles loading at a station when the vehicle is not actually at the station.
rubidium
parents: 7414
diff changeset
  2136
		}
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2137
	}
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  2138
6560
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2139
	if (CheckSavegameVersion(58)) {
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2140
		/* patch difficulty number_industries other then zero get bumped to +1
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2141
		 * since a new option (very low at position1) has been added */
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2142
		if (_opt.diff.number_industries > 0) {
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2143
			_opt.diff.number_industries++;
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2144
		}
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2145
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2146
		/* Same goes for number of towns, although no test is needed, just an increment */
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2147
		_opt.diff.number_towns++;
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2148
	}
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6500
diff changeset
  2149
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2150
	if (CheckSavegameVersion(64)) {
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2151
		/* copy the signal type/variant and move signal states bits */
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2152
		for (TileIndex t = 0; t < map_size; t++) {
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2153
			if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2154
				SetSignalStates(t, GB(_m[t].m2, 4, 4));
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2155
				SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2156
				SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  2157
				ClrBit(_m[t].m2, 7);
6770
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2158
			}
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2159
		}
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2160
	}
408585d467f9 (svn r10006) -Fix (FS#362): allow different signal types on one tile
glx
parents: 6757
diff changeset
  2161
7012
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2162
	if (CheckSavegameVersion(69)) {
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2163
		/* In some old savegames a bit was cleared when it should not be cleared */
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2164
		Vehicle *v;
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2165
		FOR_ALL_VEHICLES(v) {
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2166
			if (v->type == VEH_ROAD && (v->u.road.state == 250 || v->u.road.state == 251)) {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2167
				SetBit(v->u.road.state, RVS_IS_STOPPING);
7012
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2168
			}
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2169
		}
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2170
	}
b7bdf660e8d7 (svn r10268) -Fix: some old savegames could have the wrong bits unset (follow up of r10147)
rubidium
parents: 7010
diff changeset
  2171
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2172
	if (CheckSavegameVersion(70)) {
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2173
		/* Added variables to support newindustries */
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2174
		Industry *i;
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2175
		FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2176
	}
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7170
diff changeset
  2177
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2178
	/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2179
	    Replace the owner for those by OWNER_NONE. */
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2180
	if (CheckSavegameVersion(82)) {
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2181
		for (TileIndex t = 0; t < map_size; t++) {
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2182
			if (IsTileType(t, MP_WATER) &&
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2183
					GetWaterTileType(t) == WATER_TILE_CLEAR &&
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2184
					GetTileOwner(t) == OWNER_WATER &&
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2185
					TileHeight(t) != 0) {
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2186
				SetTileOwner(t, OWNER_NONE);
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2187
			}
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2188
		}
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2189
	}
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7710
diff changeset
  2190
8029
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2191
	/*
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2192
	 * Add the 'previous' owner to the ship depots so we can reset it with
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2193
	 * the correct values when it gets destroyed. This prevents that
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2194
	 * someone can remove canals owned by somebody else and it prevents
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2195
	 * making floods using the removal of ship depots.
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2196
	 */
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2197
	if (CheckSavegameVersion(83)) {
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2198
		for (TileIndex t = 0; t < map_size; t++) {
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2199
			if (IsTileType(t, MP_WATER) && IsShipDepot(t)) {
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2200
				_m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2201
			}
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2202
		}
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2203
	}
6cc607fe1d3d (svn r11589) -Fix [FS#1514]: when ship depots got destroyed they always returned to water, even when it should've been canals.
rubidium
parents: 8013
diff changeset
  2204
7515
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2205
	if (CheckSavegameVersion(74)) {
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2206
		Station *st;
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2207
		FOR_ALL_STATIONS(st) {
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2208
			for (CargoID c = 0; c < NUM_CARGO; c++) {
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2209
				st->goods[c].last_speed = 0;
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2210
				if (st->goods[c].cargo.Count() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::PICKUP);
7515
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2211
			}
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2212
		}
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2213
	}
67cd8c519fab (svn r11030) -Revert r11016, Fix [FS#1178]: the way to determine whether a station should get goods was not done properly.
rubidium
parents: 7475
diff changeset
  2214
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2215
	if (CheckSavegameVersion(78)) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2216
		Industry *i;
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2217
		uint j;
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2218
		FOR_ALL_INDUSTRIES(i) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2219
			const IndustrySpec *indsp = GetIndustrySpec(i->type);
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2220
			for (j = 0; j < lengthof(i->produced_cargo); j++) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2221
				i->produced_cargo[j] = indsp->produced_cargo[j];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2222
			}
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2223
			for (j = 0; j < lengthof(i->accepts_cargo); j++) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2224
				i->accepts_cargo[j] = indsp->accepts_cargo[j];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2225
			}
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2226
		}
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7609
diff changeset
  2227
	}
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6629
diff changeset
  2228
7710
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2229
	/* Before version 81, the density of grass was always stored as zero, and
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2230
	 * grassy trees were always drawn fully grassy. Furthermore, trees on rough
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2231
	 * land used to have zero density, now they have full density. Therefore,
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2232
	 * make all grassy/rough land trees have a density of 3. */
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2233
	if (CheckSavegameVersion(81)) {
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2234
		for (TileIndex t = 0; t < map_size; t++) {
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2235
			if (GetTileType(t) == MP_TREES) {
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2236
				TreeGround groundType = GetTreeGround(t);
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2237
				if (groundType != TREE_GROUND_SNOW_DESERT) SetTreeGroundDensity(t, groundType, 3);
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2238
			}
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2239
		}
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2240
	}
777524fbb1fb (svn r11244) -Fix: trees can now be planted on bare land without making it grassy (Csaboka)
truelight
parents: 7645
diff changeset
  2241
8057
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2242
	if (CheckSavegameVersion(84)) {
8155
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2243
		/* Update go to buoy orders because they are just waypoints */
8057
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2244
		Order *order;
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2245
		FOR_ALL_ORDERS(order) {
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2246
			if (order->type == OT_GOTO_STATION && GetStation(order->dest)->IsBuoy()) {
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2247
				order->flags = 0;
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2248
			}
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2249
		}
8155
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2250
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2251
		/* Set all share owners to PLAYER_SPECTATOR for
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2252
		 * 1) all inactive players
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2253
		 *     (when inactive players were stored in the savegame - TTD, TTDP and some
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2254
		 *      *really* old revisions of OTTD; else it is already set in InitializePlayers())
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2255
		 * 2) shares that are owned by inactive players or self
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2256
		 *     (caused by cheating players in earlier revisions) */
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2257
		Player *p;
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2258
		FOR_ALL_PLAYERS(p) {
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2259
			if (!p->is_active) {
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2260
				for (uint i = 0; i < 4; i++) { p->share_owners[i] = PLAYER_SPECTATOR; }
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2261
			} else {
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2262
				for (uint i = 0; i < 4; i++) {
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2263
					PlayerID o = p->share_owners[i];
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2264
					if (o == PLAYER_SPECTATOR) continue;
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2265
					if (!IsValidPlayer(o) || o == p->index || !GetPlayer(o)->is_active) p->share_owners[i] = PLAYER_SPECTATOR;
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2266
				}
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2267
			}
ab1e6353db79 (svn r11717) -Fix [FS#1590]: make sure invalid players have all shares owned by PLAYER_SPECTATOR
smatz
parents: 8152
diff changeset
  2268
		}
8057
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2269
	}
9a378e86100b (svn r11618) -Fix: buoys are just waypoints, so don't allow load/unload/transfert for them
glx
parents: 8029
diff changeset
  2270
7981
84dd1b37e314 (svn r11537) -Codechange: make it much harder to 'accidentally' add savegame conversion code after the window and cache initializations.
rubidium
parents: 7969
diff changeset
  2271
	return InitializeWindowsAndCaches();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2272
}
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2273
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2274
/** 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
  2275
 * version of AfterLoadGame().
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2276
 * 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
  2277
 * 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
  2278
 * 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
  2279
 * removed or added and changed statistics */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2280
void ReloadNewGRFData()
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2281
{
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2282
	/* reload grf data */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2283
	GfxLoadSprites();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2284
	LoadStringWidthTable();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2285
	/* reload vehicles */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2286
	ResetVehiclePosHash();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2287
	AfterLoadVehicles();
6196
ac5aa79d27ea (svn r8976) -Codechange: Reinitialize all engines after grf files have been reloaded/changed.
Darkvater
parents: 6193
diff changeset
  2288
	StartupEngines();
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2289
	/* 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
  2290
	AfterLoadWaypoints();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2291
	AfterLoadStations();
6332
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  2292
	/* check that house ids are still valid */
f3f436dcd7d0 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6317
diff changeset
  2293
	CheckHouseIDs();
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2294
	/* 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
  2295
	MarkWholeScreenDirty();
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2296
}