3 {$INCLUDE ../shared/a_modes.inc}
6 -----------------------------------
7 MAPREADER.PAS ÂÅÐÑÈß ÎÒ 13.11.07
9 Ïîääåðæêà êàðò âåðñèè 1
10 -----------------------------------
19 TDataBlock
= packed record
24 TDataBlocksArray
= packed array of TDataBlock
;
26 TMapReader
= class(TObject
)
30 FDataBlocks
: TDataBlocksArray
;
31 function GetBlocks(BlocksType
: Byte): TDataBlocksArray
;
34 destructor Destroy(); override;
35 function LoadMap(Data
: Pointer): Boolean;
37 function HandledVersion(): Byte; virtual;
39 property GetError
: Byte read FError
;
40 property GetVersion
: Byte read FVersion
;
43 TMapReader_1
= class(TMapReader
)
46 function GetMapHeader(): TMapHeaderRec_1
;
47 function GetTextures(): TTexturesRec1Array
;
48 function GetPanels(): TPanelsRec1Array
;
49 function GetItems(): TItemsRec1Array
;
50 function GetAreas(): TAreasRec1Array
;
51 function GetMonsters(): TMonsterRec1Array
;
52 function GetTriggers(): TTriggersRec1Array
;
53 function HandledVersion(): Byte; override;
58 MAP_ERROR_SIGNATURE
= $01;
59 MAP_ERROR_VERSION
= $02;
66 function g_Texture_NumNameFindStart(name
: String): Boolean;
67 function g_Texture_NumNameFindNext(var newName
: String): Byte;
75 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
76 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
77 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
79 function g_Texture_NumNameFindStart(name
: String): Boolean;
89 for i
:= Length(name
) downto 1 do
90 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
92 if i
= Length(name
) then
93 begin // Íåò öèôð â êîíöå ñòðîêè
98 NNF_PureName
:= Copy(name
, 1, i
);
104 // Íå ïåðåâåñòè â ÷èñëî:
105 if not TryStrToInt(name
, NNF_FirstNum
) then
113 function g_Texture_NumNameFindNext(var newName
: String): Byte;
115 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
118 Result
:= NNF_NO_NAME
;
122 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
124 if NNF_CurrentNum
< NNF_FirstNum
then
125 Result
:= NNF_NAME_BEFORE
127 if NNF_CurrentNum
> NNF_FirstNum
then
128 Result
:= NNF_NAME_AFTER
130 Result
:= NNF_NAME_EQUALS
;
135 { T M a p R e a d e r _ 1 : }
137 function TMapReader_1
.GetAreas(): TAreasRec1Array
;
139 TempDataBlocks
: TDataBlocksArray
;
145 TempDataBlocks
:= GetBlocks(BLOCK_AREAS
);
147 if TempDataBlocks
= nil then Exit
;
149 size
:= SizeOf(TAreaRec_1
);
151 for a
:= 0 to High(TempDataBlocks
) do
152 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
154 SetLength(Result
, Length(Result
)+1);
155 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
158 TempDataBlocks
:= nil;
161 function TMapReader_1
.GetItems(): TItemsRec1Array
;
163 TempDataBlocks
: TDataBlocksArray
;
169 TempDataBlocks
:= GetBlocks(BLOCK_ITEMS
);
171 if TempDataBlocks
= nil then Exit
;
173 size
:= SizeOf(TItemRec_1
);
175 for a
:= 0 to High(TempDataBlocks
) do
176 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
178 SetLength(Result
, Length(Result
)+1);
179 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
182 TempDataBlocks
:= nil;
185 function TMapReader_1
.GetMapHeader(): TMapHeaderRec_1
;
187 TempDataBlocks
: TDataBlocksArray
;
189 ZeroMemory(@Result
, SizeOf(TMapHeaderRec_1
));
191 TempDataBlocks
:= GetBlocks(BLOCK_HEADER
);
193 if TempDataBlocks
= nil then Exit
;
195 CopyMemory(@Result
, TempDataBlocks
[0].Data
, SizeOf(TMapHeaderRec_1
));
197 TempDataBlocks
:= nil;
200 function TMapReader_1
.GetMonsters(): TMonsterRec1Array
;
202 TempDataBlocks
: TDataBlocksArray
;
208 TempDataBlocks
:= GetBlocks(BLOCK_MONSTERS
);
210 if TempDataBlocks
= nil then Exit
;
212 size
:= SizeOf(TMonsterRec_1
);
214 for a
:= 0 to High(TempDataBlocks
) do
215 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
217 SetLength(Result
, Length(Result
)+1);
218 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
221 TempDataBlocks
:= nil;
224 function TMapReader_1
.GetPanels(): TPanelsRec1Array
;
226 TempDataBlocks
: TDataBlocksArray
;
232 TempDataBlocks
:= GetBlocks(BLOCK_PANELS
);
234 if TempDataBlocks
= nil then Exit
;
236 size
:= SizeOf(TPanelRec_1
);
238 for a
:= 0 to High(TempDataBlocks
) do
239 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
241 SetLength(Result
, Length(Result
)+1);
242 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
245 TempDataBlocks
:= nil;
248 function TMapReader_1
.GetTextures(): TTexturesRec1Array
;
250 TempDataBlocks
: TDataBlocksArray
;
256 TempDataBlocks
:= GetBlocks(BLOCK_TEXTURES
);
258 if TempDataBlocks
= nil then Exit
;
260 size
:= SizeOf(TTextureRec_1
);
262 for a
:= 0 to High(TempDataBlocks
) do
263 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
265 SetLength(Result
, Length(Result
)+1);
266 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
269 TempDataBlocks
:= nil;
272 function TMapReader_1
.GetTriggers(): TTriggersRec1Array
;
274 TempDataBlocks
: TDataBlocksArray
;
280 TempDataBlocks
:= GetBlocks(BLOCK_TRIGGERS
);
282 if TempDataBlocks
= nil then Exit
;
284 size
:= SizeOf(TTriggerRec_1
);
286 for a
:= 0 to High(TempDataBlocks
) do
287 for b
:= 0 to (TempDataBlocks
[a
].Block
.BlockSize
div size
)-1 do
289 SetLength(Result
, Length(Result
)+1);
290 CopyMemory(@Result
[High(Result
)], Pointer(PtrUInt(TempDataBlocks
[a
].Data
)+b
*size
), size
);
293 TempDataBlocks
:= nil;
296 function TMapReader_1
.HandledVersion
: Byte;
301 { T M a p R e a d e r : }
303 constructor TMapReader
.Create();
306 FError
:= MAP_ERROR_NONE
;
310 destructor TMapReader
.Destroy();
317 procedure TMapReader
.FreeMap();
321 if FDataBlocks
<> nil then
322 for a
:= 0 to High(FDataBlocks
) do
323 if FDataBlocks
[a
].Data
<> nil then FreeMem(FDataBlocks
[a
].Data
);
327 FError
:= MAP_ERROR_NONE
;
330 function TMapReader
.GetBlocks(BlocksType
: Byte): TDataBlocksArray
;
336 if FDataBlocks
= nil then Exit
;
338 for a
:= 0 to High(FDataBlocks
) do
339 if FDataBlocks
[a
].Block
.BlockType
= BlocksType
then
341 SetLength(Result
, Length(Result
)+1);
342 Result
[High(Result
)] := FDataBlocks
[a
];
346 function TMapReader
.HandledVersion(): Byte;
351 function TMapReader
.LoadMap(Data
: Pointer): Boolean;
355 Sign
: array[0..2] of Char;
360 CopyMemory(@Sign
[0], Data
, 3);
361 if Sign
<> MAP_SIGNATURE
then
363 FError
:= MAP_ERROR_SIGNATURE
;
368 CopyMemory(@Ver
, Pointer(PtrUInt(Data
)+adr
), 1);
370 if Ver
> HandledVersion() then
372 FError
:= MAP_ERROR_VERSION
;
378 SetLength(FDataBlocks
, Length(FDataBlocks
)+1);
379 _id
:= High(FDataBlocks
);
381 CopyMemory(@FDataBlocks
[_id
].Block
, Pointer(PtrUInt(Data
)+adr
), SizeOf(TBlock
));
382 adr
:= adr
+SizeOf(TBlock
);
384 FDataBlocks
[_id
].Data
:= GetMemory(FDataBlocks
[_id
].Block
.BlockSize
);
386 CopyMemory(FDataBlocks
[_id
].Data
, Pointer(PtrUInt(Data
)+adr
), FDataBlocks
[_id
].Block
.BlockSize
);
388 adr
:= adr
+FDataBlocks
[_id
].Block
.BlockSize
;
389 until FDataBlocks
[_id
].Block
.BlockType
= BLOCK_NONE
;