4 -----------------------------------
5 MAPWRITER.PAS ÂÅÐÑÈß ÎÒ 24.09.06
7 Ïîääåðæêà êàðò âåðñèè 1
8 -----------------------------------
17 TDataBlock
= packed record
22 TDataBlocksArray
= packed array of TDataBlock
;
24 TMapWriter
= class(TObject
)
26 FDataBlocks
: TDataBlocksArray
;
29 destructor Destroy(); override;
31 function SaveMap(var Data
: Pointer): LongWord
;
32 function HandledVersion(): Byte; virtual;
35 TMapWriter_1
= class(TMapWriter
)
37 function AddTextures(Textures
: TTexturesRec1Array
): Boolean;
38 function AddPanels(Panels
: TPanelsRec1Array
): Boolean;
39 function AddItems(Items
: TItemsRec1Array
): Boolean;
40 function AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
41 function AddAreas(Areas
: TAreasRec1Array
): Boolean;
42 function AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
43 function AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
44 function HandledVersion(): Byte; override;
55 constructor TMapWriter
.Create();
60 destructor TMapWriter
.Destroy();
67 procedure TMapWriter
.FreeMap();
71 if FDataBlocks
<> nil then
72 for a
:= 0 to High(FDataBlocks
) do
73 if FDataBlocks
[a
].Data
<> nil then FreeMem(FDataBlocks
[a
].Data
);
78 function TMapWriter
.SaveMap(var Data
: Pointer): LongWord
;
82 Sign
: array[0..2] of Char;
85 b
:= 3+1+SizeOf(TBlock
)*(Length(FDataBlocks
)+1);
87 if FDataBlocks
<> nil then
88 for a
:= 0 to High(FDataBlocks
) do
89 b
:= b
+FDataBlocks
[a
].Block
.BlockSize
;
95 Sign
:= MAP_SIGNATURE
;
96 CopyMemory(Data
, @Sign
[0], 3);
99 Ver
:= HandledVersion();
100 CopyMemory(Pointer(LongWord(Data
)+c
), @Ver
, 1);
103 if FDataBlocks
<> nil then
104 for a
:= 0 to High(FDataBlocks
) do
106 CopyMemory(Pointer(LongWord(Data
)+c
), @FDataBlocks
[a
].Block
, SizeOf(TBlock
));
107 c
:= c
+SizeOf(TBlock
);
108 CopyMemory(Pointer(LongWord(Data
)+c
), FDataBlocks
[a
].Data
, FDataBlocks
[a
].Block
.BlockSize
);
109 c
:= c
+FDataBlocks
[a
].Block
.BlockSize
;
112 ZeroMemory(Pointer(LongWord(Data
)+c
), SizeOf(TBlock
));
115 function TMapWriter
.HandledVersion(): Byte;
122 function TMapWriter_1
.AddAreas(Areas
: TAreasRec1Array
): Boolean;
132 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
134 size
:= SizeOf(TAreaRec_1
);
136 with FDataBlocks
[High(FDataBlocks
)] do
138 Block
.BlockType
:= BLOCK_AREAS
;
139 Block
.Reserved
:= $00000000;
140 Block
.BlockSize
:= LongWord(Length(Areas
))*size
;
142 Data
:= GetMemory(Block
.BlockSize
);
144 for a
:= 0 to High(Areas
) do
145 CopyMemory(Pointer(LongWord(Data
)+a
*Size
), @Areas
[a
], size
);
151 function TMapWriter_1
.AddItems(Items
: TItemsRec1Array
): Boolean;
161 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
163 size
:= SizeOf(TItemRec_1
);
165 with FDataBlocks
[High(FDataBlocks
)] do
167 Block
.BlockType
:= BLOCK_ITEMS
;
168 Block
.Reserved
:= $00000000;
169 Block
.BlockSize
:= LongWord(Length(Items
))*size
;
171 Data
:= GetMemory(Block
.BlockSize
);
173 for a
:= 0 to High(Items
) do
174 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Items
[a
], size
);
180 function TMapWriter_1
.AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
184 if Monsters
= nil then
190 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
192 size
:= SizeOf(TMonsterRec_1
);
194 with FDataBlocks
[High(FDataBlocks
)] do
196 Block
.BlockType
:= BLOCK_MONSTERS
;
197 Block
.Reserved
:= $00000000;
198 Block
.BlockSize
:= LongWord(Length(Monsters
))*size
;
200 Data
:= GetMemory(Block
.BlockSize
);
202 for a
:= 0 to High(Monsters
) do
203 CopyMemory(Pointer(LongWord(Data
)+a
*Size
), @Monsters
[a
], size
);
209 function TMapWriter_1
.AddPanels(Panels
: TPanelsRec1Array
): Boolean;
219 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
221 size
:= SizeOf(TPanelRec_1
);
223 with FDataBlocks
[High(FDataBlocks
)] do
225 Block
.BlockType
:= BLOCK_PANELS
;
226 Block
.Reserved
:= $00000000;
227 Block
.BlockSize
:= LongWord(Length(Panels
))*size
;
229 Data
:= GetMemory(Block
.BlockSize
);
231 for a
:= 0 to High(Panels
) do
232 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Panels
[a
], size
);
238 function TMapWriter_1
.AddTextures(Textures
: TTexturesRec1Array
): Boolean;
242 if Textures
= nil then
248 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
250 size
:= SizeOf(TTextureRec_1
);
252 with FDataBlocks
[High(FDataBlocks
)] do
254 Block
.BlockType
:= BLOCK_TEXTURES
;
255 Block
.Reserved
:= $00000000;
256 Block
.BlockSize
:= LongWord(Length(Textures
))*size
;
258 Data
:= GetMemory(Block
.BlockSize
);
260 for a
:= 0 to High(Textures
) do
261 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Textures
[a
], size
);
267 function TMapWriter_1
.AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
271 if Triggers
= nil then
277 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
279 size
:= SizeOf(TTriggerRec_1
);
281 with FDataBlocks
[High(FDataBlocks
)] do
283 Block
.BlockType
:= BLOCK_TRIGGERS
;
284 Block
.Reserved
:= $00000000;
285 Block
.BlockSize
:= LongWord(Length(Triggers
))*size
;
287 Data
:= GetMemory(Block
.BlockSize
);
289 for a
:= 0 to High(Triggers
) do
290 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Triggers
[a
], size
);
296 function TMapWriter_1
.AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
300 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
302 size
:= SizeOf(TMapHeaderRec_1
);
304 with FDataBlocks
[High(FDataBlocks
)] do
306 Block
.BlockType
:= BLOCK_HEADER
;
307 Block
.Reserved
:= $00000000;
308 Block
.BlockSize
:= size
;
310 Data
:= GetMemory(Block
.BlockSize
);
312 CopyMemory(Pointer(LongWord(Data
)), @MapHeader
, size
);
318 function TMapWriter_1
.HandledVersion(): Byte;