src/openttd.cpp
author celestar
Tue, 19 Jun 2007 07:21:01 +0000
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
permissions -rw-r--r--
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
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
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
     3
/** @file openttd.cpp */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
     6
#define VARDEF
1317
f382f1b439c7 (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1314
diff changeset
     7
#include "string.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     8
#include "table/strings.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1296
diff changeset
     9
#include "debug.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
    10
#include "driver.h"
2162
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 2147
diff changeset
    11
#include "saveload.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1301
diff changeset
    12
#include "strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 659
diff changeset
    13
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1199
diff changeset
    14
#include "tile.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3121
diff changeset
    15
#include "void_map.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    16
#include "helpers.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
    18
#include "openttd.h"
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    19
#include "bridge_map.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2162
diff changeset
    20
#include "functions.h"
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
    21
#include "mixer.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1329
diff changeset
    22
#include "spritecache.h"
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4880
diff changeset
    23
#include "strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "gfx.h"
2340
0a9f3eeccb96 (svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents: 2322
diff changeset
    25
#include "gfxinit.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#include "gui.h"
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
    27
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#include "station.h"
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    29
#include "station_map.h"
3558
36ca79c931f2 (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
    30
#include "town_map.h"
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
    31
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
#include "sound.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
#include "fileio.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
#include "hal.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
#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
    46
#include "aircraft.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 123
diff changeset
    47
#include "console.h"
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    48
#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
    49
#include "network/network.h"
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
    50
#include "signs.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1310
diff changeset
    51
#include "depot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
    52
#include "waypoint.h"
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
    53
#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
    54
#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
    55
#include "yapf/yapf.h"
3889
cc4a8556c19d (svn r4945) Fix (r3726): make -t command line option (set starting date/year) work again
rubidium
parents: 3765
diff changeset
    56
#include "settings.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
    57
#include "genworld.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4260
diff changeset
    58
#include "date.h"
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
    59
#include "clear_map.h"
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
    60
#include "fontcache.h"
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
    61
#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
    62
#include "newgrf_config.h"
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
    63
#include "newgrf_house.h"
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    64
#include "newgrf_commons.h"
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6501
diff changeset
    65
#include "player_face.h"
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
    66
#include "group.h"
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
    67
#include "blitter/factory.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
    69
#include "bridge_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
    70
#include "clear_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
    71
#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
    72
#include "road_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
    73
#include "water_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
    74
#include "industry_map.h"
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    75
#include "unmovable_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
    76
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    79
void CallLandscapeTick();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    80
void IncreaseDate();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    81
void DoPaletteAnimations();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    82
void MusicLoop();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
    83
void ResetMusic();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    86
extern Player* DoStartupNewPlayer(bool is_ai);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
extern void ShowOSErrorBox(const char *buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
    89
const char *_default_blitter = "8bpp-optimized";
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
    90
1436
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    91
/* TODO: usrerror() for errors which are not of an internal nature but
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    92
 * caused by the user, i.e. missing files or fatal configuration errors.
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    93
 * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */
8a9892695dcb (svn r1940) TODO about usrerror().
pasky
parents: 1406
diff changeset
    94
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
    95
void CDECL error(const char *s, ...)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    96
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
	char buf[512];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
    99
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	va_start(va, s);
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   101
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	va_end(va);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   103
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	ShowOSErrorBox(buf);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   105
	if (_video_driver != NULL) _video_driver->stop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
void CDECL ShowInfoF(const char *str, ...)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	va_start(va, str);
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   116
	vsnprintf(buf, lengthof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
	va_end(va);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	ShowInfo(buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
1310
85cde2193afc (svn r1814) Let ReadFileToMem() return void* (instead of byte*) because we don't know what the caller wants to do with the data
tron
parents: 1309
diff changeset
   122
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	FILE *in;
1105
b3003b14e45c (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   125
	byte *mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	size_t len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	in = fopen(filename, "rb");
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   129
	if (in == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	fseek(in, 0, SEEK_END);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	len = ftell(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	fseek(in, 0, SEEK_SET);
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   134
	if (len > maxsize || (mem = MallocT<byte>(len + 1)) == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	}
1105
b3003b14e45c (svn r1606) Fix some bogus casts
tron
parents: 1095
diff changeset
   138
	mem[len] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	if (fread(mem, len, 1, in) != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
		fclose(in);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
		free(mem);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	fclose(in);
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
	*lenp = len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	return mem;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   150
extern const char _openttd_revision[];
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   151
static void showhelp()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	char buf[4096], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   155
	p = buf;
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   156
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   157
	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
   158
	p = strecpy(p,
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   159
		"\n"
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   160
		"\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
		"Command line options:\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   162
		"  -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
   163
		"  -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
   164
		"  -m drv              = Set music driver (see below)\n"
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   165
		"  -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
   166
		"  -r res              = Set resolution (for instance 800x600)\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   167
		"  -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
   168
		"  -t year             = Set starting year\n"
1440
2eb4dd1e0465 (svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents: 1436
diff changeset
   169
		"  -d [[fac=]lvl[,...]]= Debug mode\n"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   170
		"  -e                  = Start Editor\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   171
		"  -g [savegame]       = Start new/save game immediately\n"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   172
		"  -G seed             = Set random seed\n"
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   173
#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
   174
		"  -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
   175
		"  -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
   176
		"  -l ip[:port]        = Redirect DEBUG()\n"
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   177
#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
   178
		"  -f                  = Fork into the background (dedicated only)\n"
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   179
#endif
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   180
#endif /* ENABLE_NETWORK */
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   181
		"  -i                  = Force to use the DOS palette\n"
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2828
diff changeset
   182
		"                          (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
   183
		"  -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
   184
		"  -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
   185
		lastof(buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 5166
diff changeset
   188
	p = GetDriverList(p, lastof(buf));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   190
	/* List the blitters */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   191
	p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   192
5974
7de3ff0166f8 (svn r8240) -Fix (r8013): Put the output of -h to stdout and not to stderr (through ShowInfo)
Darkvater
parents: 5958
diff changeset
   193
	/* 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
   194
	 * 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
   195
#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
   196
	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
   197
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	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
   199
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   203
struct MyGetOptData {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	char *opt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	int numleft;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	char **argv;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	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
   208
	const char *cont;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   210
	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
   211
	{
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   212
		opt = NULL;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   213
		numleft = argc;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   214
		this->argv = argv;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   215
		this->options = options;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   216
		cont = NULL;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   217
	}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   218
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
static int MyGetOpt(MyGetOptData *md)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   222
	const char *s,*r,*t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   224
	s = md->cont;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   225
	if (s != NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		goto md_continue_here;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   228
	for (;;) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   229
		if (--md->numleft < 0) return -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
		s = *md->argv++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
		if (*s == '-') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
md_continue_here:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
			s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			if (*s != 0) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   236
				/* Found argument, try to locate it in options. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
				if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   238
					/* ERROR! */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
					return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
				if (r[1] == ':') {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   242
					/* 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
   243
					if (!*(t = s + 1)) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   244
						/* 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
   245
						if (--md->numleft < 0 || *(t = *md->argv) == '-') {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   246
							/* Check if item is optional? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
							if (r[2] != ':')
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
								return -2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
							md->numleft++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
							t = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
						} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
							md->argv++;
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
					}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   255
					md->opt = (char*)t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
					md->cont = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
					return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
				md->opt = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
				md->cont = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
				return *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   264
			/* This is currently not supported. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
			return -2;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   271
static void ParseResolution(int res[2], const char *s)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   273
	const char *t = strchr(s, 'x');
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	if (t == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
		ShowInfoF("Invalid resolution '%s'", s);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
1764
a976570cdbd9 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   279
	res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH);
a976570cdbd9 (svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents: 1688
diff changeset
   280
	res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   281
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   283
static void InitializeDynamicVariables()
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   284
{
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   285
	/* Dynamic stuff needs to be initialized somewhere... */
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1264
diff changeset
   286
	_town_sort     = NULL;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   287
	_industry_sort = NULL;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   288
}
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   289
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
   290
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   291
static void UnInitializeGame()
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   292
{
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
   293
	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
   294
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
   295
	/* Uninitialize airport state machines */
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
   296
	UnInitializeAirports();
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
   297
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
   298
	/* Uninitialize variables that are allocated dynamically */
4983
16a0ede2f7fb (svn r6986) Use the pool macros for the Town pool
tron
parents: 4980
diff changeset
   299
	CleanPool(&_Town_pool);
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4972
diff changeset
   300
	CleanPool(&_Industry_pool);
4980
bdc86a42db2c (svn r6983) Use the pool macros for the Station pool
tron
parents: 4979
diff changeset
   301
	CleanPool(&_Station_pool);
4972
af023b864bad (svn r6975) Use the pool macros for the Vehicle pool
tron
parents: 4912
diff changeset
   302
	CleanPool(&_Vehicle_pool);
4979
bb8927cf4e1f (svn r6982) Use the pool macros for the Sign pool
tron
parents: 4977
diff changeset
   303
	CleanPool(&_Sign_pool);
4977
ccecdac3075c (svn r6980) Use the pool macros for the Order pool
tron
parents: 4976
diff changeset
   304
	CleanPool(&_Order_pool);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   305
	CleanPool(&_Group_pool);
1260
c60e76928e5c (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1246
diff changeset
   306
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   307
	free((void*)_town_sort);
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4268
diff changeset
   308
	free((void*)_industry_sort);
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
   309
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
   310
	free(_config_file);
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   311
}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   312
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   313
static void LoadIntroGame()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   314
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   315
	_game_mode = GM_MENU;
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   316
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   317
	/* Clear transparency options */
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   318
	_transparent_opt = 0;
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
   319
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   320
	_opt_ptr = &_opt_newgame;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   321
	ResetGRFConfig(false);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   322
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   323
	/* Setup main window */
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   324
	ResetWindowSystem();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   325
	SetupColorsAndInitialWindow();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   326
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   327
	/* Load the default opening screen savegame */
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   328
	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
   329
		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
   330
		WaitTillGeneratedWorld();
921
1884bb89c8dc (svn r1409) Simplify some preprocessor magic
tron
parents: 919
diff changeset
   331
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   332
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   333
	_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
   334
	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
   335
	/* Make sure you can't scroll in the menu */
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
   336
	_scrolling_viewport = 0;
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
   337
	_cursor.fix_at = false;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   338
	MarkWholeScreenDirty();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   339
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   340
	/* Play main theme */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   341
	if (_music_driver->is_song_playing()) ResetMusic();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   342
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   343
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   344
#if defined(UNIX) && !defined(__MORPHOS__)
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   345
extern void DedicatedFork();
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   346
#endif
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   347
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
   348
int ttd_main(int argc, char *argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	int i;
1010
17470a8e5eb7 (svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents: 1009
diff changeset
   351
	const char *optformat;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   352
	char musicdriver[32], sounddriver[32], videodriver[32], blitter[32];
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   353
	int resolution[2] = {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
   354
	Year startyear = INVALID_YEAR;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   355
	uint generation_seed = GENERATE_NEW_SEED;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   356
	bool save_config = true;
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   357
#if defined(ENABLE_NETWORK)
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   358
	bool dedicated = false;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   359
	bool network   = false;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   360
	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
   361
	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
   362
	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
   363
	uint16 dedicated_port = 0;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   364
#endif /* ENABLE_NETWORK */
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1397
diff changeset
   365
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   366
	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
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	_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
   370
	_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
   371
	_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
   372
	_config_file = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   374
	/* The last param of the following function means this:
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   375
	 *   a letter means: it accepts that param (e.g.: -h)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   376
	 *   a ':' behind it means: it need a param (e.g.: -m<driver>)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   377
	 *   a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   378
	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
   379
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   380
		"f"
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   381
#endif
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   382
	;
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 768
diff changeset
   383
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
   384
	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
   385
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	while ((i = MyGetOpt(&mgo)) != -1) {
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   387
		switch (i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		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
   389
		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
   390
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   391
		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
   392
#if defined(ENABLE_NETWORK)
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   393
		case 'D':
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   394
			strcpy(musicdriver, "null");
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   395
			strcpy(sounddriver, "null");
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   396
			strcpy(videodriver, "dedicated");
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   397
			strcpy(blitter, "null");
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   398
			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
   399
			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
   400
				/* 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
   401
				 * 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
   402
				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
   403
				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
   404
				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
   405
				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
   406
				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
   407
			}
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   408
			break;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   409
		case 'f': _dedicated_forks = true; break;
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   410
		case 'n':
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   411
			network = true;
3059
9f25d987c6ae (svn r3648) - Fix typo in r3647, don't ask me how it got there s/_/./
Darkvater
parents: 3058
diff changeset
   412
			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
   413
			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
   414
		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
   415
			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
   416
			break;
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   417
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
		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
   419
		case 't': startyear = atoi(mgo.opt); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
		case 'd': {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
#if defined(WIN32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
				CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
#endif
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   424
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
			} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
		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
   427
		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
   428
		case 'g':
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   429
			if (mgo.opt != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
				strcpy(_file_to_saveload.name, mgo.opt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
				_switch_mode = SM_LOAD;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   432
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
				_switch_mode = SM_NEWGAME;
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   434
				/* Give a random map */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   435
				generation_seed = InteractiveRandom();
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
   436
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
			break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   438
		case 'G': generation_seed = atoi(mgo.opt); break;
3058
32bbf65085e8 (svn r3647) Some style-changes to the parameter parser
Darkvater
parents: 3033
diff changeset
   439
		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
   440
		case 'x': save_config = false; break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
		case -2:
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1993
diff changeset
   442
		case 'h':
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
			showhelp();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
			return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   448
	DeterminePaths(argv[0]);
961
26fdd7e62075 (svn r1453) Feature: MD5 hash check for TTD files
dominik
parents: 959
diff changeset
   449
	CheckExternalFiles();
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   450
2290
3283963c5422 (svn r2814) -Fix: made MorphOS to compile again
truelight
parents: 2285
diff changeset
   451
#if defined(UNIX) && !defined(__MORPHOS__)
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   452
	/* 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
   453
	if (_dedicated_forks)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   454
		DedicatedFork();
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   455
#endif
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   456
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	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
   458
	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
   459
	LoadFromHighScore();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   461
	/* 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
   462
	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
   463
	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
   464
	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   465
	if (StrEmpty(blitter)) ttd_strlcpy(blitter, _default_blitter, sizeof(blitter));
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
   466
	if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4285
diff changeset
   467
	if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   468
	if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   470
	/* The width and height must be at least 1 pixel, this
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   471
	 * way all internal drawing routines work correctly. */
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   472
	if (_cur_resolution[0] == 0) _cur_resolution[0] = 1;
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   473
	if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   474
5943
9acc30eb83cd (svn r8155) -Fix: fixed compilation when --disable-network is in use
bjarni
parents: 5934
diff changeset
   475
#if defined(ENABLE_NETWORK)
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
   476
	if (dedicated_host) snprintf(_network_server_bind_ip_host, NETWORK_HOSTNAME_LENGTH, "%s", dedicated_host);
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
   477
	if (dedicated_port) _network_server_port = dedicated_port;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   478
	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
   479
#endif /* ENABLE_NETWORK */
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 679
diff changeset
   480
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   481
	/* enumerate language files */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	InitializeLanguagePacks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   484
	/* initialize screenshot formats */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	InitializeScreenshotFormats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   487
	/* initialize airport state machines */
105
44e894da0fef (svn r106) New network core (by sign_de)
dominik
parents: 96
diff changeset
   488
	InitializeAirports();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   489
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   490
	/* 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
   491
	InitializeDynamicVariables();
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   492
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   493
	/* start the AI */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   494
	AI_Initialize();
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   495
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   496
	/* Sample catalogue */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   497
	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
   498
	MxInitialize(11025);
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1482
diff changeset
   499
	SoundInitialize("sample.cat");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
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
   501
	/* 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
   502
	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
   503
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   504
	/* This must be done early, since functions use the InvalidateWindow* calls */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   505
	InitWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
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
   507
	/* 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
   508
	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
   509
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   510
	DEBUG(misc, 1, "Loading blitter '%s'...", blitter);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   511
	if (BlitterFactoryBase::SelectBlitter(blitter) == NULL)
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
   512
		error("Failed to select requested blitter '%s'; does it exist?", blitter);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   513
	DEBUG(driver, 1, "Loading drivers...");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	LoadDriver(SOUND_DRIVER, _ini_sounddriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2498
diff changeset
   517
	_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   518
	/* Initialize the zoom level of the screen to normal */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   519
	_screen.zoom = ZOOM_LVL_NORMAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   521
	/* restore saved music volume */
3678
599ea808a4f8 (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   522
	_music_driver->set_volume(msf.music_vol);
599ea808a4f8 (svn r4595) - Fix (FS#63) Music volume is now restored to the value saved in openttd.cfg
glx
parents: 3676
diff changeset
   523
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   524
	NetworkStartUp(); // initialize network-core
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   525
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
   526
#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
   527
	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
   528
		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
   529
		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
   530
		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
   531
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
   532
		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
   533
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
   534
		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
   535
		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
   536
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
   537
		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
   538
	}
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
   539
#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
   540
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   541
	ScanNewGRFFiles();
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   542
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   543
	_opt_ptr = &_opt_newgame;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   544
	ResetGRFConfig(false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   545
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   546
	/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   547
	if (_opt_newgame.diff_level == 9) SetDifficultyLevel(0, &_opt_newgame);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   549
	/* Make sure _patches is filled with _patches_newgame if we switch to a game directly */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   550
	if (_switch_mode != SM_NONE) {
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   551
		_opt = _opt_newgame;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   552
		UpdatePatches();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   553
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   554
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   555
	/* initialize the ingame console */
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   556
	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
   557
	_cursor.in_window = true;
1246
45f15251412b (svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents: 1243
diff changeset
   558
	InitializeGUI();
644
e833509107ad (svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents: 630
diff changeset
   559
	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
   560
2828
996de8e891c7 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   561
	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
   562
	WaitTillGeneratedWorld();
1268
306ebfea663a (svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents: 1267
diff changeset
   563
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   564
#ifdef ENABLE_NETWORK
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   565
	if (network && _network_available) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   566
		if (network_conn != NULL) {
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   567
			const char *port = NULL;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1317
diff changeset
   568
			const char *player = NULL;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   569
			uint16 rport;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   570
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   571
			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
   572
			_network_playas = PLAYER_NEW_COMPANY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   573
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   574
			ParseConnectionString(&player, &port, network_conn);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   575
4861
f28bfa84f9ad (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   576
			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
   577
				_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
   578
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   579
				if (_network_playas != PLAYER_SPECTATOR) {
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   580
					_network_playas--;
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   581
					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
   582
				}
4861
f28bfa84f9ad (svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
Darkvater
parents: 4854
diff changeset
   583
			}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   584
			if (port != NULL) rport = atoi(port);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   585
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   586
			LoadIntroGame();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   587
			_switch_mode = SM_NONE;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   588
			NetworkClientConnectGame(network_conn, rport);
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1105
diff changeset
   589
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   590
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   591
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   592
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2204
diff changeset
   593
	_video_driver->main_loop();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   594
2285
3193cbd1ba88 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2234
diff changeset
   595
	WaitTillSaved();
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
   596
	IConsoleFree();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
   598
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
	_video_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	_music_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	_sound_driver->stop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
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
   604
	/* 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
   605
	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
   606
		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
   607
		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
   608
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
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
   610
	/* Reset windowing system and free config file */
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
   611
	UnInitializeGame();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 865
diff changeset
   612
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   613
	/* stop the AI */
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   614
	AI_Uninitialize();
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   615
1036
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   616
	/* Close all and any open filehandles */
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   617
	FioCloseAll();
5f0c307fbadd (svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents: 1035
diff changeset
   618
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   622
void HandleExitGameRequest()
4548
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   623
{
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   624
	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
   625
		_exit_game = true;
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   626
	} else if (_patches.autosave_on_exit) {
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   627
		DoExitSave();
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   628
		_exit_game = true;
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   629
	} else {
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   630
		AskExitGame();
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   631
	}
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   632
}
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   633
23b56455df33 (svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents: 4537
diff changeset
   634
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   635
/** Mutex so that only one thread can communicate with the main program
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   636
 * at any given time */
4323
78204e7c3100 (svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with
truelight
parents: 4300
diff changeset
   637
static ThreadMsg _message = MSG_OTTD_NO_MESSAGE;
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   638
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   639
static inline void OTTD_ReleaseMutex() {_message = MSG_OTTD_NO_MESSAGE;}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   640
static inline ThreadMsg OTTD_PollThreadEvent() {return _message;}
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   641
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   642
/** Called by running thread to execute some action in the main game.
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   643
 * It will stall as long as the mutex is not freed (handled) by the game */
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   644
void OTTD_SendThreadMessage(ThreadMsg msg)
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   645
{
2383
80ff60d10aed (svn r2909) Game would hang where the autosave_on_exit was activated.
Darkvater
parents: 2380
diff changeset
   646
	if (_exit_game) return;
4323
78204e7c3100 (svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with
truelight
parents: 4300
diff changeset
   647
	while (_message != MSG_OTTD_NO_MESSAGE) CSleep(10);
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   648
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   649
	_message = msg;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   650
}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   651
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   652
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   653
/** Handle the user-messages sent to us
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   654
 * @param message message sent
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   655
 */
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2814
diff changeset
   656
static void ProcessSentMessage(ThreadMsg message)
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   657
{
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   658
	switch (message) {
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   659
		case MSG_OTTD_SAVETHREAD_DONE:  SaveFileDone(); break;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   660
		case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   661
		default: NOT_REACHED();
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   662
	}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   663
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   664
	OTTD_ReleaseMutex(); // release mutex so that other threads, messages can be handled
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   665
}
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
   666
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
static void ShowScreenshotResult(bool b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
	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
   670
		SetDParamStr(0, _screenshot_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		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
   672
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
		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
   674
	}
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
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   678
static void MakeNewGameDone()
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   679
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   680
	/* 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
   681
	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
   682
		SetLocalPlayer(PLAYER_SPECTATOR);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   683
		return;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   684
	}
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
	/* Create a single player */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   687
	DoStartupNewPlayer(false);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   688
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   689
	SetLocalPlayer(PLAYER_FIRST);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   690
	_current_player = _local_player;
4661
59492734db06 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4603
diff changeset
   691
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   692
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   693
	SettingsDisableElrail(_patches.disable_elrails);
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
   694
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   695
	MarkWholeScreenDirty();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   696
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   697
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   698
static void MakeNewGame(bool from_heightmap)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   702
	ResetGRFConfig(true);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
   703
	_house_mngr.ResetMapping();
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   704
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   705
	GenerateWorldSetCallback(&MakeNewGameDone);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   706
	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   707
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   709
static void MakeNewEditorWorldDone()
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   710
{
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
   711
	SetLocalPlayer(OWNER_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   716
static void MakeNewEditorWorld()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	_game_mode = GM_EDITOR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   720
	ResetGRFConfig(true);
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   721
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   722
	GenerateWorldSetCallback(&MakeNewEditorWorldDone);
2828
996de8e891c7 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2818
diff changeset
   723
	GenerateWorld(GW_EMPTY, 1 << _patches.map_x, 1 << _patches.map_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   726
void StartupPlayers();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   727
void StartupDisasters();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   728
extern void StartupEconomy();
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 115
diff changeset
   729
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   730
/**
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   731
 * Start Scenario starts a new game based on a scenario.
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   732
 * 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
   733
 * This starts a scenario based on your current difficulty settings
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   734
 */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   735
static void StartScenario()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
	_game_mode = GM_NORMAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   739
	/* invalid type */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
	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
   741
		DEBUG(sl, 0, "Savegame is obsolete or invalid format: '%s'", _file_to_saveload.name);
2749
46aba09ca365 (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   742
		ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
		_game_mode = GM_MENU;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   747
	/* Reinitialize windows */
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
   748
	ResetWindowSystem();
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
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
5313
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   752
	ResetGRFConfig(true);
ea491c0b40f1 (svn r7469) -Fix (r7348): NewGRF settings weren't loaded in cases.
peter1138
parents: 5296
diff changeset
   753
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   754
	/* Load game */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   755
	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
   756
		LoadIntroGame();
2749
46aba09ca365 (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   757
		ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
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
   760
	_opt_ptr = &_opt;
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5015
diff changeset
   761
	_opt_ptr->diff = _opt_newgame.diff;
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
   762
	_opt.diff_level = _opt_newgame.diff_level;
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   763
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   764
	/* Inititalize data */
3891
b39019cd32cf (svn r4947) - Fix [FS#145]: Starting scenarios did not adhere to local difficulty settings
Darkvater
parents: 3889
diff changeset
   765
	StartupEconomy();
115
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   766
	StartupPlayers();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   767
	StartupEngines();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   768
	StartupDisasters();
3a3c64e7be82 (svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents: 105
diff changeset
   769
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   770
	SetLocalPlayer(PLAYER_FIRST);
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
   771
	_current_player = _local_player;
4661
59492734db06 (svn r6544) - Codechange: Rename CmdReplaceVehicle to CmdSetAutoReplace, to reflect what it does.
peter1138
parents: 4603
diff changeset
   772
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   777
/** Load the specified savegame but on error do different things.
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   778
 * If loading fails due to corrupt savegame, bad version, etc. go back to
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   779
 * a previous correct state. In the menu for example load the intro game again.
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   780
 * @param filename file to be loaded
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   781
 * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   782
 * @param newgm switch to this mode of loading fails due to some unknown error
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   783
 * @param subdir default directory to look for filename, set to 0 if not needed */
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   784
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
   785
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
	byte ogm = _game_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	_game_mode = newgm;
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   789
	assert(mode == SL_LOAD || mode == SL_OLD_LOAD);
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   790
	switch (SaveOrLoad(filename, mode, subdir)) {
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   791
		case SL_OK: return true;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   792
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   793
		case SL_REINIT:
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   794
			switch (ogm) {
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   795
				case GM_MENU:   LoadIntroGame();      break;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   796
				case GM_EDITOR: MakeNewEditorWorld(); break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   797
				default:        MakeNewGame(false);   break;
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   798
			}
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   799
			return false;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   800
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   801
		default:
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   802
			_game_mode = ogm;
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
   803
			return false;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   804
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   807
void SwitchMode(int new_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
{
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   809
#ifdef ENABLE_NETWORK
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   810
	/* 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
   811
	if (new_mode != SM_SAVE) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   812
		/* 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
   813
		if (_networking) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   814
			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
   815
				NetworkReboot();
5870
86e55167c9e3 (svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents: 5860
diff changeset
   816
				NetworkUDPCloseAll();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   817
			} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   818
				NetworkDisconnect();
5870
86e55167c9e3 (svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents: 5860
diff changeset
   819
				NetworkUDPCloseAll();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   820
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   821
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   822
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   823
		/* 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
   824
		if (_is_network_server) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   825
			/* 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
   826
			if (new_mode != SM_MENU) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   827
				NetworkServerStart();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   828
			} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   829
				/* 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
   830
				_is_network_server = false;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   831
			}
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
#endif /* ENABLE_NETWORK */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   835
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   836
	switch (new_mode) {
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   837
	case SM_EDITOR: /* Switch to scenario editor */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		MakeNewEditorWorld();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   841
	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
   842
#ifdef ENABLE_NETWORK
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   843
		if (_network_server) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   844
			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
   845
		}
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   846
#endif /* ENABLE_NETWORK */
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   847
		MakeNewGame(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   850
	case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   851
#ifdef ENABLE_NETWORK
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   852
		if (_network_server) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   853
			snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   854
		}
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   855
#endif /* ENABLE_NETWORK */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   856
		StartScenario();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   857
		break;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   858
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   859
	case SM_LOAD: { /* Load game, Play Scenario */
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   860
		_opt_ptr = &_opt;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
   861
		ResetGRFConfig(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   863
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
942
31f28eedd2b8 (svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents: 929
diff changeset
   864
			LoadIntroGame();
2749
46aba09ca365 (svn r3294) - Fix: use INVALID_STRING_ID instead of -1.
Darkvater
parents: 2701
diff changeset
   865
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		} else {
5197
a441951424e7 (svn r7312) -Fix: When loading a game from a dedicated server the local player global variable was
Darkvater
parents: 5170
diff changeset
   867
			/* Update the local player for a loaded game. It is either always
a441951424e7 (svn r7312) -Fix: When loading a game from a dedicated server the local player global variable was
Darkvater
parents: 5170
diff changeset
   868
			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   869
			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   871
#ifdef ENABLE_NETWORK
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   872
			if (_network_server) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2969
diff changeset
   873
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   874
			}
630
fd3c36132342 (svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents: 614
diff changeset
   875
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   880
	case SM_START_HEIGHTMAP: /* Load a heightmap and start a new game from it */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   881
#ifdef ENABLE_NETWORK
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   882
		if (_network_server) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   883
			snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   884
		}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   885
#endif /* ENABLE_NETWORK */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   886
		MakeNewGame(true);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   887
		break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   888
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   889
	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
   890
		SetLocalPlayer(OWNER_NONE);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   891
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   892
		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   893
		MarkWholeScreenDirty();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   894
		break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   895
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   896
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   897
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   898
			_opt_ptr = &_opt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
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
   900
			SetLocalPlayer(OWNER_NONE);
4537
fefcd6142977 (svn r6366) -Fix (FS#324): when opening a scenario, the date was set 1920 years into the future.
rubidium
parents: 4536
diff changeset
   901
			_patches_newgame.starting_year = _cur_year;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   902
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   904
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   908
	case SM_MENU: /* Switch to game intro menu */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
		LoadIntroGame();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   912
	case SM_SAVE: /* Save game */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   913
		if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
			ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   915
		} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
			DeleteWindowById(WC_SAVELOAD, 0);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
   917
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   920
	case SM_GENRANDLAND: /* Generate random land within 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
   921
		SetLocalPlayer(OWNER_NONE);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   922
		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   923
		/* XXX: set date */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   927
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   928
	if (_switch_mode_errorstr != INVALID_STRING_ID) {
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   929
		ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2950
diff changeset
   930
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   934
/* State controlling game loop.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   935
 * The state must not be changed from anywhere
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   936
 * but here.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   937
 * That check is enforced in DoCommand. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   938
void StateGameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
{
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   940
	/* dont execute the state loop during pause */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   941
	if (_pause_game) return;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
   942
	if (IsGeneratingWorld()) return;
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
   943
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	if (_game_mode == GM_EDITOR) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		NewsLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   951
		/* All these actions has to be done from OWNER_NONE
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
   952
		 *  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
   953
		PlayerID p = _current_player;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   954
		_current_player = OWNER_NONE;
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   955
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
		AnimateAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
		IncreaseDate();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
		RunTileLoop();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
		CallVehicleTicks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
		CallLandscapeTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
2395
19b4da30806b (svn r2921) -Codechange: moved all AI-code to 1 central place (ai/ai.c)
truelight
parents: 2383
diff changeset
   962
		AI_RunGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
		CallWindowTickEvent();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
		NewsLoop();
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   966
		_current_player = p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   970
/** Create an autosave. The default name is "autosave#.sav". However with
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   971
 * the patch setting 'keep_all_autosave' the name defaults to company-name + date */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
   972
static void DoAutosave()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
{
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   974
	char buf[MAX_PATH];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
   975
6228
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   976
#if defined(PSP)
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   977
	/* Autosaving in networking is too time expensive for the PSP */
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   978
	if (_networking)
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   979
		return;
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   980
#endif /* PSP */
2de23d5a2b11 (svn r8675) [PSP] -Fix: don't autosave in networking for PSP, to time expensive
truelight
parents: 6210
diff changeset
   981
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4840
diff changeset
   982
	if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1927
diff changeset
   983
		const Player *p = GetPlayer(_local_player);
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1496
diff changeset
   984
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   985
		SetDParam(0, p->name_1);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   986
		SetDParam(1, p->name_2);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   987
		SetDParam(2, _date);
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   988
		GetString(buf, STR_4004, lastof(buf));
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   989
		ttd_strlcpy(buf, ".sav", sizeof(buf));
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   990
	} else {
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   991
		/* generate a savegame name and number according to _patches.max_num_autosaves */
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   992
		snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
2672
ea469d7b34ff (svn r3214) -Feature: openttd.cfg can now set how many autosaves to keep before starting to overwrite old ones
bjarni
parents: 2670
diff changeset
   993
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   994
		if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   997
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   998
	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
   999
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1002
static void ScrollMainViewport(int x, int y)
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1003
{
4536
f13408cba18f (svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents: 4502
diff changeset
  1004
	if (_game_mode != GM_MENU) {
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1005
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1006
		assert(w);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1007
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1008
		WP(w,vp_d).dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1009
		WP(w,vp_d).dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1010
	}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1011
}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1012
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1013
static const int8 scrollamt[16][2] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4336
diff changeset
  1014
	{ 0,  0},
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1015
	{-2,  0}, ///<  1 : left
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1016
	{ 0, -2}, ///<  2 : up
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1017
	{-2, -1}, ///<  3 : left + up
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1018
	{ 2,  0}, ///<  4 : right
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1019
	{ 0,  0}, ///<  5 : left + right
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1020
	{ 2, -1}, ///<  6 : right + up
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1021
	{ 0, -2}, ///<  7 : left + right + up = up
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1022
	{ 0  ,2}, ///<  8 : down
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1023
	{-2  ,1}, ///<  9 : down+left
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1024
	{ 0,  0}, ///< 10 : impossible
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1025
	{-2,  0}, ///< 11 : left + up + down = left
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1026
	{ 2,  1}, ///< 12 : down+right
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1027
	{ 0,  2}, ///< 13 : left + right + down = down
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1028
	{ 0, -2}, ///< 14 : left + right + up = up
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1029
	{ 0,  0}, ///< 15 : impossible
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1030
};
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1031
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1032
static void HandleKeyScrolling()
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1033
{
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1034
	if (_dirkeys && !_no_scroll) {
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1035
		int factor = _shift_pressed ? 50 : 10;
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1036
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1037
	}
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1385
diff changeset
  1038
}
1199
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
  1039
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1040
void GameLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
{
2380
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
  1042
	ThreadMsg message;
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
  1043
3b26659b4a9a (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2360
diff changeset
  1044
	if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1046
	/* autosave game? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	if (_do_autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
		_do_autosave = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
		DoAutosave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
		RedrawAutosave();
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
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1053
	/* handle scrolling of the main window */
4502
45c93dbca534 (svn r6287) -Codechange: Remove a redundant check
tron
parents: 4383
diff changeset
  1054
	HandleKeyScrolling();
1199
15d0c3424a45 (svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents: 1181
diff changeset
  1055
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1056
	/* make a screenshot? */
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4171
diff changeset
  1057
	if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1059
	/* switch game mode? */
3024
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1060
	if (_switch_mode != SM_NONE) {
723b875af8b0 (svn r3604) Remove two unnecessary local variables
tron
parents: 2989
diff changeset
  1061
		SwitchMode(_switch_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
		_switch_mode = SM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	IncreaseSpriteLRU();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	InteractiveRandom();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1068
	if (_scroller_click_timeout > 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
		_scroller_click_timeout -= 3;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1070
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
		_scroller_click_timeout = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1072
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	_caret_timer += 3;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1075
	_timer_counter += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	CursorTick();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1078
#ifdef ENABLE_NETWORK
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1079
	/* Check for UDP stuff */
4830
0ff2a14e90be (svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking
Darkvater
parents: 4829
diff changeset
  1080
	if (_network_available) NetworkUDPGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4293
diff changeset
  1082
	if (_networking && !IsGeneratingWorld()) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1083
		/* Multiplayer */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1084
		NetworkGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1085
	} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1086
		if (_network_reconnect > 0 && --_network_reconnect == 0) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1087
			/* This means that we want to reconnect to the last host
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1088
			 * We do this here, because it means that the network is really closed */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1089
			NetworkClientConnectGame(_network_last_host, _network_last_port);
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
  1090
		}
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1091
		/* Singleplayer */
213
770e504a6e51 (svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents: 208
diff changeset
  1092
		StateGameLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1094
#else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1095
	StateGameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1096
#endif /* ENABLE_NETWORK */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1098
	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
  1099
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1100
	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
  1101
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
  1102
	InputLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
1608
074dff2e4890 (svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents: 1570
diff changeset
  1104
	MusicLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1107
void BeforeSaveGame()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1109
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
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
  1111
	if (w != NULL) {
2643
735ef1e7884b (svn r3185) const
tron
parents: 2641
diff changeset
  1112
		_saved_scrollpos_x = WP(w, const vp_d).scrollpos_x;
735ef1e7884b (svn r3185) const
tron
parents: 2641
diff changeset
  1113
		_saved_scrollpos_y = WP(w, const vp_d).scrollpos_y;
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1114
		_saved_scrollpos_zoom = w->viewport->zoom;
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 961
diff changeset
  1115
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1118
static void ConvertTownOwner()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1120
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 861
diff changeset
  1122
	for (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
  1123
		switch (GetTileType(tile)) {
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
  1124
			case MP_STREET:
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1125
				if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HASBIT(_m[tile].m4, 7)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1126
					_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
  1127
				}
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
  1128
				/* FALLTHROUGH */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
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
  1130
			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
  1131
				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
  1132
				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
  1133
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
  1134
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1139
/* before savegame version 4, the name of the company determined if it existed */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1140
static void CheckIsPlayerActive()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1142
	Player *p;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1143
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	FOR_ALL_PLAYERS(p) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1145
		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
  1146
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1149
/* since savegame version 4.1, exclusive transport rights are stored at towns */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1150
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
  1151
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1152
	Town *t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1153
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1154
	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
  1155
		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
  1156
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1157
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  1158
	/* 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
  1159
	 *   could be implemented this way:
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1160
	 * 1.) Go through all stations
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4548
diff changeset
  1161
	 *     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
  1162
	 *     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
  1163
	 * 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
  1164
	 *     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
  1165
	 */
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1166
}
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 116
diff changeset
  1167
2756
0c73c4710821 (svn r3301) One more static
tron
parents: 2754
diff changeset
  1168
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
  1169
	 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
  1170
	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
  1171
	 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
  1172
	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
  1173
	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
  1174
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1175
/* since savegame version 4.2 the currencies are arranged differently */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1176
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
  1177
{
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
  1178
	_opt.currency = convert_currency[_opt.currency];
762
7afe6c8554cb (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 760
diff changeset
  1179
}
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
  1180
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
  1181
/* 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
  1182
 * 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
  1183
 */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1184
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
  1185
{
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 950
diff changeset
  1186
	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
  1187
3075
f0d692c60465 (svn r3664) Add a function to turn a tile into a void tile
tron
parents: 3059
diff changeset
  1188
	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
  1189
	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
  1190
}
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
  1191
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1192
/* since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1193
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
  1194
{
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1195
	Sign *si;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1196
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1197
	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
  1198
}
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1115
diff changeset
  1199
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1200
extern void UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1202
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1203
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
  1204
{
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1205
	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
  1206
}
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1207
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1208
bool AfterLoadGame()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
{
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1210
	TileIndex map_size = MapSize();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	ViewPort *vp;
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1213
	Player *p;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
  1214
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1215
	/* 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
  1216
	if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1218
	/* 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
  1219
	if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1220
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1221
	/* 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
  1222
	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
  1223
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1224
	/* 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
  1225
	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
  1226
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1227
	/* In old version there seems to be a problem that water is owned by
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1228
	    OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1229
	    (4.3) version, so I just check when versions are older, and then
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1230
	    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
  1231
	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
  1232
		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
  1233
			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
  1234
				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
  1235
			}
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1236
		}
831
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1237
	}
f1cee10e3422 (svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents: 802
diff changeset
  1238
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1239
	/* convert road side to my format. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	if (_opt.road_side) _opt.road_side = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
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
  1242
	/* Check if all NewGRFs are present, we are very strict in MP mode */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1243
	GRFListCompatibility gcf_res = IsGoodGRFConfigList();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1244
	if (_networking && gcf_res != GLC_ALL_GOOD) return false;
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
  1245
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
  1246
	switch (gcf_res) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1247
		case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1248
		case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; break;
5903
cd2d0ef3a3b9 (svn r8111) -Fix r8106: silence warnings
glx
parents: 5898
diff changeset
  1249
		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
  1250
	}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5197
diff changeset
  1251
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1252
	/* Update current year
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1253
	 * 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
  1254
	SetDate(_date);
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5314
diff changeset
  1255
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1256
	/* Load the sprites */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	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
  1258
	LoadStringWidthTable();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
2814
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1260
	/* 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
  1261
	 * subtype to the new format */
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1262
	if (CheckSavegameVersionOldStyle(17, 1)) ConvertOldMultiheadToNew();
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2808
diff changeset
  1263
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
  1264
	/* 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
  1265
	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
  1266
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1267
	/* reinit the landscape variables (landscape might have changed) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	InitializeLandscapeVariables(true);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1269
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1270
	/* Update all vehicles */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	AfterLoadVehicles();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1272
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1273
	/* Update all waypoints */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1274
	if (CheckSavegameVersion(12)) FixOldWaypoints();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1275
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1276
	UpdateAllWaypointSigns();
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1501
diff changeset
  1277
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1278
	/* in version 2.2 of the savegame, we have new airports */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1279
	if (CheckSavegameVersionOldStyle(2, 2)) UpdateOldAircraft();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	UpdateAllStationVirtCoord();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1283
	/* Setup town coords */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	AfterLoadTown();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	UpdateAllSignVirtCoords();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1287
	/* make sure there is a town in the game */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1288
	if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
		_error_message = STR_NO_TOWN_IN_SCENARIO;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1293
	/* Initialize windows */
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1440
diff changeset
  1294
	ResetWindowSystem();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
	SetupColorsAndInitialWindow();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	w = FindWindowById(WC_MAIN_WINDOW, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
	WP(w,vp_d).scrollpos_x = _saved_scrollpos_x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	WP(w,vp_d).scrollpos_y = _saved_scrollpos_y;
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1301
	WP(w,vp_d).dest_scrollpos_x = _saved_scrollpos_x;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1302
	WP(w,vp_d).dest_scrollpos_y = _saved_scrollpos_y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1303
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	vp = w->viewport;
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
  1305
	vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1306
	vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1307
	vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1309
	/* in version 4.1 of the savegame, is_active was introduced to determine
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1310
	 * 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
  1311
	if (CheckSavegameVersionOldStyle(4, 1)) CheckIsPlayerActive();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 185
diff changeset
  1312
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1313
	/* the void tiles on the southern border used to belong to a wrong class (pre 4.3). */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1314
	if (CheckSavegameVersionOldStyle(4, 3)) 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
  1315
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1316
	/* If Load Scenario / New (Scenario) Game is used,
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1317
	 *  a player does not exist yet. So create one here.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1318
	 * 1 exeption: network-games. Those can have 0 players
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1319
	 *   But this exeption is not true for non dedicated network_servers! */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1320
	if (!_players[0].is_active && (!_networking || (_networking && _network_server && !_network_dedicated)))
139
ac354a826b30 (svn r140) -Fix: Load Scenario fix
truelight
parents: 136
diff changeset
  1321
		DoStartupNewPlayer(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 139
diff changeset
  1323
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1326
	for (TileIndex t = 0; t < map_size; t++) {
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1327
		switch (GetTileType(t)) {
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1328
			case MP_STATION: {
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1329
				Station *st = GetStationByTile(t);
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1330
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1331
				st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1332
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1333
				switch (GetStationType(t)) {
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1334
					case STATION_TRUCK:
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1335
					case STATION_BUS:
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1336
						if (CheckSavegameVersion(6)) {
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1337
							/* From this version on there can be multiple road stops of the
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1338
							 * same type per station. Convert the existing stops to the new
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1339
							 * internal data structure. */
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1340
							RoadStop *rs = new RoadStop(t);
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1341
							if (rs == NULL) error("Too many road stops in savegame");
6130
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1342
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1343
							RoadStop **head =
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1344
								IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1345
							*head = rs;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1346
						}
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1347
						break;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1348
6135
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1349
					case STATION_OILRIG: {
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1350
						/* Very old savegames sometimes have phantom oil rigs, i.e.
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1351
						 * an oil rig which got shut down, but not completly removed from
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1352
						 * the map
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1353
						 */
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1354
						TileIndex t1 = TILE_ADDXY(t, 1, 0);
6137
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1355
						if (IsTileType(t1, MP_INDUSTRY) &&
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1356
								GetIndustryGfx(t1) == GFX_OILRIG_3) {
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1357
							/* The internal encoding of oil rigs was changed twice.
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1358
							 * It was 3 (till 2.2) and later 5 (till 5.1).
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1359
							 * Setting it unconditionally does not hurt.
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1360
							 */
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1361
							GetStationByTile(t)->airport_type = AT_OILRIG;
3d0a1dfdfba7 (svn r8498) -Fix
tron
parents: 6136
diff changeset
  1362
						} else {
6135
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1363
							DeleteOilRig(t);
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1364
						}
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1365
						break;
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1366
					}
72fa67e22bc2 (svn r8485) -Fix
tron
parents: 6131
diff changeset
  1367
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1368
					default: break;
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1369
				}
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1370
				break;
6419
5620cce64826 (svn r8828) -Fix
tron
parents: 6326
diff changeset
  1371
			}
6131
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1372
ee99976fa536 (svn r8478) -Fix
tron
parents: 6130
diff changeset
  1373
			default: break;
6130
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1374
		}
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1375
	}
f67231d82e91 (svn r8477) -Fix
tron
parents: 6099
diff changeset
  1376
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1377
	/* 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
  1378
	 *  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
  1379
	 *  all about ;) */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1380
	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
  1381
		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
  1382
			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
  1383
				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
  1384
					_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
  1385
					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
  1386
					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
  1387
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
  1388
				case MP_STREET:
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1389
					_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
  1390
					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
  1391
						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
  1392
					} 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
  1393
						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
  1394
					}
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
  1395
					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
  1396
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
  1397
				default: break;
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1398
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1399
		}
1264
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1400
	}
280792016b02 (svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents: 1260
diff changeset
  1401
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1402
	/* 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
  1403
	 *  before that. */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1404
	if (CheckSavegameVersion(9)) {
1377
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1405
		Town *t;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2634
diff changeset
  1406
		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
  1407
	}
2a418162176e (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1349
diff changeset
  1408
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1409
	/* 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
  1410
	 *  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
  1411
	if (CheckSavegameVersion(16)) {
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1412
		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
  1413
			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
  1414
			p->engine_renew        = false;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1415
			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
  1416
			p->engine_renew_money  = 100000;
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1417
		}
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
  1418
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
  1419
		/* 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
  1420
		 * 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
  1421
		 * 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
  1422
		 * 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
  1423
		 * 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
  1424
		 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1425
		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
  1426
			p = GetPlayer(PLAYER_FIRST);
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
  1427
			p->engine_renew        = _patches.autorenew;
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
  1428
			p->engine_renew_months = _patches.autorenew_months;
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
  1429
			p->engine_renew_money  = _patches.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
  1430
		}
2293
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1431
	}
a71c210076be (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2290
diff changeset
  1432
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1433
	if (CheckSavegameVersion(48)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1434
		for (TileIndex t = 0; t < map_size; t++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1435
			switch (GetTileType(t)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1436
				case MP_RAILWAY:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1437
					if (IsPlainRailTile(t)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1438
						/* Swap ground type and signal type for plain rail tiles, so the
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1439
						 * ground type uses the same bits as for depots and waypoints. */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1440
						uint tmp = GB(_m[t].m4, 0, 4);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1441
						SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1442
						SB(_m[t].m2, 0, 4, tmp);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1443
					} else if (HASBIT(_m[t].m5, 2)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1444
						/* Split waypoint and depot rail type and remove the subtype. */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1445
						CLRBIT(_m[t].m5, 2);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1446
						CLRBIT(_m[t].m5, 6);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1447
					}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1448
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1449
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1450
				case MP_STREET:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1451
					/* Swap m3 and m4, so the track type for rail crossings is the
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1452
					 * same as for normal rail. */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1453
					Swap(_m[t].m3, _m[t].m4);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1454
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1455
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1456
				default: break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1457
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1458
		}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1459
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1460
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1461
	if (CheckSavegameVersion(61)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1462
		/* Added the RoadType */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1463
		bool old_bridge = CheckSavegameVersion(42);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1464
		for (TileIndex t = 0; t < map_size; t++) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1465
			switch(GetTileType(t)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1466
				case MP_STREET:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1467
					SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1468
					switch (GetRoadTileType(t)) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1469
						default: NOT_REACHED();
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1470
						case ROAD_TILE_NORMAL:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1471
							SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1472
							SB(_m[t].m4, 4, 4, 0);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1473
							SB(_m[t].m6, 2, 4, 0);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1474
							break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1475
						case ROAD_TILE_CROSSING:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1476
							SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1477
							break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1478
						case ROAD_TILE_DEPOT:    break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1479
					}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1480
					SetRoadTypes(t, ROADTYPES_ROAD);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1481
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1482
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1483
				case MP_STATION:
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1484
					if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1485
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1486
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1487
				case MP_TUNNELBRIDGE:
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1488
					/* Middle part of "old" bridges */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1489
					if (old_bridge && IsBridgeTile(t) && HASBIT(_m[t].m5, 6)) break;
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1490
					if ((IsTunnel(t) ? GetTunnelTransportType(t) : (old_bridge ? (TransportType)GB(_m[t].m5, 1, 2) : GetBridgeTransportType(t))) == TRANSPORT_ROAD) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1491
						SetRoadTypes(t, ROADTYPES_ROAD);
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1492
					}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1493
					break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1494
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1495
				default: break;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1496
			}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1497
		}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1498
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1499
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1500
	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
  1501
		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
  1502
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1503
		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
  1504
			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
  1505
			if (IsBridgeTile(t)) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1506
				if (HASBIT(_m[t].m5, 6)) { // middle part
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1507
					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
  1508
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1509
					if (HASBIT(_m[t].m5, 5)) { // transport route under bridge?
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1510
						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
  1511
							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
  1512
								t,
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1513
								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
  1514
								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
  1515
								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
  1516
							);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1517
						} 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
  1518
							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
  1519
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1520
							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
  1521
								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
  1522
								axis == AXIS_X ? ROAD_Y : ROAD_X,
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1523
								ROADTYPES_ROAD,
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1524
								town,
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1525
								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
  1526
							);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1527
						}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1528
					} 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
  1529
						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
  1530
							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
  1531
						} 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
  1532
							MakeCanal(t, 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
  1533
						}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1534
					}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1535
					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
  1536
				} 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
  1537
					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
  1538
					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
  1539
					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
  1540
					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
  1541
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1542
					_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
  1543
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1544
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1545
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1546
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1547
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1548
			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
  1549
			if (IsBridgeTile(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
  1550
				DiagDirection dir = GetBridgeRampDirection(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
  1551
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1552
				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
  1553
				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
  1554
					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
  1555
					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
  1556
					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
  1557
					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
  1558
					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
  1559
				}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1560
			} 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
  1561
				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
  1562
			} else {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1563
				continue;
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1564
			}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1565
			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
  1566
				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
  1567
			} 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
  1568
				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
  1569
			}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1570
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1571
	}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
  1572
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
  1573
	/* 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
  1574
	if (CheckSavegameVersion(24)) {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4132
diff changeset
  1575
		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
  1576
		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
  1577
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
  1578
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1579
			if (v->type == VEH_TRAIN) {
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 5974
diff changeset
  1580
				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
  1581
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
  1582
				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
  1583
				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
  1584
			}
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
  1585
		}
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
  1586
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
  1587
		/* .. 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
  1588
		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
  1589
			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
  1590
				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
  1591
					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
  1592
					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
  1593
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
  1594
				case MP_STREET:
3656
4e75522d698d (svn r4571) Change the rail type update for electrified rails so it doesn't use bit magic
tron
parents: 3580
diff changeset
  1595
					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
  1596
						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
  1597
					}
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
  1598
					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
  1599
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
  1600
				case MP_STATION:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1601
					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
  1602
						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
  1603
					}
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
  1604
					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
  1605
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
  1606
				case MP_TUNNELBRIDGE:
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1607
					if (IsTunnel(t)) {
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1608
						if (GetTunnelTransportType(t) == TRANSPORT_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
  1609
							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
  1610
						}
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
  1611
					} else {
3367
3f82c99d42af (svn r4164) Use acessor functions
tron
parents: 3355
diff changeset
  1612
						if (GetBridgeTransportType(t) == TRANSPORT_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
  1613
							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
  1614
						}
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
  1615
					}
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
  1616
					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
  1617
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
  1618
				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
  1619
					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
  1620
			}
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
  1621
		}
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
  1622
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
  1623
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1624
			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
  1625
		}
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
  1626
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
  1627
	}
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
  1628
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
  1629
	/* 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
  1630
	 * 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
  1631
	 * to false */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1632
	if (CheckSavegameVersionOldStyle(16, 1)) {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4032
diff changeset
  1633
		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
  1634
	}
a9e1a187de99 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2572
diff changeset
  1635
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
  1636
	/* 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
  1637
	 * 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
  1638
	 * 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
  1639
	 * waypoint struct. */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2684
diff changeset
  1640
	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
  1641
		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
  1642
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
  1643
		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
  1644
			if (wp->deleted == 0) {
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1645
				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
  1646
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
  1647
				if (HASBIT(_m[wp->xy].m3, 4))
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1648
					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
  1649
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1650
				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
  1651
					wp->stat_id = _m[wp->xy].m4 + 1;
9908
0fa543611bbe (svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents: 9906
diff changeset
  1652
					wp->grfid = statspec->grffile->grfid;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3656
diff changeset
  1653
					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
  1654
				} else {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1655
					/* 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
  1656
					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
  1657
					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
  1658
					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
  1659
				}
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
  1660
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1661
				/* 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
  1662
				_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1663
				/* 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
  1664
				_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
  1665
			}
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
  1666
		}
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
  1667
	} 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
  1668
		/* 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
  1669
		 * 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
  1670
		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
  1671
	}
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
  1672
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
  1673
	/* 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
  1674
	 *  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
  1675
	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
  1676
		for (TileIndex t = 0; t < map_size; t++) {
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1677
			switch (GetTileType(t)) {
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1678
				case MP_RAILWAY:
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1679
					if (HasSignals(t)) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1680
						/* convert PBS signals to combo-signals */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1681
						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
  1682
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1683
						/* move the signal variant back */
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1684
						SetSignalVariant(t, TRACK_X, HASBIT(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
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
  1685
						CLRBIT(_m[t].m2, 3);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1686
					}
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1687
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1688
					/* Clear PBS reservation on track */
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1689
					if (!IsTileDepotType(t, TRANSPORT_RAIL)) {
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1690
						SB(_m[t].m4, 4, 4, 0);
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1691
					} else {
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1692
						CLRBIT(_m[t].m3, 6);
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1693
					}
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1694
					break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1695
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1696
				case MP_STREET: /* Clear PBS reservation on crossing */
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1697
					if (IsLevelCrossing(t)) CLRBIT(_m[t].m5, 0);
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1698
					break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1699
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9901
diff changeset
  1700
				case MP_STATION: /* Clear PBS reservation on station */
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
					CLRBIT(_m[t].m3, 6);
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1702
					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
  1703
5958
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1704
				default: break;
82161fb80839 (svn r8184) if cascade -> switch
tron
parents: 5957
diff changeset
  1705
			}
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
		}
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
  1707
	}
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
  1708
3121
2e50f731567a (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1709
	if (CheckSavegameVersion(22))  UpdatePatches();
2e50f731567a (svn r3726) - [6/6] Finalize conversion, finally save the patches struct.
Darkvater
parents: 3075
diff changeset
  1710
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1711
	if (CheckSavegameVersion(25)) {
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1712
		Vehicle *v;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1713
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1714
			if (v->type == VEH_ROAD) {
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1715
				v->vehstatus &= ~0x40;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1716
				v->u.road.slot = NULL;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1717
				v->u.road.slot_age = 0;
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1718
			}
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1719
		}
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
  1720
	} 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
  1721
		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
  1722
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1723
			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
  1724
		}
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1725
	}
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3367
diff changeset
  1726
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
  1727
	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
  1728
		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
  1729
		FOR_ALL_STATIONS(st) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1730
			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
  1731
		}
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
  1732
	}
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
  1733
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3891
diff changeset
  1734
	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
  1735
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
  1736
	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
  1737
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1738
	FOR_ALL_PLAYERS(p) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1739
		p->avail_railtypes = GetPlayerRailtypes(p->index);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1740
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1741
	}
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2100
diff changeset
  1742
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1743
	if (!CheckSavegameVersion(27)) AfterLoadStations();
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3678
diff changeset
  1744
4574
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1745
	{
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1746
		/* Set up the engine count for all players */
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1747
		Player *players[MAX_PLAYERS];
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1748
		const Vehicle *v;
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1749
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1750
		for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) players[i] = GetPlayer(i);
4574
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1751
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1752
		FOR_ALL_VEHICLES(v) {
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1753
			if (!IsEngineCountable(v)) continue;
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1754
			players[v->owner]->num_engines[v->engine_type]++;
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1755
		}
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1756
	}
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
  1757
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
  1758
	/* 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
  1759
	 * 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
  1760
	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
  1761
		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
  1762
		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
  1763
		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
  1764
		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
  1765
		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
  1766
		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
  1767
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1768
		_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
  1769
		_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
  1770
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1771
		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
  1772
		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
  1773
		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
  1774
		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
  1775
		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
  1776
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1777
		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
  1778
			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
  1779
			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
  1780
		}
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1781
	}
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4323
diff changeset
  1782
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
  1783
	/* 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
  1784
	 *  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
  1785
	 *  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
  1786
	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
  1787
		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
  1788
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1789
		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
  1790
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1791
				MakeClear(t, CLEAR_GRASS, 3);
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
  1792
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1793
		}
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
  1794
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
  1795
		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
  1796
			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
  1797
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  1798
			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
  1799
				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
  1800
			}
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
  1801
		}
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
  1802
	}
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
  1803
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
  1804
	/* 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
  1805
	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
  1806
		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
  1807
		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
  1808
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
  1809
		FOR_ALL_ORDERS(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
  1810
			order->refit_cargo   = CT_NO_REFIT;
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
  1811
			order->refit_subtype = CT_NO_REFIT;
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
  1812
		}
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
  1813
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
  1814
		FOR_ALL_VEHICLES(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
  1815
			v->current_order.refit_cargo   = CT_NO_REFIT;
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
  1816
			v->current_order.refit_subtype = CT_NO_REFIT;
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
  1817
		}
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
  1818
	}
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
  1819
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
  1820
	if (CheckSavegameVersion(37)) {
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
  1821
		ConvertNameArray();
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
  1822
	}
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
  1823
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
  1824
	/* 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
  1825
	 * preference of a user, let elrails enabled; it can be disabled manually */
6099
85bbae40f52c (svn r8422) -Fix
tron
parents: 6074
diff changeset
  1826
	if (CheckSavegameVersion(38)) _patches.disable_elrails = false;
85bbae40f52c (svn r8422) -Fix
tron
parents: 6074
diff changeset
  1827
	/* do the same as when elrails were enabled/disabled manually just now */
85bbae40f52c (svn r8422) -Fix
tron
parents: 6074
diff changeset
  1828
	SettingsDisableElrail(_patches.disable_elrails);
5116
2a33a74925c5 (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5108
diff changeset
  1829
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1830
	/* From version 53, the map array was changed for house tiles to allow
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1831
	 * space for newhouses grf features. A new byte, m7, was also added. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1832
	if (CheckSavegameVersion(53)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1833
		for (TileIndex t = 0; t < map_size; t++) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1834
			if (IsTileType(t, MP_HOUSE)) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1835
				if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1836
					/* Move the construction stage from m3[7..6] to m5[5..4].
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1837
					 * The construction counter does not have to move. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1838
					SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1839
					SB(_m[t].m3, 6, 2, 0);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1840
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1841
					/* The "house is completed" bit is now in m6[2]. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1842
					SetHouseCompleted(t, false);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1843
				} else {
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1844
					/* The "lift has destination" bit has been moved from
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1845
					 * m5[7] to m7[0]. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1846
					SB(_me[t].m7, 0, 1, HASBIT(_m[t].m5, 7));
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1847
					CLRBIT(_m[t].m5, 7);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1848
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1849
					/* The "lift is moving" bit has been removed, as it does
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1850
					 * the same job as the "lift has destination" bit. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1851
					CLRBIT(_m[t].m1, 7);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1852
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1853
					/* The position of the lift goes from m1[7..0] to m6[7..2],
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1854
					 * making m1 totally free, now. The lift position does not
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1855
					 * have to be a full byte since the maximum value is 36. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1856
					SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1857
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1858
					_m[t].m1 = 0;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1859
					_m[t].m3 = 0;
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1860
					SetHouseCompleted(t, true);
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1861
				}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1862
			}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1863
		}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1864
	}
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1865
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1866
	/* Count the buildings after updating the map array. */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1867
	AfterLoadCountBuildings();
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  1868
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
  1869
	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
  1870
		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
  1871
			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
  1872
				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
  1873
					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
  1874
						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
  1875
						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
  1876
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  1877
					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
  1878
					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
  1879
					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
  1880
						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
  1881
						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
  1882
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  1883
					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
  1884
					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
  1885
					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
  1886
						 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
  1887
						 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
  1888
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  1889
					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
  1890
						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
  1891
				}
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  1892
			}
5957
b28cf25e7e18 (svn r8183) When iterating over the map in AfterLoadGame() do it the same way for all loops
tron
parents: 5943
diff changeset
  1893
		}
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
  1894
	}
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5676
diff changeset
  1895
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
  1896
	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
  1897
		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
  1898
		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
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
  1899
		 * 0, 0 to be the origin of the cargo, resulting in very high payments usually. v->cargo_source_xy
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
  1900
		 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
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
  1901
		 * where this situation exists, the cargo-source information is lost. in this case, we set the origin
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
  1902
		 * 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
  1903
		 */
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
  1904
		FOR_ALL_VEHICLES(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
  1905
			v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile;
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
  1906
		}
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1907
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1908
		/* Store position of the station where the goods come from, so there
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1909
		 * are no very high payments when stations get removed. However, if the
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1910
		 * station where the goods came from is already removed, the source
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1911
		 * information is lost. In that case we set it to the position of this
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1912
		 * station */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1913
		Station *st;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1914
		FOR_ALL_STATIONS(st) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1915
			for (CargoID c = 0; c < NUM_CARGO; c++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1916
				GoodsEntry *ge = &st->goods[c];
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1917
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1918
				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1919
				if (CheckSavegameVersion(7) && ge->enroute_from == 0xFF) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1920
					ge->enroute_from = INVALID_STATION;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1921
				}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1922
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1923
				ge->enroute_from_xy = IsValidStationID(ge->enroute_from) ? GetStation(ge->enroute_from)->xy : st->xy;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1924
			}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1925
		}
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
  1926
	}
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
  1927
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
  1928
	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
  1929
		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
  1930
		/* 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
  1931
		 * 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
  1932
		 * 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
  1933
		 * 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
  1934
		 * 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
  1935
		FOR_ALL_VEHICLES(v) {
6501
1e95e8d993ff (svn r8945) -Codechange: Rename v->load_status to v->vehicle_flags so it can be used for more than just the gradual loading status.
maedhros
parents: 6498
diff changeset
  1936
			if (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
  1937
				v->cargo_paid_for = v->cargo_count;
6501
1e95e8d993ff (svn r8945) -Codechange: Rename v->load_status to v->vehicle_flags so it can be used for more than just the gradual loading status.
maedhros
parents: 6498
diff changeset
  1938
				CLRBIT(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
  1939
			} else {
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
  1940
				v->cargo_paid_for = 0;
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
  1941
			}
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
  1942
		}
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
  1943
	}
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
  1944
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
  1945
	/* 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
  1946
	 * 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
  1947
	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
  1948
		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
  1949
		FOR_ALL_STATIONS(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
  1950
			if (st->IsBuoy() && IsTileOwner(st->xy, OWNER_NONE)) SetTileOwner(st->xy, 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
  1951
		}
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
  1952
	}
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
  1953
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
  1954
	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
  1955
		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
  1956
		/* 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
  1957
		FOR_ALL_VEHICLES(v) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1958
			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
  1959
				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
  1960
				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
  1961
				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
  1962
				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
  1963
				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
  1964
			}
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
  1965
		}
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
  1966
	}
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
  1967
6516
ee6d057b9850 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 6501
diff changeset
  1968
	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
  1969
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1970
	if (CheckSavegameVersion(52)) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1971
		for (TileIndex t = 0; t < map_size; t++) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1972
			if (IsStatueTile(t)) {
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1973
				_m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1974
			}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1975
		}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1976
	}
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  1977
9909
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1978
	/* A patch option containing the proportion of towns that grow twice as
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1979
	 * fast was added in version 54. From version 56 this is now saved in the
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1980
	 * town as cities can be built specifically in the scenario editor. */
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1981
	if (CheckSavegameVersion(56)) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1982
		Town *t;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1983
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1984
		FOR_ALL_TOWNS(t) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1985
			if (_patches.larger_towns != 0 && (t->index % _patches.larger_towns) == 0) {
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1986
				t->larger_town = true;
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1987
			}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1988
		}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1989
	}
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1990
dce9a6923bb7 (svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents: 9908
diff changeset
  1991
	if (CheckSavegameVersion(57)) {
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1992
		Vehicle *v;
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1993
		/* Added a FIFO queue of vehicles loading at stations */
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1994
		FOR_ALL_VEHICLES(v) {
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1995
			if ((v->type != VEH_TRAIN || IsFrontEngine(v)) &&  // for all locs
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1996
					!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1997
					v->current_order.type == OT_LOADING) {         // loading
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  1998
				GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  1999
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2000
				/* The loading finished flag is *only* set when actually completely
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2001
				 * finished. Because the vehicle is loading, it is not finished. */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2002
				CLRBIT(v->vehicle_flags, VF_LOADING_FINISHED);
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2003
			}
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2004
		}
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2005
	}
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2006
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9909
diff changeset
  2007
	if (CheckSavegameVersion(58)) {
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2008
		/* patch difficulty number_industries other then zero get bumped to +1
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2009
		 * since a new option (very low at position1) has been added */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2010
		if (_opt.diff.number_industries > 0) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2011
			_opt.diff.number_industries++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2012
		}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2013
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2014
		/* Same goes for number of towns, although no test is needed, just an increment */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2015
		_opt.diff.number_towns++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2016
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2017
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2018
	if (CheckSavegameVersion(64)) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2019
		/* copy the signal type/variant and move signal states bits */
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2020
		for (TileIndex t = 0; t < map_size; t++) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2021
			if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2022
				SetSignalStates(t, GB(_m[t].m2, 4, 4));
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2023
				SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2024
				SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2025
				CLRBIT(_m[t].m2, 7);
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2026
			}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2027
		}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2028
	}
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2029
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2030
	/* Recalculate */
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2031
	Group *g;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2032
	FOR_ALL_GROUPS(g) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2033
		const Vehicle *v;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2034
		FOR_ALL_VEHICLES(v) {
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2035
			if (!IsEngineCountable(v)) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2036
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2037
			if (v->group_id != g->index || v->type != g->vehicle_type || v->owner != g->owner) continue;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2038
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2039
			g->num_engines[v->engine_type]++;
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2040
		}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2041
	}
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9910
diff changeset
  2042
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9911
diff changeset
  2043
	if (CheckSavegameVersion(65)) {
9901
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9896
diff changeset
  2044
		Town *t;
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9896
diff changeset
  2045
		FOR_ALL_TOWNS(t) t->SetActivity(1);
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9896
diff changeset
  2046
	}
a922f277ebfd (svn r9408) [gamebalance] -Feature: The new economic data is stored in the savegame from now on. I'll try to make sure that intra-branch compability is maintained in the future for easier testing. Newer trunk games (as soon as trunk bumps the saveload revision) will not load however.
celestar
parents: 9896
diff changeset
  2047
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
}
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2050
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2051
/** 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
  2052
 * version of AfterLoadGame().
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2053
 * 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
  2054
 * 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
  2055
 * 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
  2056
 * removed or added and changed statistics */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6522
diff changeset
  2057
void ReloadNewGRFData()
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2058
{
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2059
	/* reload grf data */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2060
	GfxLoadSprites();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2061
	LoadStringWidthTable();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2062
	/* reload vehicles */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2063
	ResetVehiclePosHash();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2064
	AfterLoadVehicles();
6522
bf0da9f42953 (svn r8976) -Codechange: Reinitialize all engines after grf files have been reloaded/changed.
Darkvater
parents: 6519
diff changeset
  2065
	StartupEngines();
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2066
	/* 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
  2067
	AfterLoadWaypoints();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2068
	AfterLoadStations();
9896
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2069
	/* check that house ids are still valid */
2473804114de (svn r9324) [gamebalance] -Sync: r9314:9322 from trunk (newhouses)
celestar
parents: 9895
diff changeset
  2070
	CheckHouseIDs();
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2071
	/* 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
  2072
	MarkWholeScreenDirty();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5350
diff changeset
  2073
}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2074
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2075
HalMusicDriver *_music_driver;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2076
HalSoundDriver *_sound_driver;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2077
HalVideoDriver *_video_driver;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2078