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
, 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 panel or nil
96 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
97 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
99 // returns panel or nil
100 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
101 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
104 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
106 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
107 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
109 // trace liquid, stepping by `dx` and `dy`
110 // return last seen liquid coords, and `false` if we're started outside of the liquid
111 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
114 procedure g_Map_ProfilersBegin ();
115 procedure g_Map_ProfilersEnd ();
119 RESPAWNPOINT_PLAYER1
= 1;
120 RESPAWNPOINT_PLAYER2
= 2;
122 RESPAWNPOINT_RED
= 4;
123 RESPAWNPOINT_BLUE
= 5;
131 FLAG_STATE_NORMAL
= 1;
132 FLAG_STATE_DROPPED
= 2;
133 FLAG_STATE_CAPTURED
= 3;
134 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
135 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
137 FLAG_TIME
= 720; // 20 seconds
139 SKY_STRETCH
: Single = 1.5;
154 // sorted by draw priority
155 GridTagBack
= 1 shl 0;
156 GridTagStep
= 1 shl 1;
157 GridTagWall
= 1 shl 2;
158 GridTagDoor
= 1 shl 3;
159 GridTagAcid1
= 1 shl 4;
160 GridTagAcid2
= 1 shl 5;
161 GridTagWater
= 1 shl 6;
162 GridTagFore
= 1 shl 7;
163 // the following are invisible
164 GridTagLift
= 1 shl 8;
165 GridTagBlockMon
= 1 shl 9;
167 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
172 gRenderBackgrounds
: TPanelArray
;
173 gRenderForegrounds
: TPanelArray
;
174 gWater
, gAcid1
, gAcid2
: TPanelArray
;
177 gBlockMon
: TPanelArray
;
178 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
179 //gDOMFlags: array of TFlag;
182 gDoorMap
: array of array of DWORD
;
183 gLiftMap
: array of array of DWORD
;
184 gWADHash
: TMD5Digest
;
185 BackID
: DWORD
= DWORD(-1);
186 gExternalResources
: TStringList
;
188 gdbg_map_use_accel_render
: Boolean = true;
189 gdbg_map_use_accel_coldet
: Boolean = true;
190 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
191 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
194 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
198 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
201 mapGrid
: TPanelGrid
= nil;
207 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
208 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
209 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
210 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
212 ImagingTypes
, Imaging
, ImagingUtility
,
213 ImagingGif
, ImagingNetworkGraphics
;
216 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
217 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
218 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
221 function panelTypeToTag (panelType
: Word): Integer;
224 PANEL_WALL
: result
:= GridTagWall
; // gWalls
225 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
226 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
227 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
228 PANEL_WATER
: result
:= GridTagWater
; // gWater
229 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
230 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
231 PANEL_STEP
: result
:= GridTagStep
; // gSteps
232 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
233 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
234 else result
:= GridTagInvalid
;
239 function dplLess (a
, b
: TObject
): Boolean;
245 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
246 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
247 result
:= (pa
.arrIdx
< pb
.arrIdx
);
250 procedure dplClear ();
252 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
258 PWhere
: ^TPanelArray
;
263 PanelById
: array of TPanelID
;
264 Textures
: TLevelTextureArray
;
265 RespawnPoints
: Array of TRespawnPoint
;
266 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
267 //DOMFlagPoints: Array of TFlagPoint;
270 procedure g_Map_ProfilersBegin ();
272 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
273 profMapCollision
.mainBegin(g_profile_collision
);
275 if g_profile_collision
then
277 profMapCollision
.sectionBegin('*solids');
278 profMapCollision
.sectionEnd();
279 profMapCollision
.sectionBegin('liquids');
280 profMapCollision
.sectionEnd();
284 procedure g_Map_ProfilersEnd ();
286 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
290 // wall index in `gWalls` or -1
291 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
295 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
296 if (result
<> nil) then
298 if (hitx
<> nil) then hitx
^ := ex
;
299 if (hity
<> nil) then hity
^ := ey
;
303 if (hitx
<> nil) then hitx
^ := x1
;
304 if (hity
<> nil) then hity
^ := y1
;
308 // returns panel or nil
309 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
313 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
314 if (result
<> nil) then
316 if (hitx
<> nil) then hitx
^ := ex
;
317 if (hity
<> nil) then hity
^ := ey
;
321 if (hitx
<> nil) then hitx
^ := x1
;
322 if (hity
<> nil) then hity
^ := y1
;
327 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
329 function checker (pan
: TPanel
; tag
: Integer): Boolean;
332 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
334 result := pan.Enabled; // stop if wall is enabled
339 if ((tag
and GridTagLift
) <> 0) then
341 // stop if the lift of the right type
343 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
344 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
345 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
346 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
350 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
354 tagmask
: Integer = 0;
358 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
359 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
360 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
361 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
362 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
363 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
364 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
366 if (tagmask
= 0) then exit
;// just in case
367 if ((tagmask
and GridTagLift
) <> 0) then
370 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
375 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
380 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
383 if (tagmask
= 0) then exit
;
384 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
388 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
390 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
391 (Texture
= TEXTURE_NAME_ACID1
) or
392 (Texture
= TEXTURE_NAME_ACID2
);
395 procedure CreateDoorMap();
397 PanelArray
: Array of record
403 a
, b
, c
, m
, i
, len
: Integer;
411 SetLength(PanelArray
, len
);
413 for a
:= 0 to High(gWalls
) do
414 if gWalls
[a
].Door
then
416 PanelArray
[i
].X
:= gWalls
[a
].X
;
417 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
418 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
419 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
420 PanelArray
[i
].Active
:= True;
421 PanelArray
[i
].PanelID
:= a
;
427 SetLength(PanelArray
, len
);
438 SetLength(gDoorMap
, 0);
440 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
443 if PanelArray
[a
].Active
then
445 PanelArray
[a
].Active
:= False;
446 m
:= Length(gDoorMap
);
447 SetLength(gDoorMap
, m
+1);
448 SetLength(gDoorMap
[m
], 1);
449 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
457 if PanelArray
[b
].Active
then
458 for c
:= 0 to High(gDoorMap
[m
]) do
459 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
460 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
461 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
462 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
463 gWalls
[gDoorMap
[m
, c
]].X
,
464 gWalls
[gDoorMap
[m
, c
]].Y
,
465 gWalls
[gDoorMap
[m
, c
]].Width
,
466 gWalls
[gDoorMap
[m
, c
]].Height
) then
468 PanelArray
[b
].Active
:= False;
469 SetLength(gDoorMap
[m
],
470 Length(gDoorMap
[m
])+1);
471 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
477 g_Game_StepLoading();
483 procedure CreateLiftMap();
485 PanelArray
: Array of record
490 a
, b
, c
, len
, i
, j
: Integer;
496 len
:= Length(gLifts
);
497 SetLength(PanelArray
, len
);
499 for a
:= 0 to len
-1 do
501 PanelArray
[a
].X
:= gLifts
[a
].X
;
502 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
503 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
504 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
505 PanelArray
[a
].Active
:= True;
508 SetLength(gLiftMap
, len
);
511 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
513 for a
:= 0 to len
-1 do
514 if PanelArray
[a
].Active
then
516 PanelArray
[a
].Active
:= False;
517 SetLength(gLiftMap
[i
], 32);
525 for b
:= 0 to len
-1 do
526 if PanelArray
[b
].Active
then
528 if g_CollideAround(PanelArray
[b
].X
,
531 PanelArray
[b
].Height
,
532 PanelArray
[gLiftMap
[i
, c
]].X
,
533 PanelArray
[gLiftMap
[i
, c
]].Y
,
534 PanelArray
[gLiftMap
[i
, c
]].Width
,
535 PanelArray
[gLiftMap
[i
, c
]].Height
) then
537 PanelArray
[b
].Active
:= False;
539 if j
> High(gLiftMap
[i
]) then
540 SetLength(gLiftMap
[i
],
541 Length(gLiftMap
[i
])+32);
550 SetLength(gLiftMap
[i
], j
+1);
553 g_Game_StepLoading();
556 SetLength(gLiftMap
, i
);
561 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
562 CurTex
: Integer; sav
: Boolean): Integer;
565 panels
: ^TPanelArray
;
569 case PanelRec
.PanelType
of
570 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
573 panels
:= @gRenderBackgrounds
;
575 panels
:= @gRenderForegrounds
;
584 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
587 panels
:= @gBlockMon
;
592 len
:= Length(panels
^);
593 SetLength(panels
^, len
+ 1);
595 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
596 panels
^[len
].arrIdx
:= len
;
597 panels
^[len
].proxyId
:= -1;
598 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
600 panels
^[len
].SaveIt
:= True;
604 len
:= Length(PanelByID
);
605 SetLength(PanelByID
, len
+ 1);
606 PanelByID
[len
].PWhere
:= panels
;
607 PanelByID
[len
].PArrID
:= Result
;
610 function CreateNullTexture(RecName
: String): Integer;
612 SetLength(Textures
, Length(Textures
)+1);
613 result
:= High(Textures
);
615 with Textures
[High(Textures
)] do
617 TextureName
:= RecName
;
621 TextureID
:= TEXTURE_NONE
;
625 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
628 TextureData
: Pointer;
629 WADName
, txname
: String;
630 a
, ResLength
: Integer;
634 if Textures
<> nil then
635 for a
:= 0 to High(Textures
) do
636 if Textures
[a
].TextureName
= RecName
then
637 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
642 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
643 if (RecName
= TEXTURE_NAME_WATER
) or
644 (RecName
= TEXTURE_NAME_ACID1
) or
645 (RecName
= TEXTURE_NAME_ACID2
) then
647 SetLength(Textures
, Length(Textures
)+1);
649 with Textures
[High(Textures
)] do
651 TextureName
:= RecName
;
653 if TextureName
= TEXTURE_NAME_WATER
then
654 TextureID
:= TEXTURE_SPECIAL_WATER
656 if TextureName
= TEXTURE_NAME_ACID1
then
657 TextureID
:= TEXTURE_SPECIAL_ACID1
659 if TextureName
= TEXTURE_NAME_ACID2
then
660 TextureID
:= TEXTURE_SPECIAL_ACID2
;
665 result
:= High(Textures
);
669 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
670 WADName
:= g_ExtractWadName(RecName
);
672 WAD
:= TWADFile
.Create();
674 if WADName
<> '' then
675 WADName
:= GameDir
+'/wads/'+WADName
679 WAD
.ReadFile(WADName
);
683 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
685 FreeMem(TextureData);
686 RecName := 'COMMON\ALIEN';
690 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
692 SetLength(Textures
, Length(Textures
)+1);
693 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
695 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
696 @Textures
[High(Textures
)].Width
,
697 @Textures
[High(Textures
)].Height
);
698 FreeMem(TextureData
);
699 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
700 Textures
[High(Textures
)].Anim
:= False;
702 result
:= High(Textures
);
704 else // Íåò òàêîãî ðåóñðñà â WAD'å
706 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
709 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
710 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
717 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
720 TextureWAD
: PChar = nil;
721 TextData
: Pointer = nil;
722 TextureData
: Pointer = nil;
726 TextureResource
: String;
727 _width
, _height
, _framecount
, _speed
: Integer;
728 _backanimation
: Boolean;
730 ia
: TDynImageDataArray
= nil;
731 f
, c
, frdelay
, frloop
: Integer;
735 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
737 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
738 WADName
:= g_ExtractWadName(RecName
);
740 WAD
:= TWADFile
.Create();
742 if WADName
<> '' then
743 WADName
:= GameDir
+'/wads/'+WADName
747 WAD
.ReadFile(WADName
);
749 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
753 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
754 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
760 if WADName = Map then
762 //FreeMem(TextureWAD);
763 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
769 if ResLength
< 6 then
771 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
775 // ýòî ïòèöà? ýòî ñàìîë¸ò?
776 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
777 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
779 // íåò, ýòî ñóïåðìåí!
780 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
782 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
786 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
787 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
789 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
793 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
795 TextureResource
:= cfg
.ReadStr('', 'resource', '');
796 if TextureResource
= '' then
798 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
802 _width
:= cfg
.ReadInt('', 'framewidth', 0);
803 _height
:= cfg
.ReadInt('', 'frameheight', 0);
804 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
805 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
806 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
811 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
812 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
814 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
821 SetLength(Textures
, Length(Textures
)+1);
822 with Textures
[High(Textures
)] do
824 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
825 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
827 TextureName
:= RecName
;
831 FramesCount
:= _framecount
;
833 result
:= High(Textures
);
837 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
843 // try animated image
845 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
846 if length(imgfmt) = 0 then
848 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
852 GlobalMetadata
.ClearMetaItems();
853 GlobalMetadata
.ClearMetaItemsForSaving();
854 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
856 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
859 if length(ia
) = 0 then
861 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
868 _width
:= ia
[0].width
;
869 _height
:= ia
[0].height
;
870 _framecount
:= length(ia
);
872 _backanimation
:= false;
875 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
877 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
879 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
881 if f
< 0 then f
:= 0;
884 if c
< 13 then c
:= 0 else c
:= 1;
886 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
891 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
893 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
895 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
897 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
901 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
902 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
903 f
:= ord(_backanimation
);
904 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
);
906 SetLength(Textures
, Length(Textures
)+1);
907 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
908 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
910 Textures
[High(Textures
)].TextureName
:= RecName
;
911 Textures
[High(Textures
)].Width
:= _width
;
912 Textures
[High(Textures
)].Height
:= _height
;
913 Textures
[High(Textures
)].Anim
:= True;
914 Textures
[High(Textures
)].FramesCount
:= length(ia
);
915 Textures
[High(Textures
)].Speed
:= _speed
;
916 result
:= High(Textures
);
917 //writeln(' CREATED!');
921 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
925 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
928 if TextureWAD
<> nil then FreeMem(TextureWAD
);
929 if TextData
<> nil then FreeMem(TextData
);
930 if TextureData
<> nil then FreeMem(TextureData
);
934 procedure CreateItem(Item
: TItemRec_1
);
936 if g_Game_IsClient
then Exit
;
938 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
939 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
942 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
943 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
946 procedure CreateArea(Area
: TAreaRec_1
);
951 case Area
.AreaType
of
952 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
953 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
955 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
956 with RespawnPoints
[High(RespawnPoints
)] do
960 Direction
:= TDirection(Area
.Direction
);
962 case Area
.AreaType
of
963 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
964 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
965 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
966 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
967 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
972 AREA_REDFLAG
, AREA_BLUEFLAG
:
974 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
976 if FlagPoints
[a
] <> nil then Exit
;
980 with FlagPoints
[a
]^ do
982 X
:= Area
.X
-FLAGRECT
.X
;
983 Y
:= Area
.Y
-FLAGRECT
.Y
;
984 Direction
:= TDirection(Area
.Direction
);
990 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
991 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
994 Animation
:= TAnimation
.Create(id
, True, 8);
995 Obj
.Rect
:= FLAGRECT
;
1003 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1004 with DOMFlagPoints[High(DOMFlagPoints)] do
1008 Direction := TDirection(Area.Direction);
1011 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1016 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1020 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1026 Width
:= Trigger
.Width
;
1027 Height
:= Trigger
.Height
;
1028 Enabled
:= ByteBool(Trigger
.Enabled
);
1029 TexturePanel
:= Trigger
.TexturePanel
;
1030 TexturePanelType
:= fTexturePanel1Type
;
1031 ShotPanelType
:= fTexturePanel2Type
;
1032 TriggerType
:= Trigger
.TriggerType
;
1033 ActivateType
:= Trigger
.ActivateType
;
1034 Keys
:= Trigger
.Keys
;
1035 Data
.Default
:= Trigger
.DATA
;
1038 g_Triggers_Create(_trigger
);
1041 procedure CreateMonster(monster
: TMonsterRec_1
);
1046 if g_Game_IsClient
then Exit
;
1048 if (gGameSettings
.GameType
= GT_SINGLE
)
1049 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1051 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1053 if gTriggers
<> nil then
1055 for a
:= 0 to High(gTriggers
) do
1057 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1059 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1064 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1068 procedure g_Map_ReAdd_DieTriggers();
1070 function monsDieTrig (mon
: TMonster
): Boolean;
1074 result
:= false; // don't stop
1075 mon
.ClearTriggers();
1076 for a
:= 0 to High(gTriggers
) do
1078 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1080 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1086 if g_Game_IsClient
then Exit
;
1088 g_Mons_ForEach(monsDieTrig
);
1091 function extractWadName(resourceName
: string): string;
1095 posN
:= Pos(':', resourceName
);
1097 Result
:= Copy(resourceName
, 0, posN
-1)
1102 procedure addResToExternalResList(res
: string);
1104 res
:= extractWadName(res
);
1105 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1106 gExternalResources
.Add(res
);
1109 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1111 textures
: TTexturesRec1Array
;
1112 mapHeader
: TMapHeaderRec_1
;
1114 resFile
: String = '';
1116 if gExternalResources
= nil then
1117 gExternalResources
:= TStringList
.Create
;
1119 gExternalResources
.Clear
;
1120 textures
:= mapReader
.GetTextures();
1121 for i
:= 0 to High(textures
) do
1123 addResToExternalResList(resFile
);
1128 mapHeader
:= mapReader
.GetMapHeader
;
1130 addResToExternalResList(mapHeader
.MusicName
);
1131 addResToExternalResList(mapHeader
.SkyName
);
1135 procedure mapCreateGrid ();
1137 mapX0
: Integer = $3fffffff;
1138 mapY0
: Integer = $3fffffff;
1139 mapX1
: Integer = -$3fffffff;
1140 mapY1
: Integer = -$3fffffff;
1142 procedure calcBoundingBox (constref panels
: TPanelArray
);
1147 for idx
:= 0 to High(panels
) do
1150 if not pan
.visvalid
then continue
;
1151 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1152 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1153 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1154 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1155 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1159 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1165 //tag := panelTypeToTag(tag);
1166 for idx
:= 0 to High(panels
) do
1169 if not pan
.visvalid
then continue
;
1170 if (pan
.proxyId
<> -1) then
1172 {$IF DEFINED(D2F_DEBUG)}
1173 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
);
1177 case pan
.PanelType
of
1178 PANEL_WALL
: newtag
:= GridTagWall
;
1179 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1180 PANEL_BACK
: newtag
:= GridTagBack
;
1181 PANEL_FORE
: newtag
:= GridTagFore
;
1182 PANEL_WATER
: newtag
:= GridTagWater
;
1183 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1184 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1185 PANEL_STEP
: newtag
:= GridTagStep
;
1186 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1187 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1188 else continue
; // oops
1192 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1193 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1194 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1195 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1197 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1199 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1210 calcBoundingBox(gWalls
);
1211 calcBoundingBox(gRenderBackgrounds
);
1212 calcBoundingBox(gRenderForegrounds
);
1213 calcBoundingBox(gWater
);
1214 calcBoundingBox(gAcid1
);
1215 calcBoundingBox(gAcid2
);
1216 calcBoundingBox(gSteps
);
1217 calcBoundingBox(gLifts
);
1218 calcBoundingBox(gBlockMon
);
1220 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]), MSG_WARNING
);
1222 if (mapX0
> 0) then mapX0
:= 0;
1223 if (mapY0
> 0) then mapY0
:= 0;
1225 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1226 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1228 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1230 addPanelsToGrid(gWalls
);
1231 addPanelsToGrid(gRenderBackgrounds
);
1232 addPanelsToGrid(gRenderForegrounds
);
1233 addPanelsToGrid(gWater
);
1234 addPanelsToGrid(gAcid1
);
1235 addPanelsToGrid(gAcid2
);
1236 addPanelsToGrid(gSteps
);
1237 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1238 addPanelsToGrid(gBlockMon
);
1240 mapGrid
.dumpStats();
1242 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1246 function g_Map_Load(Res
: String): Boolean;
1248 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1249 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1252 MapReader
: TMapReader_1
;
1253 Header
: TMapHeaderRec_1
;
1254 _textures
: TTexturesRec1Array
;
1255 _texnummap
: array of Integer; // `_textures` -> `Textures`
1256 panels
: TPanelsRec1Array
;
1257 items
: TItemsRec1Array
;
1258 monsters
: TMonsterRec1Array
;
1259 areas
: TAreasRec1Array
;
1260 triggers
: TTriggersRec1Array
;
1261 a
, b
, c
, k
: Integer;
1263 AddTextures
: TAddTextureArray
;
1264 texture
: TTextureRec_1
;
1265 TriggersTable
: Array of record
1266 TexturePanel
: Integer;
1271 FileName
, mapResName
, s
, TexName
: String;
1274 ok
, isAnim
, trigRef
: Boolean;
1275 CurTex
, ntn
: Integer;
1284 gMapInfo
.Map
:= Res
;
1285 TriggersTable
:= nil;
1286 FillChar(texture
, SizeOf(texture
), 0);
1288 sfsGCDisable(); // temporary disable removing of temporary volumes
1291 FileName
:= g_ExtractWadName(Res
);
1292 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1293 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1295 WAD
:= TWADFile
.Create();
1296 if not WAD
.ReadFile(FileName
) then
1298 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1302 //k8: why loader ignores path here?
1303 mapResName
:= g_ExtractFileName(Res
);
1304 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1306 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1314 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1315 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1316 MapReader
:= TMapReader_1
.Create();
1318 if not MapReader
.LoadMap(Data
) then
1320 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1327 generateExternalResourcesList(MapReader
);
1328 // Çàãðóçêà òåêñòóð:
1329 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1330 _textures
:= MapReader
.GetTextures();
1333 // Çàãðóçêà îïèñàíèÿ êàðòû:
1334 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1335 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1336 Header
:= MapReader
.GetMapHeader();
1340 Name
:= Header
.MapName
;
1341 Description
:= Header
.MapDescription
;
1342 Author
:= Header
.MapAuthor
;
1343 MusicName
:= Header
.MusicName
;
1344 SkyName
:= Header
.SkyName
;
1345 Height
:= Header
.Height
;
1346 Width
:= Header
.Width
;
1349 // Äîáàâëåíèå òåêñòóð â Textures[]:
1350 if _textures
<> nil then
1352 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1353 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1354 SetLength(_texnummap
, length(_textures
));
1356 for a
:= 0 to High(_textures
) do
1359 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1360 for b
:= 1 to Length(s
) do
1366 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1367 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1368 // Àíèìèðîâàííàÿ òåêñòóðà:
1369 if ByteBool(_textures
[a
].Anim
) then
1371 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1374 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1375 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1378 else // Îáû÷íàÿ òåêñòóðà:
1379 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1382 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1383 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1386 _texnummap
[a
] := ntn
; // fix texture number
1387 g_Game_StepLoading();
1391 // Çàãðóçêà òðèããåðîâ:
1392 gTriggerClientID
:= 0;
1393 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1394 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1395 triggers
:= MapReader
.GetTriggers();
1397 // Çàãðóçêà ïàíåëåé:
1398 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1399 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1400 panels
:= MapReader
.GetPanels();
1402 // check texture numbers for panels
1403 for a
:= 0 to High(panels
) do
1405 if panels
[a
].TextureNum
> High(_textures
) then
1407 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1411 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1414 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1415 if triggers
<> nil then
1417 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1418 SetLength(TriggersTable
, Length(triggers
));
1419 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1421 for a
:= 0 to High(TriggersTable
) do
1423 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1424 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1426 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1427 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1429 TriggersTable
[a
].LiftPanel
:= -1;
1431 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1432 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1433 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1434 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1436 TriggersTable
[a
].DoorPanel
:= -1;
1438 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1439 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1441 TriggersTable
[a
].ShotPanel
:= -1;
1443 g_Game_StepLoading();
1448 if panels
<> nil then
1450 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1451 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1453 for a
:= 0 to High(panels
) do
1455 SetLength(AddTextures
, 0);
1458 if _textures
<> nil then
1460 texture
:= _textures
[panels
[a
].TextureNum
];
1468 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1469 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1471 if (TriggersTable
<> nil) and (_textures
<> nil) then
1472 for b
:= 0 to High(TriggersTable
) do
1473 if (TriggersTable
[b
].TexturePanel
= a
)
1474 or (TriggersTable
[b
].ShotPanel
= a
) then
1483 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1485 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1488 for c
:= Len
downto 1 do
1496 // Ñïåö-òåêñòóðû çàïðåùåíû:
1497 if g_Map_IsSpecialTexture(s
) then
1500 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1501 ok
:= g_Texture_NumNameFindStart(s
);
1503 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1504 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1507 k
:= NNF_NAME_BEFORE
;
1508 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1509 while ok
or (k
= NNF_NAME_BEFORE
) or
1510 (k
= NNF_NAME_EQUALS
) do
1512 k
:= g_Texture_NumNameFindNext(TexName
);
1514 if (k
= NNF_NAME_BEFORE
) or
1515 (k
= NNF_NAME_AFTER
) then
1517 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1518 if ByteBool(texture
.Anim
) then
1519 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1521 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1523 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1525 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1529 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1531 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1533 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1535 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1539 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1542 for c
:= 0 to High(Textures
) do
1543 if Textures
[c
].TextureName
= TexName
then
1545 SetLength(AddTextures
, Length(AddTextures
)+1);
1546 AddTextures
[High(AddTextures
)].Texture
:= c
;
1547 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1553 if k
= NNF_NAME_EQUALS
then
1555 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1556 SetLength(AddTextures
, Length(AddTextures
)+1);
1557 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1558 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1559 CurTex
:= High(AddTextures
);
1567 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1568 end; // if ok - ññûëàþòñÿ òðèããåðû
1572 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1573 SetLength(AddTextures
, 1);
1574 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1575 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1579 //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);
1581 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1582 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1584 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1585 if TriggersTable
<> nil then
1586 for b
:= 0 to High(TriggersTable
) do
1588 // Òðèããåð äâåðè/ëèôòà:
1589 if (TriggersTable
[b
].LiftPanel
= a
) or
1590 (TriggersTable
[b
].DoorPanel
= a
) then
1591 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1592 // Òðèããåð ñìåíû òåêñòóðû:
1593 if TriggersTable
[b
].TexturePanel
= a
then
1594 triggers
[b
].TexturePanel
:= PanelID
;
1595 // Òðèããåð "Òóðåëü":
1596 if TriggersTable
[b
].ShotPanel
= a
then
1597 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1600 g_Game_StepLoading();
1604 // create map grid, init other grids (for monsters, for example)
1605 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1608 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1609 if (triggers
<> nil) and not gLoadGameMode
then
1611 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1612 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1613 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1614 for a
:= 0 to High(triggers
) do
1616 if triggers
[a
].TexturePanel
<> -1 then
1617 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1620 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1621 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1622 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1625 CreateTrigger(triggers
[a
], b
, c
);
1629 // Çàãðóçêà ïðåäìåòîâ:
1630 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1631 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1632 items
:= MapReader
.GetItems();
1634 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1635 if (items
<> nil) and not gLoadGameMode
then
1637 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1638 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1639 for a
:= 0 to High(items
) do
1640 CreateItem(Items
[a
]);
1643 // Çàãðóçêà îáëàñòåé:
1644 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1645 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1646 areas
:= MapReader
.GetAreas();
1648 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1649 if areas
<> nil then
1651 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1652 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1653 for a
:= 0 to High(areas
) do
1654 CreateArea(areas
[a
]);
1657 // Çàãðóçêà ìîíñòðîâ:
1658 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1659 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1660 monsters
:= MapReader
.GetMonsters();
1662 gTotalMonsters
:= 0;
1664 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1665 if (monsters
<> nil) and not gLoadGameMode
then
1667 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1668 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1669 for a
:= 0 to High(monsters
) do
1670 CreateMonster(monsters
[a
]);
1676 if gMapInfo
.SkyName
<> '' then
1678 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1679 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1680 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1682 if FileName
<> '' then
1683 FileName
:= GameDir
+'/wads/'+FileName
1686 FileName
:= g_ExtractWadName(Res
);
1689 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1690 if g_Texture_CreateWAD(BackID
, s
) then
1692 g_Game_SetupScreenSize();
1695 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1700 if gMapInfo
.MusicName
<> '' then
1702 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1703 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1704 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1706 if FileName
<> '' then
1707 FileName
:= GameDir
+'/wads/'+FileName
1710 FileName
:= g_ExtractWadName(Res
);
1713 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1714 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1717 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1720 // Îñòàëüíûå óñòàíâêè:
1728 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1729 if not gLoadGameMode
then
1732 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1738 TriggersTable
:= nil;
1741 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1742 if ok
and (not gLoadGameMode
) then
1744 gMusic
.SetByName(gMapInfo
.MusicName
);
1748 gMusic
.SetByName('');
1750 sfsGCEnable(); // enable releasing unused volumes
1753 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1757 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1760 MapReader
: TMapReader_1
;
1761 Header
: TMapHeaderRec_1
;
1766 FillChar(Result
, SizeOf(Result
), 0);
1767 FileName
:= g_ExtractWadName(Res
);
1769 WAD
:= TWADFile
.Create();
1770 if not WAD
.ReadFile(FileName
) then
1776 //k8: it ignores path again
1777 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1785 MapReader
:= TMapReader_1
.Create();
1787 if not MapReader
.LoadMap(Data
) then
1789 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1790 ZeroMemory(@Header
, SizeOf(Header
));
1791 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1792 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1796 Header
:= MapReader
.GetMapHeader();
1797 Result
.Name
:= Header
.MapName
;
1798 Result
.Description
:= Header
.MapDescription
;
1805 Result
.Author
:= Header
.MapAuthor
;
1806 Result
.Height
:= Header
.Height
;
1807 Result
.Width
:= Header
.Width
;
1810 function g_Map_GetMapsList(WADName
: string): SArray
;
1817 WAD
:= TWADFile
.Create();
1818 if not WAD
.ReadFile(WADName
) then
1823 ResList
:= WAD
.GetMapResources();
1824 if ResList
<> nil then
1826 for a
:= 0 to High(ResList
) do
1828 SetLength(Result
, Length(Result
)+1);
1829 Result
[High(Result
)] := ResList
[a
];
1835 function g_Map_Exist(Res
: string): Boolean;
1838 FileName
, mnn
: string;
1844 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1846 WAD
:= TWADFile
.Create
;
1847 if not WAD
.ReadFile(FileName
) then
1853 ResList
:= WAD
.GetMapResources();
1856 mnn
:= g_ExtractFileName(Res
);
1857 if ResList
<> nil then
1858 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1865 procedure g_Map_Free();
1869 procedure FreePanelArray(var panels
: TPanelArray
);
1874 if panels
<> nil then
1876 for i
:= 0 to High(panels
) do
1889 RespawnPoints
:= nil;
1890 if FlagPoints
[FLAG_RED
] <> nil then
1892 Dispose(FlagPoints
[FLAG_RED
]);
1893 FlagPoints
[FLAG_RED
] := nil;
1895 if FlagPoints
[FLAG_BLUE
] <> nil then
1897 Dispose(FlagPoints
[FLAG_BLUE
]);
1898 FlagPoints
[FLAG_BLUE
] := nil;
1900 //DOMFlagPoints := nil;
1904 if Textures
<> nil then
1906 for a
:= 0 to High(Textures
) do
1907 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1908 if Textures
[a
].Anim
then
1909 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1911 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1912 e_DeleteTexture(Textures
[a
].TextureID
);
1917 FreePanelArray(gWalls
);
1918 FreePanelArray(gRenderBackgrounds
);
1919 FreePanelArray(gRenderForegrounds
);
1920 FreePanelArray(gWater
);
1921 FreePanelArray(gAcid1
);
1922 FreePanelArray(gAcid2
);
1923 FreePanelArray(gSteps
);
1924 FreePanelArray(gLifts
);
1925 FreePanelArray(gBlockMon
);
1927 if BackID
<> DWORD(-1) then
1931 e_DeleteTexture(BackID
);
1932 BackID
:= DWORD(-1);
1935 g_Game_StopAllSounds(False);
1937 g_Sound_Delete(gMapInfo
.MusicName
);
1939 gMapInfo
.Name
:= '';
1940 gMapInfo
.Description
:= '';
1941 gMapInfo
.MusicName
:= '';
1942 gMapInfo
.Height
:= 0;
1943 gMapInfo
.Width
:= 0;
1951 procedure g_Map_Update();
1957 procedure UpdatePanelArray(var panels
: TPanelArray
);
1962 if panels
<> nil then
1963 for i
:= 0 to High(panels
) do
1968 UpdatePanelArray(gWalls
);
1969 UpdatePanelArray(gRenderBackgrounds
);
1970 UpdatePanelArray(gRenderForegrounds
);
1971 UpdatePanelArray(gWater
);
1972 UpdatePanelArray(gAcid1
);
1973 UpdatePanelArray(gAcid2
);
1974 UpdatePanelArray(gSteps
);
1976 if gGameSettings
.GameMode
= GM_CTF
then
1978 for a
:= FLAG_RED
to FLAG_BLUE
do
1979 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1982 if gFlags
[a
].Animation
<> nil then
1983 gFlags
[a
].Animation
.Update();
1985 m
:= g_Obj_Move(@Obj
, True, True);
1987 if gTime
mod (GAME_TICK
*2) <> 0 then
1990 // Ñîïðîòèâëåíèå âîçäóõà:
1991 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1993 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1994 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1997 gFlags
[a
].CaptureTime
:= 0;
1998 if a
= FLAG_RED
then
1999 s
:= _lc
[I_PLAYER_FLAG_RED
]
2001 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2002 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2004 if g_Game_IsNet
then
2005 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2012 // Èãðîê áåðåò ôëàã:
2013 if gPlayers
<> nil then
2015 j
:= Random(Length(gPlayers
)) - 1;
2017 for d
:= 0 to High(gPlayers
) do
2020 if j
> High(gPlayers
) then
2023 if gPlayers
[j
] <> nil then
2024 if gPlayers
[j
].Live
and
2025 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2027 if gPlayers
[j
].GetFlag(a
) then
2038 procedure g_Map_DrawPanels (PanelType
: Word);
2040 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2044 if (panels
<> nil) then
2046 // alas, no visible set
2047 for idx
:= 0 to High(panels
) do
2049 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2056 PANEL_WALL
: DrawPanels(gWalls
);
2057 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2058 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2059 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2060 PANEL_WATER
: DrawPanels(gWater
);
2061 PANEL_ACID1
: DrawPanels(gAcid1
);
2062 PANEL_ACID2
: DrawPanels(gAcid2
);
2063 PANEL_STEP
: DrawPanels(gSteps
);
2069 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2071 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2073 result
:= false; // don't stop, ever
2074 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2075 gDrawPanelList
.insert(pan
);
2080 //tagmask := panelTypeToTag(PanelType);
2082 {if gdbg_map_use_tree_draw then
2084 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2088 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2090 // list will be rendered in `g_game.DrawPlayer()`
2094 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2096 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2098 result
:= false; // don't stop, ever
2099 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2103 {if gdbg_map_use_tree_draw then
2105 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2109 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2114 procedure g_Map_DrawBack(dx
, dy
: Integer);
2116 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2117 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2119 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2122 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2123 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2129 if WordBool(PanelType
and PANEL_WALL
) then
2130 if gWalls
<> nil then
2135 if gWalls
[a
].Enabled
and
2136 g_Collide(X
, Y
, Width
, Height
,
2137 gWalls
[a
].X
, gWalls
[a
].Y
,
2138 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2145 if WordBool(PanelType
and PANEL_WATER
) then
2146 if gWater
<> nil then
2151 if g_Collide(X
, Y
, Width
, Height
,
2152 gWater
[a
].X
, gWater
[a
].Y
,
2153 gWater
[a
].Width
, gWater
[a
].Height
) then
2160 if WordBool(PanelType
and PANEL_ACID1
) then
2161 if gAcid1
<> nil then
2166 if g_Collide(X
, Y
, Width
, Height
,
2167 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2168 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2175 if WordBool(PanelType
and PANEL_ACID2
) then
2176 if gAcid2
<> nil then
2181 if g_Collide(X
, Y
, Width
, Height
,
2182 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2183 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2190 if WordBool(PanelType
and PANEL_STEP
) then
2191 if gSteps
<> nil then
2196 if g_Collide(X
, Y
, Width
, Height
,
2197 gSteps
[a
].X
, gSteps
[a
].Y
,
2198 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2205 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2206 if gLifts
<> nil then
2211 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2212 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2213 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2214 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2215 g_Collide(X
, Y
, Width
, Height
,
2216 gLifts
[a
].X
, gLifts
[a
].Y
,
2217 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2224 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2225 if gBlockMon
<> nil then
2227 h
:= High(gBlockMon
);
2231 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2232 g_Collide(X
, Y
, Width
, Height
,
2233 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2234 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2242 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2246 function checkPanels (constref panels
: TPanelArray
): Boolean;
2251 if panels
= nil then exit
;
2252 for a
:= 0 to High(panels
) do
2254 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2257 texid
:= panels
[a
].GetTextureID();
2264 texid
:= TEXTURE_NONE
;
2266 if not checkPanels(gWater
) then
2267 if not checkPanels(gAcid1
) then
2268 if not checkPanels(gAcid2
) then exit
;
2273 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2275 SlowMask
= GridTagLift
or GridTagBlockMon
;
2276 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2279 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2281 result := pan.Enabled;
2286 if ((tag
and GridTagLift
) <> 0) then
2289 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2290 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2291 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2292 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2293 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2297 if ((tag
and GridTagBlockMon
) <> 0) then
2299 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2304 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2305 result
:= true; // i found her!
2309 tagmask
: Integer = 0;
2311 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2312 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2313 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2314 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2315 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2316 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2317 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2319 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2321 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2322 if gdbg_map_use_accel_coldet
then
2324 {if gdbg_map_use_tree_coldet then
2326 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2327 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2328 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2330 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2331 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2336 if (Width
= 1) and (Height
= 1) then
2338 if ((tagmask
and SlowMask
) <> 0) then
2341 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2346 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2351 if ((tagmask
and SlowMask
) <> 0) then
2354 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2359 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2366 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2368 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2372 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2374 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2377 // slightly different from the old code, but meh...
2378 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2380 result
:= false; // don't stop, ever
2381 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2384 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2385 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2386 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2389 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2391 texid
:= pan
.GetTextureID();
2392 // water? water has the highest priority, so stop right here
2393 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2395 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2397 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2401 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2402 if gdbg_map_use_accel_coldet
then
2404 texid
:= TEXTURE_NONE
;
2405 {if gdbg_map_use_tree_coldet then
2407 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2411 if (Width
= 1) and (Height
= 1) then
2413 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2417 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2424 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2426 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2430 procedure g_Map_EnableWall(ID
: DWORD
);
2435 pan
.Enabled
:= True;
2436 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2438 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2439 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2440 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2442 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2444 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2445 //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);
2449 procedure g_Map_DisableWall(ID
: DWORD
);
2454 pan
.Enabled
:= False;
2455 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2457 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2458 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2460 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2462 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2463 //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);
2467 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2472 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2475 tp
:= gRenderForegrounds
[ID
];
2477 tp
:= gRenderBackgrounds
[ID
];
2490 tp
.NextTexture(AnimLoop
);
2491 if g_Game_IsServer
and g_Game_IsNet
then
2492 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2495 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2497 if gLifts
[ID
].LiftType
= t
then
2504 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2505 //TODO: make separate lift tags, and change tag here
2507 if LiftType
= 0 then
2508 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2509 else if LiftType
= 1 then
2510 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2511 else if LiftType
= 2 then
2512 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2513 else if LiftType
= 3 then
2514 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2516 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2520 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2523 PointsArray
: Array of TRespawnPoint
;
2526 SetLength(PointsArray
, 0);
2528 if RespawnPoints
= nil then
2531 for a
:= 0 to High(RespawnPoints
) do
2532 if RespawnPoints
[a
].PointType
= PointType
then
2534 SetLength(PointsArray
, Length(PointsArray
)+1);
2535 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2538 if PointsArray
= nil then
2541 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2545 function g_Map_GetPointCount(PointType
: Byte): Word;
2551 if RespawnPoints
= nil then
2554 for a
:= 0 to High(RespawnPoints
) do
2555 if RespawnPoints
[a
].PointType
= PointType
then
2556 Result
:= Result
+ 1;
2559 function g_Map_HaveFlagPoints(): Boolean;
2561 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2564 procedure g_Map_ResetFlag(Flag
: Byte);
2566 with gFlags
[Flag
] do
2572 Direction
:= D_LEFT
;
2573 State
:= FLAG_STATE_NONE
;
2574 if FlagPoints
[Flag
] <> nil then
2576 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2577 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2578 Direction
:= FlagPoints
[Flag
]^.Direction
;
2579 State
:= FLAG_STATE_NORMAL
;
2585 procedure g_Map_DrawFlags();
2588 Mirror
: TMirrorType
;
2590 if gGameSettings
.GameMode
<> GM_CTF
then
2593 for i
:= FLAG_RED
to FLAG_BLUE
do
2595 if State
<> FLAG_STATE_CAPTURED
then
2597 if State
= FLAG_STATE_NONE
then
2600 if Direction
= D_LEFT
then
2602 Mirror
:= M_HORIZONTAL
;
2611 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2613 if g_debug_Frames
then
2615 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2617 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2618 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2624 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2631 procedure SavePanelArray(var panels
: TPanelArray
);
2633 PAMem
: TBinMemoryWriter
;
2636 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2637 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2640 while i
< Length(panels
) do
2642 if panels
[i
].SaveIt
then
2646 // Ñîõðàíÿåì ïàíåëü:
2647 panels
[i
].SaveState(PAMem
);
2652 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2653 PAMem
.SaveToMemory(Mem
);
2657 procedure SaveFlag(flag
: PFlag
);
2660 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2662 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2663 Mem
.WriteByte(flag
^.RespawnType
);
2665 Mem
.WriteByte(flag
^.State
);
2666 // Íàïðàâëåíèå ôëàãà:
2667 if flag
^.Direction
= D_LEFT
then
2673 Obj_SaveState(@flag
^.Obj
, Mem
);
2677 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2679 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2680 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2681 SavePanelArray(gWalls
);
2682 // Ñîõðàíÿåì ïàíåëè ôîíà:
2683 SavePanelArray(gRenderBackgrounds
);
2684 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2685 SavePanelArray(gRenderForegrounds
);
2686 // Ñîõðàíÿåì ïàíåëè âîäû:
2687 SavePanelArray(gWater
);
2688 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2689 SavePanelArray(gAcid1
);
2690 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2691 SavePanelArray(gAcid2
);
2692 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2693 SavePanelArray(gSteps
);
2694 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2695 SavePanelArray(gLifts
);
2698 ///// Ñîõðàíÿåì ìóçûêó: /////
2699 // Ñèãíàòóðà ìóçûêè:
2700 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2703 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2704 if gMusic
.NoMusic
then
2708 Mem
.WriteString(str
, 64);
2709 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2710 dw
:= gMusic
.GetPosition();
2712 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2713 boo
:= gMusic
.SpecPause
;
2714 Mem
.WriteBoolean(boo
);
2717 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2718 Mem
.WriteInt(gTotalMonsters
);
2721 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2722 if gGameSettings
.GameMode
= GM_CTF
then
2724 // Ôëàã Êðàñíîé êîìàíäû:
2725 SaveFlag(@gFlags
[FLAG_RED
]);
2726 // Ôëàã Ñèíåé êîìàíäû:
2727 SaveFlag(@gFlags
[FLAG_BLUE
]);
2731 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2732 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2734 // Î÷êè Êðàñíîé êîìàíäû:
2735 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2736 // Î÷êè Ñèíåé êîìàíäû:
2737 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2742 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2749 procedure LoadPanelArray(var panels
: TPanelArray
);
2751 PAMem
: TBinMemoryReader
;
2754 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2755 PAMem
:= TBinMemoryReader
.Create();
2756 PAMem
.LoadFromMemory(Mem
);
2758 for i
:= 0 to Length(panels
)-1 do
2759 if panels
[i
].SaveIt
then
2765 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2767 // Çàãðóæàåì ïàíåëü:
2768 panels
[i
].LoadState(PAMem
);
2771 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2775 procedure LoadFlag(flag
: PFlag
);
2779 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2781 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2783 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2784 Mem
.ReadByte(flag
^.RespawnType
);
2786 Mem
.ReadByte(flag
^.State
);
2787 // Íàïðàâëåíèå ôëàãà:
2790 flag
^.Direction
:= D_LEFT
2792 flag
^.Direction
:= D_RIGHT
;
2794 Obj_LoadState(@flag
^.Obj
, Mem
);
2801 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2802 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2803 LoadPanelArray(gWalls
);
2804 // Çàãðóæàåì ïàíåëè ôîíà:
2805 LoadPanelArray(gRenderBackgrounds
);
2806 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2807 LoadPanelArray(gRenderForegrounds
);
2808 // Çàãðóæàåì ïàíåëè âîäû:
2809 LoadPanelArray(gWater
);
2810 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2811 LoadPanelArray(gAcid1
);
2812 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2813 LoadPanelArray(gAcid2
);
2814 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2815 LoadPanelArray(gSteps
);
2816 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2817 LoadPanelArray(gLifts
);
2820 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2824 ///// Çàãðóæàåì ìóçûêó: /////
2825 // Ñèãíàòóðà ìóçûêè:
2827 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2829 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2832 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2833 Mem
.ReadString(str
);
2834 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2836 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2837 Mem
.ReadBoolean(boo
);
2838 // Çàïóñêàåì ýòó ìóçûêó:
2839 gMusic
.SetByName(str
);
2840 gMusic
.SpecPause
:= boo
;
2843 gMusic
.SetPosition(dw
);
2846 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2847 Mem
.ReadInt(gTotalMonsters
);
2850 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2851 if gGameSettings
.GameMode
= GM_CTF
then
2853 // Ôëàã Êðàñíîé êîìàíäû:
2854 LoadFlag(@gFlags
[FLAG_RED
]);
2855 // Ôëàã Ñèíåé êîìàíäû:
2856 LoadFlag(@gFlags
[FLAG_BLUE
]);
2860 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2861 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2863 // Î÷êè Êðàñíîé êîìàíäû:
2864 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2865 // Î÷êè Ñèíåé êîìàíäû:
2866 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2871 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2876 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2877 Arr
:= PanelByID
[PanelID
].PWhere
^;
2878 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2879 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2883 // trace liquid, stepping by `dx` and `dy`
2884 // return last seen liquid coords, and `false` if we're started outside of the liquid
2885 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2887 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2891 // started outside of the liquid?
2892 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2893 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2899 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit