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
, MAPSTRUCT
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, z_aabbtree
, md5
, binheap
, xprofiler
;
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();
64 procedure g_Map_Update();
66 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
67 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
69 procedure g_Map_DrawBack(dx
, dy
: Integer);
70 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
71 PanelType
: Word; b1x3
: Boolean=false): Boolean;
72 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
73 procedure g_Map_EnableWall(ID
: DWORD
);
74 procedure g_Map_DisableWall(ID
: DWORD
);
75 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
76 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
77 procedure g_Map_ReAdd_DieTriggers();
78 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
80 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
81 function g_Map_GetPointCount(PointType
: Byte): Word;
83 function g_Map_HaveFlagPoints(): Boolean;
85 procedure g_Map_ResetFlag(Flag
: Byte);
86 procedure g_Map_DrawFlags();
88 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
90 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
91 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
93 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
95 // returns wall index in `gWalls` or -1
96 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Boolean;
99 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
101 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
103 // trace liquid, stepping by `dx` and `dy`
104 // return last seen liquid coords, and `false` if we're started outside of the liquid
105 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
108 procedure g_Map_ProfilersBegin ();
109 procedure g_Map_ProfilersEnd ();
113 RESPAWNPOINT_PLAYER1
= 1;
114 RESPAWNPOINT_PLAYER2
= 2;
116 RESPAWNPOINT_RED
= 4;
117 RESPAWNPOINT_BLUE
= 5;
125 FLAG_STATE_NORMAL
= 1;
126 FLAG_STATE_DROPPED
= 2;
127 FLAG_STATE_CAPTURED
= 3;
128 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
129 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
131 FLAG_TIME
= 720; // 20 seconds
133 SKY_STRETCH
: Single = 1.5;
148 // sorted by draw priority
149 GridTagBack
= 1 shl 0;
150 GridTagStep
= 1 shl 1;
151 GridTagWall
= 1 shl 2;
152 GridTagDoor
= 1 shl 3;
153 GridTagAcid1
= 1 shl 4;
154 GridTagAcid2
= 1 shl 5;
155 GridTagWater
= 1 shl 6;
156 GridTagFore
= 1 shl 7;
157 // the following are invisible
158 GridTagLift
= 1 shl 8;
159 GridTagBlockMon
= 1 shl 9;
161 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
166 gRenderBackgrounds
: TPanelArray
;
167 gRenderForegrounds
: TPanelArray
;
168 gWater
, gAcid1
, gAcid2
: TPanelArray
;
171 gBlockMon
: TPanelArray
;
172 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
173 //gDOMFlags: array of TFlag;
176 gDoorMap
: array of array of DWORD
;
177 gLiftMap
: array of array of DWORD
;
178 gWADHash
: TMD5Digest
;
179 BackID
: DWORD
= DWORD(-1);
180 gExternalResources
: TStringList
;
182 gdbg_map_use_accel_render
: Boolean = true;
183 gdbg_map_use_accel_coldet
: Boolean = true;
184 //gdbg_map_use_tree_draw: Boolean = false;
185 //gdbg_map_use_tree_coldet: Boolean = false;
186 //gdbg_map_dump_coldet_tree_queries: Boolean = false;
187 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
188 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
190 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
196 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
197 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
198 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
199 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
201 ImagingTypes
, Imaging
, ImagingUtility
,
202 ImagingGif
, ImagingNetworkGraphics
;
205 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
206 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
207 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
211 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
214 TDynAABBTreePanelBase = specialize TDynAABBTreeBase<TPanel>;
216 TDynAABBTreeMap = class(TDynAABBTreePanelBase)
217 function getFleshAABB (out aabb: AABB2D; pan: TPanel; tag: Integer): Boolean; override;
222 function TDynAABBTreeMap.getFleshAABB (out aabb: AABB2D; pan: TPanel; tag: Integer): Boolean;
225 if (pan = nil) then begin aabb := AABB2D.Create(0, 0, 0, 0); exit; end;
226 aabb := AABB2D.Create(pan.X, pan.Y, pan.X+pan.Width-1, pan.Y+pan.Height-1);
227 if (pan.Width < 1) or (pan.Height < 1) then exit;
228 if not aabb.valid then raise Exception.Create('wutafuuuuuuu?!');
234 function panelTypeToTag (panelType
: Word): Integer;
237 PANEL_WALL
: result
:= GridTagWall
; // gWalls
238 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
239 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
240 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
241 PANEL_WATER
: result
:= GridTagWater
; // gWater
242 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
243 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
244 PANEL_STEP
: result
:= GridTagStep
; // gSteps
245 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
246 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
247 else result
:= GridTagInvalid
;
252 function dplLess (a
, b
: TObject
): Boolean;
258 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
259 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
260 result
:= (pa
.arrIdx
< pb
.arrIdx
);
263 procedure dplClear ();
265 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
271 PWhere
: ^TPanelArray
;
276 PanelById
: array of TPanelID
;
277 Textures
: TLevelTextureArray
;
278 RespawnPoints
: Array of TRespawnPoint
;
279 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
280 //DOMFlagPoints: Array of TFlagPoint;
281 mapGrid
: TPanelGrid
= nil;
282 //mapTree: TDynAABBTreeMap = nil;
285 procedure g_Map_ProfilersBegin ();
287 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
288 profMapCollision
.mainBegin(g_profile_collision
);
290 if g_profile_collision
then
292 profMapCollision
.sectionBegin('*solids');
293 profMapCollision
.sectionEnd();
294 profMapCollision
.sectionBegin('liquids');
295 profMapCollision
.sectionEnd();
299 procedure g_Map_ProfilersEnd ();
301 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
305 // wall index in `gWalls` or -1
307 function g_Map_traceToNearestWallOld (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): Integer;
309 function sqchecker (pan: TPanel; var ray: Ray2D): Single;
314 result := -666.0; // invalid
315 if not pan.Enabled then exit;
316 aabb := AABB2D.CreateWH(pan.X, pan.Y, pan.Width, pan.Height);
317 if not aabb.valid then exit;
318 if aabb.intersects(ray, @tmin) then
320 //if (tmin*tmin > maxDistSq) then exit;
321 if (tmin >= 0.0) then
323 //e_WriteLog(Format('sqchecker(%d,%d,%d,%d): panel #%d (%d,%d)-(%d,%d); tmin=%f', [x0, y0, x1, y1, pan.arrIdx, pan.X, pan.Y, pan.Width, pan.Height, tmin]), MSG_NOTIFY);
324 //if (tmin < 0.0) then tmin := 0.0;
331 qr: TDynAABBTreeMap.TSegmentQueryResult;
338 if (mapTree = nil) then exit;
339 if mapTree.segmentQuery(qr, x0, y0, x1, y1, sqchecker, (GridTagWall or GridTagDoor)) then
341 maxDistSq := (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
342 if (qr.flesh <> nil) and (qr.time*qr.time <= maxDistSq) then
344 result := qr.flesh.arrIdx;
345 if (hitx <> nil) or (hity <> nil) then
347 ray := Ray2D.Create(x0, y0, x1, y1);
348 hxf := ray.origX+ray.dirX*qr.time;
349 hyf := ray.origY+ray.dirY*qr.time;
354 if (hx >= qr.flesh.X) and (hy >= qr.flesh.Y) and (hx < qr.flesh.X+qr.flesh.Width) and (hy < qr.flesh.Y+qr.flesh.Height) then
365 if (hitx <> nil) then hitx^ := hx;
366 if (hity <> nil) then hity^ := hy;
374 // wall index in `gWalls` or -1
375 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Boolean;
378 lastX, lastY, lastDistSq: Integer;
379 wasHit: Boolean = false;
381 // pan=nil: before processing new tile
382 function sqchecker (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
388 // stop if something was hit at the previous tile
394 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
396 if not pan.Enabled then exit;
398 distSq := (prevx-x0)*(prevx-x0)+(prevy-y0)*(prevy-y0);
399 if (distSq < lastDistSq) then
402 lastDistSq := distSq;
414 if (mapGrid = nil) then exit;
415 lastDistSq := (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+1;
418 result := mapGrid.traceRay(x0, y0, x1, y1, sqchecker, (GridTagWall or GridTagDoor));
419 if (hitx <> nil) then hitx^ := lastX;
420 if (hity <> nil) then hity^ := lastY;
422 result
:= (mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
)) <> nil);
426 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
428 function checker (pan
: TPanel
; tag
: Integer): Boolean;
431 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
433 result := pan.Enabled; // stop if wall is enabled
438 if ((tag
and GridTagLift
) <> 0) then
440 // stop if the lift of the right type
442 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
443 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
444 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
445 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
449 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
453 tagmask
: Integer = 0;
457 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
458 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
459 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
460 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
461 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
462 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
463 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
465 if (tagmask
= 0) then exit
;// just in case
466 if ((tagmask
and GridTagLift
) <> 0) then
469 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
474 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
479 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
481 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
482 (Texture
= TEXTURE_NAME_ACID1
) or
483 (Texture
= TEXTURE_NAME_ACID2
);
486 procedure CreateDoorMap();
488 PanelArray
: Array of record
494 a
, b
, c
, m
, i
, len
: Integer;
502 SetLength(PanelArray
, len
);
504 for a
:= 0 to High(gWalls
) do
505 if gWalls
[a
].Door
then
507 PanelArray
[i
].X
:= gWalls
[a
].X
;
508 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
509 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
510 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
511 PanelArray
[i
].Active
:= True;
512 PanelArray
[i
].PanelID
:= a
;
518 SetLength(PanelArray
, len
);
529 SetLength(gDoorMap
, 0);
531 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
534 if PanelArray
[a
].Active
then
536 PanelArray
[a
].Active
:= False;
537 m
:= Length(gDoorMap
);
538 SetLength(gDoorMap
, m
+1);
539 SetLength(gDoorMap
[m
], 1);
540 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
548 if PanelArray
[b
].Active
then
549 for c
:= 0 to High(gDoorMap
[m
]) do
550 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
551 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
552 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
553 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
554 gWalls
[gDoorMap
[m
, c
]].X
,
555 gWalls
[gDoorMap
[m
, c
]].Y
,
556 gWalls
[gDoorMap
[m
, c
]].Width
,
557 gWalls
[gDoorMap
[m
, c
]].Height
) then
559 PanelArray
[b
].Active
:= False;
560 SetLength(gDoorMap
[m
],
561 Length(gDoorMap
[m
])+1);
562 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
568 g_Game_StepLoading();
574 procedure CreateLiftMap();
576 PanelArray
: Array of record
581 a
, b
, c
, len
, i
, j
: Integer;
587 len
:= Length(gLifts
);
588 SetLength(PanelArray
, len
);
590 for a
:= 0 to len
-1 do
592 PanelArray
[a
].X
:= gLifts
[a
].X
;
593 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
594 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
595 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
596 PanelArray
[a
].Active
:= True;
599 SetLength(gLiftMap
, len
);
602 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
604 for a
:= 0 to len
-1 do
605 if PanelArray
[a
].Active
then
607 PanelArray
[a
].Active
:= False;
608 SetLength(gLiftMap
[i
], 32);
616 for b
:= 0 to len
-1 do
617 if PanelArray
[b
].Active
then
619 if g_CollideAround(PanelArray
[b
].X
,
622 PanelArray
[b
].Height
,
623 PanelArray
[gLiftMap
[i
, c
]].X
,
624 PanelArray
[gLiftMap
[i
, c
]].Y
,
625 PanelArray
[gLiftMap
[i
, c
]].Width
,
626 PanelArray
[gLiftMap
[i
, c
]].Height
) then
628 PanelArray
[b
].Active
:= False;
630 if j
> High(gLiftMap
[i
]) then
631 SetLength(gLiftMap
[i
],
632 Length(gLiftMap
[i
])+32);
641 SetLength(gLiftMap
[i
], j
+1);
644 g_Game_StepLoading();
647 SetLength(gLiftMap
, i
);
652 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
653 CurTex
: Integer; sav
: Boolean): Integer;
656 panels
: ^TPanelArray
;
660 case PanelRec
.PanelType
of
661 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
664 panels
:= @gRenderBackgrounds
;
666 panels
:= @gRenderForegrounds
;
675 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
678 panels
:= @gBlockMon
;
683 len
:= Length(panels
^);
684 SetLength(panels
^, len
+ 1);
686 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
687 panels
^[len
].arrIdx
:= len
;
688 panels
^[len
].proxyId
:= -1;
689 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
691 panels
^[len
].SaveIt
:= True;
695 len
:= Length(PanelByID
);
696 SetLength(PanelByID
, len
+ 1);
697 PanelByID
[len
].PWhere
:= panels
;
698 PanelByID
[len
].PArrID
:= Result
;
701 function CreateNullTexture(RecName
: String): Integer;
703 SetLength(Textures
, Length(Textures
)+1);
704 result
:= High(Textures
);
706 with Textures
[High(Textures
)] do
708 TextureName
:= RecName
;
712 TextureID
:= TEXTURE_NONE
;
716 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
719 TextureData
: Pointer;
720 WADName
, txname
: String;
721 a
, ResLength
: Integer;
725 if Textures
<> nil then
726 for a
:= 0 to High(Textures
) do
727 if Textures
[a
].TextureName
= RecName
then
728 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
733 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
734 if (RecName
= TEXTURE_NAME_WATER
) or
735 (RecName
= TEXTURE_NAME_ACID1
) or
736 (RecName
= TEXTURE_NAME_ACID2
) then
738 SetLength(Textures
, Length(Textures
)+1);
740 with Textures
[High(Textures
)] do
742 TextureName
:= RecName
;
744 if TextureName
= TEXTURE_NAME_WATER
then
745 TextureID
:= TEXTURE_SPECIAL_WATER
747 if TextureName
= TEXTURE_NAME_ACID1
then
748 TextureID
:= TEXTURE_SPECIAL_ACID1
750 if TextureName
= TEXTURE_NAME_ACID2
then
751 TextureID
:= TEXTURE_SPECIAL_ACID2
;
756 result
:= High(Textures
);
760 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
761 WADName
:= g_ExtractWadName(RecName
);
763 WAD
:= TWADFile
.Create();
765 if WADName
<> '' then
766 WADName
:= GameDir
+'/wads/'+WADName
770 WAD
.ReadFile(WADName
);
774 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
776 FreeMem(TextureData);
777 RecName := 'COMMON\ALIEN';
781 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
783 SetLength(Textures
, Length(Textures
)+1);
784 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
786 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
787 @Textures
[High(Textures
)].Width
,
788 @Textures
[High(Textures
)].Height
);
789 FreeMem(TextureData
);
790 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
791 Textures
[High(Textures
)].Anim
:= False;
793 result
:= High(Textures
);
795 else // Íåò òàêîãî ðåóñðñà â WAD'å
797 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
800 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
801 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
808 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
811 TextureWAD
: PChar = nil;
812 TextData
: Pointer = nil;
813 TextureData
: Pointer = nil;
817 TextureResource
: String;
818 _width
, _height
, _framecount
, _speed
: Integer;
819 _backanimation
: Boolean;
821 ia
: TDynImageDataArray
= nil;
822 f
, c
, frdelay
, frloop
: Integer;
826 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
828 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
829 WADName
:= g_ExtractWadName(RecName
);
831 WAD
:= TWADFile
.Create();
833 if WADName
<> '' then
834 WADName
:= GameDir
+'/wads/'+WADName
838 WAD
.ReadFile(WADName
);
840 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
844 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
845 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
851 if WADName = Map then
853 //FreeMem(TextureWAD);
854 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
860 if ResLength
< 6 then
862 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
866 // ýòî ïòèöà? ýòî ñàìîë¸ò?
867 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
868 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
870 // íåò, ýòî ñóïåðìåí!
871 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
873 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
877 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
878 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
880 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
884 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
886 TextureResource
:= cfg
.ReadStr('', 'resource', '');
887 if TextureResource
= '' then
889 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
893 _width
:= cfg
.ReadInt('', 'framewidth', 0);
894 _height
:= cfg
.ReadInt('', 'frameheight', 0);
895 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
896 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
897 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
902 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
903 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
905 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
912 SetLength(Textures
, Length(Textures
)+1);
913 with Textures
[High(Textures
)] do
915 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
916 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
918 TextureName
:= RecName
;
922 FramesCount
:= _framecount
;
924 result
:= High(Textures
);
928 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
934 // try animated image
936 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
937 if length(imgfmt) = 0 then
939 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
943 GlobalMetadata
.ClearMetaItems();
944 GlobalMetadata
.ClearMetaItemsForSaving();
945 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
947 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
950 if length(ia
) = 0 then
952 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
959 _width
:= ia
[0].width
;
960 _height
:= ia
[0].height
;
961 _framecount
:= length(ia
);
963 _backanimation
:= false;
966 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
968 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
970 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
972 if f
< 0 then f
:= 0;
975 if c
< 13 then c
:= 0 else c
:= 1;
977 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
982 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
984 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
986 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
988 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
992 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
993 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
994 f
:= ord(_backanimation
);
995 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
);
997 SetLength(Textures
, Length(Textures
)+1);
998 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
999 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1001 Textures
[High(Textures
)].TextureName
:= RecName
;
1002 Textures
[High(Textures
)].Width
:= _width
;
1003 Textures
[High(Textures
)].Height
:= _height
;
1004 Textures
[High(Textures
)].Anim
:= True;
1005 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1006 Textures
[High(Textures
)].Speed
:= _speed
;
1007 result
:= High(Textures
);
1008 //writeln(' CREATED!');
1012 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1016 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1019 if TextureWAD
<> nil then FreeMem(TextureWAD
);
1020 if TextData
<> nil then FreeMem(TextData
);
1021 if TextureData
<> nil then FreeMem(TextureData
);
1025 procedure CreateItem(Item
: TItemRec_1
);
1027 if g_Game_IsClient
then Exit
;
1029 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1030 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1033 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1034 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1037 procedure CreateArea(Area
: TAreaRec_1
);
1042 case Area
.AreaType
of
1043 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1044 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1046 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1047 with RespawnPoints
[High(RespawnPoints
)] do
1051 Direction
:= TDirection(Area
.Direction
);
1053 case Area
.AreaType
of
1054 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1055 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1056 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1057 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1058 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1063 AREA_REDFLAG
, AREA_BLUEFLAG
:
1065 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1067 if FlagPoints
[a
] <> nil then Exit
;
1071 with FlagPoints
[a
]^ do
1073 X
:= Area
.X
-FLAGRECT
.X
;
1074 Y
:= Area
.Y
-FLAGRECT
.Y
;
1075 Direction
:= TDirection(Area
.Direction
);
1081 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1082 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1085 Animation
:= TAnimation
.Create(id
, True, 8);
1086 Obj
.Rect
:= FLAGRECT
;
1094 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1095 with DOMFlagPoints[High(DOMFlagPoints)] do
1099 Direction := TDirection(Area.Direction);
1102 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1107 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1111 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1117 Width
:= Trigger
.Width
;
1118 Height
:= Trigger
.Height
;
1119 Enabled
:= ByteBool(Trigger
.Enabled
);
1120 TexturePanel
:= Trigger
.TexturePanel
;
1121 TexturePanelType
:= fTexturePanel1Type
;
1122 ShotPanelType
:= fTexturePanel2Type
;
1123 TriggerType
:= Trigger
.TriggerType
;
1124 ActivateType
:= Trigger
.ActivateType
;
1125 Keys
:= Trigger
.Keys
;
1126 Data
.Default
:= Trigger
.DATA
;
1129 g_Triggers_Create(_trigger
);
1132 procedure CreateMonster(monster
: TMonsterRec_1
);
1137 if g_Game_IsClient
then Exit
;
1139 if (gGameSettings
.GameType
= GT_SINGLE
)
1140 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1142 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1144 if gTriggers
<> nil then
1146 for a
:= 0 to High(gTriggers
) do
1148 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1150 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1155 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1159 procedure g_Map_ReAdd_DieTriggers();
1161 function monsDieTrig (mon
: TMonster
): Boolean;
1165 result
:= false; // don't stop
1166 mon
.ClearTriggers();
1167 for a
:= 0 to High(gTriggers
) do
1169 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1171 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1177 if g_Game_IsClient
then Exit
;
1179 g_Mons_ForEach(monsDieTrig
);
1182 function extractWadName(resourceName
: string): string;
1186 posN
:= Pos(':', resourceName
);
1188 Result
:= Copy(resourceName
, 0, posN
-1)
1193 procedure addResToExternalResList(res
: string);
1195 res
:= extractWadName(res
);
1196 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1197 gExternalResources
.Add(res
);
1200 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1202 textures
: TTexturesRec1Array
;
1203 mapHeader
: TMapHeaderRec_1
;
1205 resFile
: String = '';
1207 if gExternalResources
= nil then
1208 gExternalResources
:= TStringList
.Create
;
1210 gExternalResources
.Clear
;
1211 textures
:= mapReader
.GetTextures();
1212 for i
:= 0 to High(textures
) do
1214 addResToExternalResList(resFile
);
1219 mapHeader
:= mapReader
.GetMapHeader
;
1221 addResToExternalResList(mapHeader
.MusicName
);
1222 addResToExternalResList(mapHeader
.SkyName
);
1225 procedure mapCreateGrid ();
1227 mapX0
: Integer = $3fffffff;
1228 mapY0
: Integer = $3fffffff;
1229 mapX1
: Integer = -$3fffffff;
1230 mapY1
: Integer = -$3fffffff;
1232 procedure calcBoundingBox (constref panels
: TPanelArray
);
1237 for idx
:= 0 to High(panels
) do
1240 if not pan
.visvalid
then continue
;
1241 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1242 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1243 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1244 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1245 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1249 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1254 tag
:= panelTypeToTag(tag
);
1255 for idx
:= High(panels
) downto 0 do
1259 if not pan
.visvalid
then continue
;
1260 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1261 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1262 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1263 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1264 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
1266 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
])]), MSG_NOTIFY
);
1269 //mapTree.insertObject(pan, tag, true); // as static object
1279 calcBoundingBox(gWalls
);
1280 calcBoundingBox(gRenderBackgrounds
);
1281 calcBoundingBox(gRenderForegrounds
);
1282 calcBoundingBox(gWater
);
1283 calcBoundingBox(gAcid1
);
1284 calcBoundingBox(gAcid2
);
1285 calcBoundingBox(gSteps
);
1286 calcBoundingBox(gLifts
);
1287 calcBoundingBox(gBlockMon
);
1289 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1291 mapGrid
:= TPanelGrid
.Create(mapX0
-512, mapY0
-512, mapX1
-mapX0
+1+512*2, mapY1
-mapY0
+1+512*2);
1292 //mapTree := TDynAABBTreeMap.Create();
1294 addPanelsToGrid(gWalls
, PANEL_WALL
);
1295 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1296 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1297 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1298 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1299 addPanelsToGrid(gWater
, PANEL_WATER
);
1300 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1301 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1302 addPanelsToGrid(gSteps
, PANEL_STEP
);
1303 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1304 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1306 mapGrid
.dumpStats();
1307 //e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree.computeTreeHeight, mapTree.nodeCount, mapTree.nodeAlloced]), MSG_NOTIFY);
1308 //mapTree.forEachLeaf(nil);
1311 function g_Map_Load(Res
: String): Boolean;
1313 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1314 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1317 MapReader
: TMapReader_1
;
1318 Header
: TMapHeaderRec_1
;
1319 _textures
: TTexturesRec1Array
;
1320 _texnummap
: array of Integer; // `_textures` -> `Textures`
1321 panels
: TPanelsRec1Array
;
1322 items
: TItemsRec1Array
;
1323 monsters
: TMonsterRec1Array
;
1324 areas
: TAreasRec1Array
;
1325 triggers
: TTriggersRec1Array
;
1326 a
, b
, c
, k
: Integer;
1328 AddTextures
: TAddTextureArray
;
1329 texture
: TTextureRec_1
;
1330 TriggersTable
: Array of record
1331 TexturePanel
: Integer;
1336 FileName
, mapResName
, s
, TexName
: String;
1339 ok
, isAnim
, trigRef
: Boolean;
1340 CurTex
, ntn
: Integer;
1349 gMapInfo
.Map
:= Res
;
1350 TriggersTable
:= nil;
1351 FillChar(texture
, SizeOf(texture
), 0);
1353 sfsGCDisable(); // temporary disable removing of temporary volumes
1356 FileName
:= g_ExtractWadName(Res
);
1357 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1358 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1360 WAD
:= TWADFile
.Create();
1361 if not WAD
.ReadFile(FileName
) then
1363 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1367 //k8: why loader ignores path here?
1368 mapResName
:= g_ExtractFileName(Res
);
1369 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1371 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1379 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1380 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1381 MapReader
:= TMapReader_1
.Create();
1383 if not MapReader
.LoadMap(Data
) then
1385 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1392 generateExternalResourcesList(MapReader
);
1393 // Çàãðóçêà òåêñòóð:
1394 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1395 _textures
:= MapReader
.GetTextures();
1398 // Äîáàâëåíèå òåêñòóð â Textures[]:
1399 if _textures
<> nil then
1401 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1402 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1403 SetLength(_texnummap
, length(_textures
));
1405 for a
:= 0 to High(_textures
) do
1408 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1409 for b
:= 1 to Length(s
) do
1415 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1416 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1417 // Àíèìèðîâàííàÿ òåêñòóðà:
1418 if ByteBool(_textures
[a
].Anim
) then
1420 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1423 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1424 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1427 else // Îáû÷íàÿ òåêñòóðà:
1428 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1431 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1432 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1435 _texnummap
[a
] := ntn
; // fix texture number
1436 g_Game_StepLoading();
1440 // Çàãðóçêà òðèããåðîâ:
1441 gTriggerClientID
:= 0;
1442 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1443 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1444 triggers
:= MapReader
.GetTriggers();
1446 // Çàãðóçêà ïàíåëåé:
1447 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1448 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1449 panels
:= MapReader
.GetPanels();
1451 // check texture numbers for panels
1452 for a
:= 0 to High(panels
) do
1454 if panels
[a
].TextureNum
> High(_textures
) then
1456 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1460 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1463 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1464 if triggers
<> nil then
1466 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1467 SetLength(TriggersTable
, Length(triggers
));
1468 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1470 for a
:= 0 to High(TriggersTable
) do
1472 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1473 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1475 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1476 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1478 TriggersTable
[a
].LiftPanel
:= -1;
1480 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1481 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1482 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1483 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1485 TriggersTable
[a
].DoorPanel
:= -1;
1487 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1488 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1490 TriggersTable
[a
].ShotPanel
:= -1;
1492 g_Game_StepLoading();
1497 if panels
<> nil then
1499 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1500 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1502 for a
:= 0 to High(panels
) do
1504 SetLength(AddTextures
, 0);
1507 if _textures
<> nil then
1509 texture
:= _textures
[panels
[a
].TextureNum
];
1517 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1518 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1520 if (TriggersTable
<> nil) and (_textures
<> nil) then
1521 for b
:= 0 to High(TriggersTable
) do
1522 if (TriggersTable
[b
].TexturePanel
= a
)
1523 or (TriggersTable
[b
].ShotPanel
= a
) then
1532 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1534 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1537 for c
:= Len
downto 1 do
1545 // Ñïåö-òåêñòóðû çàïðåùåíû:
1546 if g_Map_IsSpecialTexture(s
) then
1549 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1550 ok
:= g_Texture_NumNameFindStart(s
);
1552 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1553 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1556 k
:= NNF_NAME_BEFORE
;
1557 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1558 while ok
or (k
= NNF_NAME_BEFORE
) or
1559 (k
= NNF_NAME_EQUALS
) do
1561 k
:= g_Texture_NumNameFindNext(TexName
);
1563 if (k
= NNF_NAME_BEFORE
) or
1564 (k
= NNF_NAME_AFTER
) then
1566 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1567 if ByteBool(texture
.Anim
) then
1568 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1570 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1572 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1574 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1578 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1580 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1582 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1584 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1588 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1591 for c
:= 0 to High(Textures
) do
1592 if Textures
[c
].TextureName
= TexName
then
1594 SetLength(AddTextures
, Length(AddTextures
)+1);
1595 AddTextures
[High(AddTextures
)].Texture
:= c
;
1596 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1602 if k
= NNF_NAME_EQUALS
then
1604 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1605 SetLength(AddTextures
, Length(AddTextures
)+1);
1606 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1607 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1608 CurTex
:= High(AddTextures
);
1616 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1617 end; // if ok - ññûëàþòñÿ òðèããåðû
1621 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1622 SetLength(AddTextures
, 1);
1623 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1624 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1628 //e_WriteLog(Format('panel #%d: TextureNum=%d; ht=%d; ht1=%d; atl=%d', [a, panels[a].TextureNum, High(_textures), High(Textures), High(AddTextures)]), MSG_NOTIFY);
1630 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1631 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1633 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1634 if TriggersTable
<> nil then
1635 for b
:= 0 to High(TriggersTable
) do
1637 // Òðèããåð äâåðè/ëèôòà:
1638 if (TriggersTable
[b
].LiftPanel
= a
) or
1639 (TriggersTable
[b
].DoorPanel
= a
) then
1640 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1641 // Òðèããåð ñìåíû òåêñòóðû:
1642 if TriggersTable
[b
].TexturePanel
= a
then
1643 triggers
[b
].TexturePanel
:= PanelID
;
1644 // Òðèããåð "Òóðåëü":
1645 if TriggersTable
[b
].ShotPanel
= a
then
1646 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1649 g_Game_StepLoading();
1653 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1654 if (triggers
<> nil) and not gLoadGameMode
then
1656 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1657 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1658 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1659 for a
:= 0 to High(triggers
) do
1661 if triggers
[a
].TexturePanel
<> -1 then
1662 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1665 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1666 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1667 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1670 CreateTrigger(triggers
[a
], b
, c
);
1674 // Çàãðóçêà ïðåäìåòîâ:
1675 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1676 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1677 items
:= MapReader
.GetItems();
1679 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1680 if (items
<> nil) and not gLoadGameMode
then
1682 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1683 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1684 for a
:= 0 to High(items
) do
1685 CreateItem(Items
[a
]);
1688 // Çàãðóçêà îáëàñòåé:
1689 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1690 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1691 areas
:= MapReader
.GetAreas();
1693 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1694 if areas
<> nil then
1696 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1697 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1698 for a
:= 0 to High(areas
) do
1699 CreateArea(areas
[a
]);
1702 // Çàãðóçêà ìîíñòðîâ:
1703 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1704 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1705 monsters
:= MapReader
.GetMonsters();
1707 gTotalMonsters
:= 0;
1709 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1710 if (monsters
<> nil) and not gLoadGameMode
then
1712 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1713 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1714 for a
:= 0 to High(monsters
) do
1715 CreateMonster(monsters
[a
]);
1718 // Çàãðóçêà îïèñàíèÿ êàðòû:
1719 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1720 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1721 Header
:= MapReader
.GetMapHeader();
1727 Name
:= Header
.MapName
;
1728 Description
:= Header
.MapDescription
;
1729 Author
:= Header
.MapAuthor
;
1730 MusicName
:= Header
.MusicName
;
1731 SkyName
:= Header
.SkyName
;
1732 Height
:= Header
.Height
;
1733 Width
:= Header
.Width
;
1737 if gMapInfo
.SkyName
<> '' then
1739 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1740 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1741 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1743 if FileName
<> '' then
1744 FileName
:= GameDir
+'/wads/'+FileName
1747 FileName
:= g_ExtractWadName(Res
);
1750 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1751 if g_Texture_CreateWAD(BackID
, s
) then
1753 g_Game_SetupScreenSize();
1756 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1761 if gMapInfo
.MusicName
<> '' then
1763 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1764 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1765 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1767 if FileName
<> '' then
1768 FileName
:= GameDir
+'/wads/'+FileName
1771 FileName
:= g_ExtractWadName(Res
);
1774 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1775 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1778 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1781 // Îñòàëüíûå óñòàíâêè:
1789 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1790 if not gLoadGameMode
then
1793 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1799 TriggersTable
:= nil;
1802 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1803 if ok
and (not gLoadGameMode
) then
1805 gMusic
.SetByName(gMapInfo
.MusicName
);
1809 gMusic
.SetByName('');
1811 sfsGCEnable(); // enable releasing unused volumes
1814 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1817 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1821 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1824 MapReader
: TMapReader_1
;
1825 Header
: TMapHeaderRec_1
;
1830 FillChar(Result
, SizeOf(Result
), 0);
1831 FileName
:= g_ExtractWadName(Res
);
1833 WAD
:= TWADFile
.Create();
1834 if not WAD
.ReadFile(FileName
) then
1840 //k8: it ignores path again
1841 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1849 MapReader
:= TMapReader_1
.Create();
1851 if not MapReader
.LoadMap(Data
) then
1853 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1854 ZeroMemory(@Header
, SizeOf(Header
));
1855 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1856 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1860 Header
:= MapReader
.GetMapHeader();
1861 Result
.Name
:= Header
.MapName
;
1862 Result
.Description
:= Header
.MapDescription
;
1869 Result
.Author
:= Header
.MapAuthor
;
1870 Result
.Height
:= Header
.Height
;
1871 Result
.Width
:= Header
.Width
;
1874 function g_Map_GetMapsList(WADName
: string): SArray
;
1881 WAD
:= TWADFile
.Create();
1882 if not WAD
.ReadFile(WADName
) then
1887 ResList
:= WAD
.GetMapResources();
1888 if ResList
<> nil then
1890 for a
:= 0 to High(ResList
) do
1892 SetLength(Result
, Length(Result
)+1);
1893 Result
[High(Result
)] := ResList
[a
];
1899 function g_Map_Exist(Res
: string): Boolean;
1902 FileName
, mnn
: string;
1908 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1910 WAD
:= TWADFile
.Create
;
1911 if not WAD
.ReadFile(FileName
) then
1917 ResList
:= WAD
.GetMapResources();
1920 mnn
:= g_ExtractFileName(Res
);
1921 if ResList
<> nil then
1922 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1929 procedure g_Map_Free();
1933 procedure FreePanelArray(var panels
: TPanelArray
);
1938 if panels
<> nil then
1940 for i
:= 0 to High(panels
) do
1953 RespawnPoints
:= nil;
1954 if FlagPoints
[FLAG_RED
] <> nil then
1956 Dispose(FlagPoints
[FLAG_RED
]);
1957 FlagPoints
[FLAG_RED
] := nil;
1959 if FlagPoints
[FLAG_BLUE
] <> nil then
1961 Dispose(FlagPoints
[FLAG_BLUE
]);
1962 FlagPoints
[FLAG_BLUE
] := nil;
1964 //DOMFlagPoints := nil;
1968 if Textures
<> nil then
1970 for a
:= 0 to High(Textures
) do
1971 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1972 if Textures
[a
].Anim
then
1973 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1975 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1976 e_DeleteTexture(Textures
[a
].TextureID
);
1981 FreePanelArray(gWalls
);
1982 FreePanelArray(gRenderBackgrounds
);
1983 FreePanelArray(gRenderForegrounds
);
1984 FreePanelArray(gWater
);
1985 FreePanelArray(gAcid1
);
1986 FreePanelArray(gAcid2
);
1987 FreePanelArray(gSteps
);
1988 FreePanelArray(gLifts
);
1989 FreePanelArray(gBlockMon
);
1991 if BackID
<> DWORD(-1) then
1995 e_DeleteTexture(BackID
);
1996 BackID
:= DWORD(-1);
1999 g_Game_StopAllSounds(False);
2001 g_Sound_Delete(gMapInfo
.MusicName
);
2003 gMapInfo
.Name
:= '';
2004 gMapInfo
.Description
:= '';
2005 gMapInfo
.MusicName
:= '';
2006 gMapInfo
.Height
:= 0;
2007 gMapInfo
.Width
:= 0;
2015 procedure g_Map_Update();
2021 procedure UpdatePanelArray(var panels
: TPanelArray
);
2026 if panels
<> nil then
2027 for i
:= 0 to High(panels
) do
2032 UpdatePanelArray(gWalls
);
2033 UpdatePanelArray(gRenderBackgrounds
);
2034 UpdatePanelArray(gRenderForegrounds
);
2035 UpdatePanelArray(gWater
);
2036 UpdatePanelArray(gAcid1
);
2037 UpdatePanelArray(gAcid2
);
2038 UpdatePanelArray(gSteps
);
2040 if gGameSettings
.GameMode
= GM_CTF
then
2042 for a
:= FLAG_RED
to FLAG_BLUE
do
2043 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2046 if gFlags
[a
].Animation
<> nil then
2047 gFlags
[a
].Animation
.Update();
2049 m
:= g_Obj_Move(@Obj
, True, True);
2051 if gTime
mod (GAME_TICK
*2) <> 0 then
2054 // Ñîïðîòèâëåíèå âîçäóõà:
2055 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2057 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
2058 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2061 gFlags
[a
].CaptureTime
:= 0;
2062 if a
= FLAG_RED
then
2063 s
:= _lc
[I_PLAYER_FLAG_RED
]
2065 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2066 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2068 if g_Game_IsNet
then
2069 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2076 // Èãðîê áåðåò ôëàã:
2077 if gPlayers
<> nil then
2079 j
:= Random(Length(gPlayers
)) - 1;
2081 for d
:= 0 to High(gPlayers
) do
2084 if j
> High(gPlayers
) then
2087 if gPlayers
[j
] <> nil then
2088 if gPlayers
[j
].Live
and
2089 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2091 if gPlayers
[j
].GetFlag(a
) then
2102 procedure g_Map_DrawPanels (PanelType
: Word);
2104 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2108 if (panels
<> nil) then
2110 // alas, no visible set
2111 for idx
:= 0 to High(panels
) do
2113 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2120 PANEL_WALL
: DrawPanels(gWalls
);
2121 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2122 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2123 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2124 PANEL_WATER
: DrawPanels(gWater
);
2125 PANEL_ACID1
: DrawPanels(gAcid1
);
2126 PANEL_ACID2
: DrawPanels(gAcid2
);
2127 PANEL_STEP
: DrawPanels(gSteps
);
2133 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2135 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2137 result
:= false; // don't stop, ever
2138 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2139 gDrawPanelList
.insert(pan
);
2144 //tagmask := panelTypeToTag(PanelType);
2146 {if gdbg_map_use_tree_draw then
2148 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2152 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
, true);
2154 // list will be rendered in `g_game.DrawPlayer()`
2158 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2160 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2162 result
:= false; // don't stop, ever
2163 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2167 {if gdbg_map_use_tree_draw then
2169 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2173 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
), true);
2178 procedure g_Map_DrawBack(dx
, dy
: Integer);
2180 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2181 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2183 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2186 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2187 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2193 if WordBool(PanelType
and PANEL_WALL
) then
2194 if gWalls
<> nil then
2199 if gWalls
[a
].Enabled
and
2200 g_Collide(X
, Y
, Width
, Height
,
2201 gWalls
[a
].X
, gWalls
[a
].Y
,
2202 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2209 if WordBool(PanelType
and PANEL_WATER
) then
2210 if gWater
<> nil then
2215 if g_Collide(X
, Y
, Width
, Height
,
2216 gWater
[a
].X
, gWater
[a
].Y
,
2217 gWater
[a
].Width
, gWater
[a
].Height
) then
2224 if WordBool(PanelType
and PANEL_ACID1
) then
2225 if gAcid1
<> nil then
2230 if g_Collide(X
, Y
, Width
, Height
,
2231 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2232 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2239 if WordBool(PanelType
and PANEL_ACID2
) then
2240 if gAcid2
<> nil then
2245 if g_Collide(X
, Y
, Width
, Height
,
2246 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2247 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2254 if WordBool(PanelType
and PANEL_STEP
) then
2255 if gSteps
<> nil then
2260 if g_Collide(X
, Y
, Width
, Height
,
2261 gSteps
[a
].X
, gSteps
[a
].Y
,
2262 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2269 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2270 if gLifts
<> nil then
2275 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2276 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2277 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2278 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2279 g_Collide(X
, Y
, Width
, Height
,
2280 gLifts
[a
].X
, gLifts
[a
].Y
,
2281 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2288 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2289 if gBlockMon
<> nil then
2291 h
:= High(gBlockMon
);
2295 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2296 g_Collide(X
, Y
, Width
, Height
,
2297 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2298 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2306 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2310 function checkPanels (constref panels
: TPanelArray
): Boolean;
2315 if panels
= nil then exit
;
2316 for a
:= 0 to High(panels
) do
2318 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2321 texid
:= panels
[a
].GetTextureID();
2328 texid
:= TEXTURE_NONE
;
2330 if not checkPanels(gWater
) then
2331 if not checkPanels(gAcid1
) then
2332 if not checkPanels(gAcid2
) then exit
;
2337 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2339 SlowMask
= GridTagLift
or GridTagBlockMon
;
2340 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2343 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2345 result := pan.Enabled;
2350 if ((tag
and GridTagLift
) <> 0) then
2353 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2354 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2355 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2356 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2357 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2361 if ((tag
and GridTagBlockMon
) <> 0) then
2363 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2368 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2369 result
:= true; // i found her!
2373 tagmask
: Integer = 0;
2375 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2376 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2377 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2378 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2379 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2380 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2381 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2383 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2385 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2386 if gdbg_map_use_accel_coldet
then
2388 {if gdbg_map_use_tree_coldet then
2390 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2391 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2392 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2394 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2395 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2400 if (Width
= 1) and (Height
= 1) then
2402 if ((tagmask
and SlowMask
) <> 0) then
2405 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2410 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2415 if ((tagmask
and SlowMask
) <> 0) then
2418 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2423 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2430 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2432 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2436 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2438 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2441 // slightly different from the old code, but meh...
2442 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2444 result
:= false; // don't stop, ever
2445 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2448 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2449 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2450 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2453 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2455 texid
:= pan
.GetTextureID();
2456 // water? water has the highest priority, so stop right here
2457 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2459 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2461 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2465 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2466 if gdbg_map_use_accel_coldet
then
2468 texid
:= TEXTURE_NONE
;
2469 {if gdbg_map_use_tree_coldet then
2471 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2475 if (Width
= 1) and (Height
= 1) then
2477 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2481 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2488 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2490 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2494 procedure g_Map_EnableWall(ID
: DWORD
);
2499 pan
.Enabled
:= True;
2500 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2502 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2503 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2504 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2506 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2508 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2509 e_WriteLog(Format('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
);
2513 procedure g_Map_DisableWall(ID
: DWORD
);
2518 pan
.Enabled
:= False;
2519 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2521 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2522 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2524 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2526 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2527 e_WriteLog(Format('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
);
2531 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2536 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2539 tp
:= gRenderForegrounds
[ID
];
2541 tp
:= gRenderBackgrounds
[ID
];
2554 tp
.NextTexture(AnimLoop
);
2555 if g_Game_IsServer
and g_Game_IsNet
then
2556 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2559 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2561 if gLifts
[ID
].LiftType
= t
then
2568 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2569 //TODO: make separate lift tags, and change tag here
2571 if LiftType
= 0 then
2572 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2573 else if LiftType
= 1 then
2574 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2575 else if LiftType
= 2 then
2576 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2577 else if LiftType
= 3 then
2578 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2580 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2584 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2587 PointsArray
: Array of TRespawnPoint
;
2590 SetLength(PointsArray
, 0);
2592 if RespawnPoints
= nil then
2595 for a
:= 0 to High(RespawnPoints
) do
2596 if RespawnPoints
[a
].PointType
= PointType
then
2598 SetLength(PointsArray
, Length(PointsArray
)+1);
2599 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2602 if PointsArray
= nil then
2605 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2609 function g_Map_GetPointCount(PointType
: Byte): Word;
2615 if RespawnPoints
= nil then
2618 for a
:= 0 to High(RespawnPoints
) do
2619 if RespawnPoints
[a
].PointType
= PointType
then
2620 Result
:= Result
+ 1;
2623 function g_Map_HaveFlagPoints(): Boolean;
2625 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2628 procedure g_Map_ResetFlag(Flag
: Byte);
2630 with gFlags
[Flag
] do
2636 Direction
:= D_LEFT
;
2637 State
:= FLAG_STATE_NONE
;
2638 if FlagPoints
[Flag
] <> nil then
2640 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2641 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2642 Direction
:= FlagPoints
[Flag
]^.Direction
;
2643 State
:= FLAG_STATE_NORMAL
;
2649 procedure g_Map_DrawFlags();
2652 Mirror
: TMirrorType
;
2654 if gGameSettings
.GameMode
<> GM_CTF
then
2657 for i
:= FLAG_RED
to FLAG_BLUE
do
2659 if State
<> FLAG_STATE_CAPTURED
then
2661 if State
= FLAG_STATE_NONE
then
2664 if Direction
= D_LEFT
then
2666 Mirror
:= M_HORIZONTAL
;
2675 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2677 if g_debug_Frames
then
2679 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2681 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2682 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2688 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2695 procedure SavePanelArray(var panels
: TPanelArray
);
2697 PAMem
: TBinMemoryWriter
;
2700 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2701 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2704 while i
< Length(panels
) do
2706 if panels
[i
].SaveIt
then
2710 // Ñîõðàíÿåì ïàíåëü:
2711 panels
[i
].SaveState(PAMem
);
2716 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2717 PAMem
.SaveToMemory(Mem
);
2721 procedure SaveFlag(flag
: PFlag
);
2724 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2726 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2727 Mem
.WriteByte(flag
^.RespawnType
);
2729 Mem
.WriteByte(flag
^.State
);
2730 // Íàïðàâëåíèå ôëàãà:
2731 if flag
^.Direction
= D_LEFT
then
2737 Obj_SaveState(@flag
^.Obj
, Mem
);
2741 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2743 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2744 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2745 SavePanelArray(gWalls
);
2746 // Ñîõðàíÿåì ïàíåëè ôîíà:
2747 SavePanelArray(gRenderBackgrounds
);
2748 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2749 SavePanelArray(gRenderForegrounds
);
2750 // Ñîõðàíÿåì ïàíåëè âîäû:
2751 SavePanelArray(gWater
);
2752 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2753 SavePanelArray(gAcid1
);
2754 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2755 SavePanelArray(gAcid2
);
2756 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2757 SavePanelArray(gSteps
);
2758 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2759 SavePanelArray(gLifts
);
2762 ///// Ñîõðàíÿåì ìóçûêó: /////
2763 // Ñèãíàòóðà ìóçûêè:
2764 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2767 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2768 if gMusic
.NoMusic
then
2772 Mem
.WriteString(str
, 64);
2773 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2774 dw
:= gMusic
.GetPosition();
2776 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2777 boo
:= gMusic
.SpecPause
;
2778 Mem
.WriteBoolean(boo
);
2781 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2782 Mem
.WriteInt(gTotalMonsters
);
2785 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2786 if gGameSettings
.GameMode
= GM_CTF
then
2788 // Ôëàã Êðàñíîé êîìàíäû:
2789 SaveFlag(@gFlags
[FLAG_RED
]);
2790 // Ôëàã Ñèíåé êîìàíäû:
2791 SaveFlag(@gFlags
[FLAG_BLUE
]);
2795 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2796 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2798 // Î÷êè Êðàñíîé êîìàíäû:
2799 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2800 // Î÷êè Ñèíåé êîìàíäû:
2801 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2806 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2813 procedure LoadPanelArray(var panels
: TPanelArray
);
2815 PAMem
: TBinMemoryReader
;
2818 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2819 PAMem
:= TBinMemoryReader
.Create();
2820 PAMem
.LoadFromMemory(Mem
);
2822 for i
:= 0 to Length(panels
)-1 do
2823 if panels
[i
].SaveIt
then
2829 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2831 // Çàãðóæàåì ïàíåëü:
2832 panels
[i
].LoadState(PAMem
);
2835 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2839 procedure LoadFlag(flag
: PFlag
);
2843 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2845 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2847 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2848 Mem
.ReadByte(flag
^.RespawnType
);
2850 Mem
.ReadByte(flag
^.State
);
2851 // Íàïðàâëåíèå ôëàãà:
2854 flag
^.Direction
:= D_LEFT
2856 flag
^.Direction
:= D_RIGHT
;
2858 Obj_LoadState(@flag
^.Obj
, Mem
);
2865 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2866 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2867 LoadPanelArray(gWalls
);
2868 // Çàãðóæàåì ïàíåëè ôîíà:
2869 LoadPanelArray(gRenderBackgrounds
);
2870 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2871 LoadPanelArray(gRenderForegrounds
);
2872 // Çàãðóæàåì ïàíåëè âîäû:
2873 LoadPanelArray(gWater
);
2874 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2875 LoadPanelArray(gAcid1
);
2876 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2877 LoadPanelArray(gAcid2
);
2878 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2879 LoadPanelArray(gSteps
);
2880 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2881 LoadPanelArray(gLifts
);
2884 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2888 ///// Çàãðóæàåì ìóçûêó: /////
2889 // Ñèãíàòóðà ìóçûêè:
2891 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2893 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2896 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2897 Mem
.ReadString(str
);
2898 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2900 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2901 Mem
.ReadBoolean(boo
);
2902 // Çàïóñêàåì ýòó ìóçûêó:
2903 gMusic
.SetByName(str
);
2904 gMusic
.SpecPause
:= boo
;
2907 gMusic
.SetPosition(dw
);
2910 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2911 Mem
.ReadInt(gTotalMonsters
);
2914 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2915 if gGameSettings
.GameMode
= GM_CTF
then
2917 // Ôëàã Êðàñíîé êîìàíäû:
2918 LoadFlag(@gFlags
[FLAG_RED
]);
2919 // Ôëàã Ñèíåé êîìàíäû:
2920 LoadFlag(@gFlags
[FLAG_BLUE
]);
2924 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2925 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2927 // Î÷êè Êðàñíîé êîìàíäû:
2928 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2929 // Î÷êè Ñèíåé êîìàíäû:
2930 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2935 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2940 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2941 Arr
:= PanelByID
[PanelID
].PWhere
^;
2942 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2943 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2947 // trace liquid, stepping by `dx` and `dy`
2948 // return last seen liquid coords, and `false` if we're started outside of the liquid
2949 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2951 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2955 // started outside of the liquid?
2956 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2957 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2963 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit