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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
16 {$DEFINE MAP_DEBUG_ENABLED_FLAG}
22 SysUtils
, Classes
, mempool
,
23 e_graphics
, g_basic
, MAPDEF
, g_textures
,
24 g_phys
, utils
, 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): SSArray
;
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; hasAmbient
: Boolean; constref ambColor
: TDFColor
); // 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 (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 (st
: TStream
);
99 procedure g_Map_LoadState (st
: TStream
);
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 is nested
; // 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 // return `true` from `cb` to stop
123 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
125 procedure g_Map_NetSendInterestingPanels (); // yay!
128 procedure g_Map_ProfilersBegin ();
129 procedure g_Map_ProfilersEnd ();
132 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
135 function g_Map_MinX (): Integer; inline;
136 function g_Map_MinY (): Integer; inline;
137 function g_Map_MaxX (): Integer; inline;
138 function g_Map_MaxY (): Integer; inline;
146 function g_Texture_NumNameFindStart(name
: String): Boolean;
147 function g_Texture_NumNameFindNext(var newName
: String): Byte;
150 RESPAWNPOINT_PLAYER1
= 1;
151 RESPAWNPOINT_PLAYER2
= 2;
153 RESPAWNPOINT_RED
= 4;
154 RESPAWNPOINT_BLUE
= 5;
162 FLAG_STATE_NORMAL
= 1;
163 FLAG_STATE_DROPPED
= 2;
164 FLAG_STATE_CAPTURED
= 3;
165 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
166 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
168 FLAG_TIME
= 720; // 20 seconds
170 SKY_STRETCH
: Single = 1.5;
185 // sorted by draw priority
186 GridTagBack
= 1 shl 0; // gRenderBackgrounds
187 GridTagStep
= 1 shl 1; // gSteps
188 GridTagWall
= 1 shl 2; // gWalls
189 GridTagDoor
= 1 shl 3; // gWalls
190 GridTagAcid1
= 1 shl 4; // gAcid1
191 GridTagAcid2
= 1 shl 5; // gAcid2
192 GridTagWater
= 1 shl 6; // gWater
193 GridTagFore
= 1 shl 7; // gRenderForegrounds
194 // the following are invisible
195 GridTagLift
= 1 shl 8; // gLifts
196 GridTagBlockMon
= 1 shl 9; // gBlockMon
198 GridTagSolid
= (GridTagWall
or GridTagDoor
);
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
: array of TDiskFileInfo
= nil;
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 {$INCLUDE ../nogl/noGLuses.inc}
256 e_input
, g_main
, e_log
, e_texture
, e_res
, g_items
, g_gfx
, g_console
,
257 g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
258 g_options
, g_triggers
, g_player
,
259 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
260 sfs
, xstreams
, hashtable
, wadreader
,
261 ImagingTypes
, Imaging
, ImagingUtility
,
262 ImagingGif
, ImagingNetworkGraphics
,
266 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
267 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
268 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
271 // ////////////////////////////////////////////////////////////////////////// //
272 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
276 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
280 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
285 // ////////////////////////////////////////////////////////////////////////// //
287 panByGUID
: array of TPanel
= nil;
290 // ////////////////////////////////////////////////////////////////////////// //
291 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
293 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
294 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
298 // return `true` from `cb` to stop
299 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
304 if not assigned(cb
) then exit
;
305 for pan
in panByGUID
do
307 if cb(pan
) then begin result
:= pan
; exit
; end;
312 procedure g_Map_NetSendInterestingPanels ();
316 if g_Game_IsServer
and g_Game_IsNet
then
318 for pan
in panByGUID
do
320 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
326 // ////////////////////////////////////////////////////////////////////////// //
327 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
328 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
329 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
330 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
333 // ////////////////////////////////////////////////////////////////////////// //
335 dfmapdef
: TDynMapDef
= nil;
338 procedure loadMapDefinition ();
340 pr
: TTextParser
= nil;
344 if (dfmapdef
<> nil) then exit
;
347 e_LogWritefln('parsing "mapdef.txt"...', []);
348 st
:= e_OpenResourceRO(DataDirs
, 'mapdef.txt');
349 e_LogWritefln('found local "mapdef.txt"', []);
356 WAD
:= TWADFile
.Create();
357 if not WAD
.ReadFile(GameWAD
) then
359 //raise Exception.Create('cannot load "game.wad"');
364 st
:= WAD
.openFileStream('mapdef.txt');
371 //raise Exception.Create('cannot open "mapdef.txt"');
372 e_LogWriteln('using default "mapdef.txt"...');
373 pr
:= TStrTextParser
.Create(defaultMapDef
);
377 pr
:= TFileTextParser
.Create(st
);
379 except on e
: Exception
do
381 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
387 dfmapdef
:= TDynMapDef
.Create(pr
);
389 on e
: TDynParseException
do
390 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
392 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
400 // ////////////////////////////////////////////////////////////////////////// //
401 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
403 wst
: TSFSMemoryChunkStream
= nil;
406 if (dataLen
< 4) then exit
;
408 if (dfmapdef
= nil) then writeln('need to load mapdef');
410 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
412 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
414 result
:= dfmapdef
.parseMap(wst
);
416 on e
: TDynParseException
do
418 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
425 e_LogWritefln('ERROR: %s', [e
.message]);
432 //e_LogWriteln('map parsed.');
436 // ////////////////////////////////////////////////////////////////////////// //
438 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
439 NNF_PureExt
: String; // extension postfix
440 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
441 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
444 function g_Texture_NumNameFindStart(name
: String): Boolean;
453 NNF_CurrentNum
:= -1;
455 for i
:= Length(name
) downto 1 do
456 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
458 if i
= Length(name
) then
459 begin // Íåò öèôð â êîíöå ñòðîêè
465 while (j
<= Length(name
)) and (name
[j
] <> '.') do inc(j
);
466 NNF_PureName
:= Copy(name
, 1, i
);
467 NNF_PureExt
:= Copy(name
, j
);
468 name
:= Copy(name
, i
+ 1, j
- i
- 1);
473 // Íå ïåðåâåñòè â ÷èñëî:
474 if not TryStrToInt(name
, NNF_FirstNum
) then
483 function g_Texture_NumNameFindNext(var newName
: String): Byte;
485 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
488 Result
:= NNF_NO_NAME
;
492 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
) + NNF_PureExt
;
494 if NNF_CurrentNum
< NNF_FirstNum
then
495 Result
:= NNF_NAME_BEFORE
497 if NNF_CurrentNum
> NNF_FirstNum
then
498 Result
:= NNF_NAME_AFTER
500 Result
:= NNF_NAME_EQUALS
;
506 // ////////////////////////////////////////////////////////////////////////// //
507 function panelTypeToTag (panelType
: Word): Integer;
510 PANEL_WALL
: result
:= GridTagWall
; // gWalls
511 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
512 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
513 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
514 PANEL_WATER
: result
:= GridTagWater
; // gWater
515 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
516 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
517 PANEL_STEP
: result
:= GridTagStep
; // gSteps
518 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
519 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
520 else result
:= GridTagInvalid
;
525 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
527 if (a
.tag
< b
.tag
) then begin result
:= true; exit
; end;
528 if (a
.tag
> b
.tag
) then begin result
:= false; exit
; end;
529 result
:= (a
.arrIdx
< b
.arrIdx
);
532 procedure dplClear ();
534 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinHeapPanelDraw
.Create() else gDrawPanelList
.clear();
539 Textures
: TLevelTextureArray
= nil;
540 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
541 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
542 RespawnPoints
: array of TRespawnPoint
;
543 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
544 //DOMFlagPoints: Array of TFlagPoint;
547 procedure g_Map_ProfilersBegin ();
549 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
550 if (profMapCollision
<> nil) then profMapCollision
.mainBegin(g_profile_collision
);
552 if g_profile_collision
and (profMapCollision
<> nil) then
554 profMapCollision
.sectionBegin('*solids');
555 profMapCollision
.sectionEnd();
556 profMapCollision
.sectionBegin('liquids');
557 profMapCollision
.sectionEnd();
561 procedure g_Map_ProfilersEnd ();
563 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
567 // wall index in `gWalls` or -1
568 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
572 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, (GridTagWall
or GridTagDoor
));
573 if (result
<> nil) then
575 if (hitx
<> nil) then hitx
^ := ex
;
576 if (hity
<> nil) then hity
^ := ey
;
580 if (hitx
<> nil) then hitx
^ := x1
;
581 if (hity
<> nil) then hity
^ := y1
;
585 // returns panel or nil
586 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
590 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, tag
);
591 if (result
<> nil) then
593 if (hitx
<> nil) then hitx
^ := ex
;
594 if (hity
<> nil) then hity
^ := ey
;
598 if (hitx
<> nil) then hitx
^ := x1
;
599 if (hity
<> nil) then hity
^ := y1
;
604 function xxPanAtPointChecker (pan
: TPanel
; panelType
: Word): Boolean; inline;
606 if ((pan
.tag
and GridTagLift
) <> 0) then
608 // stop if the lift of the right type
610 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
611 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
612 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
613 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
)));
616 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
619 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
621 tagmask
: Integer = 0;
627 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
628 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
629 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
630 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
631 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
632 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
633 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
635 if (tagmask
= 0) then exit
;// just in case
637 if ((tagmask
and GridTagLift
) <> 0) then
640 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
);
641 for mwit
in it
do if (xxPanAtPointChecker(mwit
^, PanelType
)) then begin result
:= true; break
; end;
646 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true);
647 result
:= (it
.length
<> 0); // firsthit
653 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
658 if (tagmask
= 0) then exit
;
659 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true); // firsthit
660 if (it
.length
<> 0) then result
:= it
.first
^;
665 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
667 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
668 (Texture
= TEXTURE_NAME_ACID1
) or
669 (Texture
= TEXTURE_NAME_ACID2
);
672 procedure CreateDoorMap();
674 PanelArray
: Array of record
680 a
, b
, c
, m
, i
, len
: Integer;
688 SetLength(PanelArray
, len
);
690 for a
:= 0 to High(gWalls
) do
691 if gWalls
[a
].Door
then
693 PanelArray
[i
].X
:= gWalls
[a
].X
;
694 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
695 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
696 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
697 PanelArray
[i
].Active
:= True;
698 PanelArray
[i
].PanelID
:= a
;
704 SetLength(PanelArray
, len
);
715 SetLength(gDoorMap
, 0);
717 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
720 if PanelArray
[a
].Active
then
722 PanelArray
[a
].Active
:= False;
723 m
:= Length(gDoorMap
);
724 SetLength(gDoorMap
, m
+1);
725 SetLength(gDoorMap
[m
], 1);
726 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
734 if PanelArray
[b
].Active
then
735 for c
:= 0 to High(gDoorMap
[m
]) do
736 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
737 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
738 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
739 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
740 gWalls
[gDoorMap
[m
, c
]].X
,
741 gWalls
[gDoorMap
[m
, c
]].Y
,
742 gWalls
[gDoorMap
[m
, c
]].Width
,
743 gWalls
[gDoorMap
[m
, c
]].Height
) then
745 PanelArray
[b
].Active
:= False;
746 SetLength(gDoorMap
[m
],
747 Length(gDoorMap
[m
])+1);
748 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
754 g_Game_StepLoading();
760 procedure CreateLiftMap();
762 PanelArray
: Array of record
767 a
, b
, c
, len
, i
, j
: Integer;
773 len
:= Length(gLifts
);
774 SetLength(PanelArray
, len
);
776 for a
:= 0 to len
-1 do
778 PanelArray
[a
].X
:= gLifts
[a
].X
;
779 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
780 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
781 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
782 PanelArray
[a
].Active
:= True;
785 SetLength(gLiftMap
, len
);
788 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
790 for a
:= 0 to len
-1 do
791 if PanelArray
[a
].Active
then
793 PanelArray
[a
].Active
:= False;
794 SetLength(gLiftMap
[i
], 32);
802 for b
:= 0 to len
-1 do
803 if PanelArray
[b
].Active
then
805 if g_CollideAround(PanelArray
[b
].X
,
808 PanelArray
[b
].Height
,
809 PanelArray
[gLiftMap
[i
, c
]].X
,
810 PanelArray
[gLiftMap
[i
, c
]].Y
,
811 PanelArray
[gLiftMap
[i
, c
]].Width
,
812 PanelArray
[gLiftMap
[i
, c
]].Height
) then
814 PanelArray
[b
].Active
:= False;
816 if j
> High(gLiftMap
[i
]) then
817 SetLength(gLiftMap
[i
],
818 Length(gLiftMap
[i
])+32);
827 SetLength(gLiftMap
[i
], j
+1);
830 g_Game_StepLoading();
833 SetLength(gLiftMap
, i
);
838 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
841 panels
: ^TPanelArray
;
847 case PanelRec
.PanelType
of
848 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
849 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
850 PANEL_FORE
: panels
:= @gRenderForegrounds
;
851 PANEL_WATER
: panels
:= @gWater
;
852 PANEL_ACID1
: panels
:= @gAcid1
;
853 PANEL_ACID2
: panels
:= @gAcid2
;
854 PANEL_STEP
: panels
:= @gSteps
;
855 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
856 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
860 len
:= Length(panels
^);
861 SetLength(panels
^, len
+1);
863 pguid
:= Length(panByGUID
);
864 SetLength(panByGUID
, pguid
+1); //FIXME!
865 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
867 assert(pguid
< Length(panByGUID
));
868 panByGUID
[pguid
] := pan
;
872 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
874 PanelRec
.user
['panel_guid'] := pguid
;
881 function CreateNullTexture(RecName
: String): Integer;
883 RecName
:= toLowerCase1251(RecName
);
884 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
885 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
887 SetLength(Textures
, Length(Textures
)+1);
888 result
:= High(Textures
);
890 with Textures
[High(Textures
)] do
892 TextureName
:= RecName
;
896 TextureID
:= LongWord(TEXTURE_NONE
);
899 TextNameHash
.put(RecName
, result
);
903 function GetReplacementWad (WadName
: AnsiString): AnsiString;
906 if WadName
<> '' then
909 if g_Game_IsClient
then
910 result
:= g_Res_FindReplacementWad(WadName
);
911 if (result
= WadName
) then
912 result
:= e_FindWad(WadDirs
, result
)
917 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
920 TextureData
: Pointer;
922 a
, ResLength
: Integer;
924 RecName
:= toLowerCase1251(RecName
);
925 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
926 if TextNameHash
.get(RecName
, result
) then
929 //e_LogWritefln('texture ''%s'' already loaded (%s)', [RecName, result]);
935 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
938 if Textures <> nil then
940 for a := 0 to High(Textures) do
942 if (Textures[a].TextureName = RecName) then
943 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
944 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
952 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
953 if (RecName
= TEXTURE_NAME_WATER
) or
954 (RecName
= TEXTURE_NAME_ACID1
) or
955 (RecName
= TEXTURE_NAME_ACID2
) then
957 SetLength(Textures
, Length(Textures
)+1);
959 with Textures
[High(Textures
)] do
961 TextureName
:= RecName
;
962 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
963 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
964 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
969 result
:= High(Textures
);
970 TextNameHash
.put(RecName
, result
);
974 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
975 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
976 if WADName
= '' then WADName
:= Map
; //WADName := GameDir+'/wads/'+WADName else
978 WAD
:= TWADFile
.Create();
979 WAD
.ReadFile(WADName
);
983 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
985 FreeMem(TextureData);
986 RecName := 'COMMON\ALIEN';
990 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
992 SetLength(Textures
, Length(Textures
)+1);
993 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
995 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
996 SetLength(Textures
, Length(Textures
)-1);
1000 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
1001 FreeMem(TextureData
);
1002 Textures
[High(Textures
)].TextureName
:= RecName
;
1003 Textures
[High(Textures
)].Anim
:= False;
1005 result
:= High(Textures
);
1006 TextNameHash
.put(RecName
, result
);
1008 else // Íåò òàêîãî ðåóñðñà â WAD'å
1010 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
1011 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1012 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
1014 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
1015 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1017 BadTextNameHash
.put(RecName
, -1);
1024 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1027 TextureWAD
: PChar = nil;
1028 TextData
: Pointer = nil;
1029 TextureData
: Pointer = nil;
1033 TextureResource
: String;
1034 _width
, _height
, _framecount
, _speed
: Integer;
1035 _backanimation
: Boolean;
1037 ia
: TDynImageDataArray
= nil;
1038 f
, c
, frdelay
, frloop
: Integer;
1040 RecName
:= toLowerCase1251(RecName
);
1041 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
1042 if TextNameHash
.get(RecName
, result
) then
1045 //e_LogWritefln('animated texture ''%s'' already loaded (%s)', [RecName, result]);
1051 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1053 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1054 if BadTextNameHash
.get(RecName
, f
) then
1056 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1060 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1061 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
1062 if WADName
= '' then WADName
:= Map
; //WADName := GameDir+'/wads/'+WADName else
1064 WAD
:= TWADFile
.Create();
1066 //if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
1068 WAD
.ReadFile(WADName
);
1070 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1072 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1073 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1075 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1076 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1078 BadTextNameHash
.put(RecName
, -1);
1083 if WADName = Map then
1085 //FreeMem(TextureWAD);
1086 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1092 if ResLength
< 6 then
1094 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), TMsgType
.Warning
);
1095 BadTextNameHash
.put(RecName
, -1);
1099 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1100 if isWadData(TextureWAD
, ResLength
) then
1102 // íåò, ýòî ñóïåðìåí!
1103 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1105 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1106 BadTextNameHash
.put(RecName
, -1);
1110 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1111 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1113 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1114 BadTextNameHash
.put(RecName
, -1);
1118 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1120 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1121 if TextureResource
= '' then
1123 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), TMsgType
.Warning
);
1124 BadTextNameHash
.put(RecName
, -1);
1128 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1129 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1130 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1131 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1132 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1137 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1138 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1140 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), TMsgType
.Warning
);
1141 BadTextNameHash
.put(RecName
, -1);
1148 SetLength(Textures
, Length(Textures
)+1);
1149 with Textures
[High(Textures
)] do
1151 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1152 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1154 TextureName
:= RecName
;
1158 FramesCount
:= _framecount
;
1160 result
:= High(Textures
);
1161 TextNameHash
.put(RecName
, result
);
1165 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1166 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1168 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1170 BadTextNameHash
.put(RecName
, -1);
1176 // try animated image
1178 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1179 if length(imgfmt) = 0 then
1181 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1185 GlobalMetadata
.ClearMetaItems();
1186 GlobalMetadata
.ClearMetaItemsForSaving();
1187 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1189 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), TMsgType
.Warning
);
1190 BadTextNameHash
.put(RecName
, -1);
1193 if length(ia
) = 0 then
1195 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), TMsgType
.Warning
);
1196 BadTextNameHash
.put(RecName
, -1);
1203 _width
:= ia
[0].width
;
1204 _height
:= ia
[0].height
;
1205 _framecount
:= length(ia
);
1207 _backanimation
:= false;
1210 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1212 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1214 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1216 if f
< 0 then f
:= 0;
1219 if c
< 13 then c
:= 0 else c
:= 1;
1221 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1226 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1228 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1230 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1232 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1236 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1237 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1238 f
:= ord(_backanimation
);
1239 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
);
1241 SetLength(Textures
, Length(Textures
)+1);
1242 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1243 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1245 Textures
[High(Textures
)].TextureName
:= RecName
;
1246 Textures
[High(Textures
)].Width
:= _width
;
1247 Textures
[High(Textures
)].Height
:= _height
;
1248 Textures
[High(Textures
)].Anim
:= True;
1249 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1250 Textures
[High(Textures
)].Speed
:= _speed
;
1251 result
:= High(Textures
);
1252 TextNameHash
.put(RecName
, result
);
1253 //writeln(' CREATED!');
1257 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1258 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1260 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), TMsgType
.Warning
);
1262 BadTextNameHash
.put(RecName
, -1);
1266 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1269 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1270 if (TextData
<> nil) then FreeMem(TextData
);
1271 if (TextureData
<> nil) then FreeMem(TextureData
);
1275 procedure CreateItem(Item
: TDynRecord
);
1277 if g_Game_IsClient
then Exit
;
1279 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1280 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1283 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1284 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1287 procedure CreateArea(Area
: TDynRecord
);
1292 case Area
.AreaType
of
1293 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1294 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1296 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1297 with RespawnPoints
[High(RespawnPoints
)] do
1301 Direction
:= TDirection(Area
.Direction
);
1303 case Area
.AreaType
of
1304 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1305 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1306 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1307 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1308 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1313 AREA_REDFLAG
, AREA_BLUEFLAG
:
1315 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1317 if FlagPoints
[a
] <> nil then Exit
;
1321 with FlagPoints
[a
]^ do
1323 X
:= Area
.X
-FLAGRECT
.X
;
1324 Y
:= Area
.Y
-FLAGRECT
.Y
;
1325 Direction
:= TDirection(Area
.Direction
);
1331 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1332 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1335 Animation
:= TAnimation
.Create(id
, True, 8);
1336 Obj
.Rect
:= FLAGRECT
;
1344 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1345 with DOMFlagPoints[High(DOMFlagPoints)] do
1349 Direction := TDirection(Area.Direction);
1352 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1357 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1363 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1367 mapId
:= Trigger
.id
;
1368 mapIndex
:= amapIdx
;
1371 Width
:= Trigger
.Width
;
1372 Height
:= Trigger
.Height
;
1373 Enabled
:= Trigger
.Enabled
;
1374 TexturePanelGUID
:= atpanid
;
1375 TriggerType
:= Trigger
.TriggerType
;
1376 ActivateType
:= Trigger
.ActivateType
;
1377 Keys
:= Trigger
.Keys
;
1378 trigPanelGUID
:= atrigpanid
;
1379 // HACK: used in TPanel.CanChangeTexture. maybe there's a better way?
1380 if TexturePanelGUID
<> -1 then
1382 tp
:= g_Map_PanelByGUID(TexturePanelGUID
);
1383 if (tp
<> nil) then tp
.hasTexTrigger
:= True;
1387 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1390 procedure CreateMonster(monster
: TDynRecord
);
1395 if g_Game_IsClient
then Exit
;
1397 if (gGameSettings
.GameType
= GT_SINGLE
)
1398 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1400 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1402 if gTriggers
<> nil then
1404 for a
:= 0 to High(gTriggers
) do
1406 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1408 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1409 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1414 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1418 procedure g_Map_ReAdd_DieTriggers();
1420 function monsDieTrig (mon
: TMonster
): Boolean;
1423 //tw: TStrTextWriter;
1425 result
:= false; // don't stop
1426 mon
.ClearTriggers();
1427 for a
:= 0 to High(gTriggers
) do
1429 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1431 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1433 tw := TStrTextWriter.Create();
1435 gTriggers[a].trigData.writeTo(tw);
1436 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1441 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1447 if g_Game_IsClient
then Exit
;
1449 g_Mons_ForEach(monsDieTrig
);
1452 function extractWadName(resourceName
: string): string;
1456 posN
:= Pos(':', resourceName
);
1458 Result
:= Copy(resourceName
, 0, posN
-1)
1464 procedure addResToExternalResList (res
: AnsiString);
1470 if g_Game_IsClient
or not g_Game_IsNet
then exit
;
1471 if (length(res
) = 0) then exit
; // map wad
1472 res
:= extractWadName(res
);
1473 if (length(res
) = 0) then exit
; // map wad
1474 uname
:= toLowerCase1251(res
);
1475 // do not add duplicates
1476 for f
:= 0 to High(gExternalResources
) do
1478 if (gExternalResources
[f
].userName
= uname
) then exit
;
1481 fi
.userName
:= uname
;
1482 if (not GetDiskFileInfo(GameDir
+'/wads/'+res
, fi
)) then
1488 fi
.tag
:= 0; // non-zero means "cannot caclucate hash"
1490 fi
.hash
:= MD5File(fi
.diskName
);
1495 //e_LogWritefln('addext: res=[%s]; uname=[%s]; diskName=[%s]', [res, fi.userName, fi.diskName]);
1496 SetLength(gExternalResources
, length(gExternalResources
)+1);
1497 gExternalResources
[High(gExternalResources
)] := fi
;
1501 procedure compactExtResList ();
1507 for src
:= 0 to High(gExternalResources
) do
1509 if (gExternalResources
[src
].tag
= 0) then
1512 if (dest
<> src
) then gExternalResources
[dest
] := gExternalResources
[src
];
1516 if (dest
<> length(gExternalResources
)) then SetLength(gExternalResources
, dest
);
1520 procedure generateExternalResourcesList (map
: TDynRecord
);
1522 SetLength(gExternalResources
, 0);
1523 addResToExternalResList(map
.MusicName
);
1524 addResToExternalResList(map
.SkyName
);
1528 procedure mapCreateGrid ();
1530 mapX0
: Integer = $3fffffff;
1531 mapY0
: Integer = $3fffffff;
1532 mapX1
: Integer = -$3fffffff;
1533 mapY1
: Integer = -$3fffffff;
1535 procedure calcBoundingBox (constref panels
: TPanelArray
);
1540 for idx
:= 0 to High(panels
) do
1543 if not pan
.visvalid
then continue
;
1544 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1545 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1546 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1547 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1548 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1552 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1558 //tag := panelTypeToTag(tag);
1559 for idx
:= 0 to High(panels
) do
1562 if not pan
.visvalid
then continue
;
1563 if (pan
.proxyId
<> -1) then
1565 {$IF DEFINED(D2F_DEBUG)}
1566 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
);
1570 case pan
.PanelType
of
1571 PANEL_WALL
: newtag
:= GridTagWall
;
1572 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1573 PANEL_BACK
: newtag
:= GridTagBack
;
1574 PANEL_FORE
: newtag
:= GridTagFore
;
1575 PANEL_WATER
: newtag
:= GridTagWater
;
1576 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1577 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1578 PANEL_STEP
: newtag
:= GridTagStep
;
1579 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1580 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1581 else continue
; // oops
1585 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1586 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1587 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1588 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1590 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1592 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1603 calcBoundingBox(gWalls
);
1604 calcBoundingBox(gRenderBackgrounds
);
1605 calcBoundingBox(gRenderForegrounds
);
1606 calcBoundingBox(gWater
);
1607 calcBoundingBox(gAcid1
);
1608 calcBoundingBox(gAcid2
);
1609 calcBoundingBox(gSteps
);
1610 calcBoundingBox(gLifts
);
1611 calcBoundingBox(gBlockMon
);
1613 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1615 if (mapX0
> 0) then mapX0
:= 0;
1616 if (mapY0
> 0) then mapY0
:= 0;
1618 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1619 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1621 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1622 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1624 addPanelsToGrid(gWalls
);
1625 addPanelsToGrid(gRenderBackgrounds
);
1626 addPanelsToGrid(gRenderForegrounds
);
1627 addPanelsToGrid(gWater
);
1628 addPanelsToGrid(gAcid1
);
1629 addPanelsToGrid(gAcid2
);
1630 addPanelsToGrid(gSteps
);
1631 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1632 addPanelsToGrid(gBlockMon
);
1634 mapGrid
.dumpStats();
1636 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1640 function g_Map_Load(Res
: String): Boolean;
1642 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1643 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1647 //TexturePanel: Integer;
1650 trigrec
: TDynRecord
;
1652 texPanelIdx
: Integer;
1653 texPanel
: TDynRecord
;
1655 actPanelIdx
: Integer;
1656 actPanel
: TDynRecord
;
1659 WAD
, TestWAD
: TWADFile
;
1660 //mapReader: TDynRecord = nil;
1661 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1662 panels
: TDynField
= nil; //TPanelsRec1Array;
1663 items
: TDynField
= nil; //TItemsRec1Array;
1664 monsters
: TDynField
= nil; //TMonsterRec1Array;
1665 areas
: TDynField
= nil; //TAreasRec1Array;
1666 triggers
: TDynField
= nil; //TTriggersRec1Array;
1669 AddTextures
: TAddTextureArray
;
1670 TriggersTable
: array of TTRec
;
1671 FileName
, mapResName
, TexName
, s
: AnsiString;
1674 ok
, isAnim
: Boolean;
1675 CurTex
, ntn
: Integer;
1676 rec
, texrec
: TDynRecord
;
1678 pannum
, trignum
, cnt
, tgpid
: Integer;
1680 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1681 //moveActive: Boolean;
1683 mapOk
: Boolean = false;
1684 usedTextures
: THashStrInt
= nil; // key: mapTextureList
1691 //gCurrentMap.Free();
1692 //gCurrentMap := nil;
1697 gMapInfo
.Map
:= Res
;
1698 TriggersTable
:= nil;
1701 sfsGCDisable(); // temporary disable removing of temporary volumes
1703 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1704 if (gCurrentMap
= nil) then
1706 FileName
:= g_ExtractWadName(Res
);
1707 e_LogWritefln('Loading map WAD [%s] (res=[%s])', [FileName
, Res
], TMsgType
.Notify
);
1708 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1710 WAD
:= TWADFile
.Create();
1711 if not WAD
.ReadFile(FileName
) then
1713 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1718 if gTestMap
<> '' then
1720 s
:= g_ExtractWadName(gTestMap
);
1721 TestWAD
:= TWADFile
.Create();
1722 if not TestWAD
.ReadFile(s
) then
1724 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [s
]));
1730 if TestWAD
<> nil then
1732 mapResName
:= g_ExtractFileName(gTestMap
);
1733 if not TestWAD
.GetMapResource(mapResName
, Data
, Len
) then
1735 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1738 e_WriteLog('Using test map: '+gTestMap
, TMsgType
.Notify
);
1745 //k8: why loader ignores path here?
1746 mapResName
:= g_ExtractFileName(Res
);
1747 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1749 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1759 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1765 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1766 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1768 stt
:= getTimeMicro();
1771 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1774 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1776 gCurrentMapFileName
:= '';
1782 if (gCurrentMap
= nil) then
1784 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1785 gCurrentMapFileName
:= '';
1791 stt
:= getTimeMicro();
1794 //gCurrentMap := mapReader;
1796 generateExternalResourcesList(gCurrentMap
);
1797 mapTextureList
:= gCurrentMap
['texture'];
1798 // get all other lists here too
1799 panels
:= gCurrentMap
['panel'];
1800 triggers
:= gCurrentMap
['trigger'];
1801 items
:= gCurrentMap
['item'];
1802 areas
:= gCurrentMap
['area'];
1803 monsters
:= gCurrentMap
['monster'];
1805 // Çàãðóçêà îïèñàíèÿ êàðòû:
1806 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1807 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1811 Name
:= gCurrentMap
.MapName
;
1812 Description
:= gCurrentMap
.MapDesc
;
1813 Author
:= gCurrentMap
.MapAuthor
;
1814 MusicName
:= gCurrentMap
.MusicName
;
1815 SkyName
:= gCurrentMap
.SkyName
;
1816 Height
:= gCurrentMap
.Height
;
1817 Width
:= gCurrentMap
.Width
;
1820 // Çàãðóçêà òåêñòóð:
1821 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1822 // Äîáàâëåíèå òåêñòóð â Textures[]:
1823 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1825 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1826 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1828 // find used textures
1829 usedTextures
:= THashStrInt
.Create();
1831 if (panels
<> nil) and (panels
.count
> 0) then
1833 for rec
in panels
do
1835 texrec
:= rec
.TextureRec
;
1836 if (texrec
<> nil) then usedTextures
.put(toLowerCase1251(texrec
.Resource
), 42);
1841 for rec
in mapTextureList
do
1844 if not usedTextures
.has(toLowerCase1251(rec
.Resource
)) then
1846 rec
.tagInt
:= -1; // just in case
1847 e_LogWritefln(' Unused texture #%d: %s', [cnt
, rec
.Resource
]);
1851 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1852 e_LogWritefln(' Loading texture #%d: %s', [cnt
, rec
.Resource
]);
1854 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1857 // Àíèìèðîâàííàÿ òåêñòóðà
1858 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1859 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [rec
.Resource
]));
1864 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1865 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [rec
.Resource
]));
1869 ntn
:= CreateNullTexture(rec
.Resource
);
1873 addResToExternalResList(rec
.Resource
);
1876 rec
.tagInt
:= ntn
; // remember texture number
1878 g_Game_StepLoading();
1881 usedTextures
.Free();
1884 // set panel tagInt to texture index
1885 if (panels
<> nil) then
1887 for rec
in panels
do
1889 texrec
:= rec
.TextureRec
;
1890 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1896 // Çàãðóçêà òðèããåðîâ
1897 gTriggerClientID
:= 0;
1898 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1899 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1902 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1903 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1905 // check texture numbers for panels
1906 if (panels
<> nil) and (panels
.count
> 0) then
1908 for rec
in panels
do
1910 if (rec
.tagInt
< 0) then
1912 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1916 gCurrentMapFileName
:= '';
1922 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1923 if (triggers
<> nil) and (triggers
.count
> 0) then
1925 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1926 //SetLength(TriggersTable, triggers.count);
1927 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1929 SetLength(TriggersTable
, triggers
.count
);
1931 for rec
in triggers
do
1934 pttit
:= @TriggersTable
[trignum
];
1935 pttit
.trigrec
:= rec
;
1936 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1937 pttit
.texPanelIdx
:= -1; // will be fixed later
1938 pttit
.texPanel
:= rec
.TexturePanelRec
;
1940 pttit
.actPanelIdx
:= -1;
1941 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1943 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1944 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1946 g_Game_StepLoading();
1951 if (panels
<> nil) and (panels
.count
> 0) then
1953 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1954 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1957 for rec
in panels
do
1960 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1962 SetLength(AddTextures
, 0);
1966 if (mapTextureList
<> nil) then
1968 texrec
:= rec
.TextureRec
;
1969 ok
:= (texrec
<> nil);
1974 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1975 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1977 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1979 if rec
.userPanelTrigRef
then
1981 // e_LogWritefln('trigref for panel %s', [pannum]);
1989 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1990 s
:= texrec
.Resource
;
1992 // Ñïåö-òåêñòóðû çàïðåùåíû
1993 if g_Map_IsSpecialTexture(s
) then
1999 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
2000 ok
:= g_Texture_NumNameFindStart(s
);
2003 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
2004 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
2007 k
:= NNF_NAME_BEFORE
;
2008 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
2009 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
2011 k
:= g_Texture_NumNameFindNext(TexName
);
2013 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
2015 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
2018 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
2020 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2021 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2022 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2025 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
2027 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2028 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
2029 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2034 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
2036 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2037 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
2038 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2041 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
2043 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2044 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2045 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2049 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
2053 for c := 0 to High(Textures) do
2055 if (Textures[c].TextureName = TexName) then
2057 SetLength(AddTextures, Length(AddTextures)+1);
2058 AddTextures[High(AddTextures)].Texture := c;
2059 AddTextures[High(AddTextures)].Anim := isAnim;
2064 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
2066 SetLength(AddTextures
, Length(AddTextures
)+1);
2067 AddTextures
[High(AddTextures
)].Texture
:= c
;
2068 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
2074 if k
= NNF_NAME_EQUALS
then
2076 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
2077 SetLength(AddTextures
, Length(AddTextures
)+1);
2078 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
2079 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
2080 CurTex
:= High(AddTextures
);
2091 end; // if ok - åñòü ñìåæíûå òåêñòóðû
2092 end; // if ok - ññûëàþòñÿ òðèããåðû
2096 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
2097 SetLength(AddTextures
, 1);
2098 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
2099 AddTextures
[0].Anim
:= false;
2100 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2104 //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);
2106 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2108 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2109 //e_LogWritefln('new panel; tcount=%s; curtex=%s', [Length(AddTextures), CurTex]);
2110 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2111 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2112 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2115 moveSpeed
:= rec
.moveSpeed
;
2116 //moveStart := rec.moveStart;
2117 //moveEnd := rec.moveEnd;
2118 //moveActive := rec['move_active'].value;
2119 if not moveSpeed
.isZero
then
2121 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2122 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2123 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2126 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2128 g_Game_StepLoading();
2132 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2133 for b
:= 0 to High(TriggersTable
) do
2135 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
2136 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
2139 // create map grid, init other grids (for monsters, for example)
2140 e_WriteLog('Creating map grid', TMsgType
.Notify
);
2143 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2144 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2146 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2147 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2148 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2150 for rec
in triggers
do
2153 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
2154 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2155 TriggersTable
[trignum
].tnum
:= trignum
;
2156 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
2160 //FIXME: use hashtable!
2161 for pan
in panByGUID
do
2163 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2165 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2167 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2169 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2173 // Çàãðóçêà ïðåäìåòîâ
2174 e_WriteLog(' Loading items...', TMsgType
.Notify
);
2175 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2177 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2178 if (items
<> nil) and not gLoadGameMode
then
2180 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
2181 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2182 for rec
in items
do CreateItem(rec
);
2185 // Çàãðóçêà îáëàñòåé
2186 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
2187 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2189 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2190 if areas
<> nil then
2192 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
2193 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2194 for rec
in areas
do CreateArea(rec
);
2197 // Çàãðóçêà ìîíñòðîâ
2198 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
2199 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2201 gTotalMonsters
:= 0;
2203 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2204 if (monsters
<> nil) and not gLoadGameMode
then
2206 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
2207 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2208 for rec
in monsters
do CreateMonster(rec
);
2211 //gCurrentMap := mapReader; // this will be our current map now
2212 gCurrentMapFileName
:= Res
;
2216 if (gMapInfo
.SkyName
<> '') then
2218 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
2219 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2220 if gTextureFilter
then TEXTUREFILTER
:= GL_LINEAR
else TEXTUREFILTER
:= GL_NEAREST
;
2222 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.SkyName
, g_ExtractWadName(Res
));
2223 if g_Texture_CreateWAD(BackID
, s
) then
2224 g_Game_SetupScreenSize
2226 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]))
2228 TEXTUREFILTER
:= GL_NEAREST
;
2234 if gMapInfo
.MusicName
<> '' then
2236 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
2237 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2239 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.MusicName
, g_ExtractWadName(Res
));
2240 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2243 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2246 // Îñòàëüíûå óñòàíâêè
2254 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2255 if not gLoadGameMode
then g_GFX_Init();
2257 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2258 mapTextureList
:= nil;
2263 TriggersTable
:= nil;
2266 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2267 if ok
and (not gLoadGameMode
) then
2269 gMusic
.SetByName(gMapInfo
.MusicName
);
2274 gMusic
.SetByName('');
2277 stt
:= getTimeMicro()-stt
;
2278 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2281 sfsGCEnable(); // enable releasing unused volumes
2283 e_UnpressAllKeys
; // why not?
2288 gCurrentMapFileName
:= '';
2292 compactExtResList();
2293 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2298 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2301 mapReader
: TDynRecord
;
2302 //Header: TMapHeaderRec_1;
2307 FillChar(Result
, SizeOf(Result
), 0);
2308 FileName
:= g_ExtractWadName(Res
);
2310 WAD
:= TWADFile
.Create();
2311 if not WAD
.ReadFile(FileName
) then
2317 //k8: it ignores path again
2318 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2327 mapReader
:= g_Map_ParseMap(Data
, Len
);
2336 if (mapReader
= nil) then exit
;
2338 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2340 Result
.Name
:= mapReader
.MapName
;
2341 Result
.Description
:= mapReader
.MapDesc
;
2343 Result
.Author
:= mapReader
.MapAuthor
;
2344 Result
.Height
:= mapReader
.Height
;
2345 Result
.Width
:= mapReader
.Width
;
2349 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2350 //ZeroMemory(@Header, SizeOf(Header));
2351 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2352 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2354 Result
.Author
:= '';
2362 function g_Map_GetMapsList(WADName
: string): SSArray
;
2369 WAD
:= TWADFile
.Create();
2370 if not WAD
.ReadFile(WADName
) then
2375 ResList
:= WAD
.GetMapResources();
2376 if ResList
<> nil then
2378 for a
:= 0 to High(ResList
) do
2380 SetLength(Result
, Length(Result
)+1);
2381 Result
[High(Result
)] := ResList
[a
];
2387 function g_Map_Exist(Res
: string): Boolean;
2390 FileName
, mnn
: string;
2396 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2398 WAD
:= TWADFile
.Create
;
2399 if not WAD
.ReadFile(FileName
) then
2405 ResList
:= WAD
.GetMapResources();
2408 mnn
:= g_ExtractFileName(Res
);
2409 if ResList
<> nil then
2410 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2417 procedure g_Map_Free(freeTextures
: Boolean=true);
2421 procedure FreePanelArray(var panels
: TPanelArray
);
2426 if panels
<> nil then
2428 for i
:= 0 to High(panels
) do
2441 RespawnPoints
:= nil;
2442 if FlagPoints
[FLAG_RED
] <> nil then
2444 Dispose(FlagPoints
[FLAG_RED
]);
2445 FlagPoints
[FLAG_RED
] := nil;
2447 if FlagPoints
[FLAG_BLUE
] <> nil then
2449 Dispose(FlagPoints
[FLAG_BLUE
]);
2450 FlagPoints
[FLAG_BLUE
] := nil;
2452 //DOMFlagPoints := nil;
2456 if (Length(gCurrentMapFileName
) <> 0) then
2458 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2462 e_LogWritefln('g_Map_Free: no previous map.', []);
2465 if freeTextures
then
2467 e_LogWritefln('g_Map_Free: clearing textures...', []);
2468 if (Textures
<> nil) then
2470 for a
:= 0 to High(Textures
) do
2472 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2474 if Textures
[a
].Anim
then
2476 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2480 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2482 e_DeleteTexture(Textures
[a
].TextureID
);
2489 TextNameHash
.Free();
2490 TextNameHash
:= nil;
2491 BadTextNameHash
.Free();
2492 BadTextNameHash
:= nil;
2493 gCurrentMapFileName
:= '';
2500 FreePanelArray(gWalls
);
2501 FreePanelArray(gRenderBackgrounds
);
2502 FreePanelArray(gRenderForegrounds
);
2503 FreePanelArray(gWater
);
2504 FreePanelArray(gAcid1
);
2505 FreePanelArray(gAcid2
);
2506 FreePanelArray(gSteps
);
2507 FreePanelArray(gLifts
);
2508 FreePanelArray(gBlockMon
);
2509 gMovingWallIds
:= nil;
2511 if BackID
<> DWORD(-1) then
2515 e_DeleteTexture(BackID
);
2516 BackID
:= DWORD(-1);
2519 g_Game_StopAllSounds(False);
2521 g_Sound_Delete(gMapInfo
.MusicName
);
2523 gMapInfo
.Name
:= '';
2524 gMapInfo
.Description
:= '';
2525 gMapInfo
.MusicName
:= '';
2526 gMapInfo
.Height
:= 0;
2527 gMapInfo
.Width
:= 0;
2533 procedure g_Map_Update();
2540 procedure UpdatePanelArray(var panels
: TPanelArray
);
2545 for i
:= 0 to High(panels
) do panels
[i
].Update();
2549 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2551 UpdatePanelArray(gWalls
);
2552 UpdatePanelArray(gRenderBackgrounds
);
2553 UpdatePanelArray(gRenderForegrounds
);
2554 UpdatePanelArray(gWater
);
2555 UpdatePanelArray(gAcid1
);
2556 UpdatePanelArray(gAcid2
);
2557 UpdatePanelArray(gSteps
);
2559 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2561 if gGameSettings
.GameMode
= GM_CTF
then
2563 for a
:= FLAG_RED
to FLAG_BLUE
do
2565 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2569 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2571 m
:= g_Obj_Move(@Obj
, True, True);
2573 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2575 // Ñîïðîòèâëåíèå âîçäóõà
2576 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2578 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2579 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2582 gFlags
[a
].CaptureTime
:= 0;
2583 if a
= FLAG_RED
then
2584 s
:= _lc
[I_PLAYER_FLAG_RED
]
2586 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2587 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2589 if (((gPlayer1
<> nil) and (((gPlayer1
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer1
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))
2590 or ((gPlayer2
<> nil) and (((gPlayer2
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer2
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))) then
2595 if not sound_ret_flag
[b
].IsPlaying() then
2596 sound_ret_flag
[b
].Play();
2598 if g_Game_IsNet
then
2599 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2603 if Count
> 0 then Count
-= 1;
2606 if gPlayers
<> nil then
2608 j
:= Random(Length(gPlayers
)) - 1;
2609 for d
:= 0 to High(gPlayers
) do
2612 if j
> High(gPlayers
) then j
:= 0;
2613 if gPlayers
[j
] <> nil then
2615 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2617 if gPlayers
[j
].GetFlag(a
) then Break
;
2630 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2632 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2636 if (panels
<> nil) then
2638 // alas, no visible set
2639 for idx
:= 0 to High(panels
) do
2641 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw(hasAmbient
, ambColor
);
2648 PANEL_WALL
: DrawPanels(gWalls
);
2649 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2650 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2651 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2652 PANEL_WATER
: DrawPanels(gWater
);
2653 PANEL_ACID1
: DrawPanels(gAcid1
);
2654 PANEL_ACID2
: DrawPanels(gAcid2
);
2655 PANEL_STEP
: DrawPanels(gSteps
);
2661 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2664 it
: TPanelGrid
.Iter
;
2667 it
:= mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, GridDrawableMask
);
2668 for mwit
in it
do if (((mwit
^.tag
and GridTagDoor
) <> 0) = mwit
^.Door
) then gDrawPanelList
.insert(mwit
^);
2670 // list will be rendered in `g_game.DrawPlayer()`
2674 procedure g_Map_DrawPanelShadowVolumes (lightX
: Integer; lightY
: Integer; radius
: Integer);
2677 it
: TPanelGrid
.Iter
;
2679 it
:= mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, (GridTagWall
or GridTagDoor
));
2680 for mwit
in it
do mwit
^.DrawShadowVolume(lightX
, lightY
, radius
);
2685 procedure g_Map_DrawBack(dx
, dy
: Integer);
2687 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2688 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2690 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2693 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2694 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2700 if WordBool(PanelType
and PANEL_WALL
) then
2701 if gWalls
<> nil then
2706 if gWalls
[a
].Enabled
and
2707 g_Collide(X
, Y
, Width
, Height
,
2708 gWalls
[a
].X
, gWalls
[a
].Y
,
2709 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2716 if WordBool(PanelType
and PANEL_WATER
) then
2717 if gWater
<> nil then
2722 if g_Collide(X
, Y
, Width
, Height
,
2723 gWater
[a
].X
, gWater
[a
].Y
,
2724 gWater
[a
].Width
, gWater
[a
].Height
) then
2731 if WordBool(PanelType
and PANEL_ACID1
) then
2732 if gAcid1
<> nil then
2737 if g_Collide(X
, Y
, Width
, Height
,
2738 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2739 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2746 if WordBool(PanelType
and PANEL_ACID2
) then
2747 if gAcid2
<> nil then
2752 if g_Collide(X
, Y
, Width
, Height
,
2753 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2754 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2761 if WordBool(PanelType
and PANEL_STEP
) then
2762 if gSteps
<> nil then
2767 if g_Collide(X
, Y
, Width
, Height
,
2768 gSteps
[a
].X
, gSteps
[a
].Y
,
2769 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2776 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2777 if gLifts
<> nil then
2782 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= LIFTTYPE_UP
)) or
2783 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= LIFTTYPE_DOWN
)) or
2784 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_LEFT
)) or
2785 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_RIGHT
))) and
2786 g_Collide(X
, Y
, Width
, Height
,
2787 gLifts
[a
].X
, gLifts
[a
].Y
,
2788 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2795 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2796 if gBlockMon
<> nil then
2798 h
:= High(gBlockMon
);
2802 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2803 g_Collide(X
, Y
, Width
, Height
,
2804 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2805 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2813 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2817 function checkPanels (constref panels
: TPanelArray
): Boolean;
2822 if panels
= nil then exit
;
2823 for a
:= 0 to High(panels
) do
2825 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2828 texid
:= panels
[a
].GetTextureID();
2835 texid
:= LongWord(TEXTURE_NONE
);
2837 if not checkPanels(gWater
) then
2838 if not checkPanels(gAcid1
) then
2839 if not checkPanels(gAcid2
) then exit
;
2844 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2846 SlowMask
= GridTagLift
or GridTagBlockMon
;
2848 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2851 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2853 result := pan.Enabled;
2858 if ((tag
and GridTagLift
) <> 0) then
2861 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2862 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2863 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2864 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2865 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2869 if ((tag
and GridTagBlockMon
) <> 0) then
2871 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2876 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2877 result
:= true; // i found her!
2881 tagmask
: Integer = 0;
2883 it
: TPanelGrid
.Iter
;
2887 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2888 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2889 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2890 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2891 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2892 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2893 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2895 if (tagmask
= 0) then exit
; // just in case
2897 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2898 if gdbg_map_use_accel_coldet
then
2900 if ((tagmask
and SlowMask
) <> 0) then
2903 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
);
2907 if ((pan
.tag
and GridTagLift
) <> 0) then
2910 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2911 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2912 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2913 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2914 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2916 else if ((pan
.tag
and GridTagBlockMon
) <> 0) then
2918 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2923 result
:= true; // i found her!
2925 if (result
) then break
;
2931 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
, false, true); // return first hit
2932 result
:= (it
.length
> 0);
2938 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2940 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2944 // returns `true` if we need to stop
2945 function liquidChecker (pan
: TPanel
; var texid
: DWORD
; var cctype
: Integer): Boolean; inline;
2948 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2951 0: if ((pan
.tag
and GridTagWater
) = 0) then exit
; // allowed: water
2952 1: if ((pan
.tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2953 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2956 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2958 texid
:= pan
.GetTextureID();
2959 // water? water has the highest priority, so stop right here
2960 if ((pan
.tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2962 if ((pan
.tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2964 if ((pan
.tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2967 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2969 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2971 it
: TPanelGrid
.Iter
;
2973 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2974 if gdbg_map_use_accel_coldet
then
2976 result
:= LongWord(TEXTURE_NONE
);
2977 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2978 for mwit
in it
do if (liquidChecker(mwit
^, result
, cctype
)) then break
;
2983 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2985 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2989 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2990 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2991 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2994 procedure g_Map_EnableWallGUID (pguid
: Integer);
2998 //pan := gWalls[ID];
2999 pan
:= g_Map_PanelByGUID(pguid
);
3000 if (pan
= nil) then exit
;
3001 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
3003 pan
.Enabled
:= True;
3004 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
3006 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
3007 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
3008 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
3010 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3011 // mark platform as interesting
3014 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
3015 //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);
3020 procedure g_Map_DisableWallGUID (pguid
: Integer);
3024 //pan := gWalls[ID];
3025 pan
:= g_Map_PanelByGUID(pguid
);
3026 if (pan
= nil) then exit
;
3027 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
3029 pan
.Enabled
:= False;
3030 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
3032 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
3033 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
3035 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3036 // mark platform as interesting
3039 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
3040 //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);
3045 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
3049 tp
:= g_Map_PanelByGUID(pguid
);
3050 if (tp
= nil) then exit
;
3051 tp
.NextTexture(AnimLoop
);
3052 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
3056 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
3060 //pan := gLifts[ID];
3061 pan
:= g_Map_PanelByGUID(pguid
);
3062 if (pan
= nil) then exit
;
3063 if not pan
.isGLift
then exit
;
3065 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
3067 with {gLifts[ID]} pan
do
3071 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
3072 //TODO: make separate lift tags, and change tag here
3075 LIFTTYPE_UP
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
3076 LIFTTYPE_DOWN
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
3077 LIFTTYPE_LEFT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
3078 LIFTTYPE_RIGHT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
3081 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3082 // mark platform as interesting
3088 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
3091 PointsArray
: Array of TRespawnPoint
;
3094 SetLength(PointsArray
, 0);
3096 if RespawnPoints
= nil then
3099 for a
:= 0 to High(RespawnPoints
) do
3100 if RespawnPoints
[a
].PointType
= PointType
then
3102 SetLength(PointsArray
, Length(PointsArray
)+1);
3103 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3106 if PointsArray
= nil then
3109 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3113 function g_Map_GetPointCount(PointType
: Byte): Word;
3119 if RespawnPoints
= nil then
3122 for a
:= 0 to High(RespawnPoints
) do
3123 if RespawnPoints
[a
].PointType
= PointType
then
3124 Result
:= Result
+ 1;
3127 function g_Map_HaveFlagPoints(): Boolean;
3129 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3132 procedure g_Map_ResetFlag(Flag
: Byte);
3134 with gFlags
[Flag
] do
3140 Direction
:= TDirection
.D_LEFT
;
3141 State
:= FLAG_STATE_NONE
;
3142 if FlagPoints
[Flag
] <> nil then
3144 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3145 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3146 Direction
:= FlagPoints
[Flag
]^.Direction
;
3147 State
:= FLAG_STATE_NORMAL
;
3153 procedure g_Map_DrawFlags();
3156 Mirror
: TMirrorType
;
3158 if gGameSettings
.GameMode
<> GM_CTF
then
3161 for i
:= FLAG_RED
to FLAG_BLUE
do
3163 if State
<> FLAG_STATE_CAPTURED
then
3165 if State
= FLAG_STATE_NONE
then
3168 if Direction
= TDirection
.D_LEFT
then
3170 Mirror
:= TMirrorType
.Horizontal
;
3175 Mirror
:= TMirrorType
.None
;
3179 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3181 if g_debug_Frames
then
3183 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3185 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3186 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3193 procedure g_Map_SaveState (st
: TStream
);
3197 procedure savePanels ();
3202 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
3203 for pan
in panByGUID
do pan
.SaveState(st
);
3206 procedure saveFlag (flag
: PFlag
);
3210 utils
.writeSign(st
, 'FLAG');
3211 utils
.writeInt(st
, Byte(0)); // version
3212 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3213 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
3215 utils
.writeInt(st
, Byte(flag
^.State
));
3216 // Íàïðàâëåíèå ôëàãà
3217 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3218 utils
.writeInt(st
, Byte(b
));
3220 Obj_SaveState(st
, @flag
^.Obj
);
3227 utils
.writeSign(st
, 'MUSI');
3228 utils
.writeInt(st
, Byte(0));
3230 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3231 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3232 utils
.writeStr(st
, str
);
3233 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3234 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
3235 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3236 utils
.writeBool(st
, gMusic
.SpecPause
);
3238 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3239 utils
.writeInt(st
, LongInt(gTotalMonsters
));
3242 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3243 if (gGameSettings
.GameMode
= GM_CTF
) then
3245 // Ôëàã Êðàñíîé êîìàíäû
3246 saveFlag(@gFlags
[FLAG_RED
]);
3247 // Ôëàã Ñèíåé êîìàíäû
3248 saveFlag(@gFlags
[FLAG_BLUE
]);
3252 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3253 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3255 // Î÷êè Êðàñíîé êîìàíäû
3256 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Goals
));
3257 // Î÷êè Ñèíåé êîìàíäû
3258 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Goals
));
3264 procedure g_Map_LoadState (st
: TStream
);
3270 procedure loadPanels ();
3275 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
3276 for pan
in panByGUID
do
3279 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3283 procedure loadFlag (flag
: PFlag
);
3288 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
3289 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
3290 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3291 flag
^.RespawnType
:= utils
.readByte(st
);
3293 flag
^.State
:= utils
.readByte(st
);
3294 // Íàïðàâëåíèå ôëàãà
3295 b
:= utils
.readByte(st
);
3296 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
3298 Obj_LoadState(@flag
^.Obj
, st
);
3302 if (st
= nil) then exit
;
3304 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3308 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3312 ///// Çàãðóæàåì ìóçûêó: /////
3313 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
3314 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
3316 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3317 str
:= utils
.readStr(st
);
3318 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3319 dw
:= utils
.readLongWord(st
);
3320 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3321 boo
:= utils
.readBool(st
);
3322 // Çàïóñêàåì ýòó ìóçûêó
3323 gMusic
.SetByName(str
);
3324 gMusic
.SpecPause
:= boo
;
3327 gMusic
.SetPosition(dw
);
3330 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3331 gTotalMonsters
:= utils
.readLongInt(st
);
3334 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3335 if (gGameSettings
.GameMode
= GM_CTF
) then
3337 // Ôëàã Êðàñíîé êîìàíäû
3338 loadFlag(@gFlags
[FLAG_RED
]);
3339 // Ôëàã Ñèíåé êîìàíäû
3340 loadFlag(@gFlags
[FLAG_BLUE
]);
3344 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3345 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3347 // Î÷êè Êðàñíîé êîìàíäû
3348 gTeamStat
[TEAM_RED
].Goals
:= utils
.readSmallInt(st
);
3349 // Î÷êè Ñèíåé êîìàíäû
3350 gTeamStat
[TEAM_BLUE
].Goals
:= utils
.readSmallInt(st
);
3356 // trace liquid, stepping by `dx` and `dy`
3357 // return last seen liquid coords, and `false` if we're started outside of the liquid
3358 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3360 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3364 // started outside of the liquid?
3365 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
3366 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3367 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3373 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
3374 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3382 DynWarningCB
:= mapWarningCB
;