1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 -----------------------------------
21 MAPWRITER.PAS ÂÅÐÑÈß ÎÒ 24.09.06
23 Ïîääåðæêà êàðò âåðñèè 1
24 -----------------------------------
33 TDataBlock
= packed record
38 TDataBlocksArray
= packed array of TDataBlock
;
40 TMapWriter
= class(TObject
)
42 FDataBlocks
: TDataBlocksArray
;
45 destructor Destroy(); override;
47 function SaveMap(var Data
: Pointer): LongWord;
48 function HandledVersion(): Byte; virtual;
51 TMapWriter_1
= class(TMapWriter
)
53 function AddTextures(Textures
: TTexturesRec1Array
): Boolean;
54 function AddPanels(Panels
: TPanelsRec1Array
): Boolean;
55 function AddItems(Items
: TItemsRec1Array
): Boolean;
56 function AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
57 function AddAreas(Areas
: TAreasRec1Array
): Boolean;
58 function AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
59 function AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
60 function HandledVersion(): Byte; override;
71 constructor TMapWriter
.Create();
76 destructor TMapWriter
.Destroy();
83 procedure TMapWriter
.FreeMap();
87 if FDataBlocks
<> nil then
88 for a
:= 0 to High(FDataBlocks
) do
89 if FDataBlocks
[a
].Data
<> nil then FreeMem(FDataBlocks
[a
].Data
);
94 function TMapWriter
.SaveMap(var Data
: Pointer): LongWord;
98 Sign
: array[0..2] of Char;
101 b
:= 3+1+SizeOf(TBlock
)*(Length(FDataBlocks
)+1);
103 if FDataBlocks
<> nil then
104 for a
:= 0 to High(FDataBlocks
) do
105 b
:= b
+FDataBlocks
[a
].Block
.BlockSize
;
111 Sign
:= MAP_SIGNATURE
;
112 CopyMemory(Data
, @Sign
[0], 3);
115 Ver
:= HandledVersion();
116 CopyMemory(Pointer(LongWord(Data
)+c
), @Ver
, 1);
119 if FDataBlocks
<> nil then
120 for a
:= 0 to High(FDataBlocks
) do
122 CopyMemory(Pointer(LongWord(Data
)+c
), @FDataBlocks
[a
].Block
, SizeOf(TBlock
));
123 c
:= c
+SizeOf(TBlock
);
124 CopyMemory(Pointer(LongWord(Data
)+c
), FDataBlocks
[a
].Data
, FDataBlocks
[a
].Block
.BlockSize
);
125 c
:= c
+FDataBlocks
[a
].Block
.BlockSize
;
128 ZeroMemory(Pointer(LongWord(Data
)+c
), SizeOf(TBlock
));
131 function TMapWriter
.HandledVersion(): Byte;
138 function TMapWriter_1
.AddAreas(Areas
: TAreasRec1Array
): Boolean;
148 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
150 size
:= SizeOf(TAreaRec_1
);
152 with FDataBlocks
[High(FDataBlocks
)] do
154 Block
.BlockType
:= BLOCK_AREAS
;
155 Block
.Reserved
:= $00000000;
156 Block
.BlockSize
:= LongWord(Length(Areas
))*size
;
158 Data
:= GetMemory(Block
.BlockSize
);
160 for a
:= 0 to High(Areas
) do
161 CopyMemory(Pointer(LongWord(Data
)+a
*Size
), @Areas
[a
], size
);
167 function TMapWriter_1
.AddItems(Items
: TItemsRec1Array
): Boolean;
177 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
179 size
:= SizeOf(TItemRec_1
);
181 with FDataBlocks
[High(FDataBlocks
)] do
183 Block
.BlockType
:= BLOCK_ITEMS
;
184 Block
.Reserved
:= $00000000;
185 Block
.BlockSize
:= LongWord(Length(Items
))*size
;
187 Data
:= GetMemory(Block
.BlockSize
);
189 for a
:= 0 to High(Items
) do
190 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Items
[a
], size
);
196 function TMapWriter_1
.AddMonsters(Monsters
: TMonsterRec1Array
): Boolean;
200 if Monsters
= nil then
206 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
208 size
:= SizeOf(TMonsterRec_1
);
210 with FDataBlocks
[High(FDataBlocks
)] do
212 Block
.BlockType
:= BLOCK_MONSTERS
;
213 Block
.Reserved
:= $00000000;
214 Block
.BlockSize
:= LongWord(Length(Monsters
))*size
;
216 Data
:= GetMemory(Block
.BlockSize
);
218 for a
:= 0 to High(Monsters
) do
219 CopyMemory(Pointer(LongWord(Data
)+a
*Size
), @Monsters
[a
], size
);
225 function TMapWriter_1
.AddPanels(Panels
: TPanelsRec1Array
): Boolean;
235 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
237 size
:= SizeOf(TPanelRec_1
);
239 with FDataBlocks
[High(FDataBlocks
)] do
241 Block
.BlockType
:= BLOCK_PANELS
;
242 Block
.Reserved
:= $00000000;
243 Block
.BlockSize
:= LongWord(Length(Panels
))*size
;
245 Data
:= GetMemory(Block
.BlockSize
);
247 for a
:= 0 to High(Panels
) do
248 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Panels
[a
], size
);
254 function TMapWriter_1
.AddTextures(Textures
: TTexturesRec1Array
): Boolean;
258 if Textures
= nil then
264 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
266 size
:= SizeOf(TTextureRec_1
);
268 with FDataBlocks
[High(FDataBlocks
)] do
270 Block
.BlockType
:= BLOCK_TEXTURES
;
271 Block
.Reserved
:= $00000000;
272 Block
.BlockSize
:= LongWord(Length(Textures
))*size
;
274 Data
:= GetMemory(Block
.BlockSize
);
276 for a
:= 0 to High(Textures
) do
277 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Textures
[a
], size
);
283 function TMapWriter_1
.AddTriggers(Triggers
: TTriggersRec1Array
): Boolean;
287 if Triggers
= nil then
293 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
295 size
:= SizeOf(TTriggerRec_1
);
297 with FDataBlocks
[High(FDataBlocks
)] do
299 Block
.BlockType
:= BLOCK_TRIGGERS
;
300 Block
.Reserved
:= $00000000;
301 Block
.BlockSize
:= LongWord(Length(Triggers
))*size
;
303 Data
:= GetMemory(Block
.BlockSize
);
305 for a
:= 0 to High(Triggers
) do
306 CopyMemory(Pointer(LongWord(Data
)+a
*size
), @Triggers
[a
], size
);
312 function TMapWriter_1
.AddHeader(MapHeader
: TMapHeaderRec_1
): Boolean;
316 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
318 size
:= SizeOf(TMapHeaderRec_1
);
320 with FDataBlocks
[High(FDataBlocks
)] do
322 Block
.BlockType
:= BLOCK_HEADER
;
323 Block
.Reserved
:= $00000000;
324 Block
.BlockSize
:= size
;
326 Data
:= GetMemory(Block
.BlockSize
);
328 CopyMemory(Pointer(LongWord(Data
)), @MapHeader
, size
);
334 function TMapWriter_1
.HandledVersion(): Byte;