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 is nested
; // return `true` to stop
114 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
115 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
117 // trace liquid, stepping by `dx` and `dy`
118 // return last seen liquid coords, and `false` if we're started outside of the liquid
119 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
122 // return `true` from `cb` to stop
123 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
125 procedure g_Map_NetSendInterestingPanels (); // yay!
128 procedure g_Map_ProfilersBegin ();
129 procedure g_Map_ProfilersEnd ();
132 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
135 function g_Map_MinX (): Integer; inline;
136 function g_Map_MinY (): Integer; inline;
137 function g_Map_MaxX (): Integer; inline;
138 function g_Map_MaxY (): Integer; inline;
146 function g_Texture_NumNameFindStart(name
: String): Boolean;
147 function g_Texture_NumNameFindNext(var newName
: String): Byte;
150 RESPAWNPOINT_PLAYER1
= 1;
151 RESPAWNPOINT_PLAYER2
= 2;
153 RESPAWNPOINT_RED
= 4;
154 RESPAWNPOINT_BLUE
= 5;
162 FLAG_STATE_NORMAL
= 1;
163 FLAG_STATE_DROPPED
= 2;
164 FLAG_STATE_CAPTURED
= 3;
165 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
166 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
168 FLAG_TIME
= 720; // 20 seconds
170 SKY_STRETCH
: Single = 1.5;
185 // sorted by draw priority
186 GridTagBack
= 1 shl 0; // gRenderBackgrounds
187 GridTagStep
= 1 shl 1; // gSteps
188 GridTagWall
= 1 shl 2; // gWalls
189 GridTagDoor
= 1 shl 3; // gWalls
190 GridTagAcid1
= 1 shl 4; // gAcid1
191 GridTagAcid2
= 1 shl 5; // gAcid2
192 GridTagWater
= 1 shl 6; // gWater
193 GridTagFore
= 1 shl 7; // gRenderForegrounds
194 // the following are invisible
195 GridTagLift
= 1 shl 8; // gLifts
196 GridTagBlockMon
= 1 shl 9; // gBlockMon
198 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
199 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
201 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
206 gRenderBackgrounds
: TPanelArray
;
207 gRenderForegrounds
: TPanelArray
;
208 gWater
, gAcid1
, gAcid2
: TPanelArray
;
211 gBlockMon
: TPanelArray
;
212 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
213 //gDOMFlags: array of TFlag;
216 gDoorMap
: array of array of DWORD
;
217 gLiftMap
: array of array of DWORD
;
218 gWADHash
: TMD5Digest
;
219 BackID
: DWORD
= DWORD(-1);
220 gExternalResources
: TStringList
;
221 gMovingWallIds
: array of Integer = nil;
223 gdbg_map_use_accel_render
: Boolean = true;
224 gdbg_map_use_accel_coldet
: Boolean = true;
225 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
226 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
228 gCurrentMap
: TDynRecord
= nil;
229 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
232 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
236 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
239 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
245 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
246 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
247 g_options
, g_triggers
, g_player
,
248 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
249 utils
, sfs
, xstreams
, hashtable
,
250 ImagingTypes
, Imaging
, ImagingUtility
,
251 ImagingGif
, ImagingNetworkGraphics
;
254 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
255 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
256 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
260 panByGUID
: array of TPanel
= nil;
263 // ////////////////////////////////////////////////////////////////////////// //
264 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
266 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
267 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
271 // return `true` from `cb` to stop
272 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
277 if not assigned(cb
) then exit
;
278 for pan
in panByGUID
do
280 if cb(pan
) then begin result
:= pan
; exit
; end;
285 procedure g_Map_NetSendInterestingPanels ();
289 if g_Game_IsServer
and g_Game_IsNet
then
291 for pan
in panByGUID
do
293 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
299 // ////////////////////////////////////////////////////////////////////////// //
300 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
301 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
302 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
303 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
306 // ////////////////////////////////////////////////////////////////////////// //
308 dfmapdef
: TDynMapDef
= nil;
311 procedure loadMapDefinition ();
313 pr
: TTextParser
= nil;
317 if (dfmapdef
<> nil) then exit
;
320 e_LogWritefln('parsing "mapdef.txt"...', []);
321 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
322 e_LogWritefln('found local "%smapdef.txt"', [DataDir
]);
329 WAD
:= TWADFile
.Create();
330 if not WAD
.ReadFile(GameWAD
) then
332 //raise Exception.Create('cannot load "game.wad"');
337 st
:= WAD
.openFileStream('mapdef.txt');
344 //raise Exception.Create('cannot open "mapdef.txt"');
345 e_LogWriteln('using default "mapdef.txt"...');
346 pr
:= TStrTextParser
.Create(defaultMapDef
);
350 pr
:= TFileTextParser
.Create(st
);
352 except on e
: Exception
do
354 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
360 dfmapdef
:= TDynMapDef
.Create(pr
);
362 on e
: TDynParseException
do
363 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
365 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
373 // ////////////////////////////////////////////////////////////////////////// //
374 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
376 wst
: TSFSMemoryChunkStream
= nil;
379 if (dataLen
< 4) then exit
;
381 if (dfmapdef
= nil) then writeln('need to load mapdef');
383 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
385 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
387 result
:= dfmapdef
.parseMap(wst
);
389 on e
: TDynParseException
do
391 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
398 e_LogWritefln('ERROR: %s', [e
.message]);
405 //e_LogWriteln('map parsed.');
409 // ////////////////////////////////////////////////////////////////////////// //
411 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
412 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
413 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
416 function g_Texture_NumNameFindStart(name
: String): Boolean;
424 NNF_CurrentNum
:= -1;
426 for i
:= Length(name
) downto 1 do
427 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
429 if i
= Length(name
) then
430 begin // Íåò öèôð â êîíöå ñòðîêè
435 NNF_PureName
:= Copy(name
, 1, i
);
441 // Íå ïåðåâåñòè â ÷èñëî:
442 if not TryStrToInt(name
, NNF_FirstNum
) then
451 function g_Texture_NumNameFindNext(var newName
: String): Byte;
453 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
456 Result
:= NNF_NO_NAME
;
460 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
462 if NNF_CurrentNum
< NNF_FirstNum
then
463 Result
:= NNF_NAME_BEFORE
465 if NNF_CurrentNum
> NNF_FirstNum
then
466 Result
:= NNF_NAME_AFTER
468 Result
:= NNF_NAME_EQUALS
;
474 // ////////////////////////////////////////////////////////////////////////// //
475 function panelTypeToTag (panelType
: Word): Integer;
478 PANEL_WALL
: result
:= GridTagWall
; // gWalls
479 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
480 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
481 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
482 PANEL_WATER
: result
:= GridTagWater
; // gWater
483 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
484 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
485 PANEL_STEP
: result
:= GridTagStep
; // gSteps
486 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
487 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
488 else result
:= GridTagInvalid
;
493 function dplLess (a
, b
: TObject
): Boolean;
499 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
500 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
501 result
:= (pa
.arrIdx
< pb
.arrIdx
);
504 procedure dplClear ();
506 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
511 Textures
: TLevelTextureArray
= nil;
512 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
513 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
514 RespawnPoints
: array of TRespawnPoint
;
515 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
516 //DOMFlagPoints: Array of TFlagPoint;
519 procedure g_Map_ProfilersBegin ();
521 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
522 profMapCollision
.mainBegin(g_profile_collision
);
524 if g_profile_collision
then
526 profMapCollision
.sectionBegin('*solids');
527 profMapCollision
.sectionEnd();
528 profMapCollision
.sectionBegin('liquids');
529 profMapCollision
.sectionEnd();
533 procedure g_Map_ProfilersEnd ();
535 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
539 // wall index in `gWalls` or -1
540 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
544 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
545 if (result
<> nil) then
547 if (hitx
<> nil) then hitx
^ := ex
;
548 if (hity
<> nil) then hity
^ := ey
;
552 if (hitx
<> nil) then hitx
^ := x1
;
553 if (hity
<> nil) then hity
^ := y1
;
557 // returns panel or nil
558 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
562 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
563 if (result
<> nil) then
565 if (hitx
<> nil) then hitx
^ := ex
;
566 if (hity
<> nil) then hity
^ := ey
;
570 if (hitx
<> nil) then hitx
^ := x1
;
571 if (hity
<> nil) then hity
^ := y1
;
576 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
578 function checker (pan
: TPanel
; tag
: Integer): Boolean;
581 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
583 result := pan.Enabled; // stop if wall is enabled
588 if ((tag
and GridTagLift
) <> 0) then
590 // stop if the lift of the right type
592 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
593 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
594 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
595 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
599 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
603 tagmask
: Integer = 0;
607 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
608 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
609 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
610 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
611 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
612 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
613 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
615 if (tagmask
= 0) then exit
;// just in case
616 if ((tagmask
and GridTagLift
) <> 0) then
619 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
624 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
629 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
632 if (tagmask
= 0) then exit
;
633 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
637 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
639 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
640 (Texture
= TEXTURE_NAME_ACID1
) or
641 (Texture
= TEXTURE_NAME_ACID2
);
644 procedure CreateDoorMap();
646 PanelArray
: Array of record
652 a
, b
, c
, m
, i
, len
: Integer;
660 SetLength(PanelArray
, len
);
662 for a
:= 0 to High(gWalls
) do
663 if gWalls
[a
].Door
then
665 PanelArray
[i
].X
:= gWalls
[a
].X
;
666 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
667 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
668 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
669 PanelArray
[i
].Active
:= True;
670 PanelArray
[i
].PanelID
:= a
;
676 SetLength(PanelArray
, len
);
687 SetLength(gDoorMap
, 0);
689 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
692 if PanelArray
[a
].Active
then
694 PanelArray
[a
].Active
:= False;
695 m
:= Length(gDoorMap
);
696 SetLength(gDoorMap
, m
+1);
697 SetLength(gDoorMap
[m
], 1);
698 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
706 if PanelArray
[b
].Active
then
707 for c
:= 0 to High(gDoorMap
[m
]) do
708 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
709 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
710 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
711 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
712 gWalls
[gDoorMap
[m
, c
]].X
,
713 gWalls
[gDoorMap
[m
, c
]].Y
,
714 gWalls
[gDoorMap
[m
, c
]].Width
,
715 gWalls
[gDoorMap
[m
, c
]].Height
) then
717 PanelArray
[b
].Active
:= False;
718 SetLength(gDoorMap
[m
],
719 Length(gDoorMap
[m
])+1);
720 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
726 g_Game_StepLoading();
732 procedure CreateLiftMap();
734 PanelArray
: Array of record
739 a
, b
, c
, len
, i
, j
: Integer;
745 len
:= Length(gLifts
);
746 SetLength(PanelArray
, len
);
748 for a
:= 0 to len
-1 do
750 PanelArray
[a
].X
:= gLifts
[a
].X
;
751 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
752 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
753 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
754 PanelArray
[a
].Active
:= True;
757 SetLength(gLiftMap
, len
);
760 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
762 for a
:= 0 to len
-1 do
763 if PanelArray
[a
].Active
then
765 PanelArray
[a
].Active
:= False;
766 SetLength(gLiftMap
[i
], 32);
774 for b
:= 0 to len
-1 do
775 if PanelArray
[b
].Active
then
777 if g_CollideAround(PanelArray
[b
].X
,
780 PanelArray
[b
].Height
,
781 PanelArray
[gLiftMap
[i
, c
]].X
,
782 PanelArray
[gLiftMap
[i
, c
]].Y
,
783 PanelArray
[gLiftMap
[i
, c
]].Width
,
784 PanelArray
[gLiftMap
[i
, c
]].Height
) then
786 PanelArray
[b
].Active
:= False;
788 if j
> High(gLiftMap
[i
]) then
789 SetLength(gLiftMap
[i
],
790 Length(gLiftMap
[i
])+32);
799 SetLength(gLiftMap
[i
], j
+1);
802 g_Game_StepLoading();
805 SetLength(gLiftMap
, i
);
810 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
813 panels
: ^TPanelArray
;
819 case PanelRec
.PanelType
of
820 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
821 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
822 PANEL_FORE
: panels
:= @gRenderForegrounds
;
823 PANEL_WATER
: panels
:= @gWater
;
824 PANEL_ACID1
: panels
:= @gAcid1
;
825 PANEL_ACID2
: panels
:= @gAcid2
;
826 PANEL_STEP
: panels
:= @gSteps
;
827 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
828 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
832 len
:= Length(panels
^);
833 SetLength(panels
^, len
+1);
835 pguid
:= Length(panByGUID
);
836 SetLength(panByGUID
, pguid
+1); //FIXME!
837 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
839 assert(pguid
< Length(panByGUID
));
840 panByGUID
[pguid
] := pan
;
844 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
846 PanelRec
.user
['panel_guid'] := pguid
;
853 function CreateNullTexture(RecName
: String): Integer;
855 RecName
:= toLowerCase1251(RecName
);
856 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
857 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
859 SetLength(Textures
, Length(Textures
)+1);
860 result
:= High(Textures
);
862 with Textures
[High(Textures
)] do
864 TextureName
:= RecName
;
868 TextureID
:= LongWord(TEXTURE_NONE
);
871 TextNameHash
.put(RecName
, result
);
875 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
878 TextureData
: Pointer;
880 a
, ResLength
: Integer;
882 RecName
:= toLowerCase1251(RecName
);
883 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
884 if TextNameHash
.get(RecName
, result
) then
887 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
893 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
896 if Textures <> nil then
898 for a := 0 to High(Textures) do
900 if (Textures[a].TextureName = RecName) then
901 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
902 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
910 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
911 if (RecName
= TEXTURE_NAME_WATER
) or
912 (RecName
= TEXTURE_NAME_ACID1
) or
913 (RecName
= TEXTURE_NAME_ACID2
) then
915 SetLength(Textures
, Length(Textures
)+1);
917 with Textures
[High(Textures
)] do
919 TextureName
:= RecName
;
920 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
921 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
922 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
927 result
:= High(Textures
);
928 TextNameHash
.put(RecName
, result
);
932 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
933 WADName
:= g_ExtractWadName(RecName
);
935 WAD
:= TWADFile
.Create();
937 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
939 WAD
.ReadFile(WADName
);
943 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
945 FreeMem(TextureData);
946 RecName := 'COMMON\ALIEN';
950 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
952 SetLength(Textures
, Length(Textures
)+1);
953 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
955 SetLength(Textures
, Length(Textures
)-1);
958 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
959 FreeMem(TextureData
);
960 Textures
[High(Textures
)].TextureName
:= RecName
;
961 Textures
[High(Textures
)].Anim
:= False;
963 result
:= High(Textures
);
964 TextNameHash
.put(RecName
, result
);
966 else // Íåò òàêîãî ðåóñðñà â WAD'å
968 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
969 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
970 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
972 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
973 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
975 BadTextNameHash
.put(RecName
, -1);
982 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
985 TextureWAD
: PChar = nil;
986 TextData
: Pointer = nil;
987 TextureData
: Pointer = nil;
991 TextureResource
: String;
992 _width
, _height
, _framecount
, _speed
: Integer;
993 _backanimation
: Boolean;
995 ia
: TDynImageDataArray
= nil;
996 f
, c
, frdelay
, frloop
: Integer;
998 RecName
:= toLowerCase1251(RecName
);
999 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
1000 if TextNameHash
.get(RecName
, result
) then
1003 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
1009 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1011 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1012 if BadTextNameHash
.get(RecName
, f
) then
1014 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1018 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1019 WADName
:= g_ExtractWadName(RecName
);
1021 WAD
:= TWADFile
.Create();
1023 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
1025 WAD
.ReadFile(WADName
);
1027 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1029 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1030 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1032 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1033 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1035 BadTextNameHash
.put(RecName
, -1);
1040 if WADName = Map then
1042 //FreeMem(TextureWAD);
1043 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1049 if ResLength
< 6 then
1051 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
1052 BadTextNameHash
.put(RecName
, -1);
1056 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1057 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1058 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1060 // íåò, ýòî ñóïåðìåí!
1061 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1063 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1064 BadTextNameHash
.put(RecName
, -1);
1068 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1069 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1071 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1072 BadTextNameHash
.put(RecName
, -1);
1076 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1078 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1079 if TextureResource
= '' then
1081 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1082 BadTextNameHash
.put(RecName
, -1);
1086 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1087 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1088 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1089 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1090 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1095 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1096 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1098 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1099 BadTextNameHash
.put(RecName
, -1);
1106 SetLength(Textures
, Length(Textures
)+1);
1107 with Textures
[High(Textures
)] do
1109 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1110 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1112 TextureName
:= RecName
;
1116 FramesCount
:= _framecount
;
1118 result
:= High(Textures
);
1119 TextNameHash
.put(RecName
, result
);
1123 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1124 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1126 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1128 BadTextNameHash
.put(RecName
, -1);
1134 // try animated image
1136 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1137 if length(imgfmt) = 0 then
1139 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1143 GlobalMetadata
.ClearMetaItems();
1144 GlobalMetadata
.ClearMetaItemsForSaving();
1145 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1147 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1148 BadTextNameHash
.put(RecName
, -1);
1151 if length(ia
) = 0 then
1153 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1154 BadTextNameHash
.put(RecName
, -1);
1161 _width
:= ia
[0].width
;
1162 _height
:= ia
[0].height
;
1163 _framecount
:= length(ia
);
1165 _backanimation
:= false;
1168 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1170 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1172 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1174 if f
< 0 then f
:= 0;
1177 if c
< 13 then c
:= 0 else c
:= 1;
1179 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1184 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1186 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1188 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1190 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1194 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1195 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1196 f
:= ord(_backanimation
);
1197 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
);
1199 SetLength(Textures
, Length(Textures
)+1);
1200 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1201 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1203 Textures
[High(Textures
)].TextureName
:= RecName
;
1204 Textures
[High(Textures
)].Width
:= _width
;
1205 Textures
[High(Textures
)].Height
:= _height
;
1206 Textures
[High(Textures
)].Anim
:= True;
1207 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1208 Textures
[High(Textures
)].Speed
:= _speed
;
1209 result
:= High(Textures
);
1210 TextNameHash
.put(RecName
, result
);
1211 //writeln(' CREATED!');
1215 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1216 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1218 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1220 BadTextNameHash
.put(RecName
, -1);
1224 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1227 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1228 if (TextData
<> nil) then FreeMem(TextData
);
1229 if (TextureData
<> nil) then FreeMem(TextureData
);
1233 procedure CreateItem(Item
: TDynRecord
);
1235 if g_Game_IsClient
then Exit
;
1237 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1238 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1241 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1242 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1245 procedure CreateArea(Area
: TDynRecord
);
1250 case Area
.AreaType
of
1251 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1252 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1254 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1255 with RespawnPoints
[High(RespawnPoints
)] do
1259 Direction
:= TDirection(Area
.Direction
);
1261 case Area
.AreaType
of
1262 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1263 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1264 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1265 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1266 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1271 AREA_REDFLAG
, AREA_BLUEFLAG
:
1273 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1275 if FlagPoints
[a
] <> nil then Exit
;
1279 with FlagPoints
[a
]^ do
1281 X
:= Area
.X
-FLAGRECT
.X
;
1282 Y
:= Area
.Y
-FLAGRECT
.Y
;
1283 Direction
:= TDirection(Area
.Direction
);
1289 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1290 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1293 Animation
:= TAnimation
.Create(id
, True, 8);
1294 Obj
.Rect
:= FLAGRECT
;
1302 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1303 with DOMFlagPoints[High(DOMFlagPoints)] do
1307 Direction := TDirection(Area.Direction);
1310 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1315 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word): Integer;
1320 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1324 mapId
:= Trigger
.id
;
1325 mapIndex
:= amapIdx
;
1328 Width
:= Trigger
.Width
;
1329 Height
:= Trigger
.Height
;
1330 Enabled
:= Trigger
.Enabled
;
1331 //TexturePanel := Trigger.TexturePanel;
1332 TexturePanelGUID
:= atpanid
;
1333 TexturePanelType
:= fTexturePanel1Type
;
1334 ShotPanelType
:= fTexturePanel2Type
;
1335 TriggerType
:= Trigger
.TriggerType
;
1336 ActivateType
:= Trigger
.ActivateType
;
1337 Keys
:= Trigger
.Keys
;
1338 trigPanelGUID
:= atrigpanid
;
1339 //trigShotPanelId := ashotpanid;
1340 //Data.Default := Trigger.DATA;
1341 if (Trigger
.trigRec
= nil) then
1345 if (TriggerType
<> TRIGGER_SECRET
) then
1347 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1352 trigDataRec
:= Trigger
.trigRec
.clone(nil);
1356 result
:= Integer(g_Triggers_Create(_trigger
));
1359 procedure CreateMonster(monster
: TDynRecord
);
1364 if g_Game_IsClient
then Exit
;
1366 if (gGameSettings
.GameType
= GT_SINGLE
)
1367 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1369 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1371 if gTriggers
<> nil then
1373 for a
:= 0 to High(gTriggers
) do
1375 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1377 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1378 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1383 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1387 procedure g_Map_ReAdd_DieTriggers();
1389 function monsDieTrig (mon
: TMonster
): Boolean;
1392 //tw: TStrTextWriter;
1394 result
:= false; // don't stop
1395 mon
.ClearTriggers();
1396 for a
:= 0 to High(gTriggers
) do
1398 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1400 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1402 tw := TStrTextWriter.Create();
1404 gTriggers[a].trigData.writeTo(tw);
1405 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1410 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1416 if g_Game_IsClient
then Exit
;
1418 g_Mons_ForEach(monsDieTrig
);
1421 function extractWadName(resourceName
: string): string;
1425 posN
:= Pos(':', resourceName
);
1427 Result
:= Copy(resourceName
, 0, posN
-1)
1432 procedure addResToExternalResList(res
: string);
1434 res
:= extractWadName(res
);
1435 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1436 gExternalResources
.Add(res
);
1439 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1441 //textures: TTexturesRec1Array;
1442 //textures: TDynField;
1444 //mapHeader: TMapHeaderRec_1;
1446 //resFile: String = '';
1448 if gExternalResources
= nil then
1449 gExternalResources
:= TStringList
.Create
;
1451 gExternalResources
.Clear
;
1455 textures := GetTextures(map);
1456 for i := 0 to High(textures) do
1458 addResToExternalResList(resFile);
1462 textures := map['texture'];
1463 if (textures <> nil) then
1465 for trec in textures do
1467 addResToExternalResList(resFile);
1474 //mapHeader := GetMapHeader(map);
1476 addResToExternalResList(map
.MusicName
);
1477 addResToExternalResList(map
.SkyName
);
1481 procedure mapCreateGrid ();
1483 mapX0
: Integer = $3fffffff;
1484 mapY0
: Integer = $3fffffff;
1485 mapX1
: Integer = -$3fffffff;
1486 mapY1
: Integer = -$3fffffff;
1488 procedure calcBoundingBox (constref panels
: TPanelArray
);
1493 for idx
:= 0 to High(panels
) do
1496 if not pan
.visvalid
then continue
;
1497 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1498 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1499 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1500 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1501 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1505 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1511 //tag := panelTypeToTag(tag);
1512 for idx
:= 0 to High(panels
) do
1515 if not pan
.visvalid
then continue
;
1516 if (pan
.proxyId
<> -1) then
1518 {$IF DEFINED(D2F_DEBUG)}
1519 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
);
1523 case pan
.PanelType
of
1524 PANEL_WALL
: newtag
:= GridTagWall
;
1525 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1526 PANEL_BACK
: newtag
:= GridTagBack
;
1527 PANEL_FORE
: newtag
:= GridTagFore
;
1528 PANEL_WATER
: newtag
:= GridTagWater
;
1529 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1530 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1531 PANEL_STEP
: newtag
:= GridTagStep
;
1532 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1533 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1534 else continue
; // oops
1538 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1539 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1540 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1541 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1543 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1545 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1556 calcBoundingBox(gWalls
);
1557 calcBoundingBox(gRenderBackgrounds
);
1558 calcBoundingBox(gRenderForegrounds
);
1559 calcBoundingBox(gWater
);
1560 calcBoundingBox(gAcid1
);
1561 calcBoundingBox(gAcid2
);
1562 calcBoundingBox(gSteps
);
1563 calcBoundingBox(gLifts
);
1564 calcBoundingBox(gBlockMon
);
1566 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1568 if (mapX0
> 0) then mapX0
:= 0;
1569 if (mapY0
> 0) then mapY0
:= 0;
1571 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1572 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1574 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1575 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1577 addPanelsToGrid(gWalls
);
1578 addPanelsToGrid(gRenderBackgrounds
);
1579 addPanelsToGrid(gRenderForegrounds
);
1580 addPanelsToGrid(gWater
);
1581 addPanelsToGrid(gAcid1
);
1582 addPanelsToGrid(gAcid2
);
1583 addPanelsToGrid(gSteps
);
1584 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1585 addPanelsToGrid(gBlockMon
);
1587 mapGrid
.dumpStats();
1589 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1593 function g_Map_Load(Res
: String): Boolean;
1595 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1596 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1600 //TexturePanel: Integer;
1604 LiftPanelIdx
: Integer;
1605 DoorPanelIdx
: Integer;
1606 ShotPanelIdx
: Integer;
1607 MPlatPanelIdx
: Integer;
1608 trigrec
: TDynRecord
;
1610 liftPan
: TDynRecord
;
1611 doorPan
: TDynRecord
;
1612 shotPan
: TDynRecord
;
1613 mplatPan
: TDynRecord
;
1617 mapReader
: TDynRecord
= nil;
1618 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1619 panels
: TDynField
= nil; //TPanelsRec1Array;
1620 items
: TDynField
= nil; //TItemsRec1Array;
1621 monsters
: TDynField
= nil; //TMonsterRec1Array;
1622 areas
: TDynField
= nil; //TAreasRec1Array;
1623 triggers
: TDynField
= nil; //TTriggersRec1Array;
1626 AddTextures
: TAddTextureArray
;
1627 TriggersTable
: array of TTRec
;
1628 FileName
, mapResName
, s
, TexName
: String;
1631 ok
, isAnim
: Boolean;
1632 CurTex
, ntn
: Integer;
1633 rec
, texrec
: TDynRecord
;
1635 pannum
, trignum
, cnt
, tgpid
: Integer;
1637 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1638 //moveActive: Boolean;
1650 gMapInfo
.Map
:= Res
;
1651 TriggersTable
:= nil;
1654 sfsGCDisable(); // temporary disable removing of temporary volumes
1657 FileName
:= g_ExtractWadName(Res
);
1658 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1659 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1661 WAD
:= TWADFile
.Create();
1662 if not WAD
.ReadFile(FileName
) then
1664 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1669 //k8: why loader ignores path here?
1670 mapResName
:= g_ExtractFileName(Res
);
1671 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1673 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1682 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1688 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1689 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1691 stt
:= curTimeMicro();
1694 mapReader
:= g_Map_ParseMap(Data
, Len
);
1697 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1704 if (mapReader
= nil) then
1706 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1710 generateExternalResourcesList(mapReader
);
1711 mapTextureList
:= mapReader
['texture'];
1712 // get all other lists here too
1713 panels
:= mapReader
['panel'];
1714 triggers
:= mapReader
['trigger'];
1715 items
:= mapReader
['item'];
1716 areas
:= mapReader
['area'];
1717 monsters
:= mapReader
['monster'];
1719 // Çàãðóçêà îïèñàíèÿ êàðòû:
1720 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1721 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1725 Name
:= mapReader
.MapName
;
1726 Description
:= mapReader
.MapDesc
;
1727 Author
:= mapReader
.MapAuthor
;
1728 MusicName
:= mapReader
.MusicName
;
1729 SkyName
:= mapReader
.SkyName
;
1730 Height
:= mapReader
.Height
;
1731 Width
:= mapReader
.Width
;
1734 // Çàãðóçêà òåêñòóð:
1735 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1736 // Äîáàâëåíèå òåêñòóð â Textures[]:
1737 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1739 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1740 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1743 for rec
in mapTextureList
do
1747 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1748 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1750 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1753 // Àíèìèðîâàííàÿ òåêñòóðà
1754 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1755 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1760 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1761 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1763 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1765 rec
.tagInt
:= ntn
; // remember texture number
1766 g_Game_StepLoading();
1769 // set panel tagInt to texture index
1770 if (panels
<> nil) then
1772 for rec
in panels
do
1774 texrec
:= rec
.TextureRec
;
1775 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1780 // Çàãðóçêà òðèããåðîâ
1781 gTriggerClientID
:= 0;
1782 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1783 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1786 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1787 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1789 // check texture numbers for panels
1790 if (panels
<> nil) and (panels
.count
> 0) then
1792 for rec
in panels
do
1794 if (rec
.tagInt
< 0) then
1796 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1803 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1804 if (triggers
<> nil) and (triggers
.count
> 0) then
1806 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1807 //SetLength(TriggersTable, triggers.count);
1808 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1810 for rec
in triggers
do
1812 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1813 pttit
:= @TriggersTable
[High(TriggersTable
)];
1814 pttit
.trigrec
:= rec
;
1815 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1816 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1817 pttit
.liftPan
:= nil;
1818 pttit
.doorPan
:= nil;
1819 pttit
.shotPan
:= nil;
1820 pttit
.mplatPan
:= nil;
1821 pttit
.texPanIdx
:= -1;
1822 pttit
.LiftPanelIdx
:= -1;
1823 pttit
.DoorPanelIdx
:= -1;
1824 pttit
.ShotPanelIdx
:= -1;
1825 pttit
.MPlatPanelIdx
:= -1;
1827 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1829 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1832 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1834 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1837 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1839 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1842 if rec
.TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1844 pttit
.mplatPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1847 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1848 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1849 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1850 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1851 if (pttit
.mplatPan
<> nil) then pttit
.mplatPan
.userPanelTrigRef
:= true;
1853 g_Game_StepLoading();
1858 if (panels
<> nil) and (panels
.count
> 0) then
1860 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1861 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1864 for rec
in panels
do
1867 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1869 SetLength(AddTextures
, 0);
1873 if (mapTextureList
<> nil) then
1875 texrec
:= rec
.TextureRec
;
1876 ok
:= (texrec
<> nil);
1881 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1882 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1884 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1886 if rec
.userPanelTrigRef
then
1888 // e_LogWritefln('trigref for panel %s', [pannum]);
1896 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1897 s
:= texrec
.Resource
;
1899 // Ñïåö-òåêñòóðû çàïðåùåíû
1900 if g_Map_IsSpecialTexture(s
) then
1906 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1907 ok
:= g_Texture_NumNameFindStart(s
);
1910 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1911 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1914 k
:= NNF_NAME_BEFORE
;
1915 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1916 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1918 k
:= g_Texture_NumNameFindNext(TexName
);
1920 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1922 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1925 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1927 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1928 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1929 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1932 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1934 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1935 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1936 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1941 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1943 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1944 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1945 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1948 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1950 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1951 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1952 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1956 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1960 for c := 0 to High(Textures) do
1962 if (Textures[c].TextureName = TexName) then
1964 SetLength(AddTextures, Length(AddTextures)+1);
1965 AddTextures[High(AddTextures)].Texture := c;
1966 AddTextures[High(AddTextures)].Anim := isAnim;
1971 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1973 SetLength(AddTextures
, Length(AddTextures
)+1);
1974 AddTextures
[High(AddTextures
)].Texture
:= c
;
1975 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1981 if k
= NNF_NAME_EQUALS
then
1983 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1984 SetLength(AddTextures
, Length(AddTextures
)+1);
1985 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1986 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1987 CurTex
:= High(AddTextures
);
1998 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1999 end; // if ok - ññûëàþòñÿ òðèããåðû
2003 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
2004 SetLength(AddTextures
, 1);
2005 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
2006 AddTextures
[0].Anim
:= false;
2007 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
2011 //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);
2013 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
2015 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
2016 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2017 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2018 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2021 moveSpeed
:= rec
.moveSpeed
;
2022 //moveStart := rec.moveStart;
2023 //moveEnd := rec.moveEnd;
2024 //moveActive := rec['move_active'].value;
2025 if not moveSpeed
.isZero
then
2027 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2028 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2029 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2032 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2034 g_Game_StepLoading();
2038 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2039 for b
:= 0 to High(TriggersTable
) do
2041 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
2042 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
2043 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
2044 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
2045 if (TriggersTable
[b
].mplatPan
<> nil) then TriggersTable
[b
].MPlatPanelIdx
:= TriggersTable
[b
].mplatPan
.userPanelId
;
2048 // create map grid, init other grids (for monsters, for example)
2049 e_WriteLog('Creating map grid', MSG_NOTIFY
);
2052 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2053 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2055 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2056 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2057 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2059 for rec
in triggers
do
2062 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
2063 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
2064 // we can have only one of those
2065 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
2066 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
2067 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
2068 else if (TriggersTable
[trignum
].MPlatPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].MPlatPanelIdx
2070 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2071 TriggersTable
[trignum
].tnum
:= trignum
;
2072 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
2076 //FIXME: use hashtable!
2077 for pan
in panByGUID
do
2079 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2081 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2083 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2085 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2089 // Çàãðóçêà ïðåäìåòîâ
2090 e_WriteLog(' Loading items...', MSG_NOTIFY
);
2091 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2093 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2094 if (items
<> nil) and not gLoadGameMode
then
2096 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
2097 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2098 for rec
in items
do CreateItem(rec
);
2101 // Çàãðóçêà îáëàñòåé
2102 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2103 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2105 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2106 if areas
<> nil then
2108 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2109 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2110 for rec
in areas
do CreateArea(rec
);
2113 // Çàãðóçêà ìîíñòðîâ
2114 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2115 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2117 gTotalMonsters
:= 0;
2119 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2120 if (monsters
<> nil) and not gLoadGameMode
then
2122 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2123 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2124 for rec
in monsters
do CreateMonster(rec
);
2127 gCurrentMap
:= mapReader
; // this will be our current map now
2128 gCurrentMapFileName
:= Res
;
2132 if gMapInfo
.SkyName
<> '' then
2134 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2135 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2136 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2138 if FileName
<> '' then
2139 FileName
:= GameDir
+'/wads/'+FileName
2142 FileName
:= g_ExtractWadName(Res
);
2145 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2146 if g_Texture_CreateWAD(BackID
, s
) then
2148 g_Game_SetupScreenSize();
2151 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2156 if gMapInfo
.MusicName
<> '' then
2158 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2159 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2160 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2162 if FileName
<> '' then
2163 FileName
:= GameDir
+'/wads/'+FileName
2166 FileName
:= g_ExtractWadName(Res
);
2169 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2170 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2173 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2176 // Îñòàëüíûå óñòàíâêè
2184 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2185 if not gLoadGameMode
then g_GFX_Init();
2187 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2188 mapTextureList
:= nil;
2193 TriggersTable
:= nil;
2196 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2197 if ok
and (not gLoadGameMode
) then
2199 gMusic
.SetByName(gMapInfo
.MusicName
);
2204 gMusic
.SetByName('');
2207 stt
:= curTimeMicro()-stt
;
2208 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2210 sfsGCEnable(); // enable releasing unused volumes
2212 e_ClearInputBuffer(); // why not?
2215 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2220 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2223 mapReader
: TDynRecord
;
2224 //Header: TMapHeaderRec_1;
2229 FillChar(Result
, SizeOf(Result
), 0);
2230 FileName
:= g_ExtractWadName(Res
);
2232 WAD
:= TWADFile
.Create();
2233 if not WAD
.ReadFile(FileName
) then
2239 //k8: it ignores path again
2240 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2249 mapReader
:= g_Map_ParseMap(Data
, Len
);
2258 if (mapReader
= nil) then exit
;
2260 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2262 Result
.Name
:= mapReader
.MapName
;
2263 Result
.Description
:= mapReader
.MapDesc
;
2265 Result
.Author
:= mapReader
.MapAuthor
;
2266 Result
.Height
:= mapReader
.Height
;
2267 Result
.Width
:= mapReader
.Width
;
2271 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2272 //ZeroMemory(@Header, SizeOf(Header));
2273 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2274 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2276 Result
.Author
:= '';
2284 function g_Map_GetMapsList(WADName
: string): SArray
;
2291 WAD
:= TWADFile
.Create();
2292 if not WAD
.ReadFile(WADName
) then
2297 ResList
:= WAD
.GetMapResources();
2298 if ResList
<> nil then
2300 for a
:= 0 to High(ResList
) do
2302 SetLength(Result
, Length(Result
)+1);
2303 Result
[High(Result
)] := ResList
[a
];
2309 function g_Map_Exist(Res
: string): Boolean;
2312 FileName
, mnn
: string;
2318 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2320 WAD
:= TWADFile
.Create
;
2321 if not WAD
.ReadFile(FileName
) then
2327 ResList
:= WAD
.GetMapResources();
2330 mnn
:= g_ExtractFileName(Res
);
2331 if ResList
<> nil then
2332 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2339 procedure g_Map_Free(freeTextures
: Boolean=true);
2343 procedure FreePanelArray(var panels
: TPanelArray
);
2348 if panels
<> nil then
2350 for i
:= 0 to High(panels
) do
2363 RespawnPoints
:= nil;
2364 if FlagPoints
[FLAG_RED
] <> nil then
2366 Dispose(FlagPoints
[FLAG_RED
]);
2367 FlagPoints
[FLAG_RED
] := nil;
2369 if FlagPoints
[FLAG_BLUE
] <> nil then
2371 Dispose(FlagPoints
[FLAG_BLUE
]);
2372 FlagPoints
[FLAG_BLUE
] := nil;
2374 //DOMFlagPoints := nil;
2378 if (Length(gCurrentMapFileName
) <> 0) then
2380 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2384 e_LogWritefln('g_Map_Free: no previous map.', []);
2386 if freeTextures
then
2388 e_LogWritefln('g_Map_Free: clearing textures...', []);
2389 if (Textures
<> nil) then
2391 for a
:= 0 to High(Textures
) do
2393 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2395 if Textures
[a
].Anim
then
2397 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2401 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2403 e_DeleteTexture(Textures
[a
].TextureID
);
2410 TextNameHash
.Free();
2411 TextNameHash
:= nil;
2412 BadTextNameHash
.Free();
2413 BadTextNameHash
:= nil;
2418 FreePanelArray(gWalls
);
2419 FreePanelArray(gRenderBackgrounds
);
2420 FreePanelArray(gRenderForegrounds
);
2421 FreePanelArray(gWater
);
2422 FreePanelArray(gAcid1
);
2423 FreePanelArray(gAcid2
);
2424 FreePanelArray(gSteps
);
2425 FreePanelArray(gLifts
);
2426 FreePanelArray(gBlockMon
);
2427 gMovingWallIds
:= nil;
2429 if BackID
<> DWORD(-1) then
2433 e_DeleteTexture(BackID
);
2434 BackID
:= DWORD(-1);
2437 g_Game_StopAllSounds(False);
2439 g_Sound_Delete(gMapInfo
.MusicName
);
2441 gMapInfo
.Name
:= '';
2442 gMapInfo
.Description
:= '';
2443 gMapInfo
.MusicName
:= '';
2444 gMapInfo
.Height
:= 0;
2445 gMapInfo
.Width
:= 0;
2451 procedure g_Map_Update();
2457 procedure UpdatePanelArray(var panels
: TPanelArray
);
2462 for i
:= 0 to High(panels
) do panels
[i
].Update();
2466 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2468 UpdatePanelArray(gWalls
);
2469 UpdatePanelArray(gRenderBackgrounds
);
2470 UpdatePanelArray(gRenderForegrounds
);
2471 UpdatePanelArray(gWater
);
2472 UpdatePanelArray(gAcid1
);
2473 UpdatePanelArray(gAcid2
);
2474 UpdatePanelArray(gSteps
);
2476 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2478 if gGameSettings
.GameMode
= GM_CTF
then
2480 for a
:= FLAG_RED
to FLAG_BLUE
do
2482 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2486 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2488 m
:= g_Obj_Move(@Obj
, True, True);
2490 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2492 // Ñîïðîòèâëåíèå âîçäóõà
2493 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2495 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2496 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2499 gFlags
[a
].CaptureTime
:= 0;
2500 if a
= FLAG_RED
then
2501 s
:= _lc
[I_PLAYER_FLAG_RED
]
2503 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2504 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2506 if g_Game_IsNet
then
2507 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2511 if Count
> 0 then Count
-= 1;
2514 if gPlayers
<> nil then
2516 j
:= Random(Length(gPlayers
)) - 1;
2517 for d
:= 0 to High(gPlayers
) do
2520 if j
> High(gPlayers
) then j
:= 0;
2521 if gPlayers
[j
] <> nil then
2523 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2525 if gPlayers
[j
].GetFlag(a
) then Break
;
2538 procedure g_Map_DrawPanels (PanelType
: Word);
2540 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2544 if (panels
<> nil) then
2546 // alas, no visible set
2547 for idx
:= 0 to High(panels
) do
2549 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2556 PANEL_WALL
: DrawPanels(gWalls
);
2557 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2558 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2559 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2560 PANEL_WATER
: DrawPanels(gWater
);
2561 PANEL_ACID1
: DrawPanels(gAcid1
);
2562 PANEL_ACID2
: DrawPanels(gAcid2
);
2563 PANEL_STEP
: DrawPanels(gSteps
);
2569 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2571 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2573 result
:= false; // don't stop, ever
2574 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2575 gDrawPanelList
.insert(pan
);
2580 //tagmask := panelTypeToTag(PanelType);
2581 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2582 // list will be rendered in `g_game.DrawPlayer()`
2586 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2588 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2590 result
:= false; // don't stop, ever
2591 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2595 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2599 procedure g_Map_DrawBack(dx
, dy
: Integer);
2601 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2602 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2604 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2607 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2608 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2614 if WordBool(PanelType
and PANEL_WALL
) then
2615 if gWalls
<> nil then
2620 if gWalls
[a
].Enabled
and
2621 g_Collide(X
, Y
, Width
, Height
,
2622 gWalls
[a
].X
, gWalls
[a
].Y
,
2623 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2630 if WordBool(PanelType
and PANEL_WATER
) then
2631 if gWater
<> nil then
2636 if g_Collide(X
, Y
, Width
, Height
,
2637 gWater
[a
].X
, gWater
[a
].Y
,
2638 gWater
[a
].Width
, gWater
[a
].Height
) then
2645 if WordBool(PanelType
and PANEL_ACID1
) then
2646 if gAcid1
<> nil then
2651 if g_Collide(X
, Y
, Width
, Height
,
2652 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2653 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2660 if WordBool(PanelType
and PANEL_ACID2
) then
2661 if gAcid2
<> nil then
2666 if g_Collide(X
, Y
, Width
, Height
,
2667 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2668 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2675 if WordBool(PanelType
and PANEL_STEP
) then
2676 if gSteps
<> nil then
2681 if g_Collide(X
, Y
, Width
, Height
,
2682 gSteps
[a
].X
, gSteps
[a
].Y
,
2683 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2690 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2691 if gLifts
<> nil then
2696 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2697 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2698 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2699 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2700 g_Collide(X
, Y
, Width
, Height
,
2701 gLifts
[a
].X
, gLifts
[a
].Y
,
2702 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2709 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2710 if gBlockMon
<> nil then
2712 h
:= High(gBlockMon
);
2716 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2717 g_Collide(X
, Y
, Width
, Height
,
2718 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2719 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2727 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2731 function checkPanels (constref panels
: TPanelArray
): Boolean;
2736 if panels
= nil then exit
;
2737 for a
:= 0 to High(panels
) do
2739 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2742 texid
:= panels
[a
].GetTextureID();
2749 texid
:= LongWord(TEXTURE_NONE
);
2751 if not checkPanels(gWater
) then
2752 if not checkPanels(gAcid1
) then
2753 if not checkPanels(gAcid2
) then exit
;
2758 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2760 SlowMask
= GridTagLift
or GridTagBlockMon
;
2761 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2764 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2766 result := pan.Enabled;
2771 if ((tag
and GridTagLift
) <> 0) then
2774 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2775 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2776 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2777 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2778 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2782 if ((tag
and GridTagBlockMon
) <> 0) then
2784 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2789 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2790 result
:= true; // i found her!
2794 tagmask
: Integer = 0;
2796 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2797 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2798 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2799 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2800 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2801 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2802 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2804 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2806 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2807 if gdbg_map_use_accel_coldet
then
2809 if (Width
= 1) and (Height
= 1) then
2811 if ((tagmask
and SlowMask
) <> 0) then
2814 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2819 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2824 if ((tagmask
and SlowMask
) <> 0) then
2827 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2832 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2838 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2840 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2844 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2846 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2849 // slightly different from the old code, but meh...
2850 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2852 result
:= false; // don't stop, ever
2853 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2856 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2857 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2858 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2861 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2863 texid
:= pan
.GetTextureID();
2864 // water? water has the highest priority, so stop right here
2865 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2867 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2869 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2873 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2874 if gdbg_map_use_accel_coldet
then
2876 texid
:= LongWord(TEXTURE_NONE
);
2877 if (Width
= 1) and (Height
= 1) then
2879 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2883 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2889 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2891 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2895 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2896 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2897 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2900 procedure g_Map_EnableWallGUID (pguid
: Integer);
2904 //pan := gWalls[ID];
2905 pan
:= g_Map_PanelByGUID(pguid
);
2906 if (pan
= nil) then exit
;
2907 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
2909 pan
.Enabled
:= True;
2910 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2912 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2913 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2914 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2916 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2917 // mark platform as interesting
2920 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2921 //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);
2926 procedure g_Map_DisableWallGUID (pguid
: Integer);
2930 //pan := gWalls[ID];
2931 pan
:= g_Map_PanelByGUID(pguid
);
2932 if (pan
= nil) then exit
;
2933 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
2935 pan
.Enabled
:= False;
2936 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2938 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2939 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2941 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2942 // mark platform as interesting
2945 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2946 //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);
2951 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
2955 tp
:= g_Map_PanelByGUID(pguid
);
2956 if (tp
= nil) then exit
;
2959 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: tp := gWalls[ID];
2960 PANEL_FORE: tp := gRenderForegrounds[ID];
2961 PANEL_BACK: tp := gRenderBackgrounds[ID];
2962 PANEL_WATER: tp := gWater[ID];
2963 PANEL_ACID1: tp := gAcid1[ID];
2964 PANEL_ACID2: tp := gAcid2[ID];
2965 PANEL_STEP: tp := gSteps[ID];
2970 tp
.NextTexture(AnimLoop
);
2971 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
2975 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2979 //pan := gLifts[ID];
2980 pan
:= g_Map_PanelByGUID(pguid
);
2981 if (pan
= nil) then exit
;
2982 if not pan
.isGLift
then exit
;
2984 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2986 with {gLifts[ID]} pan
do
2990 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2991 //TODO: make separate lift tags, and change tag here
2994 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2995 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2996 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2997 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
3000 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
3001 // mark platform as interesting
3007 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
3010 PointsArray
: Array of TRespawnPoint
;
3013 SetLength(PointsArray
, 0);
3015 if RespawnPoints
= nil then
3018 for a
:= 0 to High(RespawnPoints
) do
3019 if RespawnPoints
[a
].PointType
= PointType
then
3021 SetLength(PointsArray
, Length(PointsArray
)+1);
3022 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
3025 if PointsArray
= nil then
3028 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3032 function g_Map_GetPointCount(PointType
: Byte): Word;
3038 if RespawnPoints
= nil then
3041 for a
:= 0 to High(RespawnPoints
) do
3042 if RespawnPoints
[a
].PointType
= PointType
then
3043 Result
:= Result
+ 1;
3046 function g_Map_HaveFlagPoints(): Boolean;
3048 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3051 procedure g_Map_ResetFlag(Flag
: Byte);
3053 with gFlags
[Flag
] do
3059 Direction
:= D_LEFT
;
3060 State
:= FLAG_STATE_NONE
;
3061 if FlagPoints
[Flag
] <> nil then
3063 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3064 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3065 Direction
:= FlagPoints
[Flag
]^.Direction
;
3066 State
:= FLAG_STATE_NORMAL
;
3072 procedure g_Map_DrawFlags();
3075 Mirror
: TMirrorType
;
3077 if gGameSettings
.GameMode
<> GM_CTF
then
3080 for i
:= FLAG_RED
to FLAG_BLUE
do
3082 if State
<> FLAG_STATE_CAPTURED
then
3084 if State
= FLAG_STATE_NONE
then
3087 if Direction
= D_LEFT
then
3089 Mirror
:= M_HORIZONTAL
;
3098 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3100 if g_debug_Frames
then
3102 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3104 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3105 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3112 procedure g_Map_SaveState (var Mem
: TBinMemoryWriter
);
3119 procedure savePanels ();
3121 PAMem
: TBinMemoryWriter
;
3125 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé
3126 PAMem
:= TBinMemoryWriter
.Create((Length(panByGUID
)+1) * 40);
3129 count
:= Length(panByGUID
);
3130 Mem
.WriteInt(count
);
3131 for pan
in panByGUID
do pan
.SaveState(PAMem
);
3133 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé
3134 PAMem
.SaveToMemory(Mem
);
3138 procedure SaveFlag (flag
: PFlag
);
3141 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3143 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3144 Mem
.WriteByte(flag
^.RespawnType
);
3146 Mem
.WriteByte(flag
^.State
);
3147 // Íàïðàâëåíèå ôëàãà
3148 if flag
^.Direction
= D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3151 Obj_SaveState(@flag
^.Obj
, Mem
);
3155 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3157 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3161 ///// Ñîõðàíÿåì ìóçûêó: /////
3162 // Ñèãíàòóðà ìóçûêè:
3163 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3166 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3167 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3168 Mem
.WriteString(str
, 64);
3169 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3170 dw
:= gMusic
.GetPosition();
3172 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3173 boo
:= gMusic
.SpecPause
;
3174 Mem
.WriteBoolean(boo
);
3177 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3178 Mem
.WriteInt(gTotalMonsters
);
3181 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3182 if gGameSettings
.GameMode
= GM_CTF
then
3184 // Ôëàã Êðàñíîé êîìàíäû
3185 SaveFlag(@gFlags
[FLAG_RED
]);
3186 // Ôëàã Ñèíåé êîìàíäû
3187 SaveFlag(@gFlags
[FLAG_BLUE
]);
3191 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3192 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3194 // Î÷êè Êðàñíîé êîìàíäû
3195 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3196 // Î÷êè Ñèíåé êîìàíäû
3197 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3203 procedure g_Map_LoadState (var Mem
: TBinMemoryReader
);
3210 procedure loadPanels ();
3212 PAMem
: TBinMemoryReader
;
3216 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé
3217 PAMem
:= TBinMemoryReader
.Create();
3218 PAMem
.LoadFromMemory(Mem
);
3221 PAMem
.ReadInt(count
);
3222 if (count
<> Length(panByGUID
)) then raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: invalid number of panels');
3223 for pan
in panByGUID
do
3225 pan
.LoadState(PAMem
);
3226 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3229 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí
3233 procedure LoadFlag(flag
: PFlag
);
3238 if dw
<> FLAG_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3239 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3240 Mem
.ReadByte(flag
^.RespawnType
);
3242 Mem
.ReadByte(flag
^.State
);
3243 // Íàïðàâëåíèå ôëàãà
3245 if b
= 1 then flag
^.Direction
:= D_LEFT
else flag
^.Direction
:= D_RIGHT
; // b = 2
3247 Obj_LoadState(@flag
^.Obj
, Mem
);
3251 if Mem
= nil then Exit
;
3253 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3257 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3261 ///// Çàãðóæàåì ìóçûêó: /////
3265 if dw
<> MUSIC_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3267 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3268 Mem
.ReadString(str
);
3269 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3271 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3272 Mem
.ReadBoolean(boo
);
3273 // Çàïóñêàåì ýòó ìóçûêó
3274 gMusic
.SetByName(str
);
3275 gMusic
.SpecPause
:= boo
;
3278 gMusic
.SetPosition(dw
);
3281 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3282 Mem
.ReadInt(gTotalMonsters
);
3285 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3286 if gGameSettings
.GameMode
= GM_CTF
then
3288 // Ôëàã Êðàñíîé êîìàíäû
3289 LoadFlag(@gFlags
[FLAG_RED
]);
3290 // Ôëàã Ñèíåé êîìàíäû
3291 LoadFlag(@gFlags
[FLAG_BLUE
]);
3295 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3296 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3298 // Î÷êè Êðàñíîé êîìàíäû
3299 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3300 // Î÷êè Ñèíåé êîìàíäû
3301 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3307 // trace liquid, stepping by `dx` and `dy`
3308 // return last seen liquid coords, and `false` if we're started outside of the liquid
3309 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3311 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3315 // started outside of the liquid?
3316 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3317 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3323 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit