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 SysUtils
, Classes
, mempool
,
24 e_graphics
, g_basic
, MAPDEF
, g_textures
,
25 g_phys
, utils
, g_panel
, g_grid
, md5
, binheap
, xprofiler
, xparser
, xdynrec
;
39 PRespawnPoint
= ^TRespawnPoint
;
40 TRespawnPoint
= record
42 Direction
: TDirection
;
46 PFlagPoint
= ^TFlagPoint
;
47 TFlagPoint
= TRespawnPoint
;
55 CaptureTime
: LongWord;
56 Animation
: TAnimation
;
57 Direction
: TDirection
;
60 function g_Map_Load(Res
: String): Boolean;
61 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
62 function g_Map_GetMapsList(WADName
: String): SSArray
;
63 function g_Map_Exist(Res
: String): Boolean;
64 procedure g_Map_Free(freeTextures
: Boolean=true);
65 procedure g_Map_Update();
67 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
69 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
); // unaccelerated
70 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
72 procedure g_Map_DrawBack(dx
, dy
: Integer);
73 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
74 PanelType
: Word; b1x3
: Boolean=false): Boolean;
75 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
77 procedure g_Map_EnableWallGUID (pguid
: Integer);
78 procedure g_Map_DisableWallGUID (pguid
: Integer);
79 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
82 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
83 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
84 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
86 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
88 procedure g_Map_ReAdd_DieTriggers();
89 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
91 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
92 function g_Map_GetPointCount(PointType
: Byte): Word;
94 function g_Map_HaveFlagPoints(): Boolean;
96 procedure g_Map_ResetFlag(Flag
: Byte);
97 procedure g_Map_DrawFlags();
99 procedure g_Map_SaveState (st
: TStream
);
100 procedure g_Map_LoadState (st
: TStream
);
102 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
104 // returns panel or nil
105 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
106 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
108 // returns panel or nil
109 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
110 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
113 TForEachPanelCB
= function (pan
: TPanel
): Boolean is nested
; // return `true` to stop
115 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
116 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
118 // trace liquid, stepping by `dx` and `dy`
119 // return last seen liquid coords, and `false` if we're started outside of the liquid
120 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
123 // return `true` from `cb` to stop
124 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
126 procedure g_Map_NetSendInterestingPanels (); // yay!
129 procedure g_Map_ProfilersBegin ();
130 procedure g_Map_ProfilersEnd ();
133 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
136 function g_Map_MinX (): Integer; inline;
137 function g_Map_MinY (): Integer; inline;
138 function g_Map_MaxX (): Integer; inline;
139 function g_Map_MaxY (): Integer; inline;
147 function g_Texture_NumNameFindStart(name
: String): Boolean;
148 function g_Texture_NumNameFindNext(var newName
: String): Byte;
151 RESPAWNPOINT_PLAYER1
= 1;
152 RESPAWNPOINT_PLAYER2
= 2;
154 RESPAWNPOINT_RED
= 4;
155 RESPAWNPOINT_BLUE
= 5;
163 FLAG_STATE_NORMAL
= 1;
164 FLAG_STATE_DROPPED
= 2;
165 FLAG_STATE_CAPTURED
= 3;
166 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
167 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
169 FLAG_TIME
= 720; // 20 seconds
171 SKY_STRETCH
: Single = 1.5;
186 // sorted by draw priority
187 GridTagBack
= 1 shl 0; // gRenderBackgrounds
188 GridTagStep
= 1 shl 1; // gSteps
189 GridTagWall
= 1 shl 2; // gWalls
190 GridTagDoor
= 1 shl 3; // gWalls
191 GridTagAcid1
= 1 shl 4; // gAcid1
192 GridTagAcid2
= 1 shl 5; // gAcid2
193 GridTagWater
= 1 shl 6; // gWater
194 GridTagFore
= 1 shl 7; // gRenderForegrounds
195 // the following are invisible
196 GridTagLift
= 1 shl 8; // gLifts
197 GridTagBlockMon
= 1 shl 9; // gBlockMon
199 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
200 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
202 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
206 TBinHeapPanelDrawCmp
= class
208 class function less (const a
, b
: TPanel
): Boolean; inline;
211 TBinHeapPanelDraw
= specialize TBinaryHeapBase
<TPanel
, TBinHeapPanelDrawCmp
>;
215 gRenderBackgrounds
: TPanelArray
;
216 gRenderForegrounds
: TPanelArray
;
217 gWater
, gAcid1
, gAcid2
: TPanelArray
;
220 gBlockMon
: TPanelArray
;
221 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
222 //gDOMFlags: array of TFlag;
225 gDoorMap
: array of array of DWORD
;
226 gLiftMap
: array of array of DWORD
;
227 gWADHash
: TMD5Digest
;
228 BackID
: DWORD
= DWORD(-1);
229 gExternalResources
: TStringList
;
230 gMovingWallIds
: array of Integer = nil;
232 gdbg_map_use_accel_render
: Boolean = true;
233 gdbg_map_use_accel_coldet
: Boolean = true;
234 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
235 gDrawPanelList
: TBinHeapPanelDraw
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
237 gCurrentMap
: TDynRecord
= nil;
238 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
239 gTestMap
: String = '';
242 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
246 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
249 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
255 e_input
, g_main
, e_log
, e_texture
, g_items
, g_gfx
, g_console
,
256 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
257 g_options
, g_triggers
, g_player
,
258 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
259 sfs
, xstreams
, hashtable
, wadreader
,
260 ImagingTypes
, Imaging
, ImagingUtility
,
261 ImagingGif
, ImagingNetworkGraphics
;
264 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
265 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
266 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
269 // ////////////////////////////////////////////////////////////////////////// //
270 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
274 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
278 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
283 // ////////////////////////////////////////////////////////////////////////// //
285 panByGUID
: array of TPanel
= nil;
288 // ////////////////////////////////////////////////////////////////////////// //
289 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
291 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
292 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
296 // return `true` from `cb` to stop
297 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
302 if not assigned(cb
) then exit
;
303 for pan
in panByGUID
do
305 if cb(pan
) then begin result
:= pan
; exit
; end;
310 procedure g_Map_NetSendInterestingPanels ();
314 if g_Game_IsServer
and g_Game_IsNet
then
316 for pan
in panByGUID
do
318 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
324 // ////////////////////////////////////////////////////////////////////////// //
325 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
326 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
327 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
328 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
331 // ////////////////////////////////////////////////////////////////////////// //
333 dfmapdef
: TDynMapDef
= nil;
336 procedure loadMapDefinition ();
338 pr
: TTextParser
= nil;
342 if (dfmapdef
<> nil) then exit
;
345 e_LogWritefln('parsing "mapdef.txt"...', []);
346 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
347 e_LogWritefln('found local "%smapdef.txt"', [DataDir
]);
354 WAD
:= TWADFile
.Create();
355 if not WAD
.ReadFile(GameWAD
) then
357 //raise Exception.Create('cannot load "game.wad"');
362 st
:= WAD
.openFileStream('mapdef.txt');
369 //raise Exception.Create('cannot open "mapdef.txt"');
370 e_LogWriteln('using default "mapdef.txt"...');
371 pr
:= TStrTextParser
.Create(defaultMapDef
);
375 pr
:= TFileTextParser
.Create(st
);
377 except on e
: Exception
do
379 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
385 dfmapdef
:= TDynMapDef
.Create(pr
);
387 on e
: TDynParseException
do
388 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
390 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
398 // ////////////////////////////////////////////////////////////////////////// //
399 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
401 wst
: TSFSMemoryChunkStream
= nil;
404 if (dataLen
< 4) then exit
;
406 if (dfmapdef
= nil) then writeln('need to load mapdef');
408 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
410 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
412 result
:= dfmapdef
.parseMap(wst
);
414 on e
: TDynParseException
do
416 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
423 e_LogWritefln('ERROR: %s', [e
.message]);
430 //e_LogWriteln('map parsed.');
434 // ////////////////////////////////////////////////////////////////////////// //
436 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
437 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
438 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
441 function g_Texture_NumNameFindStart(name
: String): Boolean;
449 NNF_CurrentNum
:= -1;
451 for i
:= Length(name
) downto 1 do
452 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
454 if i
= Length(name
) then
455 begin // Íåò öèôð â êîíöå ñòðîêè
460 NNF_PureName
:= Copy(name
, 1, i
);
466 // Íå ïåðåâåñòè â ÷èñëî:
467 if not TryStrToInt(name
, NNF_FirstNum
) then
476 function g_Texture_NumNameFindNext(var newName
: String): Byte;
478 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
481 Result
:= NNF_NO_NAME
;
485 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
487 if NNF_CurrentNum
< NNF_FirstNum
then
488 Result
:= NNF_NAME_BEFORE
490 if NNF_CurrentNum
> NNF_FirstNum
then
491 Result
:= NNF_NAME_AFTER
493 Result
:= NNF_NAME_EQUALS
;
499 // ////////////////////////////////////////////////////////////////////////// //
500 function panelTypeToTag (panelType
: Word): Integer;
503 PANEL_WALL
: result
:= GridTagWall
; // gWalls
504 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
505 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
506 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
507 PANEL_WATER
: result
:= GridTagWater
; // gWater
508 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
509 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
510 PANEL_STEP
: result
:= GridTagStep
; // gSteps
511 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
512 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
513 else result
:= GridTagInvalid
;
518 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
520 if (a
.tag
< b
.tag
) then begin result
:= true; exit
; end;
521 if (a
.tag
> b
.tag
) then begin result
:= false; exit
; end;
522 result
:= (a
.arrIdx
< b
.arrIdx
);
525 procedure dplClear ();
527 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinHeapPanelDraw
.Create() else gDrawPanelList
.clear();
532 Textures
: TLevelTextureArray
= nil;
533 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
534 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
535 RespawnPoints
: array of TRespawnPoint
;
536 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
537 //DOMFlagPoints: Array of TFlagPoint;
540 procedure g_Map_ProfilersBegin ();
542 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
543 profMapCollision
.mainBegin(g_profile_collision
);
545 if g_profile_collision
then
547 profMapCollision
.sectionBegin('*solids');
548 profMapCollision
.sectionEnd();
549 profMapCollision
.sectionBegin('liquids');
550 profMapCollision
.sectionEnd();
554 procedure g_Map_ProfilersEnd ();
556 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
560 // wall index in `gWalls` or -1
561 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
565 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, (GridTagWall
or GridTagDoor
));
566 if (result
<> nil) then
568 if (hitx
<> nil) then hitx
^ := ex
;
569 if (hity
<> nil) then hity
^ := ey
;
573 if (hitx
<> nil) then hitx
^ := x1
;
574 if (hity
<> nil) then hity
^ := y1
;
578 // returns panel or nil
579 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
583 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, tag
);
584 if (result
<> nil) then
586 if (hitx
<> nil) then hitx
^ := ex
;
587 if (hity
<> nil) then hity
^ := ey
;
591 if (hitx
<> nil) then hitx
^ := x1
;
592 if (hity
<> nil) then hity
^ := y1
;
597 function xxPanAtPointChecker (pan
: TPanel
; panelType
: Word): Boolean; inline;
599 if ((pan
.tag
and GridTagLift
) <> 0) then
601 // stop if the lift of the right type
603 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
604 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
605 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
606 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
609 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
612 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
614 tagmask
: Integer = 0;
621 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
622 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
623 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
624 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
625 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
626 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
627 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
629 if (tagmask
= 0) then exit
;// just in case
631 pmark
:= framePool
.mark();
632 if ((tagmask
and GridTagLift
) <> 0) then
635 hitcount
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
);
636 ppan
:= PPanel(framePool
.getPtr(pmark
));
637 while (hitcount
> 0) do
639 if (xxPanAtPointChecker(ppan
^, PanelType
)) then begin result
:= true; break
; end;
647 result
:= (mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true) <> 0); // firsthit
649 framePool
.release(pmark
);
653 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
659 if (tagmask
= 0) then exit
;
660 pmark
:= framePool
.mark();
661 hitcount
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true); // firsthit
662 if (hitcount
<> 0) then result
:= PPanel(framePool
.getPtr(pmark
))^;
663 framePool
.release(pmark
);
667 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
669 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
670 (Texture
= TEXTURE_NAME_ACID1
) or
671 (Texture
= TEXTURE_NAME_ACID2
);
674 procedure CreateDoorMap();
676 PanelArray
: Array of record
682 a
, b
, c
, m
, i
, len
: Integer;
690 SetLength(PanelArray
, len
);
692 for a
:= 0 to High(gWalls
) do
693 if gWalls
[a
].Door
then
695 PanelArray
[i
].X
:= gWalls
[a
].X
;
696 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
697 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
698 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
699 PanelArray
[i
].Active
:= True;
700 PanelArray
[i
].PanelID
:= a
;
706 SetLength(PanelArray
, len
);
717 SetLength(gDoorMap
, 0);
719 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
722 if PanelArray
[a
].Active
then
724 PanelArray
[a
].Active
:= False;
725 m
:= Length(gDoorMap
);
726 SetLength(gDoorMap
, m
+1);
727 SetLength(gDoorMap
[m
], 1);
728 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
736 if PanelArray
[b
].Active
then
737 for c
:= 0 to High(gDoorMap
[m
]) do
738 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
739 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
740 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
741 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
742 gWalls
[gDoorMap
[m
, c
]].X
,
743 gWalls
[gDoorMap
[m
, c
]].Y
,
744 gWalls
[gDoorMap
[m
, c
]].Width
,
745 gWalls
[gDoorMap
[m
, c
]].Height
) then
747 PanelArray
[b
].Active
:= False;
748 SetLength(gDoorMap
[m
],
749 Length(gDoorMap
[m
])+1);
750 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
756 g_Game_StepLoading();
762 procedure CreateLiftMap();
764 PanelArray
: Array of record
769 a
, b
, c
, len
, i
, j
: Integer;
775 len
:= Length(gLifts
);
776 SetLength(PanelArray
, len
);
778 for a
:= 0 to len
-1 do
780 PanelArray
[a
].X
:= gLifts
[a
].X
;
781 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
782 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
783 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
784 PanelArray
[a
].Active
:= True;
787 SetLength(gLiftMap
, len
);
790 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
792 for a
:= 0 to len
-1 do
793 if PanelArray
[a
].Active
then
795 PanelArray
[a
].Active
:= False;
796 SetLength(gLiftMap
[i
], 32);
804 for b
:= 0 to len
-1 do
805 if PanelArray
[b
].Active
then
807 if g_CollideAround(PanelArray
[b
].X
,
810 PanelArray
[b
].Height
,
811 PanelArray
[gLiftMap
[i
, c
]].X
,
812 PanelArray
[gLiftMap
[i
, c
]].Y
,
813 PanelArray
[gLiftMap
[i
, c
]].Width
,
814 PanelArray
[gLiftMap
[i
, c
]].Height
) then
816 PanelArray
[b
].Active
:= False;
818 if j
> High(gLiftMap
[i
]) then
819 SetLength(gLiftMap
[i
],
820 Length(gLiftMap
[i
])+32);
829 SetLength(gLiftMap
[i
], j
+1);
832 g_Game_StepLoading();
835 SetLength(gLiftMap
, i
);
840 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
843 panels
: ^TPanelArray
;
849 case PanelRec
.PanelType
of
850 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
851 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
852 PANEL_FORE
: panels
:= @gRenderForegrounds
;
853 PANEL_WATER
: panels
:= @gWater
;
854 PANEL_ACID1
: panels
:= @gAcid1
;
855 PANEL_ACID2
: panels
:= @gAcid2
;
856 PANEL_STEP
: panels
:= @gSteps
;
857 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
858 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
862 len
:= Length(panels
^);
863 SetLength(panels
^, len
+1);
865 pguid
:= Length(panByGUID
);
866 SetLength(panByGUID
, pguid
+1); //FIXME!
867 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
869 assert(pguid
< Length(panByGUID
));
870 panByGUID
[pguid
] := pan
;
874 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
876 PanelRec
.user
['panel_guid'] := pguid
;
883 function CreateNullTexture(RecName
: String): Integer;
885 RecName
:= toLowerCase1251(RecName
);
886 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
887 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
889 SetLength(Textures
, Length(Textures
)+1);
890 result
:= High(Textures
);
892 with Textures
[High(Textures
)] do
894 TextureName
:= RecName
;
898 TextureID
:= LongWord(TEXTURE_NONE
);
901 TextNameHash
.put(RecName
, result
);
905 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
908 TextureData
: Pointer;
910 a
, ResLength
: Integer;
912 RecName
:= toLowerCase1251(RecName
);
913 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
914 if TextNameHash
.get(RecName
, result
) then
917 //e_LogWritefln('texture ''%s'' already loaded (%s)', [RecName, result]);
923 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
926 if Textures <> nil then
928 for a := 0 to High(Textures) do
930 if (Textures[a].TextureName = RecName) then
931 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
932 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
940 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
941 if (RecName
= TEXTURE_NAME_WATER
) or
942 (RecName
= TEXTURE_NAME_ACID1
) or
943 (RecName
= TEXTURE_NAME_ACID2
) then
945 SetLength(Textures
, Length(Textures
)+1);
947 with Textures
[High(Textures
)] do
949 TextureName
:= RecName
;
950 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
951 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
952 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
957 result
:= High(Textures
);
958 TextNameHash
.put(RecName
, result
);
962 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
963 WADName
:= g_ExtractWadName(RecName
);
965 WAD
:= TWADFile
.Create();
967 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
969 WAD
.ReadFile(WADName
);
973 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
975 FreeMem(TextureData);
976 RecName := 'COMMON\ALIEN';
980 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
982 SetLength(Textures
, Length(Textures
)+1);
983 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
985 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
986 SetLength(Textures
, Length(Textures
)-1);
990 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
991 FreeMem(TextureData
);
992 Textures
[High(Textures
)].TextureName
:= RecName
;
993 Textures
[High(Textures
)].Anim
:= False;
995 result
:= High(Textures
);
996 TextNameHash
.put(RecName
, result
);
998 else // Íåò òàêîãî ðåóñðñà â WAD'å
1000 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
1001 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1002 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
1004 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
1005 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1007 BadTextNameHash
.put(RecName
, -1);
1014 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1017 TextureWAD
: PChar = nil;
1018 TextData
: Pointer = nil;
1019 TextureData
: Pointer = nil;
1023 TextureResource
: String;
1024 _width
, _height
, _framecount
, _speed
: Integer;
1025 _backanimation
: Boolean;
1027 ia
: TDynImageDataArray
= nil;
1028 f
, c
, frdelay
, frloop
: Integer;
1030 RecName
:= toLowerCase1251(RecName
);
1031 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
1032 if TextNameHash
.get(RecName
, result
) then
1035 //e_LogWritefln('animated texture ''%s'' already loaded (%s)', [RecName, result]);
1041 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1043 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1044 if BadTextNameHash
.get(RecName
, f
) then
1046 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1050 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1051 WADName
:= g_ExtractWadName(RecName
);
1053 WAD
:= TWADFile
.Create();
1055 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
1057 WAD
.ReadFile(WADName
);
1059 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1061 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1062 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1064 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1065 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1067 BadTextNameHash
.put(RecName
, -1);
1072 if WADName = Map then
1074 //FreeMem(TextureWAD);
1075 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1081 if ResLength
< 6 then
1083 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), TMsgType
.Warning
);
1084 BadTextNameHash
.put(RecName
, -1);
1088 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1089 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1090 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1092 // íåò, ýòî ñóïåðìåí!
1093 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1095 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1096 BadTextNameHash
.put(RecName
, -1);
1100 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1101 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1103 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1104 BadTextNameHash
.put(RecName
, -1);
1108 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1110 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1111 if TextureResource
= '' then
1113 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), TMsgType
.Warning
);
1114 BadTextNameHash
.put(RecName
, -1);
1118 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1119 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1120 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1121 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1122 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1127 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1128 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1130 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), TMsgType
.Warning
);
1131 BadTextNameHash
.put(RecName
, -1);
1138 SetLength(Textures
, Length(Textures
)+1);
1139 with Textures
[High(Textures
)] do
1141 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1142 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1144 TextureName
:= RecName
;
1148 FramesCount
:= _framecount
;
1150 result
:= High(Textures
);
1151 TextNameHash
.put(RecName
, result
);
1155 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1156 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1158 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1160 BadTextNameHash
.put(RecName
, -1);
1166 // try animated image
1168 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1169 if length(imgfmt) = 0 then
1171 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1175 GlobalMetadata
.ClearMetaItems();
1176 GlobalMetadata
.ClearMetaItemsForSaving();
1177 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1179 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), TMsgType
.Warning
);
1180 BadTextNameHash
.put(RecName
, -1);
1183 if length(ia
) = 0 then
1185 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), TMsgType
.Warning
);
1186 BadTextNameHash
.put(RecName
, -1);
1193 _width
:= ia
[0].width
;
1194 _height
:= ia
[0].height
;
1195 _framecount
:= length(ia
);
1197 _backanimation
:= false;
1200 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1202 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1204 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1206 if f
< 0 then f
:= 0;
1209 if c
< 13 then c
:= 0 else c
:= 1;
1211 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1216 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1218 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1220 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1222 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1226 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1227 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1228 f
:= ord(_backanimation
);
1229 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
]), TMsgType
.Notify
);
1231 SetLength(Textures
, Length(Textures
)+1);
1232 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1233 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1235 Textures
[High(Textures
)].TextureName
:= RecName
;
1236 Textures
[High(Textures
)].Width
:= _width
;
1237 Textures
[High(Textures
)].Height
:= _height
;
1238 Textures
[High(Textures
)].Anim
:= True;
1239 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1240 Textures
[High(Textures
)].Speed
:= _speed
;
1241 result
:= High(Textures
);
1242 TextNameHash
.put(RecName
, result
);
1243 //writeln(' CREATED!');
1247 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1248 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1250 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), TMsgType
.Warning
);
1252 BadTextNameHash
.put(RecName
, -1);
1256 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1259 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1260 if (TextData
<> nil) then FreeMem(TextData
);
1261 if (TextureData
<> nil) then FreeMem(TextureData
);
1265 procedure CreateItem(Item
: TDynRecord
);
1267 if g_Game_IsClient
then Exit
;
1269 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1270 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1273 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1274 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1277 procedure CreateArea(Area
: TDynRecord
);
1282 case Area
.AreaType
of
1283 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1284 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1286 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1287 with RespawnPoints
[High(RespawnPoints
)] do
1291 Direction
:= TDirection(Area
.Direction
);
1293 case Area
.AreaType
of
1294 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1295 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1296 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1297 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1298 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1303 AREA_REDFLAG
, AREA_BLUEFLAG
:
1305 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1307 if FlagPoints
[a
] <> nil then Exit
;
1311 with FlagPoints
[a
]^ do
1313 X
:= Area
.X
-FLAGRECT
.X
;
1314 Y
:= Area
.Y
-FLAGRECT
.Y
;
1315 Direction
:= TDirection(Area
.Direction
);
1321 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1322 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1325 Animation
:= TAnimation
.Create(id
, True, 8);
1326 Obj
.Rect
:= FLAGRECT
;
1334 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1335 with DOMFlagPoints[High(DOMFlagPoints)] do
1339 Direction := TDirection(Area.Direction);
1342 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1347 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1352 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1356 mapId
:= Trigger
.id
;
1357 mapIndex
:= amapIdx
;
1360 Width
:= Trigger
.Width
;
1361 Height
:= Trigger
.Height
;
1362 Enabled
:= Trigger
.Enabled
;
1363 TexturePanelGUID
:= atpanid
;
1364 TriggerType
:= Trigger
.TriggerType
;
1365 ActivateType
:= Trigger
.ActivateType
;
1366 Keys
:= Trigger
.Keys
;
1367 trigPanelGUID
:= atrigpanid
;
1370 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1373 procedure CreateMonster(monster
: TDynRecord
);
1378 if g_Game_IsClient
then Exit
;
1380 if (gGameSettings
.GameType
= GT_SINGLE
)
1381 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1383 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1385 if gTriggers
<> nil then
1387 for a
:= 0 to High(gTriggers
) do
1389 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1391 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1392 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1397 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1401 procedure g_Map_ReAdd_DieTriggers();
1403 function monsDieTrig (mon
: TMonster
): Boolean;
1406 //tw: TStrTextWriter;
1408 result
:= false; // don't stop
1409 mon
.ClearTriggers();
1410 for a
:= 0 to High(gTriggers
) do
1412 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1414 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1416 tw := TStrTextWriter.Create();
1418 gTriggers[a].trigData.writeTo(tw);
1419 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1424 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1430 if g_Game_IsClient
then Exit
;
1432 g_Mons_ForEach(monsDieTrig
);
1435 function extractWadName(resourceName
: string): string;
1439 posN
:= Pos(':', resourceName
);
1441 Result
:= Copy(resourceName
, 0, posN
-1)
1446 procedure addResToExternalResList(res
: string);
1448 res
:= extractWadName(res
);
1449 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1450 gExternalResources
.Add(res
);
1453 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1455 //textures: TTexturesRec1Array;
1456 //textures: TDynField;
1458 //mapHeader: TMapHeaderRec_1;
1460 //resFile: String = '';
1462 if gExternalResources
= nil then
1463 gExternalResources
:= TStringList
.Create
;
1465 gExternalResources
.Clear
;
1469 textures := GetTextures(map);
1470 for i := 0 to High(textures) do
1472 addResToExternalResList(resFile);
1476 textures := map['texture'];
1477 if (textures <> nil) then
1479 for trec in textures do
1481 addResToExternalResList(resFile);
1488 //mapHeader := GetMapHeader(map);
1490 addResToExternalResList(map
.MusicName
);
1491 addResToExternalResList(map
.SkyName
);
1495 procedure mapCreateGrid ();
1497 mapX0
: Integer = $3fffffff;
1498 mapY0
: Integer = $3fffffff;
1499 mapX1
: Integer = -$3fffffff;
1500 mapY1
: Integer = -$3fffffff;
1502 procedure calcBoundingBox (constref panels
: TPanelArray
);
1507 for idx
:= 0 to High(panels
) do
1510 if not pan
.visvalid
then continue
;
1511 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1512 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1513 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1514 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1515 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1519 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1525 //tag := panelTypeToTag(tag);
1526 for idx
:= 0 to High(panels
) do
1529 if not pan
.visvalid
then continue
;
1530 if (pan
.proxyId
<> -1) then
1532 {$IF DEFINED(D2F_DEBUG)}
1533 e_WriteLog(Format('DUPLICATE wall #%d(%d) enabled (%d); type:%08x', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.PanelType
]), TMsgType
.Notify
);
1537 case pan
.PanelType
of
1538 PANEL_WALL
: newtag
:= GridTagWall
;
1539 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1540 PANEL_BACK
: newtag
:= GridTagBack
;
1541 PANEL_FORE
: newtag
:= GridTagFore
;
1542 PANEL_WATER
: newtag
:= GridTagWater
;
1543 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1544 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1545 PANEL_STEP
: newtag
:= GridTagStep
;
1546 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1547 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1548 else continue
; // oops
1552 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1553 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1554 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1555 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1557 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1559 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1570 calcBoundingBox(gWalls
);
1571 calcBoundingBox(gRenderBackgrounds
);
1572 calcBoundingBox(gRenderForegrounds
);
1573 calcBoundingBox(gWater
);
1574 calcBoundingBox(gAcid1
);
1575 calcBoundingBox(gAcid2
);
1576 calcBoundingBox(gSteps
);
1577 calcBoundingBox(gLifts
);
1578 calcBoundingBox(gBlockMon
);
1580 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1582 if (mapX0
> 0) then mapX0
:= 0;
1583 if (mapY0
> 0) then mapY0
:= 0;
1585 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1586 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1588 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1589 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1591 addPanelsToGrid(gWalls
);
1592 addPanelsToGrid(gRenderBackgrounds
);
1593 addPanelsToGrid(gRenderForegrounds
);
1594 addPanelsToGrid(gWater
);
1595 addPanelsToGrid(gAcid1
);
1596 addPanelsToGrid(gAcid2
);
1597 addPanelsToGrid(gSteps
);
1598 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1599 addPanelsToGrid(gBlockMon
);
1601 mapGrid
.dumpStats();
1603 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1607 function g_Map_Load(Res
: String): Boolean;
1609 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1610 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1614 //TexturePanel: Integer;
1617 trigrec
: TDynRecord
;
1619 texPanelIdx
: Integer;
1620 texPanel
: TDynRecord
;
1622 actPanelIdx
: Integer;
1623 actPanel
: TDynRecord
;
1626 WAD
, TestWAD
: TWADFile
;
1627 //mapReader: TDynRecord = nil;
1628 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1629 panels
: TDynField
= nil; //TPanelsRec1Array;
1630 items
: TDynField
= nil; //TItemsRec1Array;
1631 monsters
: TDynField
= nil; //TMonsterRec1Array;
1632 areas
: TDynField
= nil; //TAreasRec1Array;
1633 triggers
: TDynField
= nil; //TTriggersRec1Array;
1636 AddTextures
: TAddTextureArray
;
1637 TriggersTable
: array of TTRec
;
1638 FileName
, mapResName
, TexName
, s
: AnsiString;
1641 ok
, isAnim
: Boolean;
1642 CurTex
, ntn
: Integer;
1643 rec
, texrec
: TDynRecord
;
1645 pannum
, trignum
, cnt
, tgpid
: Integer;
1647 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1648 //moveActive: Boolean;
1650 mapOk
: Boolean = false;
1651 usedTextures
: THashStrInt
= nil; // key: mapTextureList
1658 //gCurrentMap.Free();
1659 //gCurrentMap := nil;
1664 gMapInfo
.Map
:= Res
;
1665 TriggersTable
:= nil;
1668 sfsGCDisable(); // temporary disable removing of temporary volumes
1670 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1671 if (gCurrentMap
= nil) then
1673 FileName
:= g_ExtractWadName(Res
);
1674 e_WriteLog('Loading map WAD: '+FileName
, TMsgType
.Notify
);
1675 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1677 WAD
:= TWADFile
.Create();
1678 if not WAD
.ReadFile(FileName
) then
1680 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1685 if gTestMap
<> '' then
1687 s
:= g_ExtractWadName(gTestMap
);
1688 TestWAD
:= TWADFile
.Create();
1689 if not TestWAD
.ReadFile(s
) then
1691 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [s
]));
1697 if TestWAD
<> nil then
1699 mapResName
:= g_ExtractFileName(gTestMap
);
1700 if not TestWAD
.GetMapResource(mapResName
, Data
, Len
) then
1702 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1705 e_WriteLog('Using test map: '+gTestMap
, TMsgType
.Notify
);
1712 //k8: why loader ignores path here?
1713 mapResName
:= g_ExtractFileName(Res
);
1714 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1716 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1726 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1732 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1733 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1735 stt
:= getTimeMicro();
1738 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1741 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1743 gCurrentMapFileName
:= '';
1749 if (gCurrentMap
= nil) then
1751 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1752 gCurrentMapFileName
:= '';
1758 stt
:= getTimeMicro();
1761 //gCurrentMap := mapReader;
1763 generateExternalResourcesList(gCurrentMap
);
1764 mapTextureList
:= gCurrentMap
['texture'];
1765 // get all other lists here too
1766 panels
:= gCurrentMap
['panel'];
1767 triggers
:= gCurrentMap
['trigger'];
1768 items
:= gCurrentMap
['item'];
1769 areas
:= gCurrentMap
['area'];
1770 monsters
:= gCurrentMap
['monster'];
1772 // Çàãðóçêà îïèñàíèÿ êàðòû:
1773 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1774 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1778 Name
:= gCurrentMap
.MapName
;
1779 Description
:= gCurrentMap
.MapDesc
;
1780 Author
:= gCurrentMap
.MapAuthor
;
1781 MusicName
:= gCurrentMap
.MusicName
;
1782 SkyName
:= gCurrentMap
.SkyName
;
1783 Height
:= gCurrentMap
.Height
;
1784 Width
:= gCurrentMap
.Width
;
1787 // Çàãðóçêà òåêñòóð:
1788 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1789 // Äîáàâëåíèå òåêñòóð â Textures[]:
1790 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1792 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1793 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1795 // find used textures
1796 usedTextures
:= THashStrInt
.Create();
1798 if (panels
<> nil) and (panels
.count
> 0) then
1800 for rec
in panels
do
1802 texrec
:= rec
.TextureRec
;
1803 if (texrec
<> nil) then usedTextures
.put(toLowerCase1251(texrec
.Resource
), 42);
1808 for rec
in mapTextureList
do
1811 if not usedTextures
.has(toLowerCase1251(rec
.Resource
)) then
1813 rec
.tagInt
:= -1; // just in case
1814 e_LogWritefln(' Unused texture #%d: %s', [cnt
, rec
.Resource
]);
1818 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1819 e_LogWritefln(' Loading texture #%d: %s', [cnt
, rec
.Resource
]);
1821 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1824 // Àíèìèðîâàííàÿ òåêñòóðà
1825 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1826 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [rec
.Resource
]));
1831 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1832 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [rec
.Resource
]));
1834 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1836 rec
.tagInt
:= ntn
; // remember texture number
1838 g_Game_StepLoading();
1841 usedTextures
.Free();
1844 // set panel tagInt to texture index
1845 if (panels
<> nil) then
1847 for rec
in panels
do
1849 texrec
:= rec
.TextureRec
;
1850 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1856 // Çàãðóçêà òðèããåðîâ
1857 gTriggerClientID
:= 0;
1858 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1859 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1862 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1863 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1865 // check texture numbers for panels
1866 if (panels
<> nil) and (panels
.count
> 0) then
1868 for rec
in panels
do
1870 if (rec
.tagInt
< 0) then
1872 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1876 gCurrentMapFileName
:= '';
1882 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1883 if (triggers
<> nil) and (triggers
.count
> 0) then
1885 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1886 //SetLength(TriggersTable, triggers.count);
1887 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1889 SetLength(TriggersTable
, triggers
.count
);
1891 for rec
in triggers
do
1894 pttit
:= @TriggersTable
[trignum
];
1895 pttit
.trigrec
:= rec
;
1896 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1897 pttit
.texPanelIdx
:= -1; // will be fixed later
1898 pttit
.texPanel
:= rec
.TexturePanelRec
;
1900 pttit
.actPanelIdx
:= -1;
1901 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1903 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1904 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1906 g_Game_StepLoading();
1911 if (panels
<> nil) and (panels
.count
> 0) then
1913 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1914 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1917 for rec
in panels
do
1920 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1922 SetLength(AddTextures
, 0);
1926 if (mapTextureList
<> nil) then
1928 texrec
:= rec
.TextureRec
;
1929 ok
:= (texrec
<> nil);
1934 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1935 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1937 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1939 if rec
.userPanelTrigRef
then
1941 // e_LogWritefln('trigref for panel %s', [pannum]);
1949 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1950 s
:= texrec
.Resource
;
1952 // Ñïåö-òåêñòóðû çàïðåùåíû
1953 if g_Map_IsSpecialTexture(s
) then
1959 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1960 ok
:= g_Texture_NumNameFindStart(s
);
1963 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1964 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1967 k
:= NNF_NAME_BEFORE
;
1968 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1969 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1971 k
:= g_Texture_NumNameFindNext(TexName
);
1973 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1975 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1978 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1980 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1981 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1982 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1985 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1987 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1988 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1989 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1994 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1996 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1997 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1998 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2001 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
2003 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2004 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2005 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2009 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
2013 for c := 0 to High(Textures) do
2015 if (Textures[c].TextureName = TexName) then
2017 SetLength(AddTextures, Length(AddTextures)+1);
2018 AddTextures[High(AddTextures)].Texture := c;
2019 AddTextures[High(AddTextures)].Anim := isAnim;
2024 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
2026 SetLength(AddTextures
, Length(AddTextures
)+1);
2027 AddTextures
[High(AddTextures
)].Texture
:= c
;
2028 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
2034 if k
= NNF_NAME_EQUALS
then
2036 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
2037 SetLength(AddTextures
, Length(AddTextures
)+1);
2038 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
2039 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
2040 CurTex
:= High(AddTextures
);
2051 end; // if ok - åñòü ñìåæíûå òåêñòóðû
2052 end; // if ok - ññûëàþòñÿ òðèããåðû
2056 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
2057 SetLength(AddTextures
, 1);
2058 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
2059 AddTextures
[0].Anim
:= false;
2060 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2064 //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);
2066 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2068 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2069 //e_LogWritefln('new panel; tcount=%s; curtex=%s', [Length(AddTextures), CurTex]);
2070 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2071 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2072 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2075 moveSpeed
:= rec
.moveSpeed
;
2076 //moveStart := rec.moveStart;
2077 //moveEnd := rec.moveEnd;
2078 //moveActive := rec['move_active'].value;
2079 if not moveSpeed
.isZero
then
2081 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2082 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2083 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2086 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2088 g_Game_StepLoading();
2092 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2093 for b
:= 0 to High(TriggersTable
) do
2095 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
2096 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
2099 // create map grid, init other grids (for monsters, for example)
2100 e_WriteLog('Creating map grid', TMsgType
.Notify
);
2103 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2104 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2106 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2107 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2108 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2110 for rec
in triggers
do
2113 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
2114 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2115 TriggersTable
[trignum
].tnum
:= trignum
;
2116 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
2120 //FIXME: use hashtable!
2121 for pan
in panByGUID
do
2123 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2125 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2127 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2129 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2133 // Çàãðóçêà ïðåäìåòîâ
2134 e_WriteLog(' Loading items...', TMsgType
.Notify
);
2135 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2137 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2138 if (items
<> nil) and not gLoadGameMode
then
2140 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
2141 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2142 for rec
in items
do CreateItem(rec
);
2145 // Çàãðóçêà îáëàñòåé
2146 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
2147 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2149 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2150 if areas
<> nil then
2152 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
2153 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2154 for rec
in areas
do CreateArea(rec
);
2157 // Çàãðóçêà ìîíñòðîâ
2158 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
2159 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2161 gTotalMonsters
:= 0;
2163 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2164 if (monsters
<> nil) and not gLoadGameMode
then
2166 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
2167 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2168 for rec
in monsters
do CreateMonster(rec
);
2171 //gCurrentMap := mapReader; // this will be our current map now
2172 gCurrentMapFileName
:= Res
;
2176 if (gMapInfo
.SkyName
<> '') then
2178 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
2179 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2180 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2182 if (FileName
<> '') then FileName
:= GameDir
+'/wads/'+FileName
else FileName
:= g_ExtractWadName(Res
);
2184 if gTextureFilter
then TEXTUREFILTER
:= GL_LINEAR
else TEXTUREFILTER
:= GL_NEAREST
;
2186 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2187 if g_Texture_CreateWAD(BackID
, s
) then
2189 g_Game_SetupScreenSize();
2193 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2196 TEXTUREFILTER
:= GL_NEAREST
;
2202 if gMapInfo
.MusicName
<> '' then
2204 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
2205 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2206 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2208 if FileName
<> '' then
2209 FileName
:= GameDir
+'/wads/'+FileName
2212 FileName
:= g_ExtractWadName(Res
);
2215 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2216 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2219 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2222 // Îñòàëüíûå óñòàíâêè
2230 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2231 if not gLoadGameMode
then g_GFX_Init();
2233 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2234 mapTextureList
:= nil;
2239 TriggersTable
:= nil;
2242 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2243 if ok
and (not gLoadGameMode
) then
2245 gMusic
.SetByName(gMapInfo
.MusicName
);
2250 gMusic
.SetByName('');
2253 stt
:= getTimeMicro()-stt
;
2254 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2257 sfsGCEnable(); // enable releasing unused volumes
2259 e_ClearInputBuffer(); // why not?
2264 gCurrentMapFileName
:= '';
2268 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2273 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2276 mapReader
: TDynRecord
;
2277 //Header: TMapHeaderRec_1;
2282 FillChar(Result
, SizeOf(Result
), 0);
2283 FileName
:= g_ExtractWadName(Res
);
2285 WAD
:= TWADFile
.Create();
2286 if not WAD
.ReadFile(FileName
) then
2292 //k8: it ignores path again
2293 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2302 mapReader
:= g_Map_ParseMap(Data
, Len
);
2311 if (mapReader
= nil) then exit
;
2313 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2315 Result
.Name
:= mapReader
.MapName
;
2316 Result
.Description
:= mapReader
.MapDesc
;
2318 Result
.Author
:= mapReader
.MapAuthor
;
2319 Result
.Height
:= mapReader
.Height
;
2320 Result
.Width
:= mapReader
.Width
;
2324 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2325 //ZeroMemory(@Header, SizeOf(Header));
2326 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2327 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2329 Result
.Author
:= '';
2337 function g_Map_GetMapsList(WADName
: string): SSArray
;
2344 WAD
:= TWADFile
.Create();
2345 if not WAD
.ReadFile(WADName
) then
2350 ResList
:= WAD
.GetMapResources();
2351 if ResList
<> nil then
2353 for a
:= 0 to High(ResList
) do
2355 SetLength(Result
, Length(Result
)+1);
2356 Result
[High(Result
)] := ResList
[a
];
2362 function g_Map_Exist(Res
: string): Boolean;
2365 FileName
, mnn
: string;
2371 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2373 WAD
:= TWADFile
.Create
;
2374 if not WAD
.ReadFile(FileName
) then
2380 ResList
:= WAD
.GetMapResources();
2383 mnn
:= g_ExtractFileName(Res
);
2384 if ResList
<> nil then
2385 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2392 procedure g_Map_Free(freeTextures
: Boolean=true);
2396 procedure FreePanelArray(var panels
: TPanelArray
);
2401 if panels
<> nil then
2403 for i
:= 0 to High(panels
) do
2416 RespawnPoints
:= nil;
2417 if FlagPoints
[FLAG_RED
] <> nil then
2419 Dispose(FlagPoints
[FLAG_RED
]);
2420 FlagPoints
[FLAG_RED
] := nil;
2422 if FlagPoints
[FLAG_BLUE
] <> nil then
2424 Dispose(FlagPoints
[FLAG_BLUE
]);
2425 FlagPoints
[FLAG_BLUE
] := nil;
2427 //DOMFlagPoints := nil;
2431 if (Length(gCurrentMapFileName
) <> 0) then
2433 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2437 e_LogWritefln('g_Map_Free: no previous map.', []);
2440 if freeTextures
then
2442 e_LogWritefln('g_Map_Free: clearing textures...', []);
2443 if (Textures
<> nil) then
2445 for a
:= 0 to High(Textures
) do
2447 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2449 if Textures
[a
].Anim
then
2451 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2455 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2457 e_DeleteTexture(Textures
[a
].TextureID
);
2464 TextNameHash
.Free();
2465 TextNameHash
:= nil;
2466 BadTextNameHash
.Free();
2467 BadTextNameHash
:= nil;
2468 gCurrentMapFileName
:= '';
2475 FreePanelArray(gWalls
);
2476 FreePanelArray(gRenderBackgrounds
);
2477 FreePanelArray(gRenderForegrounds
);
2478 FreePanelArray(gWater
);
2479 FreePanelArray(gAcid1
);
2480 FreePanelArray(gAcid2
);
2481 FreePanelArray(gSteps
);
2482 FreePanelArray(gLifts
);
2483 FreePanelArray(gBlockMon
);
2484 gMovingWallIds
:= nil;
2486 if BackID
<> DWORD(-1) then
2490 e_DeleteTexture(BackID
);
2491 BackID
:= DWORD(-1);
2494 g_Game_StopAllSounds(False);
2496 g_Sound_Delete(gMapInfo
.MusicName
);
2498 gMapInfo
.Name
:= '';
2499 gMapInfo
.Description
:= '';
2500 gMapInfo
.MusicName
:= '';
2501 gMapInfo
.Height
:= 0;
2502 gMapInfo
.Width
:= 0;
2508 procedure g_Map_Update();
2514 procedure UpdatePanelArray(var panels
: TPanelArray
);
2519 for i
:= 0 to High(panels
) do panels
[i
].Update();
2523 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2525 UpdatePanelArray(gWalls
);
2526 UpdatePanelArray(gRenderBackgrounds
);
2527 UpdatePanelArray(gRenderForegrounds
);
2528 UpdatePanelArray(gWater
);
2529 UpdatePanelArray(gAcid1
);
2530 UpdatePanelArray(gAcid2
);
2531 UpdatePanelArray(gSteps
);
2533 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2535 if gGameSettings
.GameMode
= GM_CTF
then
2537 for a
:= FLAG_RED
to FLAG_BLUE
do
2539 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2543 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2545 m
:= g_Obj_Move(@Obj
, True, True);
2547 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2549 // Ñîïðîòèâëåíèå âîçäóõà
2550 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2552 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2553 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2556 gFlags
[a
].CaptureTime
:= 0;
2557 if a
= FLAG_RED
then
2558 s
:= _lc
[I_PLAYER_FLAG_RED
]
2560 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2561 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2563 if g_Game_IsNet
then
2564 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2568 if Count
> 0 then Count
-= 1;
2571 if gPlayers
<> nil then
2573 j
:= Random(Length(gPlayers
)) - 1;
2574 for d
:= 0 to High(gPlayers
) do
2577 if j
> High(gPlayers
) then j
:= 0;
2578 if gPlayers
[j
] <> nil then
2580 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2582 if gPlayers
[j
].GetFlag(a
) then Break
;
2595 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2597 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2601 if (panels
<> nil) then
2603 // alas, no visible set
2604 for idx
:= 0 to High(panels
) do
2606 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw(hasAmbient
, ambColor
);
2613 PANEL_WALL
: DrawPanels(gWalls
);
2614 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2615 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2616 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2617 PANEL_WATER
: DrawPanels(gWater
);
2618 PANEL_ACID1
: DrawPanels(gAcid1
);
2619 PANEL_ACID2
: DrawPanels(gAcid2
);
2620 PANEL_STEP
: DrawPanels(gSteps
);
2626 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2633 pmark
:= framePool
.mark();
2634 hitcount
:= mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, GridDrawableMask
);
2635 if (hitcount
= 0) then exit
;
2636 phit
:= PPanel(framePool
.getPtr(pmark
));
2637 while (hitcount
> 0) do
2639 if (((phit
^.tag
and GridTagDoor
) <> 0) = phit
^.Door
) then gDrawPanelList
.insert(phit
^);
2643 framePool
.release(pmark
);
2644 // list will be rendered in `g_game.DrawPlayer()`
2648 procedure g_Map_DrawPanelShadowVolumes (lightX
: Integer; lightY
: Integer; radius
: Integer);
2654 pmark
:= framePool
.mark();
2655 hitcount
:= mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, (GridTagWall
or GridTagDoor
));
2656 if (hitcount
= 0) then exit
;
2657 phit
:= PPanel(framePool
.getPtr(pmark
));
2658 while (hitcount
> 0) do
2660 phit
^.DrawShadowVolume(lightX
, lightY
, radius
);
2664 framePool
.release(pmark
);
2668 procedure g_Map_DrawBack(dx
, dy
: Integer);
2670 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2671 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2673 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2676 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2677 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2683 if WordBool(PanelType
and PANEL_WALL
) then
2684 if gWalls
<> nil then
2689 if gWalls
[a
].Enabled
and
2690 g_Collide(X
, Y
, Width
, Height
,
2691 gWalls
[a
].X
, gWalls
[a
].Y
,
2692 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2699 if WordBool(PanelType
and PANEL_WATER
) then
2700 if gWater
<> nil then
2705 if g_Collide(X
, Y
, Width
, Height
,
2706 gWater
[a
].X
, gWater
[a
].Y
,
2707 gWater
[a
].Width
, gWater
[a
].Height
) then
2714 if WordBool(PanelType
and PANEL_ACID1
) then
2715 if gAcid1
<> nil then
2720 if g_Collide(X
, Y
, Width
, Height
,
2721 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2722 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2729 if WordBool(PanelType
and PANEL_ACID2
) then
2730 if gAcid2
<> nil then
2735 if g_Collide(X
, Y
, Width
, Height
,
2736 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2737 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2744 if WordBool(PanelType
and PANEL_STEP
) then
2745 if gSteps
<> nil then
2750 if g_Collide(X
, Y
, Width
, Height
,
2751 gSteps
[a
].X
, gSteps
[a
].Y
,
2752 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2759 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2760 if gLifts
<> nil then
2765 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2766 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2767 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2768 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2769 g_Collide(X
, Y
, Width
, Height
,
2770 gLifts
[a
].X
, gLifts
[a
].Y
,
2771 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2778 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2779 if gBlockMon
<> nil then
2781 h
:= High(gBlockMon
);
2785 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2786 g_Collide(X
, Y
, Width
, Height
,
2787 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2788 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2796 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2800 function checkPanels (constref panels
: TPanelArray
): Boolean;
2805 if panels
= nil then exit
;
2806 for a
:= 0 to High(panels
) do
2808 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2811 texid
:= panels
[a
].GetTextureID();
2818 texid
:= LongWord(TEXTURE_NONE
);
2820 if not checkPanels(gWater
) then
2821 if not checkPanels(gAcid1
) then
2822 if not checkPanels(gAcid2
) then exit
;
2827 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2829 SlowMask
= GridTagLift
or GridTagBlockMon
;
2831 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2834 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2836 result := pan.Enabled;
2841 if ((tag
and GridTagLift
) <> 0) then
2844 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2845 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2846 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2847 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2848 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2852 if ((tag
and GridTagBlockMon
) <> 0) then
2854 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2859 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2860 result
:= true; // i found her!
2864 tagmask
: Integer = 0;
2871 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2872 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2873 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2874 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2875 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2876 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2877 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2879 if (tagmask
= 0) then exit
; // just in case
2881 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2882 if gdbg_map_use_accel_coldet
then
2884 pmark
:= framePool
.mark();
2885 if ((tagmask
and SlowMask
) <> 0) then
2888 hitcount
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
);
2889 phit
:= PPanel(framePool
.getPtr(pmark
));
2890 while (hitcount
> 0) do
2893 if ((pan
.tag
and GridTagLift
) <> 0) then
2896 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2897 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2898 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2899 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2900 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2902 else if ((pan
.tag
and GridTagBlockMon
) <> 0) then
2904 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2909 result
:= true; // i found her!
2911 if (result
) then break
;
2919 hitcount
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
, false, true); // return first hit
2920 result
:= (hitcount
> 0);
2922 framePool
.release(pmark
);
2926 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2928 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2932 // returns `true` if we need to stop
2933 function liquidChecker (pan
: TPanel
; var texid
: DWORD
; var cctype
: Integer): Boolean; inline;
2936 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2939 0: if ((pan
.tag
and GridTagWater
) = 0) then exit
; // allowed: water
2940 1: if ((pan
.tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2941 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2944 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2946 texid
:= pan
.GetTextureID();
2947 // water? water has the highest priority, so stop right here
2948 if ((pan
.tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2950 if ((pan
.tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2952 if ((pan
.tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2955 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2957 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2963 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2964 if gdbg_map_use_accel_coldet
then
2966 result
:= LongWord(TEXTURE_NONE
);
2967 pmark
:= framePool
.mark();
2968 hitcount
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2969 if (hitcount
= 0) then exit
;
2970 phit
:= PPanel(framePool
.getPtr(pmark
));
2971 while (hitcount
> 0) do
2976 if (liquidChecker(pan
, result
, cctype
)) then break
;
2978 framePool
.release(pmark
);
2982 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2984 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2988 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2989 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2990 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2993 procedure g_Map_EnableWallGUID (pguid
: Integer);
2997 //pan := gWalls[ID];
2998 pan
:= g_Map_PanelByGUID(pguid
);
2999 if (pan
= nil) then exit
;
3000 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
3002 pan
.Enabled
:= True;
3003 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
3005 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
3006 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
3007 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
3009 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3010 // mark platform as interesting
3013 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
3014 //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);
3019 procedure g_Map_DisableWallGUID (pguid
: Integer);
3023 //pan := gWalls[ID];
3024 pan
:= g_Map_PanelByGUID(pguid
);
3025 if (pan
= nil) then exit
;
3026 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
3028 pan
.Enabled
:= False;
3029 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
3031 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
3032 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
3034 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3035 // mark platform as interesting
3038 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
3039 //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);
3044 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
3048 tp
:= g_Map_PanelByGUID(pguid
);
3049 if (tp
= nil) then exit
;
3050 tp
.NextTexture(AnimLoop
);
3051 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
3055 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
3059 //pan := gLifts[ID];
3060 pan
:= g_Map_PanelByGUID(pguid
);
3061 if (pan
= nil) then exit
;
3062 if not pan
.isGLift
then exit
;
3064 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
3066 with {gLifts[ID]} pan
do
3070 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
3071 //TODO: make separate lift tags, and change tag here
3074 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
3075 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
3076 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
3077 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
3080 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3081 // mark platform as interesting
3087 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
3090 PointsArray
: Array of TRespawnPoint
;
3093 SetLength(PointsArray
, 0);
3095 if RespawnPoints
= nil then
3098 for a
:= 0 to High(RespawnPoints
) do
3099 if RespawnPoints
[a
].PointType
= PointType
then
3101 SetLength(PointsArray
, Length(PointsArray
)+1);
3102 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3105 if PointsArray
= nil then
3108 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3112 function g_Map_GetPointCount(PointType
: Byte): Word;
3118 if RespawnPoints
= nil then
3121 for a
:= 0 to High(RespawnPoints
) do
3122 if RespawnPoints
[a
].PointType
= PointType
then
3123 Result
:= Result
+ 1;
3126 function g_Map_HaveFlagPoints(): Boolean;
3128 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3131 procedure g_Map_ResetFlag(Flag
: Byte);
3133 with gFlags
[Flag
] do
3139 Direction
:= TDirection
.D_LEFT
;
3140 State
:= FLAG_STATE_NONE
;
3141 if FlagPoints
[Flag
] <> nil then
3143 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3144 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3145 Direction
:= FlagPoints
[Flag
]^.Direction
;
3146 State
:= FLAG_STATE_NORMAL
;
3152 procedure g_Map_DrawFlags();
3155 Mirror
: TMirrorType
;
3157 if gGameSettings
.GameMode
<> GM_CTF
then
3160 for i
:= FLAG_RED
to FLAG_BLUE
do
3162 if State
<> FLAG_STATE_CAPTURED
then
3164 if State
= FLAG_STATE_NONE
then
3167 if Direction
= TDirection
.D_LEFT
then
3169 Mirror
:= TMirrorType
.Horizontal
;
3174 Mirror
:= TMirrorType
.None
;
3178 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3180 if g_debug_Frames
then
3182 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3184 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3185 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3192 procedure g_Map_SaveState (st
: TStream
);
3196 procedure savePanels ();
3201 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
3202 for pan
in panByGUID
do pan
.SaveState(st
);
3205 procedure saveFlag (flag
: PFlag
);
3209 utils
.writeSign(st
, 'FLAG');
3210 utils
.writeInt(st
, Byte(0)); // version
3211 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3212 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
3214 utils
.writeInt(st
, Byte(flag
^.State
));
3215 // Íàïðàâëåíèå ôëàãà
3216 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3217 utils
.writeInt(st
, Byte(b
));
3219 Obj_SaveState(st
, @flag
^.Obj
);
3226 utils
.writeSign(st
, 'MUSI');
3227 utils
.writeInt(st
, Byte(0));
3229 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3230 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3231 utils
.writeStr(st
, str
);
3232 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3233 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
3234 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3235 utils
.writeBool(st
, gMusic
.SpecPause
);
3237 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3238 utils
.writeInt(st
, LongInt(gTotalMonsters
));
3241 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3242 if (gGameSettings
.GameMode
= GM_CTF
) then
3244 // Ôëàã Êðàñíîé êîìàíäû
3245 saveFlag(@gFlags
[FLAG_RED
]);
3246 // Ôëàã Ñèíåé êîìàíäû
3247 saveFlag(@gFlags
[FLAG_BLUE
]);
3251 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3252 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3254 // Î÷êè Êðàñíîé êîìàíäû
3255 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Goals
));
3256 // Î÷êè Ñèíåé êîìàíäû
3257 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Goals
));
3263 procedure g_Map_LoadState (st
: TStream
);
3269 procedure loadPanels ();
3274 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
3275 for pan
in panByGUID
do
3278 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3282 procedure loadFlag (flag
: PFlag
);
3287 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
3288 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
3289 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3290 flag
^.RespawnType
:= utils
.readByte(st
);
3292 flag
^.State
:= utils
.readByte(st
);
3293 // Íàïðàâëåíèå ôëàãà
3294 b
:= utils
.readByte(st
);
3295 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
3297 Obj_LoadState(@flag
^.Obj
, st
);
3301 if (st
= nil) then exit
;
3303 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3307 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3311 ///// Çàãðóæàåì ìóçûêó: /////
3312 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
3313 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
3315 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3316 str
:= utils
.readStr(st
);
3317 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3318 dw
:= utils
.readLongWord(st
);
3319 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3320 boo
:= utils
.readBool(st
);
3321 // Çàïóñêàåì ýòó ìóçûêó
3322 gMusic
.SetByName(str
);
3323 gMusic
.SpecPause
:= boo
;
3326 gMusic
.SetPosition(dw
);
3329 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3330 gTotalMonsters
:= utils
.readLongInt(st
);
3333 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3334 if (gGameSettings
.GameMode
= GM_CTF
) then
3336 // Ôëàã Êðàñíîé êîìàíäû
3337 loadFlag(@gFlags
[FLAG_RED
]);
3338 // Ôëàã Ñèíåé êîìàíäû
3339 loadFlag(@gFlags
[FLAG_BLUE
]);
3343 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3344 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3346 // Î÷êè Êðàñíîé êîìàíäû
3347 gTeamStat
[TEAM_RED
].Goals
:= utils
.readSmallInt(st
);
3348 // Î÷êè Ñèíåé êîìàíäû
3349 gTeamStat
[TEAM_BLUE
].Goals
:= utils
.readSmallInt(st
);
3355 // trace liquid, stepping by `dx` and `dy`
3356 // return last seen liquid coords, and `false` if we're started outside of the liquid
3357 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3359 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3363 // started outside of the liquid?
3364 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
3365 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3366 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3372 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
3373 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3381 DynWarningCB
:= mapWarningCB
;