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
: 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 {$INCLUDE ../nogl/noGLuses.inc}
256 e_input
, g_main
, e_log
, e_texture
, 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
;
265 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
266 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
267 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
270 // ////////////////////////////////////////////////////////////////////////// //
271 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
275 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
279 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
284 // ////////////////////////////////////////////////////////////////////////// //
286 panByGUID
: array of TPanel
= nil;
289 // ////////////////////////////////////////////////////////////////////////// //
290 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
292 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
293 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
297 // return `true` from `cb` to stop
298 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
303 if not assigned(cb
) then exit
;
304 for pan
in panByGUID
do
306 if cb(pan
) then begin result
:= pan
; exit
; end;
311 procedure g_Map_NetSendInterestingPanels ();
315 if g_Game_IsServer
and g_Game_IsNet
then
317 for pan
in panByGUID
do
319 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
325 // ////////////////////////////////////////////////////////////////////////// //
326 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
327 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
328 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
329 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
332 // ////////////////////////////////////////////////////////////////////////// //
334 dfmapdef
: TDynMapDef
= nil;
337 procedure loadMapDefinition ();
339 pr
: TTextParser
= nil;
343 if (dfmapdef
<> nil) then exit
;
346 e_LogWritefln('parsing "mapdef.txt"...', []);
347 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
348 e_LogWritefln('found local "%smapdef.txt"', [DataDir
]);
355 WAD
:= TWADFile
.Create();
356 if not WAD
.ReadFile(GameWAD
) then
358 //raise Exception.Create('cannot load "game.wad"');
363 st
:= WAD
.openFileStream('mapdef.txt');
370 //raise Exception.Create('cannot open "mapdef.txt"');
371 e_LogWriteln('using default "mapdef.txt"...');
372 pr
:= TStrTextParser
.Create(defaultMapDef
);
376 pr
:= TFileTextParser
.Create(st
);
378 except on e
: Exception
do
380 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
386 dfmapdef
:= TDynMapDef
.Create(pr
);
388 on e
: TDynParseException
do
389 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
391 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
399 // ////////////////////////////////////////////////////////////////////////// //
400 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
402 wst
: TSFSMemoryChunkStream
= nil;
405 if (dataLen
< 4) then exit
;
407 if (dfmapdef
= nil) then writeln('need to load mapdef');
409 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
411 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
413 result
:= dfmapdef
.parseMap(wst
);
415 on e
: TDynParseException
do
417 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
424 e_LogWritefln('ERROR: %s', [e
.message]);
431 //e_LogWriteln('map parsed.');
435 // ////////////////////////////////////////////////////////////////////////// //
437 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
438 NNF_PureExt
: String; // extension postfix
439 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
440 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
443 function g_Texture_NumNameFindStart(name
: String): Boolean;
452 NNF_CurrentNum
:= -1;
454 for i
:= Length(name
) downto 1 do
455 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
457 if i
= Length(name
) then
458 begin // Íåò öèôð â êîíöå ñòðîêè
464 while (j
<= Length(name
)) and (name
[j
] <> '.') do inc(j
);
465 NNF_PureName
:= Copy(name
, 1, i
);
466 NNF_PureExt
:= Copy(name
, j
);
467 name
:= Copy(name
, i
+ 1, j
- i
- 1);
472 // Íå ïåðåâåñòè â ÷èñëî:
473 if not TryStrToInt(name
, NNF_FirstNum
) then
482 function g_Texture_NumNameFindNext(var newName
: String): Byte;
484 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
487 Result
:= NNF_NO_NAME
;
491 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
) + NNF_PureExt
;
493 if NNF_CurrentNum
< NNF_FirstNum
then
494 Result
:= NNF_NAME_BEFORE
496 if NNF_CurrentNum
> NNF_FirstNum
then
497 Result
:= NNF_NAME_AFTER
499 Result
:= NNF_NAME_EQUALS
;
505 // ////////////////////////////////////////////////////////////////////////// //
506 function panelTypeToTag (panelType
: Word): Integer;
509 PANEL_WALL
: result
:= GridTagWall
; // gWalls
510 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
511 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
512 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
513 PANEL_WATER
: result
:= GridTagWater
; // gWater
514 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
515 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
516 PANEL_STEP
: result
:= GridTagStep
; // gSteps
517 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
518 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
519 else result
:= GridTagInvalid
;
524 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
526 if (a
.tag
< b
.tag
) then begin result
:= true; exit
; end;
527 if (a
.tag
> b
.tag
) then begin result
:= false; exit
; end;
528 result
:= (a
.arrIdx
< b
.arrIdx
);
531 procedure dplClear ();
533 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinHeapPanelDraw
.Create() else gDrawPanelList
.clear();
538 Textures
: TLevelTextureArray
= nil;
539 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
540 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
541 RespawnPoints
: array of TRespawnPoint
;
542 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
543 //DOMFlagPoints: Array of TFlagPoint;
546 procedure g_Map_ProfilersBegin ();
548 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
549 if (profMapCollision
<> nil) then profMapCollision
.mainBegin(g_profile_collision
);
551 if g_profile_collision
and (profMapCollision
<> nil) then
553 profMapCollision
.sectionBegin('*solids');
554 profMapCollision
.sectionEnd();
555 profMapCollision
.sectionBegin('liquids');
556 profMapCollision
.sectionEnd();
560 procedure g_Map_ProfilersEnd ();
562 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
566 // wall index in `gWalls` or -1
567 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
571 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, (GridTagWall
or GridTagDoor
));
572 if (result
<> nil) then
574 if (hitx
<> nil) then hitx
^ := ex
;
575 if (hity
<> nil) then hity
^ := ey
;
579 if (hitx
<> nil) then hitx
^ := x1
;
580 if (hity
<> nil) then hity
^ := y1
;
584 // returns panel or nil
585 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
589 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, tag
);
590 if (result
<> nil) then
592 if (hitx
<> nil) then hitx
^ := ex
;
593 if (hity
<> nil) then hity
^ := ey
;
597 if (hitx
<> nil) then hitx
^ := x1
;
598 if (hity
<> nil) then hity
^ := y1
;
603 function xxPanAtPointChecker (pan
: TPanel
; panelType
: Word): Boolean; inline;
605 if ((pan
.tag
and GridTagLift
) <> 0) then
607 // stop if the lift of the right type
609 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
610 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
611 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
612 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
)));
615 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
618 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
620 tagmask
: Integer = 0;
626 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
627 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
628 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
629 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
630 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
631 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
632 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
634 if (tagmask
= 0) then exit
;// just in case
636 if ((tagmask
and GridTagLift
) <> 0) then
639 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
);
640 for mwit
in it
do if (xxPanAtPointChecker(mwit
^, PanelType
)) then begin result
:= true; break
; end;
645 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true);
646 result
:= (it
.length
<> 0); // firsthit
652 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
657 if (tagmask
= 0) then exit
;
658 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true); // firsthit
659 if (it
.length
<> 0) then result
:= it
.first
^;
664 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
666 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
667 (Texture
= TEXTURE_NAME_ACID1
) or
668 (Texture
= TEXTURE_NAME_ACID2
);
671 procedure CreateDoorMap();
673 PanelArray
: Array of record
679 a
, b
, c
, m
, i
, len
: Integer;
687 SetLength(PanelArray
, len
);
689 for a
:= 0 to High(gWalls
) do
690 if gWalls
[a
].Door
then
692 PanelArray
[i
].X
:= gWalls
[a
].X
;
693 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
694 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
695 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
696 PanelArray
[i
].Active
:= True;
697 PanelArray
[i
].PanelID
:= a
;
703 SetLength(PanelArray
, len
);
714 SetLength(gDoorMap
, 0);
716 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
719 if PanelArray
[a
].Active
then
721 PanelArray
[a
].Active
:= False;
722 m
:= Length(gDoorMap
);
723 SetLength(gDoorMap
, m
+1);
724 SetLength(gDoorMap
[m
], 1);
725 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
733 if PanelArray
[b
].Active
then
734 for c
:= 0 to High(gDoorMap
[m
]) do
735 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
736 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
737 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
738 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
739 gWalls
[gDoorMap
[m
, c
]].X
,
740 gWalls
[gDoorMap
[m
, c
]].Y
,
741 gWalls
[gDoorMap
[m
, c
]].Width
,
742 gWalls
[gDoorMap
[m
, c
]].Height
) then
744 PanelArray
[b
].Active
:= False;
745 SetLength(gDoorMap
[m
],
746 Length(gDoorMap
[m
])+1);
747 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
753 g_Game_StepLoading();
759 procedure CreateLiftMap();
761 PanelArray
: Array of record
766 a
, b
, c
, len
, i
, j
: Integer;
772 len
:= Length(gLifts
);
773 SetLength(PanelArray
, len
);
775 for a
:= 0 to len
-1 do
777 PanelArray
[a
].X
:= gLifts
[a
].X
;
778 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
779 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
780 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
781 PanelArray
[a
].Active
:= True;
784 SetLength(gLiftMap
, len
);
787 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
789 for a
:= 0 to len
-1 do
790 if PanelArray
[a
].Active
then
792 PanelArray
[a
].Active
:= False;
793 SetLength(gLiftMap
[i
], 32);
801 for b
:= 0 to len
-1 do
802 if PanelArray
[b
].Active
then
804 if g_CollideAround(PanelArray
[b
].X
,
807 PanelArray
[b
].Height
,
808 PanelArray
[gLiftMap
[i
, c
]].X
,
809 PanelArray
[gLiftMap
[i
, c
]].Y
,
810 PanelArray
[gLiftMap
[i
, c
]].Width
,
811 PanelArray
[gLiftMap
[i
, c
]].Height
) then
813 PanelArray
[b
].Active
:= False;
815 if j
> High(gLiftMap
[i
]) then
816 SetLength(gLiftMap
[i
],
817 Length(gLiftMap
[i
])+32);
826 SetLength(gLiftMap
[i
], j
+1);
829 g_Game_StepLoading();
832 SetLength(gLiftMap
, i
);
837 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
840 panels
: ^TPanelArray
;
846 case PanelRec
.PanelType
of
847 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
848 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
849 PANEL_FORE
: panels
:= @gRenderForegrounds
;
850 PANEL_WATER
: panels
:= @gWater
;
851 PANEL_ACID1
: panels
:= @gAcid1
;
852 PANEL_ACID2
: panels
:= @gAcid2
;
853 PANEL_STEP
: panels
:= @gSteps
;
854 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
855 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
859 len
:= Length(panels
^);
860 SetLength(panels
^, len
+1);
862 pguid
:= Length(panByGUID
);
863 SetLength(panByGUID
, pguid
+1); //FIXME!
864 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
866 assert(pguid
< Length(panByGUID
));
867 panByGUID
[pguid
] := pan
;
871 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
873 PanelRec
.user
['panel_guid'] := pguid
;
880 function CreateNullTexture(RecName
: String): Integer;
882 RecName
:= toLowerCase1251(RecName
);
883 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
884 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
886 SetLength(Textures
, Length(Textures
)+1);
887 result
:= High(Textures
);
889 with Textures
[High(Textures
)] do
891 TextureName
:= RecName
;
895 TextureID
:= LongWord(TEXTURE_NONE
);
898 TextNameHash
.put(RecName
, result
);
902 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
905 TextureData
: Pointer;
907 a
, ResLength
: Integer;
909 RecName
:= toLowerCase1251(RecName
);
910 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
911 if TextNameHash
.get(RecName
, result
) then
914 //e_LogWritefln('texture ''%s'' already loaded (%s)', [RecName, result]);
920 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
923 if Textures <> nil then
925 for a := 0 to High(Textures) do
927 if (Textures[a].TextureName = RecName) then
928 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
929 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
937 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
938 if (RecName
= TEXTURE_NAME_WATER
) or
939 (RecName
= TEXTURE_NAME_ACID1
) or
940 (RecName
= TEXTURE_NAME_ACID2
) then
942 SetLength(Textures
, Length(Textures
)+1);
944 with Textures
[High(Textures
)] do
946 TextureName
:= RecName
;
947 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
948 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
949 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
954 result
:= High(Textures
);
955 TextNameHash
.put(RecName
, result
);
959 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
960 WADName
:= g_ExtractWadName(RecName
);
962 WAD
:= TWADFile
.Create();
964 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
966 WAD
.ReadFile(WADName
);
970 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
972 FreeMem(TextureData);
973 RecName := 'COMMON\ALIEN';
977 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
979 SetLength(Textures
, Length(Textures
)+1);
980 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
982 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
983 SetLength(Textures
, Length(Textures
)-1);
987 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
988 FreeMem(TextureData
);
989 Textures
[High(Textures
)].TextureName
:= RecName
;
990 Textures
[High(Textures
)].Anim
:= False;
992 result
:= High(Textures
);
993 TextNameHash
.put(RecName
, result
);
995 else // Íåò òàêîãî ðåóñðñà â WAD'å
997 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
998 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
999 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
1001 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
1002 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1004 BadTextNameHash
.put(RecName
, -1);
1011 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1014 TextureWAD
: PChar = nil;
1015 TextData
: Pointer = nil;
1016 TextureData
: Pointer = nil;
1020 TextureResource
: String;
1021 _width
, _height
, _framecount
, _speed
: Integer;
1022 _backanimation
: Boolean;
1024 ia
: TDynImageDataArray
= nil;
1025 f
, c
, frdelay
, frloop
: Integer;
1027 RecName
:= toLowerCase1251(RecName
);
1028 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
1029 if TextNameHash
.get(RecName
, result
) then
1032 //e_LogWritefln('animated texture ''%s'' already loaded (%s)', [RecName, result]);
1038 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1040 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1041 if BadTextNameHash
.get(RecName
, f
) then
1043 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1047 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1048 WADName
:= g_ExtractWadName(RecName
);
1050 WAD
:= TWADFile
.Create();
1052 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
1054 WAD
.ReadFile(WADName
);
1056 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1058 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1059 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1061 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1062 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1064 BadTextNameHash
.put(RecName
, -1);
1069 if WADName = Map then
1071 //FreeMem(TextureWAD);
1072 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1078 if ResLength
< 6 then
1080 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), TMsgType
.Warning
);
1081 BadTextNameHash
.put(RecName
, -1);
1085 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1086 if isWadData(TextureWAD
, ResLength
) then
1088 // íåò, ýòî ñóïåðìåí!
1089 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1091 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1092 BadTextNameHash
.put(RecName
, -1);
1096 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1097 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1099 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1100 BadTextNameHash
.put(RecName
, -1);
1104 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1106 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1107 if TextureResource
= '' then
1109 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), TMsgType
.Warning
);
1110 BadTextNameHash
.put(RecName
, -1);
1114 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1115 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1116 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1117 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1118 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1123 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1124 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1126 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), TMsgType
.Warning
);
1127 BadTextNameHash
.put(RecName
, -1);
1134 SetLength(Textures
, Length(Textures
)+1);
1135 with Textures
[High(Textures
)] do
1137 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1138 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1140 TextureName
:= RecName
;
1144 FramesCount
:= _framecount
;
1146 result
:= High(Textures
);
1147 TextNameHash
.put(RecName
, result
);
1151 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1152 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1154 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1156 BadTextNameHash
.put(RecName
, -1);
1162 // try animated image
1164 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1165 if length(imgfmt) = 0 then
1167 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1171 GlobalMetadata
.ClearMetaItems();
1172 GlobalMetadata
.ClearMetaItemsForSaving();
1173 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1175 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), TMsgType
.Warning
);
1176 BadTextNameHash
.put(RecName
, -1);
1179 if length(ia
) = 0 then
1181 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), TMsgType
.Warning
);
1182 BadTextNameHash
.put(RecName
, -1);
1189 _width
:= ia
[0].width
;
1190 _height
:= ia
[0].height
;
1191 _framecount
:= length(ia
);
1193 _backanimation
:= false;
1196 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1198 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1200 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1202 if f
< 0 then f
:= 0;
1205 if c
< 13 then c
:= 0 else c
:= 1;
1207 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1212 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1214 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1216 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1218 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1222 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1223 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1224 f
:= ord(_backanimation
);
1225 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
);
1227 SetLength(Textures
, Length(Textures
)+1);
1228 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1229 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1231 Textures
[High(Textures
)].TextureName
:= RecName
;
1232 Textures
[High(Textures
)].Width
:= _width
;
1233 Textures
[High(Textures
)].Height
:= _height
;
1234 Textures
[High(Textures
)].Anim
:= True;
1235 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1236 Textures
[High(Textures
)].Speed
:= _speed
;
1237 result
:= High(Textures
);
1238 TextNameHash
.put(RecName
, result
);
1239 //writeln(' CREATED!');
1243 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1244 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1246 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), TMsgType
.Warning
);
1248 BadTextNameHash
.put(RecName
, -1);
1252 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1255 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1256 if (TextData
<> nil) then FreeMem(TextData
);
1257 if (TextureData
<> nil) then FreeMem(TextureData
);
1261 procedure CreateItem(Item
: TDynRecord
);
1263 if g_Game_IsClient
then Exit
;
1265 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1266 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1269 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1270 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1273 procedure CreateArea(Area
: TDynRecord
);
1278 case Area
.AreaType
of
1279 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1280 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1282 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1283 with RespawnPoints
[High(RespawnPoints
)] do
1287 Direction
:= TDirection(Area
.Direction
);
1289 case Area
.AreaType
of
1290 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1291 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1292 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1293 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1294 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1299 AREA_REDFLAG
, AREA_BLUEFLAG
:
1301 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1303 if FlagPoints
[a
] <> nil then Exit
;
1307 with FlagPoints
[a
]^ do
1309 X
:= Area
.X
-FLAGRECT
.X
;
1310 Y
:= Area
.Y
-FLAGRECT
.Y
;
1311 Direction
:= TDirection(Area
.Direction
);
1317 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1318 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1321 Animation
:= TAnimation
.Create(id
, True, 8);
1322 Obj
.Rect
:= FLAGRECT
;
1330 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1331 with DOMFlagPoints[High(DOMFlagPoints)] do
1335 Direction := TDirection(Area.Direction);
1338 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1343 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1349 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1353 mapId
:= Trigger
.id
;
1354 mapIndex
:= amapIdx
;
1357 Width
:= Trigger
.Width
;
1358 Height
:= Trigger
.Height
;
1359 Enabled
:= Trigger
.Enabled
;
1360 TexturePanelGUID
:= atpanid
;
1361 TriggerType
:= Trigger
.TriggerType
;
1362 ActivateType
:= Trigger
.ActivateType
;
1363 Keys
:= Trigger
.Keys
;
1364 trigPanelGUID
:= atrigpanid
;
1365 // HACK: used in TPanel.CanChangeTexture. maybe there's a better way?
1366 if TexturePanelGUID
<> -1 then
1368 tp
:= g_Map_PanelByGUID(TexturePanelGUID
);
1369 if (tp
<> nil) then tp
.hasTexTrigger
:= True;
1373 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1376 procedure CreateMonster(monster
: TDynRecord
);
1381 if g_Game_IsClient
then Exit
;
1383 if (gGameSettings
.GameType
= GT_SINGLE
)
1384 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1386 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1388 if gTriggers
<> nil then
1390 for a
:= 0 to High(gTriggers
) do
1392 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1394 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1395 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1400 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1404 procedure g_Map_ReAdd_DieTriggers();
1406 function monsDieTrig (mon
: TMonster
): Boolean;
1409 //tw: TStrTextWriter;
1411 result
:= false; // don't stop
1412 mon
.ClearTriggers();
1413 for a
:= 0 to High(gTriggers
) do
1415 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1417 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1419 tw := TStrTextWriter.Create();
1421 gTriggers[a].trigData.writeTo(tw);
1422 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1427 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1433 if g_Game_IsClient
then Exit
;
1435 g_Mons_ForEach(monsDieTrig
);
1438 function extractWadName(resourceName
: string): string;
1442 posN
:= Pos(':', resourceName
);
1444 Result
:= Copy(resourceName
, 0, posN
-1)
1449 procedure addResToExternalResList(res
: string);
1451 res
:= extractWadName(res
);
1452 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1453 gExternalResources
.Add(res
);
1456 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1458 //textures: TTexturesRec1Array;
1459 //textures: TDynField;
1461 //mapHeader: TMapHeaderRec_1;
1463 //resFile: String = '';
1465 if gExternalResources
= nil then
1466 gExternalResources
:= TStringList
.Create
;
1468 gExternalResources
.Clear
;
1472 textures := GetTextures(map);
1473 for i := 0 to High(textures) do
1475 addResToExternalResList(resFile);
1479 textures := map['texture'];
1480 if (textures <> nil) then
1482 for trec in textures do
1484 addResToExternalResList(resFile);
1491 //mapHeader := GetMapHeader(map);
1493 addResToExternalResList(map
.MusicName
);
1494 addResToExternalResList(map
.SkyName
);
1498 procedure mapCreateGrid ();
1500 mapX0
: Integer = $3fffffff;
1501 mapY0
: Integer = $3fffffff;
1502 mapX1
: Integer = -$3fffffff;
1503 mapY1
: Integer = -$3fffffff;
1505 procedure calcBoundingBox (constref panels
: TPanelArray
);
1510 for idx
:= 0 to High(panels
) do
1513 if not pan
.visvalid
then continue
;
1514 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1515 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1516 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1517 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1518 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1522 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1528 //tag := panelTypeToTag(tag);
1529 for idx
:= 0 to High(panels
) do
1532 if not pan
.visvalid
then continue
;
1533 if (pan
.proxyId
<> -1) then
1535 {$IF DEFINED(D2F_DEBUG)}
1536 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
);
1540 case pan
.PanelType
of
1541 PANEL_WALL
: newtag
:= GridTagWall
;
1542 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1543 PANEL_BACK
: newtag
:= GridTagBack
;
1544 PANEL_FORE
: newtag
:= GridTagFore
;
1545 PANEL_WATER
: newtag
:= GridTagWater
;
1546 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1547 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1548 PANEL_STEP
: newtag
:= GridTagStep
;
1549 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1550 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1551 else continue
; // oops
1555 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1556 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1557 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1558 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1560 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1562 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1573 calcBoundingBox(gWalls
);
1574 calcBoundingBox(gRenderBackgrounds
);
1575 calcBoundingBox(gRenderForegrounds
);
1576 calcBoundingBox(gWater
);
1577 calcBoundingBox(gAcid1
);
1578 calcBoundingBox(gAcid2
);
1579 calcBoundingBox(gSteps
);
1580 calcBoundingBox(gLifts
);
1581 calcBoundingBox(gBlockMon
);
1583 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1585 if (mapX0
> 0) then mapX0
:= 0;
1586 if (mapY0
> 0) then mapY0
:= 0;
1588 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1589 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1591 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1592 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1594 addPanelsToGrid(gWalls
);
1595 addPanelsToGrid(gRenderBackgrounds
);
1596 addPanelsToGrid(gRenderForegrounds
);
1597 addPanelsToGrid(gWater
);
1598 addPanelsToGrid(gAcid1
);
1599 addPanelsToGrid(gAcid2
);
1600 addPanelsToGrid(gSteps
);
1601 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1602 addPanelsToGrid(gBlockMon
);
1604 mapGrid
.dumpStats();
1606 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1610 function g_Map_Load(Res
: String): Boolean;
1612 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1613 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1617 //TexturePanel: Integer;
1620 trigrec
: TDynRecord
;
1622 texPanelIdx
: Integer;
1623 texPanel
: TDynRecord
;
1625 actPanelIdx
: Integer;
1626 actPanel
: TDynRecord
;
1629 WAD
, TestWAD
: TWADFile
;
1630 //mapReader: TDynRecord = nil;
1631 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1632 panels
: TDynField
= nil; //TPanelsRec1Array;
1633 items
: TDynField
= nil; //TItemsRec1Array;
1634 monsters
: TDynField
= nil; //TMonsterRec1Array;
1635 areas
: TDynField
= nil; //TAreasRec1Array;
1636 triggers
: TDynField
= nil; //TTriggersRec1Array;
1639 AddTextures
: TAddTextureArray
;
1640 TriggersTable
: array of TTRec
;
1641 FileName
, mapResName
, TexName
, s
: AnsiString;
1644 ok
, isAnim
: Boolean;
1645 CurTex
, ntn
: Integer;
1646 rec
, texrec
: TDynRecord
;
1648 pannum
, trignum
, cnt
, tgpid
: Integer;
1650 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1651 //moveActive: Boolean;
1653 mapOk
: Boolean = false;
1654 usedTextures
: THashStrInt
= nil; // key: mapTextureList
1661 //gCurrentMap.Free();
1662 //gCurrentMap := nil;
1667 gMapInfo
.Map
:= Res
;
1668 TriggersTable
:= nil;
1671 sfsGCDisable(); // temporary disable removing of temporary volumes
1673 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1674 if (gCurrentMap
= nil) then
1676 FileName
:= g_ExtractWadName(Res
);
1677 e_WriteLog('Loading map WAD: '+FileName
, TMsgType
.Notify
);
1678 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1680 WAD
:= TWADFile
.Create();
1681 if not WAD
.ReadFile(FileName
) then
1683 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1688 if gTestMap
<> '' then
1690 s
:= g_ExtractWadName(gTestMap
);
1691 TestWAD
:= TWADFile
.Create();
1692 if not TestWAD
.ReadFile(s
) then
1694 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [s
]));
1700 if TestWAD
<> nil then
1702 mapResName
:= g_ExtractFileName(gTestMap
);
1703 if not TestWAD
.GetMapResource(mapResName
, Data
, Len
) then
1705 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1708 e_WriteLog('Using test map: '+gTestMap
, TMsgType
.Notify
);
1715 //k8: why loader ignores path here?
1716 mapResName
:= g_ExtractFileName(Res
);
1717 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1719 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1729 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1735 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1736 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1738 stt
:= getTimeMicro();
1741 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1744 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1746 gCurrentMapFileName
:= '';
1752 if (gCurrentMap
= nil) then
1754 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1755 gCurrentMapFileName
:= '';
1761 stt
:= getTimeMicro();
1764 //gCurrentMap := mapReader;
1766 generateExternalResourcesList(gCurrentMap
);
1767 mapTextureList
:= gCurrentMap
['texture'];
1768 // get all other lists here too
1769 panels
:= gCurrentMap
['panel'];
1770 triggers
:= gCurrentMap
['trigger'];
1771 items
:= gCurrentMap
['item'];
1772 areas
:= gCurrentMap
['area'];
1773 monsters
:= gCurrentMap
['monster'];
1775 // Çàãðóçêà îïèñàíèÿ êàðòû:
1776 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1777 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1781 Name
:= gCurrentMap
.MapName
;
1782 Description
:= gCurrentMap
.MapDesc
;
1783 Author
:= gCurrentMap
.MapAuthor
;
1784 MusicName
:= gCurrentMap
.MusicName
;
1785 SkyName
:= gCurrentMap
.SkyName
;
1786 Height
:= gCurrentMap
.Height
;
1787 Width
:= gCurrentMap
.Width
;
1790 // Çàãðóçêà òåêñòóð:
1791 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1792 // Äîáàâëåíèå òåêñòóð â Textures[]:
1793 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1795 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1796 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1798 // find used textures
1799 usedTextures
:= THashStrInt
.Create();
1801 if (panels
<> nil) and (panels
.count
> 0) then
1803 for rec
in panels
do
1805 texrec
:= rec
.TextureRec
;
1806 if (texrec
<> nil) then usedTextures
.put(toLowerCase1251(texrec
.Resource
), 42);
1811 for rec
in mapTextureList
do
1814 if not usedTextures
.has(toLowerCase1251(rec
.Resource
)) then
1816 rec
.tagInt
:= -1; // just in case
1817 e_LogWritefln(' Unused texture #%d: %s', [cnt
, rec
.Resource
]);
1821 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1822 e_LogWritefln(' Loading texture #%d: %s', [cnt
, rec
.Resource
]);
1824 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1827 // Àíèìèðîâàííàÿ òåêñòóðà
1828 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1829 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [rec
.Resource
]));
1834 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1835 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [rec
.Resource
]));
1837 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1839 rec
.tagInt
:= ntn
; // remember texture number
1841 g_Game_StepLoading();
1844 usedTextures
.Free();
1847 // set panel tagInt to texture index
1848 if (panels
<> nil) then
1850 for rec
in panels
do
1852 texrec
:= rec
.TextureRec
;
1853 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1859 // Çàãðóçêà òðèããåðîâ
1860 gTriggerClientID
:= 0;
1861 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1862 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1865 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1866 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1868 // check texture numbers for panels
1869 if (panels
<> nil) and (panels
.count
> 0) then
1871 for rec
in panels
do
1873 if (rec
.tagInt
< 0) then
1875 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1879 gCurrentMapFileName
:= '';
1885 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1886 if (triggers
<> nil) and (triggers
.count
> 0) then
1888 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1889 //SetLength(TriggersTable, triggers.count);
1890 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1892 SetLength(TriggersTable
, triggers
.count
);
1894 for rec
in triggers
do
1897 pttit
:= @TriggersTable
[trignum
];
1898 pttit
.trigrec
:= rec
;
1899 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1900 pttit
.texPanelIdx
:= -1; // will be fixed later
1901 pttit
.texPanel
:= rec
.TexturePanelRec
;
1903 pttit
.actPanelIdx
:= -1;
1904 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1906 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1907 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1909 g_Game_StepLoading();
1914 if (panels
<> nil) and (panels
.count
> 0) then
1916 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1917 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1920 for rec
in panels
do
1923 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1925 SetLength(AddTextures
, 0);
1929 if (mapTextureList
<> nil) then
1931 texrec
:= rec
.TextureRec
;
1932 ok
:= (texrec
<> nil);
1937 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1938 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1940 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1942 if rec
.userPanelTrigRef
then
1944 // e_LogWritefln('trigref for panel %s', [pannum]);
1952 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1953 s
:= texrec
.Resource
;
1955 // Ñïåö-òåêñòóðû çàïðåùåíû
1956 if g_Map_IsSpecialTexture(s
) then
1962 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1963 ok
:= g_Texture_NumNameFindStart(s
);
1966 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1967 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1970 k
:= NNF_NAME_BEFORE
;
1971 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1972 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1974 k
:= g_Texture_NumNameFindNext(TexName
);
1976 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1978 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1981 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1983 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1984 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1985 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1988 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1990 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1991 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1992 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1997 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1999 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2000 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
2001 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2004 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
2006 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2007 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2008 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2012 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
2016 for c := 0 to High(Textures) do
2018 if (Textures[c].TextureName = TexName) then
2020 SetLength(AddTextures, Length(AddTextures)+1);
2021 AddTextures[High(AddTextures)].Texture := c;
2022 AddTextures[High(AddTextures)].Anim := isAnim;
2027 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
2029 SetLength(AddTextures
, Length(AddTextures
)+1);
2030 AddTextures
[High(AddTextures
)].Texture
:= c
;
2031 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
2037 if k
= NNF_NAME_EQUALS
then
2039 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
2040 SetLength(AddTextures
, Length(AddTextures
)+1);
2041 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
2042 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
2043 CurTex
:= High(AddTextures
);
2054 end; // if ok - åñòü ñìåæíûå òåêñòóðû
2055 end; // if ok - ññûëàþòñÿ òðèããåðû
2059 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
2060 SetLength(AddTextures
, 1);
2061 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
2062 AddTextures
[0].Anim
:= false;
2063 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2067 //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);
2069 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2071 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2072 //e_LogWritefln('new panel; tcount=%s; curtex=%s', [Length(AddTextures), CurTex]);
2073 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2074 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2075 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2078 moveSpeed
:= rec
.moveSpeed
;
2079 //moveStart := rec.moveStart;
2080 //moveEnd := rec.moveEnd;
2081 //moveActive := rec['move_active'].value;
2082 if not moveSpeed
.isZero
then
2084 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2085 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2086 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2089 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2091 g_Game_StepLoading();
2095 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2096 for b
:= 0 to High(TriggersTable
) do
2098 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
2099 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
2102 // create map grid, init other grids (for monsters, for example)
2103 e_WriteLog('Creating map grid', TMsgType
.Notify
);
2106 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2107 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2109 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2110 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2111 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2113 for rec
in triggers
do
2116 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
2117 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2118 TriggersTable
[trignum
].tnum
:= trignum
;
2119 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
2123 //FIXME: use hashtable!
2124 for pan
in panByGUID
do
2126 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2128 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2130 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2132 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2136 // Çàãðóçêà ïðåäìåòîâ
2137 e_WriteLog(' Loading items...', TMsgType
.Notify
);
2138 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2140 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2141 if (items
<> nil) and not gLoadGameMode
then
2143 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
2144 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2145 for rec
in items
do CreateItem(rec
);
2148 // Çàãðóçêà îáëàñòåé
2149 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
2150 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2152 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2153 if areas
<> nil then
2155 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
2156 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2157 for rec
in areas
do CreateArea(rec
);
2160 // Çàãðóçêà ìîíñòðîâ
2161 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
2162 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2164 gTotalMonsters
:= 0;
2166 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2167 if (monsters
<> nil) and not gLoadGameMode
then
2169 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
2170 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2171 for rec
in monsters
do CreateMonster(rec
);
2174 //gCurrentMap := mapReader; // this will be our current map now
2175 gCurrentMapFileName
:= Res
;
2179 if (gMapInfo
.SkyName
<> '') then
2181 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
2182 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2183 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2185 if (FileName
<> '') then FileName
:= GameDir
+'/wads/'+FileName
else FileName
:= g_ExtractWadName(Res
);
2187 if gTextureFilter
then TEXTUREFILTER
:= GL_LINEAR
else TEXTUREFILTER
:= GL_NEAREST
;
2189 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2190 if g_Texture_CreateWAD(BackID
, s
) then
2192 g_Game_SetupScreenSize();
2196 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2199 TEXTUREFILTER
:= GL_NEAREST
;
2205 if gMapInfo
.MusicName
<> '' then
2207 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
2208 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2209 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2211 if FileName
<> '' then
2212 FileName
:= GameDir
+'/wads/'+FileName
2215 FileName
:= g_ExtractWadName(Res
);
2218 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2219 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2222 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2225 // Îñòàëüíûå óñòàíâêè
2233 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2234 if not gLoadGameMode
then g_GFX_Init();
2236 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2237 mapTextureList
:= nil;
2242 TriggersTable
:= nil;
2245 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2246 if ok
and (not gLoadGameMode
) then
2248 gMusic
.SetByName(gMapInfo
.MusicName
);
2253 gMusic
.SetByName('');
2256 stt
:= getTimeMicro()-stt
;
2257 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2260 sfsGCEnable(); // enable releasing unused volumes
2262 e_UnpressAllKeys
; // why not?
2267 gCurrentMapFileName
:= '';
2271 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2276 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2279 mapReader
: TDynRecord
;
2280 //Header: TMapHeaderRec_1;
2285 FillChar(Result
, SizeOf(Result
), 0);
2286 FileName
:= g_ExtractWadName(Res
);
2288 WAD
:= TWADFile
.Create();
2289 if not WAD
.ReadFile(FileName
) then
2295 //k8: it ignores path again
2296 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2305 mapReader
:= g_Map_ParseMap(Data
, Len
);
2314 if (mapReader
= nil) then exit
;
2316 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2318 Result
.Name
:= mapReader
.MapName
;
2319 Result
.Description
:= mapReader
.MapDesc
;
2321 Result
.Author
:= mapReader
.MapAuthor
;
2322 Result
.Height
:= mapReader
.Height
;
2323 Result
.Width
:= mapReader
.Width
;
2327 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2328 //ZeroMemory(@Header, SizeOf(Header));
2329 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2330 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2332 Result
.Author
:= '';
2340 function g_Map_GetMapsList(WADName
: string): SSArray
;
2347 WAD
:= TWADFile
.Create();
2348 if not WAD
.ReadFile(WADName
) then
2353 ResList
:= WAD
.GetMapResources();
2354 if ResList
<> nil then
2356 for a
:= 0 to High(ResList
) do
2358 SetLength(Result
, Length(Result
)+1);
2359 Result
[High(Result
)] := ResList
[a
];
2365 function g_Map_Exist(Res
: string): Boolean;
2368 FileName
, mnn
: string;
2374 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2376 WAD
:= TWADFile
.Create
;
2377 if not WAD
.ReadFile(FileName
) then
2383 ResList
:= WAD
.GetMapResources();
2386 mnn
:= g_ExtractFileName(Res
);
2387 if ResList
<> nil then
2388 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2395 procedure g_Map_Free(freeTextures
: Boolean=true);
2399 procedure FreePanelArray(var panels
: TPanelArray
);
2404 if panels
<> nil then
2406 for i
:= 0 to High(panels
) do
2419 RespawnPoints
:= nil;
2420 if FlagPoints
[FLAG_RED
] <> nil then
2422 Dispose(FlagPoints
[FLAG_RED
]);
2423 FlagPoints
[FLAG_RED
] := nil;
2425 if FlagPoints
[FLAG_BLUE
] <> nil then
2427 Dispose(FlagPoints
[FLAG_BLUE
]);
2428 FlagPoints
[FLAG_BLUE
] := nil;
2430 //DOMFlagPoints := nil;
2434 if (Length(gCurrentMapFileName
) <> 0) then
2436 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2440 e_LogWritefln('g_Map_Free: no previous map.', []);
2443 if freeTextures
then
2445 e_LogWritefln('g_Map_Free: clearing textures...', []);
2446 if (Textures
<> nil) then
2448 for a
:= 0 to High(Textures
) do
2450 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2452 if Textures
[a
].Anim
then
2454 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2458 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2460 e_DeleteTexture(Textures
[a
].TextureID
);
2467 TextNameHash
.Free();
2468 TextNameHash
:= nil;
2469 BadTextNameHash
.Free();
2470 BadTextNameHash
:= nil;
2471 gCurrentMapFileName
:= '';
2478 FreePanelArray(gWalls
);
2479 FreePanelArray(gRenderBackgrounds
);
2480 FreePanelArray(gRenderForegrounds
);
2481 FreePanelArray(gWater
);
2482 FreePanelArray(gAcid1
);
2483 FreePanelArray(gAcid2
);
2484 FreePanelArray(gSteps
);
2485 FreePanelArray(gLifts
);
2486 FreePanelArray(gBlockMon
);
2487 gMovingWallIds
:= nil;
2489 if BackID
<> DWORD(-1) then
2493 e_DeleteTexture(BackID
);
2494 BackID
:= DWORD(-1);
2497 g_Game_StopAllSounds(False);
2499 g_Sound_Delete(gMapInfo
.MusicName
);
2501 gMapInfo
.Name
:= '';
2502 gMapInfo
.Description
:= '';
2503 gMapInfo
.MusicName
:= '';
2504 gMapInfo
.Height
:= 0;
2505 gMapInfo
.Width
:= 0;
2511 procedure g_Map_Update();
2518 procedure UpdatePanelArray(var panels
: TPanelArray
);
2523 for i
:= 0 to High(panels
) do panels
[i
].Update();
2527 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2529 UpdatePanelArray(gWalls
);
2530 UpdatePanelArray(gRenderBackgrounds
);
2531 UpdatePanelArray(gRenderForegrounds
);
2532 UpdatePanelArray(gWater
);
2533 UpdatePanelArray(gAcid1
);
2534 UpdatePanelArray(gAcid2
);
2535 UpdatePanelArray(gSteps
);
2537 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2539 if gGameSettings
.GameMode
= GM_CTF
then
2541 for a
:= FLAG_RED
to FLAG_BLUE
do
2543 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2547 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2549 m
:= g_Obj_Move(@Obj
, True, True);
2551 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2553 // Ñîïðîòèâëåíèå âîçäóõà
2554 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2556 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2557 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2560 gFlags
[a
].CaptureTime
:= 0;
2561 if a
= FLAG_RED
then
2562 s
:= _lc
[I_PLAYER_FLAG_RED
]
2564 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2565 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2567 if (((gPlayer1
<> nil) and (((gPlayer1
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer1
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))
2568 or ((gPlayer2
<> nil) and (((gPlayer2
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer2
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))) then
2573 if not sound_ret_flag
[b
].IsPlaying() then
2574 sound_ret_flag
[b
].Play();
2576 if g_Game_IsNet
then
2577 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2581 if Count
> 0 then Count
-= 1;
2584 if gPlayers
<> nil then
2586 j
:= Random(Length(gPlayers
)) - 1;
2587 for d
:= 0 to High(gPlayers
) do
2590 if j
> High(gPlayers
) then j
:= 0;
2591 if gPlayers
[j
] <> nil then
2593 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2595 if gPlayers
[j
].GetFlag(a
) then Break
;
2608 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2610 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2614 if (panels
<> nil) then
2616 // alas, no visible set
2617 for idx
:= 0 to High(panels
) do
2619 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw(hasAmbient
, ambColor
);
2626 PANEL_WALL
: DrawPanels(gWalls
);
2627 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2628 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2629 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2630 PANEL_WATER
: DrawPanels(gWater
);
2631 PANEL_ACID1
: DrawPanels(gAcid1
);
2632 PANEL_ACID2
: DrawPanels(gAcid2
);
2633 PANEL_STEP
: DrawPanels(gSteps
);
2639 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2642 it
: TPanelGrid
.Iter
;
2645 it
:= mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, GridDrawableMask
);
2646 for mwit
in it
do if (((mwit
^.tag
and GridTagDoor
) <> 0) = mwit
^.Door
) then gDrawPanelList
.insert(mwit
^);
2648 // list will be rendered in `g_game.DrawPlayer()`
2652 procedure g_Map_DrawPanelShadowVolumes (lightX
: Integer; lightY
: Integer; radius
: Integer);
2655 it
: TPanelGrid
.Iter
;
2657 it
:= mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, (GridTagWall
or GridTagDoor
));
2658 for mwit
in it
do mwit
^.DrawShadowVolume(lightX
, lightY
, radius
);
2663 procedure g_Map_DrawBack(dx
, dy
: Integer);
2665 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2666 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2668 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2671 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2672 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2678 if WordBool(PanelType
and PANEL_WALL
) then
2679 if gWalls
<> nil then
2684 if gWalls
[a
].Enabled
and
2685 g_Collide(X
, Y
, Width
, Height
,
2686 gWalls
[a
].X
, gWalls
[a
].Y
,
2687 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2694 if WordBool(PanelType
and PANEL_WATER
) then
2695 if gWater
<> nil then
2700 if g_Collide(X
, Y
, Width
, Height
,
2701 gWater
[a
].X
, gWater
[a
].Y
,
2702 gWater
[a
].Width
, gWater
[a
].Height
) then
2709 if WordBool(PanelType
and PANEL_ACID1
) then
2710 if gAcid1
<> nil then
2715 if g_Collide(X
, Y
, Width
, Height
,
2716 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2717 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2724 if WordBool(PanelType
and PANEL_ACID2
) then
2725 if gAcid2
<> nil then
2730 if g_Collide(X
, Y
, Width
, Height
,
2731 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2732 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2739 if WordBool(PanelType
and PANEL_STEP
) then
2740 if gSteps
<> nil then
2745 if g_Collide(X
, Y
, Width
, Height
,
2746 gSteps
[a
].X
, gSteps
[a
].Y
,
2747 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2754 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2755 if gLifts
<> nil then
2760 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= LIFTTYPE_UP
)) or
2761 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= LIFTTYPE_DOWN
)) or
2762 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_LEFT
)) or
2763 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_RIGHT
))) and
2764 g_Collide(X
, Y
, Width
, Height
,
2765 gLifts
[a
].X
, gLifts
[a
].Y
,
2766 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2773 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2774 if gBlockMon
<> nil then
2776 h
:= High(gBlockMon
);
2780 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2781 g_Collide(X
, Y
, Width
, Height
,
2782 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2783 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2791 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2795 function checkPanels (constref panels
: TPanelArray
): Boolean;
2800 if panels
= nil then exit
;
2801 for a
:= 0 to High(panels
) do
2803 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2806 texid
:= panels
[a
].GetTextureID();
2813 texid
:= LongWord(TEXTURE_NONE
);
2815 if not checkPanels(gWater
) then
2816 if not checkPanels(gAcid1
) then
2817 if not checkPanels(gAcid2
) then exit
;
2822 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2824 SlowMask
= GridTagLift
or GridTagBlockMon
;
2826 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2829 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2831 result := pan.Enabled;
2836 if ((tag
and GridTagLift
) <> 0) then
2839 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2840 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2841 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2842 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2843 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2847 if ((tag
and GridTagBlockMon
) <> 0) then
2849 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2854 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2855 result
:= true; // i found her!
2859 tagmask
: Integer = 0;
2861 it
: TPanelGrid
.Iter
;
2865 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2866 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2867 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2868 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2869 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2870 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2871 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2873 if (tagmask
= 0) then exit
; // just in case
2875 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2876 if gdbg_map_use_accel_coldet
then
2878 if ((tagmask
and SlowMask
) <> 0) then
2881 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
);
2885 if ((pan
.tag
and GridTagLift
) <> 0) then
2888 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2889 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2890 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2891 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2892 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2894 else if ((pan
.tag
and GridTagBlockMon
) <> 0) then
2896 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2901 result
:= true; // i found her!
2903 if (result
) then break
;
2909 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
, false, true); // return first hit
2910 result
:= (it
.length
> 0);
2916 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2918 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2922 // returns `true` if we need to stop
2923 function liquidChecker (pan
: TPanel
; var texid
: DWORD
; var cctype
: Integer): Boolean; inline;
2926 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2929 0: if ((pan
.tag
and GridTagWater
) = 0) then exit
; // allowed: water
2930 1: if ((pan
.tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2931 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2934 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2936 texid
:= pan
.GetTextureID();
2937 // water? water has the highest priority, so stop right here
2938 if ((pan
.tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2940 if ((pan
.tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2942 if ((pan
.tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2945 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2947 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2949 it
: TPanelGrid
.Iter
;
2951 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2952 if gdbg_map_use_accel_coldet
then
2954 result
:= LongWord(TEXTURE_NONE
);
2955 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2956 for mwit
in it
do if (liquidChecker(mwit
^, result
, cctype
)) then break
;
2961 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2963 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2967 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2968 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2969 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2972 procedure g_Map_EnableWallGUID (pguid
: Integer);
2976 //pan := gWalls[ID];
2977 pan
:= g_Map_PanelByGUID(pguid
);
2978 if (pan
= nil) then exit
;
2979 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
2981 pan
.Enabled
:= True;
2982 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2984 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2985 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2986 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2988 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2989 // mark platform as interesting
2992 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2993 //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);
2998 procedure g_Map_DisableWallGUID (pguid
: Integer);
3002 //pan := gWalls[ID];
3003 pan
:= g_Map_PanelByGUID(pguid
);
3004 if (pan
= nil) then exit
;
3005 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
3007 pan
.Enabled
:= False;
3008 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
3010 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
3011 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
3013 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3014 // mark platform as interesting
3017 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
3018 //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);
3023 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
3027 tp
:= g_Map_PanelByGUID(pguid
);
3028 if (tp
= nil) then exit
;
3029 tp
.NextTexture(AnimLoop
);
3030 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
3034 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
3038 //pan := gLifts[ID];
3039 pan
:= g_Map_PanelByGUID(pguid
);
3040 if (pan
= nil) then exit
;
3041 if not pan
.isGLift
then exit
;
3043 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
3045 with {gLifts[ID]} pan
do
3049 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
3050 //TODO: make separate lift tags, and change tag here
3053 LIFTTYPE_UP
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
3054 LIFTTYPE_DOWN
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
3055 LIFTTYPE_LEFT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
3056 LIFTTYPE_RIGHT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
3059 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3060 // mark platform as interesting
3066 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
3069 PointsArray
: Array of TRespawnPoint
;
3072 SetLength(PointsArray
, 0);
3074 if RespawnPoints
= nil then
3077 for a
:= 0 to High(RespawnPoints
) do
3078 if RespawnPoints
[a
].PointType
= PointType
then
3080 SetLength(PointsArray
, Length(PointsArray
)+1);
3081 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3084 if PointsArray
= nil then
3087 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3091 function g_Map_GetPointCount(PointType
: Byte): Word;
3097 if RespawnPoints
= nil then
3100 for a
:= 0 to High(RespawnPoints
) do
3101 if RespawnPoints
[a
].PointType
= PointType
then
3102 Result
:= Result
+ 1;
3105 function g_Map_HaveFlagPoints(): Boolean;
3107 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3110 procedure g_Map_ResetFlag(Flag
: Byte);
3112 with gFlags
[Flag
] do
3118 Direction
:= TDirection
.D_LEFT
;
3119 State
:= FLAG_STATE_NONE
;
3120 if FlagPoints
[Flag
] <> nil then
3122 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3123 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3124 Direction
:= FlagPoints
[Flag
]^.Direction
;
3125 State
:= FLAG_STATE_NORMAL
;
3131 procedure g_Map_DrawFlags();
3134 Mirror
: TMirrorType
;
3136 if gGameSettings
.GameMode
<> GM_CTF
then
3139 for i
:= FLAG_RED
to FLAG_BLUE
do
3141 if State
<> FLAG_STATE_CAPTURED
then
3143 if State
= FLAG_STATE_NONE
then
3146 if Direction
= TDirection
.D_LEFT
then
3148 Mirror
:= TMirrorType
.Horizontal
;
3153 Mirror
:= TMirrorType
.None
;
3157 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3159 if g_debug_Frames
then
3161 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3163 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3164 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3171 procedure g_Map_SaveState (st
: TStream
);
3175 procedure savePanels ();
3180 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
3181 for pan
in panByGUID
do pan
.SaveState(st
);
3184 procedure saveFlag (flag
: PFlag
);
3188 utils
.writeSign(st
, 'FLAG');
3189 utils
.writeInt(st
, Byte(0)); // version
3190 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3191 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
3193 utils
.writeInt(st
, Byte(flag
^.State
));
3194 // Íàïðàâëåíèå ôëàãà
3195 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3196 utils
.writeInt(st
, Byte(b
));
3198 Obj_SaveState(st
, @flag
^.Obj
);
3205 utils
.writeSign(st
, 'MUSI');
3206 utils
.writeInt(st
, Byte(0));
3208 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3209 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3210 utils
.writeStr(st
, str
);
3211 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3212 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
3213 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3214 utils
.writeBool(st
, gMusic
.SpecPause
);
3216 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3217 utils
.writeInt(st
, LongInt(gTotalMonsters
));
3220 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3221 if (gGameSettings
.GameMode
= GM_CTF
) then
3223 // Ôëàã Êðàñíîé êîìàíäû
3224 saveFlag(@gFlags
[FLAG_RED
]);
3225 // Ôëàã Ñèíåé êîìàíäû
3226 saveFlag(@gFlags
[FLAG_BLUE
]);
3230 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3231 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3233 // Î÷êè Êðàñíîé êîìàíäû
3234 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Goals
));
3235 // Î÷êè Ñèíåé êîìàíäû
3236 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Goals
));
3242 procedure g_Map_LoadState (st
: TStream
);
3248 procedure loadPanels ();
3253 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
3254 for pan
in panByGUID
do
3257 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3261 procedure loadFlag (flag
: PFlag
);
3266 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
3267 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
3268 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3269 flag
^.RespawnType
:= utils
.readByte(st
);
3271 flag
^.State
:= utils
.readByte(st
);
3272 // Íàïðàâëåíèå ôëàãà
3273 b
:= utils
.readByte(st
);
3274 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
3276 Obj_LoadState(@flag
^.Obj
, st
);
3280 if (st
= nil) then exit
;
3282 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3286 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3290 ///// Çàãðóæàåì ìóçûêó: /////
3291 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
3292 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
3294 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3295 str
:= utils
.readStr(st
);
3296 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3297 dw
:= utils
.readLongWord(st
);
3298 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3299 boo
:= utils
.readBool(st
);
3300 // Çàïóñêàåì ýòó ìóçûêó
3301 gMusic
.SetByName(str
);
3302 gMusic
.SpecPause
:= boo
;
3305 gMusic
.SetPosition(dw
);
3308 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3309 gTotalMonsters
:= utils
.readLongInt(st
);
3312 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3313 if (gGameSettings
.GameMode
= GM_CTF
) then
3315 // Ôëàã Êðàñíîé êîìàíäû
3316 loadFlag(@gFlags
[FLAG_RED
]);
3317 // Ôëàã Ñèíåé êîìàíäû
3318 loadFlag(@gFlags
[FLAG_BLUE
]);
3322 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3323 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3325 // Î÷êè Êðàñíîé êîìàíäû
3326 gTeamStat
[TEAM_RED
].Goals
:= utils
.readSmallInt(st
);
3327 // Î÷êè Ñèíåé êîìàíäû
3328 gTeamStat
[TEAM_BLUE
].Goals
:= utils
.readSmallInt(st
);
3334 // trace liquid, stepping by `dx` and `dy`
3335 // return last seen liquid coords, and `false` if we're started outside of the liquid
3336 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3338 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3342 // started outside of the liquid?
3343 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
3344 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3345 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3351 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
3352 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3360 DynWarningCB
:= mapWarningCB
;