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!
246 var (* private state *)
247 Textures
: TLevelTextureArray
= nil;
252 e_input
, e_log
, e_res
, g_items
, g_gfx
, g_console
,
253 g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
254 g_options
, g_triggers
, g_player
, r_textures
, r_animations
,
255 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
256 sfs
, xstreams
, hashtable
, wadreader
,
260 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
261 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
262 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
265 // ////////////////////////////////////////////////////////////////////////// //
266 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
270 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
274 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
279 // ////////////////////////////////////////////////////////////////////////// //
281 panByGUID
: array of TPanel
= nil;
284 // ////////////////////////////////////////////////////////////////////////// //
285 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
287 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
288 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
292 // return `true` from `cb` to stop
293 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
298 if not assigned(cb
) then exit
;
299 for pan
in panByGUID
do
301 if cb(pan
) then begin result
:= pan
; exit
; end;
306 procedure g_Map_NetSendInterestingPanels ();
310 if g_Game_IsServer
and g_Game_IsNet
then
312 for pan
in panByGUID
do
314 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
320 // ////////////////////////////////////////////////////////////////////////// //
321 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
322 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
323 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
324 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
327 // ////////////////////////////////////////////////////////////////////////// //
329 dfmapdef
: TDynMapDef
= nil;
332 procedure loadMapDefinition ();
334 pr
: TTextParser
= nil;
338 if (dfmapdef
<> nil) then exit
;
341 e_LogWritefln('parsing "mapdef.txt"...', []);
342 st
:= e_OpenResourceRO(DataDirs
, 'mapdef.txt');
343 e_LogWritefln('found local "mapdef.txt"', []);
350 WAD
:= TWADFile
.Create();
351 if not WAD
.ReadFile(GameWAD
) then
353 //raise Exception.Create('cannot load "game.wad"');
358 st
:= WAD
.openFileStream('mapdef.txt');
365 //raise Exception.Create('cannot open "mapdef.txt"');
366 e_LogWriteln('using default "mapdef.txt"...');
367 pr
:= TStrTextParser
.Create(defaultMapDef
);
371 pr
:= TFileTextParser
.Create(st
);
373 except on e
: Exception
do
375 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
381 dfmapdef
:= TDynMapDef
.Create(pr
);
383 on e
: TDynParseException
do
384 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
386 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
394 // ////////////////////////////////////////////////////////////////////////// //
395 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
397 wst
: TSFSMemoryChunkStream
= nil;
400 if (dataLen
< 4) then exit
;
402 if (dfmapdef
= nil) then writeln('need to load mapdef');
404 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
406 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
408 result
:= dfmapdef
.parseMap(wst
);
410 on e
: TDynParseException
do
412 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
419 e_LogWritefln('ERROR: %s', [e
.message]);
426 //e_LogWriteln('map parsed.');
430 // ////////////////////////////////////////////////////////////////////////// //
432 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
433 NNF_PureExt
: String; // extension postfix
434 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
435 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
438 function g_Texture_NumNameFindStart(name
: String): Boolean;
447 NNF_CurrentNum
:= -1;
449 for i
:= Length(name
) downto 1 do
450 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
452 if i
= Length(name
) then
453 begin // Íåò öèôð â êîíöå ñòðîêè
459 while (j
<= Length(name
)) and (name
[j
] <> '.') do inc(j
);
460 NNF_PureName
:= Copy(name
, 1, i
);
461 NNF_PureExt
:= Copy(name
, j
);
462 name
:= Copy(name
, i
+ 1, j
- i
- 1);
467 // Íå ïåðåâåñòè â ÷èñëî:
468 if not TryStrToInt(name
, NNF_FirstNum
) then
477 function g_Texture_NumNameFindNext(var newName
: String): Byte;
479 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
482 Result
:= NNF_NO_NAME
;
486 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
) + NNF_PureExt
;
488 if NNF_CurrentNum
< NNF_FirstNum
then
489 Result
:= NNF_NAME_BEFORE
491 if NNF_CurrentNum
> NNF_FirstNum
then
492 Result
:= NNF_NAME_AFTER
494 Result
:= NNF_NAME_EQUALS
;
500 // ////////////////////////////////////////////////////////////////////////// //
501 function panelTypeToTag (panelType
: Word): Integer;
504 PANEL_WALL
: result
:= GridTagWall
; // gWalls
505 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
506 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
507 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
508 PANEL_WATER
: result
:= GridTagWater
; // gWater
509 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
510 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
511 PANEL_STEP
: result
:= GridTagStep
; // gSteps
512 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
513 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
514 else result
:= GridTagInvalid
;
519 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
521 if (a
.tag
< b
.tag
) then begin result
:= true; exit
; end;
522 if (a
.tag
> b
.tag
) then begin result
:= false; exit
; end;
523 result
:= (a
.arrIdx
< b
.arrIdx
);
527 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
528 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
529 RespawnPoints
: array of TRespawnPoint
;
530 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
531 //DOMFlagPoints: Array of TFlagPoint;
534 procedure g_Map_ProfilersBegin ();
536 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
537 if (profMapCollision
<> nil) then profMapCollision
.mainBegin(g_profile_collision
);
539 if g_profile_collision
and (profMapCollision
<> nil) then
541 profMapCollision
.sectionBegin('*solids');
542 profMapCollision
.sectionEnd();
543 profMapCollision
.sectionBegin('liquids');
544 profMapCollision
.sectionEnd();
548 procedure g_Map_ProfilersEnd ();
550 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
554 // wall index in `gWalls` or -1
555 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
559 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, (GridTagWall
or GridTagDoor
));
560 if (result
<> nil) then
562 if (hitx
<> nil) then hitx
^ := ex
;
563 if (hity
<> nil) then hity
^ := ey
;
567 if (hitx
<> nil) then hitx
^ := x1
;
568 if (hity
<> nil) then hity
^ := y1
;
572 // returns panel or nil
573 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
577 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, tag
);
578 if (result
<> nil) then
580 if (hitx
<> nil) then hitx
^ := ex
;
581 if (hity
<> nil) then hity
^ := ey
;
585 if (hitx
<> nil) then hitx
^ := x1
;
586 if (hity
<> nil) then hity
^ := y1
;
591 function xxPanAtPointChecker (pan
: TPanel
; panelType
: Word): Boolean; inline;
593 if ((pan
.tag
and GridTagLift
) <> 0) then
595 // stop if the lift of the right type
597 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
598 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
599 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
600 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
)));
603 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
606 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
608 tagmask
: Integer = 0;
614 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
615 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
616 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
617 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
618 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
619 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
620 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
622 if (tagmask
= 0) then exit
;// just in case
624 if ((tagmask
and GridTagLift
) <> 0) then
627 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
);
628 for mwit
in it
do if (xxPanAtPointChecker(mwit
^, PanelType
)) then begin result
:= true; break
; end;
633 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true);
634 result
:= (it
.length
<> 0); // firsthit
640 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
645 if (tagmask
= 0) then exit
;
646 it
:= mapGrid
.forEachAtPoint(x
, y
, tagmask
, false, true); // firsthit
647 if (it
.length
<> 0) then result
:= it
.first
^;
652 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
654 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
655 (Texture
= TEXTURE_NAME_ACID1
) or
656 (Texture
= TEXTURE_NAME_ACID2
);
659 procedure CreateDoorMap();
661 PanelArray
: Array of record
667 a
, b
, c
, m
, i
, len
: Integer;
675 SetLength(PanelArray
, len
);
677 for a
:= 0 to High(gWalls
) do
678 if gWalls
[a
].Door
then
680 PanelArray
[i
].X
:= gWalls
[a
].X
;
681 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
682 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
683 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
684 PanelArray
[i
].Active
:= True;
685 PanelArray
[i
].PanelID
:= a
;
691 SetLength(PanelArray
, len
);
702 SetLength(gDoorMap
, 0);
704 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
707 if PanelArray
[a
].Active
then
709 PanelArray
[a
].Active
:= False;
710 m
:= Length(gDoorMap
);
711 SetLength(gDoorMap
, m
+1);
712 SetLength(gDoorMap
[m
], 1);
713 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
721 if PanelArray
[b
].Active
then
722 for c
:= 0 to High(gDoorMap
[m
]) do
723 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
724 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
725 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
726 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
727 gWalls
[gDoorMap
[m
, c
]].X
,
728 gWalls
[gDoorMap
[m
, c
]].Y
,
729 gWalls
[gDoorMap
[m
, c
]].Width
,
730 gWalls
[gDoorMap
[m
, c
]].Height
) then
732 PanelArray
[b
].Active
:= False;
733 SetLength(gDoorMap
[m
],
734 Length(gDoorMap
[m
])+1);
735 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
741 g_Game_StepLoading();
747 procedure CreateLiftMap();
749 PanelArray
: Array of record
754 a
, b
, c
, len
, i
, j
: Integer;
760 len
:= Length(gLifts
);
761 SetLength(PanelArray
, len
);
763 for a
:= 0 to len
-1 do
765 PanelArray
[a
].X
:= gLifts
[a
].X
;
766 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
767 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
768 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
769 PanelArray
[a
].Active
:= True;
772 SetLength(gLiftMap
, len
);
775 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
777 for a
:= 0 to len
-1 do
778 if PanelArray
[a
].Active
then
780 PanelArray
[a
].Active
:= False;
781 SetLength(gLiftMap
[i
], 32);
789 for b
:= 0 to len
-1 do
790 if PanelArray
[b
].Active
then
792 if g_CollideAround(PanelArray
[b
].X
,
795 PanelArray
[b
].Height
,
796 PanelArray
[gLiftMap
[i
, c
]].X
,
797 PanelArray
[gLiftMap
[i
, c
]].Y
,
798 PanelArray
[gLiftMap
[i
, c
]].Width
,
799 PanelArray
[gLiftMap
[i
, c
]].Height
) then
801 PanelArray
[b
].Active
:= False;
803 if j
> High(gLiftMap
[i
]) then
804 SetLength(gLiftMap
[i
],
805 Length(gLiftMap
[i
])+32);
814 SetLength(gLiftMap
[i
], j
+1);
817 g_Game_StepLoading();
820 SetLength(gLiftMap
, i
);
825 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
828 panels
: ^TPanelArray
;
834 case PanelRec
.PanelType
of
835 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
836 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
837 PANEL_FORE
: panels
:= @gRenderForegrounds
;
838 PANEL_WATER
: panels
:= @gWater
;
839 PANEL_ACID1
: panels
:= @gAcid1
;
840 PANEL_ACID2
: panels
:= @gAcid2
;
841 PANEL_STEP
: panels
:= @gSteps
;
842 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
843 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
847 len
:= Length(panels
^);
848 SetLength(panels
^, len
+1);
850 pguid
:= Length(panByGUID
);
851 SetLength(panByGUID
, pguid
+1); //FIXME!
852 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
854 assert(pguid
< Length(panByGUID
));
855 panByGUID
[pguid
] := pan
;
859 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
861 PanelRec
.user
['panel_guid'] := pguid
;
868 function CreateNullTexture(RecName
: String): Integer;
870 RecName
:= toLowerCase1251(RecName
);
871 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
872 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
874 SetLength(Textures
, Length(Textures
) + 1);
875 Textures
[High(Textures
)].TextureName
:= RecName
;
876 Textures
[High(Textures
)].FullName
:= '';
877 Textures
[High(Textures
)].Anim
:= False;
878 Result
:= High(Textures
);
879 TextNameHash
.put(RecName
, result
);
883 function extractWadName (resourceName
: string): string;
887 posN
:= Pos(':', resourceName
);
889 Result
:= Copy(resourceName
, 0, posN
-1)
895 procedure addResToExternalResList (res
: AnsiString);
901 if g_Game_IsClient
or not g_Game_IsNet
then exit
;
902 if (length(res
) = 0) then exit
; // map wad
903 //res := extractWadName(res);
904 //if (length(res) = 0) then exit; // map wad
905 uname
:= toLowerCase1251(res
);
906 // do not add duplicates
907 for f
:= 0 to High(gExternalResources
) do
909 if (gExternalResources
[f
].userName
= uname
) then exit
;
911 //writeln('***(000) addResToExternalResList: res=[', res, ']');
913 fi
.userName
:= uname
;
914 if not findFileCI(res
) then exit
;
915 //writeln('***(001) addResToExternalResList: res=[', res, ']');
917 if (not GetDiskFileInfo(res
, fi
)) then
923 //writeln('***(002) addResToExternalResList: res=[', res, ']');
924 fi
.tag
:= 0; // non-zero means "cannot caclucate hash"
926 fi
.hash
:= MD5File(fi
.diskName
);
931 //e_LogWritefln('addext: res=[%s]; uname=[%s]; diskName=[%s]', [res, fi.userName, fi.diskName]);
932 SetLength(gExternalResources
, length(gExternalResources
)+1);
933 gExternalResources
[High(gExternalResources
)] := fi
;
937 procedure compactExtResList ();
943 for src
:= 0 to High(gExternalResources
) do
945 if (gExternalResources
[src
].tag
= 0) then
948 if (dest
<> src
) then gExternalResources
[dest
] := gExternalResources
[src
];
952 if (dest
<> length(gExternalResources
)) then SetLength(gExternalResources
, dest
);
956 function GetReplacementWad (WadName
: AnsiString): AnsiString;
959 if WadName
<> '' then
962 if g_Game_IsClient
then result
:= g_Res_FindReplacementWad(WadName
);
963 if (result
= WadName
) then result
:= e_FindWad(WadDirs
, result
)
968 procedure generateExternalResourcesList (map
: TDynRecord
);
970 SetLength(gExternalResources
, 0);
971 addResToExternalResList(GetReplacementWad(g_ExtractWadName(map
.MusicName
)));
972 addResToExternalResList(GetReplacementWad(g_ExtractWadName(map
.SkyName
)));
976 function CreateTexture (RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
979 WADName
, ResName
: String;
983 RecName
:= toLowerCase1251(RecName
);
984 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
985 if TextNameHash
.get(RecName
, result
) then
988 //e_LogWritefln('texture ''%s'' already loaded (%s)', [RecName, result]);
994 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then
995 exit
; // don't do it again and again
998 TEXTURE_NAME_WATER
, TEXTURE_NAME_ACID1
, TEXTURE_NAME_ACID2
:
1000 SetLength(Textures
, Length(Textures
) + 1);
1001 Textures
[High(Textures
)].FullName
:= RecName
;
1002 Textures
[High(Textures
)].TextureName
:= RecName
;
1003 Textures
[High(Textures
)].Anim
:= False;
1004 Result
:= High(Textures
);
1005 TextNameHash
.put(RecName
, result
);
1008 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
1009 if (WADName
<> '') then
1010 addResToExternalResList(WADName
);
1011 if WADName
= '' then
1013 ResName
:= g_ExtractFilePathName(RecName
);
1015 // !!! we have a better way to check that resource exists?
1016 WAD
:= TWADFile
.Create();
1017 if WAD
.ReadFile(WadName
) and WAD
.GetResource(ResName
, ResData
, ResLen
, log
) then
1020 SetLength(Textures
, Length(Textures
) + 1);
1021 Textures
[High(Textures
)].FullName
:= WADName
+ ':' + ResName
;
1022 Textures
[High(Textures
)].TextureName
:= RecName
;
1023 Textures
[High(Textures
)].Anim
:= False;
1024 Result
:= High(Textures
);
1025 TextNameHash
.put(RecName
, result
);
1032 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1035 TextureWAD
: PChar = nil;
1036 TextData
: Pointer = nil;
1042 RecName
:= toLowerCase1251(RecName
);
1043 if (TextNameHash
= nil) then TextNameHash
:= THashStrInt
.Create();
1044 if TextNameHash
.get(RecName
, result
) then
1047 //e_LogWritefln('animated texture ''%s'' already loaded (%s)', [RecName, result]);
1053 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1055 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1056 if BadTextNameHash
.get(RecName
, f
) then
1058 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1062 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1063 WADName
:= GetReplacementWad(g_ExtractWadName(RecName
));
1064 if (WADName
<> '') then addResToExternalResList(WADName
);
1065 if WADName
= '' then WADName
:= Map
; //WADName := GameDir+'/wads/'+WADName else
1067 WAD
:= TWADFile
.Create();
1069 WAD
.ReadFile(WADName
);
1070 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1072 if (BadTextNameHash
= nil) then BadTextNameHash
:= THashStrInt
.Create();
1073 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1075 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1076 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1078 BadTextNameHash
.put(RecName
, -1);
1083 // íåò, ýòî ñóïåðìåí!
1084 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1086 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1087 BadTextNameHash
.put(RecName
, -1);
1091 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1092 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1094 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1095 BadTextNameHash
.put(RecName
, -1);
1102 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1105 SetLength(Textures
, Length(Textures
) + 1);
1106 Textures
[High(Textures
)].TextureName
:= RecName
;
1107 Textures
[High(Textures
)].FullName
:= WadName
+ ':' + g_ExtractFilePathName(RecName
);
1108 Textures
[High(Textures
)].Anim
:= True;
1109 Textures
[High(Textures
)].FramesCount
:= cfg
.ReadInt('', 'framecount', 0);
1110 Textures
[High(Textures
)].Speed
:= cfg
.ReadInt('', 'waitcount', 0);
1111 result
:= High(Textures
);
1112 TextNameHash
.put(RecName
, result
);
1119 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1120 if (TextData
<> nil) then FreeMem(TextData
);
1124 procedure CreateItem(Item
: TDynRecord
);
1126 if g_Game_IsClient
then Exit
;
1128 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1129 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1132 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1133 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1136 procedure CreateArea(Area
: TDynRecord
);
1141 case Area
.AreaType
of
1142 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1143 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1145 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1146 with RespawnPoints
[High(RespawnPoints
)] do
1150 Direction
:= TDirection(Area
.Direction
);
1152 case Area
.AreaType
of
1153 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1154 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1155 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1156 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1157 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1162 AREA_REDFLAG
, AREA_BLUEFLAG
:
1164 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1166 if FlagPoints
[a
] <> nil then Exit
;
1170 with FlagPoints
[a
]^ do
1172 X
:= Area
.X
-FLAGRECT
.X
;
1173 Y
:= Area
.Y
-FLAGRECT
.Y
;
1174 Direction
:= TDirection(Area
.Direction
);
1180 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1181 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1184 Animation
:= TAnimation
.Create(id
, True, 8);
1185 Obj
.Rect
:= FLAGRECT
;
1193 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1194 with DOMFlagPoints[High(DOMFlagPoints)] do
1198 Direction := TDirection(Area.Direction);
1201 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1206 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1212 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1216 mapId
:= Trigger
.id
;
1217 mapIndex
:= amapIdx
;
1220 Width
:= Trigger
.Width
;
1221 Height
:= Trigger
.Height
;
1222 Enabled
:= Trigger
.Enabled
;
1223 TexturePanelGUID
:= atpanid
;
1224 TriggerType
:= Trigger
.TriggerType
;
1225 ActivateType
:= Trigger
.ActivateType
;
1226 Keys
:= Trigger
.Keys
;
1227 trigPanelGUID
:= atrigpanid
;
1228 // HACK: used in TPanel.CanChangeTexture. maybe there's a better way?
1229 if TexturePanelGUID
<> -1 then
1231 tp
:= g_Map_PanelByGUID(TexturePanelGUID
);
1232 if (tp
<> nil) then tp
.hasTexTrigger
:= True;
1236 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1239 procedure CreateMonster(monster
: TDynRecord
);
1244 if g_Game_IsClient
then Exit
;
1246 if (gGameSettings
.GameType
= GT_SINGLE
)
1247 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1249 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1251 if gTriggers
<> nil then
1253 for a
:= 0 to High(gTriggers
) do
1255 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1257 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1258 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1263 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1267 procedure g_Map_ReAdd_DieTriggers();
1269 function monsDieTrig (mon
: TMonster
): Boolean;
1272 //tw: TStrTextWriter;
1274 result
:= false; // don't stop
1275 mon
.ClearTriggers();
1276 for a
:= 0 to High(gTriggers
) do
1278 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1280 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1282 tw := TStrTextWriter.Create();
1284 gTriggers[a].trigData.writeTo(tw);
1285 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1290 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1296 if g_Game_IsClient
then Exit
;
1298 g_Mons_ForEach(monsDieTrig
);
1301 procedure mapCreateGrid ();
1303 mapX0
: Integer = $3fffffff;
1304 mapY0
: Integer = $3fffffff;
1305 mapX1
: Integer = -$3fffffff;
1306 mapY1
: Integer = -$3fffffff;
1308 procedure calcBoundingBox (constref panels
: TPanelArray
);
1313 for idx
:= 0 to High(panels
) do
1316 if not pan
.visvalid
then continue
;
1317 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1318 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1319 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1320 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1321 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1325 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1331 //tag := panelTypeToTag(tag);
1332 for idx
:= 0 to High(panels
) do
1335 if not pan
.visvalid
then continue
;
1336 if (pan
.proxyId
<> -1) then
1338 {$IF DEFINED(D2F_DEBUG)}
1339 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
);
1343 case pan
.PanelType
of
1344 PANEL_WALL
: newtag
:= GridTagWall
;
1345 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1346 PANEL_BACK
: newtag
:= GridTagBack
;
1347 PANEL_FORE
: newtag
:= GridTagFore
;
1348 PANEL_WATER
: newtag
:= GridTagWater
;
1349 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1350 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1351 PANEL_STEP
: newtag
:= GridTagStep
;
1352 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1353 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1354 else continue
; // oops
1358 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1359 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1360 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1361 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1363 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1365 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1376 calcBoundingBox(gWalls
);
1377 calcBoundingBox(gRenderBackgrounds
);
1378 calcBoundingBox(gRenderForegrounds
);
1379 calcBoundingBox(gWater
);
1380 calcBoundingBox(gAcid1
);
1381 calcBoundingBox(gAcid2
);
1382 calcBoundingBox(gSteps
);
1383 calcBoundingBox(gLifts
);
1384 calcBoundingBox(gBlockMon
);
1386 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1388 if (mapX0
> 0) then mapX0
:= 0;
1389 if (mapY0
> 0) then mapY0
:= 0;
1391 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1392 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1394 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1395 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1397 addPanelsToGrid(gWalls
);
1398 addPanelsToGrid(gRenderBackgrounds
);
1399 addPanelsToGrid(gRenderForegrounds
);
1400 addPanelsToGrid(gWater
);
1401 addPanelsToGrid(gAcid1
);
1402 addPanelsToGrid(gAcid2
);
1403 addPanelsToGrid(gSteps
);
1404 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1405 addPanelsToGrid(gBlockMon
);
1407 mapGrid
.dumpStats();
1409 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1413 function g_Map_Load(Res
: String): Boolean;
1415 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1416 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1420 //TexturePanel: Integer;
1423 trigrec
: TDynRecord
;
1425 texPanelIdx
: Integer;
1426 texPanel
: TDynRecord
;
1428 actPanelIdx
: Integer;
1429 actPanel
: TDynRecord
;
1432 WAD
, TestWAD
: TWADFile
;
1433 //mapReader: TDynRecord = nil;
1434 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1435 panels
: TDynField
= nil; //TPanelsRec1Array;
1436 items
: TDynField
= nil; //TItemsRec1Array;
1437 monsters
: TDynField
= nil; //TMonsterRec1Array;
1438 areas
: TDynField
= nil; //TAreasRec1Array;
1439 triggers
: TDynField
= nil; //TTriggersRec1Array;
1442 AddTextures
: TAddTextureArray
;
1443 TriggersTable
: array of TTRec
;
1444 FileName
, mapResName
, TexName
, s
: AnsiString;
1447 ok
, isAnim
: Boolean;
1448 CurTex
, ntn
: Integer;
1449 rec
, texrec
: TDynRecord
;
1451 pannum
, trignum
, cnt
, tgpid
: Integer;
1453 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1454 //moveActive: Boolean;
1456 mapOk
: Boolean = false;
1457 usedTextures
: THashStrInt
= nil; // key: mapTextureList
1464 //gCurrentMap.Free();
1465 //gCurrentMap := nil;
1470 gMapInfo
.Map
:= Res
;
1471 TriggersTable
:= nil;
1474 sfsGCDisable(); // temporary disable removing of temporary volumes
1476 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1477 if (gCurrentMap
= nil) then
1479 FileName
:= g_ExtractWadName(Res
);
1480 e_LogWritefln('Loading map WAD [%s] (res=[%s])', [FileName
, Res
], TMsgType
.Notify
);
1481 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1483 WAD
:= TWADFile
.Create();
1484 if not WAD
.ReadFile(FileName
) then
1486 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1491 if gTestMap
<> '' then
1493 s
:= g_ExtractWadName(gTestMap
);
1494 TestWAD
:= TWADFile
.Create();
1495 if not TestWAD
.ReadFile(s
) then
1497 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [s
]));
1503 if TestWAD
<> nil then
1505 mapResName
:= g_ExtractFileName(gTestMap
);
1506 if not TestWAD
.GetMapResource(mapResName
, Data
, Len
) then
1508 g_SimpleError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1511 e_WriteLog('Using test map: '+gTestMap
, TMsgType
.Notify
);
1518 //k8: why loader ignores path here?
1519 mapResName
:= g_ExtractFileName(Res
);
1520 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1522 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1532 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1538 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1539 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1541 stt
:= getTimeMicro();
1544 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1547 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1549 gCurrentMapFileName
:= '';
1555 if (gCurrentMap
= nil) then
1557 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1558 gCurrentMapFileName
:= '';
1564 stt
:= getTimeMicro();
1567 //gCurrentMap := mapReader;
1569 generateExternalResourcesList(gCurrentMap
);
1570 mapTextureList
:= gCurrentMap
['texture'];
1571 // get all other lists here too
1572 panels
:= gCurrentMap
['panel'];
1573 triggers
:= gCurrentMap
['trigger'];
1574 items
:= gCurrentMap
['item'];
1575 areas
:= gCurrentMap
['area'];
1576 monsters
:= gCurrentMap
['monster'];
1578 // Çàãðóçêà îïèñàíèÿ êàðòû:
1579 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1580 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1584 Name
:= gCurrentMap
.MapName
;
1585 Description
:= gCurrentMap
.MapDesc
;
1586 Author
:= gCurrentMap
.MapAuthor
;
1587 MusicName
:= gCurrentMap
.MusicName
;
1588 SkyName
:= gCurrentMap
.SkyName
;
1589 Height
:= gCurrentMap
.Height
;
1590 Width
:= gCurrentMap
.Width
;
1593 // Çàãðóçêà òåêñòóð:
1594 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1595 // Äîáàâëåíèå òåêñòóð â Textures[]:
1596 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1598 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1599 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1601 // find used textures
1602 usedTextures
:= THashStrInt
.Create();
1604 if (panels
<> nil) and (panels
.count
> 0) then
1606 for rec
in panels
do
1608 texrec
:= rec
.TextureRec
;
1609 if (texrec
<> nil) then usedTextures
.put(toLowerCase1251(texrec
.Resource
), 42);
1614 for rec
in mapTextureList
do
1617 if not usedTextures
.has(toLowerCase1251(rec
.Resource
)) then
1619 rec
.tagInt
:= -1; // just in case
1620 e_LogWritefln(' Unused texture #%d: %s', [cnt
, rec
.Resource
]);
1624 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1625 e_LogWritefln(' Loading texture #%d: %s', [cnt
, rec
.Resource
]);
1627 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1630 // Àíèìèðîâàííàÿ òåêñòóðà
1631 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1632 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [rec
.Resource
]));
1637 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1638 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [rec
.Resource
]));
1640 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1642 rec
.tagInt
:= ntn
; // remember texture number
1644 g_Game_StepLoading();
1647 usedTextures
.Free();
1650 // set panel tagInt to texture index
1651 if (panels
<> nil) then
1653 for rec
in panels
do
1655 texrec
:= rec
.TextureRec
;
1656 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1662 // Çàãðóçêà òðèããåðîâ
1663 gTriggerClientID
:= 0;
1664 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1665 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1668 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1669 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1671 // check texture numbers for panels
1672 if (panels
<> nil) and (panels
.count
> 0) then
1674 for rec
in panels
do
1676 if (rec
.tagInt
< 0) then
1678 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1682 gCurrentMapFileName
:= '';
1688 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1689 if (triggers
<> nil) and (triggers
.count
> 0) then
1691 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1692 //SetLength(TriggersTable, triggers.count);
1693 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1695 SetLength(TriggersTable
, triggers
.count
);
1697 for rec
in triggers
do
1700 pttit
:= @TriggersTable
[trignum
];
1701 pttit
.trigrec
:= rec
;
1702 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1703 pttit
.texPanelIdx
:= -1; // will be fixed later
1704 pttit
.texPanel
:= rec
.TexturePanelRec
;
1706 pttit
.actPanelIdx
:= -1;
1707 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1709 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1710 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1712 g_Game_StepLoading();
1717 if (panels
<> nil) and (panels
.count
> 0) then
1719 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1720 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1723 for rec
in panels
do
1726 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1728 SetLength(AddTextures
, 0);
1732 if (mapTextureList
<> nil) then
1734 texrec
:= rec
.TextureRec
;
1735 ok
:= (texrec
<> nil);
1740 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1741 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1743 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1745 if rec
.userPanelTrigRef
then
1747 // e_LogWritefln('trigref for panel %s', [pannum]);
1755 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1756 s
:= texrec
.Resource
;
1758 // Ñïåö-òåêñòóðû çàïðåùåíû
1759 if g_Map_IsSpecialTexture(s
) then
1765 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1766 ok
:= g_Texture_NumNameFindStart(s
);
1769 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1770 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1773 k
:= NNF_NAME_BEFORE
;
1774 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1775 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1777 k
:= g_Texture_NumNameFindNext(TexName
);
1779 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1781 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1784 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1786 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1787 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1788 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1791 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1793 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1794 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1795 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1800 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1802 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1803 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1804 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1807 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1809 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1810 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1811 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1815 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1819 for c := 0 to High(Textures) do
1821 if (Textures[c].TextureName = TexName) then
1823 SetLength(AddTextures, Length(AddTextures)+1);
1824 AddTextures[High(AddTextures)].Texture := c;
1825 AddTextures[High(AddTextures)].Anim := isAnim;
1830 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1832 SetLength(AddTextures
, Length(AddTextures
)+1);
1833 AddTextures
[High(AddTextures
)].Texture
:= c
;
1834 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1840 if k
= NNF_NAME_EQUALS
then
1842 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1843 SetLength(AddTextures
, Length(AddTextures
)+1);
1844 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1845 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1846 CurTex
:= High(AddTextures
);
1857 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1858 end; // if ok - ññûëàþòñÿ òðèããåðû
1862 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1863 SetLength(AddTextures
, 1);
1864 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1865 AddTextures
[0].Anim
:= false;
1866 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1870 //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);
1872 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1874 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
1875 //e_LogWritefln('new panel; tcount=%s; curtex=%s', [Length(AddTextures), CurTex]);
1876 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
1877 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
1878 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
1881 moveSpeed
:= rec
.moveSpeed
;
1882 //moveStart := rec.moveStart;
1883 //moveEnd := rec.moveEnd;
1884 //moveActive := rec['move_active'].value;
1885 if not moveSpeed
.isZero
then
1887 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
1888 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
1889 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
1892 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
1894 g_Game_StepLoading();
1898 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
1899 for b
:= 0 to High(TriggersTable
) do
1901 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
1902 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
1905 // create map grid, init other grids (for monsters, for example)
1906 e_WriteLog('Creating map grid', TMsgType
.Notify
);
1909 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
1910 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
1912 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
1913 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1914 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
1916 for rec
in triggers
do
1919 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
1920 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
1921 TriggersTable
[trignum
].tnum
:= trignum
;
1922 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
1926 //FIXME: use hashtable!
1927 for pan
in panByGUID
do
1929 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
1931 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
1933 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
1935 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
1939 // Çàãðóçêà ïðåäìåòîâ
1940 e_WriteLog(' Loading items...', TMsgType
.Notify
);
1941 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1943 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
1944 if (items
<> nil) and not gLoadGameMode
then
1946 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
1947 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1948 for rec
in items
do CreateItem(rec
);
1951 // Çàãðóçêà îáëàñòåé
1952 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
1953 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1955 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
1956 if areas
<> nil then
1958 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
1959 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1960 for rec
in areas
do CreateArea(rec
);
1963 // Çàãðóçêà ìîíñòðîâ
1964 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
1965 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1967 gTotalMonsters
:= 0;
1969 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
1970 if (monsters
<> nil) and not gLoadGameMode
then
1972 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
1973 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1974 for rec
in monsters
do CreateMonster(rec
);
1977 //gCurrentMap := mapReader; // this will be our current map now
1978 gCurrentMapFileName
:= Res
;
1982 if (gMapInfo
.SkyName
<> '') then
1984 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
1985 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1986 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.SkyName
, g_ExtractWadName(Res
));
1987 if g_Texture_CreateWAD(BackID
, s
, gTextureFilter
) then
1988 g_Game_SetupScreenSize
1990 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]))
1995 if gMapInfo
.MusicName
<> '' then
1997 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
1998 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2000 s
:= e_GetResourcePath(WadDirs
, gMapInfo
.MusicName
, g_ExtractWadName(Res
));
2001 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2004 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2007 // Îñòàëüíûå óñòàíâêè
2015 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2016 if not gLoadGameMode
then g_GFX_Init();
2018 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2019 mapTextureList
:= nil;
2024 TriggersTable
:= nil;
2027 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2028 if ok
and (not gLoadGameMode
) then
2030 gMusic
.SetByName(gMapInfo
.MusicName
);
2035 gMusic
.SetByName('');
2038 stt
:= getTimeMicro()-stt
;
2039 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2042 sfsGCEnable(); // enable releasing unused volumes
2044 e_UnpressAllKeys
; // why not?
2049 gCurrentMapFileName
:= '';
2053 compactExtResList();
2054 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2059 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2062 mapReader
: TDynRecord
;
2063 //Header: TMapHeaderRec_1;
2068 FillChar(Result
, SizeOf(Result
), 0);
2069 FileName
:= g_ExtractWadName(Res
);
2071 WAD
:= TWADFile
.Create();
2072 if not WAD
.ReadFile(FileName
) then
2078 //k8: it ignores path again
2079 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2088 mapReader
:= g_Map_ParseMap(Data
, Len
);
2097 if (mapReader
= nil) then exit
;
2099 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2101 Result
.Name
:= mapReader
.MapName
;
2102 Result
.Description
:= mapReader
.MapDesc
;
2104 Result
.Author
:= mapReader
.MapAuthor
;
2105 Result
.Height
:= mapReader
.Height
;
2106 Result
.Width
:= mapReader
.Width
;
2110 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2111 //ZeroMemory(@Header, SizeOf(Header));
2112 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2113 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2115 Result
.Author
:= '';
2123 function g_Map_GetMapsList(WADName
: string): SSArray
;
2130 WAD
:= TWADFile
.Create();
2131 if not WAD
.ReadFile(WADName
) then
2136 ResList
:= WAD
.GetMapResources();
2137 if ResList
<> nil then
2139 for a
:= 0 to High(ResList
) do
2141 SetLength(Result
, Length(Result
)+1);
2142 Result
[High(Result
)] := ResList
[a
];
2148 function g_Map_Exist(Res
: string): Boolean;
2151 FileName
, mnn
: string;
2157 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2159 WAD
:= TWADFile
.Create
;
2160 if not WAD
.ReadFile(FileName
) then
2166 ResList
:= WAD
.GetMapResources();
2169 mnn
:= g_ExtractFileName(Res
);
2170 if ResList
<> nil then
2171 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2178 procedure g_Map_Free(freeTextures
: Boolean=true);
2180 procedure FreePanelArray(var panels
: TPanelArray
);
2185 if panels
<> nil then
2187 for i
:= 0 to High(panels
) do
2200 RespawnPoints
:= nil;
2201 if FlagPoints
[FLAG_RED
] <> nil then
2203 Dispose(FlagPoints
[FLAG_RED
]);
2204 FlagPoints
[FLAG_RED
] := nil;
2206 if FlagPoints
[FLAG_BLUE
] <> nil then
2208 Dispose(FlagPoints
[FLAG_BLUE
]);
2209 FlagPoints
[FLAG_BLUE
] := nil;
2211 //DOMFlagPoints := nil;
2215 if (Length(gCurrentMapFileName
) <> 0) then
2217 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2221 e_LogWritefln('g_Map_Free: no previous map.', []);
2224 if freeTextures
then
2226 e_LogWritefln('g_Map_Free: clearing textures...', []);
2228 TextNameHash
.Free();
2229 TextNameHash
:= nil;
2230 BadTextNameHash
.Free();
2231 BadTextNameHash
:= nil;
2232 gCurrentMapFileName
:= '';
2239 FreePanelArray(gWalls
);
2240 FreePanelArray(gRenderBackgrounds
);
2241 FreePanelArray(gRenderForegrounds
);
2242 FreePanelArray(gWater
);
2243 FreePanelArray(gAcid1
);
2244 FreePanelArray(gAcid2
);
2245 FreePanelArray(gSteps
);
2246 FreePanelArray(gLifts
);
2247 FreePanelArray(gBlockMon
);
2248 gMovingWallIds
:= nil;
2250 if BackID
<> DWORD(-1) then
2254 e_DeleteTexture(BackID
);
2255 BackID
:= DWORD(-1);
2258 g_Game_StopAllSounds(False);
2260 g_Sound_Delete(gMapInfo
.MusicName
);
2262 gMapInfo
.Name
:= '';
2263 gMapInfo
.Description
:= '';
2264 gMapInfo
.MusicName
:= '';
2265 gMapInfo
.Height
:= 0;
2266 gMapInfo
.Width
:= 0;
2272 procedure g_Map_Update();
2279 procedure UpdatePanelArray(var panels
: TPanelArray
);
2284 for i
:= 0 to High(panels
) do panels
[i
].Update();
2288 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2290 UpdatePanelArray(gWalls
);
2291 UpdatePanelArray(gRenderBackgrounds
);
2292 UpdatePanelArray(gRenderForegrounds
);
2293 UpdatePanelArray(gWater
);
2294 UpdatePanelArray(gAcid1
);
2295 UpdatePanelArray(gAcid2
);
2296 UpdatePanelArray(gSteps
);
2298 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2300 if gGameSettings
.GameMode
= GM_CTF
then
2302 for a
:= FLAG_RED
to FLAG_BLUE
do
2304 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2308 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2313 m
:= g_Obj_Move(@Obj
, True, True);
2315 NeedSend
:= NeedSend
or (Obj
.X
<> Obj
.oldX
) or (Obj
.Y
<> Obj
.oldY
);
2317 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2319 // Ñîïðîòèâëåíèå âîçäóõà
2320 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2322 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2323 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2326 gFlags
[a
].CaptureTime
:= 0;
2327 if a
= FLAG_RED
then
2328 s
:= _lc
[I_PLAYER_FLAG_RED
]
2330 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2331 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2333 if (((gPlayer1
<> nil) and (((gPlayer1
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer1
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))
2334 or ((gPlayer2
<> nil) and (((gPlayer2
.Team
= TEAM_RED
) and (a
= FLAG_RED
)) or ((gPlayer2
.Team
= TEAM_BLUE
) and (a
= FLAG_BLUE
))))) then
2339 if not sound_ret_flag
[b
].IsPlaying() then
2340 sound_ret_flag
[b
].Play();
2342 if g_Game_IsNet
then
2343 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2347 if Count
> 0 then Count
-= 1;
2350 if gPlayers
<> nil then
2352 j
:= Random(Length(gPlayers
)) - 1;
2353 for d
:= 0 to High(gPlayers
) do
2356 if j
> High(gPlayers
) then j
:= 0;
2357 if gPlayers
[j
] <> nil then
2359 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2361 if gPlayers
[j
].GetFlag(a
) then Break
;
2372 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2373 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2379 if WordBool(PanelType
and PANEL_WALL
) then
2380 if gWalls
<> nil then
2385 if gWalls
[a
].Enabled
and
2386 g_Collide(X
, Y
, Width
, Height
,
2387 gWalls
[a
].X
, gWalls
[a
].Y
,
2388 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2395 if WordBool(PanelType
and PANEL_WATER
) then
2396 if gWater
<> nil then
2401 if g_Collide(X
, Y
, Width
, Height
,
2402 gWater
[a
].X
, gWater
[a
].Y
,
2403 gWater
[a
].Width
, gWater
[a
].Height
) then
2410 if WordBool(PanelType
and PANEL_ACID1
) then
2411 if gAcid1
<> nil then
2416 if g_Collide(X
, Y
, Width
, Height
,
2417 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2418 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2425 if WordBool(PanelType
and PANEL_ACID2
) then
2426 if gAcid2
<> nil then
2431 if g_Collide(X
, Y
, Width
, Height
,
2432 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2433 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2440 if WordBool(PanelType
and PANEL_STEP
) then
2441 if gSteps
<> nil then
2446 if g_Collide(X
, Y
, Width
, Height
,
2447 gSteps
[a
].X
, gSteps
[a
].Y
,
2448 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2455 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2456 if gLifts
<> nil then
2461 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= LIFTTYPE_UP
)) or
2462 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= LIFTTYPE_DOWN
)) or
2463 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_LEFT
)) or
2464 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= LIFTTYPE_RIGHT
))) and
2465 g_Collide(X
, Y
, Width
, Height
,
2466 gLifts
[a
].X
, gLifts
[a
].Y
,
2467 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2474 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2475 if gBlockMon
<> nil then
2477 h
:= High(gBlockMon
);
2481 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2482 g_Collide(X
, Y
, Width
, Height
,
2483 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2484 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2492 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2496 function checkPanels (constref panels
: TPanelArray
): Boolean;
2501 if panels
= nil then exit
;
2502 for a
:= 0 to High(panels
) do
2504 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2507 texid
:= panels
[a
].GetTextureID();
2514 texid
:= LongWord(TEXTURE_NONE
);
2516 if not checkPanels(gWater
) then
2517 if not checkPanels(gAcid1
) then
2518 if not checkPanels(gAcid2
) then exit
;
2523 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2525 SlowMask
= GridTagLift
or GridTagBlockMon
;
2527 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2530 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2532 result := pan.Enabled;
2537 if ((tag
and GridTagLift
) <> 0) then
2540 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2541 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2542 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2543 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2544 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2548 if ((tag
and GridTagBlockMon
) <> 0) then
2550 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2555 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2556 result
:= true; // i found her!
2560 tagmask
: Integer = 0;
2562 it
: TPanelGrid
.Iter
;
2566 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2567 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2568 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2569 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2570 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2571 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2572 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2574 if (tagmask
= 0) then exit
; // just in case
2576 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2577 if gdbg_map_use_accel_coldet
then
2579 if ((tagmask
and SlowMask
) <> 0) then
2582 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
);
2586 if ((pan
.tag
and GridTagLift
) <> 0) then
2589 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= LIFTTYPE_UP
)) or
2590 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= LIFTTYPE_DOWN
)) or
2591 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= LIFTTYPE_LEFT
)) or
2592 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= LIFTTYPE_RIGHT
))) {and
2593 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2595 else if ((pan
.tag
and GridTagBlockMon
) <> 0) then
2597 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2602 result
:= true; // i found her!
2604 if (result
) then break
;
2610 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, tagmask
, false, true); // return first hit
2611 result
:= (it
.length
> 0);
2617 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2619 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2623 // returns `true` if we need to stop
2624 function liquidChecker (pan
: TPanel
; var texid
: DWORD
; var cctype
: Integer): Boolean; inline;
2627 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2630 0: if ((pan
.tag
and GridTagWater
) = 0) then exit
; // allowed: water
2631 1: if ((pan
.tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2632 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2635 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2637 texid
:= pan
.GetTextureID();
2638 // water? water has the highest priority, so stop right here
2639 if ((pan
.tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2641 if ((pan
.tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2643 if ((pan
.tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2646 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2648 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2650 it
: TPanelGrid
.Iter
;
2652 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2653 if gdbg_map_use_accel_coldet
then
2655 result
:= LongWord(TEXTURE_NONE
);
2656 it
:= mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2657 for mwit
in it
do if (liquidChecker(mwit
^, result
, cctype
)) then break
;
2662 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2664 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2668 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2669 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2670 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2673 procedure g_Map_EnableWallGUID (pguid
: Integer);
2677 //pan := gWalls[ID];
2678 pan
:= g_Map_PanelByGUID(pguid
);
2679 if (pan
= nil) then exit
;
2680 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
2682 pan
.Enabled
:= True;
2683 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2685 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2686 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2687 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2689 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2690 // mark platform as interesting
2693 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2694 //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);
2699 procedure g_Map_DisableWallGUID (pguid
: Integer);
2703 //pan := gWalls[ID];
2704 pan
:= g_Map_PanelByGUID(pguid
);
2705 if (pan
= nil) then exit
;
2706 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
2708 pan
.Enabled
:= False;
2709 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2711 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2712 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2714 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2715 // mark platform as interesting
2718 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2719 //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);
2724 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
2728 tp
:= g_Map_PanelByGUID(pguid
);
2729 if (tp
= nil) then exit
;
2730 tp
.NextTexture(AnimLoop
);
2731 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
2735 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2739 //pan := gLifts[ID];
2740 pan
:= g_Map_PanelByGUID(pguid
);
2741 if (pan
= nil) then exit
;
2742 if not pan
.isGLift
then exit
;
2744 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2746 with {gLifts[ID]} pan
do
2750 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2751 //TODO: make separate lift tags, and change tag here
2754 LIFTTYPE_UP
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2755 LIFTTYPE_DOWN
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2756 LIFTTYPE_LEFT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2757 LIFTTYPE_RIGHT
: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
2760 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2761 // mark platform as interesting
2767 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2770 PointsArray
: Array of TRespawnPoint
;
2773 SetLength(PointsArray
, 0);
2775 if RespawnPoints
= nil then
2778 for a
:= 0 to High(RespawnPoints
) do
2779 if RespawnPoints
[a
].PointType
= PointType
then
2781 SetLength(PointsArray
, Length(PointsArray
)+1);
2782 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2785 if PointsArray
= nil then
2788 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2792 function g_Map_GetPointCount(PointType
: Byte): Word;
2798 if RespawnPoints
= nil then
2801 for a
:= 0 to High(RespawnPoints
) do
2802 if RespawnPoints
[a
].PointType
= PointType
then
2803 Result
:= Result
+ 1;
2806 function g_Map_GetRandomPointType(): Byte;
2808 if RespawnPoints
= nil then
2811 Result
:= RespawnPoints
[Random(Length(RespawnPoints
))].PointType
;
2814 function g_Map_HaveFlagPoints(): Boolean;
2816 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2819 procedure g_Map_ResetFlag(Flag
: Byte);
2821 with gFlags
[Flag
] do
2827 Direction
:= TDirection
.D_LEFT
;
2828 State
:= FLAG_STATE_NONE
;
2829 if FlagPoints
[Flag
] <> nil then
2831 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2832 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2833 Direction
:= FlagPoints
[Flag
]^.Direction
;
2834 State
:= FLAG_STATE_NORMAL
;
2838 NeedSend
:= False; // the event will take care of this
2843 procedure g_Map_SaveState (st
: TStream
);
2847 procedure savePanels ();
2852 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
2853 for pan
in panByGUID
do pan
.SaveState(st
);
2856 procedure saveFlag (flag
: PFlag
);
2860 utils
.writeSign(st
, 'FLAG');
2861 utils
.writeInt(st
, Byte(0)); // version
2862 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
2863 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
2865 utils
.writeInt(st
, Byte(flag
^.State
));
2866 // Íàïðàâëåíèå ôëàãà
2867 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
2868 utils
.writeInt(st
, Byte(b
));
2870 Obj_SaveState(st
, @flag
^.Obj
);
2877 utils
.writeSign(st
, 'MUSI');
2878 utils
.writeInt(st
, Byte(0));
2880 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2881 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
2882 utils
.writeStr(st
, str
);
2883 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
2884 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
2885 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
2886 utils
.writeBool(st
, gMusic
.SpecPause
);
2888 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2889 utils
.writeInt(st
, LongInt(gTotalMonsters
));
2892 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2893 if (gGameSettings
.GameMode
= GM_CTF
) then
2895 // Ôëàã Êðàñíîé êîìàíäû
2896 saveFlag(@gFlags
[FLAG_RED
]);
2897 // Ôëàã Ñèíåé êîìàíäû
2898 saveFlag(@gFlags
[FLAG_BLUE
]);
2902 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2903 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2905 // Î÷êè Êðàñíîé êîìàíäû
2906 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Score
));
2907 // Î÷êè Ñèíåé êîìàíäû
2908 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Score
));
2914 procedure g_Map_LoadState (st
: TStream
);
2920 procedure loadPanels ();
2925 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
2926 for pan
in panByGUID
do
2929 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
2933 procedure loadFlag (flag
: PFlag
);
2938 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
2939 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
2940 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
2941 flag
^.RespawnType
:= utils
.readByte(st
);
2943 flag
^.State
:= utils
.readByte(st
);
2944 // Íàïðàâëåíèå ôëàãà
2945 b
:= utils
.readByte(st
);
2946 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
2948 Obj_LoadState(@flag
^.Obj
, st
);
2952 if (st
= nil) then exit
;
2954 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2958 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
2962 ///// Çàãðóæàåì ìóçûêó: /////
2963 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
2964 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
2966 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2967 str
:= utils
.readStr(st
);
2968 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
2969 dw
:= utils
.readLongWord(st
);
2970 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
2971 boo
:= utils
.readBool(st
);
2972 // Çàïóñêàåì ýòó ìóçûêó
2973 gMusic
.SetByName(str
);
2974 gMusic
.SpecPause
:= boo
;
2977 gMusic
.SetPosition(dw
);
2980 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2981 gTotalMonsters
:= utils
.readLongInt(st
);
2984 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2985 if (gGameSettings
.GameMode
= GM_CTF
) then
2987 // Ôëàã Êðàñíîé êîìàíäû
2988 loadFlag(@gFlags
[FLAG_RED
]);
2989 // Ôëàã Ñèíåé êîìàíäû
2990 loadFlag(@gFlags
[FLAG_BLUE
]);
2994 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2995 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2997 // Î÷êè Êðàñíîé êîìàíäû
2998 gTeamStat
[TEAM_RED
].Score
:= utils
.readSmallInt(st
);
2999 // Î÷êè Ñèíåé êîìàíäû
3000 gTeamStat
[TEAM_BLUE
].Score
:= utils
.readSmallInt(st
);
3006 // trace liquid, stepping by `dx` and `dy`
3007 // return last seen liquid coords, and `false` if we're started outside of the liquid
3008 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3010 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3014 // started outside of the liquid?
3015 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then begin result := false; exit; end;
3016 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3017 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3023 //if (mapGrid.forEachAtPoint(x, y, nil, MaskLiquid) = nil) then exit; // out of the water, just exit
3024 if (g_Map_PanelAtPoint(x
, y
, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3032 DynWarningCB
:= mapWarningCB
;