oldloader.c
author Darkvater
Mon, 18 Jul 2005 00:17:19 +0000
changeset 2118 aec8042f000b
parent 2099 02c5a49863e9
child 2140 a04d0142ad65
permissions -rw-r--r--
(svn r2628) - Fix: Planting trees does not result in a MapSize() assertion anymore; introduced in r2598
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1537
diff changeset
     2
#include "openttd.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 436
diff changeset
     3
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 577
diff changeset
     4
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "vehicle.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 974
diff changeset
    12
#include "signs.h"
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    13
#include "debug.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1284
diff changeset
    14
#include "depot.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    16
enum {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    17
	HEADER_SIZE = 49,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    18
	BUFFER_SIZE = 4096,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    20
	OLD_MAP_SIZE = 256 * 256
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    21
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    23
typedef struct LoadgameState {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    24
	FILE *file;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    26
	uint chunk_size;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    28
	bool decoding;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    29
	byte decode_char;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    31
	uint buffer_count;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    32
	uint buffer_cur;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    33
	byte buffer[BUFFER_SIZE];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    35
	uint total_read;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    36
	bool failed;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    37
} LoadgameState;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    39
typedef bool OldChunkProc(LoadgameState *ls, int num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    41
typedef struct OldChunks {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    42
	uint32 type;         //! Type of field
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    43
	uint32 amount;       //! Amount of fields
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    44
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    45
	void *ptr;           //! Pointer where to save the data (may only be set if offset is 0)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    46
	uint offset;         //! Offset from basepointer (may only be set if ptr is NULL)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    47
	OldChunkProc *proc;  //! Pointer to function that is called with OC_CHUNK
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    48
} OldChunks;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    49
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    50
/* OldChunk-Type */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    51
enum {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    52
	OC_END       = 0,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    53
	OC_NULL      = 1 << 0,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    54
	OC_CHUNK     = 1 << 1,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    55
	OC_ASSERT    = 1 << 2,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    56
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    57
	OC_VAR_I8    = 1 << 9,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    58
	OC_VAR_U8    = 1 << 10,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    59
	OC_VAR_I16   = 1 << 11,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    60
	OC_VAR_U16   = 1 << 12,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    61
	OC_VAR_I32   = 1 << 13,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    62
	OC_VAR_U32   = 1 << 14,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    63
	OC_VAR_I64   = 1 << 15,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    64
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    65
	OC_FILE_I8   = 1 << 17,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    66
	OC_FILE_U8   = 1 << 18,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    67
	OC_FILE_I16  = 1 << 19,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    68
	OC_FILE_U16  = 1 << 20,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    69
	OC_FILE_I32  = 1 << 21,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    70
	OC_FILE_U32  = 1 << 22,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    71
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    72
	OC_INT8      = OC_VAR_I8   | OC_FILE_I8,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    73
	OC_UINT8     = OC_VAR_U8   | OC_FILE_U8,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    74
	OC_INT16     = OC_VAR_I16  | OC_FILE_I16,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    75
	OC_UINT16    = OC_VAR_U16  | OC_FILE_U16,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    76
	OC_INT32     = OC_VAR_I32  | OC_FILE_I32,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    77
	OC_UINT32    = OC_VAR_U32  | OC_FILE_U32,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    78
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    79
	OC_TILE      = OC_VAR_U32  | OC_FILE_U16
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    80
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    81
/* If it fails, check lines above.. */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    82
assert_compile(sizeof(TileIndex) == 4);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    83
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    84
static LoadgameState _ls;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    85
static uint32 _bump_assert_value;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    86
static bool   _read_ttdpatch_flags;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    87
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    88
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    89
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    90
 * Reads a byte from a file (do not call yourself, use ReadByte())
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    91
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    92
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    93
static byte ReadByteFromFile(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    95
	/* To avoid slow reads, we read BUFFER_SIZE of bytes per time
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    96
	and just return a byte per time */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    97
	if (ls->buffer_cur >= ls->buffer_count) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    98
		/* Read some new bytes from the file */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
    99
		int count = fread(ls->buffer, 1, BUFFER_SIZE, ls->file);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   101
		/* We tried to read, but there is nothing in the file anymore.. */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   102
		if (count == 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   103
			DEBUG(oldloader, 1)("[OldLoader] Read past end of file, loading failed");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   104
			ls->failed = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   105
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   106
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   107
		ls->buffer_count = count;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   108
		ls->buffer_cur   = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   111
	return ls->buffer[ls->buffer_cur++];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   114
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   115
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   116
 * Reads a byte from the buffer and decompress if needed
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   117
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   118
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   119
static byte ReadByte(LoadgameState *ls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   121
	/* Old savegames have a nice compression algorithm (RLE)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   122
	which means that we have a chunk, which starts with a length
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   123
	byte. If that byte is negative, we have to repeat the next byte
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   124
	that many times (+1). Else, we need to read that amount of bytes.
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   125
	Works pretty good if you have many zero's behind eachother */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   126
	int8 new_byte;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   128
	/* Check if we are reading a chunk */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   129
	if (ls->chunk_size != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   130
		ls->total_read++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   131
		ls->chunk_size--;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   132
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   133
		/* If we are decoding, return the decode_char */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   134
		if (ls->decoding)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   135
			return ls->decode_char;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   136
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   137
		/* Else return byte from file */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   138
		return ReadByteFromFile(ls);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   140
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   141
	/* Read new chunk */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   142
	new_byte = ReadByteFromFile(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   143
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   144
	if (new_byte < 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   145
		/* Repeat next char for new_byte times */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   146
		ls->decoding    = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   147
		ls->decode_char = ReadByteFromFile(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   148
		ls->chunk_size  = -new_byte + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	} else {
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   150
		ls->decoding    = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   151
		ls->chunk_size  = new_byte + 1;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   152
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   153
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   154
	/* Call this function again to return a byte */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   155
	return ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   156
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   157
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   158
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   159
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   160
 * Loads a chunk from the old savegame
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   161
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   162
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   163
static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   164
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   165
	const OldChunks *chunk = chunks;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   166
	byte *ptr;
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   167
	byte *base_ptr = base;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   168
	uint i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   169
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   170
	while (chunk->type != OC_END) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   171
		ptr = chunk->ptr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   172
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   173
		for (i = 0; i < chunk->amount; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   174
			if (ls->failed)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   175
				return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   176
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   177
			/* Handle simple types */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   178
			if ((chunk->type & 0xFF) != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   179
				switch (chunk->type & 0xFF) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   180
					case OC_NULL:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   181
						/* Just read the byte and forget about it */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   182
						ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   183
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   184
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   185
					case OC_CHUNK:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   186
						/* Call function, with 'i' as parameter to tell which item we
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   187
						are going to read */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   188
						if (!chunk->proc(ls, i))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   189
							return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   190
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   191
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   192
					case OC_ASSERT:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   193
						DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   194
						if (ls->total_read != chunk->offset + _bump_assert_value)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   195
							ls->failed = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   196
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   197
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   198
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   199
				}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   200
			} else {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   201
				uint32 res = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   202
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   203
				/* Reading from the file: bit 16 to 23 have the FILE */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   204
				switch (((chunk->type >> 16) & 0xFF) << 16) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   205
					case OC_FILE_I8:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   206
						res = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   207
						res = (int8)res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   208
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   209
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   210
					case OC_FILE_U8:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   211
						res = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   212
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   213
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   214
					case OC_FILE_U16:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   215
						res =  ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   216
						res += ReadByte(ls) << 8;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   217
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   218
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   219
					case OC_FILE_I16:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   220
						res =  ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   221
						res += ReadByte(ls) << 8;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   222
						res = (int16)res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   223
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   224
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   225
					case OC_FILE_U32:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   226
						res =  ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   227
						res += ReadByte(ls) << 8;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   228
						res += ReadByte(ls) << 16;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   229
						res += ReadByte(ls) << 24;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   230
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   231
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   232
					case OC_FILE_I32:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   233
						res =  ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   234
						res += ReadByte(ls) << 8;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   235
						res += ReadByte(ls) << 16;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   236
						res += ReadByte(ls) << 24;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   237
						res = (int32)res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   238
						break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   239
				}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   240
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   241
				/* Sanity check */
1325
07dc03e05fcd (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
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   243
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   244
				/* Writing to the var: bit 8 till 15 have the VAR */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   245
				switch (((chunk->type >> 8) & 0xFF) << 8) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   246
					case OC_VAR_I8:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   247
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   248
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   249
							*(int8 *)ptr = res & 0xFF;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   250
							ptr++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   251
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   252
							*(int8 *)(base_ptr + chunk->offset) = res & 0xFF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   253
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   254
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   255
					case OC_VAR_U8:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   256
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   257
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   258
							*(uint8 *)ptr = res & 0xFF;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   259
							ptr++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   260
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   261
							*(uint8 *)(base_ptr + chunk->offset) = res & 0xFF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   262
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   263
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   264
					case OC_VAR_U16:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   265
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   266
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   267
							*(uint16 *)ptr = res & 0xFFFF;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   268
							ptr += 2;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   269
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   270
							*(uint16 *)(base_ptr + chunk->offset) = res & 0xFFFF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   271
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   272
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   273
					case OC_VAR_I16:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   274
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   275
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   276
							*(int16 *)ptr = res & 0xFFFF;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   277
							ptr += 2;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   278
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   279
							*(int16 *)(base_ptr + chunk->offset) = res & 0xFFFF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   280
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   281
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   282
					case OC_VAR_U32:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   283
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   284
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   285
							*(uint32 *)ptr = res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   286
							ptr += 4;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   287
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   288
							*(uint32 *)(base_ptr + chunk->offset) = res;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   289
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   290
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   291
					case OC_VAR_I32:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   292
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   293
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   294
							*(int32 *)ptr = res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   295
							ptr += 4;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   296
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   297
							*(int32 *)(base_ptr + chunk->offset) = res;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   298
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   299
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   300
					case OC_VAR_I64:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   301
						/* Write the data */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   302
						if (chunk->ptr != NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   303
							*(int64 *)ptr = res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   304
							ptr += 8;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   305
						} else
1325
07dc03e05fcd (svn r1829) -Fix: fixed some compiler warnings (tnx to Tron for the Makefile-flag)
truelight
parents: 1322
diff changeset
   306
							*(int64 *)(base_ptr + chunk->offset) = res;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   307
							break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   308
				}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   309
			}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   310
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   311
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   312
		chunk++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   313
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   314
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   315
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   316
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   317
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   318
/**
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   319
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   320
 * Initialize some data before reading
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   321
 *
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   322
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   323
static void InitLoading(LoadgameState *ls)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   324
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   325
	ls->chunk_size   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   326
	ls->total_read   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   327
	ls->failed       = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   328
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   329
	ls->decoding     = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   330
	ls->decode_char  = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   331
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   332
	ls->buffer_cur   = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   333
	ls->buffer_count = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   334
	memset(ls->buffer, 0, BUFFER_SIZE);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   335
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   336
	_bump_assert_value = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   337
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   338
	_read_ttdpatch_flags = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   339
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   340
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   341
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   342
/*
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   343
 * Begin -- Stuff to fix the savegames to be OpenTTD compatible
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   344
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   345
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   346
extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   347
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   348
static void FixOldTowns(void)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   349
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   350
	Town *town;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   351
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   352
	/* Convert town-names if needed */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   353
	FOR_ALL_TOWNS(town) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   354
		if (town->xy == 0)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   355
			continue;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   356
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   357
		if (IS_INT_INSIDE(town->townnametype, 0x20C1, 0x20C3)) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   358
			town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _opt.town_name;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   359
			town->townnameparts = GetOldTownName(town->townnameparts, _opt.town_name);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   360
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
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
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   364
static void FixOldStations(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   366
	Station *st;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 875
diff changeset
   367
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   368
	FOR_ALL_STATIONS(st) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   369
		/* Check if we need to swap width and height for the station */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
   370
		if (st->train_tile != 0 && _m[st->train_tile].m5 & 1) {
1396
9d83f4094235 (svn r1900) Simplify a piece of code in the oldloader
tron
parents: 1340
diff changeset
   371
			swap_byte(&st->trainst_w, &st->trainst_h);
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
   372
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   374
		/* Check if there is a bus or truck station, and convert to new format */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   375
		if (st->bus_tile_obsolete != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   376
			st->bus_stops = AllocateRoadStop();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   377
			st->bus_stops->xy = st->bus_tile_obsolete;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   378
			st->bus_stops->used = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   379
			st->bus_stops->status = 3;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   380
			st->bus_stops->station = st->index;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   381
			st->bus_stops->next = NULL;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   382
			st->bus_stops->prev = NULL;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   383
			st->bus_stops->slot[0] = st->bus_stops->slot[1] = INVALID_SLOT;
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1283
diff changeset
   384
		}
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1283
diff changeset
   385
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   386
		if (st->lorry_tile_obsolete != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   387
			st->truck_stops = AllocateRoadStop();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   388
			st->truck_stops->xy = st->lorry_tile_obsolete;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   389
			st->truck_stops->used = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   390
			st->truck_stops->status = 3;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   391
			st->truck_stops->station = st->index;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   392
			st->truck_stops->next = NULL;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   393
			st->truck_stops->prev = NULL;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   394
			st->truck_stops->slot[0] = st->truck_stops->slot[1] = INVALID_SLOT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		}
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   396
	}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   397
}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   398
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   399
static void FixOldVehicles(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
{
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   401
	/* Check for shared orders, and link them correctly */
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   402
	{
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   403
		Vehicle *v;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   404
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   405
		FOR_ALL_VEHICLES(v) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   406
			Vehicle *u;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   407
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   408
			if (v->type == 0)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   409
				continue;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   410
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   411
			FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   412
				if (u->type == 0)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   413
					continue;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   414
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   415
					/* If a vehicle has the same orders, add the link to eachother
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   416
				in both vehicles */
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   417
				if (v->orders == u->orders) {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   418
					v->next_shared = u;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   419
					u->prev_shared = v;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   420
					break;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   421
				}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   422
			}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   423
		}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 988
diff changeset
   424
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   427
/*
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   428
 * End -- Stuff to fix the savegames to be OpenTTD compatible
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   429
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
   431
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   432
/* Help:
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   433
 *  - OCL_SVAR: load 'type' to offset 'offset' in a struct of type 'base', which must also
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   434
 *       be given via base in LoadChunk() as real pointer
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   435
 *  - OCL_VAR: load 'type' to a global var
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   436
 *  - OCL_END: every struct must end with this
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   437
 *  - OCL_NULL: read 'amount' of bytes and send them to /dev/null or something
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   438
 *  - OCL_CHUNK: load an other proc to load a part of the savegame, 'amount' times
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   439
 *  - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   440
 */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   441
#define OCL_SVAR(type, base, offset)         { type,          1, NULL,    offsetof(base, offset), NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   442
#define OCL_VAR(type, amount, pointer)       { type,     amount, pointer, 0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   443
#define OCL_END()                                   { OC_END,        0, NULL,    0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   444
#define OCL_NULL(amount)                            { OC_NULL,  amount, NULL,    0,                      NULL }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   445
#define OCL_CHUNK(amount, proc)                     { OC_CHUNK, amount, NULL,    0,                      proc }
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   446
#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
   447
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   448
/* The savegames has some hard-coded pointers, because it always enters the same
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   449
    piece of memory.. we don't.. so we need to remap ;)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   450
   Old Towns are 94 bytes big
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   451
   Old Orders are 2 bytes big */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   452
#define REMAP_TOWN_IDX(x) ((x) - (0x0459154 - 0x0458EF0)) / 94
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   453
#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
   454
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   455
extern TileIndex _animated_tile_list[256];
1328
eacd8225ed42 (svn r1832) Next byte -> char iteration: custom names
tron
parents: 1326
diff changeset
   456
extern char _name_array[512][32];
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   457
extern uint16 _custom_sprites_base;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   459
static byte   _old_vehicle_multipler;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   460
static uint8  _old_map3[OLD_MAP_SIZE * 2];
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   461
static bool   _new_ttdpatch_format;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   462
static uint32 _old_town_index;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   463
static uint16 _old_string_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   464
static uint16 _old_string_id_2;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   465
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   466
void ReadTTDPatchFlags(void)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   467
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   468
	int i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   469
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   470
	if (_read_ttdpatch_flags)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   471
		return;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   472
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   473
	_read_ttdpatch_flags = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   474
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   475
	/* TTDPatch misuses _old_map3 for flags.. read them! */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   476
	_old_vehicle_multipler = _old_map3[0];
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   477
	/* Somehow.... there was an error in some savegames, so 0 becomes 1
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   478
	and 1 becomes 2. The rest of the values are okay */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   479
	if (_old_vehicle_multipler < 2)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   480
		_old_vehicle_multipler++;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   481
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   482
	/* TTDPatch incraeses the Vehicle-part in the middle of the game,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   483
	so if the multipler is anything else but 1, the assert fails..
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   484
	bump the assert value so it doesn't!
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   485
	(1 multipler == 850 vehicles
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   486
	1 vehicle   == 128 bytes */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   487
	_bump_assert_value = (_old_vehicle_multipler - 1) * 850 * 128;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   488
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   489
	_new_ttdpatch_format   = false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   490
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
   491
	/* Check if we have a modern TTDPatch savegame (has extra data all around) */
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
   492
	if (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   493
		_new_ttdpatch_format = true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   494
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   495
	/* Clean the misused places */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   496
	for (i = 0; i < 17; i++)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   497
		_old_map3[i] = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   498
	for (i = 0x1FE00; i < 0x20000; i++)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   499
		_old_map3[i] = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   500
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   501
	if (_new_ttdpatch_format)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   502
		DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   503
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   504
	DEBUG(oldloader, 1)("[OldLoader] Vehicle-multipler is set to %d (%d vehicles)", _old_vehicle_multipler, _old_vehicle_multipler * 850);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   507
static const OldChunks town_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   508
	OCL_SVAR(   OC_TILE, Town, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   509
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, population ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   510
	OCL_SVAR( OC_UINT16, Town, townnametype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   511
	OCL_SVAR( OC_UINT32, Town, townnameparts ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   512
	OCL_SVAR(  OC_UINT8, Town, grow_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   513
	OCL_NULL( 1 ),         // sort_index,        no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   514
	OCL_NULL( 4 ),         // sign-coordinates,  no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   515
	OCL_NULL( 2 ),         // namewidth,         no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   516
	OCL_SVAR( OC_UINT16, Town, flags12 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   517
	OCL_NULL( 10 ),        // radius,            no longer in use
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 974
diff changeset
   518
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   519
	OCL_SVAR( OC_UINT16, Town, ratings[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   520
	OCL_SVAR( OC_UINT16, Town, ratings[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   521
	OCL_SVAR( OC_UINT16, Town, ratings[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   522
	OCL_SVAR( OC_UINT16, Town, ratings[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   523
	OCL_SVAR( OC_UINT16, Town, ratings[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   524
	OCL_SVAR( OC_UINT16, Town, ratings[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   525
	OCL_SVAR( OC_UINT16, Town, ratings[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   526
	OCL_SVAR( OC_UINT16, Town, ratings[7] ),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   528
	/* XXX - This is pretty odd.. we read 32bit, but only write 8bit.. sure there is
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   529
	nothing changed?? */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   530
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, have_ratings ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   531
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U8, Town, statues ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   532
	OCL_SVAR( OC_UINT16, Town, num_houses ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   533
	OCL_SVAR(  OC_UINT8, Town, time_until_rebuild ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   534
	OCL_SVAR(  OC_UINT8, Town, growth_rate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   535
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   536
	OCL_SVAR( OC_UINT16, Town, new_max_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   537
	OCL_SVAR( OC_UINT16, Town, new_max_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   538
	OCL_SVAR( OC_UINT16, Town, new_act_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   539
	OCL_SVAR( OC_UINT16, Town, new_act_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   540
	OCL_SVAR( OC_UINT16, Town, max_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   541
	OCL_SVAR( OC_UINT16, Town, max_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   542
	OCL_SVAR( OC_UINT16, Town, act_pass ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   543
	OCL_SVAR( OC_UINT16, Town, act_mail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   544
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   545
	OCL_SVAR(  OC_UINT8, Town, pct_pass_transported ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   546
	OCL_SVAR(  OC_UINT8, Town, pct_mail_transported ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   547
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   548
	OCL_SVAR( OC_UINT16, Town, new_act_food ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   549
	OCL_SVAR( OC_UINT16, Town, new_act_water ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   550
	OCL_SVAR( OC_UINT16, Town, act_food ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   551
	OCL_SVAR( OC_UINT16, Town, act_water ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   552
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   553
	OCL_SVAR(  OC_UINT8, Town, road_build_months ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   554
	OCL_SVAR(  OC_UINT8, Town, fund_buildings_months ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   555
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   556
	OCL_NULL( 8 ),         // some junk at the end of the record
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   557
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   558
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   559
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   560
static bool LoadOldTown(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   561
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   562
	if (!AddBlockIfNeeded(&_town_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   563
		error("Towns: failed loading savegame: too many towns");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   564
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   565
	return LoadChunk(ls, GetTown(num), town_chunk);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   568
static uint16 _old_order;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   569
static const OldChunks order_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   570
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   571
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   572
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   573
static bool LoadOldOrder(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   575
	if (!AddBlockIfNeeded(&_order_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   576
		error("Orders: failed loading savegame: too many orders");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   577
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   578
	if (!LoadChunk(ls, NULL, order_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   579
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   580
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   581
	AssignOrder(GetOrder(num), UnpackOldOrder(_old_order));
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   582
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   583
	/* Relink the orders to eachother (in TTD(Patch) the orders for one
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   584
	vehicle are behind eachother, with OT_NOTHING as indication that
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   585
	it is the last order */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   586
	if (num > 0 && GetOrder(num)->type != OT_NOTHING)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   587
		GetOrder(num - 1)->next = GetOrder(num);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   588
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   589
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   592
static const OldChunks depot_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   593
	OCL_SVAR(   OC_TILE, Depot, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   594
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   595
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   596
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   597
static bool LoadOldDepot(LoadgameState *ls, int num)
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   598
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   599
	if (!AddBlockIfNeeded(&_depot_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   600
		error("Depots: failed loading savegame: too many depots");
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   601
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   602
	if (!LoadChunk(ls, GetDepot(num), depot_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   603
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   604
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   605
	if (GetDepot(num)->xy != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   606
		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   607
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   608
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   609
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   610
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   611
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   612
static int32 _old_price;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   613
static uint16 _old_price_frac;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   614
static const OldChunks price_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   615
	OCL_VAR (  OC_INT32,   1, &_old_price ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   616
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   617
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   618
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   619
static bool LoadOldPrice(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   620
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   621
	if (!LoadChunk(ls, NULL, price_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   622
		return false;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   623
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   624
	/* We use a struct to store the prices, but they are ints in a row..
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   625
	so just access the struct as an array of int32's */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   626
	((int32*)&_price)[num] = _old_price;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   627
	_price_frac[num] = _old_price_frac;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   628
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   629
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   630
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   631
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   632
static const OldChunks cargo_payment_rate_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   633
	OCL_VAR (  OC_INT32,   1, &_old_price ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   634
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   635
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   636
	OCL_NULL( 2 ),         // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   637
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   638
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   639
static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   640
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   641
	if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   642
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   643
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   644
	_cargo_payment_rates[num] = -_old_price;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   645
	_cargo_payment_rates_frac[num] = _old_price_frac;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   646
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   647
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   648
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   649
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   650
static uint8 _old_platforms;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   651
static uint _current_station_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   652
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   653
static const OldChunks goods_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   654
	OCL_SVAR( OC_UINT16, GoodsEntry, waiting_acceptance ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   655
	OCL_SVAR(  OC_UINT8, GoodsEntry, days_since_pickup ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   656
	OCL_SVAR(  OC_UINT8, GoodsEntry, rating ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   657
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, GoodsEntry, enroute_from ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   658
	OCL_SVAR(  OC_UINT8, GoodsEntry, enroute_time ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   659
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   660
	OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   661
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   662
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   663
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   664
static bool LoadOldGood(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   665
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   666
	Station *st = GetStation(_current_station_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   667
	return LoadChunk(ls, &st->goods[num], goods_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   668
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   669
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   670
static const OldChunks station_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   671
	OCL_SVAR(   OC_TILE, Station, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   672
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   673
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   674
	OCL_SVAR(   OC_TILE, Station, bus_tile_obsolete ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   675
	OCL_SVAR(   OC_TILE, Station, lorry_tile_obsolete ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   676
	OCL_SVAR(   OC_TILE, Station, train_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   677
	OCL_SVAR(   OC_TILE, Station, airport_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   678
	OCL_SVAR(   OC_TILE, Station, dock_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   679
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   680
	OCL_VAR (  OC_UINT8,   1, &_old_platforms ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   681
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   682
	OCL_NULL( 1 ),         // sort-index, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   683
	OCL_NULL( 2 ),         // sign-width, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   684
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   685
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   686
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   687
	OCL_NULL( 4 ),         // sign left/top, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   688
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   689
	OCL_SVAR( OC_UINT16, Station, had_vehicle_of_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   690
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   691
	OCL_CHUNK( 12, LoadOldGood ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   692
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   693
	OCL_SVAR(  OC_UINT8, Station, time_since_load ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   694
	OCL_SVAR(  OC_UINT8, Station, time_since_unload ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   695
	OCL_SVAR(  OC_UINT8, Station, delete_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   696
	OCL_SVAR(  OC_UINT8, Station, owner ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   697
	OCL_SVAR(  OC_UINT8, Station, facilities ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   698
	OCL_SVAR(  OC_UINT8, Station, airport_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   699
	OCL_NULL( 2 ),         // Bus/truck status, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   700
	OCL_SVAR(  OC_UINT8, Station, blocked_months_obsolete ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   701
	OCL_NULL( 1 ),         // Unknown
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   702
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Station, airport_flags ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   703
	OCL_SVAR( OC_UINT16, Station, last_vehicle ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   704
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   705
	OCL_NULL( 4 ),         // Junk at end of chunk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   706
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   707
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   708
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   709
static bool LoadOldStation(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   710
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   711
	Station *st;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   712
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   713
	if (!AddBlockIfNeeded(&_station_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   714
		error("Stations: failed loading savegame: too many stations");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   715
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   716
	st = GetStation(num);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   717
	_current_station_id = num;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   718
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   719
	if (!LoadChunk(ls, st, station_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   720
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   721
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   722
	if (st->xy != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   723
		if (st->train_tile) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   724
			/* Calculate the trainst_w and trainst_h */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   725
			int w = (_old_platforms >> 3) & 0x7;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   726
			int h = (_old_platforms & 0x7);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   727
			st->trainst_w = w;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   728
			st->trainst_h = h;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   729
		}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   730
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   731
		st->town    = GetTown(REMAP_TOWN_IDX(_old_town_index));
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   732
		st->string_id = RemapOldStringID(_old_string_id);
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   733
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   734
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   735
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   736
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   737
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   738
static const OldChunks industry_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   739
	OCL_SVAR(   OC_TILE, Industry, xy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   740
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   741
	OCL_SVAR(  OC_UINT8, Industry, width ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   742
	OCL_SVAR(  OC_UINT8, Industry, height ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   743
	OCL_SVAR(  OC_UINT8, Industry, produced_cargo[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   744
	OCL_SVAR(  OC_UINT8, Industry, produced_cargo[1] ),
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   745
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   746
	OCL_SVAR( OC_UINT16, Industry, cargo_waiting[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   747
	OCL_SVAR( OC_UINT16, Industry, cargo_waiting[1] ),
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   748
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   749
	OCL_SVAR(  OC_UINT8, Industry, production_rate[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   750
	OCL_SVAR(  OC_UINT8, Industry, production_rate[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   751
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   752
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   753
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   754
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   755
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   756
	OCL_SVAR(  OC_UINT8, Industry, prod_level ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   757
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   758
	OCL_SVAR( OC_UINT16, Industry, last_mo_production[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   759
	OCL_SVAR( OC_UINT16, Industry, last_mo_production[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   760
	OCL_SVAR( OC_UINT16, Industry, last_mo_transported[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   761
	OCL_SVAR( OC_UINT16, Industry, last_mo_transported[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   762
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   763
	OCL_SVAR(  OC_UINT8, Industry, pct_transported[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   764
	OCL_SVAR(  OC_UINT8, Industry, pct_transported[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   765
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   766
	OCL_SVAR( OC_UINT16, Industry, total_production[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   767
	OCL_SVAR( OC_UINT16, Industry, total_production[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   768
	OCL_SVAR( OC_UINT16, Industry, total_transported[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   769
	OCL_SVAR( OC_UINT16, Industry, total_transported[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   770
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   771
	OCL_SVAR(  OC_UINT8, Industry, type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   772
	OCL_SVAR(  OC_UINT8, Industry, owner ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   773
	OCL_SVAR(  OC_UINT8, Industry, color_map ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   774
	OCL_SVAR(  OC_UINT8, Industry, last_prod_year ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   775
	OCL_SVAR( OC_UINT16, Industry, counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   776
	OCL_SVAR(  OC_UINT8, Industry, was_cargo_delivered ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   777
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   778
	OCL_NULL( 9 ), // Random junk at the end of this chunk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   779
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   780
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   781
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   782
static bool LoadOldIndustry(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   783
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   784
	Industry *i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   785
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   786
	if (!AddBlockIfNeeded(&_industry_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   787
		error("Industries: failed loading savegame: too many industries");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   788
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   789
	i = GetIndustry(num);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   790
	if (!LoadChunk(ls, i, industry_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   791
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   792
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   793
	if (i->xy != 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   794
		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   795
	}
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   796
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   797
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   798
}
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   799
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   800
static uint _current_player_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   801
static uint16 _old_inaugurated_year;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   802
static int32 _old_yearly;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   803
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   804
static const OldChunks player_yearly_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   805
	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   806
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   807
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   808
static bool OldPlayerYearly(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   809
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   810
	int i;
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   811
	Player *p = GetPlayer(_current_player_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   812
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   813
	for (i = 0; i < 13; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   814
		if (!LoadChunk(ls, NULL, player_yearly_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   815
			return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   816
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   817
		p->yearly_expenses[num][i] = _old_yearly;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   818
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   819
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   820
	return true;
436
02955496f740 (svn r645) -Feature: Finally support for TTDLX games on Big Endian machines such as Macintosh and MorphOS; thanks for testing Bjarni :)
darkvater
parents: 410
diff changeset
   821
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   823
static const OldChunks player_economy_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   824
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, income ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   825
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, expenses ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   826
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, delivered_cargo ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   827
	OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   828
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   829
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   830
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   831
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   832
static bool OldPlayerEconomy(LoadgameState *ls, int num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
{
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   834
	int i;
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   835
	Player *p = GetPlayer(_current_player_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   836
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   837
	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   838
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   839
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   840
	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   841
	p->cur_economy.income   = -p->cur_economy.income;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   842
	p->cur_economy.expenses = -p->cur_economy.expenses;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   843
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   844
	for (i = 0; i < 24; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   845
		if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   846
			return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   847
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   848
		p->old_economy[i].income   = -p->old_economy[i].income;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   849
		p->old_economy[i].expenses = -p->old_economy[i].expenses;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   850
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   851
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   852
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   853
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   854
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   855
static const OldChunks player_ai_build_rec_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   856
	OCL_SVAR(   OC_TILE, AiBuildRec, spec_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   857
	OCL_SVAR(   OC_TILE, AiBuildRec, use_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   858
	OCL_SVAR(  OC_UINT8, AiBuildRec, rand_rng ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   859
	OCL_SVAR(  OC_UINT8, AiBuildRec, cur_building_rule ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   860
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk6 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   861
	OCL_SVAR(  OC_UINT8, AiBuildRec, unk7 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   862
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   863
	OCL_SVAR(  OC_UINT8, AiBuildRec, buildcmd_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   864
	OCL_SVAR(  OC_UINT8, AiBuildRec, direction ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   865
	OCL_SVAR(  OC_UINT8, AiBuildRec, cargo ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   866
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   867
	OCL_NULL( 8 ),  // Junk...
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   868
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   869
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   870
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   871
static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   872
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   873
	Player *p = GetPlayer(_current_player_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   874
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   875
	switch (num) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   876
		case 0: return LoadChunk(ls, &p->ai.src, player_ai_build_rec_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   877
		case 1: return LoadChunk(ls, &p->ai.dst, player_ai_build_rec_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   878
		case 2: return LoadChunk(ls, &p->ai.mid1, player_ai_build_rec_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   879
		case 3: return LoadChunk(ls, &p->ai.mid2, player_ai_build_rec_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   880
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   881
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   882
	return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   883
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   884
static const OldChunks player_ai_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   885
	OCL_SVAR(  OC_UINT8, PlayerAI, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   886
	OCL_NULL( 1 ),         // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   887
	OCL_SVAR(  OC_UINT8, PlayerAI, state_mode ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   888
	OCL_SVAR( OC_UINT16, PlayerAI, state_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   889
	OCL_SVAR( OC_UINT16, PlayerAI, timeout_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   890
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   891
	OCL_CHUNK( 4, OldLoadAIBuildRec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   892
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   893
	OCL_NULL( 20 ),        // More junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   894
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   895
	OCL_SVAR(  OC_UINT8, PlayerAI, cargo_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   896
	OCL_SVAR(  OC_UINT8, PlayerAI, num_wagons ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   897
	OCL_SVAR(  OC_UINT8, PlayerAI, build_kind ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   898
	OCL_SVAR(  OC_UINT8, PlayerAI, num_build_rec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   899
	OCL_SVAR(  OC_UINT8, PlayerAI, num_loco_to_build ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   900
	OCL_SVAR(  OC_UINT8, PlayerAI, num_want_fullload ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   901
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   902
	OCL_NULL( 14 ),        // Oh no more junk :|
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   903
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   904
	OCL_NULL( 2 ),         // Loco-id, not used
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   905
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   906
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   907
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   908
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   909
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   910
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   911
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   912
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   913
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[7] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   914
	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[8] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   915
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   916
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   917
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   918
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   919
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   920
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   921
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   922
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[7] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   923
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[8] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   924
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[9] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   925
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[10] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   926
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[11] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   927
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[12] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   928
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[13] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   929
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[14] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   930
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[15] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   931
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[16] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   932
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[17] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   933
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[18] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   934
	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[19] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   935
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   936
	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   937
	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   938
	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   939
	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   940
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   941
	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   942
	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   943
	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_a ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   944
	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_b ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   945
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   946
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_tile_count ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   947
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   948
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   949
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   950
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   951
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   952
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   953
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   954
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   955
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   956
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   957
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[4] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   958
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   959
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[5] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   960
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   961
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[6] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   962
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[7] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   963
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[7] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   964
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[8] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   965
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[8] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   966
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[9] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   967
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[9] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   968
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[10] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   969
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[10] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   970
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[11] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   971
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[11] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   972
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[12] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   973
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[12] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   974
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[13] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   975
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[13] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   976
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[14] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   977
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[14] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   978
	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[15] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   979
	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[15] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   980
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   981
	OCL_SVAR(  OC_UINT8, PlayerAI, railtype_to_use ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   982
	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   983
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   984
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   985
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   986
static bool OldPlayerAI(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   987
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   988
	Player *p = GetPlayer(_current_player_id);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   989
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   990
	return LoadChunk(ls, &p->ai, player_ai_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   991
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   992
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   993
static const OldChunks player_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   994
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   995
	OCL_SVAR( OC_UINT32, Player, name_2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   996
	OCL_SVAR( OC_UINT32, Player, face ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   997
	OCL_VAR ( OC_UINT16,   1, &_old_string_id_2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   998
	OCL_SVAR( OC_UINT32, Player, president_name_2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
   999
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1000
	OCL_SVAR(  OC_INT32, Player, player_money ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1001
	OCL_SVAR(  OC_INT32, Player, current_loan ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1002
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1003
	OCL_SVAR(  OC_UINT8, Player, player_color ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1004
	OCL_SVAR(  OC_UINT8, Player, player_money_fraction ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1005
	OCL_SVAR(  OC_UINT8, Player, quarters_of_bankrupcy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1006
	OCL_SVAR(  OC_UINT8, Player, bankrupt_asked ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1007
	OCL_SVAR( OC_UINT32, Player, bankrupt_value ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1008
	OCL_SVAR( OC_UINT16, Player, bankrupt_timeout ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1009
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1010
	OCL_SVAR( OC_FILE_U32 | OC_VAR_U16, Player, cargo_types ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1011
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1012
	OCL_CHUNK( 3, OldPlayerYearly ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1013
	OCL_CHUNK( 1, OldPlayerEconomy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1014
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1015
	OCL_VAR ( OC_UINT16,   1,    &_old_inaugurated_year ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1016
	OCL_SVAR(   OC_TILE, Player, last_build_coordinate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1017
	OCL_SVAR(  OC_UINT8, Player, num_valid_stat_ent ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1018
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1019
	OCL_CHUNK( 1, OldPlayerAI ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1020
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1021
	OCL_SVAR(  OC_UINT8, Player, block_preview ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1022
	OCL_SVAR(  OC_UINT8, Player, ai.tick ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1023
	OCL_SVAR(  OC_UINT8, Player, max_railtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1024
	OCL_SVAR(   OC_TILE, Player, location_of_house ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1025
	OCL_SVAR(  OC_UINT8, Player, share_owners[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1026
	OCL_SVAR(  OC_UINT8, Player, share_owners[1] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1027
	OCL_SVAR(  OC_UINT8, Player, share_owners[2] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1028
	OCL_SVAR(  OC_UINT8, Player, share_owners[3] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1029
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1030
	OCL_NULL( 8 ), // junk at end of chunk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1031
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1032
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1033
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1034
static bool LoadOldPlayer(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1035
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
  1036
	Player *p = GetPlayer(num);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1037
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1038
	_current_player_id = num;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1039
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1040
	if (!LoadChunk(ls, p, player_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1041
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1042
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1043
	p->name_1 = RemapOldStringID(_old_string_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1044
	p->president_name_1 = RemapOldStringID(_old_string_id_2);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1045
	p->money64 = p->player_money;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1046
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1047
	if (num == 0) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1048
		/* If the first player has no name, make sure we call it UNNAMED */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1049
		if (p->name_1 == 0)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1050
			p->name_1 = STR_SV_UNNAMED;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1051
	} else {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1052
		/* Beside some multiplayer maps (1 on 1), which we don't official support,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1053
		all other players are an AI.. mark them as such */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1054
		p->is_ai = 1;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1055
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1056
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1057
	/* Sometimes it is better to not ask.. in old scenarios, the money
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1058
	was always 893288 pounds. In the newer versions this is correct,
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1059
	but correct for those oldies
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1060
	Ps: this also means that if you had exact 893288 pounds, you will go back
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1061
	to 10000.. this is a very VERY small chance ;) */
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1062
	if (p->player_money == 893288)
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1063
		p->money64 = p->player_money = p->current_loan = 100000;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1064
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1065
	_player_colors[num] = p->player_color;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1066
	p->inaugurated_year = _old_inaugurated_year - MAX_YEAR_BEGIN_REAL;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1067
	if (p->location_of_house == 0xFFFF)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1068
		p->location_of_house = 0;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1069
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1070
	/* State 20 for AI players is sell vehicle. Since the AI struct is not
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1071
	 * really figured out as of now, p->ai.cur_veh; needed for 'sell vehicle'
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1072
	 * is NULL and the function will crash. To fix this, just change the state
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1073
	 * to some harmless state, like 'loop vehicle'; 1 */
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1074
	if (!IS_HUMAN_PLAYER(num) && p->ai.state == 20) p->ai.state = 1;
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1075
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1076
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1077
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1078
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1079
static uint32 _old_order_ptr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1080
static uint16 _old_next_ptr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1081
static uint32 _current_vehicle_id;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1082
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1083
static const OldChunks vehicle_train_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1084
	OCL_SVAR(  OC_UINT8, VehicleRail, track ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1085
	OCL_SVAR(  OC_UINT8, VehicleRail, force_proceed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1086
	OCL_SVAR( OC_UINT16, VehicleRail, crash_anim_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1087
	OCL_SVAR(  OC_UINT8, VehicleRail, railtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1088
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1089
	OCL_NULL( 5 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1090
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1091
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1092
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1093
static const OldChunks vehicle_road_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1094
	OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1095
	OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1096
	OCL_SVAR( OC_UINT16, VehicleRoad, unk2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1097
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1098
	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1099
	OCL_SVAR( OC_UINT16, VehicleRoad, crashed_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1100
	OCL_SVAR(  OC_UINT8, VehicleRoad, reverse_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1101
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1102
	OCL_NULL( 1 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1103
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1104
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1105
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1106
static const OldChunks vehicle_ship_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1107
	OCL_SVAR(  OC_UINT8, VehicleShip, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1108
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1109
	OCL_NULL( 9 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1110
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1111
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1112
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1113
static const OldChunks vehicle_air_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1114
	OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1115
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1116
	OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1117
	OCL_SVAR(  OC_UINT8, VehicleAir, state ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1118
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1119
	OCL_NULL( 5 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1120
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1121
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1122
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1123
static const OldChunks vehicle_special_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1124
	OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1125
	OCL_SVAR(  OC_UINT8, VehicleSpecial, unk2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1126
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1127
	OCL_NULL( 7 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1128
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1129
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1130
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1131
static const OldChunks vehicle_disaster_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1132
	OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1133
	OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1134
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1135
	OCL_NULL( 6 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1136
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1137
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1138
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1139
static const OldChunks vehicle_empty_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1140
	OCL_NULL( 10 ), // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1141
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1142
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1143
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1144
static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1145
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1146
	Vehicle *v = GetVehicle(_current_vehicle_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1147
	uint temp = ls->total_read;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1148
	bool res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1149
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1150
	switch (v->type) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1151
		case VEH_Train:    res = LoadChunk(ls, &v->u.rail,     vehicle_train_chunk);    break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1152
		case VEH_Road:     res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1153
		case VEH_Ship:     res = LoadChunk(ls, &v->u.ship,     vehicle_ship_chunk);     break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1154
		case VEH_Aircraft: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1155
		case VEH_Special:  res = LoadChunk(ls, &v->u.special,  vehicle_special_chunk);  break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1156
		case VEH_Disaster: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1157
		default:           res = LoadChunk(ls, NULL,           vehicle_empty_chunk);    break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1158
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1159
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1160
	/* This chunk size should always be 10 bytes */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1161
	if (ls->total_read - temp != 10) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1162
		DEBUG(oldloader, 4)("[OldLoader] Assert failed in Vehicle");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1163
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1164
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1165
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1166
	return res;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1167
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1168
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1169
static const OldChunks vehicle_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1170
	OCL_SVAR(  OC_UINT8, Vehicle, type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1171
	OCL_SVAR(  OC_UINT8, Vehicle, subtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1172
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1173
	OCL_NULL( 2 ),         // Hash, calculated automatically
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1174
	OCL_NULL( 2 ),         // Index, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1175
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1176
	OCL_VAR ( OC_UINT32,   1, &_old_order_ptr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1177
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1178
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1179
	OCL_SVAR(  OC_UINT8, Vehicle, num_orders ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1180
	OCL_SVAR(  OC_UINT8, Vehicle, cur_order_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1181
	OCL_SVAR(   OC_TILE, Vehicle, dest_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1182
	OCL_SVAR( OC_UINT16, Vehicle, load_unload_time_rem ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1183
	OCL_SVAR( OC_UINT16, Vehicle, date_of_last_service ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1184
	OCL_SVAR( OC_UINT16, Vehicle, service_interval ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1185
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, last_station_visited ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1186
	OCL_SVAR(  OC_UINT8, Vehicle, tick_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1187
	OCL_SVAR( OC_UINT16, Vehicle, max_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1188
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1189
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, x_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1190
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Vehicle, y_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1191
	OCL_SVAR(  OC_UINT8, Vehicle, z_pos ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1192
	OCL_SVAR(  OC_UINT8, Vehicle, direction ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1193
	OCL_SVAR(   OC_INT8, Vehicle, x_offs ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1194
	OCL_SVAR(   OC_INT8, Vehicle, y_offs ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1195
	OCL_SVAR(  OC_UINT8, Vehicle, sprite_width ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1196
	OCL_SVAR(  OC_UINT8, Vehicle, sprite_height ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1197
	OCL_SVAR(  OC_UINT8, Vehicle, z_height ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1198
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1199
	OCL_SVAR(  OC_UINT8, Vehicle, owner ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1200
	OCL_SVAR(   OC_TILE, Vehicle, tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1201
	OCL_SVAR( OC_UINT16, Vehicle, cur_image ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1202
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1203
	OCL_NULL( 8 ),        // Vehicle sprite box, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1204
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1205
	OCL_SVAR( OC_FILE_U16 | OC_VAR_U8, Vehicle, vehstatus ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1206
	OCL_SVAR( OC_UINT16, Vehicle, cur_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1207
	OCL_SVAR(  OC_UINT8, Vehicle, subspeed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1208
	OCL_SVAR(  OC_UINT8, Vehicle, acceleration ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1209
	OCL_SVAR(  OC_UINT8, Vehicle, progress ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1210
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1211
	OCL_SVAR(  OC_UINT8, Vehicle, cargo_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1212
	OCL_SVAR( OC_UINT16, Vehicle, cargo_cap ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1213
	OCL_SVAR( OC_UINT16, Vehicle, cargo_count ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1214
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, cargo_source ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1215
	OCL_SVAR(  OC_UINT8, Vehicle, cargo_days ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1216
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1217
	OCL_SVAR( OC_UINT16, Vehicle, age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1218
	OCL_SVAR( OC_UINT16, Vehicle, max_age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1219
	OCL_SVAR(  OC_UINT8, Vehicle, build_year ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1220
	OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Vehicle, unitnumber ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1221
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1222
	OCL_SVAR( OC_UINT16, Vehicle, engine_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1223
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1224
	OCL_SVAR(  OC_UINT8, Vehicle, spritenum ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1225
	OCL_SVAR(  OC_UINT8, Vehicle, day_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1226
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1227
	OCL_SVAR(  OC_UINT8, Vehicle, breakdowns_since_last_service ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1228
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1229
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_delay ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1230
	OCL_SVAR(  OC_UINT8, Vehicle, breakdown_chance ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1231
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1232
	OCL_SVAR( OC_UINT16, Vehicle, reliability ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1233
	OCL_SVAR( OC_UINT16, Vehicle, reliability_spd_dec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1234
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1235
	OCL_SVAR(  OC_INT32, Vehicle, profit_this_year ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1236
	OCL_SVAR(  OC_INT32, Vehicle, profit_last_year ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1237
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1238
	OCL_VAR ( OC_UINT16,   1, &_old_next_ptr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1239
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1240
	OCL_SVAR( OC_UINT32, Vehicle, value ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1241
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1242
	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1243
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1244
	OCL_CHUNK( 1, LoadOldVehicleUnion ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1245
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1246
	OCL_NULL( 20 ), // Junk at end of struct (TTDPatch has some data in it)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1247
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1248
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1249
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1250
static bool LoadOldVehicle(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1251
{
959
e6a3bbda610f (svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents: 923
diff changeset
  1252
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1254
	/* Read the TTDPatch flags, because we need some info from it */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1255
	ReadTTDPatchFlags();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1257
	for (i = 0; i < _old_vehicle_multipler; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1258
		Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1260
		_current_vehicle_id = num * _old_vehicle_multipler + i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1261
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1262
		if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1263
			error("Vehicles: failed loading savegame: too many vehicles");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1264
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1265
		v = GetVehicle(_current_vehicle_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1266
		if (!LoadChunk(ls, v, vehicle_chunk))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1267
			return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1268
1340
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1269
		/* This should be consistent, else we have a big problem... */
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1270
		if (v->index != _current_vehicle_id) {
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1271
			DEBUG(oldloader, 0)("[OldLoader] -- Loading failed - vehicle-array is invalid");
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1272
			return false;
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1273
		}
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1274
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1275
		if (_old_order_ptr != 0 && _old_order_ptr != 0xFFFFFFFF) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1276
			v->orders = GetOrder(REMAP_ORDER_IDX(_old_order_ptr));
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1277
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1278
		AssignOrder(&v->current_order, UnpackOldOrder(_old_order));
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1279
		/* TTDPatch maps sprites from 0x2000 up. */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1280
		if (v->cur_image >= 0x2000)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1281
			v->cur_image -= 0x2000 - _custom_sprites_base;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1282
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1283
		/* For some reason we need to correct for this */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1284
		switch (v->spritenum) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1285
			case 0xfd: break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1286
			case 0xff: v->spritenum = 0xfe; break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1287
			default:   v->spritenum >>= 1; break;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1288
		}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1289
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1290
		if (_old_next_ptr != 0xFFFF)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1291
			v->next = GetVehicle(_old_next_ptr);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1292
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1293
		v->string_id = RemapOldStringID(_old_string_id);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1294
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1295
		/* Vehicle-subtype is different in TTD(Patch) */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1296
		if (v->type == VEH_Special)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1297
			v->subtype = v->subtype >> 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1300
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1301
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1302
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1303
static const OldChunks sign_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1304
	OCL_SVAR( OC_UINT16, SignStruct, str ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1305
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,SignStruct, x ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1306
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32,SignStruct, y ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1307
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I8, SignStruct, z ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1308
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1309
	OCL_NULL( 6 ),         // Width of sign, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1310
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1311
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1312
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1313
static bool LoadOldSign(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1314
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1315
	if (!AddBlockIfNeeded(&_sign_pool, num))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1316
		error("Signs: failed loading savegame: too many signs");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1317
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1318
	return LoadChunk(ls, GetSign(num), sign_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1319
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1320
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1321
static const OldChunks engine_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1322
	OCL_SVAR( OC_UINT16, Engine, player_avail ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1323
	OCL_SVAR( OC_UINT16, Engine, intro_date ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1324
	OCL_SVAR( OC_UINT16, Engine, age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1325
	OCL_SVAR( OC_UINT16, Engine, reliability ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1326
	OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1327
	OCL_SVAR( OC_UINT16, Engine, reliability_start ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1328
	OCL_SVAR( OC_UINT16, Engine, reliability_max ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1329
	OCL_SVAR( OC_UINT16, Engine, reliability_final ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1330
	OCL_SVAR( OC_UINT16, Engine, duration_phase_1 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1331
	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1332
	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1333
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1334
	OCL_SVAR(  OC_UINT8, Engine, lifelength ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1335
	OCL_SVAR(  OC_UINT8, Engine, flags ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1336
	OCL_SVAR(  OC_UINT8, Engine, preview_player ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1337
	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1338
	OCL_SVAR(  OC_UINT8, Engine, railtype ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1339
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1340
	OCL_NULL( 1 ),         // Junk
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1341
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1342
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1343
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1344
static bool LoadOldEngine(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1345
{
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1891
diff changeset
  1346
	if (!LoadChunk(ls, GetEngine(num), engine_chunk))
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1347
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1348
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1349
	/* Make sure wagons are marked as do-not-age */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1350
	if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116))
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1891
diff changeset
  1351
		GetEngine(num)->age = 0xFFFF;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1352
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1353
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1354
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1355
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1356
static const OldChunks subsidy_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1357
	OCL_SVAR(  OC_UINT8, Subsidy, cargo_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1358
	OCL_SVAR(  OC_UINT8, Subsidy, age ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1359
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1360
	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1361
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1362
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1363
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1364
static bool LoadOldSubsidy(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1365
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1366
	return LoadChunk(ls, &_subsidies[num], subsidy_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1367
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1368
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1369
static const OldChunks game_difficulty_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1370
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, max_no_competitors ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1371
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, competitor_start_time ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1372
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, number_towns ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1373
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, number_industries ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1374
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, max_loan ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1375
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, initial_interest ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1376
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, vehicle_costs ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1377
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, competitor_speed ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1378
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, competitor_intelligence ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1379
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, vehicle_breakdowns ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1380
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, subsidy_multiplier ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1381
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, construction_cost ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1382
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, terrain_type ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1383
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, quantity_sea_lakes ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1384
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, economy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1385
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, line_reverse_mode ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1386
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, disasters ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1387
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1388
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1389
static bool LoadOldGameDifficulty(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1390
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1391
	return LoadChunk(ls, &_opt.diff, game_difficulty_chunk);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1392
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1393
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1394
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1395
static bool LoadOldMapPart1(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1396
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1397
	uint i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1398
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1399
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1400
		_m[i].owner = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1401
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1402
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1403
		_m[i].m2 = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1404
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1405
	for (i = 0; i < OLD_MAP_SIZE; i++) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1406
		_old_map3[i * 2] = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1407
		_old_map3[i * 2 + 1] = ReadByte(ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1408
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1409
	for (i = 0; i < OLD_MAP_SIZE / 4; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1410
		byte b = ReadByte(ls);
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1411
		_m[i * 4 + 0].extra = GB(b, 0, 2);
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1412
		_m[i * 4 + 1].extra = GB(b, 2, 2);
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1413
		_m[i * 4 + 2].extra = GB(b, 4, 2);
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1414
		_m[i * 4 + 3].extra = GB(b, 6, 2);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1415
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1416
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1417
	return !ls->failed;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1418
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1419
static bool LoadOldMapPart2(LoadgameState *ls, int num)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1420
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1421
	uint i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1422
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1423
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1424
		_m[i].type_height = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1425
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1426
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1427
		_m[i].m5 = ReadByte(ls);
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1428
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1429
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1430
	return !ls->failed;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1431
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1432
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1433
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1434
static uint32 _old_cur_town_ctr;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1435
static const OldChunks main_chunk[] = {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1436
	OCL_ASSERT( 0 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1437
	OCL_VAR ( OC_UINT16,   1, &_date ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1438
	OCL_VAR ( OC_UINT16,   1, &_date_fract ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1439
	OCL_NULL( 600 ),            // TextEffects
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1440
	OCL_VAR ( OC_UINT32,   2, &_random_seeds[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1441
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1442
	OCL_ASSERT( 0x264 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1443
	OCL_CHUNK(  70, LoadOldTown ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1444
	OCL_ASSERT( 0x1C18 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1445
	OCL_CHUNK(5000, LoadOldOrder ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1446
	OCL_ASSERT( 0x4328 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1447
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1448
	OCL_VAR (   OC_TILE, 256, &_animated_tile_list[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1449
	OCL_NULL( 4 ),              // old end-of-order-list-pointer, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1450
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1451
	OCL_CHUNK( 255, LoadOldDepot ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1452
	OCL_ASSERT( 0x4B26 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1453
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1454
	OCL_VAR ( OC_UINT32,   1, &_old_cur_town_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1455
	OCL_NULL( 2 ),              // timer_counter, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1456
	OCL_NULL( 2 ),              // land_code,     no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1457
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1458
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1459
	OCL_VAR ( OC_UINT16,   1, &_tick_counter ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1460
	OCL_VAR (   OC_TILE,   1, &_cur_tileloop_tile ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1461
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1462
	OCL_CHUNK( 49, LoadOldPrice ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1463
	OCL_CHUNK( 12, LoadOldCargoPaymentRate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1464
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1465
	OCL_ASSERT( 0x4CBA ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1466
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1467
	OCL_CHUNK( 1, LoadOldMapPart1 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1468
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1469
	OCL_ASSERT( 0x48CBA ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1470
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1471
	OCL_CHUNK(250, LoadOldStation ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1472
	OCL_CHUNK( 90, LoadOldIndustry ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1473
	OCL_CHUNK(  8, LoadOldPlayer ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1474
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1475
	OCL_ASSERT( 0x547F2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1476
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1477
	OCL_CHUNK( 850, LoadOldVehicle ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1478
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1479
	OCL_ASSERT( 0x6F0F2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1480
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1481
	OCL_VAR (  OC_UINT8, 32 * 500, &_name_array[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1482
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1483
	OCL_NULL( 0x2000 ),            // Old hash-table, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1484
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1485
	OCL_CHUNK( 40, LoadOldSign ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1486
	OCL_CHUNK(256, LoadOldEngine ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1487
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1488
	OCL_VAR ( OC_UINT16,    1, &_vehicle_id_ctr_day ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1489
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1490
	OCL_CHUNK(  8, LoadOldSubsidy ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1491
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1492
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,   1, &_next_competitor_start ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1493
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_x ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1494
	OCL_VAR ( OC_FILE_I16 | OC_VAR_I32,   1, &_saved_scrollpos_y ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1495
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8,    1, &_saved_scrollpos_zoom ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1496
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1497
	OCL_VAR ( OC_UINT32,    1, &_economy.max_loan ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1498
	OCL_VAR ( OC_UINT32,    1, &_economy.max_loan_unround ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1499
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32,    1, &_economy.fluct ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1500
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1501
	OCL_VAR ( OC_UINT16,    1, &_disaster_delay ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1502
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1503
	OCL_NULL( 144 ),             // cargo-stuff, calculated in InitializeLandscapeVariables
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1504
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1505
	OCL_VAR ( OC_UINT16,  256, &_engine_name_strings[0] ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1506
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1507
	OCL_NULL( 144 ),             // AI cargo-stuff, calculated in InitializeLandscapeVariables
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1508
	OCL_NULL( 2 ),               // Company indexes of players, no longer in use
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1509
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1510
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1511
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1512
	OCL_VAR (  OC_UINT8,    1, &_opt.currency ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1513
	OCL_VAR (  OC_UINT8,    1, &_opt.kilometers ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1514
	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_player_tick_index ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1515
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1516
	OCL_NULL( 2 ),               // Date stuff, calculated automatically
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1517
	OCL_NULL( 8 ),               // Player colors, calculated automatically
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1518
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1519
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1520
	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount_pr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1521
	OCL_VAR (  OC_UINT8,    1, &_economy.interest_rate ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1522
	OCL_VAR (  OC_UINT8,    1, &_avail_aircraft ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1523
	OCL_VAR (  OC_UINT8,    1, &_opt.road_side ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1524
	OCL_VAR (  OC_UINT8,    1, &_opt.town_name ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1525
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1526
	OCL_CHUNK( 1, LoadOldGameDifficulty ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1527
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1528
	OCL_ASSERT( 0x77130 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1529
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1530
	OCL_VAR (  OC_UINT8,    1, &_opt.diff_level ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1531
	OCL_VAR (  OC_UINT8,    1, &_opt.landscape ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1532
	OCL_VAR (  OC_UINT8,    1, &_trees_tick_ctr ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1533
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1534
	OCL_NULL( 1 ),               // Custom vehicle types yes/no, no longer used
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1535
	OCL_VAR (  OC_UINT8,    1, &_opt.snow_line ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1536
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1537
	OCL_NULL( 32 ),              // new_industry_randtable, no longer used (because of new design)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1538
	OCL_NULL( 36 ),              // cargo-stuff, calculated in InitializeLandscapeVariables
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1539
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1540
	OCL_ASSERT( 0x77179 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1541
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1542
	OCL_CHUNK( 1, LoadOldMapPart2 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1543
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1544
	OCL_ASSERT( 0x97179 ),
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1545
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1546
	/* Below any (if available) extra chunks from TTDPatch can follow */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1547
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1548
	OCL_END()
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1549
};
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1550
static bool LoadOldMain(LoadgameState *ls)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1551
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1552
	int i;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1553
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1554
	/* The first 49 is the name of the game + checksum, skip it */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1555
	fseek(ls->file, HEADER_SIZE, SEEK_SET);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1556
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1557
	DEBUG(oldloader, 4)("[OldLoader] Going to read main chunk..");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1558
	/* Load the biggest chunk */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1559
	if (!LoadChunk(&_ls, NULL, main_chunk)) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1560
		DEBUG(oldloader, 0)("[OldLoader] Loading failed!");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1561
		return false;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1562
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1563
	DEBUG(oldloader, 4)("[OldLoader] Done. Converting stuff..");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1564
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1565
	/* Fix some general stuff */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1566
	_opt.landscape = _opt.landscape & 0xF;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1567
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1568
	/* Remap some pointers */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1569
	_cur_town_ctr      = REMAP_TOWN_IDX(_old_cur_town_ctr);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1570
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1571
	/* _old_map3 is changed in _map3_lo and _map3_hi */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1572
	for (i = 0; i < OLD_MAP_SIZE; i++) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1573
		_m[i].m3 = _old_map3[i * 2];
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1574
		_m[i].m4 = _old_map3[i * 2 + 1];
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1575
	}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1576
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1577
	for (i = 0; i < OLD_MAP_SIZE; i ++) {
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1578
		if (IsTileType(i, MP_RAILWAY)) {
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1579
			/* We save presignals different from TTDPatch, convert them */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1580
			if ((_m[i].m5 & 0xC0) == 0x40) {
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1581
				/* This byte is always zero in TTD for this type of tile */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1582
				if (_m[i].m4) /* Convert the presignals to our own format */
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1583
					_m[i].m4 = (_m[i].m4 >> 1) & 7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
			}
2019
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1585
			/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
9cbdcd40386c (svn r2528) - Fix: TTDPatch games had garbage in _map3[hi]&0xF0 which interfered with OpenTTD PBS functionality; fixed in oldloader
Darkvater
parents: 1962
diff changeset
  1586
			* clear it for ourselves and let OTTD's rebuild PBS itself */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2019
diff changeset
  1587
			_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1591
	/* Fix the game to be compatible with OpenTTD */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1592
	FixOldTowns();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1593
	FixOldStations();
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1594
	FixOldVehicles();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1596
	AddTypeToEngines();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1598
	/* We have a new difficulty setting */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1599
	_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
  1600
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1601
	DEBUG(oldloader, 4)("[OldLoader] Done!");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1602
	DEBUG(oldloader, 1)("[OldLoader] TTD(Patch) savegame successfully converted");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1604
	return true;
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1605
}
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1606
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1607
bool LoadOldSaveGame(const char *file)
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1608
{
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1609
	DEBUG(oldloader, 4)("[OldLoader] Trying to load an TTD(Patch) savegame");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1610
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1611
	InitLoading(&_ls);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1612
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1613
	/* Open file */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1614
	_ls.file = fopen(file, "rb");
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1615
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1616
	if (_ls.file == NULL) {
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1617
		DEBUG(oldloader, 0)("[OldLoader] Could not open file %s", file);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1618
		return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1621
	/* Load the main chunk */
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1622
	if (!LoadOldMain(&_ls))
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1623
		return false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 123
diff changeset
  1624
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1625
	fclose(_ls.file);
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1626
1340
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1627
	_pause = 2;
efd001622906 (svn r1844) -Fix: small protection in oldloader.c, and put the savegame on pause by default
truelight
parents: 1328
diff changeset
  1628
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
void GetOldSaveGameName(char *title, const char *file)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	FILE *f;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	f = fopen(file, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	title[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	title[48] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
1326
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1640
	if (f == NULL)
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1641
		return;
7f8452ae2f65 (svn r1830) -Codechange: small stuff to make the file more beautiful (tnx Tron)
truelight
parents: 1325
diff changeset
  1642
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1643
	if (fread(title, 1, 48, f) != 48)
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2090
diff changeset
  1644
		snprintf(title, 48, "Corrupt file");
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1314
diff changeset
  1645
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
	fclose(f);
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
void GetOldScenarioGameName(char *title, const char *file)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	GetOldSaveGameName(title, file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
}