1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {$DEFINE MAP_DEBUG_ENABLED_FLAG}
23 e_graphics
, g_basic
, MAPDEF
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
, binheap
, xprofiler
, xparser
, xdynrec
;
38 PRespawnPoint
= ^TRespawnPoint
;
39 TRespawnPoint
= record
41 Direction
: TDirection
;
45 PFlagPoint
= ^TFlagPoint
;
46 TFlagPoint
= TRespawnPoint
;
54 CaptureTime
: LongWord;
55 Animation
: TAnimation
;
56 Direction
: TDirection
;
59 function g_Map_Load(Res
: String): Boolean;
60 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
61 function g_Map_GetMapsList(WADName
: String): SArray
;
62 function g_Map_Exist(Res
: String): Boolean;
63 procedure g_Map_Free(freeTextures
: Boolean=true);
64 procedure g_Map_Update();
66 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
68 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
69 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
71 procedure g_Map_DrawBack(dx
, dy
: Integer);
72 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
73 PanelType
: Word; b1x3
: Boolean=false): Boolean;
74 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
76 procedure g_Map_EnableWallGUID (pguid
: Integer);
77 procedure g_Map_DisableWallGUID (pguid
: Integer);
78 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
81 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
82 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
83 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
85 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
87 procedure g_Map_ReAdd_DieTriggers();
88 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
90 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
91 function g_Map_GetPointCount(PointType
: Byte): Word;
93 function g_Map_HaveFlagPoints(): Boolean;
95 procedure g_Map_ResetFlag(Flag
: Byte);
96 procedure g_Map_DrawFlags();
98 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
99 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
101 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
103 // returns panel or nil
104 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
105 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
107 // returns panel or nil
108 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
109 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
112 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
114 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
115 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
117 // trace liquid, stepping by `dx` and `dy`
118 // return last seen liquid coords, and `false` if we're started outside of the liquid
119 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
122 procedure g_Map_ProfilersBegin ();
123 procedure g_Map_ProfilersEnd ();
126 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
129 function g_Map_MinX (): Integer; inline;
130 function g_Map_MinY (): Integer; inline;
131 function g_Map_MaxX (): Integer; inline;
132 function g_Map_MaxY (): Integer; inline;
140 function g_Texture_NumNameFindStart(name
: String): Boolean;
141 function g_Texture_NumNameFindNext(var newName
: String): Byte;
144 RESPAWNPOINT_PLAYER1
= 1;
145 RESPAWNPOINT_PLAYER2
= 2;
147 RESPAWNPOINT_RED
= 4;
148 RESPAWNPOINT_BLUE
= 5;
156 FLAG_STATE_NORMAL
= 1;
157 FLAG_STATE_DROPPED
= 2;
158 FLAG_STATE_CAPTURED
= 3;
159 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
160 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
162 FLAG_TIME
= 720; // 20 seconds
164 SKY_STRETCH
: Single = 1.5;
179 // sorted by draw priority
180 GridTagBack
= 1 shl 0; // gRenderBackgrounds
181 GridTagStep
= 1 shl 1; // gSteps
182 GridTagWall
= 1 shl 2; // gWalls
183 GridTagDoor
= 1 shl 3; // gWalls
184 GridTagAcid1
= 1 shl 4; // gAcid1
185 GridTagAcid2
= 1 shl 5; // gAcid2
186 GridTagWater
= 1 shl 6; // gWater
187 GridTagFore
= 1 shl 7; // gRenderForegrounds
188 // the following are invisible
189 GridTagLift
= 1 shl 8; // gLifts
190 GridTagBlockMon
= 1 shl 9; // gBlockMon
192 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
193 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
195 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
200 gRenderBackgrounds
: TPanelArray
;
201 gRenderForegrounds
: TPanelArray
;
202 gWater
, gAcid1
, gAcid2
: TPanelArray
;
205 gBlockMon
: TPanelArray
;
206 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
207 //gDOMFlags: array of TFlag;
210 gDoorMap
: array of array of DWORD
;
211 gLiftMap
: array of array of DWORD
;
212 gWADHash
: TMD5Digest
;
213 BackID
: DWORD
= DWORD(-1);
214 gExternalResources
: TStringList
;
215 gMovingWallIds
: array of Integer = nil;
217 gdbg_map_use_accel_render
: Boolean = true;
218 gdbg_map_use_accel_coldet
: Boolean = true;
219 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
220 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
222 gCurrentMap
: TDynRecord
= nil;
223 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
226 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
230 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
233 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
239 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
240 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
241 g_options
, g_triggers
, g_player
,
242 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
243 utils
, sfs
, xstreams
, hashtable
,
244 ImagingTypes
, Imaging
, ImagingUtility
,
245 ImagingGif
, ImagingNetworkGraphics
;
248 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
249 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
250 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
254 panByGUID
: array of TPanel
= nil;
257 // ////////////////////////////////////////////////////////////////////////// //
258 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
260 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
261 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
265 // ////////////////////////////////////////////////////////////////////////// //
266 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
267 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
268 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
269 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
272 // ////////////////////////////////////////////////////////////////////////// //
274 dfmapdef
: TDynMapDef
= nil;
277 procedure loadMapDefinition ();
279 pr
: TTextParser
= nil;
283 if (dfmapdef
<> nil) then exit
;
286 e_LogWritefln('parsing "mapdef.txt"...', []);
287 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
288 e_LogWritefln('found local "%smapdef.txt"', [DataDir
]);
295 WAD
:= TWADFile
.Create();
296 if not WAD
.ReadFile(GameWAD
) then
298 //raise Exception.Create('cannot load "game.wad"');
303 st
:= WAD
.openFileStream('mapdef.txt');
310 //raise Exception.Create('cannot open "mapdef.txt"');
311 e_LogWriteln('using default "mapdef.txt"...');
312 pr
:= TStrTextParser
.Create(defaultMapDef
);
316 pr
:= TFileTextParser
.Create(st
);
318 except on e
: Exception
do
320 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
326 dfmapdef
:= TDynMapDef
.Create(pr
);
327 except on e
: Exception
do
328 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
336 // ////////////////////////////////////////////////////////////////////////// //
337 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
339 wst
: TSFSMemoryChunkStream
= nil;
340 pr
: TTextParser
= nil;
343 if (dataLen
< 4) then exit
;
345 if (dfmapdef
= nil) then writeln('need to load mapdef');
347 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
349 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
351 if (PAnsiChar(data
)[0] = 'M') and (PAnsiChar(data
)[1] = 'A') and (PAnsiChar(data
)[2] = 'P') and (PByte(data
)[3] = 1) then
355 //e_LogWriteln('parsing binary map...');
356 result
:= dfmapdef
.parseBinMap(wst
);
357 except on e
: Exception
do
359 e_LogWritefln('ERROR: %s', [e
.message]);
370 pr
:= TFileTextParser
.Create(wst
);
372 //e_LogWriteln('parsing text map...');
373 result
:= dfmapdef
.parseMap(pr
);
374 except on e
: Exception
do
376 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message])
377 else e_LogWritefln('ERROR: %s', [e
.message]);
378 pr
.Free(); // will free `wst`
383 pr
.Free(); // will free `wst`
385 //e_LogWriteln('map parsed.');
389 // ////////////////////////////////////////////////////////////////////////// //
391 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
392 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
393 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
396 function g_Texture_NumNameFindStart(name
: String): Boolean;
404 NNF_CurrentNum
:= -1;
406 for i
:= Length(name
) downto 1 do
407 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
409 if i
= Length(name
) then
410 begin // Íåò öèôð â êîíöå ñòðîêè
415 NNF_PureName
:= Copy(name
, 1, i
);
421 // Íå ïåðåâåñòè â ÷èñëî:
422 if not TryStrToInt(name
, NNF_FirstNum
) then
431 function g_Texture_NumNameFindNext(var newName
: String): Byte;
433 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
436 Result
:= NNF_NO_NAME
;
440 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
442 if NNF_CurrentNum
< NNF_FirstNum
then
443 Result
:= NNF_NAME_BEFORE
445 if NNF_CurrentNum
> NNF_FirstNum
then
446 Result
:= NNF_NAME_AFTER
448 Result
:= NNF_NAME_EQUALS
;
454 // ////////////////////////////////////////////////////////////////////////// //
455 function panelTypeToTag (panelType
: Word): Integer;
458 PANEL_WALL
: result
:= GridTagWall
; // gWalls
459 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
460 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
461 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
462 PANEL_WATER
: result
:= GridTagWater
; // gWater
463 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
464 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
465 PANEL_STEP
: result
:= GridTagStep
; // gSteps
466 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
467 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
468 else result
:= GridTagInvalid
;
473 function dplLess (a
, b
: TObject
): Boolean;
479 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
480 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
481 result
:= (pa
.arrIdx
< pb
.arrIdx
);
484 procedure dplClear ();
486 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
491 Textures
: TLevelTextureArray
= nil;
492 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
493 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
494 RespawnPoints
: array of TRespawnPoint
;
495 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
496 //DOMFlagPoints: Array of TFlagPoint;
499 procedure g_Map_ProfilersBegin ();
501 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
502 profMapCollision
.mainBegin(g_profile_collision
);
504 if g_profile_collision
then
506 profMapCollision
.sectionBegin('*solids');
507 profMapCollision
.sectionEnd();
508 profMapCollision
.sectionBegin('liquids');
509 profMapCollision
.sectionEnd();
513 procedure g_Map_ProfilersEnd ();
515 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
519 // wall index in `gWalls` or -1
520 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
524 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
525 if (result
<> nil) then
527 if (hitx
<> nil) then hitx
^ := ex
;
528 if (hity
<> nil) then hity
^ := ey
;
532 if (hitx
<> nil) then hitx
^ := x1
;
533 if (hity
<> nil) then hity
^ := y1
;
537 // returns panel or nil
538 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
542 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
543 if (result
<> nil) then
545 if (hitx
<> nil) then hitx
^ := ex
;
546 if (hity
<> nil) then hity
^ := ey
;
550 if (hitx
<> nil) then hitx
^ := x1
;
551 if (hity
<> nil) then hity
^ := y1
;
556 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
558 function checker (pan
: TPanel
; tag
: Integer): Boolean;
561 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
563 result := pan.Enabled; // stop if wall is enabled
568 if ((tag
and GridTagLift
) <> 0) then
570 // stop if the lift of the right type
572 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
573 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
574 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
575 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
579 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
583 tagmask
: Integer = 0;
587 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
588 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
589 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
590 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
591 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
592 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
593 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
595 if (tagmask
= 0) then exit
;// just in case
596 if ((tagmask
and GridTagLift
) <> 0) then
599 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
604 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
609 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
612 if (tagmask
= 0) then exit
;
613 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
617 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
619 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
620 (Texture
= TEXTURE_NAME_ACID1
) or
621 (Texture
= TEXTURE_NAME_ACID2
);
624 procedure CreateDoorMap();
626 PanelArray
: Array of record
632 a
, b
, c
, m
, i
, len
: Integer;
640 SetLength(PanelArray
, len
);
642 for a
:= 0 to High(gWalls
) do
643 if gWalls
[a
].Door
then
645 PanelArray
[i
].X
:= gWalls
[a
].X
;
646 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
647 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
648 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
649 PanelArray
[i
].Active
:= True;
650 PanelArray
[i
].PanelID
:= a
;
656 SetLength(PanelArray
, len
);
667 SetLength(gDoorMap
, 0);
669 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
672 if PanelArray
[a
].Active
then
674 PanelArray
[a
].Active
:= False;
675 m
:= Length(gDoorMap
);
676 SetLength(gDoorMap
, m
+1);
677 SetLength(gDoorMap
[m
], 1);
678 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
686 if PanelArray
[b
].Active
then
687 for c
:= 0 to High(gDoorMap
[m
]) do
688 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
689 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
690 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
691 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
692 gWalls
[gDoorMap
[m
, c
]].X
,
693 gWalls
[gDoorMap
[m
, c
]].Y
,
694 gWalls
[gDoorMap
[m
, c
]].Width
,
695 gWalls
[gDoorMap
[m
, c
]].Height
) then
697 PanelArray
[b
].Active
:= False;
698 SetLength(gDoorMap
[m
],
699 Length(gDoorMap
[m
])+1);
700 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
706 g_Game_StepLoading();
712 procedure CreateLiftMap();
714 PanelArray
: Array of record
719 a
, b
, c
, len
, i
, j
: Integer;
725 len
:= Length(gLifts
);
726 SetLength(PanelArray
, len
);
728 for a
:= 0 to len
-1 do
730 PanelArray
[a
].X
:= gLifts
[a
].X
;
731 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
732 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
733 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
734 PanelArray
[a
].Active
:= True;
737 SetLength(gLiftMap
, len
);
740 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
742 for a
:= 0 to len
-1 do
743 if PanelArray
[a
].Active
then
745 PanelArray
[a
].Active
:= False;
746 SetLength(gLiftMap
[i
], 32);
754 for b
:= 0 to len
-1 do
755 if PanelArray
[b
].Active
then
757 if g_CollideAround(PanelArray
[b
].X
,
760 PanelArray
[b
].Height
,
761 PanelArray
[gLiftMap
[i
, c
]].X
,
762 PanelArray
[gLiftMap
[i
, c
]].Y
,
763 PanelArray
[gLiftMap
[i
, c
]].Width
,
764 PanelArray
[gLiftMap
[i
, c
]].Height
) then
766 PanelArray
[b
].Active
:= False;
768 if j
> High(gLiftMap
[i
]) then
769 SetLength(gLiftMap
[i
],
770 Length(gLiftMap
[i
])+32);
779 SetLength(gLiftMap
[i
], j
+1);
782 g_Game_StepLoading();
785 SetLength(gLiftMap
, i
);
790 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer; sav
: Boolean): Integer;
793 panels
: ^TPanelArray
;
799 case PanelRec
.PanelType
of
800 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
801 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
802 PANEL_FORE
: panels
:= @gRenderForegrounds
;
803 PANEL_WATER
: panels
:= @gWater
;
804 PANEL_ACID1
: panels
:= @gAcid1
;
805 PANEL_ACID2
: panels
:= @gAcid2
;
806 PANEL_STEP
: panels
:= @gSteps
;
807 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
808 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
812 len
:= Length(panels
^);
813 SetLength(panels
^, len
+1);
815 pguid
:= Length(panByGUID
);
816 SetLength(panByGUID
, pguid
+1); //FIXME!
817 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
819 assert(pguid
< Length(panByGUID
));
820 panByGUID
[pguid
] := pan
;
824 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
825 if sav
then pan
.SaveIt
:= True;
827 PanelRec
.user
['panel_guid'] := pguid
;
834 function CreateNullTexture(RecName
: String): Integer;
836 RecName
:= toLowerCase1251(RecName
);
837 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
838 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
840 SetLength(Textures
, Length(Textures
)+1);
841 result
:= High(Textures
);
843 with Textures
[High(Textures
)] do
845 TextureName
:= RecName
;
849 TextureID
:= LongWord(TEXTURE_NONE
);
852 TextNameHash
.put(RecName
, result
);
856 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
859 TextureData
: Pointer;
861 a
, ResLength
: Integer;
863 RecName
:= toLowerCase1251(RecName
);
864 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
865 if TextNameHash
.get(RecName
, result
) then
868 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
874 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
877 if Textures <> nil then
879 for a := 0 to High(Textures) do
881 if (Textures[a].TextureName = RecName) then
882 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
883 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
891 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
892 if (RecName
= TEXTURE_NAME_WATER
) or
893 (RecName
= TEXTURE_NAME_ACID1
) or
894 (RecName
= TEXTURE_NAME_ACID2
) then
896 SetLength(Textures
, Length(Textures
)+1);
898 with Textures
[High(Textures
)] do
900 TextureName
:= RecName
;
901 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
902 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
903 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
908 result
:= High(Textures
);
909 TextNameHash
.put(RecName
, result
);
913 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
914 WADName
:= g_ExtractWadName(RecName
);
916 WAD
:= TWADFile
.Create();
918 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
920 WAD
.ReadFile(WADName
);
924 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
926 FreeMem(TextureData);
927 RecName := 'COMMON\ALIEN';
931 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
933 SetLength(Textures
, Length(Textures
)+1);
934 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
936 SetLength(Textures
, Length(Textures
)-1);
939 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
940 FreeMem(TextureData
);
941 Textures
[High(Textures
)].TextureName
:= RecName
;
942 Textures
[High(Textures
)].Anim
:= False;
944 result
:= High(Textures
);
945 TextNameHash
.put(RecName
, result
);
947 else // Íåò òàêîãî ðåóñðñà â WAD'å
949 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
950 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
951 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
953 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
954 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
956 BadTextNameHash
.put(RecName
, -1);
963 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
966 TextureWAD
: PChar = nil;
967 TextData
: Pointer = nil;
968 TextureData
: Pointer = nil;
972 TextureResource
: String;
973 _width
, _height
, _framecount
, _speed
: Integer;
974 _backanimation
: Boolean;
976 ia
: TDynImageDataArray
= nil;
977 f
, c
, frdelay
, frloop
: Integer;
979 RecName
:= toLowerCase1251(RecName
);
980 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
981 if TextNameHash
.get(RecName
, result
) then
984 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
990 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
992 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
993 if BadTextNameHash
.get(RecName
, f
) then
995 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
999 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1000 WADName
:= g_ExtractWadName(RecName
);
1002 WAD
:= TWADFile
.Create();
1004 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
1006 WAD
.ReadFile(WADName
);
1008 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1010 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1011 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1013 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1014 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1016 BadTextNameHash
.put(RecName
, -1);
1021 if WADName = Map then
1023 //FreeMem(TextureWAD);
1024 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1030 if ResLength
< 6 then
1032 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
1033 BadTextNameHash
.put(RecName
, -1);
1037 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1038 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1039 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1041 // íåò, ýòî ñóïåðìåí!
1042 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1044 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1045 BadTextNameHash
.put(RecName
, -1);
1049 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1050 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1052 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1053 BadTextNameHash
.put(RecName
, -1);
1057 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1059 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1060 if TextureResource
= '' then
1062 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1063 BadTextNameHash
.put(RecName
, -1);
1067 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1068 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1069 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1070 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1071 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1076 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1077 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1079 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1080 BadTextNameHash
.put(RecName
, -1);
1087 SetLength(Textures
, Length(Textures
)+1);
1088 with Textures
[High(Textures
)] do
1090 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1091 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1093 TextureName
:= RecName
;
1097 FramesCount
:= _framecount
;
1099 result
:= High(Textures
);
1100 TextNameHash
.put(RecName
, result
);
1104 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1105 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1107 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1109 BadTextNameHash
.put(RecName
, -1);
1115 // try animated image
1117 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1118 if length(imgfmt) = 0 then
1120 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1124 GlobalMetadata
.ClearMetaItems();
1125 GlobalMetadata
.ClearMetaItemsForSaving();
1126 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1128 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1129 BadTextNameHash
.put(RecName
, -1);
1132 if length(ia
) = 0 then
1134 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1135 BadTextNameHash
.put(RecName
, -1);
1142 _width
:= ia
[0].width
;
1143 _height
:= ia
[0].height
;
1144 _framecount
:= length(ia
);
1146 _backanimation
:= false;
1149 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1151 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1153 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1155 if f
< 0 then f
:= 0;
1158 if c
< 13 then c
:= 0 else c
:= 1;
1160 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1165 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1167 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1169 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1171 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1175 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1176 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1177 f
:= ord(_backanimation
);
1178 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
]), MSG_NOTIFY
);
1180 SetLength(Textures
, Length(Textures
)+1);
1181 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1182 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1184 Textures
[High(Textures
)].TextureName
:= RecName
;
1185 Textures
[High(Textures
)].Width
:= _width
;
1186 Textures
[High(Textures
)].Height
:= _height
;
1187 Textures
[High(Textures
)].Anim
:= True;
1188 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1189 Textures
[High(Textures
)].Speed
:= _speed
;
1190 result
:= High(Textures
);
1191 TextNameHash
.put(RecName
, result
);
1192 //writeln(' CREATED!');
1196 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1197 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1199 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1201 BadTextNameHash
.put(RecName
, -1);
1205 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1208 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1209 if (TextData
<> nil) then FreeMem(TextData
);
1210 if (TextureData
<> nil) then FreeMem(TextureData
);
1214 procedure CreateItem(Item
: TDynRecord
);
1216 if g_Game_IsClient
then Exit
;
1218 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1219 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1222 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1223 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1226 procedure CreateArea(Area
: TDynRecord
);
1231 case Area
.AreaType
of
1232 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1233 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1235 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1236 with RespawnPoints
[High(RespawnPoints
)] do
1240 Direction
:= TDirection(Area
.Direction
);
1242 case Area
.AreaType
of
1243 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1244 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1245 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1246 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1247 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1252 AREA_REDFLAG
, AREA_BLUEFLAG
:
1254 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1256 if FlagPoints
[a
] <> nil then Exit
;
1260 with FlagPoints
[a
]^ do
1262 X
:= Area
.X
-FLAGRECT
.X
;
1263 Y
:= Area
.Y
-FLAGRECT
.Y
;
1264 Direction
:= TDirection(Area
.Direction
);
1270 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1271 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1274 Animation
:= TAnimation
.Create(id
, True, 8);
1275 Obj
.Rect
:= FLAGRECT
;
1283 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1284 with DOMFlagPoints[High(DOMFlagPoints)] do
1288 Direction := TDirection(Area.Direction);
1291 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1296 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word): Integer;
1301 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1305 mapId
:= Trigger
.id
;
1306 mapIndex
:= amapIdx
;
1309 Width
:= Trigger
.Width
;
1310 Height
:= Trigger
.Height
;
1311 Enabled
:= Trigger
.Enabled
;
1312 //TexturePanel := Trigger.TexturePanel;
1313 TexturePanelGUID
:= atpanid
;
1314 TexturePanelType
:= fTexturePanel1Type
;
1315 ShotPanelType
:= fTexturePanel2Type
;
1316 TriggerType
:= Trigger
.TriggerType
;
1317 ActivateType
:= Trigger
.ActivateType
;
1318 Keys
:= Trigger
.Keys
;
1319 trigPanelGUID
:= atrigpanid
;
1320 //trigShotPanelId := ashotpanid;
1321 //Data.Default := Trigger.DATA;
1322 if (Trigger
.trigRec
= nil) then
1325 if (TriggerType
<> TRIGGER_SECRET
) then
1327 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1332 trigData
:= Trigger
.trigRec
.clone(nil);
1336 result
:= Integer(g_Triggers_Create(_trigger
));
1339 procedure CreateMonster(monster
: TDynRecord
);
1344 if g_Game_IsClient
then Exit
;
1346 if (gGameSettings
.GameType
= GT_SINGLE
)
1347 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1349 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1351 if gTriggers
<> nil then
1353 for a
:= 0 to High(gTriggers
) do
1355 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1357 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1358 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1363 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1367 procedure g_Map_ReAdd_DieTriggers();
1369 function monsDieTrig (mon
: TMonster
): Boolean;
1372 //tw: TStrTextWriter;
1374 result
:= false; // don't stop
1375 mon
.ClearTriggers();
1376 for a
:= 0 to High(gTriggers
) do
1378 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1380 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1382 tw := TStrTextWriter.Create();
1384 gTriggers[a].trigData.writeTo(tw);
1385 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1390 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1396 if g_Game_IsClient
then Exit
;
1398 g_Mons_ForEach(monsDieTrig
);
1401 function extractWadName(resourceName
: string): string;
1405 posN
:= Pos(':', resourceName
);
1407 Result
:= Copy(resourceName
, 0, posN
-1)
1412 procedure addResToExternalResList(res
: string);
1414 res
:= extractWadName(res
);
1415 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1416 gExternalResources
.Add(res
);
1419 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1421 //textures: TTexturesRec1Array;
1422 //textures: TDynField;
1424 //mapHeader: TMapHeaderRec_1;
1426 //resFile: String = '';
1428 if gExternalResources
= nil then
1429 gExternalResources
:= TStringList
.Create
;
1431 gExternalResources
.Clear
;
1435 textures := GetTextures(map);
1436 for i := 0 to High(textures) do
1438 addResToExternalResList(resFile);
1442 textures := map['texture'];
1443 if (textures <> nil) then
1445 for trec in textures do
1447 addResToExternalResList(resFile);
1454 //mapHeader := GetMapHeader(map);
1456 addResToExternalResList(map
.MusicName
);
1457 addResToExternalResList(map
.SkyName
);
1461 procedure mapCreateGrid ();
1463 mapX0
: Integer = $3fffffff;
1464 mapY0
: Integer = $3fffffff;
1465 mapX1
: Integer = -$3fffffff;
1466 mapY1
: Integer = -$3fffffff;
1468 procedure calcBoundingBox (constref panels
: TPanelArray
);
1473 for idx
:= 0 to High(panels
) do
1476 if not pan
.visvalid
then continue
;
1477 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1478 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1479 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1480 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1481 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1485 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1491 //tag := panelTypeToTag(tag);
1492 for idx
:= 0 to High(panels
) do
1495 if not pan
.visvalid
then continue
;
1496 if (pan
.proxyId
<> -1) then
1498 {$IF DEFINED(D2F_DEBUG)}
1499 e_WriteLog(Format('DUPLICATE wall #%d(%d) enabled (%d); type:%08x', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.PanelType
]), MSG_NOTIFY
);
1503 case pan
.PanelType
of
1504 PANEL_WALL
: newtag
:= GridTagWall
;
1505 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1506 PANEL_BACK
: newtag
:= GridTagBack
;
1507 PANEL_FORE
: newtag
:= GridTagFore
;
1508 PANEL_WATER
: newtag
:= GridTagWater
;
1509 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1510 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1511 PANEL_STEP
: newtag
:= GridTagStep
;
1512 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1513 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1514 else continue
; // oops
1518 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1519 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1520 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1521 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1523 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1525 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1536 calcBoundingBox(gWalls
);
1537 calcBoundingBox(gRenderBackgrounds
);
1538 calcBoundingBox(gRenderForegrounds
);
1539 calcBoundingBox(gWater
);
1540 calcBoundingBox(gAcid1
);
1541 calcBoundingBox(gAcid2
);
1542 calcBoundingBox(gSteps
);
1543 calcBoundingBox(gLifts
);
1544 calcBoundingBox(gBlockMon
);
1546 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1548 if (mapX0
> 0) then mapX0
:= 0;
1549 if (mapY0
> 0) then mapY0
:= 0;
1551 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1552 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1554 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1555 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1557 addPanelsToGrid(gWalls
);
1558 addPanelsToGrid(gRenderBackgrounds
);
1559 addPanelsToGrid(gRenderForegrounds
);
1560 addPanelsToGrid(gWater
);
1561 addPanelsToGrid(gAcid1
);
1562 addPanelsToGrid(gAcid2
);
1563 addPanelsToGrid(gSteps
);
1564 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1565 addPanelsToGrid(gBlockMon
);
1567 mapGrid
.dumpStats();
1569 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1573 function g_Map_Load(Res
: String): Boolean;
1575 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1576 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1580 //TexturePanel: Integer;
1584 LiftPanelIdx
: Integer;
1585 DoorPanelIdx
: Integer;
1586 ShotPanelIdx
: Integer;
1587 MPlatPanelIdx
: Integer;
1588 trigrec
: TDynRecord
;
1590 liftPan
: TDynRecord
;
1591 doorPan
: TDynRecord
;
1592 shotPan
: TDynRecord
;
1593 mplatPan
: TDynRecord
;
1597 mapReader
: TDynRecord
= nil;
1598 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1599 panels
: TDynField
= nil; //TPanelsRec1Array;
1600 items
: TDynField
= nil; //TItemsRec1Array;
1601 monsters
: TDynField
= nil; //TMonsterRec1Array;
1602 areas
: TDynField
= nil; //TAreasRec1Array;
1603 triggers
: TDynField
= nil; //TTriggersRec1Array;
1606 AddTextures
: TAddTextureArray
;
1607 TriggersTable
: array of TTRec
;
1608 FileName
, mapResName
, s
, TexName
: String;
1611 ok
, isAnim
, trigRef
: Boolean;
1612 CurTex
, ntn
: Integer;
1613 rec
, texrec
: TDynRecord
;
1615 pannum
, trignum
, cnt
, tgpid
: Integer;
1617 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1618 //moveActive: Boolean;
1630 gMapInfo
.Map
:= Res
;
1631 TriggersTable
:= nil;
1634 sfsGCDisable(); // temporary disable removing of temporary volumes
1637 FileName
:= g_ExtractWadName(Res
);
1638 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1639 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1641 WAD
:= TWADFile
.Create();
1642 if not WAD
.ReadFile(FileName
) then
1644 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1649 //k8: why loader ignores path here?
1650 mapResName
:= g_ExtractFileName(Res
);
1651 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1653 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1662 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1668 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1669 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1671 stt
:= curTimeMicro();
1674 mapReader
:= g_Map_ParseMap(Data
, Len
);
1677 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1684 if (mapReader
= nil) then
1686 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1690 generateExternalResourcesList(mapReader
);
1691 mapTextureList
:= mapReader
['texture'];
1692 // get all other lists here too
1693 panels
:= mapReader
['panel'];
1694 triggers
:= mapReader
['trigger'];
1695 items
:= mapReader
['item'];
1696 areas
:= mapReader
['area'];
1697 monsters
:= mapReader
['monster'];
1699 // Çàãðóçêà îïèñàíèÿ êàðòû:
1700 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1701 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1705 Name
:= mapReader
.MapName
;
1706 Description
:= mapReader
.MapDesc
;
1707 Author
:= mapReader
.MapAuthor
;
1708 MusicName
:= mapReader
.MusicName
;
1709 SkyName
:= mapReader
.SkyName
;
1710 Height
:= mapReader
.Height
;
1711 Width
:= mapReader
.Width
;
1714 // Çàãðóçêà òåêñòóð:
1715 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1716 // Äîáàâëåíèå òåêñòóð â Textures[]:
1717 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1719 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1720 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1723 for rec
in mapTextureList
do
1727 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1728 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1730 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1733 // Àíèìèðîâàííàÿ òåêñòóðà
1734 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1735 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1740 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1741 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1743 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1745 rec
.tagInt
:= ntn
; // remember texture number
1746 g_Game_StepLoading();
1749 // set panel tagInt to texture index
1750 if (panels
<> nil) then
1752 for rec
in panels
do
1754 texrec
:= rec
.TextureRec
;
1755 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1760 // Çàãðóçêà òðèããåðîâ
1761 gTriggerClientID
:= 0;
1762 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1763 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1766 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1767 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1769 // check texture numbers for panels
1770 if (panels
<> nil) and (panels
.count
> 0) then
1772 for rec
in panels
do
1774 if (rec
.tagInt
< 0) then
1776 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1783 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1784 if (triggers
<> nil) and (triggers
.count
> 0) then
1786 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1787 //SetLength(TriggersTable, triggers.count);
1788 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1790 for rec
in triggers
do
1792 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1793 pttit
:= @TriggersTable
[High(TriggersTable
)];
1794 pttit
.trigrec
:= rec
;
1795 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1796 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1797 pttit
.liftPan
:= nil;
1798 pttit
.doorPan
:= nil;
1799 pttit
.shotPan
:= nil;
1800 pttit
.mplatPan
:= nil;
1801 pttit
.texPanIdx
:= -1;
1802 pttit
.LiftPanelIdx
:= -1;
1803 pttit
.DoorPanelIdx
:= -1;
1804 pttit
.ShotPanelIdx
:= -1;
1805 pttit
.MPlatPanelIdx
:= -1;
1807 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1809 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1812 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1814 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1817 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1819 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1822 if rec
.TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1824 pttit
.mplatPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1827 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1828 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1829 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1830 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1831 if (pttit
.mplatPan
<> nil) then pttit
.mplatPan
.userPanelTrigRef
:= true;
1833 g_Game_StepLoading();
1838 if (panels
<> nil) and (panels
.count
> 0) then
1840 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1841 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1844 for rec
in panels
do
1847 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1849 SetLength(AddTextures
, 0);
1854 if (mapTextureList
<> nil) then
1856 texrec
:= rec
.TextureRec
;
1857 ok
:= (texrec
<> nil);
1862 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1863 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1865 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1868 for b := 0 to High(TriggersTable) do
1870 if (TriggersTable[b].texPan = rec) or (TriggersTable[b].shotPan = rec) then
1878 if rec
.userPanelTrigRef
then
1880 // e_LogWritefln('trigref for panel %s', [pannum]);
1889 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1890 s
:= texrec
.Resource
;
1892 // Ñïåö-òåêñòóðû çàïðåùåíû
1893 if g_Map_IsSpecialTexture(s
) then
1899 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1900 ok
:= g_Texture_NumNameFindStart(s
);
1903 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1904 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1907 k
:= NNF_NAME_BEFORE
;
1908 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1909 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1911 k
:= g_Texture_NumNameFindNext(TexName
);
1913 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1915 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1918 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1920 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1921 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1922 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1925 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1927 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1928 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1929 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1934 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1936 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1937 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1938 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1941 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1943 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1944 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1945 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1949 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1953 for c := 0 to High(Textures) do
1955 if (Textures[c].TextureName = TexName) then
1957 SetLength(AddTextures, Length(AddTextures)+1);
1958 AddTextures[High(AddTextures)].Texture := c;
1959 AddTextures[High(AddTextures)].Anim := isAnim;
1964 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1966 SetLength(AddTextures
, Length(AddTextures
)+1);
1967 AddTextures
[High(AddTextures
)].Texture
:= c
;
1968 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1974 if k
= NNF_NAME_EQUALS
then
1976 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1977 SetLength(AddTextures
, Length(AddTextures
)+1);
1978 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1979 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1980 CurTex
:= High(AddTextures
);
1991 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1992 end; // if ok - ññûëàþòñÿ òðèããåðû
1996 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1997 SetLength(AddTextures
, 1);
1998 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1999 AddTextures
[0].Anim
:= false;
2000 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2004 //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);
2006 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2008 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2009 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
, trigRef
);
2010 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2011 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2014 moveSpeed
:= rec
.moveSpeed
;
2015 //moveStart := rec.moveStart;
2016 //moveEnd := rec.moveEnd;
2017 //moveActive := rec['move_active'].varvalue;
2018 if not moveSpeed
.isZero
then
2020 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2021 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2022 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2025 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2027 g_Game_StepLoading();
2031 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2032 for b
:= 0 to High(TriggersTable
) do
2034 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
2035 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
2036 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
2037 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
2038 if (TriggersTable
[b
].mplatPan
<> nil) then TriggersTable
[b
].MPlatPanelIdx
:= TriggersTable
[b
].mplatPan
.userPanelId
;
2041 // create map grid, init other grids (for monsters, for example)
2042 e_WriteLog('Creating map grid', MSG_NOTIFY
);
2045 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2046 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2048 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2049 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2050 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2052 for rec
in triggers
do
2055 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
2056 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
2057 // we can have only one of those
2058 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
2059 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
2060 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
2061 else if (TriggersTable
[trignum
].MPlatPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].MPlatPanelIdx
2063 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2064 TriggersTable
[trignum
].tnum
:= trignum
;
2065 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
2069 //FIXME: use hashtable!
2070 for pan
in panByGUID
do
2072 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2074 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2076 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2078 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2082 // Çàãðóçêà ïðåäìåòîâ
2083 e_WriteLog(' Loading items...', MSG_NOTIFY
);
2084 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2086 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2087 if (items
<> nil) and not gLoadGameMode
then
2089 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
2090 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2091 for rec
in items
do CreateItem(rec
);
2094 // Çàãðóçêà îáëàñòåé
2095 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2096 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2098 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2099 if areas
<> nil then
2101 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2102 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2103 for rec
in areas
do CreateArea(rec
);
2106 // Çàãðóçêà ìîíñòðîâ
2107 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2108 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2110 gTotalMonsters
:= 0;
2112 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2113 if (monsters
<> nil) and not gLoadGameMode
then
2115 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2116 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2117 for rec
in monsters
do CreateMonster(rec
);
2120 gCurrentMap
:= mapReader
; // this will be our current map now
2121 gCurrentMapFileName
:= Res
;
2125 if gMapInfo
.SkyName
<> '' then
2127 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2128 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2129 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2131 if FileName
<> '' then
2132 FileName
:= GameDir
+'/wads/'+FileName
2135 FileName
:= g_ExtractWadName(Res
);
2138 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2139 if g_Texture_CreateWAD(BackID
, s
) then
2141 g_Game_SetupScreenSize();
2144 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2149 if gMapInfo
.MusicName
<> '' then
2151 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2152 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2153 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2155 if FileName
<> '' then
2156 FileName
:= GameDir
+'/wads/'+FileName
2159 FileName
:= g_ExtractWadName(Res
);
2162 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2163 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2166 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2169 // Îñòàëüíûå óñòàíâêè
2177 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2178 if not gLoadGameMode
then g_GFX_Init();
2180 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2181 mapTextureList
:= nil;
2186 TriggersTable
:= nil;
2189 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2190 if ok
and (not gLoadGameMode
) then
2192 gMusic
.SetByName(gMapInfo
.MusicName
);
2197 gMusic
.SetByName('');
2200 stt
:= curTimeMicro()-stt
;
2201 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2203 sfsGCEnable(); // enable releasing unused volumes
2205 e_ClearInputBuffer(); // why not?
2208 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2213 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2216 mapReader
: TDynRecord
;
2217 //Header: TMapHeaderRec_1;
2222 FillChar(Result
, SizeOf(Result
), 0);
2223 FileName
:= g_ExtractWadName(Res
);
2225 WAD
:= TWADFile
.Create();
2226 if not WAD
.ReadFile(FileName
) then
2232 //k8: it ignores path again
2233 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2242 mapReader
:= g_Map_ParseMap(Data
, Len
);
2251 if (mapReader
= nil) then exit
;
2253 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2255 Result
.Name
:= mapReader
.MapName
;
2256 Result
.Description
:= mapReader
.MapDesc
;
2258 Result
.Author
:= mapReader
.MapAuthor
;
2259 Result
.Height
:= mapReader
.Height
;
2260 Result
.Width
:= mapReader
.Width
;
2264 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2265 //ZeroMemory(@Header, SizeOf(Header));
2266 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2267 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2269 Result
.Author
:= '';
2277 function g_Map_GetMapsList(WADName
: string): SArray
;
2284 WAD
:= TWADFile
.Create();
2285 if not WAD
.ReadFile(WADName
) then
2290 ResList
:= WAD
.GetMapResources();
2291 if ResList
<> nil then
2293 for a
:= 0 to High(ResList
) do
2295 SetLength(Result
, Length(Result
)+1);
2296 Result
[High(Result
)] := ResList
[a
];
2302 function g_Map_Exist(Res
: string): Boolean;
2305 FileName
, mnn
: string;
2311 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2313 WAD
:= TWADFile
.Create
;
2314 if not WAD
.ReadFile(FileName
) then
2320 ResList
:= WAD
.GetMapResources();
2323 mnn
:= g_ExtractFileName(Res
);
2324 if ResList
<> nil then
2325 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2332 procedure g_Map_Free(freeTextures
: Boolean=true);
2336 procedure FreePanelArray(var panels
: TPanelArray
);
2341 if panels
<> nil then
2343 for i
:= 0 to High(panels
) do
2356 RespawnPoints
:= nil;
2357 if FlagPoints
[FLAG_RED
] <> nil then
2359 Dispose(FlagPoints
[FLAG_RED
]);
2360 FlagPoints
[FLAG_RED
] := nil;
2362 if FlagPoints
[FLAG_BLUE
] <> nil then
2364 Dispose(FlagPoints
[FLAG_BLUE
]);
2365 FlagPoints
[FLAG_BLUE
] := nil;
2367 //DOMFlagPoints := nil;
2371 if (Length(gCurrentMapFileName
) <> 0) then
2373 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2377 e_LogWritefln('g_Map_Free: no previous map.', []);
2379 if freeTextures
then
2381 e_LogWritefln('g_Map_Free: clearing textures...', []);
2382 if (Textures
<> nil) then
2384 for a
:= 0 to High(Textures
) do
2386 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2388 if Textures
[a
].Anim
then
2390 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2394 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2396 e_DeleteTexture(Textures
[a
].TextureID
);
2403 TextNameHash
.Free();
2404 TextNameHash
:= nil;
2405 BadTextNameHash
.Free();
2406 BadTextNameHash
:= nil;
2411 FreePanelArray(gWalls
);
2412 FreePanelArray(gRenderBackgrounds
);
2413 FreePanelArray(gRenderForegrounds
);
2414 FreePanelArray(gWater
);
2415 FreePanelArray(gAcid1
);
2416 FreePanelArray(gAcid2
);
2417 FreePanelArray(gSteps
);
2418 FreePanelArray(gLifts
);
2419 FreePanelArray(gBlockMon
);
2420 gMovingWallIds
:= nil;
2422 if BackID
<> DWORD(-1) then
2426 e_DeleteTexture(BackID
);
2427 BackID
:= DWORD(-1);
2430 g_Game_StopAllSounds(False);
2432 g_Sound_Delete(gMapInfo
.MusicName
);
2434 gMapInfo
.Name
:= '';
2435 gMapInfo
.Description
:= '';
2436 gMapInfo
.MusicName
:= '';
2437 gMapInfo
.Height
:= 0;
2438 gMapInfo
.Width
:= 0;
2444 procedure g_Map_Update();
2450 procedure UpdatePanelArray(var panels
: TPanelArray
);
2455 for i
:= 0 to High(panels
) do panels
[i
].Update();
2459 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2461 UpdatePanelArray(gWalls
);
2462 UpdatePanelArray(gRenderBackgrounds
);
2463 UpdatePanelArray(gRenderForegrounds
);
2464 UpdatePanelArray(gWater
);
2465 UpdatePanelArray(gAcid1
);
2466 UpdatePanelArray(gAcid2
);
2467 UpdatePanelArray(gSteps
);
2469 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2471 if gGameSettings
.GameMode
= GM_CTF
then
2473 for a
:= FLAG_RED
to FLAG_BLUE
do
2475 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2479 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2481 m
:= g_Obj_Move(@Obj
, True, True);
2483 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2485 // Ñîïðîòèâëåíèå âîçäóõà
2486 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2488 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2489 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2492 gFlags
[a
].CaptureTime
:= 0;
2493 if a
= FLAG_RED
then
2494 s
:= _lc
[I_PLAYER_FLAG_RED
]
2496 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2497 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2499 if g_Game_IsNet
then
2500 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2504 if Count
> 0 then Count
-= 1;
2507 if gPlayers
<> nil then
2509 j
:= Random(Length(gPlayers
)) - 1;
2510 for d
:= 0 to High(gPlayers
) do
2513 if j
> High(gPlayers
) then j
:= 0;
2514 if gPlayers
[j
] <> nil then
2516 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2518 if gPlayers
[j
].GetFlag(a
) then Break
;
2531 procedure g_Map_DrawPanels (PanelType
: Word);
2533 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2537 if (panels
<> nil) then
2539 // alas, no visible set
2540 for idx
:= 0 to High(panels
) do
2542 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2549 PANEL_WALL
: DrawPanels(gWalls
);
2550 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2551 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2552 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2553 PANEL_WATER
: DrawPanels(gWater
);
2554 PANEL_ACID1
: DrawPanels(gAcid1
);
2555 PANEL_ACID2
: DrawPanels(gAcid2
);
2556 PANEL_STEP
: DrawPanels(gSteps
);
2562 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2564 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2566 result
:= false; // don't stop, ever
2567 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2568 gDrawPanelList
.insert(pan
);
2573 //tagmask := panelTypeToTag(PanelType);
2574 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2575 // list will be rendered in `g_game.DrawPlayer()`
2579 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2581 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2583 result
:= false; // don't stop, ever
2584 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2588 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2592 procedure g_Map_DrawBack(dx
, dy
: Integer);
2594 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2595 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2597 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2600 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2601 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2607 if WordBool(PanelType
and PANEL_WALL
) then
2608 if gWalls
<> nil then
2613 if gWalls
[a
].Enabled
and
2614 g_Collide(X
, Y
, Width
, Height
,
2615 gWalls
[a
].X
, gWalls
[a
].Y
,
2616 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2623 if WordBool(PanelType
and PANEL_WATER
) then
2624 if gWater
<> nil then
2629 if g_Collide(X
, Y
, Width
, Height
,
2630 gWater
[a
].X
, gWater
[a
].Y
,
2631 gWater
[a
].Width
, gWater
[a
].Height
) then
2638 if WordBool(PanelType
and PANEL_ACID1
) then
2639 if gAcid1
<> nil then
2644 if g_Collide(X
, Y
, Width
, Height
,
2645 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2646 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2653 if WordBool(PanelType
and PANEL_ACID2
) then
2654 if gAcid2
<> nil then
2659 if g_Collide(X
, Y
, Width
, Height
,
2660 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2661 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2668 if WordBool(PanelType
and PANEL_STEP
) then
2669 if gSteps
<> nil then
2674 if g_Collide(X
, Y
, Width
, Height
,
2675 gSteps
[a
].X
, gSteps
[a
].Y
,
2676 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2683 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2684 if gLifts
<> nil then
2689 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2690 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2691 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2692 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2693 g_Collide(X
, Y
, Width
, Height
,
2694 gLifts
[a
].X
, gLifts
[a
].Y
,
2695 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2702 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2703 if gBlockMon
<> nil then
2705 h
:= High(gBlockMon
);
2709 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2710 g_Collide(X
, Y
, Width
, Height
,
2711 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2712 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2720 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2724 function checkPanels (constref panels
: TPanelArray
): Boolean;
2729 if panels
= nil then exit
;
2730 for a
:= 0 to High(panels
) do
2732 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2735 texid
:= panels
[a
].GetTextureID();
2742 texid
:= LongWord(TEXTURE_NONE
);
2744 if not checkPanels(gWater
) then
2745 if not checkPanels(gAcid1
) then
2746 if not checkPanels(gAcid2
) then exit
;
2751 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2753 SlowMask
= GridTagLift
or GridTagBlockMon
;
2754 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2757 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2759 result := pan.Enabled;
2764 if ((tag
and GridTagLift
) <> 0) then
2767 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2768 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2769 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2770 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2771 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2775 if ((tag
and GridTagBlockMon
) <> 0) then
2777 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2782 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2783 result
:= true; // i found her!
2787 tagmask
: Integer = 0;
2789 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2790 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2791 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2792 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2793 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2794 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2795 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2797 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2799 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2800 if gdbg_map_use_accel_coldet
then
2802 if (Width
= 1) and (Height
= 1) then
2804 if ((tagmask
and SlowMask
) <> 0) then
2807 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2812 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2817 if ((tagmask
and SlowMask
) <> 0) then
2820 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2825 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2831 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2833 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2837 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2839 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2842 // slightly different from the old code, but meh...
2843 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2845 result
:= false; // don't stop, ever
2846 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2849 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2850 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2851 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2854 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2856 texid
:= pan
.GetTextureID();
2857 // water? water has the highest priority, so stop right here
2858 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2860 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2862 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2866 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2867 if gdbg_map_use_accel_coldet
then
2869 texid
:= LongWord(TEXTURE_NONE
);
2870 if (Width
= 1) and (Height
= 1) then
2872 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2876 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2882 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2884 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2888 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2889 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2890 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2893 procedure g_Map_EnableWallGUID (pguid
: Integer);
2897 //pan := gWalls[ID];
2898 pan
:= g_Map_PanelByGUID(pguid
);
2899 if (pan
= nil) then exit
;
2900 pan
.Enabled
:= True;
2901 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2903 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2904 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2905 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2907 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState({gWalls[ID]}pan
.PanelType
, pguid
);
2909 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2910 //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);
2915 procedure g_Map_DisableWallGUID (pguid
: Integer);
2919 //pan := gWalls[ID];
2920 pan
:= g_Map_PanelByGUID(pguid
);
2921 if (pan
= nil) then exit
;
2922 pan
.Enabled
:= False;
2923 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2925 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2926 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2928 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, pguid
);
2930 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2931 //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);
2936 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
2940 tp
:= g_Map_PanelByGUID(pguid
);
2941 if (tp
= nil) then exit
;
2944 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: tp := gWalls[ID];
2945 PANEL_FORE: tp := gRenderForegrounds[ID];
2946 PANEL_BACK: tp := gRenderBackgrounds[ID];
2947 PANEL_WATER: tp := gWater[ID];
2948 PANEL_ACID1: tp := gAcid1[ID];
2949 PANEL_ACID2: tp := gAcid2[ID];
2950 PANEL_STEP: tp := gSteps[ID];
2955 tp
.NextTexture(AnimLoop
);
2956 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(PanelType
, pguid
, AnimLoop
);
2960 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2964 //pan := gLifts[ID];
2965 pan
:= g_Map_PanelByGUID(pguid
);
2966 if (pan
= nil) then exit
;
2967 if not pan
.isGLift
then exit
;
2969 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2971 with {gLifts[ID]} pan
do
2975 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2976 //TODO: make separate lift tags, and change tag here
2979 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2980 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2981 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2982 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
2985 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, pguid
);
2990 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2993 PointsArray
: Array of TRespawnPoint
;
2996 SetLength(PointsArray
, 0);
2998 if RespawnPoints
= nil then
3001 for a
:= 0 to High(RespawnPoints
) do
3002 if RespawnPoints
[a
].PointType
= PointType
then
3004 SetLength(PointsArray
, Length(PointsArray
)+1);
3005 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3008 if PointsArray
= nil then
3011 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3015 function g_Map_GetPointCount(PointType
: Byte): Word;
3021 if RespawnPoints
= nil then
3024 for a
:= 0 to High(RespawnPoints
) do
3025 if RespawnPoints
[a
].PointType
= PointType
then
3026 Result
:= Result
+ 1;
3029 function g_Map_HaveFlagPoints(): Boolean;
3031 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3034 procedure g_Map_ResetFlag(Flag
: Byte);
3036 with gFlags
[Flag
] do
3042 Direction
:= D_LEFT
;
3043 State
:= FLAG_STATE_NONE
;
3044 if FlagPoints
[Flag
] <> nil then
3046 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3047 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3048 Direction
:= FlagPoints
[Flag
]^.Direction
;
3049 State
:= FLAG_STATE_NORMAL
;
3055 procedure g_Map_DrawFlags();
3058 Mirror
: TMirrorType
;
3060 if gGameSettings
.GameMode
<> GM_CTF
then
3063 for i
:= FLAG_RED
to FLAG_BLUE
do
3065 if State
<> FLAG_STATE_CAPTURED
then
3067 if State
= FLAG_STATE_NONE
then
3070 if Direction
= D_LEFT
then
3072 Mirror
:= M_HORIZONTAL
;
3081 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3083 if g_debug_Frames
then
3085 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3087 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3088 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3095 procedure g_Map_SaveState (var Mem
: TBinMemoryWriter
);
3102 procedure savePanels ();
3104 PAMem
: TBinMemoryWriter
;
3107 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé
3108 PAMem
:= TBinMemoryWriter
.Create((Length(panByGUID
)+1) * 40);
3110 for pan
in panByGUID
do
3112 if true{pan.SaveIt} then
3115 //PAMem.WriteInt(i);
3117 pan
.SaveState(PAMem
);
3121 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé
3122 PAMem
.SaveToMemory(Mem
);
3126 procedure SaveFlag (flag
: PFlag
);
3129 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3131 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3132 Mem
.WriteByte(flag
^.RespawnType
);
3134 Mem
.WriteByte(flag
^.State
);
3135 // Íàïðàâëåíèå ôëàãà
3136 if flag
^.Direction
= D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3139 Obj_SaveState(@flag
^.Obj
, Mem
);
3143 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3145 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3149 ///// Ñîõðàíÿåì ìóçûêó: /////
3150 // Ñèãíàòóðà ìóçûêè:
3151 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3154 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3155 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3156 Mem
.WriteString(str
, 64);
3157 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3158 dw
:= gMusic
.GetPosition();
3160 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3161 boo
:= gMusic
.SpecPause
;
3162 Mem
.WriteBoolean(boo
);
3165 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3166 Mem
.WriteInt(gTotalMonsters
);
3169 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3170 if gGameSettings
.GameMode
= GM_CTF
then
3172 // Ôëàã Êðàñíîé êîìàíäû
3173 SaveFlag(@gFlags
[FLAG_RED
]);
3174 // Ôëàã Ñèíåé êîìàíäû
3175 SaveFlag(@gFlags
[FLAG_BLUE
]);
3179 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3180 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3182 // Î÷êè Êðàñíîé êîìàíäû
3183 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3184 // Î÷êè Ñèíåé êîìàíäû
3185 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3191 procedure g_Map_LoadState (var Mem
: TBinMemoryReader
);
3198 procedure loadPanels ();
3200 PAMem
: TBinMemoryReader
;
3203 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé
3204 PAMem
:= TBinMemoryReader
.Create();
3205 PAMem
.LoadFromMemory(Mem
);
3207 for pan
in panByGUID
do
3209 if true{pan.SaveIt} then
3212 //PAMem.ReadInt(id);
3214 if id <> i then raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
3217 pan
.LoadState(PAMem
);
3218 //if (panels[i].arrIdx <> i) then raise Exception.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
3219 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3223 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí
3227 procedure LoadFlag(flag
: PFlag
);
3232 if dw
<> FLAG_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3233 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3234 Mem
.ReadByte(flag
^.RespawnType
);
3236 Mem
.ReadByte(flag
^.State
);
3237 // Íàïðàâëåíèå ôëàãà
3239 if b
= 1 then flag
^.Direction
:= D_LEFT
else flag
^.Direction
:= D_RIGHT
; // b = 2
3241 Obj_LoadState(@flag
^.Obj
, Mem
);
3245 if Mem
= nil then Exit
;
3247 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3251 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3255 ///// Çàãðóæàåì ìóçûêó: /////
3259 if dw
<> MUSIC_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3261 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3262 Mem
.ReadString(str
);
3263 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3265 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3266 Mem
.ReadBoolean(boo
);
3267 // Çàïóñêàåì ýòó ìóçûêó
3268 gMusic
.SetByName(str
);
3269 gMusic
.SpecPause
:= boo
;
3272 gMusic
.SetPosition(dw
);
3275 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3276 Mem
.ReadInt(gTotalMonsters
);
3279 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3280 if gGameSettings
.GameMode
= GM_CTF
then
3282 // Ôëàã Êðàñíîé êîìàíäû
3283 LoadFlag(@gFlags
[FLAG_RED
]);
3284 // Ôëàã Ñèíåé êîìàíäû
3285 LoadFlag(@gFlags
[FLAG_BLUE
]);
3289 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3290 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3292 // Î÷êè Êðàñíîé êîìàíäû
3293 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3294 // Î÷êè Ñèíåé êîìàíäû
3295 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3301 // trace liquid, stepping by `dx` and `dy`
3302 // return last seen liquid coords, and `false` if we're started outside of the liquid
3303 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3305 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3309 // started outside of the liquid?
3310 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3311 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3317 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit