src/oldloader.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9335 18d3658adc60
child 10111 703ab46c030e
permissions -rw-r--r--
update tags
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
     3
/** @file oldloader.cpp */
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1537
diff changeset
     6
#include "openttd.h"
3558
36ca79c931f2 (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"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8725
diff changeset
    10
#include "player_func.h"
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8725
diff changeset
    11
#include "player_base.h"
7048
06b931095b26 (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: 6987
diff changeset
    12
#include "aircraft.h"
06b931095b26 (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: 6987
diff changeset
    13
#include "roadveh.h"
06b931095b26 (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: 6987
diff changeset
    14
#include "ship.h"
06b931095b26 (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: 6987
diff changeset
    15
#include "train.h"
9286
d446bf9f4a68 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 9282
diff changeset
    16
#include "signs_base.h"
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    17
#include "debug.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1284
diff changeset
    18
#include "depot.h"
7394
75d35728b8b1 (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 7315
diff changeset
    19
#include "newgrf_config.h"
2814
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
    20
#include "ai/ai.h"
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
    21
#include "ai/default/default.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    22
#include "zoom_func.h"
8627
448ebf3a8291 (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: 8619
diff changeset
    23
#include "functions.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8635
diff changeset
    24
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    25
#include "vehicle_func.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8640
diff changeset
    26
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8756
diff changeset
    28
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8756
diff changeset
    29
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    30
enum {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    31
	HEADER_SIZE = 49,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    32
	BUFFER_SIZE = 4096,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    34
	OLD_MAP_SIZE = 256 * 256
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    35
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    37
struct LoadgameState {
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    38
	FILE *file;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    40
	uint chunk_size;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    42
	bool decoding;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    43
	byte decode_char;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    45
	uint buffer_count;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    46
	uint buffer_cur;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    47
	byte buffer[BUFFER_SIZE];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    49
	uint total_read;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    50
	bool failed;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    51
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    53
/* OldChunk-Type */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    54
enum OldChunkType {
3627
14c1566323fd (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
    55
	OC_SIMPLE    = 0,
14c1566323fd (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
    56
	OC_NULL      = 1,
14c1566323fd (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
    57
	OC_CHUNK     = 2,
14c1566323fd (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_ASSERT    = 3,
14c1566323fd (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
	/* 8 bytes allocated (256 max) */
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    60
3627
14c1566323fd (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_VAR_I8    = 1 << 8,
14c1566323fd (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
    62
	OC_VAR_U8    = 2 << 8,
14c1566323fd (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
    63
	OC_VAR_I16   = 3 << 8,
14c1566323fd (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_U16   = 4 << 8,
14c1566323fd (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_I32   = 5 << 8,
14c1566323fd (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_U32   = 6 << 8,
14c1566323fd (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_I64   = 7 << 8,
14c1566323fd (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
	/* 8 bytes allocated (256 max) */
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    69
3627
14c1566323fd (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_FILE_I8   = 1 << 16,
14c1566323fd (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
    71
	OC_FILE_U8   = 2 << 16,
14c1566323fd (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
    72
	OC_FILE_I16  = 3 << 16,
14c1566323fd (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_U16  = 4 << 16,
14c1566323fd (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_I32  = 5 << 16,
14c1566323fd (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_U32  = 6 << 16,
14c1566323fd (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
	/* 8 bytes allocated (256 max) */
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    77
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    78
	OC_INT8      = OC_VAR_I8   | OC_FILE_I8,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    79
	OC_UINT8     = OC_VAR_U8   | OC_FILE_U8,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    80
	OC_INT16     = OC_VAR_I16  | OC_FILE_I16,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    81
	OC_UINT16    = OC_VAR_U16  | OC_FILE_U16,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    82
	OC_INT32     = OC_VAR_I32  | OC_FILE_I32,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    83
	OC_UINT32    = OC_VAR_U32  | OC_FILE_U32,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    84
3627
14c1566323fd (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
    85
	OC_TILE      = OC_VAR_U32  | OC_FILE_U16,
14c1566323fd (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
    86
14c1566323fd (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
    87
	OC_END       = 0 ///< End of the whole chunk, all 32bits set to zero
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    88
};
3627
14c1566323fd (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
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    90
DECLARE_ENUM_AS_BIT_SET(OldChunkType);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    91
3627
14c1566323fd (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
    92
typedef bool OldChunkProc(LoadgameState *ls, int num);
14c1566323fd (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
    93
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    94
struct OldChunks {
3627
14c1566323fd (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
    95
	OldChunkType type;   ///< Type of field
14c1566323fd (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
    96
	uint32 amount;       ///< Amount of fields
14c1566323fd (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
    97
14c1566323fd (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
	void *ptr;           ///< Pointer where to save the data (may only be set if offset is 0)
14c1566323fd (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
    99
	uint offset;         ///< Offset from basepointer (may only be set if ptr is NULL)
14c1566323fd (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
   100
	OldChunkProc *proc;  ///< Pointer to function that is called with OC_CHUNK
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   101
};
3627
14c1566323fd (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
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   103
/* If it fails, check lines above.. */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   104
assert_compile(sizeof(TileIndex) == 4);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   105
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   106
static uint32 _bump_assert_value;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   107
static bool   _read_ttdpatch_flags;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   108
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   109
static OldChunkType GetOldChunkType(OldChunkType type)     {return (OldChunkType)GB(type, 0, 8);}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   110
static OldChunkType GetOldChunkVarType(OldChunkType type)  {return (OldChunkType)(GB(type, 8, 8) << 8);}
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   111
static OldChunkType GetOldChunkFileType(OldChunkType type) {return (OldChunkType)(GB(type, 16, 8) << 16);}
3627
14c1566323fd (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
   112
14c1566323fd (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
   113
static inline byte CalcOldVarLen(OldChunkType type)
14c1566323fd (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
   114
{
14c1566323fd (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
   115
	static const byte type_mem_size[] = {0, 1, 1, 2, 2, 4, 4, 8};
14c1566323fd (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
   116
	byte length = GB(type, 8, 8);
14c1566323fd (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
   117
	assert(length != 0 && length < lengthof(type_mem_size));
14c1566323fd (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
   118
	return type_mem_size[length];
14c1566323fd (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
   119
}
14c1566323fd (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
   120
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   121
/**
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   122
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   123
 * Reads a byte from a file (do not call yourself, use ReadByte())
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   124
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   125
 */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   126
static byte ReadByteFromFile(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
{
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   128
	/* To avoid slow reads, we read BUFFER_SIZE of bytes per time
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   129
	and just return a byte per time */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   130
	if (ls->buffer_cur >= ls->buffer_count) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   131
		/* Read some new bytes from the file */
4321
b763b7007162 (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 4286
diff changeset
   132
		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
   133
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   134
		/* We tried to read, but there is nothing in the file anymore.. */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   135
		if (count == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
   136
			DEBUG(oldloader, 0, "Read past end of file, loading failed");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   137
			ls->failed = true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   138
		}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   139
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   140
		ls->buffer_count = count;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   141
		ls->buffer_cur   = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   144
	return ls->buffer[ls->buffer_cur++];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   147
/**
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   148
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   149
 * Reads a byte from the buffer and decompress if needed
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   150
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   151
 */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   152
static byte ReadByte(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
{
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   154
	/* Old savegames have a nice compression algorithm (RLE)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   155
	which means that we have a chunk, which starts with a length
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   156
	byte. If that byte is negative, we have to repeat the next byte
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6677
diff changeset
   157
	that many times ( + 1). Else, we need to read that amount of bytes.
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   158
	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
   159
2453
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   160
	if (ls->chunk_size == 0) {
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   161
		/* Read new chunk */
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   162
		int8 new_byte = ReadByteFromFile(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   163
2453
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   164
		if (new_byte < 0) {
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   165
			/* Repeat next char for new_byte times */
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   166
			ls->decoding    = true;
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   167
			ls->decode_char = ReadByteFromFile(ls);
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   168
			ls->chunk_size  = -new_byte + 1;
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   169
		} else {
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   170
			ls->decoding    = false;
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   171
			ls->chunk_size  = new_byte + 1;
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   172
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   174
2453
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   175
	ls->total_read++;
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   176
	ls->chunk_size--;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   177
2453
f2f861c22557 (svn r2979) Avoid unnecessary recursion
tron
parents: 2452
diff changeset
   178
	return ls->decoding ? ls->decode_char : ReadByteFromFile(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   179
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   180
3627
14c1566323fd (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
   181
static inline uint16 ReadUint16(LoadgameState *ls)
14c1566323fd (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
   182
{
14c1566323fd (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
   183
	byte x = ReadByte(ls);
14c1566323fd (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
   184
	return x | ReadByte(ls) << 8;
14c1566323fd (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
   185
}
14c1566323fd (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
   186
14c1566323fd (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
   187
static inline uint32 ReadUint32(LoadgameState *ls)
14c1566323fd (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
   188
{
14c1566323fd (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
   189
	uint16 x = ReadUint16(ls);
14c1566323fd (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
   190
	return x | ReadUint16(ls) << 16;
14c1566323fd (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
   191
}
14c1566323fd (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
   192
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   193
/**
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   194
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   195
 * Loads a chunk from the old savegame
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   196
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   197
 */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   198
static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   199
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   200
	const OldChunks *chunk = chunks;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   201
	byte *base_ptr = (byte*)base;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   202
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   203
	while (chunk->type != OC_END) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   204
		byte* ptr = (byte*)chunk->ptr;
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3875
diff changeset
   205
		uint i;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   206
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   207
		for (i = 0; i < chunk->amount; i++) {
3626
151f99d38c69 (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
   208
			if (ls->failed) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   209
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   210
			/* Handle simple types */
3627
14c1566323fd (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
   211
			if (GetOldChunkType(chunk->type) != 0) {
14c1566323fd (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
   212
				switch (GetOldChunkType(chunk->type)) {
3626
151f99d38c69 (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
   213
					/* Just read the byte and forget about it */
151f99d38c69 (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
   214
					case OC_NULL: ReadByte(ls); break;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   215
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   216
					case OC_CHUNK:
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   217
						/* Call function, with 'i' as parameter to tell which item we
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   218
						 * are going to read */
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   219
						if (!chunk->proc(ls, i)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   220
						break;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   221
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   222
					case OC_ASSERT:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
   223
						DEBUG(oldloader, 4, "Assert point: 0x%X / 0x%X", ls->total_read, chunk->offset + _bump_assert_value);
3626
151f99d38c69 (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
   224
						if (ls->total_read != chunk->offset + _bump_assert_value) ls->failed = true;
3629
04bdfc82b48b (svn r4528) - Fix: fix idiotic gcc warning
Darkvater
parents: 3627
diff changeset
   225
					default: break;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   226
				}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   227
			} else {
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
   228
				uint64 res = 0;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   229
3627
14c1566323fd (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
   230
				/* Reading from the file: bits 16 to 23 have the FILE type */
14c1566323fd (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
   231
				switch (GetOldChunkFileType(chunk->type)) {
14c1566323fd (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
   232
					case OC_FILE_I8:  res = (int8)ReadByte(ls); break;
14c1566323fd (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
   233
					case OC_FILE_U8:  res = ReadByte(ls); break;
14c1566323fd (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
   234
					case OC_FILE_I16: res = (int16)ReadUint16(ls); break;
14c1566323fd (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
   235
					case OC_FILE_U16: res = ReadUint16(ls); break;
14c1566323fd (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
   236
					case OC_FILE_I32: res = (int32)ReadUint32(ls); break;
14c1566323fd (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
   237
					case OC_FILE_U32: res = ReadUint32(ls); break;
14c1566323fd (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
   238
					default: NOT_REACHED();
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   239
				}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   240
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   241
				/* Sanity check */
1325
80f83e8ae77b (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   242
				assert(base_ptr != NULL || chunk->ptr != NULL);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   243
3627
14c1566323fd (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
				/* Writing to the var: bits 8 to 15 have the VAR type */
14c1566323fd (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
				if (chunk->ptr == NULL) ptr = base_ptr + chunk->offset;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   246
3627
14c1566323fd (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
				/* Write the data */
14c1566323fd (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
				switch (GetOldChunkVarType(chunk->type)) {
14c1566323fd (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_VAR_I8: *(int8  *)ptr = GB(res, 0, 8); break;
14c1566323fd (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
					case OC_VAR_U8: *(uint8 *)ptr = GB(res, 0, 8); break;
14c1566323fd (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
   251
					case OC_VAR_I16:*(int16 *)ptr = GB(res, 0, 16); break;
14c1566323fd (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
   252
					case OC_VAR_U16:*(uint16*)ptr = GB(res, 0, 16); break;
14c1566323fd (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
   253
					case OC_VAR_I32:*(int32 *)ptr = res; break;
14c1566323fd (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
   254
					case OC_VAR_U32:*(uint32*)ptr = res; break;
14c1566323fd (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
   255
					case OC_VAR_I64:*(int64 *)ptr = res; break;
14c1566323fd (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
					default: NOT_REACHED();
14c1566323fd (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
				}
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   258
3627
14c1566323fd (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
				/* Increase pointer base for arrays when looping */
14c1566323fd (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
				if (chunk->amount > 1 && chunk->ptr != NULL) ptr += CalcOldVarLen(chunk->type);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   261
			}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   262
		}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   263
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   264
		chunk++;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   265
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   266
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   267
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   268
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   269
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   270
/**
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   271
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   272
 * Initialize some data before reading
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   273
 *
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   274
 */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   275
static void InitLoading(LoadgameState *ls)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   276
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   277
	ls->chunk_size   = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   278
	ls->total_read   = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   279
	ls->failed       = false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   280
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   281
	ls->decoding     = false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   282
	ls->decode_char  = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   283
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   284
	ls->buffer_cur   = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   285
	ls->buffer_count = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   286
	memset(ls->buffer, 0, BUFFER_SIZE);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   287
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   288
	_bump_assert_value = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   289
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   290
	_read_ttdpatch_flags = false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   291
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   292
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   293
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   294
/*
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   295
 * Begin -- Stuff to fix the savegames to be OpenTTD compatible
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   296
 */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   297
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   298
extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   299
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   300
static void FixOldTowns()
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   301
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   302
	Town *town;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   303
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   304
	/* Convert town-names if needed */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   305
	FOR_ALL_TOWNS(town) {
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8425
diff changeset
   306
		if (IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   307
			town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _opt.town_name;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   308
			town->townnameparts = GetOldTownName(town->townnameparts, _opt.town_name);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   309
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   310
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   313
static void FixOldStations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
{
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   315
	Station *st;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 875
diff changeset
   316
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   317
	FOR_ALL_STATIONS(st) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   318
		/* Check if we need to swap width and height for the station */
3558
36ca79c931f2 (svn r4432) Make use of map access functions
tron
parents: 3431
diff changeset
   319
		if (st->train_tile != 0 && GetRailStationAxis(st->train_tile) != AXIS_X) {
5984
fbef81292ff9 (svn r8276) -Fix
tron
parents: 5967
diff changeset
   320
			Swap(st->trainst_w, st->trainst_h);
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
   321
		}
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   322
	}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   323
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   324
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   325
static void FixOldVehicles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
{
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   327
	/* Check for shared orders, and link them correctly */
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   328
	Vehicle* v;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   329
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   330
	FOR_ALL_VEHICLES(v) {
3626
151f99d38c69 (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
   331
		Vehicle *u;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   332
7127
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
   333
		/* We haven't used this bit for stations for ages */
7396
9376076d058e (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 7394
diff changeset
   334
		if (v->type == VEH_ROAD &&
9376076d058e (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 7394
diff changeset
   335
				v->u.road.state != RVSB_IN_DEPOT &&
9376076d058e (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 7394
diff changeset
   336
				v->u.road.state != RVSB_WORMHOLE) {
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   337
			ClrBit(v->u.road.state, RVS_IS_STOPPING);
7396
9376076d058e (svn r10147) -Fix: the oldloader did clear some bits for road vehicles that shouldn't be cleared in some cases.
rubidium
parents: 7394
diff changeset
   338
		}
7127
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
   339
9220
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   340
		/* The subtype should be 0, but it sometimes isn't :( */
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   341
		if (v->type == VEH_ROAD) v->subtype = 0;
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   342
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   343
		/* Sometimes primary vehicles would have a nothing (invalid) order
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   344
		 * or vehicles that could not have an order would still have a
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   345
		 * (loading) order which causes assertions and the like later on.
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   346
		 */
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   347
		if (!IsPlayerBuildableVehicleType(v) ||
9332
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9331
diff changeset
   348
				(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
2e120d0bd632 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 9331
diff changeset
   349
			v->current_order.MakeDummy();
9220
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   350
		}
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
   351
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   352
		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   353
			/* If a vehicle has the same orders, add the link to eachother
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   354
			 * in both vehicles */
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   355
			if (v->orders == u->orders) {
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   356
				v->next_shared = u;
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   357
				u->prev_shared = v;
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   358
				break;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   359
			}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   360
		}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   361
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   364
/*
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   365
 * End -- Stuff to fix the savegames to be OpenTTD compatible
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   366
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   368
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   369
/* Help:
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   370
 *  - OCL_SVAR: load 'type' to offset 'offset' in a struct of type 'base', which must also
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   371
 *       be given via base in LoadChunk() as real pointer
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   372
 *  - OCL_VAR: load 'type' to a global var
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   373
 *  - OCL_END: every struct must end with this
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   374
 *  - OCL_NULL: read 'amount' of bytes and send them to /dev/null or something
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   375
 *  - OCL_CHUNK: load an other proc to load a part of the savegame, 'amount' times
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   376
 *  - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   377
 */
5922
510e1bbc5992 (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: 5865
diff changeset
   378
#define OCL_SVAR(type, base, offset)         { type,          1, NULL,    (uint)cpp_offsetof(base, offset), NULL }
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   379
#define OCL_VAR(type, amount, pointer)       { type,     amount, pointer, 0,                      NULL }
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   380
#define OCL_END()                                   { OC_END,        0, NULL,    0,                      NULL }
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   381
#define OCL_NULL(amount)                            { OC_NULL,  amount, NULL,    0,                      NULL }
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   382
#define OCL_CHUNK(amount, proc)                     { OC_CHUNK, amount, NULL,    0,                      proc }
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   383
#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
   384
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   385
/* The savegames has some hard-coded pointers, because it always enters the same
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   386
    piece of memory.. we don't.. so we need to remap ;)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   387
   Old Towns are 94 bytes big
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   388
   Old Orders are 2 bytes big */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   389
#define REMAP_TOWN_IDX(x) ((x) - (0x0459154 - 0x0458EF0)) / 94
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   390
#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
   391
8190
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8033
diff changeset
   392
extern TileIndex *_animated_tile_list;
efd1f3b110a2 (svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
rubidium
parents: 8033
diff changeset
   393
extern uint _animated_tile_count;
1328
e069d2db0e4c (svn r1832) Next byte -> char iteration: custom names
tron
parents: 1326
diff changeset
   394
extern char _name_array[512][32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
3626
151f99d38c69 (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
   396
static byte   _old_vehicle_multiplier;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   397
static uint8  _old_map3[OLD_MAP_SIZE * 2];
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   398
static bool   _new_ttdpatch_format;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   399
static uint32 _old_town_index;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   400
static uint16 _old_string_id;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   401
static uint16 _old_string_id_2;
6400
7b98825c5cb0 (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: 6343
diff changeset
   402
static uint16 _old_extra_chunk_nums;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   403
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   404
static void ReadTTDPatchFlags()
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   405
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   406
	int i;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   407
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   408
	if (_read_ttdpatch_flags) return;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   409
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   410
	_read_ttdpatch_flags = true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   411
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   412
	/* TTDPatch misuses _old_map3 for flags.. read them! */
3626
151f99d38c69 (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
   413
	_old_vehicle_multiplier = _old_map3[0];
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   414
	/* Somehow.... there was an error in some savegames, so 0 becomes 1
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   415
	and 1 becomes 2. The rest of the values are okay */
3626
151f99d38c69 (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
   416
	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   417
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
   418
	/* TTDPatch increases the Vehicle-part in the middle of the game,
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   419
	so if the multipler is anything else but 1, the assert fails..
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   420
	bump the assert value so it doesn't!
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   421
	(1 multipler == 850 vehicles
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   422
	1 vehicle   == 128 bytes */
3626
151f99d38c69 (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
   423
	_bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   424
1326
f37b6aa28829 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
   425
	/* Check if we have a modern TTDPatch savegame (has extra data all around) */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
   426
	_new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   427
6400
7b98825c5cb0 (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: 6343
diff changeset
   428
	_old_extra_chunk_nums = _old_map3[_new_ttdpatch_format ? 0x1FFFE : 0x2];
7b98825c5cb0 (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: 6343
diff changeset
   429
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   430
	/* Clean the misused places */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
   431
	for (i = 0;       i < 17;      i++) _old_map3[i] = 0;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
   432
	for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   433
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
   434
	if (_new_ttdpatch_format) DEBUG(oldloader, 2, "Found TTDPatch game");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   435
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
   436
	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
   437
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   439
static const OldChunks town_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   440
	OCL_SVAR(   OC_TILE, Town, xy ),
9203
55b0289562a8 (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: 9061
diff changeset
   441
	OCL_NULL( 2 ),         ///< population,        no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   442
	OCL_SVAR( OC_UINT16, Town, townnametype ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   443
	OCL_SVAR( OC_UINT32, Town, townnameparts ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   444
	OCL_SVAR(  OC_UINT8, Town, grow_counter ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   445
	OCL_NULL( 1 ),         ///< sort_index,        no longer in use
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   446
	OCL_NULL( 4 ),         ///< sign-coordinates,  no longer in use
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   447
	OCL_NULL( 2 ),         ///< namewidth,         no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   448
	OCL_SVAR( OC_UINT16, Town, flags12 ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   449
	OCL_NULL( 10 ),        ///< radius,            no longer in use
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 974
diff changeset
   450
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   451
	OCL_SVAR( OC_UINT16, Town, ratings[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   452
	OCL_SVAR( OC_UINT16, Town, ratings[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   453
	OCL_SVAR( OC_UINT16, Town, ratings[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   454
	OCL_SVAR( OC_UINT16, Town, ratings[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   455
	OCL_SVAR( OC_UINT16, Town, ratings[4] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   456
	OCL_SVAR( OC_UINT16, Town, ratings[5] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   457
	OCL_SVAR( OC_UINT16, Town, ratings[6] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   458
	OCL_SVAR( OC_UINT16, Town, ratings[7] ),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   460
	/* XXX - This is pretty odd.. we read 32bit, but only write 8bit.. sure there is
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6677
diff changeset
   461
	nothing changed ? ? */
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   462
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, have_ratings ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   463
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, statues ),
9203
55b0289562a8 (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: 9061
diff changeset
   464
	OCL_NULL( 2 ),         ///< num_houses,        no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   465
	OCL_SVAR(  OC_UINT8, Town, time_until_rebuild ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   466
	OCL_SVAR(  OC_UINT8, Town, growth_rate ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   467
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   468
	OCL_SVAR( OC_UINT16, Town, new_max_pass ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   469
	OCL_SVAR( OC_UINT16, Town, new_max_mail ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   470
	OCL_SVAR( OC_UINT16, Town, new_act_pass ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   471
	OCL_SVAR( OC_UINT16, Town, new_act_mail ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   472
	OCL_SVAR( OC_UINT16, Town, max_pass ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   473
	OCL_SVAR( OC_UINT16, Town, max_mail ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   474
	OCL_SVAR( OC_UINT16, Town, act_pass ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   475
	OCL_SVAR( OC_UINT16, Town, act_mail ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   476
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   477
	OCL_SVAR(  OC_UINT8, Town, pct_pass_transported ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   478
	OCL_SVAR(  OC_UINT8, Town, pct_mail_transported ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   479
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   480
	OCL_SVAR( OC_UINT16, Town, new_act_food ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   481
	OCL_SVAR( OC_UINT16, Town, new_act_water ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   482
	OCL_SVAR( OC_UINT16, Town, act_food ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   483
	OCL_SVAR( OC_UINT16, Town, act_water ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   484
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   485
	OCL_SVAR(  OC_UINT8, Town, road_build_months ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   486
	OCL_SVAR(  OC_UINT8, Town, fund_buildings_months ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   487
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   488
	OCL_NULL( 8 ),         ///< some junk at the end of the record
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   489
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   490
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   491
};
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   492
static bool LoadOldTown(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   493
{
7895
62a61dc1930a (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7886
diff changeset
   494
	return LoadChunk(ls, new (num) Town(), town_chunk);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   497
static uint16 _old_order;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   498
static const OldChunks order_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   499
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   500
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   501
};
3626
151f99d38c69 (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
   502
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   503
static bool LoadOldOrder(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
{
3626
151f99d38c69 (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
   505
	if (!LoadChunk(ls, NULL, order_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   506
9335
18d3658adc60 (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 9332
diff changeset
   507
	new (num) Order(UnpackOldOrder(_old_order));
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   508
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   509
	/* Relink the orders to eachother (in TTD(Patch) the orders for one
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6585
diff changeset
   510
	vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   511
	it is the last order */
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6585
diff changeset
   512
	if (num > 0 && GetOrder(num)->IsValid())
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   513
		GetOrder(num - 1)->next = GetOrder(num);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   514
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   515
	return true;
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
8207
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   518
static bool LoadOldAnimTileList(LoadgameState *ls, int num)
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   519
{
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   520
	/* This is sligthly hackish - we must load a chunk into an array whose
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   521
	 * address isn't static, but instead pointed to by _animated_tile_list.
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   522
	 * To achieve that, create an OldChunks list on the stack on the fly.
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   523
	 * The list cannot be static because the value of _animated_tile_list
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   524
	 * can change between calls. */
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   525
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   526
	const OldChunks anim_chunk[] = {
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   527
		OCL_VAR (   OC_TILE, 256, _animated_tile_list ),
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   528
		OCL_END ()
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   529
	};
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   530
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   531
	if (!LoadChunk(ls, NULL, anim_chunk)) return false;
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   532
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   533
	/* Update the animated tile counter by counting till the first zero in the array */
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   534
	for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   535
		if (_animated_tile_list[_animated_tile_count] == 0) break;
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   536
	}
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   537
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   538
	return true;
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   539
}
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
   540
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   541
static const OldChunks depot_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   542
	OCL_SVAR(   OC_TILE, Depot, xy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   543
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   544
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   545
};
3626
151f99d38c69 (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
   546
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   547
static bool LoadOldDepot(LoadgameState *ls, int num)
436
6d8fb39a154f (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
   548
{
7895
62a61dc1930a (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7886
diff changeset
   549
	if (!LoadChunk(ls, new (num) Depot(), depot_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   550
7885
4eb9b01e37ff (svn r10758) -Codechange: make the depot struct use the pool item class as super class.
rubidium
parents: 7830
diff changeset
   551
	if (IsValidDepotID(num)) {
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   552
		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
436
6d8fb39a154f (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
   553
	}
6d8fb39a154f (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
   554
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   555
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   556
}
436
6d8fb39a154f (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
   557
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   558
static int32 _old_price;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   559
static uint16 _old_price_frac;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   560
static const OldChunks price_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   561
	OCL_VAR (  OC_INT32,   1, &_old_price ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   562
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   563
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   564
};
3626
151f99d38c69 (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
   565
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   566
static bool LoadOldPrice(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   567
{
3626
151f99d38c69 (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
   568
	if (!LoadChunk(ls, NULL, price_chunk)) return false;
436
6d8fb39a154f (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
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   570
	/* We use a struct to store the prices, but they are ints in a row..
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   571
	so just access the struct as an array of int32's */
7453
67ba4a6fc014 (svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents: 7448
diff changeset
   572
	((Money*)&_price)[num] = _old_price;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   573
	_price_frac[num] = _old_price_frac;
436
6d8fb39a154f (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
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   575
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   576
}
436
6d8fb39a154f (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
   577
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   578
static const OldChunks cargo_payment_rate_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   579
	OCL_VAR (  OC_INT32,   1, &_old_price ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   580
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   581
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   582
	OCL_NULL( 2 ),         ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   583
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   584
};
3626
151f99d38c69 (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
   585
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   586
static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   587
{
3626
151f99d38c69 (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
   588
	if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   589
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   590
	_cargo_payment_rates[num] = -_old_price;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   591
	_cargo_payment_rates_frac[num] = _old_price_frac;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   592
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   593
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   594
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   595
7506
e52d89f5c7c1 (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: 7453
diff changeset
   596
static uint8  _old_platforms;
e52d89f5c7c1 (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: 7453
diff changeset
   597
static uint   _current_station_id;
e52d89f5c7c1 (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: 7453
diff changeset
   598
static uint16 _waiting_acceptance;
e52d89f5c7c1 (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: 7453
diff changeset
   599
static uint8  _cargo_source;
e52d89f5c7c1 (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: 7453
diff changeset
   600
static uint8  _cargo_days;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   601
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   602
static const OldChunks goods_chunk[] = {
7506
e52d89f5c7c1 (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: 7453
diff changeset
   603
	OCL_VAR ( OC_UINT16, 1,          &_waiting_acceptance ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   604
	OCL_SVAR(  OC_UINT8, GoodsEntry, days_since_pickup ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   605
	OCL_SVAR(  OC_UINT8, GoodsEntry, rating ),
7506
e52d89f5c7c1 (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: 7453
diff changeset
   606
	OCL_VAR (  OC_UINT8, 1,          &_cargo_source ),
e52d89f5c7c1 (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: 7453
diff changeset
   607
	OCL_VAR (  OC_UINT8, 1,          &_cargo_days ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   608
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   609
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   610
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   611
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   612
};
3626
151f99d38c69 (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
   613
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   614
static bool LoadOldGood(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   615
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   616
	Station *st = GetStation(_current_station_id);
7506
e52d89f5c7c1 (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: 7453
diff changeset
   617
	GoodsEntry *ge = &st->goods[num];
e52d89f5c7c1 (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: 7453
diff changeset
   618
	bool ret = LoadChunk(ls, ge, goods_chunk);
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7895
diff changeset
   619
	if (!ret) return false;
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7895
diff changeset
   620
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   621
	SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7895
diff changeset
   622
	SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, _cargo_source != 0xFF);
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7895
diff changeset
   623
	if (GB(_waiting_acceptance, 0, 12) != 0) {
7506
e52d89f5c7c1 (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: 7453
diff changeset
   624
		CargoPacket *cp = new CargoPacket();
e52d89f5c7c1 (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: 7453
diff changeset
   625
		cp->source          = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
e52d89f5c7c1 (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: 7453
diff changeset
   626
		cp->count           = GB(_waiting_acceptance, 0, 12);
e52d89f5c7c1 (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: 7453
diff changeset
   627
		cp->days_in_transit = _cargo_days;
e52d89f5c7c1 (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: 7453
diff changeset
   628
		ge->cargo.Append(cp);
e52d89f5c7c1 (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: 7453
diff changeset
   629
	}
e52d89f5c7c1 (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: 7453
diff changeset
   630
	return ret;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   631
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   632
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   633
static const OldChunks station_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   634
	OCL_SVAR(   OC_TILE, Station, xy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   635
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   636
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   637
	OCL_NULL( 4 ), ///< bus/lorry tile
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   638
	OCL_SVAR(   OC_TILE, Station, train_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   639
	OCL_SVAR(   OC_TILE, Station, airport_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   640
	OCL_SVAR(   OC_TILE, Station, dock_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   641
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   642
	OCL_VAR (  OC_UINT8,   1, &_old_platforms ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   643
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   644
	OCL_NULL( 1 ),         ///< sort-index, no longer in use
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   645
	OCL_NULL( 2 ),         ///< sign-width, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   646
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   647
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   648
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   649
	OCL_NULL( 4 ),         ///< sign left/top, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   650
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   651
	OCL_SVAR( OC_UINT16, Station, had_vehicle_of_type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   652
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   653
	OCL_CHUNK( 12, LoadOldGood ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   654
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   655
	OCL_SVAR(  OC_UINT8, Station, time_since_load ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   656
	OCL_SVAR(  OC_UINT8, Station, time_since_unload ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   657
	OCL_SVAR(  OC_UINT8, Station, delete_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   658
	OCL_SVAR(  OC_UINT8, Station, owner ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   659
	OCL_SVAR(  OC_UINT8, Station, facilities ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   660
	OCL_SVAR(  OC_UINT8, Station, airport_type ),
6128
46154e074b58 (svn r8475) -Fix
tron
parents: 6074
diff changeset
   661
	/* Bus/truck status, no longer in use
46154e074b58 (svn r8475) -Fix
tron
parents: 6074
diff changeset
   662
	 * Blocked months
46154e074b58 (svn r8475) -Fix
tron
parents: 6074
diff changeset
   663
	 * Unknown
46154e074b58 (svn r8475) -Fix
tron
parents: 6074
diff changeset
   664
	 */
46154e074b58 (svn r8475) -Fix
tron
parents: 6074
diff changeset
   665
	OCL_NULL( 4 ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   666
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Station, airport_flags ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   667
	OCL_NULL( 2 ),         ///< last_vehicle. now last_vehicle_type
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   668
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   669
	OCL_NULL( 4 ),         ///< Junk at end of chunk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   670
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   671
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   672
};
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   673
static bool LoadOldStation(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   674
{
7127
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
   675
	Station *st = new (num) Station();
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   676
	_current_station_id = num;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   677
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   678
	if (!LoadChunk(ls, st, station_chunk))
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   679
		return false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   680
6322
3d191e6e89bc (svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents: 6222
diff changeset
   681
	if (st->IsValid()) {
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   682
		if (st->train_tile) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   683
			/* Calculate the trainst_w and trainst_h */
2140
d708eb80ab8b (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
   684
			uint w = GB(_old_platforms, 3, 3);
d708eb80ab8b (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
   685
			uint h = GB(_old_platforms, 0, 3);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   686
			st->trainst_w = w;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   687
			st->trainst_h = h;
436
6d8fb39a154f (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
   688
		}
6d8fb39a154f (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
   689
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   690
		st->town    = GetTown(REMAP_TOWN_IDX(_old_town_index));
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   691
		st->string_id = RemapOldStringID(_old_string_id);
436
6d8fb39a154f (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
   692
	}
6d8fb39a154f (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
   693
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   694
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   695
}
436
6d8fb39a154f (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
   696
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   697
static const OldChunks industry_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   698
	OCL_SVAR(   OC_TILE, Industry, xy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   699
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   700
	OCL_SVAR(  OC_UINT8, Industry, width ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   701
	OCL_SVAR(  OC_UINT8, Industry, height ),
7132
08abbae3073e (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: 7127
diff changeset
   702
	OCL_NULL( 2 ),  ///< used to be industry's produced_cargo
436
6d8fb39a154f (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
   703
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7506
diff changeset
   704
	OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[0] ),
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7506
diff changeset
   705
	OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[1] ),
436
6d8fb39a154f (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
   706
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   707
	OCL_SVAR(  OC_UINT8, Industry, production_rate[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   708
	OCL_SVAR(  OC_UINT8, Industry, production_rate[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   709
7132
08abbae3073e (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: 7127
diff changeset
   710
	OCL_NULL( 3 ),  ///< used to be industry's accepts_cargo
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   711
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   712
	OCL_SVAR(  OC_UINT8, Industry, prod_level ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   713
7315
f1b2591ad082 (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: 7132
diff changeset
   714
	OCL_SVAR( OC_UINT16, Industry, this_month_production[0] ),
f1b2591ad082 (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: 7132
diff changeset
   715
	OCL_SVAR( OC_UINT16, Industry, this_month_production[1] ),
f1b2591ad082 (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: 7132
diff changeset
   716
	OCL_SVAR( OC_UINT16, Industry, this_month_transported[0] ),
f1b2591ad082 (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: 7132
diff changeset
   717
	OCL_SVAR( OC_UINT16, Industry, this_month_transported[1] ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   718
7315
f1b2591ad082 (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: 7132
diff changeset
   719
	OCL_SVAR(  OC_UINT8, Industry, last_month_pct_transported[0] ),
f1b2591ad082 (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: 7132
diff changeset
   720
	OCL_SVAR(  OC_UINT8, Industry, last_month_pct_transported[1] ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   721
7315
f1b2591ad082 (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: 7132
diff changeset
   722
	OCL_SVAR( OC_UINT16, Industry, last_month_production[0] ),
f1b2591ad082 (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: 7132
diff changeset
   723
	OCL_SVAR( OC_UINT16, Industry, last_month_production[1] ),
f1b2591ad082 (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: 7132
diff changeset
   724
	OCL_SVAR( OC_UINT16, Industry, last_month_transported[0] ),
f1b2591ad082 (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: 7132
diff changeset
   725
	OCL_SVAR( OC_UINT16, Industry, last_month_transported[1] ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   726
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   727
	OCL_SVAR(  OC_UINT8, Industry, type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   728
	OCL_SVAR(  OC_UINT8, Industry, owner ),
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4845
diff changeset
   729
	OCL_SVAR(  OC_UINT8, Industry, random_color ),
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
   730
	OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Industry, last_prod_year ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   731
	OCL_SVAR( OC_UINT16, Industry, counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   732
	OCL_SVAR(  OC_UINT8, Industry, was_cargo_delivered ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   733
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   734
	OCL_NULL( 9 ), ///< Random junk at the end of this chunk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   735
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   736
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   737
};
3626
151f99d38c69 (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
   738
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   739
static bool LoadOldIndustry(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   740
{
7895
62a61dc1930a (svn r10771) -Codechange: remove some code duplication from the old loader.
rubidium
parents: 7886
diff changeset
   741
	Industry *i = new (num) Industry();
3626
151f99d38c69 (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
   742
	if (!LoadChunk(ls, i, industry_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   743
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7885
diff changeset
   744
	if (i->IsValid()) {
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   745
		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
8216
12d1cff88d38 (svn r11255) -Fix [FS#1332]: industry counter was not updated on TTD savegame loading
glx
parents: 8207
diff changeset
   746
		IncIndustryTypeCount(i->type);
436
6d8fb39a154f (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
   747
	}
6d8fb39a154f (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
   748
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   749
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   750
}
436
6d8fb39a154f (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
   751
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2453
diff changeset
   752
static PlayerID _current_player_id;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   753
static int32 _old_yearly;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   754
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   755
static const OldChunks player_yearly_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   756
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   757
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   758
};
3626
151f99d38c69 (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
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   760
static bool OldPlayerYearly(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   761
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   762
	int i;
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   763
	Player *p = GetPlayer(_current_player_id);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   764
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   765
	for (i = 0; i < 13; i++) {
3626
151f99d38c69 (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
   766
		if (!LoadChunk(ls, NULL, player_yearly_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   767
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   768
		p->yearly_expenses[num][i] = _old_yearly;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   769
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   770
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   771
	return true;
436
6d8fb39a154f (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
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   774
static const OldChunks player_economy_chunk[] = {
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
   775
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, income ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
   776
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, expenses ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   777
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, delivered_cargo ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   778
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   779
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   780
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   781
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   782
};
3626
151f99d38c69 (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
   783
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   784
static bool OldPlayerEconomy(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
{
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   786
	int i;
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   787
	Player *p = GetPlayer(_current_player_id);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   788
3626
151f99d38c69 (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
   789
	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   790
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   791
	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   792
	p->cur_economy.income   = -p->cur_economy.income;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   793
	p->cur_economy.expenses = -p->cur_economy.expenses;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   794
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   795
	for (i = 0; i < 24; i++) {
3626
151f99d38c69 (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
   796
		if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   797
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   798
		p->old_economy[i].income   = -p->old_economy[i].income;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   799
		p->old_economy[i].expenses = -p->old_economy[i].expenses;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   800
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   801
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   802
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   803
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   804
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   805
static const OldChunks player_ai_build_rec_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   806
	OCL_SVAR(   OC_TILE, AiBuildRec, spec_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   807
	OCL_SVAR(   OC_TILE, AiBuildRec, use_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   808
	OCL_SVAR(  OC_UINT8, AiBuildRec, rand_rng ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   809
	OCL_SVAR(  OC_UINT8, AiBuildRec, cur_building_rule ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   810
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk6 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   811
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk7 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   812
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_a ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   813
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_b ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   814
	OCL_SVAR(  OC_UINT8, AiBuildRec, direction ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   815
	OCL_SVAR(  OC_UINT8, AiBuildRec, cargo ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   816
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   817
	OCL_NULL( 8 ),  ///< Junk...
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   818
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   819
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   820
};
3626
151f99d38c69 (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
   821
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   822
static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   823
{
1962
51ee4f459268 (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   824
	Player *p = GetPlayer(_current_player_id);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   825
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   826
	switch (num) {
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   827
		case 0: return LoadChunk(ls, &_players_ai[p->index].src, player_ai_build_rec_chunk);
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   828
		case 1: return LoadChunk(ls, &_players_ai[p->index].dst, player_ai_build_rec_chunk);
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   829
		case 2: return LoadChunk(ls, &_players_ai[p->index].mid1, player_ai_build_rec_chunk);
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   830
		case 3: return LoadChunk(ls, &_players_ai[p->index].mid2, player_ai_build_rec_chunk);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   831
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   832
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   833
	return false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   834
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   835
static const OldChunks player_ai_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   836
	OCL_SVAR(  OC_UINT8, PlayerAI, state ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   837
	OCL_NULL( 1 ),         ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   838
	OCL_SVAR(  OC_UINT8, PlayerAI, state_mode ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   839
	OCL_SVAR( OC_UINT16, PlayerAI, state_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   840
	OCL_SVAR( OC_UINT16, PlayerAI, timeout_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   841
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   842
	OCL_CHUNK( 4, OldLoadAIBuildRec ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   843
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   844
	OCL_NULL( 20 ),        ///< More junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   845
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   846
	OCL_SVAR(  OC_UINT8, PlayerAI, cargo_type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   847
	OCL_SVAR(  OC_UINT8, PlayerAI, num_wagons ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   848
	OCL_SVAR(  OC_UINT8, PlayerAI, build_kind ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   849
	OCL_SVAR(  OC_UINT8, PlayerAI, num_build_rec ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   850
	OCL_SVAR(  OC_UINT8, PlayerAI, num_loco_to_build ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   851
	OCL_SVAR(  OC_UINT8, PlayerAI, num_want_fullload ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   852
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   853
	OCL_NULL( 14 ),        ///< Oh no more junk :|
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   854
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   855
	OCL_NULL( 2 ),         ///< Loco-id, not used
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   856
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   857
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   858
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   859
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   860
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   861
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[4] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   862
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[5] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   863
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[6] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   864
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[7] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   865
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[8] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   866
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   867
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   868
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   869
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   870
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[4] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   871
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[5] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   872
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[6] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   873
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[7] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   874
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[8] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   875
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[9] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   876
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[10] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   877
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[11] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   878
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[12] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   879
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[13] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   880
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[14] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   881
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[15] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   882
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[16] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   883
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[17] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   884
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[18] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   885
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[19] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   886
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   887
	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_a ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   888
	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_b ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   889
	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_a ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   890
	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_b ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   891
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   892
	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_a ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   893
	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_b ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   894
	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_a ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   895
	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_b ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   896
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   897
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_tile_count ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   898
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   899
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   900
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   901
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   902
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   903
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   904
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   905
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   906
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   907
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[4] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   908
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[4] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   909
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[5] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   910
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[5] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   911
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[6] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   912
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[6] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   913
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[7] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   914
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[7] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   915
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[8] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   916
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[8] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   917
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[9] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   918
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[9] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   919
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[10] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   920
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[10] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   921
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[11] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   922
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[11] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   923
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[12] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   924
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[12] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   925
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[13] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   926
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[13] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   927
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[14] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   928
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[14] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   929
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[15] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   930
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[15] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   931
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   932
	OCL_SVAR(  OC_UINT8, PlayerAI, railtype_to_use ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   933
	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   934
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   935
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   936
};
3626
151f99d38c69 (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
   937
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   938
static bool OldPlayerAI(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   939
{
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   940
	return LoadChunk(ls, &_players_ai[_current_player_id], player_ai_chunk);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   941
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   942
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   943
uint8 ai_tick;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   944
static const OldChunks player_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   945
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   946
	OCL_SVAR( OC_UINT32, Player, name_2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   947
	OCL_SVAR( OC_UINT32, Player, face ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   948
	OCL_VAR ( OC_UINT16,   1, &_old_string_id_2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   949
	OCL_SVAR( OC_UINT32, Player, president_name_2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   950
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   951
	OCL_SVAR(  OC_INT32, Player, player_money ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   952
	OCL_SVAR(  OC_INT32, Player, current_loan ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   953
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   954
	OCL_SVAR(  OC_UINT8, Player, player_color ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   955
	OCL_SVAR(  OC_UINT8, Player, player_money_fraction ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   956
	OCL_SVAR(  OC_UINT8, Player, quarters_of_bankrupcy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   957
	OCL_SVAR(  OC_UINT8, Player, bankrupt_asked ),
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
   958
	OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Player, bankrupt_value ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   959
	OCL_SVAR( OC_UINT16, Player, bankrupt_timeout ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   960
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   961
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U16, Player, cargo_types ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   962
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   963
	OCL_CHUNK( 3, OldPlayerYearly ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   964
	OCL_CHUNK( 1, OldPlayerEconomy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   965
5865
7410b9ee6435 (svn r8071) -Fix (r5999): [FS#536] Merging 32bit dates broke the inauguration date of companies in
Darkvater
parents: 5853
diff changeset
   966
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Player, inaugurated_year),
7410b9ee6435 (svn r8071) -Fix (r5999): [FS#536] Merging 32bit dates broke the inauguration date of companies in
Darkvater
parents: 5853
diff changeset
   967
	OCL_SVAR(                  OC_TILE, Player, last_build_coordinate ),
7410b9ee6435 (svn r8071) -Fix (r5999): [FS#536] Merging 32bit dates broke the inauguration date of companies in
Darkvater
parents: 5853
diff changeset
   968
	OCL_SVAR(                 OC_UINT8, Player, num_valid_stat_ent ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   969
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   970
	OCL_CHUNK( 1, OldPlayerAI ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   971
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   972
	OCL_SVAR(  OC_UINT8, Player, block_preview ),
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   973
	 OCL_VAR(  OC_UINT8,   1, &ai_tick ),
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   974
	OCL_SVAR(  OC_UINT8, Player, avail_railtypes ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   975
	OCL_SVAR(   OC_TILE, Player, location_of_house ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   976
	OCL_SVAR(  OC_UINT8, Player, share_owners[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   977
	OCL_SVAR(  OC_UINT8, Player, share_owners[1] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   978
	OCL_SVAR(  OC_UINT8, Player, share_owners[2] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   979
	OCL_SVAR(  OC_UINT8, Player, share_owners[3] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   980
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
   981
	OCL_NULL( 8 ), ///< junk at end of chunk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   982
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   983
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   984
};
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
   985
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   986
static bool LoadOldPlayer(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   987
{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   988
	Player *p = GetPlayer((PlayerID)num);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   989
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   990
	_current_player_id = (PlayerID)num;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   991
3626
151f99d38c69 (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
   992
	if (!LoadChunk(ls, p, player_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   993
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   994
	p->name_1 = RemapOldStringID(_old_string_id);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   995
	p->president_name_1 = RemapOldStringID(_old_string_id_2);
7448
424ab8df8adb (svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents: 7396
diff changeset
   996
	p->player_money = p->player_money;
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
   997
	_players_ai[_current_player_id].tick = ai_tick;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   998
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   999
	if (num == 0) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1000
		/* If the first player has no name, make sure we call it UNNAMED */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1001
		if (p->name_1 == 0)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1002
			p->name_1 = STR_SV_UNNAMED;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1003
	} else {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1004
		/* Beside some multiplayer maps (1 on 1), which we don't official support,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1005
		all other players are an AI.. mark them as such */
3345
40dc834caa24 (svn r4129) - CodeChange: Add proper bool type for is_ai as well...it is a bool type.
Darkvater
parents: 3342
diff changeset
  1006
		p->is_ai = true;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1007
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1008
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1009
	/* Sometimes it is better to not ask.. in old scenarios, the money
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1010
	was always 893288 pounds. In the newer versions this is correct,
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1011
	but correct for those oldies
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1012
	Ps: this also means that if you had exact 893288 pounds, you will go back
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1013
	to 10000.. this is a very VERY small chance ;) */
1326
f37b6aa28829 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1014
	if (p->player_money == 893288)
7448
424ab8df8adb (svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents: 7396
diff changeset
  1015
		p->player_money = p->current_loan = 100000;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1016
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1017
	_player_colors[num] = p->player_color;
5865
7410b9ee6435 (svn r8071) -Fix (r5999): [FS#536] Merging 32bit dates broke the inauguration date of companies in
Darkvater
parents: 5853
diff changeset
  1018
	p->inaugurated_year -= ORIGINAL_BASE_YEAR;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1019
	if (p->location_of_house == 0xFFFF)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1020
		p->location_of_house = 0;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1021
2019
86d632dbd4a3 (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
  1022
	/* State 20 for AI players is sell vehicle. Since the AI struct is not
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
  1023
	 * really figured out as of now, _players_ai[p->index].cur_veh; needed for 'sell vehicle'
2019
86d632dbd4a3 (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
  1024
	 * is NULL and the function will crash. To fix this, just change the state
86d632dbd4a3 (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
  1025
	 * to some harmless state, like 'loop vehicle'; 1 */
8725
b769d0a63f06 (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8717
diff changeset
  1026
	if (!IsHumanPlayer((PlayerID)num) && _players_ai[p->index].state == 20) _players_ai[p->index].state = 1;
2019
86d632dbd4a3 (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
  1027
2814
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
  1028
	if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
  1029
		AI_StartNewAI(p->index);
0f534d66544e (svn r3362) Fix issue with loading old (TTD) savegames:
peter1138
parents: 2752
diff changeset
  1030
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1031
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1032
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1033
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1034
static uint32 _old_order_ptr;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1035
static uint16 _old_next_ptr;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1036
static uint32 _current_vehicle_id;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1037
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1038
static const OldChunks vehicle_train_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1039
	OCL_SVAR(  OC_UINT8, VehicleRail, track ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1040
	OCL_SVAR(  OC_UINT8, VehicleRail, force_proceed ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1041
	OCL_SVAR( OC_UINT16, VehicleRail, crash_anim_pos ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1042
	OCL_SVAR(  OC_UINT8, VehicleRail, railtype ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1043
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1044
	OCL_NULL( 5 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1045
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1046
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1047
};
3626
151f99d38c69 (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
  1048
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1049
static const OldChunks vehicle_road_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1050
	OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1051
	OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
3009
c477ab0f00b3 (svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents: 2951
diff changeset
  1052
	OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1053
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1054
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1055
	OCL_SVAR( OC_UINT16, VehicleRoad, crashed_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1056
	OCL_SVAR(  OC_UINT8, VehicleRoad, reverse_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1057
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1058
	OCL_NULL( 1 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1059
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1060
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1061
};
3626
151f99d38c69 (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
  1062
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1063
static const OldChunks vehicle_ship_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1064
	OCL_SVAR(  OC_UINT8, VehicleShip, state ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1065
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1066
	OCL_NULL( 9 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1067
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1068
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1069
};
3626
151f99d38c69 (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
  1070
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1071
static const OldChunks vehicle_air_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1072
	OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1073
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1074
	OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1075
	OCL_SVAR(  OC_UINT8, VehicleAir, state ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1076
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1077
	OCL_NULL( 5 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1078
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1079
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1080
};
3626
151f99d38c69 (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
  1081
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1082
static const OldChunks vehicle_special_chunk[] = {
7830
210381b46ae6 (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7768
diff changeset
  1083
	OCL_SVAR( OC_UINT16, VehicleSpecial, animation_state ),
210381b46ae6 (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7768
diff changeset
  1084
	OCL_SVAR(  OC_UINT8, VehicleSpecial, animation_substate ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1085
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1086
	OCL_NULL( 7 ), // Junk
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1087
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1088
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1089
};
3626
151f99d38c69 (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
  1090
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1091
static const OldChunks vehicle_disaster_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1092
	OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
7830
210381b46ae6 (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7768
diff changeset
  1093
	OCL_SVAR( OC_UINT16, VehicleDisaster, big_ufo_destroyer_target ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1094
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1095
	OCL_NULL( 6 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1096
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1097
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1098
};
3626
151f99d38c69 (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
  1099
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1100
static const OldChunks vehicle_empty_chunk[] = {
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1101
	OCL_NULL( 10 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1102
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1103
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1104
};
3626
151f99d38c69 (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
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1106
static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1107
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1108
	Vehicle *v = GetVehicle(_current_vehicle_id);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1109
	uint temp = ls->total_read;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1110
	bool res;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1111
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1112
	switch (v->type) {
6340
35c260560a1b (svn r8737) -Regression (r8621): VEH_Type renumbering wasn't performed for TTD(P) games, failing to load them
Darkvater
parents: 6322
diff changeset
  1113
		default: NOT_REACHED();
9221
1168ec4e2ea4 (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: 9220
diff changeset
  1114
		case VEH_INVALID : res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
1168ec4e2ea4 (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: 9220
diff changeset
  1115
		case VEH_TRAIN   : res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
1168ec4e2ea4 (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: 9220
diff changeset
  1116
		case VEH_ROAD    : res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
1168ec4e2ea4 (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: 9220
diff changeset
  1117
		case VEH_SHIP    : res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
1168ec4e2ea4 (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: 9220
diff changeset
  1118
		case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
1168ec4e2ea4 (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: 9220
diff changeset
  1119
		case VEH_SPECIAL : res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
1168ec4e2ea4 (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: 9220
diff changeset
  1120
		case VEH_DISASTER: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1121
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1122
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1123
	/* This chunk size should always be 10 bytes */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1124
	if (ls->total_read - temp != 10) {
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
  1125
		DEBUG(oldloader, 0, "Assert failed in VehicleUnion: invalid chunk size");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1126
		return false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1127
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1128
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1129
	return res;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1130
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1131
7506
e52d89f5c7c1 (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: 7453
diff changeset
  1132
static uint16 _cargo_count;
e52d89f5c7c1 (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: 7453
diff changeset
  1133
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1134
static const OldChunks vehicle_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1135
	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1136
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1137
	OCL_NULL( 2 ),         ///< Hash, calculated automatically
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1138
	OCL_NULL( 2 ),         ///< Index, calculated automatically
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1139
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1140
	OCL_VAR ( OC_UINT32,   1, &_old_order_ptr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1141
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1142
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1143
	OCL_SVAR(  OC_UINT8, Vehicle, num_orders ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1144
	OCL_SVAR(  OC_UINT8, Vehicle, cur_order_index ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1145
	OCL_SVAR(   OC_TILE, Vehicle, dest_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1146
	OCL_SVAR( OC_UINT16, Vehicle, load_unload_time_rem ),
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1147
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, date_of_last_service ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1148
	OCL_SVAR( OC_UINT16, Vehicle, service_interval ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1149
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, last_station_visited ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1150
	OCL_SVAR(  OC_UINT8, Vehicle, tick_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1151
	OCL_SVAR( OC_UINT16, Vehicle, max_speed ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1152
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1153
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, x_pos ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1154
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, y_pos ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1155
	OCL_SVAR(  OC_UINT8, Vehicle, z_pos ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1156
	OCL_SVAR(  OC_UINT8, Vehicle, direction ),
7057
61e90db7d804 (svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents: 7048
diff changeset
  1157
	OCL_NULL( 2 ),         ///< x_offs and y_offs, calculated automatically
9289
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9286
diff changeset
  1158
	OCL_NULL( 2 ),         ///< x_extent and y_extent, calculated automatically
92f1249c304e (svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents: 9286
diff changeset
  1159
	OCL_NULL( 1 ),         ///< z_extent, calculated automatically
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1160
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1161
	OCL_SVAR(  OC_UINT8, Vehicle, owner ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1162
	OCL_SVAR(   OC_TILE, Vehicle, tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1163
	OCL_SVAR( OC_UINT16, Vehicle, cur_image ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1164
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1165
	OCL_NULL( 8 ),        ///< Vehicle sprite box, calculated automatically
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1166
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1167
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Vehicle, vehstatus ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1168
	OCL_SVAR( OC_UINT16, Vehicle, cur_speed ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1169
	OCL_SVAR(  OC_UINT8, Vehicle, subspeed ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1170
	OCL_SVAR(  OC_UINT8, Vehicle, acceleration ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1171
	OCL_SVAR(  OC_UINT8, Vehicle, progress ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1172
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1173
	OCL_SVAR(  OC_UINT8, Vehicle, cargo_type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1174
	OCL_SVAR( OC_UINT16, Vehicle, cargo_cap ),
7506
e52d89f5c7c1 (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: 7453
diff changeset
  1175
	OCL_VAR ( OC_UINT16, 1,       &_cargo_count ),
e52d89f5c7c1 (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: 7453
diff changeset
  1176
	OCL_VAR (  OC_UINT8, 1,       &_cargo_source ),
e52d89f5c7c1 (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: 7453
diff changeset
  1177
	OCL_VAR (  OC_UINT8, 1,       &_cargo_days ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1178
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1179
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, age ),
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1180
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Vehicle, max_age ),
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1181
	OCL_SVAR( OC_FILE_U8 | OC_VAR_I32, Vehicle, build_year ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1182
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, unitnumber ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1183
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1184
	OCL_SVAR( OC_UINT16, Vehicle, engine_type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1185
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1186
	OCL_SVAR(  OC_UINT8, Vehicle, spritenum ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1187
	OCL_SVAR(  OC_UINT8, Vehicle, day_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1188
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1189
	OCL_SVAR(  OC_UINT8, Vehicle, breakdowns_since_last_service ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1190
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1191
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_delay ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1192
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_chance ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1193
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1194
	OCL_SVAR( OC_UINT16, Vehicle, reliability ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1195
	OCL_SVAR( OC_UINT16, Vehicle, reliability_spd_dec ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1196
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1197
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_this_year ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1198
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Vehicle, profit_last_year ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1199
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1200
	OCL_VAR ( OC_UINT16,   1, &_old_next_ptr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1201
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1202
	OCL_SVAR( OC_UINT32, Vehicle, value ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1203
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1204
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1205
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1206
	OCL_CHUNK( 1, LoadOldVehicleUnion ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1207
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1208
	OCL_NULL( 20 ), ///< Junk at end of struct (TTDPatch has some data in it)
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1209
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1210
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1211
};
3626
151f99d38c69 (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
  1212
8033
f80315b59db1 (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: 7989
diff changeset
  1213
bool LoadOldVehicle(LoadgameState *ls, int num)
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1214
{
959
b031d88c76f3 (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 923
diff changeset
  1215
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1217
	/* Read the TTDPatch flags, because we need some info from it */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1218
	ReadTTDPatchFlags();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
3626
151f99d38c69 (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
  1220
	for (i = 0; i < _old_vehicle_multiplier; i++) {
151f99d38c69 (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
  1221
		_current_vehicle_id = num * _old_vehicle_multiplier + i;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1222
9221
1168ec4e2ea4 (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: 9220
diff changeset
  1223
		/* Read the vehicle type and allocate the right vehicle */
1168ec4e2ea4 (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: 9220
diff changeset
  1224
		Vehicle *v;
1168ec4e2ea4 (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: 9220
diff changeset
  1225
		switch (ReadByte(ls)) {
1168ec4e2ea4 (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: 9220
diff changeset
  1226
			default: NOT_REACHED();
1168ec4e2ea4 (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: 9220
diff changeset
  1227
			case 0x00 /*VEH_INVALID */: v = new (_current_vehicle_id) InvalidVehicle();  break;
1168ec4e2ea4 (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: 9220
diff changeset
  1228
			case 0x10 /*VEH_TRAIN   */: v = new (_current_vehicle_id) Train();           break;
1168ec4e2ea4 (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: 9220
diff changeset
  1229
			case 0x11 /*VEH_ROAD    */: v = new (_current_vehicle_id) RoadVehicle();     break;
1168ec4e2ea4 (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: 9220
diff changeset
  1230
			case 0x12 /*VEH_SHIP    */: v = new (_current_vehicle_id) Ship();            break;
1168ec4e2ea4 (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: 9220
diff changeset
  1231
			case 0x13 /*VEH_AIRCRAFT*/: v = new (_current_vehicle_id) Aircraft();        break;
1168ec4e2ea4 (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: 9220
diff changeset
  1232
			case 0x14 /*VEH_SPECIAL */: v = new (_current_vehicle_id) SpecialVehicle();  break;
1168ec4e2ea4 (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: 9220
diff changeset
  1233
			case 0x15 /*VEH_DISASTER*/: v = new (_current_vehicle_id) DisasterVehicle(); break;
1168ec4e2ea4 (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: 9220
diff changeset
  1234
		}
3626
151f99d38c69 (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
  1235
		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1236
1340
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1237
		/* This should be consistent, else we have a big problem... */
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1238
		if (v->index != _current_vehicle_id) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1239
			DEBUG(oldloader, 0, "Loading failed - vehicle-array is invalid");
1340
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1240
			return false;
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1241
		}
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1242
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1243
		if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
9220
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1244
			uint old_id = REMAP_ORDER_IDX(_old_order_ptr);
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1245
			/* There is a maximum of 5000 orders in old savegames, so *if*
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1246
			 * we go over that limit something is very wrong. In that case
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1247
			 * we just assume there are no orders for the vehicle.
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1248
			 */
100ccf09fe18 (svn r12399) -Fix: some old DOS savegame didn't load properly due to 'garbage' that was sprinkled in some places.
rubidium
parents: 9203
diff changeset
  1249
			if (old_id < 5000) v->orders = GetOrder(old_id);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1250
		}
9331
f67d4fd5ed5d (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium
parents: 9289
diff changeset
  1251
		v->current_order.AssignOrder(UnpackOldOrder(_old_order));
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1252
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1253
		/* For some reason we need to correct for this */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1254
		switch (v->spritenum) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1255
			case 0xfd: break;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1256
			case 0xff: v->spritenum = 0xfe; break;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1257
			default:   v->spritenum >>= 1; break;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1258
		}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1259
8234
7147ae98e47d (svn r11275) -Fix: oldloader crashing when referencing a vehicle that is not yet loaded.
rubidium
parents: 8232
diff changeset
  1260
		if (_old_next_ptr != 0xFFFF) v->next = GetVehiclePoolSize() <= _old_next_ptr ? new (_old_next_ptr) InvalidVehicle() : GetVehicle(_old_next_ptr);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1261
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1262
		_old_string_id = RemapOldStringID(_old_string_id);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1263
		v->name = CopyFromOldName(_old_string_id);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1264
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1265
		/* Vehicle-subtype is different in TTD(Patch) */
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  1266
		if (v->type == VEH_SPECIAL) v->subtype = v->subtype >> 1;
7506
e52d89f5c7c1 (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: 7453
diff changeset
  1267
e52d89f5c7c1 (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: 7453
diff changeset
  1268
		if (_cargo_count != 0) {
e52d89f5c7c1 (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: 7453
diff changeset
  1269
			CargoPacket *cp = new CargoPacket((_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, _cargo_count);
e52d89f5c7c1 (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: 7453
diff changeset
  1270
			cp->days_in_transit = _cargo_days;
e52d89f5c7c1 (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: 7453
diff changeset
  1271
			v->cargo.Append(cp);
e52d89f5c7c1 (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: 7453
diff changeset
  1272
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1275
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1276
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1277
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1278
static const OldChunks sign_chunk[] = {
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1279
	OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6677
diff changeset
  1280
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, x ),
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6677
diff changeset
  1281
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Sign, y ),
4349
2fc39ff2626e (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1282
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, Sign, z ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1283
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1284
	OCL_NULL( 6 ),         ///< Width of sign, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1285
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1286
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1287
};
3626
151f99d38c69 (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
  1288
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1289
static bool LoadOldSign(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1290
{
8756
512ea7de938c (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8755
diff changeset
  1291
	Sign *si = new (num) Sign();
512ea7de938c (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8755
diff changeset
  1292
	if (!LoadChunk(ls, si, sign_chunk)) return false;
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1293
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1294
	_old_string_id = RemapOldStringID(_old_string_id);
8756
512ea7de938c (svn r11824) -Fix (r11822): Converting signs from TTD games incomplete
peter1138
parents: 8755
diff changeset
  1295
	si->name = CopyFromOldName(_old_string_id);
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1296
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  1297
	return true;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1298
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1299
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1300
static const OldChunks engine_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1301
	OCL_SVAR( OC_UINT16, Engine, player_avail ),
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1302
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1303
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1304
	OCL_SVAR( OC_UINT16, Engine, reliability ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1305
	OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1306
	OCL_SVAR( OC_UINT16, Engine, reliability_start ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1307
	OCL_SVAR( OC_UINT16, Engine, reliability_max ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1308
	OCL_SVAR( OC_UINT16, Engine, reliability_final ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1309
	OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1310
	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1311
	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1312
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1313
	OCL_SVAR(  OC_UINT8, Engine, lifelength ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1314
	OCL_SVAR(  OC_UINT8, Engine, flags ),
9061
fe9f2555d02e (svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents: 8930
diff changeset
  1315
	OCL_SVAR(  OC_UINT8, Engine, preview_player_rank ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1316
	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1317
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1318
	OCL_NULL( 2 ), ///< Junk
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1319
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1320
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1321
};
3626
151f99d38c69 (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
  1322
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1323
static bool LoadOldEngine(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1324
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1325
	if (!LoadChunk(ls, GetEngine(num), engine_chunk)) return false;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1326
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1327
	/* Make sure wagons are marked as do-not-age */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1328
	if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116))
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1891
diff changeset
  1329
		GetEngine(num)->age = 0xFFFF;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1330
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1331
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1332
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1333
8755
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1334
static bool LoadOldEngineName(LoadgameState *ls, int num)
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1335
{
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1336
	Engine *e = GetEngine(num);
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1337
	e->name = CopyFromOldName(RemapOldStringID(ReadUint16(ls)));
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1338
	return true;
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1339
}
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1340
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1341
static const OldChunks subsidy_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1342
	OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1343
	OCL_SVAR(  OC_UINT8, Subsidy, age ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1344
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1345
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1346
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1347
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1348
};
3626
151f99d38c69 (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
  1349
151f99d38c69 (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
  1350
static inline bool LoadOldSubsidy(LoadgameState *ls, int num)
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1351
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1352
	return LoadChunk(ls, &_subsidies[num], subsidy_chunk);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1353
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1354
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1355
static const OldChunks game_difficulty_chunk[] = {
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1356
	OCL_SVAR( OC_UINT16, GameDifficulty, max_no_competitors ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1357
	OCL_SVAR( OC_UINT16, GameDifficulty, competitor_start_time ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1358
	OCL_SVAR( OC_UINT16, GameDifficulty, number_towns ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1359
	OCL_SVAR( OC_UINT16, GameDifficulty, number_industries ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1360
	OCL_SVAR( OC_UINT16, GameDifficulty, max_loan ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1361
	OCL_SVAR( OC_UINT16, GameDifficulty, initial_interest ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1362
	OCL_SVAR( OC_UINT16, GameDifficulty, vehicle_costs ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1363
	OCL_SVAR( OC_UINT16, GameDifficulty, competitor_speed ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1364
	OCL_SVAR( OC_UINT16, GameDifficulty, competitor_intelligence ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1365
	OCL_SVAR( OC_UINT16, GameDifficulty, vehicle_breakdowns ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1366
	OCL_SVAR( OC_UINT16, GameDifficulty, subsidy_multiplier ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1367
	OCL_SVAR( OC_UINT16, GameDifficulty, construction_cost ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1368
	OCL_SVAR( OC_UINT16, GameDifficulty, terrain_type ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1369
	OCL_SVAR( OC_UINT16, GameDifficulty, quantity_sea_lakes ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1370
	OCL_SVAR( OC_UINT16, GameDifficulty, economy ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1371
	OCL_SVAR( OC_UINT16, GameDifficulty, line_reverse_mode ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1372
	OCL_SVAR( OC_UINT16, GameDifficulty, disasters ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1373
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1374
};
3626
151f99d38c69 (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
  1375
151f99d38c69 (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
  1376
static inline bool LoadOldGameDifficulty(LoadgameState *ls, int num)
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1377
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1378
	return LoadChunk(ls, &_opt.diff, game_difficulty_chunk);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1379
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1380
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1381
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1382
static bool LoadOldMapPart1(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1383
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1384
	uint i;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1385
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1386
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2360
09e42e4ee139 (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
  1387
		_m[i].m1 = ReadByte(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1388
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1389
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
ad0d49c916d4 (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
  1390
		_m[i].m2 = ReadByte(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1391
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1392
	for (i = 0; i < OLD_MAP_SIZE; i++) {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1393
		_old_map3[i * 2] = ReadByte(ls);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1394
		_old_map3[i * 2 + 1] = ReadByte(ls);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1395
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1396
	for (i = 0; i < OLD_MAP_SIZE / 4; i++) {
2049
ad0d49c916d4 (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
  1397
		byte b = ReadByte(ls);
5847
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
  1398
		_m[i * 4 + 0].m6 = GB(b, 0, 2);
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
  1399
		_m[i * 4 + 1].m6 = GB(b, 2, 2);
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
  1400
		_m[i * 4 + 2].m6 = GB(b, 4, 2);
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
  1401
		_m[i * 4 + 3].m6 = GB(b, 6, 2);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1402
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1403
1326
f37b6aa28829 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1404
	return !ls->failed;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1405
}
3626
151f99d38c69 (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
  1406
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1407
static bool LoadOldMapPart2(LoadgameState *ls, int num)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1408
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1409
	uint i;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1410
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1411
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
ad0d49c916d4 (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
  1412
		_m[i].type_height = ReadByte(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1413
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1414
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
ad0d49c916d4 (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
  1415
		_m[i].m5 = ReadByte(ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1416
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1417
1326
f37b6aa28829 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1418
	return !ls->failed;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1419
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1420
6400
7b98825c5cb0 (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: 6343
diff changeset
  1421
static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int num)
7b98825c5cb0 (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: 6343
diff changeset
  1422
{
7b98825c5cb0 (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: 6343
diff changeset
  1423
	ReadTTDPatchFlags();
7b98825c5cb0 (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: 6343
diff changeset
  1424
7b98825c5cb0 (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: 6343
diff changeset
  1425
	DEBUG(oldloader, 2, "Found %d extra chunk(s)", _old_extra_chunk_nums);
7b98825c5cb0 (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: 6343
diff changeset
  1426
7b98825c5cb0 (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: 6343
diff changeset
  1427
	for (int i = 0; i != _old_extra_chunk_nums; i++) {
7b98825c5cb0 (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: 6343
diff changeset
  1428
		uint16 id = ReadUint16(ls);
7b98825c5cb0 (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: 6343
diff changeset
  1429
		uint32 len = ReadUint32(ls);
7b98825c5cb0 (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: 6343
diff changeset
  1430
7b98825c5cb0 (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: 6343
diff changeset
  1431
		switch (id) {
6411
20de64c934e8 (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: 6400
diff changeset
  1432
			/* List of GRFIDs, used in the savegame. 0x8004 is the new ID
6400
7b98825c5cb0 (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: 6343
diff changeset
  1433
			 * They are saved in a 'GRFID:4 active:1' format, 5 bytes for each entry */
7b98825c5cb0 (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: 6343
diff changeset
  1434
			case 0x2:
7b98825c5cb0 (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: 6343
diff changeset
  1435
			case 0x8004: {
6411
20de64c934e8 (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: 6400
diff changeset
  1436
				/* Skip the first element: TTDP hack for the Action D special variables (FFFF0000 01) */
6400
7b98825c5cb0 (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: 6343
diff changeset
  1437
				ReadUint32(ls); ReadByte(ls); len -= 5;
7b98825c5cb0 (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: 6343
diff changeset
  1438
7b98825c5cb0 (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: 6343
diff changeset
  1439
				ClearGRFConfigList(&_grfconfig);
7b98825c5cb0 (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: 6343
diff changeset
  1440
				while (len != 0) {
7b98825c5cb0 (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: 6343
diff changeset
  1441
					uint32 grfid = ReadUint32(ls);
7b98825c5cb0 (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: 6343
diff changeset
  1442
7b98825c5cb0 (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: 6343
diff changeset
  1443
					if (ReadByte(ls) == 1) {
6434
d12a3ab5acbc (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6411
diff changeset
  1444
						GRFConfig *c = CallocT<GRFConfig>(1);
d12a3ab5acbc (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6411
diff changeset
  1445
						c->grfid = grfid;
d12a3ab5acbc (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6411
diff changeset
  1446
						c->filename = strdup("TTDP game, no information");
6400
7b98825c5cb0 (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: 6343
diff changeset
  1447
6434
d12a3ab5acbc (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6411
diff changeset
  1448
						AppendToGRFConfigList(&_grfconfig, c);
d12a3ab5acbc (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6411
diff changeset
  1449
						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid));
6400
7b98825c5cb0 (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: 6343
diff changeset
  1450
					}
7b98825c5cb0 (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: 6343
diff changeset
  1451
					len -= 5;
7b98825c5cb0 (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: 6343
diff changeset
  1452
				};
7b98825c5cb0 (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: 6343
diff changeset
  1453
7b98825c5cb0 (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: 6343
diff changeset
  1454
				/* Append static NewGRF configuration */
7b98825c5cb0 (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: 6343
diff changeset
  1455
				AppendStaticGRFConfigs(&_grfconfig);
7b98825c5cb0 (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: 6343
diff changeset
  1456
			} break;
6411
20de64c934e8 (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: 6400
diff changeset
  1457
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1458
			/* TTDPatch version and configuration */
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1459
			case 0x3: {
6400
7b98825c5cb0 (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: 6343
diff changeset
  1460
				uint32 ttdpv = ReadUint32(ls);
7b98825c5cb0 (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: 6343
diff changeset
  1461
				DEBUG(oldloader, 3, "Game saved with TTDPatch version %d.%d.%d r%d", GB(ttdpv, 24, 8), GB(ttdpv, 20, 4), GB(ttdpv, 16, 4), GB(ttdpv, 0, 16));
7b98825c5cb0 (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: 6343
diff changeset
  1462
				len -= 4;
7b98825c5cb0 (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: 6343
diff changeset
  1463
				while (len-- != 0) ReadByte(ls); // skip the configuration
7b98825c5cb0 (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: 6343
diff changeset
  1464
			} break;
6411
20de64c934e8 (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: 6400
diff changeset
  1465
6400
7b98825c5cb0 (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: 6343
diff changeset
  1466
			default:
7b98825c5cb0 (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: 6343
diff changeset
  1467
				DEBUG(oldloader, 4, "Skipping unknown extra chunk %X", id);
7b98825c5cb0 (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: 6343
diff changeset
  1468
				while (len-- != 0) ReadByte(ls);
7b98825c5cb0 (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: 6343
diff changeset
  1469
				break;
7b98825c5cb0 (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: 6343
diff changeset
  1470
		}
7b98825c5cb0 (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: 6343
diff changeset
  1471
	}
7b98825c5cb0 (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: 6343
diff changeset
  1472
7b98825c5cb0 (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: 6343
diff changeset
  1473
	return !ls->failed;
7b98825c5cb0 (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: 6343
diff changeset
  1474
}
7b98825c5cb0 (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: 6343
diff changeset
  1475
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1476
static uint32 _old_cur_town_ctr;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1477
static const OldChunks main_chunk[] = {
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1478
	OCL_ASSERT( 0 ),
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4321
diff changeset
  1479
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_date ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1480
	OCL_VAR ( OC_UINT16,   1, &_date_fract ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1481
	OCL_NULL( 600 ),            ///< TextEffects
8930
361433723616 (svn r12004) -Codechange: refactor the random functions to reduce code duplication.
rubidium
parents: 8908
diff changeset
  1482
	OCL_VAR ( OC_UINT32,   2, &_random.state ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1483
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1484
	OCL_ASSERT( 0x264 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1485
	OCL_CHUNK(  70, LoadOldTown ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1486
	OCL_ASSERT( 0x1C18 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1487
	OCL_CHUNK(5000, LoadOldOrder ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1488
	OCL_ASSERT( 0x4328 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1489
8207
96f2081fb385 (svn r11245) -Fix r11228: the moreanimation feature made loading TTD(p) games impossible (Csaboka)
truelight
parents: 8190
diff changeset
  1490
	OCL_CHUNK( 1, LoadOldAnimTileList ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1491
	OCL_NULL( 4 ),              ///< old end-of-order-list-pointer, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1492
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1493
	OCL_CHUNK( 255, LoadOldDepot ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1494
	OCL_ASSERT( 0x4B26 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1495
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1496
	OCL_VAR ( OC_UINT32,   1, &_old_cur_town_ctr ),
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1497
	OCL_NULL( 2 ),              ///< timer_counter, no longer in use
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1498
	OCL_NULL( 2 ),              ///< land_code,     no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1499
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1500
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1501
	OCL_VAR ( OC_UINT16,   1, &_tick_counter ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1502
	OCL_VAR (   OC_TILE,   1, &_cur_tileloop_tile ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1503
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1504
	OCL_CHUNK( 49, LoadOldPrice ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1505
	OCL_CHUNK( 12, LoadOldCargoPaymentRate ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1506
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1507
	OCL_ASSERT( 0x4CBA ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1508
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1509
	OCL_CHUNK( 1, LoadOldMapPart1 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1510
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1511
	OCL_ASSERT( 0x48CBA ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1512
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1513
	OCL_CHUNK(250, LoadOldStation ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1514
	OCL_CHUNK( 90, LoadOldIndustry ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1515
	OCL_CHUNK(  8, LoadOldPlayer ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1516
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1517
	OCL_ASSERT( 0x547F2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1518
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1519
	OCL_CHUNK( 850, LoadOldVehicle ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1520
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1521
	OCL_ASSERT( 0x6F0F2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1522
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1523
	OCL_VAR (  OC_UINT8, 32 * 500, &_name_array[0] ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1524
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1525
	OCL_NULL( 0x2000 ),            ///< Old hash-table, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1526
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1527
	OCL_CHUNK( 40, LoadOldSign ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1528
	OCL_CHUNK(256, LoadOldEngine ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1529
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1530
	OCL_VAR ( OC_UINT16,    1, &_vehicle_id_ctr_day ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1531
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1532
	OCL_CHUNK(  8, LoadOldSubsidy ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1533
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1534
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,   1, &_next_competitor_start ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1535
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_x ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1536
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_y ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1537
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8,    1, &_saved_scrollpos_zoom ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1538
8239
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1539
	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1540
	OCL_VAR ( OC_FILE_U32 | OC_VAR_I64,   1, &_economy.max_loan_unround ),
4faca456c12d (svn r11280) -Fix [FS#1343]: wrong money related values when loading old games. Inspired on a patch by SmatZ.
rubidium
parents: 8234
diff changeset
  1541
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,   1, &_economy.fluct ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1542
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1543
	OCL_VAR ( OC_UINT16,    1, &_disaster_delay ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1544
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1545
	OCL_NULL( 144 ),             ///< cargo-stuff, calculated in InitializeLandscapeVariables
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1546
8755
f148fd44aa06 (svn r11823) -Fix (r11822): Custom names from old TTD games were not updated.
peter1138
parents: 8754
diff changeset
  1547
	OCL_CHUNK(256, LoadOldEngineName ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1548
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1549
	OCL_NULL( 144 ),             ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1550
	OCL_NULL( 2 ),               ///< Company indexes of players, no longer in use
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1551
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1552
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1553
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1554
	OCL_VAR (  OC_UINT8,    1, &_opt.currency ),
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3269
diff changeset
  1555
	OCL_VAR (  OC_UINT8,    1, &_opt.units ),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1556
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_player_tick_index ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1557
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1558
	OCL_NULL( 2 ),               ///< Date stuff, calculated automatically
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1559
	OCL_NULL( 8 ),               ///< Player colors, calculated automatically
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1560
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1561
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1562
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount_pr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1563
	OCL_VAR (  OC_UINT8,    1, &_economy.interest_rate ),
6222
50e47f803549 (svn r8660) -Fix
tron
parents: 6130
diff changeset
  1564
	OCL_NULL( 1 ), // available airports
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1565
	OCL_VAR (  OC_UINT8,    1, &_opt.road_side ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1566
	OCL_VAR (  OC_UINT8,    1, &_opt.town_name ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1567
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1568
	OCL_CHUNK( 1, LoadOldGameDifficulty ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1569
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1570
	OCL_ASSERT( 0x77130 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1571
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1572
	OCL_VAR (  OC_UINT8,    1, &_opt.diff_level ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1573
	OCL_VAR (  OC_UINT8,    1, &_opt.landscape ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1574
	OCL_VAR (  OC_UINT8,    1, &_trees_tick_ctr ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1575
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1576
	OCL_NULL( 1 ),               ///< Custom vehicle types yes/no, no longer used
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1577
	OCL_VAR (  OC_UINT8,    1, &_opt.snow_line ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1578
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1579
	OCL_NULL( 32 ),              ///< new_industry_randtable, no longer used (because of new design)
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6589
diff changeset
  1580
	OCL_NULL( 36 ),              ///< cargo-stuff, calculated in InitializeLandscapeVariables
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1581
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1582
	OCL_ASSERT( 0x77179 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1583
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1584
	OCL_CHUNK( 1, LoadOldMapPart2 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1585
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1586
	OCL_ASSERT( 0x97179 ),
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1587
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1588
	/* Below any (if available) extra chunks from TTDPatch can follow */
6400
7b98825c5cb0 (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: 6343
diff changeset
  1589
	OCL_CHUNK(1, LoadTTDPatchExtraChunks),
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1590
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1591
	OCL_END()
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1592
};
3626
151f99d38c69 (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
  1593
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1594
static bool LoadOldMain(LoadgameState *ls)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1595
{
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1596
	int i;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1597
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1598
	/* The first 49 is the name of the game + checksum, skip it */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1599
	fseek(ls->file, HEADER_SIZE, SEEK_SET);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1600
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
  1601
	DEBUG(oldloader, 3, "Reading main chunk...");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1602
	/* Load the biggest chunk */
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1603
	if (!LoadChunk(ls, NULL, main_chunk)) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1604
		DEBUG(oldloader, 0, "Loading failed");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1605
		return false;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1606
	}
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
  1607
	DEBUG(oldloader, 3, "Done, converting game data...");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1608
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1609
	/* Fix some general stuff */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1610
	_opt.landscape = _opt.landscape & 0xF;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1611
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1612
	/* Remap some pointers */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1613
	_cur_town_ctr      = REMAP_TOWN_IDX(_old_cur_town_ctr);
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1614
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1615
	/* _old_map3 is changed in _map3_lo and _map3_hi */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1616
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
ad0d49c916d4 (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
  1617
		_m[i].m3 = _old_map3[i * 2];
ad0d49c916d4 (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
  1618
		_m[i].m4 = _old_map3[i * 2 + 1];
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1619
	}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1620
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1621
	for (i = 0; i < OLD_MAP_SIZE; i ++) {
6341
5d2948b411bf (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: 6340
diff changeset
  1622
		switch (GetTileType(i)) {
7127
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1623
			case MP_STATION:
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1624
				_m[i].m4 = 0; // We do not understand this TTDP station mapping (yet)
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1625
				switch (_m[i].m5) {
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1626
					/* We have drive through stops at a totally different place */
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7661
diff changeset
  1627
					case 0x53: case 0x54: _m[i].m5 += 170 - 0x53; break; // Bus drive through
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7661
diff changeset
  1628
					case 0x57: case 0x58: _m[i].m5 += 168 - 0x57; break; // Truck drive through
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7661
diff changeset
  1629
					case 0x55: case 0x56: _m[i].m5 += 170 - 0x55; break; // Bus tram stop
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7661
diff changeset
  1630
					case 0x59: case 0x5A: _m[i].m5 += 168 - 0x59; break; // Truck tram stop
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7661
diff changeset
  1631
					default: break;
7127
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1632
				}
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1633
				break;
8d8bb32f17f8 (svn r9857) -Fix: loading of TTDP savegames with features that OTTD has.
rubidium
parents: 7057
diff changeset
  1634
6341
5d2948b411bf (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: 6340
diff changeset
  1635
			case MP_RAILWAY:
5d2948b411bf (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: 6340
diff changeset
  1636
				/* We save presignals different from TTDPatch, convert them */
5d2948b411bf (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: 6340
diff changeset
  1637
				if (GetRailTileType(i) == RAIL_TILE_SIGNALS) {
5d2948b411bf (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: 6340
diff changeset
  1638
					/* This byte is always zero in TTD for this type of tile */
5d2948b411bf (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: 6340
diff changeset
  1639
					if (_m[i].m4) /* Convert the presignals to our own format */
5d2948b411bf (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: 6340
diff changeset
  1640
						_m[i].m4 = (_m[i].m4 >> 1) & 7;
5d2948b411bf (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: 6340
diff changeset
  1641
				}
5d2948b411bf (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: 6340
diff changeset
  1642
				/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
5d2948b411bf (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: 6340
diff changeset
  1643
				 * clear it for ourselves and let OTTD's rebuild PBS itself */
5d2948b411bf (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: 6340
diff changeset
  1644
				_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
5d2948b411bf (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: 6340
diff changeset
  1645
				break;
6343
56b8beb2ee6b (svn r8740) -Fix (r8783): GCC warnings about not-handled MP_ values in switch case (glx)
Darkvater
parents: 6342
diff changeset
  1646
			default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
8232
a5bb946ff898 (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: 8216
diff changeset
  1650
	/* Make sure the available engines are really available, otherwise
a5bb946ff898 (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: 8216
diff changeset
  1651
	 * we will get a "new vehicle"-spree. */
8897
fe3716f7d205 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8760
diff changeset
  1652
	Engine *e;
fe3716f7d205 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8760
diff changeset
  1653
	FOR_ALL_ENGINES(e) {
8232
a5bb946ff898 (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: 8216
diff changeset
  1654
		if (_date >= (e->intro_date + 365)) {
a5bb946ff898 (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: 8216
diff changeset
  1655
			e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
a5bb946ff898 (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: 8216
diff changeset
  1656
			e->player_avail = (byte)-1;
a5bb946ff898 (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: 8216
diff changeset
  1657
		}
a5bb946ff898 (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: 8216
diff changeset
  1658
	}
a5bb946ff898 (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: 8216
diff changeset
  1659
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1660
	/* Fix the game to be compatible with OpenTTD */
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1661
	FixOldTowns();
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1662
	FixOldStations();
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1663
	FixOldVehicles();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1665
	/* We have a new difficulty setting */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8239
diff changeset
  1666
	_opt.diff.town_council_tolerance = Clamp(_opt.diff_level, 0, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
  1668
	DEBUG(oldloader, 3, "Finished converting game data");
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1669
	DEBUG(oldloader, 1, "TTD(Patch) savegame successfully converted");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1671
	return true;
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1672
}
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1673
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1674
bool LoadOldSaveGame(const char *file)
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1675
{
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1676
	LoadgameState ls;
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1677
6342
4a149d14f07c (svn r8739) -Codechange: Update the oldloader debug levels to be more in spec with the guidelines in debug.h.
Darkvater
parents: 6341
diff changeset
  1678
	DEBUG(oldloader, 3, "Trying to load a TTD(Patch) savegame");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1679
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1680
	InitLoading(&ls);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1681
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1682
	/* Open file */
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1683
	ls.file = fopen(file, "rb");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1684
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1685
	if (ls.file == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4983
diff changeset
  1686
		DEBUG(oldloader, 0, "Cannot open file '%s'", file);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1687
		return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1690
	/* Load the main chunk */
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1691
	if (!LoadOldMain(&ls)) return false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
  1692
2452
0960df1a61b4 (svn r2978) Make a global variable local
tron
parents: 2360
diff changeset
  1693
	fclose(ls.file);
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1694
6557
8381016f71f3 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6434
diff changeset
  1695
	_pause_game = 2;
1340
50d99579ddd0 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1696
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
4221
bb06fe8dcce2 (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
  1700
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
  1701
{
4221
bb06fe8dcce2 (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
  1702
	char filename[MAX_PATH];
bb06fe8dcce2 (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
  1703
	FILE *f;
bb06fe8dcce2 (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
  1704
bb06fe8dcce2 (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
  1705
	snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, file);
bb06fe8dcce2 (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
  1706
	f = fopen(filename, "rb");
bb06fe8dcce2 (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
  1707
	title[0] = '\0';
bb06fe8dcce2 (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
  1708
	title[48] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
3626
151f99d38c69 (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
  1710
	if (f == NULL) return;
1326
f37b6aa28829 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1711
3626
151f99d38c69 (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
  1712
	if (fread(title, 1, 48, f) != 48) snprintf(title, 48, "Corrupt file");
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1713
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
}