src/oldloader.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10427 cf023efb9a97
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9102
diff changeset
     3
/** @file oldloader.cpp Loading of old TTD(patch) savegames. */
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1537
diff changeset
     6
#include "openttd.h"
3558
9a3e12615b1c (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
     7
#include "station_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "industry.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    10
#include "company_func.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    11
#include "company_base.h"
6552
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6491
diff changeset
    12
#include "aircraft.h"
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6491
diff changeset
    13
#include "roadveh.h"
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6491
diff changeset
    14
#include "ship.h"
d87268e08799 (svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents: 6491
diff changeset
    15
#include "train.h"
8790
4a7a796b3976 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 8786
diff changeset
    16
#include "signs_base.h"
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    17
#include "debug.h"
8962
1b263c69799d (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents: 8875
diff changeset
    18
#include "depot_base.h"
6898
d23c46e9a6ec (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 6819
diff changeset
    19
#include "newgrf_config.h"
2814
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
    20
#include "ai/ai.h"
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8221
diff changeset
    21
#include "ai/default/default.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    22
#include "zoom_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8123
diff changeset
    23
#include "functions.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    24
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    25
#include "vehicle_func.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8144
diff changeset
    26
#include "variables.h"
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
    27
#include "saveload.h"
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    28
#include "strings_func.h"
9009
6684576ef32b (svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents: 9008
diff changeset
    29
#include "effectvehicle_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8260
diff changeset
    31
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8260
diff changeset
    32
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    33
enum {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    34
	HEADER_SIZE = 49,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    35
	BUFFER_SIZE = 4096,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    37
	OLD_MAP_SIZE = 256 * 256
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    38
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    40
struct LoadgameState {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    41
	FILE *file;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    43
	uint chunk_size;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    45
	bool decoding;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    46
	byte decode_char;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    48
	uint buffer_count;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    49
	uint buffer_cur;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    50
	byte buffer[BUFFER_SIZE];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    52
	uint total_read;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    53
	bool failed;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    54
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    56
/* OldChunk-Type */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    57
enum OldChunkType {
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    58
	OC_SIMPLE    = 0,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    59
	OC_NULL      = 1,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    60
	OC_CHUNK     = 2,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    61
	OC_ASSERT    = 3,
10336
9b4b4e1b0668 (svn r14587) -Cleanup: Fix some old comments. Bits are not bytes.
michi_cc
parents: 10208
diff changeset
    62
	/* 8 bits allocated (256 max) */
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    63
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    64
	OC_VAR_I8    = 1 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    65
	OC_VAR_U8    = 2 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    66
	OC_VAR_I16   = 3 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    67
	OC_VAR_U16   = 4 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    68
	OC_VAR_I32   = 5 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    69
	OC_VAR_U32   = 6 << 8,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    70
	OC_VAR_I64   = 7 << 8,
10336
9b4b4e1b0668 (svn r14587) -Cleanup: Fix some old comments. Bits are not bytes.
michi_cc
parents: 10208
diff changeset
    71
	/* 8 bits allocated (256 max) */
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    72
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    73
	OC_FILE_I8   = 1 << 16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    74
	OC_FILE_U8   = 2 << 16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    75
	OC_FILE_I16  = 3 << 16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    76
	OC_FILE_U16  = 4 << 16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    77
	OC_FILE_I32  = 5 << 16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    78
	OC_FILE_U32  = 6 << 16,
10336
9b4b4e1b0668 (svn r14587) -Cleanup: Fix some old comments. Bits are not bytes.
michi_cc
parents: 10208
diff changeset
    79
	/* 8 bits allocated (256 max) */
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    80
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    81
	OC_INT8      = OC_VAR_I8   | OC_FILE_I8,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    82
	OC_UINT8     = OC_VAR_U8   | OC_FILE_U8,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    83
	OC_INT16     = OC_VAR_I16  | OC_FILE_I16,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    84
	OC_UINT16    = OC_VAR_U16  | OC_FILE_U16,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    85
	OC_INT32     = OC_VAR_I32  | OC_FILE_I32,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    86
	OC_UINT32    = OC_VAR_U32  | OC_FILE_U32,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    87
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    88
	OC_TILE      = OC_VAR_U32  | OC_FILE_U16,
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    89
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    90
	/**
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    91
	 * Dereference the pointer once before writing to it,
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    92
	 * so we do not have to use big static arrays.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    93
	 */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    94
	OC_DEREFERENCE_POINTER = 1 << 31,
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
    95
10336
9b4b4e1b0668 (svn r14587) -Cleanup: Fix some old comments. Bits are not bytes.
michi_cc
parents: 10208
diff changeset
    96
	OC_END       = 0 ///< End of the whole chunk, all 32 bits set to zero
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    97
};
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
    98
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    99
DECLARE_ENUM_AS_BIT_SET(OldChunkType);
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   100
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   101
typedef bool OldChunkProc(LoadgameState *ls, int num);
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   102
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   103
struct OldChunks {
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   104
	OldChunkType type;   ///< Type of field
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   105
	uint32 amount;       ///< Amount of fields
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   106
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   107
	void *ptr;           ///< Pointer where to save the data (may only be set if offset is 0)
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   108
	uint offset;         ///< Offset from basepointer (may only be set if ptr is NULL)
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   109
	OldChunkProc *proc;  ///< Pointer to function that is called with OC_CHUNK
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   110
};
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   111
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   112
/* If it fails, check lines above.. */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   113
assert_compile(sizeof(TileIndex) == 4);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   114
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   115
extern SavegameType _savegame_type;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   116
extern uint32 _ttdp_version;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   117
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   118
static uint32 _bump_assert_value;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   119
static bool   _read_ttdpatch_flags;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   120
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   121
static OldChunkType GetOldChunkType(OldChunkType type)     {return (OldChunkType)GB(type, 0, 8);}
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   122
static OldChunkType GetOldChunkVarType(OldChunkType type)  {return (OldChunkType)(GB(type, 8, 8) << 8);}
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   123
static OldChunkType GetOldChunkFileType(OldChunkType type) {return (OldChunkType)(GB(type, 16, 8) << 16);}
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   124
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   125
static inline byte CalcOldVarLen(OldChunkType type)
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   126
{
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   127
	static const byte type_mem_size[] = {0, 1, 1, 2, 2, 4, 4, 8};
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   128
	byte length = GB(type, 8, 8);
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   129
	assert(length != 0 && length < lengthof(type_mem_size));
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   130
	return type_mem_size[length];
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   131
}
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   132
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   133
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   134
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   135
 * Reads a byte from a file (do not call yourself, use ReadByte())
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   136
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   137
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   138
static byte ReadByteFromFile(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   140
	/* To avoid slow reads, we read BUFFER_SIZE of bytes per time
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   141
	and just return a byte per time */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   142
	if (ls->buffer_cur >= ls->buffer_count) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   143
		/* Read some new bytes from the file */
4321
958a8e9c012b (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 4286
diff changeset
   144
		int count = (int)fread(ls->buffer, 1, BUFFER_SIZE, ls->file);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   146
		/* We tried to read, but there is nothing in the file anymore.. */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   147
		if (count == 0) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
   148
			DEBUG(oldloader, 0, "Read past end of file, loading failed");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   149
			ls->failed = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   150
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   151
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   152
		ls->buffer_count = count;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   153
		ls->buffer_cur   = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   156
	return ls->buffer[ls->buffer_cur++];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   159
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   160
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   161
 * Reads a byte from the buffer and decompress if needed
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   162
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   163
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   164
static byte ReadByte(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   166
	/* Old savegames have a nice compression algorithm (RLE)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   167
	which means that we have a chunk, which starts with a length
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   168
	byte. If that byte is negative, we have to repeat the next byte
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6351
diff changeset
   169
	that many times ( + 1). Else, we need to read that amount of bytes.
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   170
	Works pretty good if you have many zero's behind eachother */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
2453
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   172
	if (ls->chunk_size == 0) {
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   173
		/* Read new chunk */
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   174
		int8 new_byte = ReadByteFromFile(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   175
2453
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   176
		if (new_byte < 0) {
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   177
			/* Repeat next char for new_byte times */
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   178
			ls->decoding    = true;
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   179
			ls->decode_char = ReadByteFromFile(ls);
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   180
			ls->chunk_size  = -new_byte + 1;
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   181
		} else {
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   182
			ls->decoding    = false;
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   183
			ls->chunk_size  = new_byte + 1;
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   184
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   186
2453
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   187
	ls->total_read++;
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   188
	ls->chunk_size--;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   189
2453
19765362a2da (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   190
	return ls->decoding ? ls->decode_char : ReadByteFromFile(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   191
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   192
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   193
static inline uint16 ReadUint16(LoadgameState *ls)
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   194
{
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   195
	byte x = ReadByte(ls);
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   196
	return x | ReadByte(ls) << 8;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   197
}
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   198
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   199
static inline uint32 ReadUint32(LoadgameState *ls)
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   200
{
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   201
	uint16 x = ReadUint16(ls);
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   202
	return x | ReadUint16(ls) << 16;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   203
}
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   204
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   205
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   206
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   207
 * Loads a chunk from the old savegame
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   208
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   209
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   210
static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   211
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   212
	const OldChunks *chunk = chunks;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   213
	byte *base_ptr = (byte*)base;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   214
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   215
	while (chunk->type != OC_END) {
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
   216
		byte *ptr = (byte*)chunk->ptr;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
   217
		if ((chunk->type & OC_DEREFERENCE_POINTER) != 0) ptr = *(byte**)ptr;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   218
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
   219
		for (uint i = 0; i < chunk->amount; i++) {
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   220
			if (ls->failed) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   221
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   222
			/* Handle simple types */
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   223
			if (GetOldChunkType(chunk->type) != 0) {
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   224
				switch (GetOldChunkType(chunk->type)) {
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   225
					/* Just read the byte and forget about it */
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   226
					case OC_NULL: ReadByte(ls); break;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   227
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   228
					case OC_CHUNK:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   229
						/* Call function, with 'i' as parameter to tell which item we
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   230
						 * are going to read */
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   231
						if (!chunk->proc(ls, i)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   232
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   233
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   234
					case OC_ASSERT:
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
   235
						DEBUG(oldloader, 4, "Assert point: 0x%X / 0x%X", ls->total_read, chunk->offset + _bump_assert_value);
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   236
						if (ls->total_read != chunk->offset + _bump_assert_value) ls->failed = true;
3629
b8df37b2128a (svn r4528) - Fix: fix idiotic gcc warning
Darkvater
parents: 3627
diff changeset
   237
					default: break;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   238
				}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   239
			} else {
7743
7a72920ed865 (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 7738
diff changeset
   240
				uint64 res = 0;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   241
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   242
				/* Reading from the file: bits 16 to 23 have the FILE type */
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   243
				switch (GetOldChunkFileType(chunk->type)) {
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   244
					case OC_FILE_I8:  res = (int8)ReadByte(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   245
					case OC_FILE_U8:  res = ReadByte(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   246
					case OC_FILE_I16: res = (int16)ReadUint16(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   247
					case OC_FILE_U16: res = ReadUint16(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   248
					case OC_FILE_I32: res = (int32)ReadUint32(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   249
					case OC_FILE_U32: res = ReadUint32(ls); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   250
					default: NOT_REACHED();
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   251
				}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   252
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   253
				/* Sanity check */
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   254
				assert(base_ptr != NULL || chunk->ptr != NULL);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   255
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   256
				/* Writing to the var: bits 8 to 15 have the VAR type */
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   257
				if (chunk->ptr == NULL) ptr = base_ptr + chunk->offset;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   258
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   259
				/* Write the data */
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   260
				switch (GetOldChunkVarType(chunk->type)) {
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   261
					case OC_VAR_I8: *(int8  *)ptr = GB(res, 0, 8); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   262
					case OC_VAR_U8: *(uint8 *)ptr = GB(res, 0, 8); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   263
					case OC_VAR_I16:*(int16 *)ptr = GB(res, 0, 16); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   264
					case OC_VAR_U16:*(uint16*)ptr = GB(res, 0, 16); break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   265
					case OC_VAR_I32:*(int32 *)ptr = res; break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   266
					case OC_VAR_U32:*(uint32*)ptr = res; break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   267
					case OC_VAR_I64:*(int64 *)ptr = res; break;
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   268
					default: NOT_REACHED();
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   269
				}
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   270
3627
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   271
				/* Increase pointer base for arrays when looping */
3da11e0769c5 (svn r4526) - CodeChange: do some more cleanup, mainly changing the OldChunkTypes from full bitmasks into segmented values like in SaveLoad.
Darkvater
parents: 3626
diff changeset
   272
				if (chunk->amount > 1 && chunk->ptr != NULL) ptr += CalcOldVarLen(chunk->type);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   273
			}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   274
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   275
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   276
		chunk++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   277
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   278
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   279
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   280
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   281
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   282
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   283
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   284
 * Initialize some data before reading
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   285
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   286
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   287
static void InitLoading(LoadgameState *ls)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   288
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   289
	ls->chunk_size   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   290
	ls->total_read   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   291
	ls->failed       = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   292
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   293
	ls->decoding     = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   294
	ls->decode_char  = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   295
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   296
	ls->buffer_cur   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   297
	ls->buffer_count = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   298
	memset(ls->buffer, 0, BUFFER_SIZE);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   299
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   300
	_bump_assert_value = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   301
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   302
	_savegame_type   = SGT_TTD;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   303
	_ttdp_version    = 0;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   304
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   305
	_read_ttdpatch_flags = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   306
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   307
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   308
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   309
/*
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   310
 * Begin -- Stuff to fix the savegames to be OpenTTD compatible
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   311
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   312
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   313
extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   314
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   315
static void FixOldTowns()
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   316
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   317
	Town *town;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   318
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   319
	/* Convert town-names if needed */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   320
	FOR_ALL_TOWNS(town) {
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7929
diff changeset
   321
		if (IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
   322
			town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _settings_game.game_creation.town_name;
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
   323
			town->townnameparts = GetOldTownName(town->townnameparts, _settings_game.game_creation.town_name);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   324
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   325
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   328
static void FixOldStations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   330
	Station *st;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 875
diff changeset
   331
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   332
	FOR_ALL_STATIONS(st) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   333
		/* Check if we need to swap width and height for the station */
3558
9a3e12615b1c (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
   334
		if (st->train_tile != 0 && GetRailStationAxis(st->train_tile) != AXIS_X) {
5733
388bb9dcb79b (svn r8276) -Fix
tron
parents: 5716
diff changeset
   335
			Swap(st->trainst_w, st->trainst_h);
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
   336
		}
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   337
	}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   338
}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   339
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   340
static StringID *_old_vehicle_names = NULL;
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   341
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   342
static void FixOldVehicles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
{
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   344
	/* Check for shared orders, and link them correctly */
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   345
	Vehicle* v;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   346
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   347
	FOR_ALL_VEHICLES(v) {
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   348
		Vehicle *u;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   349
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   350
		v->name = CopyFromOldName(_old_vehicle_names[v->index]);
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   351
6631
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
   352
		/* We haven't used this bit for stations for ages */
6900
ee9fd6a32e77 (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 6898
diff changeset
   353
		if (v->type == VEH_ROAD &&
ee9fd6a32e77 (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 6898
diff changeset
   354
				v->u.road.state != RVSB_IN_DEPOT &&
ee9fd6a32e77 (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 6898
diff changeset
   355
				v->u.road.state != RVSB_WORMHOLE) {
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   356
			ClrBit(v->u.road.state, RVS_IS_STOPPING);
6900
ee9fd6a32e77 (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 6898
diff changeset
   357
		}
6631
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
   358
8724
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   359
		/* The subtype should be 0, but it sometimes isn't :( */
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   360
		if (v->type == VEH_ROAD) v->subtype = 0;
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   361
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   362
		/* Sometimes primary vehicles would have a nothing (invalid) order
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   363
		 * or vehicles that could not have an order would still have a
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   364
		 * (loading) order which causes assertions and the like later on.
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   365
		 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   366
		if (!IsCompanyBuildableVehicleType(v) ||
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8835
diff changeset
   367
				(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8835
diff changeset
   368
			v->current_order.MakeDummy();
8724
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   369
		}
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
   370
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   371
		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   372
			/* If a vehicle has the same orders, add the link to eachother
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   373
			 * in both vehicles */
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   374
			if (v->orders == u->orders) {
9941
8549448b55fa (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium
parents: 9749
diff changeset
   375
				u->AddToShared(v);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   376
				break;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   377
			}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   378
		}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   379
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   382
/*
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   383
 * End -- Stuff to fix the savegames to be OpenTTD compatible
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   384
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   386
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   387
/* Help:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   388
 *  - OCL_SVAR: load 'type' to offset 'offset' in a struct of type 'base', which must also
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   389
 *       be given via base in LoadChunk() as real pointer
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   390
 *  - OCL_VAR: load 'type' to a global var
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   391
 *  - OCL_END: every struct must end with this
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   392
 *  - OCL_NULL: read 'amount' of bytes and send them to /dev/null or something
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   393
 *  - OCL_CHUNK: load an other proc to load a part of the savegame, 'amount' times
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   394
 *  - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   395
 */
5671
c7b6e63f1996 (svn r8131) -Fix (r8125): g++ warning: 'invalid access to non-static data member ?<class>::<member>? of NULL object'. It is weird, but renaming the 'offsetof' macro helped.
KUDr
parents: 5614
diff changeset
   396
#define OCL_SVAR(type, base, offset)         { type,          1, NULL,    (uint)cpp_offsetof(base, offset), NULL }
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   397
#define OCL_VAR(type, amount, pointer)       { type,     amount, pointer, 0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   398
#define OCL_END()                                   { OC_END,        0, NULL,    0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   399
#define OCL_NULL(amount)                            { OC_NULL,  amount, NULL,    0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   400
#define OCL_CHUNK(amount, proc)                     { OC_CHUNK, amount, NULL,    0,                      proc }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   401
#define OCL_ASSERT(size)                            { OC_ASSERT,     1, NULL, size,                      NULL }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   403
/* The savegames has some hard-coded pointers, because it always enters the same
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   404
    piece of memory.. we don't.. so we need to remap ;)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   405
   Old Towns are 94 bytes big
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   406
   Old Orders are 2 bytes big */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   407
#define REMAP_TOWN_IDX(x) ((x) - (0x0459154 - 0x0458EF0)) / 94
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   408
#define REMAP_ORDER_IDX(x) ((x) - (0x045AB08 - 0x0458EF0)) / 2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
7694
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7537
diff changeset
   410
extern TileIndex *_animated_tile_list;
3c4a0b7894cd (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 7537
diff changeset
   411
extern uint _animated_tile_count;
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
   412
extern char *_old_name_array;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   414
static byte   _old_vehicle_multiplier;
8988
976f1e03a473 (svn r12783) -Codechange: do not statically allocate the 'temporary map3 array' in the oldloader.
rubidium
parents: 8987
diff changeset
   415
static uint8  *_old_map3;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   416
static uint32 _old_town_index;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   417
static uint16 _old_string_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   418
static uint16 _old_string_id_2;
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
   419
static uint16 _old_extra_chunk_nums;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   420
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   421
static void ReadTTDPatchFlags()
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   422
{
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   423
	if (_read_ttdpatch_flags) return;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   424
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   425
	_read_ttdpatch_flags = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   426
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   427
	/* TTDPatch misuses _old_map3 for flags.. read them! */
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   428
	_old_vehicle_multiplier = _old_map3[0];
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   429
	/* Somehow.... there was an error in some savegames, so 0 becomes 1
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   430
	and 1 becomes 2. The rest of the values are okay */
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   431
	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   432
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   433
	_old_vehicle_names = MallocT<StringID>(_old_vehicle_multiplier * 850);
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
   434
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
   435
	/* TTDPatch increases the Vehicle-part in the middle of the game,
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   436
	so if the multipler is anything else but 1, the assert fails..
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   437
	bump the assert value so it doesn't!
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   438
	(1 multipler == 850 vehicles
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   439
	1 vehicle   == 128 bytes */
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   440
	_bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   441
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   442
	for (uint i = 0; i < 17; i++) { // check tile 0, too
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   443
		if (_old_map3[i] != 0) _savegame_type = SGT_TTDP1;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   444
	}
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   445
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
   446
	/* Check if we have a modern TTDPatch savegame (has extra data all around) */
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   447
	if (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0) _savegame_type = SGT_TTDP2;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   448
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   449
	_old_extra_chunk_nums = _old_map3[_savegame_type == SGT_TTDP2 ? 0x1FFFE : 0x2];
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
   450
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   451
	/* Clean the misused places */
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   452
	for (uint i = 0;       i < 17;      i++) _old_map3[i] = 0;
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   453
	for (uint i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   454
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
   455
	if (_savegame_type == SGT_TTDP2) DEBUG(oldloader, 2, "Found TTDPatch game");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   456
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
   457
	DEBUG(oldloader, 3, "Vehicle-multiplier is set to %d (%d vehicles)", _old_vehicle_multiplier, _old_vehicle_multiplier * 850);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   460
static const OldChunks town_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   461
	OCL_SVAR(   OC_TILE, Town, xy ),
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8565
diff changeset
   462
	OCL_NULL( 2 ),         ///< population,        no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   463
	OCL_SVAR( OC_UINT16, Town, townnametype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   464
	OCL_SVAR( OC_UINT32, Town, townnameparts ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   465
	OCL_SVAR(  OC_UINT8, Town, grow_counter ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   466
	OCL_NULL( 1 ),         ///< sort_index,        no longer in use
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   467
	OCL_NULL( 4 ),         ///< sign-coordinates,  no longer in use
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   468
	OCL_NULL( 2 ),         ///< namewidth,         no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   469
	OCL_SVAR( OC_UINT16, Town, flags12 ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   470
	OCL_NULL( 10 ),        ///< radius,            no longer in use
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 974
diff changeset
   471
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   472
	OCL_SVAR( OC_UINT16, Town, ratings[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   473
	OCL_SVAR( OC_UINT16, Town, ratings[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   474
	OCL_SVAR( OC_UINT16, Town, ratings[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   475
	OCL_SVAR( OC_UINT16, Town, ratings[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   476
	OCL_SVAR( OC_UINT16, Town, ratings[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   477
	OCL_SVAR( OC_UINT16, Town, ratings[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   478
	OCL_SVAR( OC_UINT16, Town, ratings[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   479
	OCL_SVAR( OC_UINT16, Town, ratings[7] ),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   481
	/* XXX - This is pretty odd.. we read 32bit, but only write 8bit.. sure there is
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6351
diff changeset
   482
	nothing changed ? ? */
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   483
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, have_ratings ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   484
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, statues ),
8707
e57a09994e12 (svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents: 8565
diff changeset
   485
	OCL_NULL( 2 ),         ///< num_houses,        no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   486
	OCL_SVAR(  OC_UINT8, Town, time_until_rebuild ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   487
	OCL_SVAR(  OC_UINT8, Town, growth_rate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   488
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   489
	OCL_SVAR( OC_UINT16, Town, new_max_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   490
	OCL_SVAR( OC_UINT16, Town, new_max_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   491
	OCL_SVAR( OC_UINT16, Town, new_act_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   492
	OCL_SVAR( OC_UINT16, Town, new_act_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   493
	OCL_SVAR( OC_UINT16, Town, max_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   494
	OCL_SVAR( OC_UINT16, Town, max_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   495
	OCL_SVAR( OC_UINT16, Town, act_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   496
	OCL_SVAR( OC_UINT16, Town, act_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   497
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   498
	OCL_SVAR(  OC_UINT8, Town, pct_pass_transported ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   499
	OCL_SVAR(  OC_UINT8, Town, pct_mail_transported ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   500
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   501
	OCL_SVAR( OC_UINT16, Town, new_act_food ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   502
	OCL_SVAR( OC_UINT16, Town, new_act_water ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   503
	OCL_SVAR( OC_UINT16, Town, act_food ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   504
	OCL_SVAR( OC_UINT16, Town, act_water ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   505
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   506
	OCL_SVAR(  OC_UINT8, Town, road_build_months ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   507
	OCL_SVAR(  OC_UINT8, Town, fund_buildings_months ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   508
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   509
	OCL_NULL( 8 ),         ///< some junk at the end of the record
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   510
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   511
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   512
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   513
static bool LoadOldTown(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   514
{
7399
60dd9641cb34 (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7390
diff changeset
   515
	return LoadChunk(ls, new (num) Town(), town_chunk);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   518
static uint16 _old_order;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   519
static const OldChunks order_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   520
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   521
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   522
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   523
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   524
static bool LoadOldOrder(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
{
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   526
	if (!LoadChunk(ls, NULL, order_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   527
8839
6337281b393b (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 8836
diff changeset
   528
	new (num) Order(UnpackOldOrder(_old_order));
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   529
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   530
	/* Relink the orders to eachother (in TTD(Patch) the orders for one
6263
6bd0726c74e2 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6259
diff changeset
   531
	vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   532
	it is the last order */
6263
6bd0726c74e2 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6259
diff changeset
   533
	if (num > 0 && GetOrder(num)->IsValid())
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   534
		GetOrder(num - 1)->next = GetOrder(num);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   535
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   536
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
7711
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   539
static bool LoadOldAnimTileList(LoadgameState *ls, int num)
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   540
{
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   541
	/* This is sligthly hackish - we must load a chunk into an array whose
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   542
	 * address isn't static, but instead pointed to by _animated_tile_list.
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   543
	 * To achieve that, create an OldChunks list on the stack on the fly.
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   544
	 * The list cannot be static because the value of _animated_tile_list
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   545
	 * can change between calls. */
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   546
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   547
	const OldChunks anim_chunk[] = {
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   548
		OCL_VAR (   OC_TILE, 256, _animated_tile_list ),
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   549
		OCL_END ()
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   550
	};
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   551
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   552
	if (!LoadChunk(ls, NULL, anim_chunk)) return false;
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   553
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   554
	/* Update the animated tile counter by counting till the first zero in the array */
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   555
	for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   556
		if (_animated_tile_list[_animated_tile_count] == 0) break;
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   557
	}
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   558
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   559
	return true;
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   560
}
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
   561
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   562
static const OldChunks depot_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   563
	OCL_SVAR(   OC_TILE, Depot, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   564
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   565
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   566
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   567
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   568
static bool LoadOldDepot(LoadgameState *ls, int num)
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   569
{
7399
60dd9641cb34 (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7390
diff changeset
   570
	if (!LoadChunk(ls, new (num) Depot(), depot_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   571
7389
08d6a6265ced (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7334
diff changeset
   572
	if (IsValidDepotID(num)) {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   573
		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   574
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   575
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   576
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   577
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   578
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   579
static int32 _old_price;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   580
static uint16 _old_price_frac;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   581
static const OldChunks price_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   582
	OCL_VAR (  OC_INT32,   1, &_old_price ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   583
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   584
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   585
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   586
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   587
static bool LoadOldPrice(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   588
{
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   589
	if (!LoadChunk(ls, NULL, price_chunk)) return false;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   590
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   591
	/* We use a struct to store the prices, but they are ints in a row..
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   592
	so just access the struct as an array of int32's */
6957
a9af2426bf77 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 6952
diff changeset
   593
	((Money*)&_price)[num] = _old_price;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   594
	_price_frac[num] = _old_price_frac;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   595
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   596
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   597
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   598
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   599
static const OldChunks cargo_payment_rate_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   600
	OCL_VAR (  OC_INT32,   1, &_old_price ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   601
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   602
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   603
	OCL_NULL( 2 ),         ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   604
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   605
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   606
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   607
static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   608
{
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   609
	if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   610
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   611
	_cargo_payment_rates[num] = -_old_price;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   612
	_cargo_payment_rates_frac[num] = _old_price_frac;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   613
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   614
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   615
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   616
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   617
static uint8  _old_platforms;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   618
static uint   _current_station_id;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   619
static uint16 _waiting_acceptance;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   620
static uint8  _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   621
static uint8  _cargo_days;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   622
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   623
static const OldChunks goods_chunk[] = {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   624
	OCL_VAR ( OC_UINT16, 1,          &_waiting_acceptance ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   625
	OCL_SVAR(  OC_UINT8, GoodsEntry, days_since_pickup ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   626
	OCL_SVAR(  OC_UINT8, GoodsEntry, rating ),
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   627
	OCL_VAR (  OC_UINT8, 1,          &_cargo_source ),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   628
	OCL_VAR (  OC_UINT8, 1,          &_cargo_days ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   629
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   630
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   631
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   632
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   633
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   634
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   635
static bool LoadOldGood(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   636
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   637
	Station *st = GetStation(_current_station_id);
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   638
	GoodsEntry *ge = &st->goods[num];
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   639
	bool ret = LoadChunk(ls, ge, goods_chunk);
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7399
diff changeset
   640
	if (!ret) return false;
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7399
diff changeset
   641
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   642
	SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7399
diff changeset
   643
	SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, _cargo_source != 0xFF);
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7399
diff changeset
   644
	if (GB(_waiting_acceptance, 0, 12) != 0) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   645
		CargoPacket *cp = new CargoPacket();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   646
		cp->source          = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   647
		cp->count           = GB(_waiting_acceptance, 0, 12);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   648
		cp->days_in_transit = _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   649
		ge->cargo.Append(cp);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   650
	}
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
   651
	return ret;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   652
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   653
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   654
static const OldChunks station_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   655
	OCL_SVAR(   OC_TILE, Station, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   656
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   657
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   658
	OCL_NULL( 4 ), ///< bus/lorry tile
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   659
	OCL_SVAR(   OC_TILE, Station, train_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   660
	OCL_SVAR(   OC_TILE, Station, airport_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   661
	OCL_SVAR(   OC_TILE, Station, dock_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   662
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   663
	OCL_VAR (  OC_UINT8,   1, &_old_platforms ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   664
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   665
	OCL_NULL( 1 ),         ///< sort-index, no longer in use
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   666
	OCL_NULL( 2 ),         ///< sign-width, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   667
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   668
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   669
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   670
	OCL_NULL( 4 ),         ///< sign left/top, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   671
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   672
	OCL_SVAR( OC_UINT16, Station, had_vehicle_of_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   673
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   674
	OCL_CHUNK( 12, LoadOldGood ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   675
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   676
	OCL_SVAR(  OC_UINT8, Station, time_since_load ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   677
	OCL_SVAR(  OC_UINT8, Station, time_since_unload ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   678
	OCL_SVAR(  OC_UINT8, Station, delete_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   679
	OCL_SVAR(  OC_UINT8, Station, owner ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   680
	OCL_SVAR(  OC_UINT8, Station, facilities ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   681
	OCL_SVAR(  OC_UINT8, Station, airport_type ),
5877
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5823
diff changeset
   682
	/* Bus/truck status, no longer in use
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5823
diff changeset
   683
	 * Blocked months
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5823
diff changeset
   684
	 * Unknown
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5823
diff changeset
   685
	 */
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5823
diff changeset
   686
	OCL_NULL( 4 ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   687
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Station, airport_flags ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   688
	OCL_NULL( 2 ),         ///< last_vehicle. now last_vehicle_type
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   689
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   690
	OCL_NULL( 4 ),         ///< Junk at end of chunk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   691
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   692
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   693
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   694
static bool LoadOldStation(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   695
{
6631
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
   696
	Station *st = new (num) Station();
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   697
	_current_station_id = num;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   698
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   699
	if (!LoadChunk(ls, st, station_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   700
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   701
5996
4bcab9c286d8 (svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents: 5971
diff changeset
   702
	if (st->IsValid()) {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   703
		if (st->train_tile) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   704
			/* Calculate the trainst_w and trainst_h */
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2099
diff changeset
   705
			uint w = GB(_old_platforms, 3, 3);
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2099
diff changeset
   706
			uint h = GB(_old_platforms, 0, 3);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   707
			st->trainst_w = w;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   708
			st->trainst_h = h;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   709
		}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   710
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   711
		st->town    = GetTown(REMAP_TOWN_IDX(_old_town_index));
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   712
		st->string_id = RemapOldStringID(_old_string_id);
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   713
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   714
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   715
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   716
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   717
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   718
static const OldChunks industry_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   719
	OCL_SVAR(   OC_TILE, Industry, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   720
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   721
	OCL_SVAR(  OC_UINT8, Industry, width ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   722
	OCL_SVAR(  OC_UINT8, Industry, height ),
6636
fec086b5c340 (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 6631
diff changeset
   723
	OCL_NULL( 2 ),  ///< used to be industry's produced_cargo
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   724
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7010
diff changeset
   725
	OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[0] ),
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7010
diff changeset
   726
	OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[1] ),
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   727
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   728
	OCL_SVAR(  OC_UINT8, Industry, production_rate[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   729
	OCL_SVAR(  OC_UINT8, Industry, production_rate[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   730
6636
fec086b5c340 (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 6631
diff changeset
   731
	OCL_NULL( 3 ),  ///< used to be industry's accepts_cargo
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   732
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   733
	OCL_SVAR(  OC_UINT8, Industry, prod_level ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   734
6819
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   735
	OCL_SVAR( OC_UINT16, Industry, this_month_production[0] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   736
	OCL_SVAR( OC_UINT16, Industry, this_month_production[1] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   737
	OCL_SVAR( OC_UINT16, Industry, this_month_transported[0] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   738
	OCL_SVAR( OC_UINT16, Industry, this_month_transported[1] ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   739
6819
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   740
	OCL_SVAR(  OC_UINT8, Industry, last_month_pct_transported[0] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   741
	OCL_SVAR(  OC_UINT8, Industry, last_month_pct_transported[1] ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   742
6819
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   743
	OCL_SVAR( OC_UINT16, Industry, last_month_production[0] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   744
	OCL_SVAR( OC_UINT16, Industry, last_month_production[1] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   745
	OCL_SVAR( OC_UINT16, Industry, last_month_transported[0] ),
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6636
diff changeset
   746
	OCL_SVAR( OC_UINT16, Industry, last_month_transported[1] ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   747
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   748
	OCL_SVAR(  OC_UINT8, Industry, type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   749
	OCL_SVAR(  OC_UINT8, Industry, owner ),
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4845
diff changeset
   750
	OCL_SVAR(  OC_UINT8, Industry, random_color ),
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
   751
	OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Industry, last_prod_year ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   752
	OCL_SVAR( OC_UINT16, Industry, counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   753
	OCL_SVAR(  OC_UINT8, Industry, was_cargo_delivered ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   754
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   755
	OCL_NULL( 9 ), ///< Random junk at the end of this chunk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   756
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   757
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   758
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   759
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   760
static bool LoadOldIndustry(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   761
{
7399
60dd9641cb34 (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7390
diff changeset
   762
	Industry *i = new (num) Industry();
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   763
	if (!LoadChunk(ls, i, industry_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   764
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7389
diff changeset
   765
	if (i->IsValid()) {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   766
		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
7720
cc3fc48c944a (svn r11255) -Fix [FS#1332]: industry counter was not updated on TTD savegame loading
glx
parents: 7711
diff changeset
   767
		IncIndustryTypeCount(i->type);
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   768
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   769
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   770
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   771
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   772
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   773
static CompanyID _current_company_id;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   774
static int32 _old_yearly;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   775
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   776
static const OldChunks _company_yearly_chunk[] = {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   777
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   778
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   779
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   780
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   781
static bool OldCompanyYearly(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   782
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   783
	int i;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   784
	Company *c = GetCompany(_current_company_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   785
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   786
	for (i = 0; i < 13; i++) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   787
		if (!LoadChunk(ls, NULL, _company_yearly_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   788
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   789
		c->yearly_expenses[num][i] = _old_yearly;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   790
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   791
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   792
	return true;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   793
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   795
static const OldChunks _company_economy_chunk[] = {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   796
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   797
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   798
	OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, delivered_cargo ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   799
	OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, performance_history ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   800
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   801
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   802
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   803
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   804
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   805
static bool OldCompanyEconomy(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   807
	int i;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   808
	Company *c = GetCompany(_current_company_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   809
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   810
	if (!LoadChunk(ls, &c->cur_economy, _company_economy_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   811
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   812
	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   813
	c->cur_economy.income   = -c->cur_economy.income;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   814
	c->cur_economy.expenses = -c->cur_economy.expenses;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   815
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   816
	for (i = 0; i < 24; i++) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   817
		if (!LoadChunk(ls, &c->old_economy[i], _company_economy_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   818
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   819
		c->old_economy[i].income   = -c->old_economy[i].income;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   820
		c->old_economy[i].expenses = -c->old_economy[i].expenses;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   821
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   822
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   823
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   824
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   825
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   826
static const OldChunks _company_ai_build_rec_chunk[] = {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   827
	OCL_SVAR(   OC_TILE, AiBuildRec, spec_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   828
	OCL_SVAR(   OC_TILE, AiBuildRec, use_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   829
	OCL_SVAR(  OC_UINT8, AiBuildRec, rand_rng ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   830
	OCL_SVAR(  OC_UINT8, AiBuildRec, cur_building_rule ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   831
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk6 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   832
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk7 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   833
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   834
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   835
	OCL_SVAR(  OC_UINT8, AiBuildRec, direction ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   836
	OCL_SVAR(  OC_UINT8, AiBuildRec, cargo ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   837
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   838
	OCL_NULL( 8 ),  ///< Junk...
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   839
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   840
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   841
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   842
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   843
static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   844
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   845
	Company *c = GetCompany(_current_company_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   846
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   847
	switch (num) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   848
		case 0: return LoadChunk(ls, &_companies_ai[c->index].src,  _company_ai_build_rec_chunk);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   849
		case 1: return LoadChunk(ls, &_companies_ai[c->index].dst,  _company_ai_build_rec_chunk);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   850
		case 2: return LoadChunk(ls, &_companies_ai[c->index].mid1, _company_ai_build_rec_chunk);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   851
		case 3: return LoadChunk(ls, &_companies_ai[c->index].mid2, _company_ai_build_rec_chunk);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   852
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   853
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   854
	return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   855
}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   856
static const OldChunks _company_ai_chunk[] = {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   857
	OCL_SVAR(  OC_UINT8, CompanyAI, state ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   858
	OCL_NULL( 1 ),         ///< Junk
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   859
	OCL_SVAR(  OC_UINT8, CompanyAI, state_mode ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   860
	OCL_SVAR( OC_UINT16, CompanyAI, state_counter ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   861
	OCL_SVAR( OC_UINT16, CompanyAI, timeout_counter ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   862
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   863
	OCL_CHUNK( 4, OldLoadAIBuildRec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   864
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   865
	OCL_NULL( 20 ),        ///< More junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   866
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   867
	OCL_SVAR(  OC_UINT8, CompanyAI, cargo_type ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   868
	OCL_SVAR(  OC_UINT8, CompanyAI, num_wagons ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   869
	OCL_SVAR(  OC_UINT8, CompanyAI, build_kind ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   870
	OCL_SVAR(  OC_UINT8, CompanyAI, num_build_rec ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   871
	OCL_SVAR(  OC_UINT8, CompanyAI, num_loco_to_build ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   872
	OCL_SVAR(  OC_UINT8, CompanyAI, num_want_fullload ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   873
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   874
	OCL_NULL( 14 ),        ///< Oh no more junk :|
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   875
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
   876
	OCL_NULL( 2 ),         ///< Loco-id, not used
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   877
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   878
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[0] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   879
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[1] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   880
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[2] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   881
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[3] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   882
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[4] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   883
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[5] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   884
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[6] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   885
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[7] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   886
	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[8] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   887
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[0] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   888
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[1] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   889
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[2] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   890
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[3] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   891
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[4] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   892
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[5] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   893
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[6] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   894
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[7] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   895
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[8] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   896
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[9] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   897
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[10] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   898
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[11] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   899
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[12] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   900
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[13] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   901
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[14] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   902
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[15] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   903
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[16] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   904
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[17] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   905
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[18] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   906
	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[19] ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   907
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   908
	OCL_SVAR( OC_UINT16, CompanyAI, start_tile_a ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   909
	OCL_SVAR( OC_UINT16, CompanyAI, start_tile_b ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   910
	OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_a ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   911
	OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_b ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   912
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   913
	OCL_SVAR(  OC_UINT8, CompanyAI, start_dir_a ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   914
	OCL_SVAR(  OC_UINT8, CompanyAI, start_dir_b ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   915
	OCL_SVAR(  OC_UINT8, CompanyAI, cur_dir_a ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   916
	OCL_SVAR(  OC_UINT8, CompanyAI, cur_dir_b ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   917
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   918
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_tile_count ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   919
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   920
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[0] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   921
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[0] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   922
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[1] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   923
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[1] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   924
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[2] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   925
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[2] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   926
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[3] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   927
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[3] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   928
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[4] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   929
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[4] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   930
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[5] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   931
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[5] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   932
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[6] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   933
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[6] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   934
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[7] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   935
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[7] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   936
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[8] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   937
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[8] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   938
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[9] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   939
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[9] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   940
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[10] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   941
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[10] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   942
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[11] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   943
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[11] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   944
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[12] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   945
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[12] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   946
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[13] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   947
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[13] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   948
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[14] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   949
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[14] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   950
	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[15] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   951
	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[15] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   952
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   953
	OCL_SVAR(  OC_UINT8, CompanyAI, railtype_to_use ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   954
	OCL_SVAR(  OC_UINT8, CompanyAI, route_type_mask ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   955
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   956
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   957
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
   958
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   959
static bool OldCompanyAI(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   960
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   961
	return LoadChunk(ls, &_companies_ai[_current_company_id], _company_ai_chunk);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   962
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   963
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8221
diff changeset
   964
uint8 ai_tick;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   965
static const OldChunks _company_chunk[] = {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   966
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   967
	OCL_SVAR( OC_UINT32, Company, name_2 ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   968
	OCL_SVAR( OC_UINT32, Company, face ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   969
	OCL_VAR ( OC_UINT16,   1, &_old_string_id_2 ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   970
	OCL_SVAR( OC_UINT32, Company, president_name_2 ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   971
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   972
	OCL_SVAR(  OC_INT32, Company, money ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   973
	OCL_SVAR(  OC_INT32, Company, current_loan ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   974
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   975
	OCL_SVAR(  OC_UINT8, Company, colour ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   976
	OCL_SVAR(  OC_UINT8, Company, money_fraction ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   977
	OCL_SVAR(  OC_UINT8, Company, quarters_of_bankrupcy ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   978
	OCL_SVAR(  OC_UINT8, Company, bankrupt_asked ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   979
	OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   980
	OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   981
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   982
	OCL_SVAR( OC_UINT32, Company, cargo_types ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   983
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   984
	OCL_CHUNK( 3, OldCompanyYearly ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   985
	OCL_CHUNK( 1, OldCompanyEconomy ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   986
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   987
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Company, inaugurated_year),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   988
	OCL_SVAR(                  OC_TILE, Company, last_build_coordinate ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   989
	OCL_SVAR(                 OC_UINT8, Company, num_valid_stat_ent ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   990
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   991
	OCL_CHUNK( 1, OldCompanyAI ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   992
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   993
	OCL_SVAR(  OC_UINT8, Company, block_preview ),
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8221
diff changeset
   994
	 OCL_VAR(  OC_UINT8,   1, &ai_tick ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   995
	OCL_SVAR(  OC_UINT8, Company, avail_railtypes ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   996
	OCL_SVAR(   OC_TILE, Company, location_of_HQ ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   997
	OCL_SVAR(  OC_UINT8, Company, share_owners[0] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   998
	OCL_SVAR(  OC_UINT8, Company, share_owners[1] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
   999
	OCL_SVAR(  OC_UINT8, Company, share_owners[2] ),
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1000
	OCL_SVAR(  OC_UINT8, Company, share_owners[3] ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1001
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1002
	OCL_NULL( 8 ), ///< junk at end of chunk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1003
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1004
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1005
};
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1006
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1007
static bool LoadOldCompany(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1008
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1009
	Company *c = new (num) Company();
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1010
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1011
	_current_company_id = (CompanyID)num;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1012
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1013
	if (!LoadChunk(ls, c, _company_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1014
9620
13e48c238127 (svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
rubidium
parents: 9466
diff changeset
  1015
	if (_old_string_id == 0) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1016
		delete c;
9620
13e48c238127 (svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
rubidium
parents: 9466
diff changeset
  1017
		return true;
13e48c238127 (svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
rubidium
parents: 9466
diff changeset
  1018
	}
13e48c238127 (svn r13676) -Fix [FS#2126]: inactive companies from old (TTD) saves could be marked active in some cases, which then loads garbage in their statistics and such.
rubidium
parents: 9466
diff changeset
  1019
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1020
	c->name_1 = RemapOldStringID(_old_string_id);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1021
	c->president_name_1 = RemapOldStringID(_old_string_id_2);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1022
	_companies_ai[_current_company_id].tick = ai_tick;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1023
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1024
	if (num == 0) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1025
		/* If the first company has no name, make sure we call it UNNAMED */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1026
		if (c->name_1 == 0)
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1027
			c->name_1 = STR_SV_UNNAMED;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1028
	} else {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1029
		/* Beside some multiplayer maps (1 on 1), which we don't official support,
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1030
		 * all other companys are an AI.. mark them as such */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1031
		c->is_ai = true;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1032
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1033
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1034
	/* Sometimes it is better to not ask.. in old scenarios, the money
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1035
	 * was always 893288 pounds. In the newer versions this is correct,
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1036
	 * but correct for those oldies
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1037
	 * Ps: this also means that if you had exact 893288 pounds, you will go back
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1038
	 * to 10000.. this is a very VERY small chance ;) */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1039
	if (c->money == 893288) c->money = c->current_loan = 100000;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1040
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1041
	_company_colours[num] = c->colour;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1042
	c->inaugurated_year -= ORIGINAL_BASE_YEAR;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1043
	if (c->location_of_HQ == 0xFFFF)
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1044
		c->location_of_HQ = 0;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1045
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1046
	/* State 20 for AI companies is sell vehicle. Since the AI struct is not
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1047
	 * really figured out as of now, _companies_ai[c->index].cur_veh; needed for 'sell vehicle'
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1048
	 * is NULL and the function will crash. To fix this, just change the state
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1049
	 * to some harmless state, like 'loop vehicle'; 1 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1050
	if (!IsHumanCompany((CompanyID)num) && _companies_ai[c->index].state == 20) _companies_ai[c->index].state = 1;
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1051
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1052
	if (c->is_ai && (!_networking || _network_server) && _ai.enabled)
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1053
		AI_StartNewAI(c->index);
2814
872583ce2ae7 (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
  1054
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1055
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1056
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1057
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1058
static uint32 _old_order_ptr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1059
static uint16 _old_next_ptr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1060
static uint32 _current_vehicle_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1061
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1062
static const OldChunks vehicle_train_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1063
	OCL_SVAR(  OC_UINT8, VehicleRail, track ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1064
	OCL_SVAR(  OC_UINT8, VehicleRail, force_proceed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1065
	OCL_SVAR( OC_UINT16, VehicleRail, crash_anim_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1066
	OCL_SVAR(  OC_UINT8, VehicleRail, railtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1067
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1068
	OCL_NULL( 5 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1069
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1070
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1071
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1072
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1073
static const OldChunks vehicle_road_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1074
	OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1075
	OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
3009
c75f1a8d5ff9 (svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents: 2951
diff changeset
  1076
	OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1077
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1078
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1079
	OCL_SVAR( OC_UINT16, VehicleRoad, crashed_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1080
	OCL_SVAR(  OC_UINT8, VehicleRoad, reverse_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1081
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1082
	OCL_NULL( 1 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1083
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1084
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1085
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1086
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1087
static const OldChunks vehicle_ship_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1088
	OCL_SVAR(  OC_UINT8, VehicleShip, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1089
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1090
	OCL_NULL( 9 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1091
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1092
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1093
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1094
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1095
static const OldChunks vehicle_air_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1096
	OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1097
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1098
	OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1099
	OCL_SVAR(  OC_UINT8, VehicleAir, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1100
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1101
	OCL_NULL( 5 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1102
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1103
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1104
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1105
9008
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1106
static const OldChunks vehicle_effect_chunk[] = {
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1107
	OCL_SVAR( OC_UINT16, VehicleEffect, animation_state ),
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1108
	OCL_SVAR(  OC_UINT8, VehicleEffect, animation_substate ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1109
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1110
	OCL_NULL( 7 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1111
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1112
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1113
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1114
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1115
static const OldChunks vehicle_disaster_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1116
	OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7272
diff changeset
  1117
	OCL_SVAR( OC_UINT16, VehicleDisaster, big_ufo_destroyer_target ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1118
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1119
	OCL_NULL( 6 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1120
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1121
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1122
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1123
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1124
static const OldChunks vehicle_empty_chunk[] = {
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1125
	OCL_NULL( 10 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1126
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1127
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1128
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1129
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1130
static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1131
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1132
	Vehicle *v = GetVehicle(_current_vehicle_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1133
	uint temp = ls->total_read;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1134
	bool res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1135
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1136
	switch (v->type) {
6014
cd30e198dfa6 (svn r8737) -Regression (r8621): VEH_Type renumbering wasn't performed for TTD(P) games, failing to load them
Darkvater
parents: 5996
diff changeset
  1137
		default: NOT_REACHED();
8725
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1138
		case VEH_INVALID : res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1139
		case VEH_TRAIN   : res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1140
		case VEH_ROAD    : res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1141
		case VEH_SHIP    : res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1142
		case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
9008
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1143
		case VEH_EFFECT  : res = LoadChunk(ls, &v->u.effect,   vehicle_effect_chunk);   break;
8725
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1144
		case VEH_DISASTER: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1145
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1146
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1147
	/* This chunk size should always be 10 bytes */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1148
	if (ls->total_read - temp != 10) {
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
  1149
		DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1150
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1151
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1152
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1153
	return res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1154
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1155
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1156
static uint16 _cargo_count;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1157
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1158
static const OldChunks vehicle_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1159
	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1160
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1161
	OCL_NULL( 2 ),         ///< Hash, calculated automatically
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1162
	OCL_NULL( 2 ),         ///< Index, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1163
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1164
	OCL_VAR ( OC_UINT32,   1, &_old_order_ptr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1165
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1166
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1167
	OCL_SVAR(  OC_UINT8, Vehicle, num_orders ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1168
	OCL_SVAR(  OC_UINT8, Vehicle, cur_order_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1169
	OCL_SVAR(   OC_TILE, Vehicle, dest_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1170
	OCL_SVAR( OC_UINT16, Vehicle, load_unload_time_rem ),
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1171
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, date_of_last_service ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1172
	OCL_SVAR( OC_UINT16, Vehicle, service_interval ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1173
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, last_station_visited ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1174
	OCL_SVAR(  OC_UINT8, Vehicle, tick_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1175
	OCL_SVAR( OC_UINT16, Vehicle, max_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1176
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1177
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, x_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1178
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, y_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1179
	OCL_SVAR(  OC_UINT8, Vehicle, z_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1180
	OCL_SVAR(  OC_UINT8, Vehicle, direction ),
6561
073e48516812 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 6552
diff changeset
  1181
	OCL_NULL( 2 ),         ///< x_offs and y_offs, calculated automatically
8793
5e35232593c3 (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 8790
diff changeset
  1182
	OCL_NULL( 2 ),         ///< x_extent and y_extent, calculated automatically
5e35232593c3 (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 8790
diff changeset
  1183
	OCL_NULL( 1 ),         ///< z_extent, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1184
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1185
	OCL_SVAR(  OC_UINT8, Vehicle, owner ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1186
	OCL_SVAR(   OC_TILE, Vehicle, tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1187
	OCL_SVAR( OC_UINT16, Vehicle, cur_image ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1188
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1189
	OCL_NULL( 8 ),        ///< Vehicle sprite box, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1190
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1191
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Vehicle, vehstatus ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1192
	OCL_SVAR( OC_UINT16, Vehicle, cur_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1193
	OCL_SVAR(  OC_UINT8, Vehicle, subspeed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1194
	OCL_SVAR(  OC_UINT8, Vehicle, acceleration ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1195
	OCL_SVAR(  OC_UINT8, Vehicle, progress ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1196
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1197
	OCL_SVAR(  OC_UINT8, Vehicle, cargo_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1198
	OCL_SVAR( OC_UINT16, Vehicle, cargo_cap ),
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1199
	OCL_VAR ( OC_UINT16, 1,       &_cargo_count ),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1200
	OCL_VAR (  OC_UINT8, 1,       &_cargo_source ),
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1201
	OCL_VAR (  OC_UINT8, 1,       &_cargo_days ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1202
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1203
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, age ),
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1204
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, max_age ),
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1205
	OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Vehicle, build_year ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1206
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, unitnumber ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1207
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1208
	OCL_SVAR( OC_UINT16, Vehicle, engine_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1209
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1210
	OCL_SVAR(  OC_UINT8, Vehicle, spritenum ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1211
	OCL_SVAR(  OC_UINT8, Vehicle, day_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1212
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1213
	OCL_SVAR(  OC_UINT8, Vehicle, breakdowns_since_last_service ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1214
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1215
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_delay ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1216
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_chance ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1217
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1218
	OCL_SVAR( OC_UINT16, Vehicle, reliability ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1219
	OCL_SVAR( OC_UINT16, Vehicle, reliability_spd_dec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1220
7743
7a72920ed865 (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 7738
diff changeset
  1221
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_this_year ),
7a72920ed865 (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 7738
diff changeset
  1222
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_last_year ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1223
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1224
	OCL_VAR ( OC_UINT16,   1, &_old_next_ptr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1225
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1226
	OCL_SVAR( OC_UINT32, Vehicle, value ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1227
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1228
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1229
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1230
	OCL_CHUNK( 1, LoadOldVehicleUnion ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1231
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1232
	OCL_NULL( 20 ), ///< Junk at end of struct (TTDPatch has some data in it)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1233
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1234
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1235
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1236
7537
0b720e804ae2 (svn r11057) -Fix [FS#1215]: loading TTD savegames went into an infinite loop due to not yet properly set next and previous pointers.
rubidium
parents: 7493
diff changeset
  1237
bool LoadOldVehicle(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1238
{
959
e6a3bbda610f (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 923
diff changeset
  1239
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1241
	/* Read the TTDPatch flags, because we need some info from it */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1242
	ReadTTDPatchFlags();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1244
	for (i = 0; i < _old_vehicle_multiplier; i++) {
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1245
		_current_vehicle_id = num * _old_vehicle_multiplier + i;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1246
8725
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1247
		/* Read the vehicle type and allocate the right vehicle */
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1248
		Vehicle *v;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1249
		switch (ReadByte(ls)) {
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1250
			default: NOT_REACHED();
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1251
			case 0x00 /*VEH_INVALID */: v = new (_current_vehicle_id) InvalidVehicle();  break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1252
			case 0x10 /*VEH_TRAIN   */: v = new (_current_vehicle_id) Train();           break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1253
			case 0x11 /*VEH_ROAD    */: v = new (_current_vehicle_id) RoadVehicle();     break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1254
			case 0x12 /*VEH_SHIP    */: v = new (_current_vehicle_id) Ship();            break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1255
			case 0x13 /*VEH_AIRCRAFT*/: v = new (_current_vehicle_id) Aircraft();        break;
9008
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1256
			case 0x14 /*VEH_EFFECT  */: v = new (_current_vehicle_id) EffectVehicle();   break;
8725
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1257
			case 0x15 /*VEH_DISASTER*/: v = new (_current_vehicle_id) DisasterVehicle(); break;
82b411efffdc (svn r12401) -Fix (r9754): when loading TTD savegame some data were lost (profits, ...) due to a 'reallocation' for vehicle type conversion. The conversion is now done before loading the vehicle chunk.
glx
parents: 8724
diff changeset
  1258
		}
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1259
		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1260
1340
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1261
		/* This should be consistent, else we have a big problem... */
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1262
		if (v->index != _current_vehicle_id) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1263
			DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid");
1340
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1264
			return false;
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1265
		}
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1266
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1267
		if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
8724
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1268
			uint old_id = REMAP_ORDER_IDX(_old_order_ptr);
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1269
			/* There is a maximum of 5000 orders in old savegames, so *if*
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1270
			 * we go over that limit something is very wrong. In that case
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1271
			 * we just assume there are no orders for the vehicle.
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1272
			 */
9a3f2c2116fd (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 8707
diff changeset
  1273
			if (old_id < 5000) v->orders = GetOrder(old_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1274
		}
8835
8fa962d90b63 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents: 8793
diff changeset
  1275
		v->current_order.AssignOrder(UnpackOldOrder(_old_order));
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1276
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1277
		/* For some reason we need to correct for this */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1278
		switch (v->spritenum) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1279
			case 0xfd: break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1280
			case 0xff: v->spritenum = 0xfe; break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1281
			default:   v->spritenum >>= 1; break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1282
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1283
7738
1c288fd7f2bc (svn r11275) -Fix: oldloader crashing when referencing a vehicle that is not yet loaded.
rubidium
parents: 7736
diff changeset
  1284
		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1285
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
  1286
		_old_vehicle_names[_current_vehicle_id] = RemapOldStringID(_old_string_id);
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
  1287
		v->name = NULL;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1288
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1289
		/* Vehicle-subtype is different in TTD(Patch) */
9008
de19c73e405f (svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents: 8988
diff changeset
  1290
		if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1291
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1292
		if (_cargo_count != 0) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1293
			CargoPacket *cp = new CargoPacket((_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, _cargo_count);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1294
			cp->days_in_transit = _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1295
			v->cargo.Append(cp);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6957
diff changeset
  1296
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1299
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1300
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1301
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1302
static const OldChunks sign_chunk[] = {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1303
	OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6351
diff changeset
  1304
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ),
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6351
diff changeset
  1305
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ),
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1306
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1307
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1308
	OCL_NULL( 6 ),         ///< Width of sign, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1309
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1310
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1311
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1312
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1313
static bool LoadOldSign(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1314
{
8260
b0187eaec344 (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8259
diff changeset
  1315
	Sign *si = new (num) Sign();
b0187eaec344 (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8259
diff changeset
  1316
	if (!LoadChunk(ls, si, sign_chunk)) return false;
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1317
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1318
	_old_string_id = RemapOldStringID(_old_string_id);
8260
b0187eaec344 (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8259
diff changeset
  1319
	si->name = CopyFromOldName(_old_string_id);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1320
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1321
	return true;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1322
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1323
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1324
static const OldChunks engine_chunk[] = {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1325
	OCL_SVAR( OC_UINT16, Engine, company_avail ),
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1326
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1327
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1328
	OCL_SVAR( OC_UINT16, Engine, reliability ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1329
	OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1330
	OCL_SVAR( OC_UINT16, Engine, reliability_start ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1331
	OCL_SVAR( OC_UINT16, Engine, reliability_max ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1332
	OCL_SVAR( OC_UINT16, Engine, reliability_final ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1333
	OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1334
	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1335
	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1336
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1337
	OCL_SVAR(  OC_UINT8, Engine, lifelength ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1338
	OCL_SVAR(  OC_UINT8, Engine, flags ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1339
	OCL_SVAR(  OC_UINT8, Engine, preview_company_rank ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1340
	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1341
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1342
	OCL_NULL( 2 ), ///< Junk
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1343
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1344
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1345
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1346
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1347
static bool LoadOldEngine(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1348
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9017
diff changeset
  1349
	Engine *e = GetTempDataEngine(num);
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10336
diff changeset
  1350
	return LoadChunk(ls, e, engine_chunk);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1351
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1352
8259
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1353
static bool LoadOldEngineName(LoadgameState *ls, int num)
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1354
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9017
diff changeset
  1355
	Engine *e = GetTempDataEngine(num);
8259
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1356
	e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1357
	return true;
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1358
}
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1359
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1360
static const OldChunks subsidy_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1361
	OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1362
	OCL_SVAR(  OC_UINT8, Subsidy, age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1363
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1364
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1365
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1366
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1367
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1368
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1369
static inline bool LoadOldSubsidy(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1370
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1371
	return LoadChunk(ls, &_subsidies[num], subsidy_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1372
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1373
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1374
static const OldChunks game_difficulty_chunk[] = {
9358
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1375
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, max_no_competitors ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1376
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, competitor_start_time ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1377
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_towns ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1378
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, number_industries ),
9359
3a8554ac1cb8 (svn r13256) -Codechange: merge the OPTS and PATS chuncks.
rubidium
parents: 9358
diff changeset
  1379
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, DifficultySettings, max_loan ),
9358
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1380
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, initial_interest ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1381
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_costs ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1382
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, competitor_speed ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1383
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, competitor_intelligence ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1384
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, vehicle_breakdowns ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1385
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, subsidy_multiplier ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1386
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, construction_cost ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1387
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, terrain_type ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1388
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, quantity_sea_lakes ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1389
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, economy ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1390
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, line_reverse_mode ),
2e1e4d2f71dd (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 9200
diff changeset
  1391
	OCL_SVAR( OC_FILE_U16 |  OC_VAR_U8, DifficultySettings, disasters ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1392
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1393
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1394
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1395
static inline bool LoadOldGameDifficulty(LoadgameState *ls, int num)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1396
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1397
	bool ret = LoadChunk(ls, &_settings_game.difficulty, game_difficulty_chunk);
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1398
	_settings_game.difficulty.max_loan *= 1000;
9359
3a8554ac1cb8 (svn r13256) -Codechange: merge the OPTS and PATS chuncks.
rubidium
parents: 9358
diff changeset
  1399
	return ret;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1400
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1401
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1402
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1403
static bool LoadOldMapPart1(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1404
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1405
	uint i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1406
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1407
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2186
diff changeset
  1408
		_m[i].m1 = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1409
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1410
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1411
		_m[i].m2 = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1412
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1413
	for (i = 0; i < OLD_MAP_SIZE; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1414
		_old_map3[i * 2] = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1415
		_old_map3[i * 2 + 1] = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1416
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1417
	for (i = 0; i < OLD_MAP_SIZE / 4; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1418
		byte b = ReadByte(ls);
5596
5bf7128140a0 (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5587
diff changeset
  1419
		_m[i * 4 + 0].m6 = GB(b, 0, 2);
5bf7128140a0 (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5587
diff changeset
  1420
		_m[i * 4 + 1].m6 = GB(b, 2, 2);
5bf7128140a0 (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5587
diff changeset
  1421
		_m[i * 4 + 2].m6 = GB(b, 4, 2);
5bf7128140a0 (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5587
diff changeset
  1422
		_m[i * 4 + 3].m6 = GB(b, 6, 2);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1423
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1424
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1425
	return !ls->failed;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1426
}
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1427
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1428
static bool LoadOldMapPart2(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1429
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1430
	uint i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1431
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1432
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1433
		_m[i].type_height = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1434
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1435
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1436
		_m[i].m5 = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1437
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1438
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1439
	return !ls->failed;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1440
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1441
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1442
static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int num)
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1443
{
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1444
	ReadTTDPatchFlags();
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1445
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1446
	DEBUG(oldloader, 2, "Found %d extra chunk(s)", _old_extra_chunk_nums);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1447
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1448
	for (int i = 0; i != _old_extra_chunk_nums; i++) {
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1449
		uint16 id = ReadUint16(ls);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1450
		uint32 len = ReadUint32(ls);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1451
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1452
		switch (id) {
6085
f6f90fd20181 (svn r8820) -Codechange (r8807, r8806): Remove the unneeded calloc/free allocation of GRFConfig and turn it into a simple variable (it's supposed to be data-only). Thanks Tron.
Darkvater
parents: 6074
diff changeset
  1453
			/* List of GRFIDs, used in the savegame. 0x8004 is the new ID
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1454
			 * They are saved in a 'GRFID:4 active:1' format, 5 bytes for each entry */
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1455
			case 0x2:
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1456
			case 0x8004: {
6085
f6f90fd20181 (svn r8820) -Codechange (r8807, r8806): Remove the unneeded calloc/free allocation of GRFConfig and turn it into a simple variable (it's supposed to be data-only). Thanks Tron.
Darkvater
parents: 6074
diff changeset
  1457
				/* Skip the first element: TTDP hack for the Action D special variables (FFFF0000 01) */
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1458
				ReadUint32(ls); ReadByte(ls); len -= 5;
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1459
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1460
				ClearGRFConfigList(&_grfconfig);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1461
				while (len != 0) {
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1462
					uint32 grfid = ReadUint32(ls);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1463
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1464
					if (ReadByte(ls) == 1) {
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6085
diff changeset
  1465
						GRFConfig *c = CallocT<GRFConfig>(1);
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6085
diff changeset
  1466
						c->grfid = grfid;
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6085
diff changeset
  1467
						c->filename = strdup("TTDP game, no information");
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1468
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6085
diff changeset
  1469
						AppendToGRFConfigList(&_grfconfig, c);
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6085
diff changeset
  1470
						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid));
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1471
					}
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1472
					len -= 5;
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1473
				};
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1474
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1475
				/* Append static NewGRF configuration */
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1476
				AppendStaticGRFConfigs(&_grfconfig);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1477
			} break;
6085
f6f90fd20181 (svn r8820) -Codechange (r8807, r8806): Remove the unneeded calloc/free allocation of GRFConfig and turn it into a simple variable (it's supposed to be data-only). Thanks Tron.
Darkvater
parents: 6074
diff changeset
  1478
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1479
			/* TTDPatch version and configuration */
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
  1480
			case 0x3:
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
  1481
				_ttdp_version = ReadUint32(ls);
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
  1482
				DEBUG(oldloader, 3, "Game saved with TTDPatch version %d.%d.%d r%d",
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
  1483
					GB(_ttdp_version, 24, 8), GB(_ttdp_version, 20, 4), GB(_ttdp_version, 16, 4), GB(_ttdp_version, 0, 16));
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1484
				len -= 4;
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1485
				while (len-- != 0) ReadByte(ls); // skip the configuration
9102
bc00c1654067 (svn r12962) -Fix (r12961): forgot one break
smatz
parents: 9101
diff changeset
  1486
				break;
6085
f6f90fd20181 (svn r8820) -Codechange (r8807, r8806): Remove the unneeded calloc/free allocation of GRFConfig and turn it into a simple variable (it's supposed to be data-only). Thanks Tron.
Darkvater
parents: 6074
diff changeset
  1487
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1488
			default:
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1489
				DEBUG(oldloader, 4, "Skipping unknown extra chunk %X", id);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1490
				while (len-- != 0) ReadByte(ls);
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1491
				break;
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1492
		}
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1493
	}
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1494
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1495
	return !ls->failed;
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1496
}
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1497
8973
749e572f9378 (svn r12765) -Codechange: move some stuff out of variables.h that required including other headers in variables.h.
rubidium
parents: 8962
diff changeset
  1498
extern TileIndex _cur_tileloop_tile;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1499
static uint32 _old_cur_town_ctr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1500
static const OldChunks main_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1501
	OCL_ASSERT( 0 ),
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1502
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_date ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1503
	OCL_VAR ( OC_UINT16,   1, &_date_fract ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1504
	OCL_NULL( 600 ),            ///< TextEffects
8434
558c39956ba2 (svn r12004) -Codechange: refactor the random functions to reduce code duplication.
rubidium
parents: 8412
diff changeset
  1505
	OCL_VAR ( OC_UINT32,   2, &_random.state ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1506
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1507
	OCL_ASSERT( 0x264 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1508
	OCL_CHUNK(  70, LoadOldTown ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1509
	OCL_ASSERT( 0x1C18 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1510
	OCL_CHUNK(5000, LoadOldOrder ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1511
	OCL_ASSERT( 0x4328 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1512
7711
7e1bb2c5dc99 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 7694
diff changeset
  1513
	OCL_CHUNK( 1, LoadOldAnimTileList ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1514
	OCL_NULL( 4 ),              ///< old end-of-order-list-pointer, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1515
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1516
	OCL_CHUNK( 255, LoadOldDepot ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1517
	OCL_ASSERT( 0x4B26 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1518
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1519
	OCL_VAR ( OC_UINT32,   1, &_old_cur_town_ctr ),
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1520
	OCL_NULL( 2 ),              ///< timer_counter, no longer in use
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1521
	OCL_NULL( 2 ),              ///< land_code,     no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1522
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1523
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1524
	OCL_VAR ( OC_UINT16,   1, &_tick_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1525
	OCL_VAR (   OC_TILE,   1, &_cur_tileloop_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1526
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1527
	OCL_CHUNK( 49, LoadOldPrice ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1528
	OCL_CHUNK( 12, LoadOldCargoPaymentRate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1529
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1530
	OCL_ASSERT( 0x4CBA ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1531
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1532
	OCL_CHUNK( 1, LoadOldMapPart1 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1533
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1534
	OCL_ASSERT( 0x48CBA ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1535
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1536
	OCL_CHUNK(250, LoadOldStation ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1537
	OCL_CHUNK( 90, LoadOldIndustry ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1538
	OCL_CHUNK(  8, LoadOldCompany ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1539
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1540
	OCL_ASSERT( 0x547F2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1541
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1542
	OCL_CHUNK( 850, LoadOldVehicle ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1543
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1544
	OCL_ASSERT( 0x6F0F2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1545
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8973
diff changeset
  1546
	OCL_VAR (  OC_UINT8 | OC_DEREFERENCE_POINTER, 32 * 500, &_old_name_array ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1547
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1548
	OCL_NULL( 0x2000 ),            ///< Old hash-table, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1549
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1550
	OCL_CHUNK( 40, LoadOldSign ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1551
	OCL_CHUNK(256, LoadOldEngine ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1552
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1553
	OCL_VAR ( OC_UINT16,    1, &_vehicle_id_ctr_day ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1554
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1555
	OCL_CHUNK(  8, LoadOldSubsidy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1556
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1557
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,   1, &_next_competitor_start ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1558
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_x ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1559
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_y ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1560
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8,    1, &_saved_scrollpos_zoom ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1561
7743
7a72920ed865 (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 7738
diff changeset
  1562
	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan ),
7a72920ed865 (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 7738
diff changeset
  1563
	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan_unround ),
9623
fce00b25b921 (svn r13679) -Fix [FS#2131]: saving TTD imported games in recession failed due to wrong (and unneeded) type conversions in the saveload code.
rubidium
parents: 9620
diff changeset
  1564
	OCL_VAR (  OC_INT16,    1, &_economy.fluct ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1565
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1566
	OCL_VAR ( OC_UINT16,    1, &_disaster_delay ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1567
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1568
	OCL_NULL( 144 ),             ///< cargo-stuff, calculated in InitializeLandscapeVariables
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1569
8259
3fb6f1f46a4f (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8258
diff changeset
  1570
	OCL_CHUNK(256, LoadOldEngineName ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1571
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1572
	OCL_NULL( 144 ),             ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1573
	OCL_NULL( 2 ),               ///< Company indexes of companies, no longer in use
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1574
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1575
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1576
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
  1577
	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.currency ),
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
  1578
	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.units ),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1579
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_company_tick_index ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1580
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1581
	OCL_NULL( 2 ),               ///< Date stuff, calculated automatically
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1582
	OCL_NULL( 8 ),               ///< Company colors, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1583
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1584
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1585
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount_pr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1586
	OCL_VAR (  OC_UINT8,    1, &_economy.interest_rate ),
5971
b21fda7c7f1e (svn r8660) -Fix
tron
parents: 5879
diff changeset
  1587
	OCL_NULL( 1 ), // available airports
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1588
	OCL_VAR (  OC_UINT8,    1, &_settings_game.vehicle.road_side ),
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1589
	OCL_VAR (  OC_UINT8,    1, &_settings_game.game_creation.town_name ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1590
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1591
	OCL_CHUNK( 1, LoadOldGameDifficulty ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1592
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1593
	OCL_ASSERT( 0x77130 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1594
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1595
	OCL_VAR (  OC_UINT8,    1, &_settings_game.difficulty.diff_level ),
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1596
	OCL_VAR (  OC_UINT8,    1, &_settings_game.game_creation.landscape ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1597
	OCL_VAR (  OC_UINT8,    1, &_trees_tick_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1598
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1599
	OCL_NULL( 1 ),               ///< Custom vehicle types yes/no, no longer used
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1600
	OCL_VAR (  OC_UINT8,    1, &_settings_game.game_creation.snow_line ),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1601
6351
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1602
	OCL_NULL( 32 ),              ///< new_industry_randtable, no longer used (because of new design)
8d0b6cce8d6d (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6263
diff changeset
  1603
	OCL_NULL( 36 ),              ///< cargo-stuff, calculated in InitializeLandscapeVariables
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1604
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1605
	OCL_ASSERT( 0x77179 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1606
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1607
	OCL_CHUNK( 1, LoadOldMapPart2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1608
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1609
	OCL_ASSERT( 0x97179 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1610
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1611
	/* Below any (if available) extra chunks from TTDPatch can follow */
6074
5d7d0c753d49 (svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
Darkvater
parents: 6017
diff changeset
  1612
	OCL_CHUNK(1, LoadTTDPatchExtraChunks),
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1613
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1614
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1615
};
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1616
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1617
static bool LoadOldMain(LoadgameState *ls)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1618
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1619
	int i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1620
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1621
	/* The first 49 is the name of the game + checksum, skip it */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1622
	fseek(ls->file, HEADER_SIZE, SEEK_SET);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1623
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
  1624
	DEBUG(oldloader, 3, "Reading main chunk...");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1625
	/* Load the biggest chunk */
8988
976f1e03a473 (svn r12783) -Codechange: do not statically allocate the 'temporary map3 array' in the oldloader.
rubidium
parents: 8987
diff changeset
  1626
	_old_map3 = MallocT<byte>(OLD_MAP_SIZE * 2);
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
  1627
	_old_vehicle_names = NULL;
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1628
	if (!LoadChunk(ls, NULL, main_chunk)) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1629
		DEBUG(oldloader, 0, "Loading failed");
8988
976f1e03a473 (svn r12783) -Codechange: do not statically allocate the 'temporary map3 array' in the oldloader.
rubidium
parents: 8987
diff changeset
  1630
		free(_old_map3);
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
  1631
		free(_old_vehicle_names);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1632
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1633
	}
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
  1634
	DEBUG(oldloader, 3, "Done, converting game data...");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1635
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1636
	/* Fix some general stuff */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1637
	_settings_game.game_creation.landscape = _settings_game.game_creation.landscape & 0xF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1638
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1639
	/* Remap some pointers */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1640
	_cur_town_ctr      = REMAP_TOWN_IDX(_old_cur_town_ctr);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1641
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1642
	/* _old_map3 is changed in _map3_lo and _map3_hi */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1643
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1644
		_m[i].m3 = _old_map3[i * 2];
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1645
		_m[i].m4 = _old_map3[i * 2 + 1];
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1646
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1647
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1648
	for (i = 0; i < OLD_MAP_SIZE; i ++) {
6015
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1649
		switch (GetTileType(i)) {
6631
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1650
			case MP_STATION:
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1651
				_m[i].m4 = 0; // We do not understand this TTDP station mapping (yet)
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1652
				switch (_m[i].m5) {
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1653
					/* We have drive through stops at a totally different place */
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7165
diff changeset
  1654
					case 0x53: case 0x54: _m[i].m5 += 170 - 0x53; break; // Bus drive through
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7165
diff changeset
  1655
					case 0x57: case 0x58: _m[i].m5 += 168 - 0x57; break; // Truck drive through
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7165
diff changeset
  1656
					case 0x55: case 0x56: _m[i].m5 += 170 - 0x55; break; // Bus tram stop
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7165
diff changeset
  1657
					case 0x59: case 0x5A: _m[i].m5 += 168 - 0x59; break; // Truck tram stop
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7165
diff changeset
  1658
					default: break;
6631
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1659
				}
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1660
				break;
731f150daf08 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 6561
diff changeset
  1661
6015
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1662
			case MP_RAILWAY:
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1663
				/* We save presignals different from TTDPatch, convert them */
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1664
				if (GetRailTileType(i) == RAIL_TILE_SIGNALS) {
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1665
					/* This byte is always zero in TTD for this type of tile */
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1666
					if (_m[i].m4) /* Convert the presignals to our own format */
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1667
						_m[i].m4 = (_m[i].m4 >> 1) & 7;
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1668
				}
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1669
				/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1670
				 * clear it for ourselves and let OTTD's rebuild PBS itself */
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1671
				_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
210486c21833 (svn r8738) -Fix: TTDP games have all tiles touching the water marked as MP_WATER, we do not (tiles with one corner, or steep tiles), so check and fix these tiles.
Darkvater
parents: 6014
diff changeset
  1672
				break;
9200
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1673
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1674
			case MP_WATER:
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1675
				if (GetWaterClass(i) == 3) MakeRiver(i, Random());
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1676
				break;
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1677
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1678
			default:
ae323616f9ab (svn r13066) -Fix [FS#2005]: loading of TTDP savegames with rivers in them.
rubidium
parents: 9111
diff changeset
  1679
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
7736
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1683
	/* Make sure the available engines are really available, otherwise
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1684
	 * we will get a "new vehicle"-spree. */
8401
26fb10da8c68 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8264
diff changeset
  1685
	Engine *e;
26fb10da8c68 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8264
diff changeset
  1686
	FOR_ALL_ENGINES(e) {
7736
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1687
		if (_date >= (e->intro_date + 365)) {
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1688
			e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10010
diff changeset
  1689
			e->company_avail = (CompanyMask)-1;
7736
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1690
		}
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1691
	}
0686379ea57b (svn r11271) -Fix [FS#1333]: some (very) old games (TTD original scenarios for example) would give a new vehicle spree, even though the vehicles were introduced decades ago.
rubidium
parents: 7720
diff changeset
  1692
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1693
	/* Fix the game to be compatible with OpenTTD */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1694
	FixOldTowns();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1695
	FixOldStations();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1696
	FixOldVehicles();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1698
	/* We have a new difficulty setting */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9359
diff changeset
  1699
	_settings_game.difficulty.town_council_tolerance = Clamp(_settings_game.difficulty.diff_level, 0, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
  1701
	DEBUG(oldloader, 3, "Finished converting game data");
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1702
	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
8988
976f1e03a473 (svn r12783) -Codechange: do not statically allocate the 'temporary map3 array' in the oldloader.
rubidium
parents: 8987
diff changeset
  1704
	free(_old_map3);
9749
ad943e548576 (svn r13884) -Fix (r11822): custom vehicle names from TTD(Patch) games were lost
smatz
parents: 9659
diff changeset
  1705
	free(_old_vehicle_names);
8988
976f1e03a473 (svn r12783) -Codechange: do not statically allocate the 'temporary map3 array' in the oldloader.
rubidium
parents: 8987
diff changeset
  1706
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1707
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1708
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1709
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1710
bool LoadOldSaveGame(const char *file)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1711
{
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1712
	LoadgameState ls;
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1713
6016
2ef12cdf79db (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6015
diff changeset
  1714
	DEBUG(oldloader, 3, "Trying to load a TTD(Patch) savegame");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1715
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1716
	InitLoading(&ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1717
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1718
	/* Open file */
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1719
	ls.file = fopen(file, "rb");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1720
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1721
	if (ls.file == NULL) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1722
		DEBUG(oldloader, 0, "Cannot open file '%s'", file);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1723
		return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1726
	/* Load the main chunk */
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1727
	if (!LoadOldMain(&ls)) return false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
  1728
2452
f49ab2c9d83b (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1729
	fclose(ls.file);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1730
9101
40c05255536e (svn r12961) -Codechange: store the type of savegame we are loading in a global variable
smatz
parents: 9070
diff changeset
  1731
	/* Some old TTD(Patch) savegames could have buoys at tile 0
8875
cbf73f3c1de3 (svn r12642) -Fix: remove buggy buoys at tile 0 from old TTDP savegames
smatz
parents: 8839
diff changeset
  1732
	 * (without assigned station struct)
cbf73f3c1de3 (svn r12642) -Fix: remove buggy buoys at tile 0 from old TTDP savegames
smatz
parents: 8839
diff changeset
  1733
	 * MakeWater() can be used as long as sea has the same
cbf73f3c1de3 (svn r12642) -Fix: remove buggy buoys at tile 0 from old TTDP savegames
smatz
parents: 8839
diff changeset
  1734
	 * format as old savegames (eg. everything is zeroed) */
cbf73f3c1de3 (svn r12642) -Fix: remove buggy buoys at tile 0 from old TTDP savegames
smatz
parents: 8839
diff changeset
  1735
	MakeWater(0);
cbf73f3c1de3 (svn r12642) -Fix: remove buggy buoys at tile 0 from old TTDP savegames
smatz
parents: 8839
diff changeset
  1736
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6108
diff changeset
  1737
	_pause_game = 2;
1340
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1738
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1742
void GetOldSaveGameName(char *title, const char *path, const char *file)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
{
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1744
	char filename[MAX_PATH];
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1745
	FILE *f;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1746
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1747
	snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, file);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1748
	f = fopen(filename, "rb");
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1749
	title[0] = '\0';
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4000
diff changeset
  1750
	title[48] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1752
	if (f == NULL) return;
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1753
3626
5569d866ea85 (svn r4525) - Codechange: Do a little cleanup; also fix a typo while here: _old_vehicle_multipler should be _old_vehicle_multiplier
Darkvater
parents: 3580
diff changeset
  1754
	if (fread(title, 1, 48, f) != 48) snprintf(title, 48, "Corrupt file");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1755
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
}