00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef OLDLOADER_H
00013 #define OLDLOADER_H
00014
00015 #include "saveload.h"
00016 #include "../tile_type.h"
00017
00018 static const uint BUFFER_SIZE = 4096;
00019 static const uint OLD_MAP_SIZE = 256 * 256;
00020
00021 struct LoadgameState {
00022 FILE *file;
00023
00024 uint chunk_size;
00025
00026 bool decoding;
00027 byte decode_char;
00028
00029 uint buffer_count;
00030 uint buffer_cur;
00031 byte buffer[BUFFER_SIZE];
00032
00033 uint total_read;
00034 };
00035
00036
00037 enum OldChunkType {
00038 OC_SIMPLE = 0,
00039 OC_NULL = 1,
00040 OC_CHUNK = 2,
00041 OC_ASSERT = 3,
00042
00043
00044 OC_TTD = 1 << 4,
00045 OC_TTO = 1 << 5,
00046
00047
00048 OC_VAR_I8 = 1 << 8,
00049 OC_VAR_U8 = 2 << 8,
00050 OC_VAR_I16 = 3 << 8,
00051 OC_VAR_U16 = 4 << 8,
00052 OC_VAR_I32 = 5 << 8,
00053 OC_VAR_U32 = 6 << 8,
00054 OC_VAR_I64 = 7 << 8,
00055 OC_VAR_U64 = 8 << 8,
00056
00057
00058 OC_FILE_I8 = 1 << 16,
00059 OC_FILE_U8 = 2 << 16,
00060 OC_FILE_I16 = 3 << 16,
00061 OC_FILE_U16 = 4 << 16,
00062 OC_FILE_I32 = 5 << 16,
00063 OC_FILE_U32 = 6 << 16,
00064
00065
00066 OC_INT8 = OC_VAR_I8 | OC_FILE_I8,
00067 OC_UINT8 = OC_VAR_U8 | OC_FILE_U8,
00068 OC_INT16 = OC_VAR_I16 | OC_FILE_I16,
00069 OC_UINT16 = OC_VAR_U16 | OC_FILE_U16,
00070 OC_INT32 = OC_VAR_I32 | OC_FILE_I32,
00071 OC_UINT32 = OC_VAR_U32 | OC_FILE_U32,
00072
00073 OC_TILE = OC_VAR_U32 | OC_FILE_U16,
00074
00079 OC_DEREFERENCE_POINTER = 1 << 31,
00080
00081 OC_END = 0,
00082 };
00083
00084 DECLARE_ENUM_AS_BIT_SET(OldChunkType)
00085
00086 typedef bool OldChunkProc(LoadgameState *ls, int num);
00087
00088 struct OldChunks {
00089 OldChunkType type;
00090 uint32 amount;
00091
00092 void *ptr;
00093 uint offset;
00094 OldChunkProc *proc;
00095 };
00096
00097
00098 assert_compile(sizeof(TileIndex) == 4);
00099
00100 extern uint _bump_assert_value;
00101 byte ReadByte(LoadgameState *ls);
00102 bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks);
00103
00104 bool LoadTTDMain(LoadgameState *ls);
00105 bool LoadTTOMain(LoadgameState *ls);
00106
00107 static inline uint16 ReadUint16(LoadgameState *ls)
00108 {
00109 byte x = ReadByte(ls);
00110 return x | ReadByte(ls) << 8;
00111 }
00112
00113 static inline uint32 ReadUint32(LoadgameState *ls)
00114 {
00115 uint16 x = ReadUint16(ls);
00116 return x | ReadUint16(ls) << 16;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #define OCL_SVAR(type, base, offset) { type, 1, NULL, (uint)cpp_offsetof(base, offset), NULL }
00129 #define OCL_VAR(type, amount, pointer) { type, amount, pointer, 0, NULL }
00130 #define OCL_END() { OC_END, 0, NULL, 0, NULL }
00131 #define OCL_CNULL(type, amount) { OC_NULL | type, amount, NULL, 0, NULL }
00132 #define OCL_CCHUNK(type, amount, proc) { OC_CHUNK | type, amount, NULL, 0, proc }
00133 #define OCL_ASSERT(type, size) { OC_ASSERT | type, 1, NULL, size, NULL }
00134 #define OCL_NULL(amount) OCL_CNULL((OldChunkType)0, amount)
00135 #define OCL_CHUNK(amount, proc) OCL_CCHUNK((OldChunkType)0, amount, proc)
00136
00137 #endif