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/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {$DEFINE MAP_DEBUG_ENABLED_FLAG}
23 e_graphics
, g_basic
, MAPDEF
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
, binheap
, xprofiler
, xparser
, xdynrec
;
38 PRespawnPoint
= ^TRespawnPoint
;
39 TRespawnPoint
= record
41 Direction
: TDirection
;
45 PFlagPoint
= ^TFlagPoint
;
46 TFlagPoint
= TRespawnPoint
;
54 CaptureTime
: LongWord;
55 Animation
: TAnimation
;
56 Direction
: TDirection
;
59 function g_Map_Load(Res
: String): Boolean;
60 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
61 function g_Map_GetMapsList(WADName
: String): SArray
;
62 function g_Map_Exist(Res
: String): Boolean;
63 procedure g_Map_Free(freeTextures
: Boolean=true);
64 procedure g_Map_Update();
66 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
68 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
69 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
71 procedure g_Map_DrawBack(dx
, dy
: Integer);
72 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
73 PanelType
: Word; b1x3
: Boolean=false): Boolean;
74 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
76 procedure g_Map_EnableWallGUID (pguid
: Integer);
77 procedure g_Map_DisableWallGUID (pguid
: Integer);
78 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
81 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
82 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
83 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
85 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
87 procedure g_Map_ReAdd_DieTriggers();
88 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
90 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
91 function g_Map_GetPointCount(PointType
: Byte): Word;
93 function g_Map_HaveFlagPoints(): Boolean;
95 procedure g_Map_ResetFlag(Flag
: Byte);
96 procedure g_Map_DrawFlags();
98 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
99 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
101 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
103 // returns panel or nil
104 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
105 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
107 // returns panel or nil
108 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
109 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
112 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
114 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
115 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
117 // trace liquid, stepping by `dx` and `dy`
118 // return last seen liquid coords, and `false` if we're started outside of the liquid
119 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
122 procedure g_Map_ProfilersBegin ();
123 procedure g_Map_ProfilersEnd ();
126 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
134 function g_Texture_NumNameFindStart(name
: String): Boolean;
135 function g_Texture_NumNameFindNext(var newName
: String): Byte;
138 RESPAWNPOINT_PLAYER1
= 1;
139 RESPAWNPOINT_PLAYER2
= 2;
141 RESPAWNPOINT_RED
= 4;
142 RESPAWNPOINT_BLUE
= 5;
150 FLAG_STATE_NORMAL
= 1;
151 FLAG_STATE_DROPPED
= 2;
152 FLAG_STATE_CAPTURED
= 3;
153 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
154 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
156 FLAG_TIME
= 720; // 20 seconds
158 SKY_STRETCH
: Single = 1.5;
173 // sorted by draw priority
174 GridTagBack
= 1 shl 0; // gRenderBackgrounds
175 GridTagStep
= 1 shl 1; // gSteps
176 GridTagWall
= 1 shl 2; // gWalls
177 GridTagDoor
= 1 shl 3; // gWalls
178 GridTagAcid1
= 1 shl 4; // gAcid1
179 GridTagAcid2
= 1 shl 5; // gAcid2
180 GridTagWater
= 1 shl 6; // gWater
181 GridTagFore
= 1 shl 7; // gRenderForegrounds
182 // the following are invisible
183 GridTagLift
= 1 shl 8; // gLifts
184 GridTagBlockMon
= 1 shl 9; // gBlockMon
186 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
191 gRenderBackgrounds
: TPanelArray
;
192 gRenderForegrounds
: TPanelArray
;
193 gWater
, gAcid1
, gAcid2
: TPanelArray
;
196 gBlockMon
: TPanelArray
;
197 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
198 //gDOMFlags: array of TFlag;
201 gDoorMap
: array of array of DWORD
;
202 gLiftMap
: array of array of DWORD
;
203 gWADHash
: TMD5Digest
;
204 BackID
: DWORD
= DWORD(-1);
205 gExternalResources
: TStringList
;
206 gMovingWallIds
: array of Integer = nil;
208 gdbg_map_use_accel_render
: Boolean = true;
209 gdbg_map_use_accel_coldet
: Boolean = true;
210 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
211 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
213 gCurrentMap
: TDynRecord
= nil;
214 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
217 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
221 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
224 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
230 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
231 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
232 g_options
, g_triggers
, g_player
,
233 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
234 utils
, sfs
, xstreams
, hashtable
,
235 ImagingTypes
, Imaging
, ImagingUtility
,
236 ImagingGif
, ImagingNetworkGraphics
;
239 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
240 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
241 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
246 THashIntPanel = specialize THashBase<Integer, TPanel>;
248 function hashNewIntPanel (): THashIntPanel;
250 result := THashIntPanel.Create(hiihash, hiiequ);
256 //panByGUID: THashIntPanel = nil;
257 panByGUID
: array of TPanel
= nil;
258 //panLastGUID: Integer = 0;
261 // ////////////////////////////////////////////////////////////////////////// //
262 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
264 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
265 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
269 // ////////////////////////////////////////////////////////////////////////// //
271 dfmapdef
: TDynMapDef
= nil;
273 procedure loadMapDefinition ();
275 pr
: TTextParser
= nil;
279 if (dfmapdef
<> nil) then exit
;
281 e_LogWritefln('parsing "mapdef.txt"...', []);
282 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
285 e_LogWritefln('local "%smapdef.txt" not found', [DataDir
]);
289 WAD
:= TWADFile
.Create();
290 if not WAD
.ReadFile(GameWAD
) then
292 //raise Exception.Create('cannot load "game.wad"');
297 st
:= WAD
.openFileStream('mapdef.txt');
303 //raise Exception.Create('cannot open "mapdef.txt"');
304 e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING
);
305 pr
:= TStrTextParser
.Create(defaultMapDef
);
309 pr
:= TFileTextParser
.Create(st
);
313 dfmapdef
:= TDynMapDef
.Create(pr
);
314 except on e
: Exception
do
315 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
323 // ////////////////////////////////////////////////////////////////////////// //
324 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
326 wst
: TSFSMemoryChunkStream
= nil;
327 pr
: TTextParser
= nil;
330 if (dataLen
< 4) then exit
;
332 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
334 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
336 if (PAnsiChar(data
)[0] = 'M') and (PAnsiChar(data
)[1] = 'A') and (PAnsiChar(data
)[2] = 'P') and (PByte(data
)[3] = 1) then
340 result
:= dfmapdef
.parseBinMap(wst
);
341 except on e
: Exception
do
343 e_LogWritefln('ERROR: %s', [e
.message]);
354 pr
:= TFileTextParser
.Create(wst
);
356 result
:= dfmapdef
.parseMap(pr
);
357 except on e
: Exception
do
359 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message])
360 else e_LogWritefln('ERROR: %s', [e
.message]);
361 pr
.Free(); // will free `wst`
366 pr
.Free(); // will free `wst`
371 // ////////////////////////////////////////////////////////////////////////// //
373 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
374 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
375 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
378 function g_Texture_NumNameFindStart(name
: String): Boolean;
386 NNF_CurrentNum
:= -1;
388 for i
:= Length(name
) downto 1 do
389 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
391 if i
= Length(name
) then
392 begin // Íåò öèôð â êîíöå ñòðîêè
397 NNF_PureName
:= Copy(name
, 1, i
);
403 // Íå ïåðåâåñòè â ÷èñëî:
404 if not TryStrToInt(name
, NNF_FirstNum
) then
413 function g_Texture_NumNameFindNext(var newName
: String): Byte;
415 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
418 Result
:= NNF_NO_NAME
;
422 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
424 if NNF_CurrentNum
< NNF_FirstNum
then
425 Result
:= NNF_NAME_BEFORE
427 if NNF_CurrentNum
> NNF_FirstNum
then
428 Result
:= NNF_NAME_AFTER
430 Result
:= NNF_NAME_EQUALS
;
436 // ////////////////////////////////////////////////////////////////////////// //
437 function panelTypeToTag (panelType
: Word): Integer;
440 PANEL_WALL
: result
:= GridTagWall
; // gWalls
441 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
442 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
443 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
444 PANEL_WATER
: result
:= GridTagWater
; // gWater
445 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
446 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
447 PANEL_STEP
: result
:= GridTagStep
; // gSteps
448 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
449 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
450 else result
:= GridTagInvalid
;
455 function dplLess (a
, b
: TObject
): Boolean;
461 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
462 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
463 result
:= (pa
.arrIdx
< pb
.arrIdx
);
466 procedure dplClear ();
468 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
473 Textures
: TLevelTextureArray
= nil;
474 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
475 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
476 RespawnPoints
: array of TRespawnPoint
;
477 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
478 //DOMFlagPoints: Array of TFlagPoint;
481 procedure g_Map_ProfilersBegin ();
483 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
484 profMapCollision
.mainBegin(g_profile_collision
);
486 if g_profile_collision
then
488 profMapCollision
.sectionBegin('*solids');
489 profMapCollision
.sectionEnd();
490 profMapCollision
.sectionBegin('liquids');
491 profMapCollision
.sectionEnd();
495 procedure g_Map_ProfilersEnd ();
497 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
501 // wall index in `gWalls` or -1
502 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
506 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
507 if (result
<> nil) then
509 if (hitx
<> nil) then hitx
^ := ex
;
510 if (hity
<> nil) then hity
^ := ey
;
514 if (hitx
<> nil) then hitx
^ := x1
;
515 if (hity
<> nil) then hity
^ := y1
;
519 // returns panel or nil
520 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
524 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
525 if (result
<> nil) then
527 if (hitx
<> nil) then hitx
^ := ex
;
528 if (hity
<> nil) then hity
^ := ey
;
532 if (hitx
<> nil) then hitx
^ := x1
;
533 if (hity
<> nil) then hity
^ := y1
;
538 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
540 function checker (pan
: TPanel
; tag
: Integer): Boolean;
543 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
545 result := pan.Enabled; // stop if wall is enabled
550 if ((tag
and GridTagLift
) <> 0) then
552 // stop if the lift of the right type
554 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
555 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
556 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
557 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
561 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
565 tagmask
: Integer = 0;
569 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
570 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
571 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
572 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
573 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
574 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
575 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
577 if (tagmask
= 0) then exit
;// just in case
578 if ((tagmask
and GridTagLift
) <> 0) then
581 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
586 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
591 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
594 if (tagmask
= 0) then exit
;
595 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
599 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
601 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
602 (Texture
= TEXTURE_NAME_ACID1
) or
603 (Texture
= TEXTURE_NAME_ACID2
);
606 procedure CreateDoorMap();
608 PanelArray
: Array of record
614 a
, b
, c
, m
, i
, len
: Integer;
622 SetLength(PanelArray
, len
);
624 for a
:= 0 to High(gWalls
) do
625 if gWalls
[a
].Door
then
627 PanelArray
[i
].X
:= gWalls
[a
].X
;
628 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
629 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
630 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
631 PanelArray
[i
].Active
:= True;
632 PanelArray
[i
].PanelID
:= a
;
638 SetLength(PanelArray
, len
);
649 SetLength(gDoorMap
, 0);
651 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
654 if PanelArray
[a
].Active
then
656 PanelArray
[a
].Active
:= False;
657 m
:= Length(gDoorMap
);
658 SetLength(gDoorMap
, m
+1);
659 SetLength(gDoorMap
[m
], 1);
660 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
668 if PanelArray
[b
].Active
then
669 for c
:= 0 to High(gDoorMap
[m
]) do
670 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
671 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
672 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
673 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
674 gWalls
[gDoorMap
[m
, c
]].X
,
675 gWalls
[gDoorMap
[m
, c
]].Y
,
676 gWalls
[gDoorMap
[m
, c
]].Width
,
677 gWalls
[gDoorMap
[m
, c
]].Height
) then
679 PanelArray
[b
].Active
:= False;
680 SetLength(gDoorMap
[m
],
681 Length(gDoorMap
[m
])+1);
682 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
688 g_Game_StepLoading();
694 procedure CreateLiftMap();
696 PanelArray
: Array of record
701 a
, b
, c
, len
, i
, j
: Integer;
707 len
:= Length(gLifts
);
708 SetLength(PanelArray
, len
);
710 for a
:= 0 to len
-1 do
712 PanelArray
[a
].X
:= gLifts
[a
].X
;
713 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
714 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
715 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
716 PanelArray
[a
].Active
:= True;
719 SetLength(gLiftMap
, len
);
722 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
724 for a
:= 0 to len
-1 do
725 if PanelArray
[a
].Active
then
727 PanelArray
[a
].Active
:= False;
728 SetLength(gLiftMap
[i
], 32);
736 for b
:= 0 to len
-1 do
737 if PanelArray
[b
].Active
then
739 if g_CollideAround(PanelArray
[b
].X
,
742 PanelArray
[b
].Height
,
743 PanelArray
[gLiftMap
[i
, c
]].X
,
744 PanelArray
[gLiftMap
[i
, c
]].Y
,
745 PanelArray
[gLiftMap
[i
, c
]].Width
,
746 PanelArray
[gLiftMap
[i
, c
]].Height
) then
748 PanelArray
[b
].Active
:= False;
750 if j
> High(gLiftMap
[i
]) then
751 SetLength(gLiftMap
[i
],
752 Length(gLiftMap
[i
])+32);
761 SetLength(gLiftMap
[i
], j
+1);
764 g_Game_StepLoading();
767 SetLength(gLiftMap
, i
);
772 function CreatePanel(PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
;
773 CurTex
: Integer; sav
: Boolean): Integer;
776 panels
: ^TPanelArray
;
782 case PanelRec
.PanelType
of
783 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
784 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
785 PANEL_FORE
: panels
:= @gRenderForegrounds
;
786 PANEL_WATER
: panels
:= @gWater
;
787 PANEL_ACID1
: panels
:= @gAcid1
;
788 PANEL_ACID2
: panels
:= @gAcid2
;
789 PANEL_STEP
: panels
:= @gSteps
;
790 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
791 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
795 len
:= Length(panels
^);
796 SetLength(panels
^, len
+1);
799 pguid
:= Length(panByGUID
);
800 SetLength(panByGUID
, pguid
+1); //FIXME!
801 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
805 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
806 if sav
then pan
.SaveIt
:= True;
808 PanelRec
.user
['panel_guid'] := pan
.guid
;
809 //panByGUID.put(pan.guid, pan);
815 function CreateNullTexture(RecName
: String): Integer;
817 RecName
:= toLowerCase1251(RecName
);
818 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
819 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
821 SetLength(Textures
, Length(Textures
)+1);
822 result
:= High(Textures
);
824 with Textures
[High(Textures
)] do
826 TextureName
:= RecName
;
830 TextureID
:= LongWord(TEXTURE_NONE
);
833 TextNameHash
.put(RecName
, result
);
837 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
840 TextureData
: Pointer;
842 a
, ResLength
: Integer;
844 RecName
:= toLowerCase1251(RecName
);
845 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
846 if TextNameHash
.get(RecName
, result
) then
849 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
855 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
858 if Textures <> nil then
860 for a := 0 to High(Textures) do
862 if (Textures[a].TextureName = RecName) then
863 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
864 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
872 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
873 if (RecName
= TEXTURE_NAME_WATER
) or
874 (RecName
= TEXTURE_NAME_ACID1
) or
875 (RecName
= TEXTURE_NAME_ACID2
) then
877 SetLength(Textures
, Length(Textures
)+1);
879 with Textures
[High(Textures
)] do
881 TextureName
:= RecName
;
882 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
883 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
884 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
889 result
:= High(Textures
);
890 TextNameHash
.put(RecName
, result
);
894 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
895 WADName
:= g_ExtractWadName(RecName
);
897 WAD
:= TWADFile
.Create();
899 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
901 WAD
.ReadFile(WADName
);
905 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
907 FreeMem(TextureData);
908 RecName := 'COMMON\ALIEN';
912 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
914 SetLength(Textures
, Length(Textures
)+1);
915 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
917 SetLength(Textures
, Length(Textures
)-1);
920 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
921 FreeMem(TextureData
);
922 Textures
[High(Textures
)].TextureName
:= RecName
;
923 Textures
[High(Textures
)].Anim
:= False;
925 result
:= High(Textures
);
926 TextNameHash
.put(RecName
, result
);
928 else // Íåò òàêîãî ðåóñðñà â WAD'å
930 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
931 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
932 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
934 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
935 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
937 BadTextNameHash
.put(RecName
, -1);
944 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
947 TextureWAD
: PChar = nil;
948 TextData
: Pointer = nil;
949 TextureData
: Pointer = nil;
953 TextureResource
: String;
954 _width
, _height
, _framecount
, _speed
: Integer;
955 _backanimation
: Boolean;
957 ia
: TDynImageDataArray
= nil;
958 f
, c
, frdelay
, frloop
: Integer;
960 RecName
:= toLowerCase1251(RecName
);
961 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
962 if TextNameHash
.get(RecName
, result
) then
965 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
971 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
973 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
974 if BadTextNameHash
.get(RecName
, f
) then
976 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
980 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
981 WADName
:= g_ExtractWadName(RecName
);
983 WAD
:= TWADFile
.Create();
985 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
987 WAD
.ReadFile(WADName
);
989 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
991 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
992 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
994 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
995 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
997 BadTextNameHash
.put(RecName
, -1);
1002 if WADName = Map then
1004 //FreeMem(TextureWAD);
1005 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1011 if ResLength
< 6 then
1013 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
1014 BadTextNameHash
.put(RecName
, -1);
1018 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1019 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1020 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1022 // íåò, ýòî ñóïåðìåí!
1023 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1025 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1026 BadTextNameHash
.put(RecName
, -1);
1030 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1031 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1033 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1034 BadTextNameHash
.put(RecName
, -1);
1038 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1040 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1041 if TextureResource
= '' then
1043 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1044 BadTextNameHash
.put(RecName
, -1);
1048 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1049 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1050 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1051 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1052 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1057 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1058 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1060 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1061 BadTextNameHash
.put(RecName
, -1);
1068 SetLength(Textures
, Length(Textures
)+1);
1069 with Textures
[High(Textures
)] do
1071 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1072 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1074 TextureName
:= RecName
;
1078 FramesCount
:= _framecount
;
1080 result
:= High(Textures
);
1081 TextNameHash
.put(RecName
, result
);
1085 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1086 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1088 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1090 BadTextNameHash
.put(RecName
, -1);
1096 // try animated image
1098 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1099 if length(imgfmt) = 0 then
1101 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1105 GlobalMetadata
.ClearMetaItems();
1106 GlobalMetadata
.ClearMetaItemsForSaving();
1107 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1109 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1110 BadTextNameHash
.put(RecName
, -1);
1113 if length(ia
) = 0 then
1115 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1116 BadTextNameHash
.put(RecName
, -1);
1123 _width
:= ia
[0].width
;
1124 _height
:= ia
[0].height
;
1125 _framecount
:= length(ia
);
1127 _backanimation
:= false;
1130 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1132 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1134 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1136 if f
< 0 then f
:= 0;
1139 if c
< 13 then c
:= 0 else c
:= 1;
1141 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1146 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1148 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1150 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1152 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1156 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1157 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1158 f
:= ord(_backanimation
);
1159 e_WriteLog(Format('Animated texture file "%s": %d frames (delay:%d; back:%d; frdelay:%d; frloop:%d), %dx%d', [RecName
, length(ia
), _speed
, f
, frdelay
, frloop
, _width
, _height
]), MSG_NOTIFY
);
1161 SetLength(Textures
, Length(Textures
)+1);
1162 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1163 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1165 Textures
[High(Textures
)].TextureName
:= RecName
;
1166 Textures
[High(Textures
)].Width
:= _width
;
1167 Textures
[High(Textures
)].Height
:= _height
;
1168 Textures
[High(Textures
)].Anim
:= True;
1169 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1170 Textures
[High(Textures
)].Speed
:= _speed
;
1171 result
:= High(Textures
);
1172 TextNameHash
.put(RecName
, result
);
1173 //writeln(' CREATED!');
1177 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1178 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1180 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1182 BadTextNameHash
.put(RecName
, -1);
1186 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1189 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1190 if (TextData
<> nil) then FreeMem(TextData
);
1191 if (TextureData
<> nil) then FreeMem(TextureData
);
1195 procedure CreateItem(Item
: TDynRecord
);
1197 if g_Game_IsClient
then Exit
;
1199 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1200 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1203 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1204 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1207 procedure CreateArea(Area
: TDynRecord
);
1212 case Area
.AreaType
of
1213 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1214 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1216 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1217 with RespawnPoints
[High(RespawnPoints
)] do
1221 Direction
:= TDirection(Area
.Direction
);
1223 case Area
.AreaType
of
1224 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1225 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1226 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1227 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1228 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1233 AREA_REDFLAG
, AREA_BLUEFLAG
:
1235 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1237 if FlagPoints
[a
] <> nil then Exit
;
1241 with FlagPoints
[a
]^ do
1243 X
:= Area
.X
-FLAGRECT
.X
;
1244 Y
:= Area
.Y
-FLAGRECT
.Y
;
1245 Direction
:= TDirection(Area
.Direction
);
1251 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1252 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1255 Animation
:= TAnimation
.Create(id
, True, 8);
1256 Obj
.Rect
:= FLAGRECT
;
1264 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1265 with DOMFlagPoints[High(DOMFlagPoints)] do
1269 Direction := TDirection(Area.Direction);
1272 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1277 procedure CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1281 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1285 mapId
:= Trigger
.id
;
1286 mapIndex
:= amapIdx
;
1289 Width
:= Trigger
.Width
;
1290 Height
:= Trigger
.Height
;
1291 Enabled
:= Trigger
.Enabled
;
1292 //TexturePanel := Trigger.TexturePanel;
1293 TexturePanelGUID
:= atpanid
;
1294 TexturePanelType
:= fTexturePanel1Type
;
1295 ShotPanelType
:= fTexturePanel2Type
;
1296 TriggerType
:= Trigger
.TriggerType
;
1297 ActivateType
:= Trigger
.ActivateType
;
1298 Keys
:= Trigger
.Keys
;
1299 trigPanelGUID
:= atrigpanid
;
1300 //trigShotPanelId := ashotpanid;
1301 //Data.Default := Trigger.DATA;
1302 if (Trigger
.trigRec
= nil) then
1305 if (TriggerType
<> TRIGGER_SECRET
) then
1307 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1312 trigData
:= Trigger
.trigRec
.clone();
1316 g_Triggers_Create(_trigger
);
1319 procedure CreateMonster(monster
: TDynRecord
);
1324 if g_Game_IsClient
then Exit
;
1326 if (gGameSettings
.GameType
= GT_SINGLE
)
1327 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1329 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1331 if gTriggers
<> nil then
1333 for a
:= 0 to High(gTriggers
) do
1335 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1337 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1338 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1343 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1347 procedure g_Map_ReAdd_DieTriggers();
1349 function monsDieTrig (mon
: TMonster
): Boolean;
1352 //tw: TStrTextWriter;
1354 result
:= false; // don't stop
1355 mon
.ClearTriggers();
1356 for a
:= 0 to High(gTriggers
) do
1358 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1360 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1362 tw := TStrTextWriter.Create();
1364 gTriggers[a].trigData.writeTo(tw);
1365 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1370 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1376 if g_Game_IsClient
then Exit
;
1378 g_Mons_ForEach(monsDieTrig
);
1381 function extractWadName(resourceName
: string): string;
1385 posN
:= Pos(':', resourceName
);
1387 Result
:= Copy(resourceName
, 0, posN
-1)
1392 procedure addResToExternalResList(res
: string);
1394 res
:= extractWadName(res
);
1395 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1396 gExternalResources
.Add(res
);
1399 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1401 //textures: TTexturesRec1Array;
1402 //textures: TDynField;
1404 //mapHeader: TMapHeaderRec_1;
1406 //resFile: String = '';
1408 if gExternalResources
= nil then
1409 gExternalResources
:= TStringList
.Create
;
1411 gExternalResources
.Clear
;
1415 textures := GetTextures(map);
1416 for i := 0 to High(textures) do
1418 addResToExternalResList(resFile);
1422 textures := map['texture'];
1423 if (textures <> nil) then
1425 for trec in textures do
1427 addResToExternalResList(resFile);
1434 //mapHeader := GetMapHeader(map);
1436 addResToExternalResList(map
.MusicName
);
1437 addResToExternalResList(map
.SkyName
);
1441 procedure mapCreateGrid ();
1443 mapX0
: Integer = $3fffffff;
1444 mapY0
: Integer = $3fffffff;
1445 mapX1
: Integer = -$3fffffff;
1446 mapY1
: Integer = -$3fffffff;
1448 procedure calcBoundingBox (constref panels
: TPanelArray
);
1453 for idx
:= 0 to High(panels
) do
1456 if not pan
.visvalid
then continue
;
1457 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1458 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1459 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1460 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1461 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1465 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1471 //tag := panelTypeToTag(tag);
1472 for idx
:= 0 to High(panels
) do
1475 if not pan
.visvalid
then continue
;
1476 if (pan
.proxyId
<> -1) then
1478 {$IF DEFINED(D2F_DEBUG)}
1479 e_WriteLog(Format('DUPLICATE wall #%d(%d) enabled (%d); type:%08x', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.PanelType
]), MSG_NOTIFY
);
1483 case pan
.PanelType
of
1484 PANEL_WALL
: newtag
:= GridTagWall
;
1485 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1486 PANEL_BACK
: newtag
:= GridTagBack
;
1487 PANEL_FORE
: newtag
:= GridTagFore
;
1488 PANEL_WATER
: newtag
:= GridTagWater
;
1489 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1490 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1491 PANEL_STEP
: newtag
:= GridTagStep
;
1492 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1493 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1494 else continue
; // oops
1498 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1499 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1500 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1501 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1503 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1505 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1516 calcBoundingBox(gWalls
);
1517 calcBoundingBox(gRenderBackgrounds
);
1518 calcBoundingBox(gRenderForegrounds
);
1519 calcBoundingBox(gWater
);
1520 calcBoundingBox(gAcid1
);
1521 calcBoundingBox(gAcid2
);
1522 calcBoundingBox(gSteps
);
1523 calcBoundingBox(gLifts
);
1524 calcBoundingBox(gBlockMon
);
1526 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1528 if (mapX0
> 0) then mapX0
:= 0;
1529 if (mapY0
> 0) then mapY0
:= 0;
1531 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1532 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1534 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1535 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1537 addPanelsToGrid(gWalls
);
1538 addPanelsToGrid(gRenderBackgrounds
);
1539 addPanelsToGrid(gRenderForegrounds
);
1540 addPanelsToGrid(gWater
);
1541 addPanelsToGrid(gAcid1
);
1542 addPanelsToGrid(gAcid2
);
1543 addPanelsToGrid(gSteps
);
1544 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1545 addPanelsToGrid(gBlockMon
);
1547 mapGrid
.dumpStats();
1549 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1553 function g_Map_Load(Res
: String): Boolean;
1555 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1556 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1560 //TexturePanel: Integer;
1562 LiftPanelIdx
: Integer;
1563 DoorPanelIdx
: Integer;
1564 ShotPanelIdx
: Integer;
1565 MPlatPanelIdx
: Integer;
1566 trigrec
: TDynRecord
;
1568 liftPan
: TDynRecord
;
1569 doorPan
: TDynRecord
;
1570 shotPan
: TDynRecord
;
1571 mplatPan
: TDynRecord
;
1575 mapReader
: TDynRecord
= nil;
1576 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1577 panels
: TDynField
= nil; //TPanelsRec1Array;
1578 items
: TDynField
= nil; //TItemsRec1Array;
1579 monsters
: TDynField
= nil; //TMonsterRec1Array;
1580 areas
: TDynField
= nil; //TAreasRec1Array;
1581 triggers
: TDynField
= nil; //TTriggersRec1Array;
1584 AddTextures
: TAddTextureArray
;
1585 TriggersTable
: array of TTRec
;
1586 FileName
, mapResName
, s
, TexName
: String;
1589 ok
, isAnim
, trigRef
: Boolean;
1590 CurTex
, ntn
: Integer;
1591 rec
, texrec
: TDynRecord
;
1593 pannum
, trignum
, cnt
, tgpid
: Integer;
1595 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1596 //moveActive: Boolean;
1605 //panByGUID := hashNewIntPanel();
1610 gMapInfo
.Map
:= Res
;
1611 TriggersTable
:= nil;
1614 sfsGCDisable(); // temporary disable removing of temporary volumes
1617 FileName
:= g_ExtractWadName(Res
);
1618 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1619 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1621 WAD
:= TWADFile
.Create();
1622 if not WAD
.ReadFile(FileName
) then
1624 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1629 //k8: why loader ignores path here?
1630 mapResName
:= g_ExtractFileName(Res
);
1631 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1633 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1642 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1648 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1649 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1651 stt
:= curTimeMicro();
1654 mapReader
:= g_Map_ParseMap(Data
, Len
);
1657 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1664 generateExternalResourcesList(mapReader
);
1665 mapTextureList
:= mapReader
['texture'];
1666 // get all other lists here too
1667 panels
:= mapReader
['panel'];
1668 triggers
:= mapReader
['trigger'];
1669 items
:= mapReader
['item'];
1670 areas
:= mapReader
['area'];
1671 monsters
:= mapReader
['monster'];
1673 // Çàãðóçêà îïèñàíèÿ êàðòû:
1674 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1675 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1679 Name
:= mapReader
.MapName
;
1680 Description
:= mapReader
.MapDesc
;
1681 Author
:= mapReader
.MapAuthor
;
1682 MusicName
:= mapReader
.MusicName
;
1683 SkyName
:= mapReader
.SkyName
;
1684 Height
:= mapReader
.Height
;
1685 Width
:= mapReader
.Width
;
1688 // Çàãðóçêà òåêñòóð:
1689 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1690 // Äîáàâëåíèå òåêñòóð â Textures[]:
1691 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1693 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1694 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1697 for rec
in mapTextureList
do
1701 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1702 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1704 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1707 // Àíèìèðîâàííàÿ òåêñòóðà
1708 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1709 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1714 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1715 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1717 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1719 rec
.tagInt
:= ntn
; // remember texture number
1720 g_Game_StepLoading();
1723 // set panel tagInt to texture index
1724 if (panels
<> nil) then
1726 for rec
in panels
do
1728 texrec
:= rec
.TextureRec
;
1729 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1734 // Çàãðóçêà òðèããåðîâ
1735 gTriggerClientID
:= 0;
1736 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1737 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1740 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1741 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1743 // check texture numbers for panels
1744 if (panels
<> nil) and (panels
.count
> 0) then
1746 for rec
in panels
do
1748 if (rec
.tagInt
< 0) then
1750 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1757 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1758 if (triggers
<> nil) and (triggers
.count
> 0) then
1760 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1761 //SetLength(TriggersTable, triggers.count);
1762 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1764 for rec
in triggers
do
1766 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1767 pttit
:= @TriggersTable
[High(TriggersTable
)];
1768 pttit
.trigrec
:= rec
;
1769 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1770 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1771 pttit
.liftPan
:= nil;
1772 pttit
.doorPan
:= nil;
1773 pttit
.shotPan
:= nil;
1774 pttit
.mplatPan
:= nil;
1775 pttit
.texPanIdx
:= -1;
1776 pttit
.LiftPanelIdx
:= -1;
1777 pttit
.DoorPanelIdx
:= -1;
1778 pttit
.ShotPanelIdx
:= -1;
1779 pttit
.MPlatPanelIdx
:= -1;
1781 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1783 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1786 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1788 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1791 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1793 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1796 if rec
.TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1798 pttit
.mplatPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1801 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1802 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1803 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1804 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1805 if (pttit
.mplatPan
<> nil) then pttit
.mplatPan
.userPanelTrigRef
:= true;
1807 g_Game_StepLoading();
1812 if (panels
<> nil) and (panels
.count
> 0) then
1814 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1815 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1818 for rec
in panels
do
1821 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1823 SetLength(AddTextures
, 0);
1828 if (mapTextureList
<> nil) then
1830 texrec
:= rec
.TextureRec
;
1831 ok
:= (texrec
<> nil);
1836 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1837 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1839 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1842 for b := 0 to High(TriggersTable) do
1844 if (TriggersTable[b].texPan = rec) or (TriggersTable[b].shotPan = rec) then
1852 if rec
.userPanelTrigRef
then
1854 // e_LogWritefln('trigref for panel %s', [pannum]);
1863 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1864 s
:= texrec
.Resource
;
1866 // Ñïåö-òåêñòóðû çàïðåùåíû
1867 if g_Map_IsSpecialTexture(s
) then
1873 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1874 ok
:= g_Texture_NumNameFindStart(s
);
1877 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1878 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1881 k
:= NNF_NAME_BEFORE
;
1882 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1883 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1885 k
:= g_Texture_NumNameFindNext(TexName
);
1887 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1889 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1892 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1894 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1895 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1896 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1899 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1901 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1902 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1903 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1908 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1910 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1911 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1912 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1915 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1917 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1918 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1919 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1923 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1927 for c := 0 to High(Textures) do
1929 if (Textures[c].TextureName = TexName) then
1931 SetLength(AddTextures, Length(AddTextures)+1);
1932 AddTextures[High(AddTextures)].Texture := c;
1933 AddTextures[High(AddTextures)].Anim := isAnim;
1938 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1940 SetLength(AddTextures
, Length(AddTextures
)+1);
1941 AddTextures
[High(AddTextures
)].Texture
:= c
;
1942 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1948 if k
= NNF_NAME_EQUALS
then
1950 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1951 SetLength(AddTextures
, Length(AddTextures
)+1);
1952 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1953 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1954 CurTex
:= High(AddTextures
);
1965 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1966 end; // if ok - ññûëàþòñÿ òðèããåðû
1970 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1971 SetLength(AddTextures
, 1);
1972 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1973 AddTextures
[0].Anim
:= false;
1974 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1978 //e_WriteLog(Format('panel #%d: TextureNum=%d; ht=%d; ht1=%d; atl=%d', [a, panels[a].TextureNum, High(mapTextureList), High(Textures), High(AddTextures)]), MSG_NOTIFY);
1980 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1982 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð
1983 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
, trigRef
);
1984 //e_LogWritefln('panel #%s of type %s got id #%s', [pannum, rec.PanelType, PanelID]);
1985 // set 'gamePanelId' field to panel id
1986 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
1989 moveSpeed
:= rec
.moveSpeed
;
1990 //moveStart := rec.moveStart;
1991 //moveEnd := rec.moveEnd;
1992 //moveActive := rec['move_active'].varvalue;
1993 if not moveSpeed
.isZero
then
1995 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
1996 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
1997 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2000 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2002 g_Game_StepLoading();
2006 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2007 for b
:= 0 to High(TriggersTable
) do
2009 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
2010 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
2011 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
2012 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
2013 if (TriggersTable
[b
].mplatPan
<> nil) then TriggersTable
[b
].MPlatPanelIdx
:= TriggersTable
[b
].mplatPan
.userPanelId
;
2016 // create map grid, init other grids (for monsters, for example)
2017 e_WriteLog('Creating map grid', MSG_NOTIFY
);
2020 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2021 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2023 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2024 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2025 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2027 for rec
in triggers
do
2030 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
2031 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
2032 // we can have only one of those
2033 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
2034 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
2035 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
2036 else if (TriggersTable
[trignum
].MPlatPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].MPlatPanelIdx
2038 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2039 CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
2043 // Çàãðóçêà ïðåäìåòîâ
2044 e_WriteLog(' Loading items...', MSG_NOTIFY
);
2045 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2047 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2048 if (items
<> nil) and not gLoadGameMode
then
2050 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
2051 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2052 for rec
in items
do CreateItem(rec
);
2055 // Çàãðóçêà îáëàñòåé
2056 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2057 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2059 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2060 if areas
<> nil then
2062 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2063 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2064 for rec
in areas
do CreateArea(rec
);
2067 // Çàãðóçêà ìîíñòðîâ
2068 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2069 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2071 gTotalMonsters
:= 0;
2073 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2074 if (monsters
<> nil) and not gLoadGameMode
then
2076 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2077 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2078 for rec
in monsters
do CreateMonster(rec
);
2081 gCurrentMap
:= mapReader
; // this will be our current map now
2082 gCurrentMapFileName
:= Res
;
2086 if gMapInfo
.SkyName
<> '' then
2088 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2089 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2090 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2092 if FileName
<> '' then
2093 FileName
:= GameDir
+'/wads/'+FileName
2096 FileName
:= g_ExtractWadName(Res
);
2099 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2100 if g_Texture_CreateWAD(BackID
, s
) then
2102 g_Game_SetupScreenSize();
2105 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2110 if gMapInfo
.MusicName
<> '' then
2112 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2113 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2114 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2116 if FileName
<> '' then
2117 FileName
:= GameDir
+'/wads/'+FileName
2120 FileName
:= g_ExtractWadName(Res
);
2123 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2124 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2127 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2130 // Îñòàëüíûå óñòàíâêè
2138 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2139 if not gLoadGameMode
then g_GFX_Init();
2141 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2142 mapTextureList
:= nil;
2147 TriggersTable
:= nil;
2150 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2151 if ok
and (not gLoadGameMode
) then
2153 gMusic
.SetByName(gMapInfo
.MusicName
);
2158 gMusic
.SetByName('');
2161 stt
:= curTimeMicro()-stt
;
2162 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2164 sfsGCEnable(); // enable releasing unused volumes
2166 e_ClearInputBuffer(); // why not?
2169 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2174 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2177 mapReader
: TDynRecord
;
2178 //Header: TMapHeaderRec_1;
2183 FillChar(Result
, SizeOf(Result
), 0);
2184 FileName
:= g_ExtractWadName(Res
);
2186 WAD
:= TWADFile
.Create();
2187 if not WAD
.ReadFile(FileName
) then
2193 //k8: it ignores path again
2194 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2203 mapReader
:= g_Map_ParseMap(Data
, Len
);
2210 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2212 Result
.Name
:= mapReader
.MapName
;
2213 Result
.Description
:= mapReader
.MapDesc
;
2215 Result
.Author
:= mapReader
.MapAuthor
;
2216 Result
.Height
:= mapReader
.Height
;
2217 Result
.Width
:= mapReader
.Width
;
2221 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2222 //ZeroMemory(@Header, SizeOf(Header));
2223 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2224 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2226 Result
.Author
:= '';
2234 function g_Map_GetMapsList(WADName
: string): SArray
;
2241 WAD
:= TWADFile
.Create();
2242 if not WAD
.ReadFile(WADName
) then
2247 ResList
:= WAD
.GetMapResources();
2248 if ResList
<> nil then
2250 for a
:= 0 to High(ResList
) do
2252 SetLength(Result
, Length(Result
)+1);
2253 Result
[High(Result
)] := ResList
[a
];
2259 function g_Map_Exist(Res
: string): Boolean;
2262 FileName
, mnn
: string;
2268 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2270 WAD
:= TWADFile
.Create
;
2271 if not WAD
.ReadFile(FileName
) then
2277 ResList
:= WAD
.GetMapResources();
2280 mnn
:= g_ExtractFileName(Res
);
2281 if ResList
<> nil then
2282 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2289 procedure g_Map_Free(freeTextures
: Boolean=true);
2293 procedure FreePanelArray(var panels
: TPanelArray
);
2298 if panels
<> nil then
2300 for i
:= 0 to High(panels
) do
2313 RespawnPoints
:= nil;
2314 if FlagPoints
[FLAG_RED
] <> nil then
2316 Dispose(FlagPoints
[FLAG_RED
]);
2317 FlagPoints
[FLAG_RED
] := nil;
2319 if FlagPoints
[FLAG_BLUE
] <> nil then
2321 Dispose(FlagPoints
[FLAG_BLUE
]);
2322 FlagPoints
[FLAG_BLUE
] := nil;
2324 //DOMFlagPoints := nil;
2328 if (Length(gCurrentMapFileName
) <> 0) then
2330 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2334 e_LogWritefln('g_Map_Free: no previous map.', []);
2336 if freeTextures
then
2338 e_LogWritefln('g_Map_Free: clearing textures...', []);
2339 if (Textures
<> nil) then
2341 for a
:= 0 to High(Textures
) do
2343 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2345 if Textures
[a
].Anim
then
2347 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2351 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2353 e_DeleteTexture(Textures
[a
].TextureID
);
2360 TextNameHash
.Free();
2361 TextNameHash
:= nil;
2362 BadTextNameHash
.Free();
2363 BadTextNameHash
:= nil;
2371 FreePanelArray(gWalls
);
2372 FreePanelArray(gRenderBackgrounds
);
2373 FreePanelArray(gRenderForegrounds
);
2374 FreePanelArray(gWater
);
2375 FreePanelArray(gAcid1
);
2376 FreePanelArray(gAcid2
);
2377 FreePanelArray(gSteps
);
2378 FreePanelArray(gLifts
);
2379 FreePanelArray(gBlockMon
);
2380 gMovingWallIds
:= nil;
2382 if BackID
<> DWORD(-1) then
2386 e_DeleteTexture(BackID
);
2387 BackID
:= DWORD(-1);
2390 g_Game_StopAllSounds(False);
2392 g_Sound_Delete(gMapInfo
.MusicName
);
2394 gMapInfo
.Name
:= '';
2395 gMapInfo
.Description
:= '';
2396 gMapInfo
.MusicName
:= '';
2397 gMapInfo
.Height
:= 0;
2398 gMapInfo
.Width
:= 0;
2404 procedure g_Map_Update();
2410 procedure UpdatePanelArray(var panels
: TPanelArray
);
2415 for i
:= 0 to High(panels
) do panels
[i
].Update();
2419 UpdatePanelArray(gWalls
);
2420 UpdatePanelArray(gRenderBackgrounds
);
2421 UpdatePanelArray(gRenderForegrounds
);
2422 UpdatePanelArray(gWater
);
2423 UpdatePanelArray(gAcid1
);
2424 UpdatePanelArray(gAcid2
);
2425 UpdatePanelArray(gSteps
);
2427 if gGameSettings
.GameMode
= GM_CTF
then
2429 for a
:= FLAG_RED
to FLAG_BLUE
do
2430 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2433 if gFlags
[a
].Animation
<> nil then
2434 gFlags
[a
].Animation
.Update();
2436 m
:= g_Obj_Move(@Obj
, True, True);
2438 if gTime
mod (GAME_TICK
*2) <> 0 then
2441 // Ñîïðîòèâëåíèå âîçäóõà:
2442 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2444 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
2445 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2448 gFlags
[a
].CaptureTime
:= 0;
2449 if a
= FLAG_RED
then
2450 s
:= _lc
[I_PLAYER_FLAG_RED
]
2452 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2453 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2455 if g_Game_IsNet
then
2456 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2463 // Èãðîê áåðåò ôëàã:
2464 if gPlayers
<> nil then
2466 j
:= Random(Length(gPlayers
)) - 1;
2468 for d
:= 0 to High(gPlayers
) do
2471 if j
> High(gPlayers
) then
2474 if gPlayers
[j
] <> nil then
2475 if gPlayers
[j
].Live
and
2476 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2478 if gPlayers
[j
].GetFlag(a
) then
2489 procedure g_Map_DrawPanels (PanelType
: Word);
2491 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2495 if (panels
<> nil) then
2497 // alas, no visible set
2498 for idx
:= 0 to High(panels
) do
2500 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2507 PANEL_WALL
: DrawPanels(gWalls
);
2508 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2509 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2510 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2511 PANEL_WATER
: DrawPanels(gWater
);
2512 PANEL_ACID1
: DrawPanels(gAcid1
);
2513 PANEL_ACID2
: DrawPanels(gAcid2
);
2514 PANEL_STEP
: DrawPanels(gSteps
);
2520 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2522 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2524 result
:= false; // don't stop, ever
2525 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2526 gDrawPanelList
.insert(pan
);
2531 //tagmask := panelTypeToTag(PanelType);
2532 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2533 // list will be rendered in `g_game.DrawPlayer()`
2537 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2539 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2541 result
:= false; // don't stop, ever
2542 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2546 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2550 procedure g_Map_DrawBack(dx
, dy
: Integer);
2552 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2553 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2555 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2558 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2559 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2565 if WordBool(PanelType
and PANEL_WALL
) then
2566 if gWalls
<> nil then
2571 if gWalls
[a
].Enabled
and
2572 g_Collide(X
, Y
, Width
, Height
,
2573 gWalls
[a
].X
, gWalls
[a
].Y
,
2574 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2581 if WordBool(PanelType
and PANEL_WATER
) then
2582 if gWater
<> nil then
2587 if g_Collide(X
, Y
, Width
, Height
,
2588 gWater
[a
].X
, gWater
[a
].Y
,
2589 gWater
[a
].Width
, gWater
[a
].Height
) then
2596 if WordBool(PanelType
and PANEL_ACID1
) then
2597 if gAcid1
<> nil then
2602 if g_Collide(X
, Y
, Width
, Height
,
2603 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2604 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2611 if WordBool(PanelType
and PANEL_ACID2
) then
2612 if gAcid2
<> nil then
2617 if g_Collide(X
, Y
, Width
, Height
,
2618 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2619 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2626 if WordBool(PanelType
and PANEL_STEP
) then
2627 if gSteps
<> nil then
2632 if g_Collide(X
, Y
, Width
, Height
,
2633 gSteps
[a
].X
, gSteps
[a
].Y
,
2634 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2641 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2642 if gLifts
<> nil then
2647 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2648 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2649 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2650 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2651 g_Collide(X
, Y
, Width
, Height
,
2652 gLifts
[a
].X
, gLifts
[a
].Y
,
2653 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2660 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2661 if gBlockMon
<> nil then
2663 h
:= High(gBlockMon
);
2667 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2668 g_Collide(X
, Y
, Width
, Height
,
2669 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2670 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2678 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2682 function checkPanels (constref panels
: TPanelArray
): Boolean;
2687 if panels
= nil then exit
;
2688 for a
:= 0 to High(panels
) do
2690 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2693 texid
:= panels
[a
].GetTextureID();
2700 texid
:= LongWord(TEXTURE_NONE
);
2702 if not checkPanels(gWater
) then
2703 if not checkPanels(gAcid1
) then
2704 if not checkPanels(gAcid2
) then exit
;
2709 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2711 SlowMask
= GridTagLift
or GridTagBlockMon
;
2712 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2715 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2717 result := pan.Enabled;
2722 if ((tag
and GridTagLift
) <> 0) then
2725 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2726 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2727 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2728 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2729 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2733 if ((tag
and GridTagBlockMon
) <> 0) then
2735 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2740 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2741 result
:= true; // i found her!
2745 tagmask
: Integer = 0;
2747 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2748 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2749 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2750 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2751 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2752 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2753 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2755 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2757 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2758 if gdbg_map_use_accel_coldet
then
2760 if (Width
= 1) and (Height
= 1) then
2762 if ((tagmask
and SlowMask
) <> 0) then
2765 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2770 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2775 if ((tagmask
and SlowMask
) <> 0) then
2778 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2783 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2789 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2791 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2795 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2797 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2800 // slightly different from the old code, but meh...
2801 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2803 result
:= false; // don't stop, ever
2804 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2807 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2808 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2809 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2812 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2814 texid
:= pan
.GetTextureID();
2815 // water? water has the highest priority, so stop right here
2816 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2818 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2820 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2824 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2825 if gdbg_map_use_accel_coldet
then
2827 texid
:= LongWord(TEXTURE_NONE
);
2828 if (Width
= 1) and (Height
= 1) then
2830 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2834 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2840 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2842 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2846 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2847 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2848 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2851 procedure g_Map_EnableWallGUID (pguid
: Integer);
2855 //pan := gWalls[ID];
2856 pan
:= g_Map_PanelByGUID(pguid
);
2857 if (pan
= nil) then exit
;
2858 pan
.Enabled
:= True;
2859 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2861 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2862 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2863 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2865 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState({gWalls[ID]}pan
.PanelType
, pguid
);
2867 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2868 //e_WriteLog(Format('ENABLE: wall #%d(%d) enabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
2873 procedure g_Map_DisableWallGUID (pguid
: Integer);
2877 //pan := gWalls[ID];
2878 pan
:= g_Map_PanelByGUID(pguid
);
2879 if (pan
= nil) then exit
;
2880 pan
.Enabled
:= False;
2881 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2883 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2884 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2886 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, pguid
);
2888 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2889 //e_WriteLog(Format('DISABLE: wall #%d(%d) disabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
2894 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
2898 tp
:= g_Map_PanelByGUID(pguid
);
2899 if (tp
= nil) then exit
;
2902 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: tp := gWalls[ID];
2903 PANEL_FORE: tp := gRenderForegrounds[ID];
2904 PANEL_BACK: tp := gRenderBackgrounds[ID];
2905 PANEL_WATER: tp := gWater[ID];
2906 PANEL_ACID1: tp := gAcid1[ID];
2907 PANEL_ACID2: tp := gAcid2[ID];
2908 PANEL_STEP: tp := gSteps[ID];
2913 tp
.NextTexture(AnimLoop
);
2914 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(PanelType
, pguid
, AnimLoop
);
2918 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2922 //pan := gLifts[ID];
2923 pan
:= g_Map_PanelByGUID(pguid
);
2924 if (pan
= nil) then exit
;
2925 if not pan
.isGLift
then exit
;
2927 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2929 with {gLifts[ID]} pan
do
2933 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2934 //TODO: make separate lift tags, and change tag here
2937 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2938 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2939 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2940 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
2943 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, pguid
);
2948 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2951 PointsArray
: Array of TRespawnPoint
;
2954 SetLength(PointsArray
, 0);
2956 if RespawnPoints
= nil then
2959 for a
:= 0 to High(RespawnPoints
) do
2960 if RespawnPoints
[a
].PointType
= PointType
then
2962 SetLength(PointsArray
, Length(PointsArray
)+1);
2963 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2966 if PointsArray
= nil then
2969 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2973 function g_Map_GetPointCount(PointType
: Byte): Word;
2979 if RespawnPoints
= nil then
2982 for a
:= 0 to High(RespawnPoints
) do
2983 if RespawnPoints
[a
].PointType
= PointType
then
2984 Result
:= Result
+ 1;
2987 function g_Map_HaveFlagPoints(): Boolean;
2989 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2992 procedure g_Map_ResetFlag(Flag
: Byte);
2994 with gFlags
[Flag
] do
3000 Direction
:= D_LEFT
;
3001 State
:= FLAG_STATE_NONE
;
3002 if FlagPoints
[Flag
] <> nil then
3004 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3005 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3006 Direction
:= FlagPoints
[Flag
]^.Direction
;
3007 State
:= FLAG_STATE_NORMAL
;
3013 procedure g_Map_DrawFlags();
3016 Mirror
: TMirrorType
;
3018 if gGameSettings
.GameMode
<> GM_CTF
then
3021 for i
:= FLAG_RED
to FLAG_BLUE
do
3023 if State
<> FLAG_STATE_CAPTURED
then
3025 if State
= FLAG_STATE_NONE
then
3028 if Direction
= D_LEFT
then
3030 Mirror
:= M_HORIZONTAL
;
3039 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3041 if g_debug_Frames
then
3043 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3045 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3046 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3052 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
3059 procedure SavePanelArray(var panels
: TPanelArray
);
3061 PAMem
: TBinMemoryWriter
;
3064 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
3065 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
3068 while i
< Length(panels
) do
3070 if true{panels[i].SaveIt} then
3074 // Ñîõðàíÿåì ïàíåëü:
3075 panels
[i
].SaveState(PAMem
);
3080 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
3081 PAMem
.SaveToMemory(Mem
);
3085 procedure SaveFlag(flag
: PFlag
);
3088 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3090 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3091 Mem
.WriteByte(flag
^.RespawnType
);
3093 Mem
.WriteByte(flag
^.State
);
3094 // Íàïðàâëåíèå ôëàãà:
3095 if flag
^.Direction
= D_LEFT
then
3101 Obj_SaveState(@flag
^.Obj
, Mem
);
3105 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3107 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3108 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
3109 SavePanelArray(gWalls
);
3110 // Ñîõðàíÿåì ïàíåëè ôîíà:
3111 SavePanelArray(gRenderBackgrounds
);
3112 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
3113 SavePanelArray(gRenderForegrounds
);
3114 // Ñîõðàíÿåì ïàíåëè âîäû:
3115 SavePanelArray(gWater
);
3116 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
3117 SavePanelArray(gAcid1
);
3118 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
3119 SavePanelArray(gAcid2
);
3120 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
3121 SavePanelArray(gSteps
);
3122 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
3123 SavePanelArray(gLifts
);
3126 ///// Ñîõðàíÿåì ìóçûêó: /////
3127 // Ñèãíàòóðà ìóçûêè:
3128 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3131 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3132 if gMusic
.NoMusic
then
3136 Mem
.WriteString(str
, 64);
3137 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3138 dw
:= gMusic
.GetPosition();
3140 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3141 boo
:= gMusic
.SpecPause
;
3142 Mem
.WriteBoolean(boo
);
3145 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3146 Mem
.WriteInt(gTotalMonsters
);
3149 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3150 if gGameSettings
.GameMode
= GM_CTF
then
3152 // Ôëàã Êðàñíîé êîìàíäû:
3153 SaveFlag(@gFlags
[FLAG_RED
]);
3154 // Ôëàã Ñèíåé êîìàíäû:
3155 SaveFlag(@gFlags
[FLAG_BLUE
]);
3159 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3160 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3162 // Î÷êè Êðàñíîé êîìàíäû:
3163 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3164 // Î÷êè Ñèíåé êîìàíäû:
3165 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3170 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
3177 procedure LoadPanelArray(var panels
: TPanelArray
);
3179 PAMem
: TBinMemoryReader
;
3182 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
3183 PAMem
:= TBinMemoryReader
.Create();
3184 PAMem
.LoadFromMemory(Mem
);
3186 for i
:= 0 to Length(panels
)-1 do
3188 if true{panels[i].SaveIt} then
3194 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
3196 // Çàãðóæàåì ïàíåëü:
3197 panels
[i
].LoadState(PAMem
);
3198 if (panels
[i
].arrIdx
<> i
) then raise Exception
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
3199 if (panels
[i
].proxyId
>= 0) then mapGrid
.proxyEnabled
[panels
[i
].proxyId
] := panels
[i
].Enabled
;
3203 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
3207 procedure LoadFlag(flag
: PFlag
);
3211 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
3213 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3215 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3216 Mem
.ReadByte(flag
^.RespawnType
);
3218 Mem
.ReadByte(flag
^.State
);
3219 // Íàïðàâëåíèå ôëàãà:
3222 flag
^.Direction
:= D_LEFT
3224 flag
^.Direction
:= D_RIGHT
;
3226 Obj_LoadState(@flag
^.Obj
, Mem
);
3233 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3234 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
3235 LoadPanelArray(gWalls
);
3236 // Çàãðóæàåì ïàíåëè ôîíà:
3237 LoadPanelArray(gRenderBackgrounds
);
3238 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
3239 LoadPanelArray(gRenderForegrounds
);
3240 // Çàãðóæàåì ïàíåëè âîäû:
3241 LoadPanelArray(gWater
);
3242 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
3243 LoadPanelArray(gAcid1
);
3244 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
3245 LoadPanelArray(gAcid2
);
3246 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
3247 LoadPanelArray(gSteps
);
3248 // Çàãðóæàåì ïàíåëè ëèôòîâ:
3249 LoadPanelArray(gLifts
);
3252 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
3256 ///// Çàãðóæàåì ìóçûêó: /////
3257 // Ñèãíàòóðà ìóçûêè:
3259 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
3261 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3264 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3265 Mem
.ReadString(str
);
3266 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3268 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3269 Mem
.ReadBoolean(boo
);
3270 // Çàïóñêàåì ýòó ìóçûêó:
3271 gMusic
.SetByName(str
);
3272 gMusic
.SpecPause
:= boo
;
3275 gMusic
.SetPosition(dw
);
3278 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3279 Mem
.ReadInt(gTotalMonsters
);
3282 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3283 if gGameSettings
.GameMode
= GM_CTF
then
3285 // Ôëàã Êðàñíîé êîìàíäû:
3286 LoadFlag(@gFlags
[FLAG_RED
]);
3287 // Ôëàã Ñèíåé êîìàíäû:
3288 LoadFlag(@gFlags
[FLAG_BLUE
]);
3292 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3293 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3295 // Î÷êè Êðàñíîé êîìàíäû:
3296 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3297 // Î÷êè Ñèíåé êîìàíäû:
3298 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3304 // trace liquid, stepping by `dx` and `dy`
3305 // return last seen liquid coords, and `false` if we're started outside of the liquid
3306 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3308 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3312 // started outside of the liquid?
3313 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3314 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3320 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit