src/openttd.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
     3
/** @file openttd.cpp Functions related to starting OpenTTD. */
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
     6
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
     7
#define VARDEF
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
     8
#include "variables.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
     9
#undef VARDEF
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
    11
#include "openttd.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    12
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    13
#include "driver.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    14
#include "blitter/factory.hpp"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    15
#include "sound/sound_driver.hpp"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    16
#include "music/music_driver.hpp"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    17
#include "video/video_driver.hpp"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    18
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    19
#include "fontcache.h"
2340
0a9f3eeccb96 (svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents: 2322
diff changeset
    20
#include "gfxinit.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    21
#include "gfx_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "gui.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    23
#include "mixer.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    24
#include "sound_func.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    25
#include "window_func.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    26
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    27
#include "debug.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    28
#include "saveload.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    29
#include "landscape.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    30
#include "player_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    31
#include "player_base.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    32
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
#include "industry.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    35
#include "news_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
#include "fileio.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    37
#include "fios.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
#include "airport.h"
6519
367d6f96e23f (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: 6516
diff changeset
    39
#include "aircraft.h"
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    40
#include "console_func.h"
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    41
#include "screenshot.h"
5720
cc0ceeafaa55 (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: 5687
diff changeset
    42
#include "network/network.h"
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
    43
#include "network/network_func.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    44
#include "signs_base.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    45
#include "signs_func.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
    46
#include "waypoint.h"
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
    47
#include "ai/ai.h"
2855
950b5a56f9d5 (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2848
diff changeset
    48
#include "train.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
    49
#include "yapf/yapf.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    50
#include "settings_func.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
    51
#include "genworld.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    52
#include "player_face.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    53
#include "group.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    54
#include "newgrf_fsmports.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    55
#include "strings_func.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    56
#include "date_func.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    57
#include "vehicle_func.h"
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
    58
#include "gamelog.h"
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
    59
#include "cheat_func.h"
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
    60
#include "animated_tile_func.h"
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
    61
#include "functions.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    62
#include "elrail_func.h"
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    63
#include "rev.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    64
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
    65
#include "newgrf.h"
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
    66
#include "newgrf_config.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
    67
#include "newgrf_house.h"
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
    68
#include "newgrf_commons.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    69
#include "newgrf_station.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
    71
#include "clear_map.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    72
#include "tree_map.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
    73
#include "rail_map.h"
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
    74
#include "road_map.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    75
#include "station_map.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    76
#include "town_map.h"
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
    77
#include "industry_map.h"
6583
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
    78
#include "unmovable_map.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    79
#include "tunnel_map.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    80
#include "bridge_map.h"
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    81
#include "water_map.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    82
#include "tunnelbridge_map.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    83
#include "void_map.h"
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    84
#include "water.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
    85
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    88
#include "table/strings.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    89
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
    90
StringID _switch_mode_errorstr;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
    91
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    92
void CallLandscapeTick();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    93
void IncreaseDate();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    94
void DoPaletteAnimations();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    95
void MusicLoop();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
    96
void ResetMusic();
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
    97
void ResetOldNames();
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
    98
void ProcessAsyncSaveFinish();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    99
void CallWindowTickEvent();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   101
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   102
extern Player* DoStartupNewPlayer(bool is_ai);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   103
extern void ShowOSErrorBox(const char *buf, bool system);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   104
extern void InitializeRailGUI();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   105
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   106
/**
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   107
 * Error handling for fatal user errors.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   108
 * @param s the string to print.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   109
 * @note Does NEVER return.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   110
 */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   111
void CDECL usererror(const char *s, ...)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   112
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   113
	va_list va;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   114
	char buf[512];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   115
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   116
	va_start(va, s);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   117
	vsnprintf(buf, lengthof(buf), s, va);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   118
	va_end(va);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   119
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   120
	ShowOSErrorBox(buf, false);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   121
	if (_video_driver != NULL) _video_driver->Stop();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   122
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   123
	exit(1);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   124
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   125
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   126
/**
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   127
 * Error handling for fatal non-user errors.
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   128
 * @param s the string to print.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   129
 * @note Does NEVER return.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   130
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   131
void CDECL error(const char *s, ...)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   132
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	char buf[512];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   135
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	va_start(va, s);
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   137
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	va_end(va);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   139
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   140
	ShowOSErrorBox(buf, true);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   141
	if (_video_driver != NULL) _video_driver->Stop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   147
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   148
 * Shows some information on the console/a popup box depending on the OS.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   149
 * @param str the text to show.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   150
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
void CDECL ShowInfoF(const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	va_start(va, str);
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   156
	vsnprintf(buf, lengthof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	va_end(va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   161
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   162
 * Show the help message when someone passed a wrong parameter.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   163
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   164
static void ShowHelp()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   166
	char buf[4096];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   167
	char *p = buf;
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   168
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   169
	p += snprintf(p, lengthof(buf), "OpenTTD %s\n", _openttd_revision);
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   170
	p = strecpy(p,
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   171
		"\n"
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   172
		"\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		"Command line options:\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   174
		"  -v drv              = Set video driver (see below)\n"
6136
1262d3c24277 (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: 6135
diff changeset
   175
		"  -s drv              = Set sound driver (see below) (param bufsize,hz)\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   176
		"  -m drv              = Set music driver (see below)\n"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   177
		"  -b drv              = Set the blitter to use (see below)\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   178
		"  -r res              = Set resolution (for instance 800x600)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   179
		"  -h                  = Display this help text\n"
4285
72b3f7d6c891 (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
   180
		"  -t year             = Set starting year\n"
1440
2eb4dd1e0465 (svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents: 1436
diff changeset
   181
		"  -d [[fac=]lvl[,...]]= Debug mode\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   182
		"  -e                  = Start Editor\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   183
		"  -g [savegame]       = Start new/save game immediately\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   184
		"  -G seed             = Set random seed\n"
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   185
#if defined(ENABLE_NETWORK)
5676
74a4ba0f4196 (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: 5573
diff changeset
   186
		"  -n [ip:port#player] = Start networkgame\n"
5759
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   187
		"  -D [ip][:port]      = Start dedicated server\n"
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   188
		"  -l ip[:port]        = Redirect DEBUG()\n"
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   189
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   190
		"  -f                  = Fork into the background (dedicated only)\n"
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   191
#endif
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   192
#endif /* ENABLE_NETWORK */
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   193
		"  -i                  = Force to use the DOS palette\n"
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   194
		"                          (use this if you see a lot of pink)\n"
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   195
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n"
5827
20879afb77f6 (svn r8013) -Codechange (r6921, rUnknown): Show the error message of corrupt or missing (own) files
Darkvater
parents: 5772
diff changeset
   196
		"  -x                  = Do not automatically save to config file on exit\n",
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   197
		lastof(buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   200
	/* List the drivers */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   201
	p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   202
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   203
	/* List the blitters */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   204
	p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
5974
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   206
	/* ShowInfo put output to stderr, but version information should go
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   207
	 * to stdout; this is the only exception */
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   208
#if !defined(WIN32) && !defined(WIN64)
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   209
	printf("%s\n", buf);
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   210
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	ShowInfo(buf);
5974
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   212
#endif
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   216
struct MyGetOptData {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	char *opt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	int numleft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	char **argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	const char *options;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   221
	const char *cont;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   223
	MyGetOptData(int argc, char **argv, const char *options)
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   224
	{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   225
		opt = NULL;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   226
		numleft = argc;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   227
		this->argv = argv;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   228
		this->options = options;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   229
		cont = NULL;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   230
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   231
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
static int MyGetOpt(MyGetOptData *md)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   235
	const char *s,*r,*t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   237
	s = md->cont;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   238
	if (s != NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		goto md_continue_here;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   241
	for (;;) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   242
		if (--md->numleft < 0) return -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		s = *md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
		if (*s == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
md_continue_here:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
			s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			if (*s != 0) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   249
				/* Found argument, try to locate it in options. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
				if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   251
					/* ERROR! */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
					return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
				if (r[1] == ':') {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   255
					/* 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
   256
					if (!*(t = s + 1)) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   257
						/* 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
   258
						if (--md->numleft < 0 || *(t = *md->argv) == '-') {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   259
							/* Check if item is optional? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
							if (r[2] != ':')
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
								return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
							md->numleft++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
							t = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
						} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
							md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
					}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   268
					md->opt = (char*)t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
					md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
					return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
				md->opt = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
				md->cont = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
				return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		} else {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   277
			/* This is currently not supported. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
			return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   283
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   284
 * Extract the resolution from the given string and store
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   285
 * it in the 'res' parameter.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   286
 * @param res variable to store the resolution in.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   287
 * @param s   the string to decompose.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   288
 */
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   289
static void ParseResolution(Dimension *res, const char *s)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   291
	const char *t = strchr(s, 'x');
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	if (t == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		ShowInfoF("Invalid resolution '%s'", s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   297
	res->width  = max(strtoul(s, NULL, 0), 64UL);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   298
	res->height = max(strtoul(t + 1, NULL, 0), 64UL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   299
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   301
static void InitializeDynamicVariables()
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   302
{
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   303
	/* Dynamic stuff needs to be initialized somewhere... */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   304
	_industry_mngr.ResetMapping();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   305
	_industile_mngr.ResetMapping();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   306
}
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   307
5910
61e264641a8d (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: 5903
diff changeset
   308
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   309
/** Unitializes drivers, frees allocated memory, cleans pools, ...
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   310
 * Generally, prepares the game for shutting down
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   311
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   312
static void ShutdownGame()
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   313
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   314
	/* stop the AI */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   315
	AI_Uninitialize();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   316
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   317
	IConsoleFree();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   318
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   319
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   320
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   321
	DriverFactoryBase::ShutdownDrivers();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   322
5910
61e264641a8d (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: 5903
diff changeset
   323
	UnInitWindowSystem();
61e264641a8d (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: 5903
diff changeset
   324
61e264641a8d (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: 5903
diff changeset
   325
	/* Uninitialize variables that are allocated dynamically */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   326
	GamelogReset();
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   327
	_Town_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   328
	_Industry_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   329
	_Station_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   330
	_Vehicle_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   331
	_Sign_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   332
	_Order_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   333
	_Group_pool.CleanPool();
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   334
	_CargoPacket_pool.CleanPool();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   335
	_Engine_pool.CleanPool();
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   336
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   337
	free(_config_file);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   338
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   339
	/* Close all and any open filehandles */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   340
	FioCloseAll();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   341
}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   342
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   343
static void LoadIntroGame()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   344
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   345
	_game_mode = GM_MENU;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
   346
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   347
	ResetGRFConfig(false);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   348
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   349
	/* Setup main window */
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   350
	ResetWindowSystem();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   351
	SetupColorsAndInitialWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   352
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   353
	/* Load the default opening screen savegame */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   354
	if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3024
diff changeset
   355
		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   356
		WaitTillGeneratedWorld();
921
1884bb89c8dc (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   357
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   358
6557
8381016f71f3 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6555
diff changeset
   359
	_pause_game = 0;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   360
	SetLocalPlayer(PLAYER_FIRST);
4336
d5cd47d24092 (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
   361
	_cursor.fix_at = false;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   362
	MarkWholeScreenDirty();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   363
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   364
	CheckForMissingGlyphsInLoadedLanguagePack();
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   365
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   366
	/* Play main theme */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   367
	if (_music_driver->IsSongPlaying()) ResetMusic();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   368
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   369
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   370
byte _savegame_sort_order;
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   371
#if defined(UNIX) && !defined(__MORPHOS__)
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   372
extern void DedicatedFork();
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   373
#endif
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   374
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   375
int ttd_main(int argc, char *argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	int i;
1010
17470a8e5eb7 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents: 1009
diff changeset
   378
	const char *optformat;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   379
	char musicdriver[32], sounddriver[32], videodriver[32], blitter[32];
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   380
	Dimension resolution = {0, 0};
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4285
diff changeset
   381
	Year startyear = INVALID_YEAR;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   382
	uint generation_seed = GENERATE_NEW_SEED;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   383
	bool save_config = true;
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   384
#if defined(ENABLE_NETWORK)
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   385
	bool dedicated = false;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   386
	bool network   = false;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   387
	char *network_conn = NULL;
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   388
	char *debuglog_conn = NULL;
5759
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   389
	char *dedicated_host = NULL;
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   390
	uint16 dedicated_port = 0;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   391
#endif /* ENABLE_NETWORK */
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   392
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   393
	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
   394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	_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
   397
	_switch_mode_errorstr = INVALID_STRING_ID;
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   398
	_dedicated_forks = false;
1482
46a8146adecf (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1478
diff changeset
   399
	_config_file = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   401
	/* The last param of the following function means this:
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   402
	 *   a letter means: it accepts that param (e.g.: -h)
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   403
	 *   a ':' behind it means: it need a param (e.g.: -m<driver>)
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   404
	 *   a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   405
	optformat = "m:s:v:b:hD::n::eit:d::r:g::G:c:xl:"
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   406
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   407
		"f"
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   408
#endif
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   409
	;
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   410
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
   411
	MyGetOptData mgo(argc - 1, argv + 1, optformat);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   412
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	while ((i = MyGetOpt(&mgo)) != -1) {
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   414
		switch (i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
		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
   416
		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
   417
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   418
		case 'b': ttd_strlcpy(blitter, mgo.opt, sizeof(blitter)); break;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   419
#if defined(ENABLE_NETWORK)
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   420
		case 'D':
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   421
			strcpy(musicdriver, "null");
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   422
			strcpy(sounddriver, "null");
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   423
			strcpy(videodriver, "dedicated");
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   424
			strcpy(blitter, "null");
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   425
			dedicated = true;
6136
1262d3c24277 (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: 6135
diff changeset
   426
			if (mgo.opt != NULL) {
5759
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   427
				/* Use the existing method for parsing (openttd -n).
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   428
				 * However, we do ignore the #player part. */
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   429
				const char *temp = NULL;
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   430
				const char *port = NULL;
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   431
				ParseConnectionString(&temp, &port, mgo.opt);
6136
1262d3c24277 (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: 6135
diff changeset
   432
				if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt;
5759
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   433
				if (port != NULL) dedicated_port = atoi(port);
5c0d748579a0 (svn r7802) -Feature: make it possible to override the bind address and port of a dedicated server from the command line.
rubidium
parents: 5758
diff changeset
   434
			}
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   435
			break;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   436
		case 'f': _dedicated_forks = true; break;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   437
		case 'n':
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   438
			network = true;
3059
9f25d987c6ae (svn r3648) - Fix typo in r3647, don't ask me how it got there s/_/./
Darkvater
parents: 3058
diff changeset
   439
			network_conn = mgo.opt; // optional IP parameter, NULL if unset
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   440
			break;
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   441
		case 'l':
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   442
			debuglog_conn = mgo.opt;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   443
			break;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   444
#endif /* ENABLE_NETWORK */
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   445
		case 'r': ParseResolution(&resolution, mgo.opt); break;
4285
72b3f7d6c891 (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
   446
		case 't': startyear = atoi(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		case 'd': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
#if defined(WIN32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
				CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
#endif
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   451
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		case 'e': _switch_mode = SM_EDITOR; break;
614
e016770cb781 (svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents: 561
diff changeset
   454
		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
   455
		case 'g':
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   456
			if (mgo.opt != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
				strcpy(_file_to_saveload.name, mgo.opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
				_switch_mode = SM_LOAD;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   459
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
				_switch_mode = SM_NEWGAME;
6635
8a2f24f0c746 (svn r9205) -Fix: if you started openttd with '-g' you got the same map every run
truelight
parents: 6630
diff changeset
   461
				/* Give a random map */
8a2f24f0c746 (svn r9205) -Fix: if you started openttd with '-g' you got the same map every run
truelight
parents: 6630
diff changeset
   462
				generation_seed = InteractiveRandom();
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   463
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
			break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   465
		case 'G': generation_seed = atoi(mgo.opt); break;
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   466
		case 'c': _config_file = strdup(mgo.opt); break;
5758
c508f77aedd7 (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: 5726
diff changeset
   467
		case 'x': save_config = false; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		case -2:
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1993
diff changeset
   469
		case 'h':
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   470
			ShowHelp();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
			return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   475
#if defined(WINCE) && defined(_DEBUG)
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   476
	/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   477
	SetDebugString("4");
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   478
#endif
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
   479
6643
7fad81bde617 (svn r9266) -Codechange: unify the retrieval of the base paths a little more.
rubidium
parents: 6635
diff changeset
   480
	DeterminePaths(argv[0]);
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 959
diff changeset
   481
	CheckExternalFiles();
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   482
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   483
#if defined(UNIX) && !defined(__MORPHOS__)
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   484
	/* We must fork here, or we'll end up without some resources we need (like sockets) */
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   485
	if (_dedicated_forks)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   486
		DedicatedFork();
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   487
#endif
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   488
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	LoadFromConfig();
1688
787400219027 (svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents: 1608
diff changeset
   490
	CheckConfig();
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
   491
	LoadFromHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   493
	/* override config? */
6136
1262d3c24277 (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: 6135
diff changeset
   494
	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
1262d3c24277 (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: 6135
diff changeset
   495
	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
1262d3c24277 (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: 6135
diff changeset
   496
	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   497
	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   498
	if (resolution.width != 0) { _cur_resolution = resolution; }
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   499
	if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   500
	if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   502
	/* The width and height must be at least 1 pixel, this
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   503
	 * way all internal drawing routines work correctly. */
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   504
	if (_cur_resolution.width  <= 0) _cur_resolution.width  = 1;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
   505
	if (_cur_resolution.height <= 0) _cur_resolution.height = 1;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   506
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   507
#if defined(ENABLE_NETWORK)
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   508
	if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   509
	if (dedicated_port) _settings_client.network.server_port = dedicated_port;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   510
	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   511
#endif /* ENABLE_NETWORK */
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   512
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   513
	/* enumerate language files */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	InitializeLanguagePacks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   516
	/* initialize screenshot formats */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	InitializeScreenshotFormats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   519
	/* initialize all variables that are allocated dynamically */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   520
	InitializeDynamicVariables();
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   521
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   522
	/* start the AI */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   523
	AI_Initialize();
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   524
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   525
	/* Sample catalogue */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   526
	DEBUG(misc, 1, "Loading sound effects...");
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   527
	MxInitialize(11025);
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   528
	SoundInitialize("sample.cat");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
5108
dc67d70b5a45 (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
   530
	/* Initialize FreeType */
dc67d70b5a45 (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
   531
	InitFreeType();
dc67d70b5a45 (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
   532
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   533
	/* This must be done early, since functions use the InvalidateWindow* calls */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   534
	InitWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
5166
c40f2b19eca9 (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
   536
	/* Initialize game palette */
c40f2b19eca9 (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
   537
	GfxInitPalettes();
c40f2b19eca9 (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
   538
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   539
	DEBUG(misc, 1, "Loading blitter...");
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   540
	if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL)
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   541
		StrEmpty(_ini_blitter) ?
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   542
			usererror("Failed to autoprobe blitter") :
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   543
			usererror("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   544
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   545
	DEBUG(driver, 1, "Loading drivers...");
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   546
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   547
	_sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   548
	if (_sound_driver == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   549
		StrEmpty(_ini_sounddriver) ?
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   550
			usererror("Failed to autoprobe sound driver") :
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   551
			usererror("Failed to select requested sound driver '%s'", _ini_sounddriver);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   552
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   553
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   554
	_music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   555
	if (_music_driver == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   556
		StrEmpty(_ini_musicdriver) ?
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   557
			usererror("Failed to autoprobe music driver") :
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   558
			usererror("Failed to select requested music driver '%s'", _ini_musicdriver);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   559
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   560
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   561
	_video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   562
	if (_video_driver == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   563
		StrEmpty(_ini_videodriver) ?
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   564
			usererror("Failed to autoprobe video driver") :
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   565
			usererror("Failed to select requested video driver '%s'", _ini_videodriver);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   566
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   567
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2498
diff changeset
   568
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
   569
	/* Initialize the zoom level of the screen to normal */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
   570
	_screen.zoom = ZOOM_LVL_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   572
	/* restore saved music volume */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   573
	_music_driver->SetVolume(msf.music_vol);
3678
599ea808a4f8 (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   574
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   575
	NetworkStartUp(); // initialize network-core
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   576
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   577
#if defined(ENABLE_NETWORK)
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   578
	if (debuglog_conn != NULL && _network_available) {
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   579
		const char *not_used = NULL;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   580
		const char *port = NULL;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   581
		uint16 rport;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   582
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   583
		rport = NETWORK_DEFAULT_DEBUGLOG_PORT;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   584
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   585
		ParseConnectionString(&not_used, &port, debuglog_conn);
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   586
		if (port != NULL) rport = atoi(port);
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   587
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   588
		NetworkStartDebugLog(debuglog_conn, rport);
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   589
	}
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   590
#endif /* ENABLE_NETWORK */
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 6141
diff changeset
   591
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   592
	ScanNewGRFFiles();
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   593
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   594
	ResetGRFConfig(false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   595
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   596
	/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   597
	if (_settings_newgame.difficulty.diff_level == 9) SetDifficultyLevel(0, &_settings_newgame.difficulty);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   599
	/* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   600
	if (_switch_mode != SM_NONE) _settings_game = _settings_newgame;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   601
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   602
	/* initialize the ingame console */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   603
	IConsoleInit();
3312
593789444b01 (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
   604
	_cursor.in_window = true;
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1243
diff changeset
   605
	InitializeGUI();
644
e833509107ad (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents: 630
diff changeset
   606
	IConsoleCmdExec("exec scripts/autoexec.scr 0");
656
01540e6c0fed (svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents: 644
diff changeset
   607
2828
996de8e891c7 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   608
	GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   609
	WaitTillGeneratedWorld();
1268
306ebfea663a (svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents: 1267
diff changeset
   610
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   611
#ifdef ENABLE_NETWORK
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   612
	if (network && _network_available) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   613
		if (network_conn != NULL) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   614
			const char *port = NULL;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   615
			const char *player = NULL;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   616
			uint16 rport;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   617
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   618
			rport = NETWORK_DEFAULT_PORT;
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   619
			_network_playas = PLAYER_NEW_COMPANY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   620
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   621
			ParseConnectionString(&player, &port, network_conn);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   622
4861
f28bfa84f9ad (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   623
			if (player != NULL) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   624
				_network_playas = (PlayerID)atoi(player);
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   625
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   626
				if (_network_playas != PLAYER_SPECTATOR) {
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   627
					_network_playas--;
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   628
					if (!IsValidPlayer(_network_playas)) return false;
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   629
				}
4861
f28bfa84f9ad (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   630
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   631
			if (port != NULL) rport = atoi(port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   632
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   633
			LoadIntroGame();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   634
			_switch_mode = SM_NONE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   635
			NetworkClientConnectGame(network_conn, rport);
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1105
diff changeset
   636
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   637
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   638
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   639
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   640
	_video_driver->MainLoop();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   641
2285
3193cbd1ba88 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2234
diff changeset
   642
	WaitTillSaved();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
5758
c508f77aedd7 (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: 5726
diff changeset
   644
	/* only save config if we have to */
c508f77aedd7 (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: 5726
diff changeset
   645
	if (save_config) {
c508f77aedd7 (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: 5726
diff changeset
   646
		SaveToConfig();
c508f77aedd7 (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: 5726
diff changeset
   647
		SaveToHighScore();
c508f77aedd7 (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: 5726
diff changeset
   648
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   650
	/* Reset windowing system, stop drivers, free used memory, ... */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   651
	ShutdownGame();
1036
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   652
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   656
void HandleExitGameRequest()
4548
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   657
{
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   658
	if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   659
		_exit_game = true;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   660
	} else if (_settings_client.gui.autosave_on_exit) {
4548
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   661
		DoExitSave();
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   662
		_exit_game = true;
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   663
	} else {
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   664
		AskExitGame();
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   665
	}
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   666
}
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   667
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
static void ShowScreenshotResult(bool b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	if (b) {
2055
9361b56db8ba (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2051
diff changeset
   671
		SetDParamStr(0, _screenshot_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		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
   673
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
		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
   675
	}
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   679
static void MakeNewGameDone()
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   680
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   681
	/* In a dedicated server, the server does not play */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   682
	if (_network_dedicated) {
5564
6e1b3ea1ba7f (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
   683
		SetLocalPlayer(PLAYER_SPECTATOR);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   684
		return;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   685
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   686
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   687
	/* Create a single player */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   688
	DoStartupNewPlayer(false);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   689
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   690
	SetLocalPlayer(PLAYER_FIRST);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   691
	_current_player = _local_player;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   692
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   693
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   694
	SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   695
	InitializeRailGUI();
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   696
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   697
#ifdef ENABLE_NETWORK
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   698
	/* We are the server, we start a new player (not dedicated),
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   699
	 * so set the default password *if* needed. */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   700
	if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   701
		char *password = _settings_client.network.default_company_pass;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   702
		NetworkChangeCompanyPassword(1, &password);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   703
	}
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   704
#endif /* ENABLE_NETWORK */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   705
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   706
	MarkWholeScreenDirty();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   707
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   708
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   709
static void MakeNewGame(bool from_heightmap)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   713
	ResetGRFConfig(true);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
   714
	_house_mngr.ResetMapping();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   715
	_industile_mngr.ResetMapping();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   716
	_industry_mngr.ResetMapping();
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   717
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   718
	GenerateWorldSetCallback(&MakeNewGameDone);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   719
	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   720
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   722
static void MakeNewEditorWorldDone()
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   723
{
5564
6e1b3ea1ba7f (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
   724
	SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   729
static void MakeNewEditorWorld()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	_game_mode = GM_EDITOR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   733
	ResetGRFConfig(true);
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   734
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   735
	GenerateWorldSetCallback(&MakeNewEditorWorldDone);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   736
	GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   739
void StartupPlayers();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   740
void StartupDisasters();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   741
extern void StartupEconomy();
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 115
diff changeset
   742
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   743
/**
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   744
 * Start Scenario starts a new game based on a scenario.
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   745
 * Eg 'New Game' --> select a preset scenario
1501
0faec0f792b0 (svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents: 1500
diff changeset
   746
 * This starts a scenario based on your current difficulty settings
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   747
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   748
static void StartScenario()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   752
	/* invalid type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	if (_file_to_saveload.mode == SL_INVALID) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   754
		DEBUG(sl, 0, "Savegame is obsolete or invalid format: '%s'", _file_to_saveload.name);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   755
		SetDParamStr(0, GetSaveLoadErrorString());
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   756
		ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
		_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   761
	/* Reinitialize windows */
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   762
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   766
	ResetGRFConfig(true);
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   767
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   768
	/* Load game */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   769
	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
   770
		LoadIntroGame();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   771
		SetDParamStr(0, GetSaveLoadErrorString());
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   772
		ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   775
	_settings_game.difficulty = _settings_newgame.difficulty;
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   776
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   777
	/* Inititalize data */
3891
b39019cd32cf (svn r4947) - Fix [FS#145]: Starting scenarios did not adhere to local difficulty settings
Darkvater
parents: 3889
diff changeset
   778
	StartupEconomy();
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   779
	StartupPlayers();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   780
	StartupEngines();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   781
	StartupDisasters();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   782
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   783
	SetLocalPlayer(PLAYER_FIRST);
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   784
	_current_player = _local_player;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   785
	DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   790
/** Load the specified savegame but on error do different things.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   791
 * If loading fails due to corrupt savegame, bad version, etc. go back to
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   792
 * a previous correct state. In the menu for example load the intro game again.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   793
 * @param filename file to be loaded
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   794
 * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   795
 * @param newgm switch to this mode of loading fails due to some unknown error
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   796
 * @param subdir default directory to look for filename, set to 0 if not needed
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   797
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
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;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   803
	assert(mode == SL_LOAD || mode == SL_OLD_LOAD);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   804
	switch (SaveOrLoad(filename, mode, subdir)) {
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   805
		case SL_OK: return true;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   806
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   807
		case SL_REINIT:
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   808
			switch (ogm) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   809
				default:
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   810
				case GM_MENU:   LoadIntroGame();      break;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   811
				case GM_EDITOR: MakeNewEditorWorld(); break;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   812
			}
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   813
			return false;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   814
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   815
		default:
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   816
			_game_mode = ogm;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   817
			return false;
2639
8a7342eb3a78 (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
e3b43338096b (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
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   823
#ifdef ENABLE_NETWORK
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   824
	/* If we are saving something, the network stays in his current state */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   825
	if (new_mode != SM_SAVE) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   826
		/* If the network is active, make it not-active */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   827
		if (_networking) {
e3b43338096b (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)) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   829
				NetworkReboot();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   830
			} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   831
				NetworkDisconnect();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   832
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   833
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   834
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   835
		/* If we are a server, we restart the server */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   836
		if (_is_network_server) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   837
			/* But not if we are going to the menu */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   838
			if (new_mode != SM_MENU) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   839
				/* check if we should reload the config */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   840
				if (_settings_client.network.reload_cfg) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   841
					LoadFromConfig();
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   842
					_settings_game = _settings_newgame;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   843
					ResetGRFConfig(false);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   844
				}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   845
				NetworkServerStart();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   846
			} else {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
   847
				/* This client no longer wants to be a network-server */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   848
				_is_network_server = false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   849
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   850
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   851
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   852
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   853
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   854
	switch (new_mode) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   855
		case SM_EDITOR: /* Switch to scenario editor */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   856
			MakeNewEditorWorld();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   857
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   859
		case SM_NEWGAME: /* New Game --> 'Random game' */
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   860
#ifdef ENABLE_NETWORK
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   861
			if (_network_server) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   862
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   863
			}
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   864
#endif /* ENABLE_NETWORK */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   865
			MakeNewGame(false);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   866
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   868
		case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   869
#ifdef ENABLE_NETWORK
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   870
			if (_network_server) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   871
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   872
			}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   873
#endif /* ENABLE_NETWORK */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   874
			StartScenario();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   875
			break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   876
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   877
		case SM_LOAD: { /* Load game, Play Scenario */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   878
			ResetGRFConfig(true);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   879
			ResetWindowSystem();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   880
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   881
			if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   882
				LoadIntroGame();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   883
				SetDParamStr(0, GetSaveLoadErrorString());
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   884
				ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   885
			} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   886
				if (_saveload_mode == SLD_LOAD_SCENARIO) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   887
					StartupEngines();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   888
				}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   889
				/* Update the local player for a loaded game. It is either always
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   890
				* player #1 (eg 0) or in the case of a dedicated server a spectator */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   891
				SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   892
				/* Decrease pause counter (was increased from opening load dialog) */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   893
				DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   894
#ifdef ENABLE_NETWORK
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   895
				if (_network_server) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   896
					snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   897
				}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   898
#endif /* ENABLE_NETWORK */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   899
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   900
			break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   901
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   903
		case SM_START_HEIGHTMAP: /* Load a heightmap and start a new game from it */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   904
#ifdef ENABLE_NETWORK
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   905
			if (_network_server) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   906
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   907
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   908
#endif /* ENABLE_NETWORK */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   909
			MakeNewGame(true);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   910
			break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   911
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   912
		case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
5564
6e1b3ea1ba7f (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
   913
			SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   915
			GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   916
			MarkWholeScreenDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   917
			break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   918
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   919
		case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   920
			if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   921
				SetLocalPlayer(OWNER_NONE);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   922
				_settings_newgame.game_creation.starting_year = _cur_year;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   923
			} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   924
				SetDParamStr(0, GetSaveLoadErrorString());
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   925
				ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   926
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   927
			break;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   928
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   930
		case SM_MENU: /* Switch to game intro menu */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   931
			LoadIntroGame();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   932
			break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   933
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   934
		case SM_SAVE: /* Save game */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   935
			/* Make network saved games on pause compatible to singleplayer */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   936
			if (_networking && _pause_game == 1) _pause_game = 2;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   937
			if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   938
				SetDParamStr(0, GetSaveLoadErrorString());
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   939
				ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   940
			} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   941
				DeleteWindowById(WC_SAVELOAD, 0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   942
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   943
			if (_networking && _pause_game == 2) _pause_game = 1;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   944
			break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   945
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   946
		case SM_GENRANDLAND: /* Generate random land within scenario editor */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   947
			SetLocalPlayer(OWNER_NONE);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   948
			GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   949
			/* XXX: set date */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   950
			MarkWholeScreenDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   951
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   953
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   954
	if (_switch_mode_errorstr != INVALID_STRING_ID) {
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   955
		ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   956
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   960
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   961
 * State controlling game loop.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   962
 * The state must not be changed from anywhere but here.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   963
 * That check is enforced in DoCommand.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   964
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   965
void StateGameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   967
	/* dont execute the state loop during pause */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   968
	if (_pause_game) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   969
		CallWindowTickEvent();
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   970
		return;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   971
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   972
	if (IsGeneratingWorld()) return;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   973
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   974
	ClearStorageChanges(false);
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   975
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	if (_game_mode == GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		CallLandscapeTick();
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   980
		ClearStorageChanges(true);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   981
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
		NewsLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	} else {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   985
#ifdef DEBUG_DUMP_COMMANDS
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   986
		Vehicle *v;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   987
		FOR_ALL_VEHICLES(v) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   988
			if (v != v->First()) continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   989
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   990
			switch (v->type) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   991
				case VEH_ROAD: {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   992
					extern byte GetRoadVehLength(const Vehicle *v);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   993
					if (GetRoadVehLength(v) != v->u.road.cached_veh_length) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   994
						printf("cache mismatch: vehicle %i, player %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   995
					}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   996
				} break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   997
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   998
				case VEH_TRAIN: {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   999
					uint length = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1000
					for (Vehicle *u = v; u != NULL; u = u->Next()) length++;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1001
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1002
					VehicleRail *wagons = MallocT<VehicleRail>(length);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1003
					length = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1004
					for (Vehicle *u = v; u != NULL; u = u->Next()) wagons[length++] = u->u.rail;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1005
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1006
					TrainConsistChanged(v);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1007
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1008
					length = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1009
					for (Vehicle *u = v; u != NULL; u = u->Next()) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1010
						if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1011
							printf("cache mismatch: vehicle %i, player %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1012
						}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1013
						length++;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1014
					}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1015
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1016
					free(wagons);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1017
				} break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1018
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1019
				case VEH_AIRCRAFT: {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1020
					uint speed = v->u.air.cached_max_speed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1021
					UpdateAircraftCache(v);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1022
					if (speed != v->u.air.cached_max_speed) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1023
						printf("cache mismatch: vehicle %i, player %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1024
					}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1025
				} break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1026
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1027
				default:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1028
					break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1029
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1030
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1031
#endif
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1032
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1033
		/* All these actions has to be done from OWNER_NONE
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1034
		 *  for multiplayer compatibility */
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2469
diff changeset
  1035
		PlayerID p = _current_player;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1036
		_current_player = OWNER_NONE;
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1037
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
		AnimateAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		IncreaseDate();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
		CallLandscapeTick();
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1043
		ClearStorageChanges(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
  1045
		AI_RunGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
		NewsLoop();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1049
		_current_player = p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1053
/** Create an autosave. The default name is "autosave#.sav". However with
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1054
 * the patch setting 'keep_all_autosave' the name defaults to company-name + date */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1055
static void DoAutosave()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1057
	char buf[MAX_PATH];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1058
6228
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
  1059
#if defined(PSP)
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
  1060
	/* Autosaving in networking is too time expensive for the PSP */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1061
	if (_networking) return;
6228
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
  1062
#endif /* PSP */
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
  1063
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1064
	if (_settings_client.gui.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1065
		SetDParam(0, _local_player);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1066
		SetDParam(1, _date);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1067
		GetString(buf, STR_4004, lastof(buf));
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6793
diff changeset
  1068
		ttd_strlcat(buf, ".sav", lengthof(buf));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1069
	} else {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1070
		/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1071
		snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
  1072
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1073
		if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
  1076
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1077
	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
  1078
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1079
	}
0
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1082
void GameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
{
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1084
	ProcessAsyncSaveFinish();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1086
	/* autosave game? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
	if (_do_autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
		_do_autosave = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
		DoAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
		RedrawAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1093
	/* make a screenshot? */
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4171
diff changeset
  1094
	if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1096
	/* switch game mode? */
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1097
	if (_switch_mode != SM_NONE) {
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1098
		SwitchMode(_switch_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		_switch_mode = SM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	IncreaseSpriteLRU();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	InteractiveRandom();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	_caret_timer += 3;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1106
	_palette_animation_counter += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	CursorTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1109
#ifdef ENABLE_NETWORK
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1110
	/* Check for UDP stuff */
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
  1111
	if (_network_available) NetworkUDPGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
  1113
	if (_networking && !IsGeneratingWorld()) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1114
		/* Multiplayer */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1115
		NetworkGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1116
	} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1117
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1118
			/* This means that we want to reconnect to the last host
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1119
			 * We do this here, because it means that the network is really closed */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1120
			NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1121
		}
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1122
		/* Singleplayer */
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
  1123
		StateGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1125
#else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1126
	StateGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1127
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1129
	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
  1130
6557
8381016f71f3 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6555
diff changeset
  1131
	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
  1132
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1542
diff changeset
  1133
	InputLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
1608
074dff2e4890 (svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents: 1570
diff changeset
  1135
	MusicLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1138
static void ConvertTownOwner()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1140
	for (TileIndex tile = 0; tile != MapSize(); tile++) {
4000
bab1ebc37da0 (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
  1141
		switch (GetTileType(tile)) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1142
			case MP_ROAD:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1143
				if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m4, 7)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1144
					_m[tile].m4 = OWNER_TOWN;
4000
bab1ebc37da0 (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
  1145
				}
bab1ebc37da0 (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
  1146
				/* FALLTHROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
4000
bab1ebc37da0 (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
  1148
			case MP_TUNNELBRIDGE:
bab1ebc37da0 (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
  1149
				if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
bab1ebc37da0 (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
  1150
				break;
bab1ebc37da0 (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
  1151
bab1ebc37da0 (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
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1157
/* before savegame version 4, the name of the company determined if it existed */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1158
static void CheckIsPlayerActive()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1160
	Player *p;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1161
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	FOR_ALL_PLAYERS(p) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1163
		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
  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
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1167
/* since savegame version 4.1, exclusive transport rights are stored at towns */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1168
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
  1169
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1170
	Town *t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1171
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1172
	FOR_ALL_TOWNS(t) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1173
		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
  1174
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1175
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  1176
	/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1177
	 *   could be implemented this way:
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1178
	 * 1.) Go through all stations
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1179
	 *     Build an array town_blocked[ town_id ][ player_id ]
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1180
	 *     that stores if at least one station in that town is blocked for a player
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1181
	 * 2.) Go through that array, if you find a town that is not blocked for
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1182
	 *     one player, but for all others, then give him exclusivity.
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1183
	 */
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1184
}
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1185
2756
0c73c4710821 (svn r3301) One more static
tron
parents: 2754
diff changeset
  1186
static const byte convert_currency[] = {
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1187
	 0,  1, 12,  8,  3,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1188
	10, 14, 19,  4,  5,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1189
	 9, 11, 13,  6, 17,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1190
	16, 22, 21,  7, 15,
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1191
	18,  2, 20, };
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1192
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1193
/* since savegame version 4.2 the currencies are arranged differently */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1194
static void UpdateCurrencies()
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1195
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1196
	_settings_game.locale.currency = convert_currency[_settings_game.locale.currency];
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1197
}
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1198
1181
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1199
/* Up to revision 1413 the invisible tiles at the southern border have not been
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1200
 * MP_VOID, even though they should have. This is fixed by this function
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1201
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1202
static void UpdateVoidTiles()
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1203
{
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 950
diff changeset
  1204
	uint i;
1181
6231b823d796 (svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents: 1165
diff changeset
  1205
3075
f0d692c60465 (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1206
	for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX());
f0d692c60465 (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1207
	for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i);
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1208
}
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1209
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1210
/* since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1211
static void UpdateSignOwner()
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1212
{
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1213
	Sign *si;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1214
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1215
	FOR_ALL_SIGNS(si) si->owner = OWNER_NONE;
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1216
}
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1217
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1218
extern void UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1220
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1221
static inline RailType UpdateRailType(RailType rt, RailType min)
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1222
{
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1223
	return rt >= min ? (RailType)(rt + 1): rt;
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1224
}
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1225
6777
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1226
void ResetAirportToNewGRFSpec(TileIndex tile, Station *st, uint32 grfid, uint8 localidx)
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1227
{
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1228
	const FSMportsSpec *fsmportspec = GetCustomFSMportsSpecByGrf(grfid, localidx);
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1229
	int fsmportspecindex = AllocateFSMportsSpecToStation(fsmportspec, st, true);
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1230
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1231
	if (grfid != 0x4450414F || localidx != 3) { // Skip oilrigs, but otherwise makeairport
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1232
		/* find layout tiletype corresponding to location on airport */
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1233
		TileIndexDiffC tile_offset = TileIndexToTileIndexDiffC(tile, st->airport_tile);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1234
		int w = fsmportspec->size_x[0];  // Old airports are always 0th graphics set orientation... ie NE
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6800
diff changeset
  1235
		const byte *layout_ptr = fsmportspec->layouts[0];
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1236
		st->FSMport_orientation = *layout_ptr++; // Orientation
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1237
		layout_ptr++; // Skip minipic ID
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6800
diff changeset
  1238
		for (byte skip = 0; skip < (tile_offset.y * w + tile_offset.x); skip++) {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1239
			layout_ptr++;  // Skip to the correct layout tiletype
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1240
		}
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1241
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1242
		/* Replace the savegame layout tiletype with the newgrf one */
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1243
		MakeAirport(tile, st->owner, st->index, *layout_ptr);
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1244
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1245
		/* Set top bit of m6 to indicate an fsmportsspec */
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1246
		SetCustomFSMportsSpecIndex(tile, fsmportspecindex);
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1247
	} else {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1248
		/* Oilrigs must be set against their root tile, not the tile of the landing pad
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1249
		 * set top bit of m6 to indicate an fsmportsspec */
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1250
		SetCustomFSMportsSpecIndex(st->xy, fsmportspecindex);
6777
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1251
	}
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1252
}
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1253
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1254
/**
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1255
 * Initialization of the windows and several kinds of caches.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1256
 * This is not done directly in AfterLoadGame because these
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1257
 * functions require that all saveload conversions have been
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1258
 * done. As people tend to add savegame conversion stuff after
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1259
 * the intialization of the windows and caches quite some bugs
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1260
 * had been made.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1261
 * Moving this out of there is both cleaner and less bug-prone.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1262
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1263
 * @return true if everything went according to plan, otherwise false.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1264
 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1265
static bool InitializeWindowsAndCaches()
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1266
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1267
	/* Initialize windows */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1268
	ResetWindowSystem();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1269
	SetupColorsAndInitialWindow();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1270
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1271
	extern void ResetViewportAfterLoadGame();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1272
	ResetViewportAfterLoadGame();
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1273
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1274
	/* Update coordinates of the signs. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1275
	UpdateAllStationVirtCoord();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1276
	UpdateAllSignVirtCoords();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1277
	UpdateAllTownVirtCoords();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1278
	UpdateAllWaypointSigns();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1279
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1280
	Player *p;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1281
	FOR_ALL_PLAYERS(p) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1282
		/* For each player, verify (while loading a scenario) that the inauguration date is the current year and set it
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1283
		 * accordingly if it is not the case.  No need to set it on players that are not been used already,
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1284
		 * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1285
		if (_file_to_saveload.filetype == FT_SCENARIO && p->inaugurated_year != MIN_YEAR) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1286
			p->inaugurated_year = _cur_year;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1287
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1288
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1289
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1290
	SetCachedEngineCounts();
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1291
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1292
	/* Towns have a noise controlled number of airports system
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1293
	 * So each airport's noise value must be added to the town->noise_reached value
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1294
	 * Reset each town's noise_reached value to '0' before. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1295
	UpdateAirportsNoise();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1296
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1297
	return true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1298
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1299
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1300
bool AfterLoadGame()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
{
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1302
	TileIndex map_size = MapSize();
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1303
	Player *p;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
  1304
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1305
	if (CheckSavegameVersion(98)) GamelogOldver();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1306
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1307
	GamelogTestRevision();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1308
	GamelogTestMode();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1309
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1310
	if (CheckSavegameVersion(98)) GamelogGRFAddList(_grfconfig);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1311
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1312
	/* in version 2.1 of the savegame, town owner was unified. */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1313
	if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1315
	/* from version 4.1 of the savegame, exclusive rights are stored at towns */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1316
	if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1317
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1318
	/* from version 4.2 of the savegame, currencies are in a different order */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1319
	if (CheckSavegameVersionOldStyle(4, 2)) UpdateCurrencies();
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1320
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1321
	/* from version 6.1 of the savegame, signs have an "owner" */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1322
	if (CheckSavegameVersionOldStyle(6, 1)) UpdateSignOwner();
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1323
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1324
	/* In old version there seems to be a problem that water is owned by
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1325
	 * OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1326
	 * (4.3) version, so I just check when versions are older, and then
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1327
	 * walk through the whole map.. */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1328
	if (CheckSavegameVersionOldStyle(4, 3)) {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1329
		for (TileIndex t = 0; t < map_size; t++) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1330
			if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_PLAYERS) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1331
				SetTileOwner(t, OWNER_WATER);
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1332
			}
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1333
		}
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1334
	}
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1335
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1336
	if (CheckSavegameVersion(84)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1337
		Player *p;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1338
		FOR_ALL_PLAYERS(p) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1339
			p->name = CopyFromOldName(p->name_1);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1340
			if (p->name != NULL) p->name_1 = STR_SV_UNNAMED;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1341
			p->president_name = CopyFromOldName(p->president_name_1);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1342
			if (p->president_name != NULL) p->president_name_1 = SPECSTR_PRESIDENT_NAME;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1343
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1344
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1345
		Station *st;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1346
		FOR_ALL_STATIONS(st) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1347
			st->name = CopyFromOldName(st->string_id);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1348
			if (st->name != NULL) st->string_id = STR_EMPTY;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1349
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1350
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1351
		Town *t;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1352
		FOR_ALL_TOWNS(t) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1353
			t->name = CopyFromOldName(t->townnametype);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1354
			if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1355
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1356
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1357
		Waypoint *wp;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1358
		FOR_ALL_WAYPOINTS(wp) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1359
			wp->name = CopyFromOldName(wp->string);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1360
			wp->string = STR_EMPTY;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1361
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1362
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1363
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1364
	/* From this point the old names array is cleared. */
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1365
	ResetOldNames();
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1366
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1367
	/* convert road side to my format. */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1368
	if (_settings_game.vehicle.road_side) _settings_game.vehicle.road_side = 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
5898
2ee7d23291fa (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: 5887
diff changeset
  1370
	/* Check if all NewGRFs are present, we are very strict in MP mode */
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6522
diff changeset
  1371
	GRFListCompatibility gcf_res = IsGoodGRFConfigList();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1372
	if (_networking && gcf_res != GLC_ALL_GOOD) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1373
		SetSaveLoadError(STR_NETWORK_ERR_CLIENT_NEWGRF_MISMATCH);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1374
		return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1375
	}
5898
2ee7d23291fa (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: 5887
diff changeset
  1376
2ee7d23291fa (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: 5887
diff changeset
  1377
	switch (gcf_res) {
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6522
diff changeset
  1378
		case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1379
		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; _pause_game = -1; break;
5903
cd2d0ef3a3b9 (svn r8111) -Fix r8106: silence warnings
glx
parents: 5898
diff changeset
  1380
		default: break;
5898
2ee7d23291fa (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: 5887
diff changeset
  1381
	}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1382
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1383
	/* Update current year
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1384
	 * must be done before loading sprites as some newgrfs check it */
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1385
	SetDate(_date);
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1386
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1387
	/* Force dynamic engines off when loading older savegames */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1388
	if (CheckSavegameVersion(95)) _settings_game.vehicle.dynamic_engines = 0;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1389
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1390
	/* Load the sprites */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	GfxLoadSprites();
5155
64f930853bea (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
  1392
	LoadStringWidthTable();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1394
	/* Copy temporary data to Engine pool */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1395
	CopyTempEngineData();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1396
2814
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1397
	/* Connect front and rear engines of multiheaded trains and converts
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1398
	 * subtype to the new format */
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1399
	if (CheckSavegameVersionOldStyle(17, 1)) ConvertOldMultiheadToNew();
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1400
2928
414b96d4d4fb (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
  1401
	/* Connect front and rear engines of multiheaded trains */
414b96d4d4fb (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
  1402
	ConnectMultiheadedTrains();
2855
950b5a56f9d5 (svn r3403) -Codechange: [multiheaded engines] the references between the front and rear engines are no longer saved
bjarni
parents: 2848
diff changeset
  1403
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1404
	/* reinit the landscape variables (landscape might have changed) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	InitializeLandscapeVariables(true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1406
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1407
	/* Update all vehicles */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1408
	AfterLoadVehicles(true);
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1409
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1410
	/* Update all waypoints */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1411
	if (CheckSavegameVersion(12)) FixOldWaypoints();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1412
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1413
	AfterLoadTown();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1414
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1415
	/* make sure there is a town in the game */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1416
	if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1417
		SetSaveLoadError(STR_NO_TOWN_IN_SCENARIO);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1421
	/* in version 4.1 of the savegame, is_active was introduced to determine
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1422
	 * if a player does exist, rather then checking name_1 */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1423
	if (CheckSavegameVersionOldStyle(4, 1)) CheckIsPlayerActive();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1424
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1425
	/* The void tiles on the southern border used to belong to a wrong class (pre 4.3).
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1426
	 * This problem appears in savegame version 21 too, see r3455. But after loading the
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1427
	 * savegame and saving again, the buggy map array could be converted to new savegame
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1428
	 * version. It didn't show up before r12070. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1429
	if (CheckSavegameVersion(87)) UpdateVoidTiles();
929
1a071a06af3f (svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents: 921
diff changeset
  1430
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1431
	/* If Load Scenario / New (Scenario) Game is used,
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1432
	 *  a player does not exist yet. So create one here.
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1433
	 * 1 exeption: network-games. Those can have 0 players
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1434
	 *   But this exeption is not true for non dedicated network_servers! */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1435
	if (!_players[0].is_active && (!_networking || (_networking && _network_server && !_network_dedicated)))
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1436
		DoStartupNewPlayer(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1438
	if (CheckSavegameVersion(72)) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1439
		/* Locks/shiplifts in very old savegames had OWNER_WATER as owner */
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1440
		for (TileIndex t = 0; t < MapSize(); t++) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1441
			switch (GetTileType(t)) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1442
				default: break;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1443
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1444
				case MP_WATER:
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1445
					if (GetWaterTileType(t) == WATER_TILE_LOCK && GetTileOwner(t) == OWNER_WATER) SetTileOwner(t, OWNER_NONE);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1446
					break;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1447
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1448
				case MP_STATION: {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1449
					if (HasBit(_m[t].m6, 3)) SetBit(_m[t].m6, 2);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1450
					StationGfx gfx = GetStationGfx(t);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1451
					StationType st;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1452
					if (       IsInsideMM(gfx,   0,   8)) { // Railway station
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1453
						st = STATION_RAIL;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1454
						SetStationGfx(t, gfx - 0);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1455
					} else if (IsInsideMM(gfx,   8,  67)) { // Airport
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1456
						st = STATION_AIRPORT;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1457
						SetStationGfx(t, gfx - 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1458
					} else if (IsInsideMM(gfx,  67,  71)) { // Truck
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1459
						st = STATION_TRUCK;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1460
						SetStationGfx(t, gfx - 67);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1461
					} else if (IsInsideMM(gfx,  71,  75)) { // Bus
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1462
						st = STATION_BUS;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1463
						SetStationGfx(t, gfx - 71);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1464
					} else if (gfx == 75) {                    // Oil rig
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1465
						st = STATION_OILRIG;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1466
						SetStationGfx(t, gfx - 75);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1467
					} else if (IsInsideMM(gfx,  76,  82)) { // Dock
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1468
						st = STATION_DOCK;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1469
						SetStationGfx(t, gfx - 76);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1470
					} else if (gfx == 82) {                    // Buoy
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1471
						st = STATION_BUOY;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1472
						SetStationGfx(t, gfx - 82);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1473
					} else if (IsInsideMM(gfx,  83, 168)) { // Extended airport
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1474
						st = STATION_AIRPORT;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1475
						SetStationGfx(t, gfx - 83 + 67 - 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1476
					} else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1477
						st = STATION_TRUCK;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1478
						SetStationGfx(t, gfx - 168 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1479
					} else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1480
						st = STATION_BUS;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1481
						SetStationGfx(t, gfx - 170 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1482
					} else {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1483
						return false;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1484
					}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1485
					SB(_m[t].m6, 3, 3, st);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1486
				} break;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1487
			}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1488
		}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1489
	}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6725
diff changeset
  1490
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1491
	for (TileIndex t = 0; t < map_size; t++) {
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1492
		switch (GetTileType(t)) {
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1493
			case MP_STATION: {
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1494
				Station *st = GetStationByTile(t);
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1495
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1496
				st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1497
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1498
				switch (GetStationType(t)) {
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1499
					case STATION_TRUCK:
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1500
					case STATION_BUS:
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1501
						if (CheckSavegameVersion(6)) {
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1502
							/* From this version on there can be multiple road stops of the
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1503
							 * same type per station. Convert the existing stops to the new
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1504
							 * internal data structure. */
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1505
							RoadStop *rs = new RoadStop(t);
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1506
							if (rs == NULL) error("Too many road stops in savegame");
6130
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1507
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1508
							RoadStop **head =
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1509
								IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1510
							*head = rs;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1511
						}
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1512
						break;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1513
6135
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1514
					case STATION_OILRIG: {
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1515
						/* Very old savegames sometimes have phantom oil rigs, i.e.
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1516
						 * an oil rig which got shut down, but not completly removed from
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1517
						 * the map
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1518
						 */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1519
						TileIndex t1 = TILE_ADDXY(t, 0, 1);
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6782
diff changeset
  1520
						ResetAirportToNewGRFSpec(t, st, 0x4450414F, 3);
6137
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1521
						if (IsTileType(t1, MP_INDUSTRY) &&
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1522
								GetIndustryGfx(t1) == GFX_OILRIG_1) {
6137
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1523
							/* The internal encoding of oil rigs was changed twice.
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1524
							 * It was 3 (till 2.2) and later 5 (till 5.1).
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1525
							 * Setting it unconditionally does not hurt.
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1526
							 */
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1527
							GetStationByTile(t)->airport_type = AT_OILRIG;
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1528
						} else {
6135
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1529
							DeleteOilRig(t);
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1530
						}
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1531
						break;
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1532
					}
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1533
6777
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1534
					case STATION_AIRPORT: {
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1535
						/* if savegame is prior to introduction of fsmportspecs, and it is an airport, convert to fsmport */
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  1536
						if (CheckSavegameVersion(NEWGRF_AIRPORTS_SAVEGAME)) {
6777
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1537
							/* things to sort out:
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1538
							 * a) assign appropriate default fsmportspec to airport
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1539
							 * b) mark each tile as part of an fsmportspec
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1540
							 * c) maybe replace tile graphics with newgrf ones, to hook all airports into new definitions
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1541
							 * d) when aircraft are loaded, they will need updating
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1542
							 */
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1543
							switch (st->airport_type) {
6837
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1544
								default: break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1545
								case AT_SMALL:         ResetAirportToNewGRFSpec(t, st, 0x4450414F, 0); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1546
								case AT_LARGE:         ResetAirportToNewGRFSpec(t, st, 0x4450414F, 1); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1547
								case AT_HELIPORT:      ResetAirportToNewGRFSpec(t, st, 0x4450414F, 2); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1548
								case AT_COMMUTER:      ResetAirportToNewGRFSpec(t, st, 0x5850414F, 0); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1549
								case AT_METROPOLITAN:  ResetAirportToNewGRFSpec(t, st, 0x5850414F, 1); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1550
								case AT_INTERNATIONAL: ResetAirportToNewGRFSpec(t, st, 0x5850414F, 2); break;
c39d50afbaf0 (svn r10920) [NewGRF_ports] -Cleanup: remove the tables/files that were used to define airports as they will all be defined in a NewGRF and we do not need them anymore.
rubidium
parents: 6833
diff changeset
  1551
								case AT_HELIDEPOT:     ResetAirportToNewGRFSpec(t, st, 0x5850414F, 3); break;
6838
33fd9078e316 (svn r10925) [NewGRF_ports] -Add: Added graphics placement of Intercontinental and Helistation. State Machines not yet functional.
richk
parents: 6837
diff changeset
  1552
								case AT_INTERCON:      ResetAirportToNewGRFSpec(t, st, 0x5850414F, 4); break;
33fd9078e316 (svn r10925) [NewGRF_ports] -Add: Added graphics placement of Intercontinental and Helistation. State Machines not yet functional.
richk
parents: 6837
diff changeset
  1553
								case AT_HELISTATION:   ResetAirportToNewGRFSpec(t, st, 0x5850414F, 5); break;
6777
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1554
							}
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1555
						}
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1556
						break;
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1557
					}
529c5c2735a8 (svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
richk
parents: 6743
diff changeset
  1558
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1559
					default: break;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1560
				}
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1561
				break;
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1562
			}
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1563
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1564
			default: break;
6130
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1565
		}
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1566
	}
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1567
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  1568
	/* after savegame version NEWGRF_AIRPORTS_SAVEGAME, we have newgrf airports. make aircraft safe (either to hangar or bounce into air) */
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  1569
	if (CheckSavegameVersion(NEWGRF_AIRPORTS_SAVEGAME)) UpdateOldAircraft();
6780
6483de08de63 (svn r10850) [NewGRF_ports] -Feature: Update aircraft positions for old savegames.
richk
parents: 6777
diff changeset
  1570
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1571
	/* In version 6.1 we put the town index in the map-array. To do this, we need
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1572
	 *  to use m2 (16bit big), so we need to clean m2, and that is where this is
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1573
	 *  all about ;) */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1574
	if (CheckSavegameVersionOldStyle(6, 1)) {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1575
		for (TileIndex t = 0; t < map_size; t++) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1576
			switch (GetTileType(t)) {
3983
d2d6496238e4 (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
  1577
				case MP_HOUSE:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1578
					_m[t].m4 = _m[t].m2;
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1579
					SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
3983
d2d6496238e4 (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
  1580
					break;
d2d6496238e4 (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
  1581
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1582
				case MP_ROAD:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1583
					_m[t].m4 |= (_m[t].m2 << 4);
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1584
					if (IsTileOwner(t, OWNER_TOWN)) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1585
						SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
3983
d2d6496238e4 (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
  1586
					} else {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1587
						SetTownIndex(t, 0);
3983
d2d6496238e4 (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
  1588
					}
d2d6496238e4 (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
  1589
					break;
d2d6496238e4 (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
  1590
d2d6496238e4 (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
  1591
				default: break;
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1592
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1593
		}
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1594
	}
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1595
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1596
	/* From version 9.0, we update the max passengers of a town (was sometimes negative
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1597
	 *  before that. */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1598
	if (CheckSavegameVersion(9)) {
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1599
		Town *t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1600
		FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1601
	}
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1602
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1603
	/* From version 16.0, we included autorenew on engines, which are now saved, but
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1604
	 *  of course, we do need to initialize them for older savegames. */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1605
	if (CheckSavegameVersion(16)) {
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1606
		FOR_ALL_PLAYERS(p) {
5564
6e1b3ea1ba7f (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
  1607
			p->engine_renew_list   = NULL;
6e1b3ea1ba7f (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
  1608
			p->engine_renew        = false;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1609
			p->engine_renew_months = -6;
5564
6e1b3ea1ba7f (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
  1610
			p->engine_renew_money  = 100000;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1611
		}
5564
6e1b3ea1ba7f (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
  1612
6e1b3ea1ba7f (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
  1613
		/* When loading a game, _local_player is not yet set to the correct value.
6e1b3ea1ba7f (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
  1614
		 * However, in a dedicated server we are a spectator, so nothing needs to
6e1b3ea1ba7f (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
  1615
		 * happen. In case we are not a dedicated server, the local player always
6e1b3ea1ba7f (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
  1616
		 * becomes player 0, unless we are in the scenario editor where all the
6e1b3ea1ba7f (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
  1617
		 * players are 'invalid'.
6e1b3ea1ba7f (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
  1618
		 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1619
		if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) {
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1620
			p = GetPlayer(PLAYER_FIRST);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1621
			p->engine_renew        = _settings_client.gui.autorenew;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1622
			p->engine_renew_months = _settings_client.gui.autorenew_months;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1623
			p->engine_renew_money  = _settings_client.gui.autorenew_money;
2322
962f8825ff6b (svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents: 2297
diff changeset
  1624
		}
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1625
	}
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1626
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1627
	if (CheckSavegameVersion(48)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1628
		for (TileIndex t = 0; t < map_size; t++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1629
			switch (GetTileType(t)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1630
				case MP_RAILWAY:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1631
					if (IsPlainRailTile(t)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1632
						/* Swap ground type and signal type for plain rail tiles, so the
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1633
						 * ground type uses the same bits as for depots and waypoints. */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1634
						uint tmp = GB(_m[t].m4, 0, 4);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1635
						SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1636
						SB(_m[t].m2, 0, 4, tmp);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1637
					} else if (HasBit(_m[t].m5, 2)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1638
						/* Split waypoint and depot rail type and remove the subtype. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1639
						ClrBit(_m[t].m5, 2);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1640
						ClrBit(_m[t].m5, 6);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1641
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1642
					break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1643
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1644
				case MP_ROAD:
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1645
					/* Swap m3 and m4, so the track type for rail crossings is the
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1646
					 * same as for normal rail. */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1647
					Swap(_m[t].m3, _m[t].m4);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1648
					break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1649
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1650
				default: break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1651
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1652
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1653
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1654
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1655
	if (CheckSavegameVersion(61)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1656
		/* Added the RoadType */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1657
		bool old_bridge = CheckSavegameVersion(42);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1658
		for (TileIndex t = 0; t < map_size; t++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1659
			switch(GetTileType(t)) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1660
				case MP_ROAD:
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1661
					SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1662
					switch (GetRoadTileType(t)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1663
						default: NOT_REACHED();
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1664
						case ROAD_TILE_NORMAL:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1665
							SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1666
							SB(_m[t].m4, 4, 4, 0);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1667
							SB(_m[t].m6, 2, 4, 0);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1668
							break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1669
						case ROAD_TILE_CROSSING:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1670
							SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1671
							break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1672
						case ROAD_TILE_DEPOT:    break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1673
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1674
					SetRoadTypes(t, ROADTYPES_ROAD);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1675
					break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1676
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1677
				case MP_STATION:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1678
					if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1679
					break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1680
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1681
				case MP_TUNNELBRIDGE:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1682
					/* Middle part of "old" bridges */
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1683
					if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1684
					if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1685
						SetRoadTypes(t, ROADTYPES_ROAD);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1686
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1687
					break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1688
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1689
				default: break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1690
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1691
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1692
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1693
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1694
	if (CheckSavegameVersion(42)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1695
		Vehicle* v;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1696
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1697
		for (TileIndex t = 0; t < map_size; t++) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1698
			if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1699
			if (IsBridgeTile(t)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1700
				if (HasBit(_m[t].m5, 6)) { // middle part
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1701
					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1702
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1703
					if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1704
						if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1705
							MakeRailNormal(
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1706
								t,
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1707
								GetTileOwner(t),
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1708
								axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1709
								GetRailType(t)
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1710
							);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1711
						} else {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1712
							TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, (uint)-1)->index : 0;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1713
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1714
							MakeRoadNormal(
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1715
								t,
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1716
								axis == AXIS_X ? ROAD_Y : ROAD_X,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1717
								ROADTYPES_ROAD,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1718
								town,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1719
								GetTileOwner(t), OWNER_NONE, OWNER_NONE
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1720
							);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1721
						}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1722
					} else {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1723
						if (GB(_m[t].m5, 3, 2) == 0) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1724
							MakeClear(t, CLEAR_GRASS, 3);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1725
						} else {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1726
							if (GetTileSlope(t, NULL) != SLOPE_FLAT) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1727
								MakeShore(t);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1728
							} else {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1729
								if (GetTileOwner(t) == OWNER_WATER) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1730
									MakeWater(t);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1731
								} else {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1732
									MakeCanal(t, GetTileOwner(t), Random());
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1733
								}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1734
							}
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1735
						}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1736
					}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1737
					SetBridgeMiddle(t, axis);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1738
				} else { // ramp
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1739
					Axis axis = (Axis)GB(_m[t].m5, 0, 1);
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1740
					uint north_south = GB(_m[t].m5, 5, 1);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1741
					DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1742
					TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1743
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1744
					_m[t].m5 = 1 << 7 | type << 2 | dir;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1745
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1746
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1747
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1748
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1749
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1750
			if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1751
			if (IsBridgeTile(v->tile)) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1752
				DiagDirection dir = GetTunnelBridgeDirection(v->tile);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1753
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1754
				if (dir != DirToDiagDir(v->direction)) continue;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1755
				switch (dir) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1756
					default: NOT_REACHED();
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1757
					case DIAGDIR_NE: if ((v->x_pos & 0xF) !=  0)            continue; break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1758
					case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1759
					case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1760
					case DIAGDIR_NW: if ((v->y_pos & 0xF) !=  0)            continue; break;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1761
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1762
			} else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1763
				v->tile = GetNorthernBridgeEnd(v->tile);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1764
			} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1765
				continue;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1766
			}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1767
			if (v->type == VEH_TRAIN) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1768
				v->u.rail.track = TRACK_BIT_WORMHOLE;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1769
			} else {
6326
c904c7ea1c8d (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 6312
diff changeset
  1770
				v->u.road.state = RVSB_WORMHOLE;
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1771
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1772
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1773
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1774
3355
a653b8e47f27 (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
  1775
	/* Elrails got added in rev 24 */
a653b8e47f27 (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
  1776
	if (CheckSavegameVersion(24)) {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1777
		Vehicle *v;
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1778
		RailType min_rail = RAILTYPE_ELECTRIC;
3355
a653b8e47f27 (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
  1779
a653b8e47f27 (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
  1780
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1781
			if (v->type == VEH_TRAIN) {
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 5974
diff changeset
  1782
				RailType rt = RailVehInfo(v->engine_type)->railtype;
3355
a653b8e47f27 (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
  1783
a653b8e47f27 (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
  1784
				v->u.rail.railtype = rt;
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1785
				if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
3355
a653b8e47f27 (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
  1786
			}
a653b8e47f27 (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
  1787
		}
a653b8e47f27 (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
  1788
a653b8e47f27 (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
  1789
		/* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1790
		for (TileIndex t = 0; t < map_size; t++) {
3355
a653b8e47f27 (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
  1791
			switch (GetTileType(t)) {
a653b8e47f27 (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
  1792
				case MP_RAILWAY:
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1793
					SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3355
a653b8e47f27 (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
  1794
					break;
a653b8e47f27 (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
  1795
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1796
				case MP_ROAD:
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1797
					if (IsLevelCrossing(t)) {
6498
aff910a05c6e (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: 6419
diff changeset
  1798
						SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1799
					}
3355
a653b8e47f27 (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
  1800
					break;
a653b8e47f27 (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
  1801
a653b8e47f27 (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
  1802
				case MP_STATION:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1803
					if (IsRailwayStation(t)) {
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1804
						SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1805
					}
3355
a653b8e47f27 (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
  1806
					break;
a653b8e47f27 (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
  1807
a653b8e47f27 (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
  1808
				case MP_TUNNELBRIDGE:
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1809
					if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1810
						SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
3355
a653b8e47f27 (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
  1811
					}
a653b8e47f27 (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
  1812
					break;
a653b8e47f27 (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
  1813
a653b8e47f27 (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
  1814
				default:
a653b8e47f27 (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
  1815
					break;
a653b8e47f27 (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
  1816
			}
a653b8e47f27 (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
  1817
		}
a653b8e47f27 (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
  1818
a653b8e47f27 (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
  1819
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1820
			if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v);
3355
a653b8e47f27 (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
  1821
		}
a653b8e47f27 (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
  1822
a653b8e47f27 (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
  1823
	}
a653b8e47f27 (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
  1824
2805
b6098e7ca457 (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
  1825
	/* In version 16.1 of the savegame a player can decide if trains, which get
b6098e7ca457 (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
  1826
	 * replaced, shall keep their old length. In all prior versions, just default
b6098e7ca457 (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
  1827
	 * to false */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1828
	if (CheckSavegameVersionOldStyle(16, 1)) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1829
		FOR_ALL_PLAYERS(p) p->renew_keep_length = false;
2617
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1830
	}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1831
2670
34970983ef08 (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
  1832
	/* In version 17, ground type is moved from m2 to m4 for depots and
34970983ef08 (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
  1833
	 * waypoints to make way for storing the index in m2. The custom graphics
34970983ef08 (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
  1834
	 * id which was stored in m4 is now saved as a grf/id reference in the
34970983ef08 (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
  1835
	 * waypoint struct. */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1836
	if (CheckSavegameVersion(17)) {
2670
34970983ef08 (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
  1837
		Waypoint *wp;
34970983ef08 (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
  1838
34970983ef08 (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
  1839
		FOR_ALL_WAYPOINTS(wp) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1840
			if (wp->deleted == 0) {
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1841
				const StationSpec *statspec = NULL;
2670
34970983ef08 (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
  1842
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1843
				if (HasBit(_m[wp->xy].m3, 4))
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1844
					statspec = GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
2670
34970983ef08 (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
  1845
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1846
				if (statspec != NULL) {
2670
34970983ef08 (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
  1847
					wp->stat_id = _m[wp->xy].m4 + 1;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1848
					wp->grfid = statspec->grffile->grfid;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1849
					wp->localidx = statspec->localidx;
2670
34970983ef08 (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
  1850
				} else {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1851
					/* No custom graphics set, so set to default. */
2670
34970983ef08 (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
  1852
					wp->stat_id = 0;
34970983ef08 (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
  1853
					wp->grfid = 0;
34970983ef08 (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
  1854
					wp->localidx = 0;
34970983ef08 (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
  1855
				}
34970983ef08 (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
  1856
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1857
				/* Move ground type bits from m2 to m4. */
2670
34970983ef08 (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
  1858
				_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1859
				/* Store waypoint index in the tile. */
2670
34970983ef08 (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
  1860
				_m[wp->xy].m2 = wp->index;
34970983ef08 (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
  1861
			}
34970983ef08 (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
  1862
		}
34970983ef08 (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
  1863
	} else {
34970983ef08 (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
  1864
		/* As of version 17, we recalculate the custom graphic ID of waypoints
34970983ef08 (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
  1865
		 * from the GRF ID / station index. */
5350
db5f6bf223d7 (svn r7521) -Codechange: Rename UpdateAllWaypointCustomGraphics to AfterLoadWaypoints to be more conforming with other such functions.
Darkvater
parents: 5340
diff changeset
  1866
		AfterLoadWaypoints();
2670
34970983ef08 (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
  1867
	}
34970983ef08 (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
  1868
2916
8f1aa489701f (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
  1869
	/* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
8f1aa489701f (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
  1870
	 *  room for PBS. Now in version 21 move it back :P. */
8f1aa489701f (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
  1871
	if (CheckSavegameVersion(21) && !CheckSavegameVersion(15)) {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1872
		for (TileIndex t = 0; t < map_size; t++) {
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1873
			switch (GetTileType(t)) {
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1874
				case MP_RAILWAY:
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1875
					if (HasSignals(t)) {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1876
						/* convert PBS signals to combo-signals */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1877
						if (HasBit(_m[t].m2, 2)) SetSignalType(t, TRACK_X, SIGTYPE_COMBO);
2916
8f1aa489701f (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
  1878
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1879
						/* move the signal variant back */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1880
						SetSignalVariant(t, TRACK_X, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1881
						ClrBit(_m[t].m2, 3);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1882
					}
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1883
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1884
					/* Clear PBS reservation on track */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1885
					if (!IsRailDepotTile(t)) {
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1886
						SB(_m[t].m4, 4, 4, 0);
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1887
					} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1888
						ClrBit(_m[t].m3, 6);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1889
					}
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1890
					break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1891
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6730
diff changeset
  1892
				case MP_ROAD: /* Clear PBS reservation on crossing */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1893
					if (IsLevelCrossing(t)) ClrBit(_m[t].m5, 0);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1894
					break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1895
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6659
diff changeset
  1896
				case MP_STATION: /* Clear PBS reservation on station */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1897
					ClrBit(_m[t].m3, 6);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1898
					break;
2916
8f1aa489701f (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
  1899
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1900
				default: break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1901
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1902
		}
2916
8f1aa489701f (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
  1903
	}
8f1aa489701f (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
  1904
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1905
	if (CheckSavegameVersion(25)) {
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1906
		Vehicle *v;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1907
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1908
			if (v->type == VEH_ROAD) {
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1909
				v->vehstatus &= ~0x40;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1910
				v->u.road.slot = NULL;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1911
				v->u.road.slot_age = 0;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1912
			}
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1913
		}
5928
d57921d78ee6 (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: 5910
diff changeset
  1914
	} else {
d57921d78ee6 (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: 5910
diff changeset
  1915
		Vehicle *v;
d57921d78ee6 (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: 5910
diff changeset
  1916
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1917
			if (v->type == VEH_ROAD && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++;
5928
d57921d78ee6 (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: 5910
diff changeset
  1918
		}
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1919
	}
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1920
3580
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1921
	if (CheckSavegameVersion(26)) {
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1922
		Station *st;
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1923
		FOR_ALL_STATIONS(st) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  1924
			st->last_vehicle_type = VEH_INVALID;
3580
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1925
		}
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1926
	}
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3558
diff changeset
  1927
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1928
	YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1929
4603
3ccd4ee0a2e2 (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
  1930
	if (CheckSavegameVersion(34)) FOR_ALL_PLAYERS(p) ResetPlayerLivery(p);
3ccd4ee0a2e2 (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
  1931
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1932
	FOR_ALL_PLAYERS(p) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1933
		p->avail_railtypes = GetPlayerRailtypes(p->index);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1934
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1935
	}
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1936
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1937
	if (!CheckSavegameVersion(27)) AfterLoadStations();
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1938
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1939
	/* Time starts at 0 instead of 1920.
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1940
	 * Account for this in older games by adding an offset */
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1941
	if (CheckSavegameVersion(31)) {
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1942
		Station *st;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1943
		Waypoint *wp;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1944
		Engine *e;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1945
		Player *player;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1946
		Industry *i;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1947
		Vehicle *v;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1948
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1949
		_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
4383
3dcf52b1efd9 (svn r6136) -Fix: _cur_year wasn't converting when reading pre-31 savegames, causing nasty desyncs
truelight
parents: 4349
diff changeset
  1950
		_cur_year += ORIGINAL_BASE_YEAR;
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1951
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1952
		FOR_ALL_STATIONS(st)    st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1953
		FOR_ALL_WAYPOINTS(wp)   wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1954
		FOR_ALL_ENGINES(e)      e->intro_date  += DAYS_TILL_ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1955
		FOR_ALL_PLAYERS(player) player->inaugurated_year += ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1956
		FOR_ALL_INDUSTRIES(i)   i->last_prod_year        += ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1957
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1958
		FOR_ALL_VEHICLES(v) {
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1959
			v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1960
			v->build_year += ORIGINAL_BASE_YEAR;
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1961
		}
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1962
	}
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1963
4328
23dd79414386 (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
  1964
	/* From 32 on we save the industry who made the farmland.
23dd79414386 (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
  1965
	 *  To give this prettyness to old savegames, we remove all farmfields and
23dd79414386 (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
  1966
	 *  plant new ones. */
23dd79414386 (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
  1967
	if (CheckSavegameVersion(32)) {
23dd79414386 (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
  1968
		Industry *i;
23dd79414386 (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
  1969
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1970
		for (TileIndex t = 0; t < map_size; t++) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1971
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1972
				/* remove fields */
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1973
				MakeClear(t, CLEAR_GRASS, 3);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1974
			} else if (IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1975
				/* remove fences around fields */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1976
				SetFenceSE(t, 0);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1977
				SetFenceSW(t, 0);
4328
23dd79414386 (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
  1978
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1979
		}
4328
23dd79414386 (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
  1980
23dd79414386 (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
  1981
		FOR_ALL_INDUSTRIES(i) {
23dd79414386 (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
  1982
			uint j;
23dd79414386 (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
  1983
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  1984
			if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
4328
23dd79414386 (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
  1985
				for (j = 0; j != 50; j++) PlantRandomFarmField(i);
23dd79414386 (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
  1986
			}
23dd79414386 (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
  1987
		}
23dd79414386 (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
  1988
	}
23dd79414386 (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
  1989
4712
273ec3b182bf (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
  1990
	/* Setting no refit flags to all orders in savegames from before refit in orders were added */
273ec3b182bf (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
  1991
	if (CheckSavegameVersion(36)) {
273ec3b182bf (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
  1992
		Order *order;
273ec3b182bf (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
  1993
		Vehicle *v;
273ec3b182bf (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
  1994
273ec3b182bf (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
  1995
		FOR_ALL_ORDERS(order) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1996
			order->SetRefit(CT_NO_REFIT);
4712
273ec3b182bf (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
  1997
		}
273ec3b182bf (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
  1998
273ec3b182bf (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
  1999
		FOR_ALL_VEHICLES(v) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2000
			v->current_order.SetRefit(CT_NO_REFIT);
4712
273ec3b182bf (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
  2001
		}
273ec3b182bf (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
  2002
	}
273ec3b182bf (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
  2003
5314
021dbca1d6da (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
  2004
	/* from version 38 we have optional elrails, since we cannot know the
021dbca1d6da (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
  2005
	 * preference of a user, let elrails enabled; it can be disabled manually */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2006
	if (CheckSavegameVersion(38)) _settings_game.vehicle.disable_elrails = false;
6099
85bbae40f52c (svn r8422) -Fix
tron
parents: 6074
diff changeset
  2007
	/* do the same as when elrails were enabled/disabled manually just now */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2008
	SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2009
	InitializeRailGUI();
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  2010
6659
9e786755ed61 (svn r9316) -Fix (r9315): Bump the savegame version for the newhouses merge.
maedhros
parents: 6658
diff changeset
  2011
	/* From version 53, the map array was changed for house tiles to allow
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2012
	 * space for newhouses grf features. A new byte, m7, was also added. */
6659
9e786755ed61 (svn r9316) -Fix (r9315): Bump the savegame version for the newhouses merge.
maedhros
parents: 6658
diff changeset
  2013
	if (CheckSavegameVersion(53)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2014
		for (TileIndex t = 0; t < map_size; t++) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2015
			if (IsTileType(t, MP_HOUSE)) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2016
				if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2017
					/* Move the construction stage from m3[7..6] to m5[5..4].
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2018
					 * The construction counter does not have to move. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2019
					SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2020
					SB(_m[t].m3, 6, 2, 0);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2021
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2022
					/* The "house is completed" bit is now in m6[2]. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2023
					SetHouseCompleted(t, false);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2024
				} else {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2025
					/* The "lift has destination" bit has been moved from
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2026
					 * m5[7] to m7[0]. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2027
					SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2028
					ClrBit(_m[t].m5, 7);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2029
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2030
					/* The "lift is moving" bit has been removed, as it does
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2031
					 * the same job as the "lift has destination" bit. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2032
					ClrBit(_m[t].m1, 7);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2033
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2034
					/* The position of the lift goes from m1[7..0] to m6[7..2],
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2035
					 * making m1 totally free, now. The lift position does not
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2036
					 * have to be a full byte since the maximum value is 36. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2037
					SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2038
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2039
					_m[t].m1 = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2040
					_m[t].m3 = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2041
					SetHouseCompleted(t, true);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2042
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2043
			}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2044
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2045
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2046
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2047
	/* Check and update house and town values */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2048
	UpdateHousesAndTowns();
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6643
diff changeset
  2049
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2050
	if (CheckSavegameVersion(43)) {
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2051
		for (TileIndex t = 0; t < map_size; t++) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2052
			if (IsTileType(t, MP_INDUSTRY)) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2053
				switch (GetIndustryGfx(t)) {
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2054
					case GFX_POWERPLANT_SPARKS:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2055
						SetIndustryAnimationState(t, GB(_m[t].m1, 2, 5));
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2056
						break;
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2057
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2058
					case GFX_OILWELL_ANIMATED_1:
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2059
					case GFX_OILWELL_ANIMATED_2:
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2060
					case GFX_OILWELL_ANIMATED_3:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2061
						SetIndustryAnimationState(t, GB(_m[t].m1, 0, 2));
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2062
						break;
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2063
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2064
					case GFX_COAL_MINE_TOWER_ANIMATED:
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2065
					case GFX_COPPER_MINE_TOWER_ANIMATED:
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2066
					case GFX_GOLD_MINE_TOWER_ANIMATED:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2067
						 SetIndustryAnimationState(t, _m[t].m1);
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2068
						 break;
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2069
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2070
					default: /* No animation states to change */
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2071
						break;
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2072
				}
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2073
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  2074
		}
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2075
	}
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  2076
5934
9f91cc4e2b17 (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: 5928
diff changeset
  2077
	if (CheckSavegameVersion(44)) {
9f91cc4e2b17 (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: 5928
diff changeset
  2078
		Vehicle *v;
9f91cc4e2b17 (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: 5928
diff changeset
  2079
		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2080
		 * 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
5934
9f91cc4e2b17 (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: 5928
diff changeset
  2081
		 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2082
		 * where this situation exists, the cargo-source information is lost. in this case, we set the source
5934
9f91cc4e2b17 (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: 5928
diff changeset
  2083
		 * to the current tile of the vehicle to prevent excessive profits
9f91cc4e2b17 (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: 5928
diff changeset
  2084
		 */
9f91cc4e2b17 (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: 5928
diff changeset
  2085
		FOR_ALL_VEHICLES(v) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2086
			const CargoList::List *packets = v->cargo.Packets();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2087
			for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2088
				CargoPacket *cp = *it;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2089
				cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : v->tile;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2090
				cp->loaded_at_xy = cp->source_xy;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2091
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2092
			v->cargo.InvalidateCache();
5934
9f91cc4e2b17 (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: 5928
diff changeset
  2093
		}
6630
4fa4f6d883ba (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: 6585
diff changeset
  2094
4fa4f6d883ba (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: 6585
diff changeset
  2095
		/* Store position of the station where the goods come from, so there
4fa4f6d883ba (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: 6585
diff changeset
  2096
		 * are no very high payments when stations get removed. However, if the
4fa4f6d883ba (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: 6585
diff changeset
  2097
		 * station where the goods came from is already removed, the source
4fa4f6d883ba (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: 6585
diff changeset
  2098
		 * information is lost. In that case we set it to the position of this
4fa4f6d883ba (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: 6585
diff changeset
  2099
		 * station */
4fa4f6d883ba (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: 6585
diff changeset
  2100
		Station *st;
4fa4f6d883ba (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: 6585
diff changeset
  2101
		FOR_ALL_STATIONS(st) {
4fa4f6d883ba (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: 6585
diff changeset
  2102
			for (CargoID c = 0; c < NUM_CARGO; c++) {
4fa4f6d883ba (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: 6585
diff changeset
  2103
				GoodsEntry *ge = &st->goods[c];
4fa4f6d883ba (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: 6585
diff changeset
  2104
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2105
				const CargoList::List *packets = ge->cargo.Packets();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2106
				for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2107
					CargoPacket *cp = *it;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2108
					cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : st->xy;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2109
					cp->loaded_at_xy = cp->source_xy;
6630
4fa4f6d883ba (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: 6585
diff changeset
  2110
				}
4fa4f6d883ba (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: 6585
diff changeset
  2111
			}
4fa4f6d883ba (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: 6585
diff changeset
  2112
		}
5934
9f91cc4e2b17 (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: 5928
diff changeset
  2113
	}
9f91cc4e2b17 (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: 5928
diff changeset
  2114
6139
e80b90da75e5 (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: 6137
diff changeset
  2115
	if (CheckSavegameVersion(45)) {
e80b90da75e5 (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: 6137
diff changeset
  2116
		Vehicle *v;
e80b90da75e5 (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: 6137
diff changeset
  2117
		/* Originally just the fact that some cargo had been paid for was
e80b90da75e5 (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: 6137
diff changeset
  2118
		 * stored to stop people cheating and cashing in several times. This
e80b90da75e5 (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: 6137
diff changeset
  2119
		 * wasn't enough though as it was cleared when the vehicle started
e80b90da75e5 (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: 6137
diff changeset
  2120
		 * loading again, even if it didn't actually load anything, so now the
e80b90da75e5 (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: 6137
diff changeset
  2121
		 * amount of cargo that has been paid for is stored. */
e80b90da75e5 (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: 6137
diff changeset
  2122
		FOR_ALL_VEHICLES(v) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2123
			const CargoList::List *packets = v->cargo.Packets();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2124
			for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2125
				CargoPacket *cp = *it;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2126
				cp->paid_for = HasBit(v->vehicle_flags, 2);
6139
e80b90da75e5 (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: 6137
diff changeset
  2127
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2128
			ClrBit(v->vehicle_flags, 2);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2129
			v->cargo.InvalidateCache();
6139
e80b90da75e5 (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: 6137
diff changeset
  2130
		}
e80b90da75e5 (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: 6137
diff changeset
  2131
	}
e80b90da75e5 (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: 6137
diff changeset
  2132
6312
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2133
	/* Buoys do now store the owner of the previous water tile, which can never
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2134
	 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2135
	if (CheckSavegameVersion(46)) {
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2136
		Station *st;
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2137
		FOR_ALL_STATIONS(st) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2138
			if (st->IsBuoy() && IsTileOwner(st->xy, OWNER_NONE) && TileHeight(st->xy) == 0) SetTileOwner(st->xy, OWNER_WATER);
6312
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2139
		}
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2140
	}
eeb950ae2a1b (svn r8689) -Fix [FS#613] (r8619): crash when an old savegame had buoys on the northern edge of the map.
rubidium
parents: 6228
diff changeset
  2141
6519
367d6f96e23f (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: 6516
diff changeset
  2142
	if (CheckSavegameVersion(50)) {
367d6f96e23f (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: 6516
diff changeset
  2143
		Vehicle *v;
367d6f96e23f (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: 6516
diff changeset
  2144
		/* Aircraft units changed from 8 mph to 1 km/h */
367d6f96e23f (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: 6516
diff changeset
  2145
		FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6583
diff changeset
  2146
			if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) {
6519
367d6f96e23f (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: 6516
diff changeset
  2147
				const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
367d6f96e23f (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: 6516
diff changeset
  2148
				v->cur_speed *= 129;
367d6f96e23f (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: 6516
diff changeset
  2149
				v->cur_speed /= 10;
367d6f96e23f (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: 6516
diff changeset
  2150
				v->max_speed = avi->max_speed;
367d6f96e23f (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: 6516
diff changeset
  2151
				v->acceleration = avi->acceleration;
367d6f96e23f (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: 6516
diff changeset
  2152
			}
367d6f96e23f (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: 6516
diff changeset
  2153
		}
367d6f96e23f (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: 6516
diff changeset
  2154
	}
367d6f96e23f (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: 6516
diff changeset
  2155
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6501
diff changeset
  2156
	if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face);
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6501
diff changeset
  2157
6583
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2158
	if (CheckSavegameVersion(52)) {
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2159
		for (TileIndex t = 0; t < map_size; t++) {
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2160
			if (IsStatueTile(t)) {
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2161
				_m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index;
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2162
			}
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2163
		}
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2164
	}
82012e77b10c (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents: 6573
diff changeset
  2165
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2166
	/* A patch option containing the proportion of towns that grow twice as
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2167
	 * fast was added in version 54. From version 56 this is now saved in the
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2168
	 * town as cities can be built specifically in the scenario editor. */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2169
	if (CheckSavegameVersion(56)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2170
		Town *t;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2171
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2172
		FOR_ALL_TOWNS(t) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2173
			if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2174
				t->larger_town = true;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2175
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2176
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2177
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2178
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2179
	if (CheckSavegameVersion(57)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2180
		Vehicle *v;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2181
		/* Added a FIFO queue of vehicles loading at stations */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2182
		FOR_ALL_VEHICLES(v) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2183
			if ((v->type != VEH_TRAIN || IsFrontEngine(v)) &&  // for all locs
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2184
					!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2185
					v->current_order.IsType(OT_LOADING)) {         // loading
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2186
				GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2187
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2188
				/* The loading finished flag is *only* set when actually completely
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2189
				 * finished. Because the vehicle is loading, it is not finished. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2190
				ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2191
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2192
		}
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2193
	} else if (CheckSavegameVersion(59)) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2194
		/* For some reason non-loading vehicles could be in the station's loading vehicle list */
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2195
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2196
		Station *st;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2197
		FOR_ALL_STATIONS(st) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2198
			std::list<Vehicle *>::iterator iter;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2199
			for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2200
				Vehicle *v = *iter;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2201
				iter++;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2202
				if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2203
			}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2204
		}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2205
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2206
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2207
	if (CheckSavegameVersion(58)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2208
		/* patch difficulty number_industries other then zero get bumped to +1
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2209
		 * since a new option (very low at position1) has been added */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2210
		if (_settings_game.difficulty.number_industries > 0) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2211
			_settings_game.difficulty.number_industries++;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2212
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2213
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2214
		/* Same goes for number of towns, although no test is needed, just an increment */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2215
		_settings_game.difficulty.number_towns++;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2216
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2217
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2218
	if (CheckSavegameVersion(64)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2219
		/* copy the signal type/variant and move signal states bits */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2220
		for (TileIndex t = 0; t < map_size; t++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2221
			if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2222
				SetSignalStates(t, GB(_m[t].m2, 4, 4));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2223
				SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2224
				SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2225
				ClrBit(_m[t].m2, 7);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2226
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2227
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2228
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2229
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2230
	if (CheckSavegameVersion(69)) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2231
		/* In some old savegames a bit was cleared when it should not be cleared */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2232
		Vehicle *v;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2233
		FOR_ALL_VEHICLES(v) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2234
			if (v->type == VEH_ROAD && (v->u.road.state == 250 || v->u.road.state == 251)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2235
				SetBit(v->u.road.state, RVS_IS_STOPPING);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2236
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2237
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2238
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2239
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2240
	if (CheckSavegameVersion(70)) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2241
		/* Added variables to support newindustries */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2242
		Industry *i;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2243
		FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2244
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2245
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2246
	/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2247
	    Replace the owner for those by OWNER_NONE. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2248
	if (CheckSavegameVersion(82)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2249
		for (TileIndex t = 0; t < map_size; t++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2250
			if (IsTileType(t, MP_WATER) &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2251
					GetWaterTileType(t) == WATER_TILE_CLEAR &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2252
					GetTileOwner(t) == OWNER_WATER &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2253
					TileHeight(t) != 0) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2254
				SetTileOwner(t, OWNER_NONE);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2255
			}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2256
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2257
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6677
diff changeset
  2258
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2259
	/*
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2260
	 * Add the 'previous' owner to the ship depots so we can reset it with
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2261
	 * the correct values when it gets destroyed. This prevents that
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2262
	 * someone can remove canals owned by somebody else and it prevents
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2263
	 * making floods using the removal of ship depots.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2264
	 */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2265
	if (CheckSavegameVersion(83)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2266
		for (TileIndex t = 0; t < map_size; t++) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2267
			if (IsTileType(t, MP_WATER) && IsShipDepot(t)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2268
				_m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2269
			}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2270
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2271
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2272
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2273
	if (CheckSavegameVersion(74)) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2274
		Station *st;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2275
		FOR_ALL_STATIONS(st) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2276
			for (CargoID c = 0; c < NUM_CARGO; c++) {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2277
				st->goods[c].last_speed = 0;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2278
				if (st->goods[c].cargo.Count() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::PICKUP);
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2279
			}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2280
		}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2281
	}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6854
diff changeset
  2282
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2283
	if (CheckSavegameVersion(78)) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2284
		Industry *i;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2285
		uint j;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2286
		FOR_ALL_INDUSTRIES(i) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2287
			const IndustrySpec *indsp = GetIndustrySpec(i->type);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2288
			for (j = 0; j < lengthof(i->produced_cargo); j++) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2289
				i->produced_cargo[j] = indsp->produced_cargo[j];
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2290
			}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2291
			for (j = 0; j < lengthof(i->accepts_cargo); j++) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2292
				i->accepts_cargo[j] = indsp->accepts_cargo[j];
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2293
			}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2294
		}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2295
	}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2296
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2297
	/* Before version 81, the density of grass was always stored as zero, and
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2298
	 * grassy trees were always drawn fully grassy. Furthermore, trees on rough
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2299
	 * land used to have zero density, now they have full density. Therefore,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2300
	 * make all grassy/rough land trees have a density of 3. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2301
	if (CheckSavegameVersion(81)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2302
		for (TileIndex t = 0; t < map_size; t++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2303
			if (GetTileType(t) == MP_TREES) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2304
				TreeGround groundType = GetTreeGround(t);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2305
				if (groundType != TREE_GROUND_SNOW_DESERT) SetTreeGroundDensity(t, groundType, 3);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2306
			}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2307
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2308
	}
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6838
diff changeset
  2309
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2310
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2311
	if (CheckSavegameVersion(93)) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2312
		/* Rework of orders. */
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2313
		Order *order;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2314
		FOR_ALL_ORDERS(order) order->ConvertFromOldSavegame();
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2315
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2316
		Vehicle *v;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2317
		FOR_ALL_VEHICLES(v) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2318
			if (v->orders != NULL && !v->orders->IsValid()) v->orders = NULL;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2319
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2320
			v->current_order.ConvertFromOldSavegame();
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2321
			if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->prev_shared == NULL) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2322
				FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2323
			}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2324
		}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2325
	} else if (CheckSavegameVersion(94)) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2326
		/* Unload and transfer are now mutual exclusive. */
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2327
		Order *order;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2328
		FOR_ALL_ORDERS(order) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2329
			if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2330
				order->SetUnloadType(OUFB_TRANSFER);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2331
				order->SetLoadType(OLFB_NO_LOAD);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2332
			}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2333
		}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2334
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2335
		Vehicle *v;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2336
		FOR_ALL_VEHICLES(v) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2337
			if ((v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2338
				v->current_order.SetUnloadType(OUFB_TRANSFER);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2339
				v->current_order.SetLoadType(OLFB_NO_LOAD);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2340
			}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2341
		}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2342
	}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10192
diff changeset
  2343
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2344
	if (CheckSavegameVersion(84)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2345
		/* Update go to buoy orders because they are just waypoints */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2346
		Order *order;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2347
		FOR_ALL_ORDERS(order) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2348
			if (order->IsType(OT_GOTO_STATION) && GetStation(order->GetDestination())->IsBuoy()) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2349
				order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2350
				order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2351
			}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2352
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2353
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2354
		/* Set all share owners to PLAYER_SPECTATOR for
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2355
		 * 1) all inactive players
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2356
		 *     (when inactive players were stored in the savegame - TTD, TTDP and some
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2357
		 *      *really* old revisions of OTTD; else it is already set in InitializePlayers())
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2358
		 * 2) shares that are owned by inactive players or self
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2359
		 *     (caused by cheating players in earlier revisions) */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2360
		Player *p;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2361
		FOR_ALL_PLAYERS(p) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2362
			if (!p->is_active) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2363
				for (uint i = 0; i < 4; i++) { p->share_owners[i] = PLAYER_SPECTATOR; }
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2364
			} else {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2365
				for (uint i = 0; i < 4; i++) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2366
					PlayerID o = p->share_owners[i];
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2367
					if (o == PLAYER_SPECTATOR) continue;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2368
					if (!IsValidPlayer(o) || o == p->index || !GetPlayer(o)->is_active) p->share_owners[i] = PLAYER_SPECTATOR;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2369
				}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2370
			}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2371
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2372
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2373
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2374
	if (CheckSavegameVersion(86)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2375
		for (TileIndex t = 0; t < map_size; t++) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2376
			/* Now all crossings should be in correct state */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2377
			if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2378
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2379
			/* Move river flag and update canals to use water class */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2380
			if (IsTileType(t, MP_WATER)) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2381
				if (GetWaterClass(t) != WATER_CLASS_RIVER) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2382
					if (IsWater(t)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2383
						Owner o = GetTileOwner(t);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2384
						if (o == OWNER_WATER) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2385
							MakeWater(t);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2386
						} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2387
							MakeCanal(t, o, Random());
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2388
						}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2389
					} else if (IsShipDepot(t)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2390
						Owner o = (Owner)_m[t].m4; // Original water owner
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2391
						SetWaterClass(t, o == OWNER_WATER ? WATER_CLASS_SEA : WATER_CLASS_CANAL);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2392
					}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2393
				}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2394
			}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2395
		}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2396
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2397
		/* Update locks, depots, docks and buoys to have a water class based
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2398
		 * on its neighbouring tiles. Done after river and canal updates to
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2399
		 * ensure neighbours are correct. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2400
		for (TileIndex t = 0; t < map_size; t++) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2401
			if (GetTileSlope(t, NULL) != SLOPE_FLAT) continue;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2402
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2403
			if (IsTileType(t, MP_WATER) && IsLock(t)) SetWaterClassDependingOnSurroundings(t);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2404
			if (IsTileType(t, MP_STATION) && (IsDock(t) || IsBuoy(t))) SetWaterClassDependingOnSurroundings(t);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2405
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2406
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2407
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2408
	if (CheckSavegameVersion(87)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2409
		for (TileIndex t = 0; t < map_size; t++) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2410
			/* skip oil rigs at borders! */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2411
			if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2412
					(TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2413
				/* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2414
				 * This conversion has to be done before buoys with invalid owner are removed. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2415
				SetWaterClass(t, WATER_CLASS_SEA);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2416
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2417
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2418
			if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2419
				Owner o = GetTileOwner(t);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2420
				if (IsValidPlayer(o) && !GetPlayer(o)->is_active) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2421
					_current_player = o;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2422
					ChangeTileOwner(t, o, PLAYER_SPECTATOR);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2423
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2424
				if (IsBuoyTile(t)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2425
					/* reset buoy owner to OWNER_NONE in the station struct
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2426
					 * (even if it is owned by active player) */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2427
					GetStationByTile(t)->owner = OWNER_NONE;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2428
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2429
			} else if (IsTileType(t, MP_ROAD)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2430
				/* works for all RoadTileType */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2431
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2432
					/* update even non-existing road types to update tile owner too */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2433
					Owner o = GetRoadOwner(t, rt);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2434
					if (IsValidPlayer(o) && !GetPlayer(o)->is_active) SetRoadOwner(t, rt, OWNER_NONE);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2435
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2436
				if (IsLevelCrossing(t)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2437
					Owner o = GetTileOwner(t);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2438
					if (!GetPlayer(o)->is_active) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2439
						/* remove leftover rail piece from crossing (from very old savegames) */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2440
						_current_player = o;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2441
						DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2442
					}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2443
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2444
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2445
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2446
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2447
		/* Convert old PF settings to new */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2448
		if (_settings_game.pf.yapf.rail_use_yapf || CheckSavegameVersion(28)) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2449
			_settings_game.pf.pathfinder_for_trains = VPF_YAPF;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2450
		} else {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2451
			_settings_game.pf.pathfinder_for_trains = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_NTP);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2452
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2453
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2454
		if (_settings_game.pf.yapf.road_use_yapf || CheckSavegameVersion(28)) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2455
			_settings_game.pf.pathfinder_for_roadvehs = VPF_YAPF;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2456
		} else {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2457
			_settings_game.pf.pathfinder_for_roadvehs = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2458
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2459
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2460
		if (_settings_game.pf.yapf.ship_use_yapf) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2461
			_settings_game.pf.pathfinder_for_ships = VPF_YAPF;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2462
		} else {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2463
			_settings_game.pf.pathfinder_for_ships = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2464
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2465
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2466
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2467
	if (CheckSavegameVersion(88)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2468
		/* Profits are now with 8 bit fract */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2469
		Vehicle *v;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2470
		FOR_ALL_VEHICLES(v) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2471
			v->profit_this_year <<= 8;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2472
			v->profit_last_year <<= 8;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2473
			v->running_ticks = 0;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2474
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2475
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2476
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2477
	if (CheckSavegameVersion(91)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2478
		/* Increase HouseAnimationFrame from 5 to 7 bits */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2479
		for (TileIndex t = 0; t < map_size; t++) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2480
			if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2481
				SetHouseAnimationFrame(t, GB(_m[t].m6, 3, 5));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2482
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2483
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2484
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2485
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2486
	if (CheckSavegameVersion(62)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2487
		/* Remove all trams from savegames without tram support.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2488
		 * There would be trams without tram track under causing crashes sooner or later. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2489
		Vehicle *v;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2490
		FOR_ALL_VEHICLES(v) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2491
			if (v->type == VEH_ROAD && v->First() == v &&
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2492
					HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2493
				if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2494
					_switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2495
				}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2496
				delete v;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2497
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2498
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2499
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2500
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2501
	if (_debug_gamelog_level > 0) GamelogPrintDebug();
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2502
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2503
	return InitializeWindowsAndCaches();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2504
}
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2505
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2506
/** Reload all NewGRF files during a running game. This is a cut-down
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2507
 * version of AfterLoadGame().
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2508
 * XXX - We need to reset the vehicle position hash because with a non-empty
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2509
 * hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles()
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2510
 * to recalculate vehicle data as some NewGRF vehicle sets could have been
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2511
 * removed or added and changed statistics */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2512
void ReloadNewGRFData()
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2513
{
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2514
	/* reload grf data */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2515
	GfxLoadSprites();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2516
	LoadStringWidthTable();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2517
	/* reload vehicles */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2518
	ResetVehiclePosHash();
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2519
	AfterLoadVehicles(false);
6522
bf0da9f42953 (svn r8976) -Codechange: Reinitialize all engines after grf files have been reloaded/changed.
Darkvater
parents: 6519
diff changeset
  2520
	StartupEngines();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2521
	SetCachedEngineCounts();
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2522
	/* update station and waypoint graphics */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2523
	AfterLoadWaypoints();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2524
	AfterLoadStations();
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2525
	/* Check and update house and town values */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2526
	UpdateHousesAndTowns();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2527
	/* Update livery selection windows */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2528
	for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) InvalidateWindowData(WC_PLAYER_COLOR, i, _loaded_newgrf_features.has_2CC);
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2529
	/* redraw the whole screen */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2530
	MarkWholeScreenDirty();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2531
}