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 g_base
, r_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
;
60 function g_Map_Load(Res
: String): Boolean;
61 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
62 function g_Map_GetMapsList(WADName
: String): SSArray
;
63 function g_Map_Exist(Res
: String): Boolean;
64 procedure g_Map_Free(freeTextures
: Boolean=true);
65 procedure g_Map_Update();
67 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
69 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
70 PanelType
: Word; b1x3
: Boolean=false): Boolean;
71 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
73 procedure g_Map_EnableWallGUID (pguid
: Integer);
74 procedure g_Map_DisableWallGUID (pguid
: Integer);
75 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
78 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
79 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
80 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
82 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
84 procedure g_Map_ReAdd_DieTriggers();
85 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
87 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
88 function g_Map_GetPointCount(PointType
: Byte): Word;
89 function g_Map_GetRandomPointType(): Byte;
91 function g_Map_HaveFlagPoints(): Boolean;
93 procedure g_Map_ResetFlag(Flag
: Byte);
95 procedure g_Map_SaveState (st
: TStream
);
96 procedure g_Map_LoadState (st
: TStream
);
98 // returns panel or nil
99 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
100 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
102 // returns panel or nil
103 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
104 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
107 TForEachPanelCB
= function (pan
: TPanel
): Boolean is nested
; // return `true` to stop
109 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
110 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
112 // trace liquid, stepping by `dx` and `dy`
113 // return last seen liquid coords, and `false` if we're started outside of the liquid
114 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
117 // return `true` from `cb` to stop
118 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
120 procedure g_Map_NetSendInterestingPanels (); // yay!
123 procedure g_Map_ProfilersBegin ();
124 procedure g_Map_ProfilersEnd ();
127 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
130 function g_Map_MinX (): Integer; inline;
131 function g_Map_MinY (): Integer; inline;
132 function g_Map_MaxX (): Integer; inline;
133 function g_Map_MaxY (): Integer; inline;
141 function g_Texture_NumNameFindStart(name
: String): Boolean;
142 function g_Texture_NumNameFindNext(var newName
: String): Byte;
145 RESPAWNPOINT_PLAYER1
= 1;
146 RESPAWNPOINT_PLAYER2
= 2;
148 RESPAWNPOINT_RED
= 4;
149 RESPAWNPOINT_BLUE
= 5;
157 FLAG_STATE_NORMAL
= 1;
158 FLAG_STATE_DROPPED
= 2;
159 FLAG_STATE_CAPTURED
= 3;
160 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
161 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
163 FLAG_TIME
= 720; // 20 seconds
165 SKY_STRETCH
: Single = 1.5;
180 // sorted by draw priority
181 GridTagBack
= 1 shl 0; // gRenderBackgrounds
182 GridTagStep
= 1 shl 1; // gSteps
183 GridTagWall
= 1 shl 2; // gWalls
184 GridTagDoor
= 1 shl 3; // gWalls
185 GridTagAcid1
= 1 shl 4; // gAcid1
186 GridTagAcid2
= 1 shl 5; // gAcid2
187 GridTagWater
= 1 shl 6; // gWater
188 GridTagFore
= 1 shl 7; // gRenderForegrounds
189 // the following are invisible
190 GridTagLift
= 1 shl 8; // gLifts
191 GridTagBlockMon
= 1 shl 9; // gBlockMon
193 GridTagSolid
= (GridTagWall
or GridTagDoor
);
194 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
195 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
197 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
201 TBinHeapPanelDrawCmp
= class
203 class function less (const a
, b
: TPanel
): Boolean; inline;
206 TBinHeapPanelDraw
= specialize TBinaryHeapBase
<TPanel
, TBinHeapPanelDrawCmp
>;
210 gRenderBackgrounds
: TPanelArray
;
211 gRenderForegrounds
: TPanelArray
;
212 gWater
, gAcid1
, gAcid2
: TPanelArray
;
215 gBlockMon
: TPanelArray
;
216 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
217 //gDOMFlags: array of TFlag;
220 gDoorMap
: array of array of DWORD
;
221 gLiftMap
: array of array of DWORD
;
222 gWADHash
: TMD5Digest
;
223 BackID
: DWORD
= DWORD(-1);
224 gExternalResources
: array of TDiskFileInfo
= nil;
225 gMovingWallIds
: array of Integer = nil;
227 gdbg_map_use_accel_render
: Boolean = true;
228 gdbg_map_use_accel_coldet
: Boolean = true;
229 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
230 gDrawPanelList
: TBinHeapPanelDraw
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
232 gCurrentMap
: TDynRecord
= nil;
233 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
234 gTestMap
: String = '';
237 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
241 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
244 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
250 {$INCLUDE ../nogl/noGLuses.inc}
251 e_input
, g_main
, e_log
, e_texture
, e_res
, g_items
, g_gfx
, g_console
,
252 g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
253 g_options
, g_triggers
, g_player
,
254 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
255 sfs
, xstreams
, hashtable
, wadreader
,
256 ImagingTypes
, Imaging
, ImagingUtility
,
257 ImagingGif
, ImagingNetworkGraphics
,
261 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
262 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
263 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
266 // ////////////////////////////////////////////////////////////////////////// //
267 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
271 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
275 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
280 // ////////////////////////////////////////////////////////////////////////// //
282 panByGUID
: array of TPanel
= nil;
285 // ////////////////////////////////////////////////////////////////////////// //
286 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
288 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
289 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
293 // return `true` from `cb` to stop
294 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
299 if not assigned(cb
) then exit
;
300 for pan
in panByGUID
do
302 if cb(pan
) then begin result
:= pan
; exit
; end;
307 procedure g_Map_NetSendInterestingPanels ();
311 if g_Game_IsServer
and g_Game_IsNet
then
313 for pan
in panByGUID
do
315 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
321 // ////////////////////////////////////////////////////////////////////////// //
322 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
323 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
324 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
325 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
328 // ////////////////////////////////////////////////////////////////////////// //
330 dfmapdef
: TDynMapDef
= nil;
333 procedure loadMapDefinition ();
335 pr
: TTextParser
= nil;
339 if (dfmapdef
<> nil) then exit
;
342 e_LogWritefln('parsing "mapdef.txt"...', []);
343 st
:= e_OpenResourceRO(DataDirs
, 'mapdef.txt');
344 e_LogWritefln('found local "mapdef.txt"', []);
351 WAD
:= TWADFile
.Create();
352 if not WAD
.ReadFile(GameWAD
) then
354 //raise Exception.Create('cannot load "game.wad"');
359 st
:= WAD
.openFileStream('mapdef.txt');
366 //raise Exception.Create('cannot open "mapdef.txt"');
367 e_LogWriteln('using default "mapdef.txt"...');
368 pr
:= TStrTextParser
.Create(defaultMapDef
);
372 pr
:= TFileTextParser
.Create(st
);
374 except on e
: Exception
do
376 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
382 dfmapdef
:= TDynMapDef
.Create(pr
);
384 on e
: TDynParseException
do
385 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
387 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
395 // ////////////////////////////////////////////////////////////////////////// //
396 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
398 wst
: TSFSMemoryChunkStream
= nil;
401 if (dataLen
< 4) then exit
;
403 if (dfmapdef
= nil) then writeln('need to load mapdef');
405 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
407 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
409 result
:= dfmapdef
.parseMap(wst
);
411 on e
: TDynParseException
do
413 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
420 e_LogWritefln('ERROR: %s', [e
.message]);
427 //e_LogWriteln('map parsed.');
431 // ////////////////////////////////////////////////////////////////////////// //
433 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
434 NNF_PureExt
: String; // extension postfix
435 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
436 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
439 function g_Texture_NumNameFindStart(name
: String): Boolean;
448 NNF_CurrentNum
:= -1;
450 for i
:= Length(name
) downto 1 do
451 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
453 if i
= Length(name
) then
454 begin // Íåò öèôð â êîíöå ñòðîêè
460 while (j
<= Length(name
)) and (name
[j
] <> '.') do inc(j
);
461 NNF_PureName
:= Copy(name
, 1, i
);
462 NNF_PureExt
:= Copy(name
, j
);
463 name
:= Copy(name
, i
+ 1, j
- i
- 1);
468 // Íå ïåðåâåñòè â ÷èñëî:
469 if not TryStrToInt(name
, NNF_FirstNum
) then
478 function g_Texture_NumNameFindNext(var newName
: String): Byte;
480 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
483 Result
:= NNF_NO_NAME
;
487 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
) + NNF_PureExt
;
489 if NNF_CurrentNum
< NNF_FirstNum
then
490 Result
:= NNF_NAME_BEFORE
492 if NNF_CurrentNum
> NNF_FirstNum
then
493 Result
:= NNF_NAME_AFTER
495 Result
:= NNF_NAME_EQUALS
;
501 // ////////////////////////////////////////////////////////////////////////// //
502 function panelTypeToTag (panelType
: Word): Integer;
505 PANEL_WALL
: result
:= GridTagWall
; // gWalls
506 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
507 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
508 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
509 PANEL_WATER
: result
:= GridTagWater
; // gWater
510 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
511 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
512 PANEL_STEP
: result
:= GridTagStep
; // gSteps
513 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
514 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
515 else result
:= GridTagInvalid
;
520 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
522 if (a
.tag
< b
.tag
) then begin result
:= true; exit
; end;
523 if (a
.tag
> b
.tag
) then begin result
:= false; exit
; end;
524 result
:= (a
.arrIdx
< b
.arrIdx
);
528 Textures
: TLevelTextureArray
= nil;
529 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
530 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
531 RespawnPoints
: array of TRespawnPoint
;
532 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
533 //DOMFlagPoints: Array of TFlagPoint;
536 procedure g_Map_ProfilersBegin ();
538 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
539 if (profMapCollision
<> nil) then profMapCollision
.mainBegin(g_profile_collision
);
541 if g_profile_collision
and (profMapCollision
<> nil) then
543 profMapCollision
.sectionBegin('*solids');
544 profMapCollision
.sectionEnd();
545 profMapCollision
.sectionBegin('liquids');
546 profMapCollision
.sectionEnd();
550 procedure g_Map_ProfilersEnd ();
552 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
556 // wall index in `gWalls` or -1
557 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
561 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, (GridTagWall
or GridTagDoor
));
562 if (result
<> nil) then
564 if (hitx
<> nil) then hitx
^ := ex
;
565 if (hity
<> nil) then hity
^ := ey
;
569 if (hitx
<> nil) then hitx
^ := x1
;
570 if (hity
<> nil) then hity
^ := y1
;
574 // returns panel or nil
575 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
579 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, tag
);
580 if (result
<> nil) then
582 if (hitx
<> nil) then hitx
^ := ex
;
583 if (hity
<> nil) then hity
^ := ey
;
587 if (hitx
<> nil) then hitx
^ := x1
;
588 if (hity
<> nil) then hity
^ := y1
;
593 function xxPanAtPointChecker (pan
: TPanel
; panelType
: Word): Boolean; inline;
595 if ((pan
.tag
and GridTagLift
) <> 0) then
597 // stop if the lift of the right type
599 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
600 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
601 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
602 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
)));
605 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
608 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
610 tagmask
: Integer = 0;
616 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
617 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
618 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
619 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
620 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
621 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
622 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
624 if (tagmask
= 0) then exit
;// just in case
626 if ((tagmask
and GridTagLift
) <> 0) then
629 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
);
630 for mwit
in it
do if (xxPanAtPointChecker(mwit
^, PanelType
)) then begin result
:= true; break
; end;
635 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true);
636 result
:= (it
.length
<> 0); // firsthit
642 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
647 if (tagmask
= 0) then exit
;
648 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true); // firsthit
649 if (it
.length
<> 0) then result
:= it
.first
^;
654 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
656 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
657 (Texture
= TEXTURE_NAME_ACID1
) or
658 (Texture
= TEXTURE_NAME_ACID2
);
661 procedure CreateDoorMap();
663 PanelArray
: Array of record
669 a
, b
, c
, m
, i
, len
: Integer;
677 SetLength(PanelArray
, len
);
679 for a
:= 0 to High(gWalls
) do
680 if gWalls
[a
].Door
then
682 PanelArray
[i
].X
:= gWalls
[a
].X
;
683 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
684 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
685 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
686 PanelArray
[i
].Active
:= True;
687 PanelArray
[i
].PanelID
:= a
;
693 SetLength(PanelArray
, len
);
704 SetLength(gDoorMap
, 0);
706 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
709 if PanelArray
[a
].Active
then
711 PanelArray
[a
].Active
:= False;
712 m
:= Length(gDoorMap
);
713 SetLength(gDoorMap
, m
+1);
714 SetLength(gDoorMap
[m
], 1);
715 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
723 if PanelArray
[b
].Active
then
724 for c
:= 0 to High(gDoorMap
[m
]) do
725 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
726 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
727 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
728 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
729 gWalls
[gDoorMap
[m
, c
]].X
,
730 gWalls
[gDoorMap
[m
, c
]].Y
,
731 gWalls
[gDoorMap
[m
, c
]].Width
,
732 gWalls
[gDoorMap
[m
, c
]].Height
) then
734 PanelArray
[b
].Active
:= False;
735 SetLength(gDoorMap
[m
],
736 Length(gDoorMap
[m
])+1);
737 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
743 g_Game_StepLoading();
749 procedure CreateLiftMap();
751 PanelArray
: Array of record
756 a
, b
, c
, len
, i
, j
: Integer;
762 len
:= Length(gLifts
);
763 SetLength(PanelArray
, len
);
765 for a
:= 0 to len
-1 do
767 PanelArray
[a
].X
:= gLifts
[a
].X
;
768 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
769 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
770 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
771 PanelArray
[a
].Active
:= True;
774 SetLength(gLiftMap
, len
);
777 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
779 for a
:= 0 to len
-1 do
780 if PanelArray
[a
].Active
then
782 PanelArray
[a
].Active
:= False;
783 SetLength(gLiftMap
[i
], 32);
791 for b
:= 0 to len
-1 do
792 if PanelArray
[b
].Active
then
794 if g_CollideAround(PanelArray
[b
].X
,
797 PanelArray
[b
].Height
,
798 PanelArray
[gLiftMap
[i
, c
]].X
,
799 PanelArray
[gLiftMap
[i
, c
]].Y
,
800 PanelArray
[gLiftMap
[i
, c
]].Width
,
801 PanelArray
[gLiftMap
[i
, c
]].Height
) then
803 PanelArray
[b
].Active
:= False;
805 if j
> High(gLiftMap
[i
]) then
806 SetLength(gLiftMap
[i
],
807 Length(gLiftMap
[i
])+32);
816 SetLength(gLiftMap
[i
], j
+1);
819 g_Game_StepLoading();
822 SetLength(gLiftMap
, i
);
827 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
830 panels
: ^TPanelArray
;
836 case PanelRec
.PanelType
of
837 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
838 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
839 PANEL_FORE
: panels
:= @gRenderForegrounds
;
840 PANEL_WATER
: panels
:= @gWater
;
841 PANEL_ACID1
: panels
:= @gAcid1
;
842 PANEL_ACID2
: panels
:= @gAcid2
;
843 PANEL_STEP
: panels
:= @gSteps
;
844 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
845 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
849 len
:= Length(panels
^);
850 SetLength(panels
^, len
+1);
852 pguid
:= Length(panByGUID
);
853 SetLength(panByGUID
, pguid
+1); //FIXME!
854 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
856 assert(pguid
< Length(panByGUID
));
857 panByGUID
[pguid
] := pan
;
861 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
863 PanelRec
.user
['panel_guid'] := pguid
;
870 function CreateNullTexture(RecName
: String): Integer;
872 RecName
:= toLowerCase1251(RecName
);
873 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
874 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
876 SetLength(Textures
, Length(Textures
)+1);
877 result
:= High(Textures
);
879 with Textures
[High(Textures
)] do
881 TextureName
:= RecName
;
885 TextureID
:= LongWord(TEXTURE_NONE
);
888 TextNameHash
.put(RecName
, result
);
892 function extractWadName (resourceName
: string): string;
896 posN
:= Pos(':', resourceName
);
898 Result
:= Copy(resourceName
, 0, posN
-1)
904 procedure addResToExternalResList (res
: AnsiString);
910 if g_Game_IsClient
or not g_Game_IsNet
then exit
;
911 if (length(res
) = 0) then exit
; // map wad
912 //res := extractWadName(res);
913 //if (length(res) = 0) then exit; // map wad
914 uname
:= toLowerCase1251(res
);
915 // do not add duplicates
916 for f
:= 0 to High(gExternalResources
) do
918 if (gExternalResources
[f
].userName
= uname
) then exit
;
920 //writeln('***(000) addResToExternalResList: res=[', res, ']');
922 fi
.userName
:= uname
;
923 if not findFileCI(res
) then exit
;
924 //writeln('***(001) addResToExternalResList: res=[', res, ']');
926 if (not GetDiskFileInfo(res
, fi
)) then
932 //writeln('***(002) addResToExternalResList: res=[', res, ']');
933 fi
.tag
:= 0; // non-zero means "cannot caclucate hash"
935 fi
.hash
:= MD5File(fi
.diskName
);
940 //e_LogWritefln('addext: res=[%s]; uname=[%s]; diskName=[%s]', [res, fi.userName, fi.diskName]);
941 SetLength(gExternalResources
, length(gExternalResources
)+1);
942 gExternalResources
[High(gExternalResources
)] := fi
;
946 procedure compactExtResList ();
952 for src
:= 0 to High(gExternalResources
) do
954 if (gExternalResources
[src
].tag
= 0) then
957 if (dest
<> src
) then gExternalResources
[dest
] := gExternalResources
[src
];
961 if (dest
<> length(gExternalResources
)) then SetLength(gExternalResources
, dest
);
965 function GetReplacementWad (WadName
: AnsiString): AnsiString;
968 if WadName
<> '' then
971 if g_Game_IsClient
then result
:= g_Res_FindReplacementWad(WadName
);
972 if (result
= WadName
) then result
:= e_FindWad(WadDirs
, result
)
977 procedure generateExternalResourcesList (map
: TDynRecord
);
979 SetLength(gExternalResources
, 0);
980 addResToExternalResList(GetReplacementWad(g_ExtractWadName(map
.MusicName
)));
981 addResToExternalResList(GetReplacementWad(g_ExtractWadName(map
.SkyName
)));
985 function CreateTexture (RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
988 TextureData
: Pointer;
990 a
, ResLength
: Integer;
992 RecName
:= toLowerCase1251(RecName
);
993 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
994 if TextNameHash
.get(RecName
, result
) then
997 //e_LogWritefln('texture ''%s'' already loaded (%s)', [RecName, result]);
1003 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
1006 if Textures <> nil then
1008 for a := 0 to High(Textures) do
1010 if (Textures[a].TextureName = RecName) then
1011 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
1012 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
1020 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
1021 if (RecName
= TEXTURE_NAME_WATER
) or
1022 (RecName
= TEXTURE_NAME_ACID1
) or
1023 (RecName
= TEXTURE_NAME_ACID2
) then
1025 SetLength(Textures
, Length(Textures
)+1);
1027 with Textures
[High(Textures
)] do
1029 TextureName
:= RecName
;
1030 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
1031 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
1032 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
1037 result
:= High(Textures
);
1038 TextNameHash
.put(RecName
, result
);
1042 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
1043 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
1044 if (WADName
<> '') then addResToExternalResList(WADName
);
1045 if WADName
= '' then WADName
:= Map
; //WADName := GameDir+'/wads/'+WADName else
1047 WAD
:= TWADFile
.Create();
1048 WAD
.ReadFile(WADName
);
1050 //txname := RecName;
1052 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
1054 FreeMem(TextureData);
1055 RecName := 'COMMON\ALIEN';
1059 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
1061 SetLength(Textures
, Length(Textures
)+1);
1062 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
1064 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
1065 SetLength(Textures
, Length(Textures
)-1);
1069 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
1070 FreeMem(TextureData
);
1071 Textures
[High(Textures
)].TextureName
:= RecName
;
1072 Textures
[High(Textures
)].Anim
:= False;
1074 result
:= High(Textures
);
1075 TextNameHash
.put(RecName
, result
);
1077 else // Íåò òàêîãî ðåóñðñà â WAD'å
1079 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
1080 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1081 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
1083 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
1084 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1086 BadTextNameHash
.put(RecName
, -1);
1093 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1096 TextureWAD
: PChar = nil;
1097 TextData
: Pointer = nil;
1098 TextureData
: Pointer = nil;
1102 TextureResource
: String;
1103 _width
, _height
, _framecount
, _speed
: Integer;
1104 _backanimation
: Boolean;
1106 ia
: TDynImageDataArray
= nil;
1107 f
, c
, frdelay
, frloop
: Integer;
1109 RecName
:= toLowerCase1251(RecName
);
1110 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
1111 if TextNameHash
.get(RecName
, result
) then
1114 //e_LogWritefln('animated texture ''%s'' already loaded (%s)', [RecName, result]);
1120 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1122 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1123 if BadTextNameHash
.get(RecName
, f
) then
1125 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1129 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1130 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
1131 if (WADName
<> '') then addResToExternalResList(WADName
);
1132 if WADName
= '' then WADName
:= Map
; //WADName := GameDir+'/wads/'+WADName else
1134 WAD
:= TWADFile
.Create();
1136 //if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
1138 WAD
.ReadFile(WADName
);
1140 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1142 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1143 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1145 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1146 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1148 BadTextNameHash
.put(RecName
, -1);
1153 if WADName = Map then
1155 //FreeMem(TextureWAD);
1156 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1162 if ResLength
< 6 then
1164 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), TMsgType
.Warning
);
1165 BadTextNameHash
.put(RecName
, -1);
1169 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1170 if isWadData(TextureWAD
, ResLength
) then
1172 // íåò, ýòî ñóïåðìåí!
1173 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1175 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1176 BadTextNameHash
.put(RecName
, -1);
1180 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1181 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1183 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1184 BadTextNameHash
.put(RecName
, -1);
1188 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1190 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1191 if TextureResource
= '' then
1193 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), TMsgType
.Warning
);
1194 BadTextNameHash
.put(RecName
, -1);
1198 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1199 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1200 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1201 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1202 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1207 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1208 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1210 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), TMsgType
.Warning
);
1211 BadTextNameHash
.put(RecName
, -1);
1218 SetLength(Textures
, Length(Textures
)+1);
1219 with Textures
[High(Textures
)] do
1221 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1222 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1224 TextureName
:= RecName
;
1228 FramesCount
:= _framecount
;
1230 result
:= High(Textures
);
1231 TextNameHash
.put(RecName
, result
);
1235 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1236 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1238 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1240 BadTextNameHash
.put(RecName
, -1);
1246 // try animated image
1248 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1249 if length(imgfmt) = 0 then
1251 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1255 GlobalMetadata
.ClearMetaItems();
1256 GlobalMetadata
.ClearMetaItemsForSaving();
1257 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1259 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), TMsgType
.Warning
);
1260 BadTextNameHash
.put(RecName
, -1);
1263 if length(ia
) = 0 then
1265 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), TMsgType
.Warning
);
1266 BadTextNameHash
.put(RecName
, -1);
1273 _width
:= ia
[0].width
;
1274 _height
:= ia
[0].height
;
1275 _framecount
:= length(ia
);
1277 _backanimation
:= false;
1280 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1282 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1284 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1286 if f
< 0 then f
:= 0;
1289 if c
< 13 then c
:= 0 else c
:= 1;
1291 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1296 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1298 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1300 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1302 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1306 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1307 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1308 f
:= ord(_backanimation
);
1309 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
);
1311 SetLength(Textures
, Length(Textures
)+1);
1312 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1313 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1315 Textures
[High(Textures
)].TextureName
:= RecName
;
1316 Textures
[High(Textures
)].Width
:= _width
;
1317 Textures
[High(Textures
)].Height
:= _height
;
1318 Textures
[High(Textures
)].Anim
:= True;
1319 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1320 Textures
[High(Textures
)].Speed
:= _speed
;
1321 result
:= High(Textures
);
1322 TextNameHash
.put(RecName
, result
);
1323 //writeln(' CREATED!');
1327 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1328 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1330 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), TMsgType
.Warning
);
1332 BadTextNameHash
.put(RecName
, -1);
1336 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1339 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1340 if (TextData
<> nil) then FreeMem(TextData
);
1341 if (TextureData
<> nil) then FreeMem(TextureData
);
1345 procedure CreateItem(Item
: TDynRecord
);
1347 if g_Game_IsClient
then Exit
;
1349 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1350 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1353 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1354 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1357 procedure CreateArea(Area
: TDynRecord
);
1362 case Area
.AreaType
of
1363 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1364 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1366 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1367 with RespawnPoints
[High(RespawnPoints
)] do
1371 Direction
:= TDirection(Area
.Direction
);
1373 case Area
.AreaType
of
1374 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1375 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1376 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1377 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1378 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1383 AREA_REDFLAG
, AREA_BLUEFLAG
:
1385 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1387 if FlagPoints
[a
] <> nil then Exit
;
1391 with FlagPoints
[a
]^ do
1393 X
:= Area
.X
-FLAGRECT
.X
;
1394 Y
:= Area
.Y
-FLAGRECT
.Y
;
1395 Direction
:= TDirection(Area
.Direction
);
1401 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1402 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1405 Animation
:= TAnimation
.Create(id
, True, 8);
1406 Obj
.Rect
:= FLAGRECT
;
1414 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1415 with DOMFlagPoints[High(DOMFlagPoints)] do
1419 Direction := TDirection(Area.Direction);
1422 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1427 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1433 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1437 mapId
:= Trigger
.id
;
1438 mapIndex
:= amapIdx
;
1441 Width
:= Trigger
.Width
;
1442 Height
:= Trigger
.Height
;
1443 Enabled
:= Trigger
.Enabled
;
1444 TexturePanelGUID
:= atpanid
;
1445 TriggerType
:= Trigger
.TriggerType
;
1446 ActivateType
:= Trigger
.ActivateType
;
1447 Keys
:= Trigger
.Keys
;
1448 trigPanelGUID
:= atrigpanid
;
1449 // HACK: used in TPanel.CanChangeTexture. maybe there's a better way?
1450 if TexturePanelGUID
<> -1 then
1452 tp
:= g_Map_PanelByGUID(TexturePanelGUID
);
1453 if (tp
<> nil) then tp
.hasTexTrigger
:= True;
1457 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1460 procedure CreateMonster(monster
: TDynRecord
);
1465 if g_Game_IsClient
then Exit
;
1467 if (gGameSettings
.GameType
= GT_SINGLE
)
1468 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1470 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1472 if gTriggers
<> nil then
1474 for a
:= 0 to High(gTriggers
) do
1476 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1478 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1479 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1484 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1488 procedure g_Map_ReAdd_DieTriggers();
1490 function monsDieTrig (mon
: TMonster
): Boolean;
1493 //tw: TStrTextWriter;
1495 result
:= false; // don't stop
1496 mon
.ClearTriggers();
1497 for a
:= 0 to High(gTriggers
) do
1499 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1501 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1503 tw := TStrTextWriter.Create();
1505 gTriggers[a].trigData.writeTo(tw);
1506 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1511 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1517 if g_Game_IsClient
then Exit
;
1519 g_Mons_ForEach(monsDieTrig
);
1522 procedure mapCreateGrid ();
1524 mapX0
: Integer = $3fffffff;
1525 mapY0
: Integer = $3fffffff;
1526 mapX1
: Integer = -$3fffffff;
1527 mapY1
: Integer = -$3fffffff;
1529 procedure calcBoundingBox (constref panels
: TPanelArray
);
1534 for idx
:= 0 to High(panels
) do
1537 if not pan
.visvalid
then continue
;
1538 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1539 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1540 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1541 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1542 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1546 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1552 //tag := panelTypeToTag(tag);
1553 for idx
:= 0 to High(panels
) do
1556 if not pan
.visvalid
then continue
;
1557 if (pan
.proxyId
<> -1) then
1559 {$IF DEFINED(D2F_DEBUG)}
1560 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
);
1564 case pan
.PanelType
of
1565 PANEL_WALL
: newtag
:= GridTagWall
;
1566 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1567 PANEL_BACK
: newtag
:= GridTagBack
;
1568 PANEL_FORE
: newtag
:= GridTagFore
;
1569 PANEL_WATER
: newtag
:= GridTagWater
;
1570 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1571 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1572 PANEL_STEP
: newtag
:= GridTagStep
;
1573 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1574 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1575 else continue
; // oops
1579 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1580 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1581 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1582 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1584 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1586 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1597 calcBoundingBox(gWalls
);
1598 calcBoundingBox(gRenderBackgrounds
);
1599 calcBoundingBox(gRenderForegrounds
);
1600 calcBoundingBox(gWater
);
1601 calcBoundingBox(gAcid1
);
1602 calcBoundingBox(gAcid2
);
1603 calcBoundingBox(gSteps
);
1604 calcBoundingBox(gLifts
);
1605 calcBoundingBox(gBlockMon
);
1607 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1609 if (mapX0
> 0) then mapX0
:= 0;
1610 if (mapY0
> 0) then mapY0
:= 0;
1612 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1613 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1615 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1616 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1618 addPanelsToGrid(gWalls
);
1619 addPanelsToGrid(gRenderBackgrounds
);
1620 addPanelsToGrid(gRenderForegrounds
);
1621 addPanelsToGrid(gWater
);
1622 addPanelsToGrid(gAcid1
);
1623 addPanelsToGrid(gAcid2
);
1624 addPanelsToGrid(gSteps
);
1625 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1626 addPanelsToGrid(gBlockMon
);
1628 mapGrid
.dumpStats();
1630 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1634 function g_Map_Load(Res
: String): Boolean;
1636 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1637 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1641 //TexturePanel: Integer;
1644 trigrec
: TDynRecord
;
1646 texPanelIdx
: Integer;
1647 texPanel
: TDynRecord
;
1649 actPanelIdx
: Integer;
1650 actPanel
: TDynRecord
;
1653 WAD
, TestWAD
: TWADFile
;
1654 //mapReader: TDynRecord = nil;
1655 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1656 panels
: TDynField
= nil; //TPanelsRec1Array;
1657 items
: TDynField
= nil; //TItemsRec1Array;
1658 monsters
: TDynField
= nil; //TMonsterRec1Array;
1659 areas
: TDynField
= nil; //TAreasRec1Array;
1660 triggers
: TDynField
= nil; //TTriggersRec1Array;
1663 AddTextures
: TAddTextureArray
;
1664 TriggersTable
: array of TTRec
;
1665 FileName
, mapResName
, TexName
, s
: AnsiString;
1668 ok
, isAnim
: Boolean;
1669 CurTex
, ntn
: Integer;
1670 rec
, texrec
: TDynRecord
;
1672 pannum
, trignum
, cnt
, tgpid
: Integer;
1674 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1675 //moveActive: Boolean;
1677 mapOk
: Boolean = false;
1678 usedTextures
: THashStrInt
= nil; // key: mapTextureList
1685 //gCurrentMap.Free();
1686 //gCurrentMap := nil;
1691 gMapInfo
.Map
:= Res
;
1692 TriggersTable
:= nil;
1695 sfsGCDisable(); // temporary disable removing of temporary volumes
1697 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1698 if (gCurrentMap
= nil) then
1700 FileName
:= g_ExtractWadName(Res
);
1701 e_LogWritefln('Loading map WAD [%s] (res=[%s])', [FileName
, Res
], TMsgType
.Notify
);
1702 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1704 WAD
:= TWADFile
.Create();
1705 if not WAD
.ReadFile(FileName
) then
1707 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1712 if gTestMap
<> '' then
1714 s
:= g_ExtractWadName(gTestMap
);
1715 TestWAD
:= TWADFile
.Create();
1716 if not TestWAD
.ReadFile(s
) then
1718 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [s
]));
1724 if TestWAD
<> nil then
1726 mapResName
:= g_ExtractFileName(gTestMap
);
1727 if not TestWAD
.GetMapResource(mapResName
, Data
, Len
) then
1729 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1732 e_WriteLog('Using test map: '+gTestMap
, TMsgType
.Notify
);
1739 //k8: why loader ignores path here?
1740 mapResName
:= g_ExtractFileName(Res
);
1741 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1743 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1753 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1759 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1760 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1762 stt
:= getTimeMicro();
1765 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1768 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1770 gCurrentMapFileName
:= '';
1776 if (gCurrentMap
= nil) then
1778 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1779 gCurrentMapFileName
:= '';
1785 stt
:= getTimeMicro();
1788 //gCurrentMap := mapReader;
1790 generateExternalResourcesList(gCurrentMap
);
1791 mapTextureList
:= gCurrentMap
['texture'];
1792 // get all other lists here too
1793 panels
:= gCurrentMap
['panel'];
1794 triggers
:= gCurrentMap
['trigger'];
1795 items
:= gCurrentMap
['item'];
1796 areas
:= gCurrentMap
['area'];
1797 monsters
:= gCurrentMap
['monster'];
1799 // Çàãðóçêà îïèñàíèÿ êàðòû:
1800 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1801 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1805 Name
:= gCurrentMap
.MapName
;
1806 Description
:= gCurrentMap
.MapDesc
;
1807 Author
:= gCurrentMap
.MapAuthor
;
1808 MusicName
:= gCurrentMap
.MusicName
;
1809 SkyName
:= gCurrentMap
.SkyName
;
1810 Height
:= gCurrentMap
.Height
;
1811 Width
:= gCurrentMap
.Width
;
1814 // Çàãðóçêà òåêñòóð:
1815 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1816 // Äîáàâëåíèå òåêñòóð â Textures[]:
1817 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1819 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1820 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1822 // find used textures
1823 usedTextures
:= THashStrInt
.Create();
1825 if (panels
<> nil) and (panels
.count
> 0) then
1827 for rec
in panels
do
1829 texrec
:= rec
.TextureRec
;
1830 if (texrec
<> nil) then usedTextures
.put(toLowerCase1251(texrec
.Resource
), 42);
1835 for rec
in mapTextureList
do
1838 if not usedTextures
.has(toLowerCase1251(rec
.Resource
)) then
1840 rec
.tagInt
:= -1; // just in case
1841 e_LogWritefln(' Unused texture #%d: %s', [cnt
, rec
.Resource
]);
1845 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1846 e_LogWritefln(' Loading texture #%d: %s', [cnt
, rec
.Resource
]);
1848 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1851 // Àíèìèðîâàííàÿ òåêñòóðà
1852 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1853 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [rec
.Resource
]));
1858 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1859 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [rec
.Resource
]));
1861 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1863 rec
.tagInt
:= ntn
; // remember texture number
1865 g_Game_StepLoading();
1868 usedTextures
.Free();
1871 // set panel tagInt to texture index
1872 if (panels
<> nil) then
1874 for rec
in panels
do
1876 texrec
:= rec
.TextureRec
;
1877 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1883 // Çàãðóçêà òðèããåðîâ
1884 gTriggerClientID
:= 0;
1885 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1886 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1889 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1890 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1892 // check texture numbers for panels
1893 if (panels
<> nil) and (panels
.count
> 0) then
1895 for rec
in panels
do
1897 if (rec
.tagInt
< 0) then
1899 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1903 gCurrentMapFileName
:= '';
1909 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1910 if (triggers
<> nil) and (triggers
.count
> 0) then
1912 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1913 //SetLength(TriggersTable, triggers.count);
1914 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1916 SetLength(TriggersTable
, triggers
.count
);
1918 for rec
in triggers
do
1921 pttit
:= @TriggersTable
[trignum
];
1922 pttit
.trigrec
:= rec
;
1923 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1924 pttit
.texPanelIdx
:= -1; // will be fixed later
1925 pttit
.texPanel
:= rec
.TexturePanelRec
;
1927 pttit
.actPanelIdx
:= -1;
1928 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1930 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1931 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1933 g_Game_StepLoading();
1938 if (panels
<> nil) and (panels
.count
> 0) then
1940 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1941 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1944 for rec
in panels
do
1947 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1949 SetLength(AddTextures
, 0);
1953 if (mapTextureList
<> nil) then
1955 texrec
:= rec
.TextureRec
;
1956 ok
:= (texrec
<> nil);
1961 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1962 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1964 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1966 if rec
.userPanelTrigRef
then
1968 // e_LogWritefln('trigref for panel %s', [pannum]);
1976 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1977 s
:= texrec
.Resource
;
1979 // Ñïåö-òåêñòóðû çàïðåùåíû
1980 if g_Map_IsSpecialTexture(s
) then
1986 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1987 ok
:= g_Texture_NumNameFindStart(s
);
1990 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1991 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1994 k
:= NNF_NAME_BEFORE
;
1995 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1996 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1998 k
:= g_Texture_NumNameFindNext(TexName
);
2000 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
2002 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
2005 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
2007 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2008 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2009 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2012 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
2014 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2015 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
2016 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2021 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
2023 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2024 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
2025 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2028 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
2030 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2031 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
2032 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
2036 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
2040 for c := 0 to High(Textures) do
2042 if (Textures[c].TextureName = TexName) then
2044 SetLength(AddTextures, Length(AddTextures)+1);
2045 AddTextures[High(AddTextures)].Texture := c;
2046 AddTextures[High(AddTextures)].Anim := isAnim;
2051 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
2053 SetLength(AddTextures
, Length(AddTextures
)+1);
2054 AddTextures
[High(AddTextures
)].Texture
:= c
;
2055 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
2061 if k
= NNF_NAME_EQUALS
then
2063 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
2064 SetLength(AddTextures
, Length(AddTextures
)+1);
2065 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
2066 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
2067 CurTex
:= High(AddTextures
);
2078 end; // if ok - åñòü ñìåæíûå òåêñòóðû
2079 end; // if ok - ññûëàþòñÿ òðèããåðû
2083 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
2084 SetLength(AddTextures
, 1);
2085 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
2086 AddTextures
[0].Anim
:= false;
2087 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2091 //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);
2093 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2095 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2096 //e_LogWritefln('new panel; tcount=%s; curtex=%s', [Length(AddTextures), CurTex]);
2097 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2098 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2099 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2102 moveSpeed
:= rec
.moveSpeed
;
2103 //moveStart := rec.moveStart;
2104 //moveEnd := rec.moveEnd;
2105 //moveActive := rec['move_active'].value;
2106 if not moveSpeed
.isZero
then
2108 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2109 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2110 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2113 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2115 g_Game_StepLoading();
2119 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2120 for b
:= 0 to High(TriggersTable
) do
2122 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
2123 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
2126 // create map grid, init other grids (for monsters, for example)
2127 e_WriteLog('Creating map grid', TMsgType
.Notify
);
2130 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2131 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2133 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2134 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2135 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2137 for rec
in triggers
do
2140 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
2141 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2142 TriggersTable
[trignum
].tnum
:= trignum
;
2143 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
2147 //FIXME: use hashtable!
2148 for pan
in panByGUID
do
2150 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2152 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2154 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2156 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2160 // Çàãðóçêà ïðåäìåòîâ
2161 e_WriteLog(' Loading items...', TMsgType
.Notify
);
2162 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2164 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2165 if (items
<> nil) and not gLoadGameMode
then
2167 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
2168 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2169 for rec
in items
do CreateItem(rec
);
2172 // Çàãðóçêà îáëàñòåé
2173 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
2174 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2176 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2177 if areas
<> nil then
2179 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
2180 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2181 for rec
in areas
do CreateArea(rec
);
2184 // Çàãðóçêà ìîíñòðîâ
2185 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
2186 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2188 gTotalMonsters
:= 0;
2190 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2191 if (monsters
<> nil) and not gLoadGameMode
then
2193 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
2194 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2195 for rec
in monsters
do CreateMonster(rec
);
2198 //gCurrentMap := mapReader; // this will be our current map now
2199 gCurrentMapFileName
:= Res
;
2203 if (gMapInfo
.SkyName
<> '') then
2205 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
2206 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2207 if gTextureFilter
then TEXTUREFILTER
:= GL_LINEAR
else TEXTUREFILTER
:= GL_NEAREST
;
2209 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.SkyName
, g_ExtractWadName(Res
));
2210 if g_Texture_CreateWAD(BackID
, s
) then
2211 g_Game_SetupScreenSize
2213 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]))
2215 TEXTUREFILTER
:= GL_NEAREST
;
2221 if gMapInfo
.MusicName
<> '' then
2223 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
2224 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2226 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.MusicName
, g_ExtractWadName(Res
));
2227 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2230 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2233 // Îñòàëüíûå óñòàíâêè
2241 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2242 if not gLoadGameMode
then g_GFX_Init();
2244 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2245 mapTextureList
:= nil;
2250 TriggersTable
:= nil;
2253 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2254 if ok
and (not gLoadGameMode
) then
2256 gMusic
.SetByName(gMapInfo
.MusicName
);
2261 gMusic
.SetByName('');
2264 stt
:= getTimeMicro()-stt
;
2265 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2268 sfsGCEnable(); // enable releasing unused volumes
2270 e_UnpressAllKeys
; // why not?
2275 gCurrentMapFileName
:= '';
2279 compactExtResList();
2280 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2285 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2288 mapReader
: TDynRecord
;
2289 //Header: TMapHeaderRec_1;
2294 FillChar(Result
, SizeOf(Result
), 0);
2295 FileName
:= g_ExtractWadName(Res
);
2297 WAD
:= TWADFile
.Create();
2298 if not WAD
.ReadFile(FileName
) then
2304 //k8: it ignores path again
2305 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2314 mapReader
:= g_Map_ParseMap(Data
, Len
);
2323 if (mapReader
= nil) then exit
;
2325 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2327 Result
.Name
:= mapReader
.MapName
;
2328 Result
.Description
:= mapReader
.MapDesc
;
2330 Result
.Author
:= mapReader
.MapAuthor
;
2331 Result
.Height
:= mapReader
.Height
;
2332 Result
.Width
:= mapReader
.Width
;
2336 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2337 //ZeroMemory(@Header, SizeOf(Header));
2338 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2339 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2341 Result
.Author
:= '';
2349 function g_Map_GetMapsList(WADName
: string): SSArray
;
2356 WAD
:= TWADFile
.Create();
2357 if not WAD
.ReadFile(WADName
) then
2362 ResList
:= WAD
.GetMapResources();
2363 if ResList
<> nil then
2365 for a
:= 0 to High(ResList
) do
2367 SetLength(Result
, Length(Result
)+1);
2368 Result
[High(Result
)] := ResList
[a
];
2374 function g_Map_Exist(Res
: string): Boolean;
2377 FileName
, mnn
: string;
2383 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2385 WAD
:= TWADFile
.Create
;
2386 if not WAD
.ReadFile(FileName
) then
2392 ResList
:= WAD
.GetMapResources();
2395 mnn
:= g_ExtractFileName(Res
);
2396 if ResList
<> nil then
2397 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2404 procedure g_Map_Free(freeTextures
: Boolean=true);
2408 procedure FreePanelArray(var panels
: TPanelArray
);
2413 if panels
<> nil then
2415 for i
:= 0 to High(panels
) do
2428 RespawnPoints
:= nil;
2429 if FlagPoints
[FLAG_RED
] <> nil then
2431 Dispose(FlagPoints
[FLAG_RED
]);
2432 FlagPoints
[FLAG_RED
] := nil;
2434 if FlagPoints
[FLAG_BLUE
] <> nil then
2436 Dispose(FlagPoints
[FLAG_BLUE
]);
2437 FlagPoints
[FLAG_BLUE
] := nil;
2439 //DOMFlagPoints := nil;
2443 if (Length(gCurrentMapFileName
) <> 0) then
2445 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2449 e_LogWritefln('g_Map_Free: no previous map.', []);
2452 if freeTextures
then
2454 e_LogWritefln('g_Map_Free: clearing textures...', []);
2455 if (Textures
<> nil) then
2457 for a
:= 0 to High(Textures
) do
2459 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2461 if Textures
[a
].Anim
then
2463 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2467 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2469 e_DeleteTexture(Textures
[a
].TextureID
);
2476 TextNameHash
.Free();
2477 TextNameHash
:= nil;
2478 BadTextNameHash
.Free();
2479 BadTextNameHash
:= nil;
2480 gCurrentMapFileName
:= '';
2487 FreePanelArray(gWalls
);
2488 FreePanelArray(gRenderBackgrounds
);
2489 FreePanelArray(gRenderForegrounds
);
2490 FreePanelArray(gWater
);
2491 FreePanelArray(gAcid1
);
2492 FreePanelArray(gAcid2
);
2493 FreePanelArray(gSteps
);
2494 FreePanelArray(gLifts
);
2495 FreePanelArray(gBlockMon
);
2496 gMovingWallIds
:= nil;
2498 if BackID
<> DWORD(-1) then
2502 e_DeleteTexture(BackID
);
2503 BackID
:= DWORD(-1);
2506 g_Game_StopAllSounds(False);
2508 g_Sound_Delete(gMapInfo
.MusicName
);
2510 gMapInfo
.Name
:= '';
2511 gMapInfo
.Description
:= '';
2512 gMapInfo
.MusicName
:= '';
2513 gMapInfo
.Height
:= 0;
2514 gMapInfo
.Width
:= 0;
2520 procedure g_Map_Update();
2527 procedure UpdatePanelArray(var panels
: TPanelArray
);
2532 for i
:= 0 to High(panels
) do panels
[i
].Update();
2536 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2538 UpdatePanelArray(gWalls
);
2539 UpdatePanelArray(gRenderBackgrounds
);
2540 UpdatePanelArray(gRenderForegrounds
);
2541 UpdatePanelArray(gWater
);
2542 UpdatePanelArray(gAcid1
);
2543 UpdatePanelArray(gAcid2
);
2544 UpdatePanelArray(gSteps
);
2546 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2548 if gGameSettings
.GameMode
= GM_CTF
then
2550 for a
:= FLAG_RED
to FLAG_BLUE
do
2552 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2556 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2561 m
:= g_Obj_Move(@Obj
, True, True);
2563 NeedSend
:= NeedSend
or (Obj
.X
<> Obj
.oldX
) or (Obj
.Y
<> Obj
.oldY
);
2565 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2567 // Ñîïðîòèâëåíèå âîçäóõà
2568 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2570 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2571 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2574 gFlags
[a
].CaptureTime
:= 0;
2575 if a
= FLAG_RED
then
2576 s
:= _lc
[I_PLAYER_FLAG_RED
]
2578 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2579 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2581 if (((gPlayer1
<> nil) and (((gPlayer1
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer1
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))
2582 or ((gPlayer2
<> nil) and (((gPlayer2
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer2
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))) then
2587 if not sound_ret_flag
[b
].IsPlaying() then
2588 sound_ret_flag
[b
].Play();
2590 if g_Game_IsNet
then
2591 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2595 if Count
> 0 then Count
-= 1;
2598 if gPlayers
<> nil then
2600 j
:= Random(Length(gPlayers
)) - 1;
2601 for d
:= 0 to High(gPlayers
) do
2604 if j
> High(gPlayers
) then j
:= 0;
2605 if gPlayers
[j
] <> nil then
2607 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2609 if gPlayers
[j
].GetFlag(a
) then Break
;
2620 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2621 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2627 if WordBool(PanelType
and PANEL_WALL
) then
2628 if gWalls
<> nil then
2633 if gWalls
[a
].Enabled
and
2634 g_Collide(X
, Y
, Width
, Height
,
2635 gWalls
[a
].X
, gWalls
[a
].Y
,
2636 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2643 if WordBool(PanelType
and PANEL_WATER
) then
2644 if gWater
<> nil then
2649 if g_Collide(X
, Y
, Width
, Height
,
2650 gWater
[a
].X
, gWater
[a
].Y
,
2651 gWater
[a
].Width
, gWater
[a
].Height
) then
2658 if WordBool(PanelType
and PANEL_ACID1
) then
2659 if gAcid1
<> nil then
2664 if g_Collide(X
, Y
, Width
, Height
,
2665 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2666 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2673 if WordBool(PanelType
and PANEL_ACID2
) then
2674 if gAcid2
<> nil then
2679 if g_Collide(X
, Y
, Width
, Height
,
2680 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2681 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2688 if WordBool(PanelType
and PANEL_STEP
) then
2689 if gSteps
<> nil then
2694 if g_Collide(X
, Y
, Width
, Height
,
2695 gSteps
[a
].X
, gSteps
[a
].Y
,
2696 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2703 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2704 if gLifts
<> nil then
2709 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= LIFTTYPE_UP
)) or
2710 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= LIFTTYPE_DOWN
)) or
2711 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_LEFT
)) or
2712 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_RIGHT
))) and
2713 g_Collide(X
, Y
, Width
, Height
,
2714 gLifts
[a
].X
, gLifts
[a
].Y
,
2715 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2722 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2723 if gBlockMon
<> nil then
2725 h
:= High(gBlockMon
);
2729 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2730 g_Collide(X
, Y
, Width
, Height
,
2731 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2732 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2740 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2744 function checkPanels (constref panels
: TPanelArray
): Boolean;
2749 if panels
= nil then exit
;
2750 for a
:= 0 to High(panels
) do
2752 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2755 texid
:= panels
[a
].GetTextureID();
2762 texid
:= LongWord(TEXTURE_NONE
);
2764 if not checkPanels(gWater
) then
2765 if not checkPanels(gAcid1
) then
2766 if not checkPanels(gAcid2
) then exit
;
2771 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2773 SlowMask
= GridTagLift
or GridTagBlockMon
;
2775 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2778 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2780 result := pan.Enabled;
2785 if ((tag
and GridTagLift
) <> 0) then
2788 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2789 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2790 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2791 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2792 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2796 if ((tag
and GridTagBlockMon
) <> 0) then
2798 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2803 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2804 result
:= true; // i found her!
2808 tagmask
: Integer = 0;
2810 it
: TPanelGrid
.Iter
;
2814 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2815 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2816 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2817 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2818 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2819 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2820 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2822 if (tagmask
= 0) then exit
; // just in case
2824 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2825 if gdbg_map_use_accel_coldet
then
2827 if ((tagmask
and SlowMask
) <> 0) then
2830 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
);
2834 if ((pan
.tag
and GridTagLift
) <> 0) then
2837 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2838 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2839 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2840 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2841 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2843 else if ((pan
.tag
and GridTagBlockMon
) <> 0) then
2845 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2850 result
:= true; // i found her!
2852 if (result
) then break
;
2858 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
, false, true); // return first hit
2859 result
:= (it
.length
> 0);
2865 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2867 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2871 // returns `true` if we need to stop
2872 function liquidChecker (pan
: TPanel
; var texid
: DWORD
; var cctype
: Integer): Boolean; inline;
2875 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2878 0: if ((pan
.tag
and GridTagWater
) = 0) then exit
; // allowed: water
2879 1: if ((pan
.tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2880 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2883 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2885 texid
:= pan
.GetTextureID();
2886 // water? water has the highest priority, so stop right here
2887 if ((pan
.tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2889 if ((pan
.tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2891 if ((pan
.tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2894 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2896 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2898 it
: TPanelGrid
.Iter
;
2900 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2901 if gdbg_map_use_accel_coldet
then
2903 result
:= LongWord(TEXTURE_NONE
);
2904 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2905 for mwit
in it
do if (liquidChecker(mwit
^, result
, cctype
)) then break
;
2910 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2912 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2916 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2917 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2918 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2921 procedure g_Map_EnableWallGUID (pguid
: Integer);
2925 //pan := gWalls[ID];
2926 pan
:= g_Map_PanelByGUID(pguid
);
2927 if (pan
= nil) then exit
;
2928 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
2930 pan
.Enabled
:= True;
2931 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2933 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2934 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2935 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2937 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2938 // mark platform as interesting
2941 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2942 //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);
2947 procedure g_Map_DisableWallGUID (pguid
: Integer);
2951 //pan := gWalls[ID];
2952 pan
:= g_Map_PanelByGUID(pguid
);
2953 if (pan
= nil) then exit
;
2954 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
2956 pan
.Enabled
:= False;
2957 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2959 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2960 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2962 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2963 // mark platform as interesting
2966 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2967 //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);
2972 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
2976 tp
:= g_Map_PanelByGUID(pguid
);
2977 if (tp
= nil) then exit
;
2978 tp
.NextTexture(AnimLoop
);
2979 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
2983 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2987 //pan := gLifts[ID];
2988 pan
:= g_Map_PanelByGUID(pguid
);
2989 if (pan
= nil) then exit
;
2990 if not pan
.isGLift
then exit
;
2992 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2994 with {gLifts[ID]} pan
do
2998 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2999 //TODO: make separate lift tags, and change tag here
3002 LIFTTYPE_UP
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
3003 LIFTTYPE_DOWN
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
3004 LIFTTYPE_LEFT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
3005 LIFTTYPE_RIGHT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
3008 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3009 // mark platform as interesting
3015 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
3018 PointsArray
: Array of TRespawnPoint
;
3021 SetLength(PointsArray
, 0);
3023 if RespawnPoints
= nil then
3026 for a
:= 0 to High(RespawnPoints
) do
3027 if RespawnPoints
[a
].PointType
= PointType
then
3029 SetLength(PointsArray
, Length(PointsArray
)+1);
3030 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3033 if PointsArray
= nil then
3036 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3040 function g_Map_GetPointCount(PointType
: Byte): Word;
3046 if RespawnPoints
= nil then
3049 for a
:= 0 to High(RespawnPoints
) do
3050 if RespawnPoints
[a
].PointType
= PointType
then
3051 Result
:= Result
+ 1;
3054 function g_Map_GetRandomPointType(): Byte;
3056 if RespawnPoints
= nil then
3059 Result
:= RespawnPoints
[Random(Length(RespawnPoints
))].PointType
;
3062 function g_Map_HaveFlagPoints(): Boolean;
3064 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3067 procedure g_Map_ResetFlag(Flag
: Byte);
3069 with gFlags
[Flag
] do
3075 Direction
:= TDirection
.D_LEFT
;
3076 State
:= FLAG_STATE_NONE
;
3077 if FlagPoints
[Flag
] <> nil then
3079 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3080 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3081 Direction
:= FlagPoints
[Flag
]^.Direction
;
3082 State
:= FLAG_STATE_NORMAL
;
3086 NeedSend
:= False; // the event will take care of this
3091 procedure g_Map_SaveState (st
: TStream
);
3095 procedure savePanels ();
3100 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
3101 for pan
in panByGUID
do pan
.SaveState(st
);
3104 procedure saveFlag (flag
: PFlag
);
3108 utils
.writeSign(st
, 'FLAG');
3109 utils
.writeInt(st
, Byte(0)); // version
3110 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3111 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
3113 utils
.writeInt(st
, Byte(flag
^.State
));
3114 // Íàïðàâëåíèå ôëàãà
3115 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3116 utils
.writeInt(st
, Byte(b
));
3118 Obj_SaveState(st
, @flag
^.Obj
);
3125 utils
.writeSign(st
, 'MUSI');
3126 utils
.writeInt(st
, Byte(0));
3128 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3129 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3130 utils
.writeStr(st
, str
);
3131 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3132 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
3133 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3134 utils
.writeBool(st
, gMusic
.SpecPause
);
3136 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3137 utils
.writeInt(st
, LongInt(gTotalMonsters
));
3140 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3141 if (gGameSettings
.GameMode
= GM_CTF
) then
3143 // Ôëàã Êðàñíîé êîìàíäû
3144 saveFlag(@gFlags
[FLAG_RED
]);
3145 // Ôëàã Ñèíåé êîìàíäû
3146 saveFlag(@gFlags
[FLAG_BLUE
]);
3150 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3151 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3153 // Î÷êè Êðàñíîé êîìàíäû
3154 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Score
));
3155 // Î÷êè Ñèíåé êîìàíäû
3156 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Score
));
3162 procedure g_Map_LoadState (st
: TStream
);
3168 procedure loadPanels ();
3173 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
3174 for pan
in panByGUID
do
3177 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3181 procedure loadFlag (flag
: PFlag
);
3186 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
3187 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
3188 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3189 flag
^.RespawnType
:= utils
.readByte(st
);
3191 flag
^.State
:= utils
.readByte(st
);
3192 // Íàïðàâëåíèå ôëàãà
3193 b
:= utils
.readByte(st
);
3194 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
3196 Obj_LoadState(@flag
^.Obj
, st
);
3200 if (st
= nil) then exit
;
3202 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3206 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3210 ///// Çàãðóæàåì ìóçûêó: /////
3211 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
3212 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
3214 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3215 str
:= utils
.readStr(st
);
3216 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3217 dw
:= utils
.readLongWord(st
);
3218 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3219 boo
:= utils
.readBool(st
);
3220 // Çàïóñêàåì ýòó ìóçûêó
3221 gMusic
.SetByName(str
);
3222 gMusic
.SpecPause
:= boo
;
3225 gMusic
.SetPosition(dw
);
3228 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3229 gTotalMonsters
:= utils
.readLongInt(st
);
3232 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3233 if (gGameSettings
.GameMode
= GM_CTF
) then
3235 // Ôëàã Êðàñíîé êîìàíäû
3236 loadFlag(@gFlags
[FLAG_RED
]);
3237 // Ôëàã Ñèíåé êîìàíäû
3238 loadFlag(@gFlags
[FLAG_BLUE
]);
3242 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3243 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3245 // Î÷êè Êðàñíîé êîìàíäû
3246 gTeamStat
[TEAM_RED
].Score
:= utils
.readSmallInt(st
);
3247 // Î÷êè Ñèíåé êîìàíäû
3248 gTeamStat
[TEAM_BLUE
].Score
:= utils
.readSmallInt(st
);
3254 // trace liquid, stepping by `dx` and `dy`
3255 // return last seen liquid coords, and `false` if we're started outside of the liquid
3256 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3258 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3262 // started outside of the liquid?
3263 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
3264 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3265 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3271 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
3272 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3280 DynWarningCB
:= mapWarningCB
;