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 wall index in `gWalls` or -1
96 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil; log
: Boolean=false): 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 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
185 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
187 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
193 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
194 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
195 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
196 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
198 ImagingTypes
, Imaging
, ImagingUtility
,
199 ImagingGif
, ImagingNetworkGraphics
;
202 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
203 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
204 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
208 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
211 function panelTypeToTag (panelType
: Word): Integer;
214 PANEL_WALL
: result
:= GridTagWall
; // gWalls
215 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
216 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
217 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
218 PANEL_WATER
: result
:= GridTagWater
; // gWater
219 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
220 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
221 PANEL_STEP
: result
:= GridTagStep
; // gSteps
222 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
223 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
224 else result
:= GridTagInvalid
;
229 function dplLess (a
, b
: TObject
): Boolean;
235 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
236 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
237 result
:= (pa
.arrIdx
< pb
.arrIdx
);
240 procedure dplClear ();
242 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
248 PWhere
: ^TPanelArray
;
253 PanelById
: array of TPanelID
;
254 Textures
: TLevelTextureArray
;
255 RespawnPoints
: Array of TRespawnPoint
;
256 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
257 //DOMFlagPoints: Array of TFlagPoint;
258 mapGrid
: TPanelGrid
= nil;
261 procedure g_Map_ProfilersBegin ();
263 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
264 profMapCollision
.mainBegin(g_profile_collision
);
266 if g_profile_collision
then
268 profMapCollision
.sectionBegin('*solids');
269 profMapCollision
.sectionEnd();
270 profMapCollision
.sectionBegin('liquids');
271 profMapCollision
.sectionEnd();
275 procedure g_Map_ProfilersEnd ();
277 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
281 // wall index in `gWalls` or -1
282 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil; log
: Boolean=false): Boolean;
286 mapGrid
.dbgShowTraceLog
:= log
;
287 result
:= (mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
)) <> nil);
288 mapGrid
.dbgShowTraceLog
:= false;
291 if (hitx
<> nil) then hitx
^ := ex
;
292 if (hity
<> nil) then hity
^ := ey
;
296 if (hitx
<> nil) then hitx
^ := x1
;
297 if (hity
<> nil) then hity
^ := y1
;
302 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
304 function checker (pan
: TPanel
; tag
: Integer): Boolean;
307 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
309 result := pan.Enabled; // stop if wall is enabled
314 if ((tag
and GridTagLift
) <> 0) then
316 // stop if the lift of the right type
318 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
319 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
320 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
321 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
325 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
329 tagmask
: Integer = 0;
333 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
334 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
335 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
336 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
337 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
338 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
339 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
341 if (tagmask
= 0) then exit
;// just in case
342 if ((tagmask
and GridTagLift
) <> 0) then
345 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
350 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
355 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
357 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
358 (Texture
= TEXTURE_NAME_ACID1
) or
359 (Texture
= TEXTURE_NAME_ACID2
);
362 procedure CreateDoorMap();
364 PanelArray
: Array of record
370 a
, b
, c
, m
, i
, len
: Integer;
378 SetLength(PanelArray
, len
);
380 for a
:= 0 to High(gWalls
) do
381 if gWalls
[a
].Door
then
383 PanelArray
[i
].X
:= gWalls
[a
].X
;
384 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
385 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
386 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
387 PanelArray
[i
].Active
:= True;
388 PanelArray
[i
].PanelID
:= a
;
394 SetLength(PanelArray
, len
);
405 SetLength(gDoorMap
, 0);
407 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
410 if PanelArray
[a
].Active
then
412 PanelArray
[a
].Active
:= False;
413 m
:= Length(gDoorMap
);
414 SetLength(gDoorMap
, m
+1);
415 SetLength(gDoorMap
[m
], 1);
416 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
424 if PanelArray
[b
].Active
then
425 for c
:= 0 to High(gDoorMap
[m
]) do
426 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
427 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
428 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
429 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
430 gWalls
[gDoorMap
[m
, c
]].X
,
431 gWalls
[gDoorMap
[m
, c
]].Y
,
432 gWalls
[gDoorMap
[m
, c
]].Width
,
433 gWalls
[gDoorMap
[m
, c
]].Height
) then
435 PanelArray
[b
].Active
:= False;
436 SetLength(gDoorMap
[m
],
437 Length(gDoorMap
[m
])+1);
438 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
444 g_Game_StepLoading();
450 procedure CreateLiftMap();
452 PanelArray
: Array of record
457 a
, b
, c
, len
, i
, j
: Integer;
463 len
:= Length(gLifts
);
464 SetLength(PanelArray
, len
);
466 for a
:= 0 to len
-1 do
468 PanelArray
[a
].X
:= gLifts
[a
].X
;
469 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
470 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
471 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
472 PanelArray
[a
].Active
:= True;
475 SetLength(gLiftMap
, len
);
478 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
480 for a
:= 0 to len
-1 do
481 if PanelArray
[a
].Active
then
483 PanelArray
[a
].Active
:= False;
484 SetLength(gLiftMap
[i
], 32);
492 for b
:= 0 to len
-1 do
493 if PanelArray
[b
].Active
then
495 if g_CollideAround(PanelArray
[b
].X
,
498 PanelArray
[b
].Height
,
499 PanelArray
[gLiftMap
[i
, c
]].X
,
500 PanelArray
[gLiftMap
[i
, c
]].Y
,
501 PanelArray
[gLiftMap
[i
, c
]].Width
,
502 PanelArray
[gLiftMap
[i
, c
]].Height
) then
504 PanelArray
[b
].Active
:= False;
506 if j
> High(gLiftMap
[i
]) then
507 SetLength(gLiftMap
[i
],
508 Length(gLiftMap
[i
])+32);
517 SetLength(gLiftMap
[i
], j
+1);
520 g_Game_StepLoading();
523 SetLength(gLiftMap
, i
);
528 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
529 CurTex
: Integer; sav
: Boolean): Integer;
532 panels
: ^TPanelArray
;
536 case PanelRec
.PanelType
of
537 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
540 panels
:= @gRenderBackgrounds
;
542 panels
:= @gRenderForegrounds
;
551 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
554 panels
:= @gBlockMon
;
559 len
:= Length(panels
^);
560 SetLength(panels
^, len
+ 1);
562 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
563 panels
^[len
].arrIdx
:= len
;
564 panels
^[len
].proxyId
:= -1;
565 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
567 panels
^[len
].SaveIt
:= True;
571 len
:= Length(PanelByID
);
572 SetLength(PanelByID
, len
+ 1);
573 PanelByID
[len
].PWhere
:= panels
;
574 PanelByID
[len
].PArrID
:= Result
;
577 function CreateNullTexture(RecName
: String): Integer;
579 SetLength(Textures
, Length(Textures
)+1);
580 result
:= High(Textures
);
582 with Textures
[High(Textures
)] do
584 TextureName
:= RecName
;
588 TextureID
:= TEXTURE_NONE
;
592 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
595 TextureData
: Pointer;
596 WADName
, txname
: String;
597 a
, ResLength
: Integer;
601 if Textures
<> nil then
602 for a
:= 0 to High(Textures
) do
603 if Textures
[a
].TextureName
= RecName
then
604 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
609 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
610 if (RecName
= TEXTURE_NAME_WATER
) or
611 (RecName
= TEXTURE_NAME_ACID1
) or
612 (RecName
= TEXTURE_NAME_ACID2
) then
614 SetLength(Textures
, Length(Textures
)+1);
616 with Textures
[High(Textures
)] do
618 TextureName
:= RecName
;
620 if TextureName
= TEXTURE_NAME_WATER
then
621 TextureID
:= TEXTURE_SPECIAL_WATER
623 if TextureName
= TEXTURE_NAME_ACID1
then
624 TextureID
:= TEXTURE_SPECIAL_ACID1
626 if TextureName
= TEXTURE_NAME_ACID2
then
627 TextureID
:= TEXTURE_SPECIAL_ACID2
;
632 result
:= High(Textures
);
636 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
637 WADName
:= g_ExtractWadName(RecName
);
639 WAD
:= TWADFile
.Create();
641 if WADName
<> '' then
642 WADName
:= GameDir
+'/wads/'+WADName
646 WAD
.ReadFile(WADName
);
650 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
652 FreeMem(TextureData);
653 RecName := 'COMMON\ALIEN';
657 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
659 SetLength(Textures
, Length(Textures
)+1);
660 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
662 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
663 @Textures
[High(Textures
)].Width
,
664 @Textures
[High(Textures
)].Height
);
665 FreeMem(TextureData
);
666 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
667 Textures
[High(Textures
)].Anim
:= False;
669 result
:= High(Textures
);
671 else // Íåò òàêîãî ðåóñðñà â WAD'å
673 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
676 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
677 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
684 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
687 TextureWAD
: PChar = nil;
688 TextData
: Pointer = nil;
689 TextureData
: Pointer = nil;
693 TextureResource
: String;
694 _width
, _height
, _framecount
, _speed
: Integer;
695 _backanimation
: Boolean;
697 ia
: TDynImageDataArray
= nil;
698 f
, c
, frdelay
, frloop
: Integer;
702 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
704 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
705 WADName
:= g_ExtractWadName(RecName
);
707 WAD
:= TWADFile
.Create();
709 if WADName
<> '' then
710 WADName
:= GameDir
+'/wads/'+WADName
714 WAD
.ReadFile(WADName
);
716 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
720 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
721 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
727 if WADName = Map then
729 //FreeMem(TextureWAD);
730 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
736 if ResLength
< 6 then
738 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
742 // ýòî ïòèöà? ýòî ñàìîë¸ò?
743 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
744 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
746 // íåò, ýòî ñóïåðìåí!
747 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
749 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
753 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
754 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
756 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
760 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
762 TextureResource
:= cfg
.ReadStr('', 'resource', '');
763 if TextureResource
= '' then
765 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
769 _width
:= cfg
.ReadInt('', 'framewidth', 0);
770 _height
:= cfg
.ReadInt('', 'frameheight', 0);
771 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
772 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
773 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
778 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
779 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
781 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
788 SetLength(Textures
, Length(Textures
)+1);
789 with Textures
[High(Textures
)] do
791 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
792 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
794 TextureName
:= RecName
;
798 FramesCount
:= _framecount
;
800 result
:= High(Textures
);
804 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
810 // try animated image
812 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
813 if length(imgfmt) = 0 then
815 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
819 GlobalMetadata
.ClearMetaItems();
820 GlobalMetadata
.ClearMetaItemsForSaving();
821 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
823 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
826 if length(ia
) = 0 then
828 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
835 _width
:= ia
[0].width
;
836 _height
:= ia
[0].height
;
837 _framecount
:= length(ia
);
839 _backanimation
:= false;
842 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
844 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
846 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
848 if f
< 0 then f
:= 0;
851 if c
< 13 then c
:= 0 else c
:= 1;
853 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
858 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
860 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
862 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
864 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
868 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
869 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
870 f
:= ord(_backanimation
);
871 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
);
873 SetLength(Textures
, Length(Textures
)+1);
874 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
875 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
877 Textures
[High(Textures
)].TextureName
:= RecName
;
878 Textures
[High(Textures
)].Width
:= _width
;
879 Textures
[High(Textures
)].Height
:= _height
;
880 Textures
[High(Textures
)].Anim
:= True;
881 Textures
[High(Textures
)].FramesCount
:= length(ia
);
882 Textures
[High(Textures
)].Speed
:= _speed
;
883 result
:= High(Textures
);
884 //writeln(' CREATED!');
888 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
892 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
895 if TextureWAD
<> nil then FreeMem(TextureWAD
);
896 if TextData
<> nil then FreeMem(TextData
);
897 if TextureData
<> nil then FreeMem(TextureData
);
901 procedure CreateItem(Item
: TItemRec_1
);
903 if g_Game_IsClient
then Exit
;
905 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
906 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
909 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
910 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
913 procedure CreateArea(Area
: TAreaRec_1
);
918 case Area
.AreaType
of
919 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
920 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
922 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
923 with RespawnPoints
[High(RespawnPoints
)] do
927 Direction
:= TDirection(Area
.Direction
);
929 case Area
.AreaType
of
930 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
931 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
932 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
933 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
934 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
939 AREA_REDFLAG
, AREA_BLUEFLAG
:
941 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
943 if FlagPoints
[a
] <> nil then Exit
;
947 with FlagPoints
[a
]^ do
949 X
:= Area
.X
-FLAGRECT
.X
;
950 Y
:= Area
.Y
-FLAGRECT
.Y
;
951 Direction
:= TDirection(Area
.Direction
);
957 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
958 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
961 Animation
:= TAnimation
.Create(id
, True, 8);
962 Obj
.Rect
:= FLAGRECT
;
970 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
971 with DOMFlagPoints[High(DOMFlagPoints)] do
975 Direction := TDirection(Area.Direction);
978 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
983 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
987 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
993 Width
:= Trigger
.Width
;
994 Height
:= Trigger
.Height
;
995 Enabled
:= ByteBool(Trigger
.Enabled
);
996 TexturePanel
:= Trigger
.TexturePanel
;
997 TexturePanelType
:= fTexturePanel1Type
;
998 ShotPanelType
:= fTexturePanel2Type
;
999 TriggerType
:= Trigger
.TriggerType
;
1000 ActivateType
:= Trigger
.ActivateType
;
1001 Keys
:= Trigger
.Keys
;
1002 Data
.Default
:= Trigger
.DATA
;
1005 g_Triggers_Create(_trigger
);
1008 procedure CreateMonster(monster
: TMonsterRec_1
);
1013 if g_Game_IsClient
then Exit
;
1015 if (gGameSettings
.GameType
= GT_SINGLE
)
1016 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1018 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1020 if gTriggers
<> nil then
1022 for a
:= 0 to High(gTriggers
) do
1024 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1026 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1031 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1035 procedure g_Map_ReAdd_DieTriggers();
1037 function monsDieTrig (mon
: TMonster
): Boolean;
1041 result
:= false; // don't stop
1042 mon
.ClearTriggers();
1043 for a
:= 0 to High(gTriggers
) do
1045 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1047 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1053 if g_Game_IsClient
then Exit
;
1055 g_Mons_ForEach(monsDieTrig
);
1058 function extractWadName(resourceName
: string): string;
1062 posN
:= Pos(':', resourceName
);
1064 Result
:= Copy(resourceName
, 0, posN
-1)
1069 procedure addResToExternalResList(res
: string);
1071 res
:= extractWadName(res
);
1072 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1073 gExternalResources
.Add(res
);
1076 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1078 textures
: TTexturesRec1Array
;
1079 mapHeader
: TMapHeaderRec_1
;
1081 resFile
: String = '';
1083 if gExternalResources
= nil then
1084 gExternalResources
:= TStringList
.Create
;
1086 gExternalResources
.Clear
;
1087 textures
:= mapReader
.GetTextures();
1088 for i
:= 0 to High(textures
) do
1090 addResToExternalResList(resFile
);
1095 mapHeader
:= mapReader
.GetMapHeader
;
1097 addResToExternalResList(mapHeader
.MusicName
);
1098 addResToExternalResList(mapHeader
.SkyName
);
1102 procedure mapCreateGrid ();
1104 mapX0
: Integer = $3fffffff;
1105 mapY0
: Integer = $3fffffff;
1106 mapX1
: Integer = -$3fffffff;
1107 mapY1
: Integer = -$3fffffff;
1109 procedure calcBoundingBox (constref panels
: TPanelArray
);
1114 for idx
:= 0 to High(panels
) do
1117 if not pan
.visvalid
then continue
;
1118 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1119 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1120 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1121 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1122 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1126 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1131 tag
:= panelTypeToTag(tag
);
1132 for idx
:= High(panels
) downto 0 do
1136 if not pan
.visvalid
then continue
;
1137 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1138 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1139 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1140 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1141 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
1143 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
])]), MSG_NOTIFY
);
1153 calcBoundingBox(gWalls
);
1154 calcBoundingBox(gRenderBackgrounds
);
1155 calcBoundingBox(gRenderForegrounds
);
1156 calcBoundingBox(gWater
);
1157 calcBoundingBox(gAcid1
);
1158 calcBoundingBox(gAcid2
);
1159 calcBoundingBox(gSteps
);
1160 calcBoundingBox(gLifts
);
1161 calcBoundingBox(gBlockMon
);
1163 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1165 mapGrid
:= TPanelGrid
.Create(mapX0
-512, mapY0
-512, mapX1
-mapX0
+1+512*2, mapY1
-mapY0
+1+512*2);
1167 addPanelsToGrid(gWalls
, PANEL_WALL
);
1168 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1169 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1170 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1171 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1172 addPanelsToGrid(gWater
, PANEL_WATER
);
1173 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1174 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1175 addPanelsToGrid(gSteps
, PANEL_STEP
);
1176 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1177 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1179 mapGrid
.dumpStats();
1181 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1185 function g_Map_Load(Res
: String): Boolean;
1187 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1188 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1191 MapReader
: TMapReader_1
;
1192 Header
: TMapHeaderRec_1
;
1193 _textures
: TTexturesRec1Array
;
1194 _texnummap
: array of Integer; // `_textures` -> `Textures`
1195 panels
: TPanelsRec1Array
;
1196 items
: TItemsRec1Array
;
1197 monsters
: TMonsterRec1Array
;
1198 areas
: TAreasRec1Array
;
1199 triggers
: TTriggersRec1Array
;
1200 a
, b
, c
, k
: Integer;
1202 AddTextures
: TAddTextureArray
;
1203 texture
: TTextureRec_1
;
1204 TriggersTable
: Array of record
1205 TexturePanel
: Integer;
1210 FileName
, mapResName
, s
, TexName
: String;
1213 ok
, isAnim
, trigRef
: Boolean;
1214 CurTex
, ntn
: Integer;
1223 gMapInfo
.Map
:= Res
;
1224 TriggersTable
:= nil;
1225 FillChar(texture
, SizeOf(texture
), 0);
1227 sfsGCDisable(); // temporary disable removing of temporary volumes
1230 FileName
:= g_ExtractWadName(Res
);
1231 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1232 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1234 WAD
:= TWADFile
.Create();
1235 if not WAD
.ReadFile(FileName
) then
1237 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1241 //k8: why loader ignores path here?
1242 mapResName
:= g_ExtractFileName(Res
);
1243 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1245 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1253 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1254 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1255 MapReader
:= TMapReader_1
.Create();
1257 if not MapReader
.LoadMap(Data
) then
1259 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1266 generateExternalResourcesList(MapReader
);
1267 // Çàãðóçêà òåêñòóð:
1268 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1269 _textures
:= MapReader
.GetTextures();
1272 // Äîáàâëåíèå òåêñòóð â Textures[]:
1273 if _textures
<> nil then
1275 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1276 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1277 SetLength(_texnummap
, length(_textures
));
1279 for a
:= 0 to High(_textures
) do
1282 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1283 for b
:= 1 to Length(s
) do
1289 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1290 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1291 // Àíèìèðîâàííàÿ òåêñòóðà:
1292 if ByteBool(_textures
[a
].Anim
) then
1294 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1297 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1298 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1301 else // Îáû÷íàÿ òåêñòóðà:
1302 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1305 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1306 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1309 _texnummap
[a
] := ntn
; // fix texture number
1310 g_Game_StepLoading();
1314 // Çàãðóçêà òðèããåðîâ:
1315 gTriggerClientID
:= 0;
1316 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1317 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1318 triggers
:= MapReader
.GetTriggers();
1320 // Çàãðóçêà ïàíåëåé:
1321 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1322 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1323 panels
:= MapReader
.GetPanels();
1325 // check texture numbers for panels
1326 for a
:= 0 to High(panels
) do
1328 if panels
[a
].TextureNum
> High(_textures
) then
1330 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1334 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1337 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1338 if triggers
<> nil then
1340 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1341 SetLength(TriggersTable
, Length(triggers
));
1342 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1344 for a
:= 0 to High(TriggersTable
) do
1346 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1347 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1349 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1350 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1352 TriggersTable
[a
].LiftPanel
:= -1;
1354 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1355 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1356 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1357 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1359 TriggersTable
[a
].DoorPanel
:= -1;
1361 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1362 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1364 TriggersTable
[a
].ShotPanel
:= -1;
1366 g_Game_StepLoading();
1371 if panels
<> nil then
1373 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1374 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1376 for a
:= 0 to High(panels
) do
1378 SetLength(AddTextures
, 0);
1381 if _textures
<> nil then
1383 texture
:= _textures
[panels
[a
].TextureNum
];
1391 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1392 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1394 if (TriggersTable
<> nil) and (_textures
<> nil) then
1395 for b
:= 0 to High(TriggersTable
) do
1396 if (TriggersTable
[b
].TexturePanel
= a
)
1397 or (TriggersTable
[b
].ShotPanel
= a
) then
1406 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1408 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1411 for c
:= Len
downto 1 do
1419 // Ñïåö-òåêñòóðû çàïðåùåíû:
1420 if g_Map_IsSpecialTexture(s
) then
1423 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1424 ok
:= g_Texture_NumNameFindStart(s
);
1426 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1427 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1430 k
:= NNF_NAME_BEFORE
;
1431 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1432 while ok
or (k
= NNF_NAME_BEFORE
) or
1433 (k
= NNF_NAME_EQUALS
) do
1435 k
:= g_Texture_NumNameFindNext(TexName
);
1437 if (k
= NNF_NAME_BEFORE
) or
1438 (k
= NNF_NAME_AFTER
) then
1440 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1441 if ByteBool(texture
.Anim
) then
1442 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1444 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1446 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1448 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1452 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1454 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1456 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1458 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1462 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1465 for c
:= 0 to High(Textures
) do
1466 if Textures
[c
].TextureName
= TexName
then
1468 SetLength(AddTextures
, Length(AddTextures
)+1);
1469 AddTextures
[High(AddTextures
)].Texture
:= c
;
1470 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1476 if k
= NNF_NAME_EQUALS
then
1478 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1479 SetLength(AddTextures
, Length(AddTextures
)+1);
1480 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1481 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1482 CurTex
:= High(AddTextures
);
1490 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1491 end; // if ok - ññûëàþòñÿ òðèããåðû
1495 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1496 SetLength(AddTextures
, 1);
1497 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1498 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1502 //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);
1504 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1505 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1507 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1508 if TriggersTable
<> nil then
1509 for b
:= 0 to High(TriggersTable
) do
1511 // Òðèããåð äâåðè/ëèôòà:
1512 if (TriggersTable
[b
].LiftPanel
= a
) or
1513 (TriggersTable
[b
].DoorPanel
= a
) then
1514 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1515 // Òðèããåð ñìåíû òåêñòóðû:
1516 if TriggersTable
[b
].TexturePanel
= a
then
1517 triggers
[b
].TexturePanel
:= PanelID
;
1518 // Òðèããåð "Òóðåëü":
1519 if TriggersTable
[b
].ShotPanel
= a
then
1520 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1523 g_Game_StepLoading();
1527 // create map grid, init other grids (for monsters, for example)
1528 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1532 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1533 if (triggers
<> nil) and not gLoadGameMode
then
1535 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1536 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1537 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1538 for a
:= 0 to High(triggers
) do
1540 if triggers
[a
].TexturePanel
<> -1 then
1541 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1544 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1545 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1546 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1549 CreateTrigger(triggers
[a
], b
, c
);
1553 // Çàãðóçêà ïðåäìåòîâ:
1554 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1555 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1556 items
:= MapReader
.GetItems();
1558 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1559 if (items
<> nil) and not gLoadGameMode
then
1561 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1562 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1563 for a
:= 0 to High(items
) do
1564 CreateItem(Items
[a
]);
1567 // Çàãðóçêà îáëàñòåé:
1568 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1569 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1570 areas
:= MapReader
.GetAreas();
1572 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1573 if areas
<> nil then
1575 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1576 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1577 for a
:= 0 to High(areas
) do
1578 CreateArea(areas
[a
]);
1581 // Çàãðóçêà ìîíñòðîâ:
1582 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1583 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1584 monsters
:= MapReader
.GetMonsters();
1586 gTotalMonsters
:= 0;
1588 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1589 if (monsters
<> nil) and not gLoadGameMode
then
1591 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1592 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1593 for a
:= 0 to High(monsters
) do
1594 CreateMonster(monsters
[a
]);
1597 // Çàãðóçêà îïèñàíèÿ êàðòû:
1598 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1599 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1600 Header
:= MapReader
.GetMapHeader();
1606 Name
:= Header
.MapName
;
1607 Description
:= Header
.MapDescription
;
1608 Author
:= Header
.MapAuthor
;
1609 MusicName
:= Header
.MusicName
;
1610 SkyName
:= Header
.SkyName
;
1611 Height
:= Header
.Height
;
1612 Width
:= Header
.Width
;
1616 if gMapInfo
.SkyName
<> '' then
1618 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1619 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1620 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1622 if FileName
<> '' then
1623 FileName
:= GameDir
+'/wads/'+FileName
1626 FileName
:= g_ExtractWadName(Res
);
1629 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1630 if g_Texture_CreateWAD(BackID
, s
) then
1632 g_Game_SetupScreenSize();
1635 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1640 if gMapInfo
.MusicName
<> '' then
1642 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1643 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1644 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1646 if FileName
<> '' then
1647 FileName
:= GameDir
+'/wads/'+FileName
1650 FileName
:= g_ExtractWadName(Res
);
1653 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1654 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1657 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1660 // Îñòàëüíûå óñòàíâêè:
1668 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1669 if not gLoadGameMode
then
1672 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1678 TriggersTable
:= nil;
1681 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1682 if ok
and (not gLoadGameMode
) then
1684 gMusic
.SetByName(gMapInfo
.MusicName
);
1688 gMusic
.SetByName('');
1690 sfsGCEnable(); // enable releasing unused volumes
1693 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1697 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1700 MapReader
: TMapReader_1
;
1701 Header
: TMapHeaderRec_1
;
1706 FillChar(Result
, SizeOf(Result
), 0);
1707 FileName
:= g_ExtractWadName(Res
);
1709 WAD
:= TWADFile
.Create();
1710 if not WAD
.ReadFile(FileName
) then
1716 //k8: it ignores path again
1717 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1725 MapReader
:= TMapReader_1
.Create();
1727 if not MapReader
.LoadMap(Data
) then
1729 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1730 ZeroMemory(@Header
, SizeOf(Header
));
1731 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1732 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1736 Header
:= MapReader
.GetMapHeader();
1737 Result
.Name
:= Header
.MapName
;
1738 Result
.Description
:= Header
.MapDescription
;
1745 Result
.Author
:= Header
.MapAuthor
;
1746 Result
.Height
:= Header
.Height
;
1747 Result
.Width
:= Header
.Width
;
1750 function g_Map_GetMapsList(WADName
: string): SArray
;
1757 WAD
:= TWADFile
.Create();
1758 if not WAD
.ReadFile(WADName
) then
1763 ResList
:= WAD
.GetMapResources();
1764 if ResList
<> nil then
1766 for a
:= 0 to High(ResList
) do
1768 SetLength(Result
, Length(Result
)+1);
1769 Result
[High(Result
)] := ResList
[a
];
1775 function g_Map_Exist(Res
: string): Boolean;
1778 FileName
, mnn
: string;
1784 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1786 WAD
:= TWADFile
.Create
;
1787 if not WAD
.ReadFile(FileName
) then
1793 ResList
:= WAD
.GetMapResources();
1796 mnn
:= g_ExtractFileName(Res
);
1797 if ResList
<> nil then
1798 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1805 procedure g_Map_Free();
1809 procedure FreePanelArray(var panels
: TPanelArray
);
1814 if panels
<> nil then
1816 for i
:= 0 to High(panels
) do
1829 RespawnPoints
:= nil;
1830 if FlagPoints
[FLAG_RED
] <> nil then
1832 Dispose(FlagPoints
[FLAG_RED
]);
1833 FlagPoints
[FLAG_RED
] := nil;
1835 if FlagPoints
[FLAG_BLUE
] <> nil then
1837 Dispose(FlagPoints
[FLAG_BLUE
]);
1838 FlagPoints
[FLAG_BLUE
] := nil;
1840 //DOMFlagPoints := nil;
1844 if Textures
<> nil then
1846 for a
:= 0 to High(Textures
) do
1847 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1848 if Textures
[a
].Anim
then
1849 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1851 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1852 e_DeleteTexture(Textures
[a
].TextureID
);
1857 FreePanelArray(gWalls
);
1858 FreePanelArray(gRenderBackgrounds
);
1859 FreePanelArray(gRenderForegrounds
);
1860 FreePanelArray(gWater
);
1861 FreePanelArray(gAcid1
);
1862 FreePanelArray(gAcid2
);
1863 FreePanelArray(gSteps
);
1864 FreePanelArray(gLifts
);
1865 FreePanelArray(gBlockMon
);
1867 if BackID
<> DWORD(-1) then
1871 e_DeleteTexture(BackID
);
1872 BackID
:= DWORD(-1);
1875 g_Game_StopAllSounds(False);
1877 g_Sound_Delete(gMapInfo
.MusicName
);
1879 gMapInfo
.Name
:= '';
1880 gMapInfo
.Description
:= '';
1881 gMapInfo
.MusicName
:= '';
1882 gMapInfo
.Height
:= 0;
1883 gMapInfo
.Width
:= 0;
1891 procedure g_Map_Update();
1897 procedure UpdatePanelArray(var panels
: TPanelArray
);
1902 if panels
<> nil then
1903 for i
:= 0 to High(panels
) do
1908 UpdatePanelArray(gWalls
);
1909 UpdatePanelArray(gRenderBackgrounds
);
1910 UpdatePanelArray(gRenderForegrounds
);
1911 UpdatePanelArray(gWater
);
1912 UpdatePanelArray(gAcid1
);
1913 UpdatePanelArray(gAcid2
);
1914 UpdatePanelArray(gSteps
);
1916 if gGameSettings
.GameMode
= GM_CTF
then
1918 for a
:= FLAG_RED
to FLAG_BLUE
do
1919 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1922 if gFlags
[a
].Animation
<> nil then
1923 gFlags
[a
].Animation
.Update();
1925 m
:= g_Obj_Move(@Obj
, True, True);
1927 if gTime
mod (GAME_TICK
*2) <> 0 then
1930 // Ñîïðîòèâëåíèå âîçäóõà:
1931 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1933 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1934 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1937 gFlags
[a
].CaptureTime
:= 0;
1938 if a
= FLAG_RED
then
1939 s
:= _lc
[I_PLAYER_FLAG_RED
]
1941 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1942 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1944 if g_Game_IsNet
then
1945 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1952 // Èãðîê áåðåò ôëàã:
1953 if gPlayers
<> nil then
1955 j
:= Random(Length(gPlayers
)) - 1;
1957 for d
:= 0 to High(gPlayers
) do
1960 if j
> High(gPlayers
) then
1963 if gPlayers
[j
] <> nil then
1964 if gPlayers
[j
].Live
and
1965 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1967 if gPlayers
[j
].GetFlag(a
) then
1978 procedure g_Map_DrawPanels (PanelType
: Word);
1980 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1984 if (panels
<> nil) then
1986 // alas, no visible set
1987 for idx
:= 0 to High(panels
) do
1989 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1996 PANEL_WALL
: DrawPanels(gWalls
);
1997 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1998 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1999 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2000 PANEL_WATER
: DrawPanels(gWater
);
2001 PANEL_ACID1
: DrawPanels(gAcid1
);
2002 PANEL_ACID2
: DrawPanels(gAcid2
);
2003 PANEL_STEP
: DrawPanels(gSteps
);
2009 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2011 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2013 result
:= false; // don't stop, ever
2014 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2015 gDrawPanelList
.insert(pan
);
2020 //tagmask := panelTypeToTag(PanelType);
2022 {if gdbg_map_use_tree_draw then
2024 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2028 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
, true);
2030 // list will be rendered in `g_game.DrawPlayer()`
2034 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2036 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2038 result
:= false; // don't stop, ever
2039 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2043 {if gdbg_map_use_tree_draw then
2045 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2049 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
), true);
2054 procedure g_Map_DrawBack(dx
, dy
: Integer);
2056 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2057 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2059 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2062 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2063 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2069 if WordBool(PanelType
and PANEL_WALL
) then
2070 if gWalls
<> nil then
2075 if gWalls
[a
].Enabled
and
2076 g_Collide(X
, Y
, Width
, Height
,
2077 gWalls
[a
].X
, gWalls
[a
].Y
,
2078 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2085 if WordBool(PanelType
and PANEL_WATER
) then
2086 if gWater
<> nil then
2091 if g_Collide(X
, Y
, Width
, Height
,
2092 gWater
[a
].X
, gWater
[a
].Y
,
2093 gWater
[a
].Width
, gWater
[a
].Height
) then
2100 if WordBool(PanelType
and PANEL_ACID1
) then
2101 if gAcid1
<> nil then
2106 if g_Collide(X
, Y
, Width
, Height
,
2107 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2108 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2115 if WordBool(PanelType
and PANEL_ACID2
) then
2116 if gAcid2
<> nil then
2121 if g_Collide(X
, Y
, Width
, Height
,
2122 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2123 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2130 if WordBool(PanelType
and PANEL_STEP
) then
2131 if gSteps
<> nil then
2136 if g_Collide(X
, Y
, Width
, Height
,
2137 gSteps
[a
].X
, gSteps
[a
].Y
,
2138 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2145 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2146 if gLifts
<> nil then
2151 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2152 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2153 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2154 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2155 g_Collide(X
, Y
, Width
, Height
,
2156 gLifts
[a
].X
, gLifts
[a
].Y
,
2157 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2164 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2165 if gBlockMon
<> nil then
2167 h
:= High(gBlockMon
);
2171 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2172 g_Collide(X
, Y
, Width
, Height
,
2173 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2174 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2182 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2186 function checkPanels (constref panels
: TPanelArray
): Boolean;
2191 if panels
= nil then exit
;
2192 for a
:= 0 to High(panels
) do
2194 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2197 texid
:= panels
[a
].GetTextureID();
2204 texid
:= TEXTURE_NONE
;
2206 if not checkPanels(gWater
) then
2207 if not checkPanels(gAcid1
) then
2208 if not checkPanels(gAcid2
) then exit
;
2213 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2215 SlowMask
= GridTagLift
or GridTagBlockMon
;
2216 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2219 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2221 result := pan.Enabled;
2226 if ((tag
and GridTagLift
) <> 0) then
2229 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2230 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2231 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2232 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2233 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2237 if ((tag
and GridTagBlockMon
) <> 0) then
2239 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2244 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2245 result
:= true; // i found her!
2249 tagmask
: Integer = 0;
2251 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2252 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2253 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2254 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2255 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2256 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2257 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2259 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2261 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2262 if gdbg_map_use_accel_coldet
then
2264 {if gdbg_map_use_tree_coldet then
2266 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2267 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2268 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2270 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2271 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2276 if (Width
= 1) and (Height
= 1) then
2278 if ((tagmask
and SlowMask
) <> 0) then
2281 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2286 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2291 if ((tagmask
and SlowMask
) <> 0) then
2294 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2299 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2306 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2308 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2312 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2314 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2317 // slightly different from the old code, but meh...
2318 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2320 result
:= false; // don't stop, ever
2321 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2324 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2325 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2326 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2329 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2331 texid
:= pan
.GetTextureID();
2332 // water? water has the highest priority, so stop right here
2333 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2335 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2337 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2341 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2342 if gdbg_map_use_accel_coldet
then
2344 texid
:= TEXTURE_NONE
;
2345 {if gdbg_map_use_tree_coldet then
2347 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2351 if (Width
= 1) and (Height
= 1) then
2353 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2357 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2364 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2366 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2370 procedure g_Map_EnableWall(ID
: DWORD
);
2375 pan
.Enabled
:= True;
2376 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2378 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2379 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2380 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2382 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2384 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2385 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
);
2389 procedure g_Map_DisableWall(ID
: DWORD
);
2394 pan
.Enabled
:= False;
2395 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2397 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2398 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2400 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2402 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2403 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
);
2407 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2412 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2415 tp
:= gRenderForegrounds
[ID
];
2417 tp
:= gRenderBackgrounds
[ID
];
2430 tp
.NextTexture(AnimLoop
);
2431 if g_Game_IsServer
and g_Game_IsNet
then
2432 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2435 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2437 if gLifts
[ID
].LiftType
= t
then
2444 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2445 //TODO: make separate lift tags, and change tag here
2447 if LiftType
= 0 then
2448 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2449 else if LiftType
= 1 then
2450 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2451 else if LiftType
= 2 then
2452 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2453 else if LiftType
= 3 then
2454 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2456 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2460 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2463 PointsArray
: Array of TRespawnPoint
;
2466 SetLength(PointsArray
, 0);
2468 if RespawnPoints
= nil then
2471 for a
:= 0 to High(RespawnPoints
) do
2472 if RespawnPoints
[a
].PointType
= PointType
then
2474 SetLength(PointsArray
, Length(PointsArray
)+1);
2475 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2478 if PointsArray
= nil then
2481 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2485 function g_Map_GetPointCount(PointType
: Byte): Word;
2491 if RespawnPoints
= nil then
2494 for a
:= 0 to High(RespawnPoints
) do
2495 if RespawnPoints
[a
].PointType
= PointType
then
2496 Result
:= Result
+ 1;
2499 function g_Map_HaveFlagPoints(): Boolean;
2501 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2504 procedure g_Map_ResetFlag(Flag
: Byte);
2506 with gFlags
[Flag
] do
2512 Direction
:= D_LEFT
;
2513 State
:= FLAG_STATE_NONE
;
2514 if FlagPoints
[Flag
] <> nil then
2516 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2517 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2518 Direction
:= FlagPoints
[Flag
]^.Direction
;
2519 State
:= FLAG_STATE_NORMAL
;
2525 procedure g_Map_DrawFlags();
2528 Mirror
: TMirrorType
;
2530 if gGameSettings
.GameMode
<> GM_CTF
then
2533 for i
:= FLAG_RED
to FLAG_BLUE
do
2535 if State
<> FLAG_STATE_CAPTURED
then
2537 if State
= FLAG_STATE_NONE
then
2540 if Direction
= D_LEFT
then
2542 Mirror
:= M_HORIZONTAL
;
2551 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2553 if g_debug_Frames
then
2555 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2557 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2558 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2564 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2571 procedure SavePanelArray(var panels
: TPanelArray
);
2573 PAMem
: TBinMemoryWriter
;
2576 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2577 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2580 while i
< Length(panels
) do
2582 if panels
[i
].SaveIt
then
2586 // Ñîõðàíÿåì ïàíåëü:
2587 panels
[i
].SaveState(PAMem
);
2592 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2593 PAMem
.SaveToMemory(Mem
);
2597 procedure SaveFlag(flag
: PFlag
);
2600 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2602 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2603 Mem
.WriteByte(flag
^.RespawnType
);
2605 Mem
.WriteByte(flag
^.State
);
2606 // Íàïðàâëåíèå ôëàãà:
2607 if flag
^.Direction
= D_LEFT
then
2613 Obj_SaveState(@flag
^.Obj
, Mem
);
2617 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2619 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2620 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2621 SavePanelArray(gWalls
);
2622 // Ñîõðàíÿåì ïàíåëè ôîíà:
2623 SavePanelArray(gRenderBackgrounds
);
2624 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2625 SavePanelArray(gRenderForegrounds
);
2626 // Ñîõðàíÿåì ïàíåëè âîäû:
2627 SavePanelArray(gWater
);
2628 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2629 SavePanelArray(gAcid1
);
2630 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2631 SavePanelArray(gAcid2
);
2632 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2633 SavePanelArray(gSteps
);
2634 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2635 SavePanelArray(gLifts
);
2638 ///// Ñîõðàíÿåì ìóçûêó: /////
2639 // Ñèãíàòóðà ìóçûêè:
2640 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2643 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2644 if gMusic
.NoMusic
then
2648 Mem
.WriteString(str
, 64);
2649 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2650 dw
:= gMusic
.GetPosition();
2652 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2653 boo
:= gMusic
.SpecPause
;
2654 Mem
.WriteBoolean(boo
);
2657 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2658 Mem
.WriteInt(gTotalMonsters
);
2661 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2662 if gGameSettings
.GameMode
= GM_CTF
then
2664 // Ôëàã Êðàñíîé êîìàíäû:
2665 SaveFlag(@gFlags
[FLAG_RED
]);
2666 // Ôëàã Ñèíåé êîìàíäû:
2667 SaveFlag(@gFlags
[FLAG_BLUE
]);
2671 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2672 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2674 // Î÷êè Êðàñíîé êîìàíäû:
2675 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2676 // Î÷êè Ñèíåé êîìàíäû:
2677 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2682 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2689 procedure LoadPanelArray(var panels
: TPanelArray
);
2691 PAMem
: TBinMemoryReader
;
2694 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2695 PAMem
:= TBinMemoryReader
.Create();
2696 PAMem
.LoadFromMemory(Mem
);
2698 for i
:= 0 to Length(panels
)-1 do
2699 if panels
[i
].SaveIt
then
2705 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2707 // Çàãðóæàåì ïàíåëü:
2708 panels
[i
].LoadState(PAMem
);
2711 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2715 procedure LoadFlag(flag
: PFlag
);
2719 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2721 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2723 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2724 Mem
.ReadByte(flag
^.RespawnType
);
2726 Mem
.ReadByte(flag
^.State
);
2727 // Íàïðàâëåíèå ôëàãà:
2730 flag
^.Direction
:= D_LEFT
2732 flag
^.Direction
:= D_RIGHT
;
2734 Obj_LoadState(@flag
^.Obj
, Mem
);
2741 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2742 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2743 LoadPanelArray(gWalls
);
2744 // Çàãðóæàåì ïàíåëè ôîíà:
2745 LoadPanelArray(gRenderBackgrounds
);
2746 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2747 LoadPanelArray(gRenderForegrounds
);
2748 // Çàãðóæàåì ïàíåëè âîäû:
2749 LoadPanelArray(gWater
);
2750 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2751 LoadPanelArray(gAcid1
);
2752 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2753 LoadPanelArray(gAcid2
);
2754 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2755 LoadPanelArray(gSteps
);
2756 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2757 LoadPanelArray(gLifts
);
2760 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2764 ///// Çàãðóæàåì ìóçûêó: /////
2765 // Ñèãíàòóðà ìóçûêè:
2767 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2769 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2772 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2773 Mem
.ReadString(str
);
2774 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2776 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2777 Mem
.ReadBoolean(boo
);
2778 // Çàïóñêàåì ýòó ìóçûêó:
2779 gMusic
.SetByName(str
);
2780 gMusic
.SpecPause
:= boo
;
2783 gMusic
.SetPosition(dw
);
2786 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2787 Mem
.ReadInt(gTotalMonsters
);
2790 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2791 if gGameSettings
.GameMode
= GM_CTF
then
2793 // Ôëàã Êðàñíîé êîìàíäû:
2794 LoadFlag(@gFlags
[FLAG_RED
]);
2795 // Ôëàã Ñèíåé êîìàíäû:
2796 LoadFlag(@gFlags
[FLAG_BLUE
]);
2800 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2801 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2803 // Î÷êè Êðàñíîé êîìàíäû:
2804 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2805 // Î÷êè Ñèíåé êîìàíäû:
2806 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2811 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2816 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2817 Arr
:= PanelByID
[PanelID
].PWhere
^;
2818 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2819 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2823 // trace liquid, stepping by `dx` and `dy`
2824 // return last seen liquid coords, and `false` if we're started outside of the liquid
2825 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2827 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2831 // started outside of the liquid?
2832 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2833 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2839 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit