3 {$INCLUDE ../shared/a_modes.inc}
6 -----------------------------------
7 MAPWRITER.PAS ÂÅÐÑÈß ÎÒ 24.09.06
9 Ïîääåðæêà êàðò âåðñèè 1
10 -----------------------------------
19 TDataBlock
= packed record
24 TDataBlocksArray
= packed array of TDataBlock
;
26 TMapWriter
= class(TObject
)
28 FDataBlocks
: TDataBlocksArray
;
31 destructor Destroy(); override;
33 function SaveMap(var Data
: Pointer): LongWord;
34 function HandledVersion(): Byte; virtual;
37 TMapWriter_1
= class(TMapWriter
)
39 function AddTextures(Textures
: TTexturesRec1Array
): Boolean;
40 function AddPanels(Panels
: TPanelsRec1Array
): Boolean;
41 function AddItems(Items
: TItemsRec1Array
): Boolean;
42 function AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
43 function AddAreas(Areas
: TAreasRec1Array
): Boolean;
44 function AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
45 function AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
46 function HandledVersion(): Byte; override;
57 constructor TMapWriter
.Create();
62 destructor TMapWriter
.Destroy();
69 procedure TMapWriter
.FreeMap();
73 if FDataBlocks
<> nil then
74 for a
:= 0 to High(FDataBlocks
) do
75 if FDataBlocks
[a
].Data
<> nil then FreeMem(FDataBlocks
[a
].Data
);
80 function TMapWriter
.SaveMap(var Data
: Pointer): LongWord;
84 Sign
: array[0..2] of Char;
87 b
:= 3+1+SizeOf(TBlock
)*(Length(FDataBlocks
)+1);
89 if FDataBlocks
<> nil then
90 for a
:= 0 to High(FDataBlocks
) do
91 b
:= b
+FDataBlocks
[a
].Block
.BlockSize
;
97 Sign
:= MAP_SIGNATURE
;
98 CopyMemory(Data
, @Sign
[0], 3);
101 Ver
:= HandledVersion();
102 CopyMemory(Pointer(PtrUInt(Data
)+c
), @Ver
, 1);
105 if FDataBlocks
<> nil then
106 for a
:= 0 to High(FDataBlocks
) do
108 CopyMemory(Pointer(PtrUInt(Data
)+c
), @FDataBlocks
[a
].Block
, SizeOf(TBlock
));
109 c
:= c
+SizeOf(TBlock
);
110 CopyMemory(Pointer(PtrUInt(Data
)+c
), FDataBlocks
[a
].Data
, FDataBlocks
[a
].Block
.BlockSize
);
111 c
:= c
+FDataBlocks
[a
].Block
.BlockSize
;
114 ZeroMemory(Pointer(PtrUInt(Data
)+c
), SizeOf(TBlock
));
117 function TMapWriter
.HandledVersion(): Byte;
124 function TMapWriter_1
.AddAreas(Areas
: TAreasRec1Array
): Boolean;
134 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
136 size
:= SizeOf(TAreaRec_1
);
138 with FDataBlocks
[High(FDataBlocks
)] do
140 Block
.BlockType
:= BLOCK_AREAS
;
141 Block
.Reserved
:= $00000000;
142 Block
.BlockSize
:= LongWord(Length(Areas
))*size
;
144 Data
:= GetMemory(Block
.BlockSize
);
146 for a
:= 0 to High(Areas
) do
147 CopyMemory(Pointer(PtrUInt(Data
)+a
*Size
), @Areas
[a
], size
);
153 function TMapWriter_1
.AddItems(Items
: TItemsRec1Array
): Boolean;
163 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
165 size
:= SizeOf(TItemRec_1
);
167 with FDataBlocks
[High(FDataBlocks
)] do
169 Block
.BlockType
:= BLOCK_ITEMS
;
170 Block
.Reserved
:= $00000000;
171 Block
.BlockSize
:= LongWord(Length(Items
))*size
;
173 Data
:= GetMemory(Block
.BlockSize
);
175 for a
:= 0 to High(Items
) do
176 CopyMemory(Pointer(PtrUInt(Data
)+a
*size
), @Items
[a
], size
);
182 function TMapWriter_1
.AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
186 if Monsters
= nil then
192 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
194 size
:= SizeOf(TMonsterRec_1
);
196 with FDataBlocks
[High(FDataBlocks
)] do
198 Block
.BlockType
:= BLOCK_MONSTERS
;
199 Block
.Reserved
:= $00000000;
200 Block
.BlockSize
:= LongWord(Length(Monsters
))*size
;
202 Data
:= GetMemory(Block
.BlockSize
);
204 for a
:= 0 to High(Monsters
) do
205 CopyMemory(Pointer(PtrUInt(Data
)+a
*Size
), @Monsters
[a
], size
);
211 function TMapWriter_1
.AddPanels(Panels
: TPanelsRec1Array
): Boolean;
221 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
223 size
:= SizeOf(TPanelRec_1
);
225 with FDataBlocks
[High(FDataBlocks
)] do
227 Block
.BlockType
:= BLOCK_PANELS
;
228 Block
.Reserved
:= $00000000;
229 Block
.BlockSize
:= LongWord(Length(Panels
))*size
;
231 Data
:= GetMemory(Block
.BlockSize
);
233 for a
:= 0 to High(Panels
) do
234 CopyMemory(Pointer(PtrUInt(Data
)+a
*size
), @Panels
[a
], size
);
240 function TMapWriter_1
.AddTextures(Textures
: TTexturesRec1Array
): Boolean;
244 if Textures
= nil then
250 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
252 size
:= SizeOf(TTextureRec_1
);
254 with FDataBlocks
[High(FDataBlocks
)] do
256 Block
.BlockType
:= BLOCK_TEXTURES
;
257 Block
.Reserved
:= $00000000;
258 Block
.BlockSize
:= LongWord(Length(Textures
))*size
;
260 Data
:= GetMemory(Block
.BlockSize
);
262 for a
:= 0 to High(Textures
) do
263 CopyMemory(Pointer(PtrUInt(Data
)+a
*size
), @Textures
[a
], size
);
269 function TMapWriter_1
.AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
273 if Triggers
= nil then
279 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
281 size
:= SizeOf(TTriggerRec_1
);
283 with FDataBlocks
[High(FDataBlocks
)] do
285 Block
.BlockType
:= BLOCK_TRIGGERS
;
286 Block
.Reserved
:= $00000000;
287 Block
.BlockSize
:= LongWord(Length(Triggers
))*size
;
289 Data
:= GetMemory(Block
.BlockSize
);
291 for a
:= 0 to High(Triggers
) do
292 CopyMemory(Pointer(PtrUInt(Data
)+a
*size
), @Triggers
[a
], size
);
298 function TMapWriter_1
.AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
302 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
304 size
:= SizeOf(TMapHeaderRec_1
);
306 with FDataBlocks
[High(FDataBlocks
)] do
308 Block
.BlockType
:= BLOCK_HEADER
;
309 Block
.Reserved
:= $00000000;
310 Block
.BlockSize
:= size
;
312 Data
:= GetMemory(Block
.BlockSize
);
314 CopyMemory(Pointer(PtrUInt(Data
)), @MapHeader
, size
);
320 function TMapWriter_1
.HandledVersion(): Byte;