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}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, z_aabbtree
, md5
, binheap
, xprofiler
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
66 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
68 procedure g_Map_DrawBack(dx
, dy
: Integer);
69 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
70 PanelType
: Word; b1x3
: Boolean): Boolean;
71 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
72 procedure g_Map_EnableWall(ID
: DWORD
);
73 procedure g_Map_DisableWall(ID
: DWORD
);
74 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
75 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
76 procedure g_Map_ReAdd_DieTriggers();
77 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
79 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
80 function g_Map_GetPointCount(PointType
: Byte): Word;
82 function g_Map_HaveFlagPoints(): Boolean;
84 procedure g_Map_ResetFlag(Flag
: Byte);
85 procedure g_Map_DrawFlags();
87 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
89 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
90 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
92 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
94 procedure g_Map_ProfilersBegin ();
95 procedure g_Map_ProfilersEnd ();
98 RESPAWNPOINT_PLAYER1
= 1;
99 RESPAWNPOINT_PLAYER2
= 2;
101 RESPAWNPOINT_RED
= 4;
102 RESPAWNPOINT_BLUE
= 5;
110 FLAG_STATE_NORMAL
= 1;
111 FLAG_STATE_DROPPED
= 2;
112 FLAG_STATE_CAPTURED
= 3;
113 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
114 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
116 FLAG_TIME
= 720; // 20 seconds
118 SKY_STRETCH
: Single = 1.5;
133 // sorted by draw priority
134 GridTagBack
= 1 shl 0;
135 GridTagStep
= 1 shl 1;
136 GridTagWall
= 1 shl 2;
137 GridTagDoor
= 1 shl 3;
138 GridTagAcid1
= 1 shl 4;
139 GridTagAcid2
= 1 shl 5;
140 GridTagWater
= 1 shl 6;
141 GridTagFore
= 1 shl 7;
142 // the following are invisible
143 GridTagLift
= 1 shl 8;
144 GridTagBlockMon
= 1 shl 9;
149 gRenderBackgrounds
: TPanelArray
;
150 gRenderForegrounds
: TPanelArray
;
151 gWater
, gAcid1
, gAcid2
: TPanelArray
;
154 gBlockMon
: TPanelArray
;
155 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
156 //gDOMFlags: array of TFlag;
159 gDoorMap
: array of array of DWORD
;
160 gLiftMap
: array of array of DWORD
;
161 gWADHash
: TMD5Digest
;
162 BackID
: DWORD
= DWORD(-1);
163 gExternalResources
: TStringList
;
165 gdbg_map_use_accel_render
: Boolean = true;
166 gdbg_map_use_accel_coldet
: Boolean = true;
167 gdbg_map_use_tree_draw
: Boolean = false;
168 gdbg_map_use_tree_coldet
: Boolean = false;
169 gdbg_map_dump_coldet_tree_queries
: Boolean = false;
170 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
171 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
173 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
175 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Integer;
181 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
182 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
183 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
184 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
186 ImagingTypes
, Imaging
, ImagingUtility
,
187 ImagingGif
, ImagingNetworkGraphics
;
190 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
191 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
192 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
196 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
198 TDynAABBTreePanelBase
= specialize TDynAABBTreeBase
<TPanel
>;
200 TDynAABBTreeMap
= class(TDynAABBTreePanelBase
)
201 function getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean; override;
204 function TDynAABBTreeMap
.getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean;
207 if (pan
= nil) then begin aabb
:= AABB2D
.Create(0, 0, 0, 0); exit
; end;
208 aabb
:= AABB2D
.Create(pan
.X
, pan
.Y
, pan
.X
+pan
.Width
-1, pan
.Y
+pan
.Height
-1);
209 if (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
210 if not aabb
.valid
then raise Exception
.Create('wutafuuuuuuu?!');
215 function panelTypeToTag (panelType
: Word): Integer;
218 PANEL_WALL
: result
:= GridTagWall
; // gWalls
219 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
220 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
221 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
222 PANEL_WATER
: result
:= GridTagWater
; // gWater
223 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
224 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
225 PANEL_STEP
: result
:= GridTagStep
; // gSteps
226 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
227 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
228 else result
:= GridTagInvalid
;
233 function dplLess (a
, b
: TObject
): Boolean;
237 //result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
240 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
241 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
242 result
:= (pa
.ArrIdx
< pb
.ArrIdx
);
245 procedure dplClear ();
247 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
253 PWhere
: ^TPanelArray
;
258 PanelById
: array of TPanelID
;
259 Textures
: TLevelTextureArray
;
260 RespawnPoints
: Array of TRespawnPoint
;
261 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
262 //DOMFlagPoints: Array of TFlagPoint;
263 gMapGrid
: TPanelGrid
= nil;
264 mapTree
: TDynAABBTreeMap
= nil;
267 procedure g_Map_ProfilersBegin ();
269 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
270 profMapCollision
.mainBegin(g_profile_collision
);
272 if g_profile_collision
then
274 profMapCollision
.sectionBegin('*solids');
275 profMapCollision
.sectionEnd();
276 profMapCollision
.sectionBegin('liquids');
277 profMapCollision
.sectionEnd();
281 procedure g_Map_ProfilersEnd ();
283 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
287 // wall index in `gWalls` or -1
288 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Integer;
290 function sqchecker (pan
: TPanel
; var ray
: Ray2D
): Single;
295 result
:= -666.0; // invalid
296 if not pan
.Enabled
then exit
;
297 aabb
:= AABB2D
.CreateWH(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
298 if not aabb
.valid
then exit
;
299 if aabb
.intersects(ray
, @tmin
) then
301 if (tmin
>= 0.0) then
303 //e_WriteLog(Format('sqchecker(%d,%d,%d,%d): panel #%d (%d,%d)-(%d,%d); tmin=%f', [x0, y0, x1, y1, pan.arrIdx, pan.X, pan.Y, pan.Width, pan.Height, tmin]), MSG_NOTIFY);
304 //if (tmin < 0.0) then tmin := 0.0;
311 qr
: TDynAABBTreeMap
.TSegmentQueryResult
;
317 if (mapTree
= nil) then exit
;
318 if mapTree
.segmentQuery(qr
, x0
, y0
, x1
, y1
, sqchecker
, (GridTagWall
or GridTagDoor
)) then
320 if (qr
.flesh
<> nil) then
322 result
:= qr
.flesh
.arrIdx
;
323 if (hitx
<> nil) or (hity
<> nil) then
325 ray
:= Ray2D
.Create(x0
, y0
, x1
, y1
);
326 hxf
:= ray
.origX
+ray
.dirX
*qr
.time
;
327 hyf
:= ray
.origY
+ray
.dirY
*qr
.time
;
332 if (hx
>= qr
.flesh
.X
) and (hy
>= qr
.flesh
.Y
) and (hx
< qr
.flesh
.X
+qr
.flesh
.Width
) and (hy
< qr
.flesh
.Y
+qr
.flesh
.Height
) then
343 if (hitx
<> nil) then hitx
^ := hx
;
344 if (hity
<> nil) then hity
^ := hy
;
351 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
353 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
354 (Texture
= TEXTURE_NAME_ACID1
) or
355 (Texture
= TEXTURE_NAME_ACID2
);
358 procedure CreateDoorMap();
360 PanelArray
: Array of record
366 a
, b
, c
, m
, i
, len
: Integer;
374 SetLength(PanelArray
, len
);
376 for a
:= 0 to High(gWalls
) do
377 if gWalls
[a
].Door
then
379 PanelArray
[i
].X
:= gWalls
[a
].X
;
380 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
381 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
382 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
383 PanelArray
[i
].Active
:= True;
384 PanelArray
[i
].PanelID
:= a
;
390 SetLength(PanelArray
, len
);
401 SetLength(gDoorMap
, 0);
403 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
406 if PanelArray
[a
].Active
then
408 PanelArray
[a
].Active
:= False;
409 m
:= Length(gDoorMap
);
410 SetLength(gDoorMap
, m
+1);
411 SetLength(gDoorMap
[m
], 1);
412 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
420 if PanelArray
[b
].Active
then
421 for c
:= 0 to High(gDoorMap
[m
]) do
422 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
423 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
424 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
425 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
426 gWalls
[gDoorMap
[m
, c
]].X
,
427 gWalls
[gDoorMap
[m
, c
]].Y
,
428 gWalls
[gDoorMap
[m
, c
]].Width
,
429 gWalls
[gDoorMap
[m
, c
]].Height
) then
431 PanelArray
[b
].Active
:= False;
432 SetLength(gDoorMap
[m
],
433 Length(gDoorMap
[m
])+1);
434 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
440 g_Game_StepLoading();
446 procedure CreateLiftMap();
448 PanelArray
: Array of record
453 a
, b
, c
, len
, i
, j
: Integer;
459 len
:= Length(gLifts
);
460 SetLength(PanelArray
, len
);
462 for a
:= 0 to len
-1 do
464 PanelArray
[a
].X
:= gLifts
[a
].X
;
465 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
466 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
467 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
468 PanelArray
[a
].Active
:= True;
471 SetLength(gLiftMap
, len
);
474 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
476 for a
:= 0 to len
-1 do
477 if PanelArray
[a
].Active
then
479 PanelArray
[a
].Active
:= False;
480 SetLength(gLiftMap
[i
], 32);
488 for b
:= 0 to len
-1 do
489 if PanelArray
[b
].Active
then
491 if g_CollideAround(PanelArray
[b
].X
,
494 PanelArray
[b
].Height
,
495 PanelArray
[gLiftMap
[i
, c
]].X
,
496 PanelArray
[gLiftMap
[i
, c
]].Y
,
497 PanelArray
[gLiftMap
[i
, c
]].Width
,
498 PanelArray
[gLiftMap
[i
, c
]].Height
) then
500 PanelArray
[b
].Active
:= False;
502 if j
> High(gLiftMap
[i
]) then
503 SetLength(gLiftMap
[i
],
504 Length(gLiftMap
[i
])+32);
513 SetLength(gLiftMap
[i
], j
+1);
516 g_Game_StepLoading();
519 SetLength(gLiftMap
, i
);
524 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
525 CurTex
: Integer; sav
: Boolean): Integer;
528 panels
: ^TPanelArray
;
532 case PanelRec
.PanelType
of
533 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
536 panels
:= @gRenderBackgrounds
;
538 panels
:= @gRenderForegrounds
;
547 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
550 panels
:= @gBlockMon
;
555 len
:= Length(panels
^);
556 SetLength(panels
^, len
+ 1);
558 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
559 panels
^[len
].ArrIdx
:= len
;
560 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
562 panels
^[len
].SaveIt
:= True;
566 len
:= Length(PanelByID
);
567 SetLength(PanelByID
, len
+ 1);
568 PanelByID
[len
].PWhere
:= panels
;
569 PanelByID
[len
].PArrID
:= Result
;
572 function CreateNullTexture(RecName
: String): Integer;
574 SetLength(Textures
, Length(Textures
)+1);
575 result
:= High(Textures
);
577 with Textures
[High(Textures
)] do
579 TextureName
:= RecName
;
583 TextureID
:= TEXTURE_NONE
;
587 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
590 TextureData
: Pointer;
591 WADName
, txname
: String;
592 a
, ResLength
: Integer;
596 if Textures
<> nil then
597 for a
:= 0 to High(Textures
) do
598 if Textures
[a
].TextureName
= RecName
then
599 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
604 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
605 if (RecName
= TEXTURE_NAME_WATER
) or
606 (RecName
= TEXTURE_NAME_ACID1
) or
607 (RecName
= TEXTURE_NAME_ACID2
) then
609 SetLength(Textures
, Length(Textures
)+1);
611 with Textures
[High(Textures
)] do
613 TextureName
:= RecName
;
615 if TextureName
= TEXTURE_NAME_WATER
then
616 TextureID
:= TEXTURE_SPECIAL_WATER
618 if TextureName
= TEXTURE_NAME_ACID1
then
619 TextureID
:= TEXTURE_SPECIAL_ACID1
621 if TextureName
= TEXTURE_NAME_ACID2
then
622 TextureID
:= TEXTURE_SPECIAL_ACID2
;
627 result
:= High(Textures
);
631 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
632 WADName
:= g_ExtractWadName(RecName
);
634 WAD
:= TWADFile
.Create();
636 if WADName
<> '' then
637 WADName
:= GameDir
+'/wads/'+WADName
641 WAD
.ReadFile(WADName
);
645 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
647 FreeMem(TextureData);
648 RecName := 'COMMON\ALIEN';
652 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
654 SetLength(Textures
, Length(Textures
)+1);
655 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
657 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
658 @Textures
[High(Textures
)].Width
,
659 @Textures
[High(Textures
)].Height
);
660 FreeMem(TextureData
);
661 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
662 Textures
[High(Textures
)].Anim
:= False;
664 result
:= High(Textures
);
666 else // Íåò òàêîãî ðåóñðñà â WAD'å
668 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
671 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
672 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
679 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
682 TextureWAD
: PChar = nil;
683 TextData
: Pointer = nil;
684 TextureData
: Pointer = nil;
688 TextureResource
: String;
689 _width
, _height
, _framecount
, _speed
: Integer;
690 _backanimation
: Boolean;
692 ia
: TDynImageDataArray
= nil;
693 f
, c
, frdelay
, frloop
: Integer;
697 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
699 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
700 WADName
:= g_ExtractWadName(RecName
);
702 WAD
:= TWADFile
.Create();
704 if WADName
<> '' then
705 WADName
:= GameDir
+'/wads/'+WADName
709 WAD
.ReadFile(WADName
);
711 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
715 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
716 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
722 if WADName = Map then
724 //FreeMem(TextureWAD);
725 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
731 if ResLength
< 6 then
733 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
737 // ýòî ïòèöà? ýòî ñàìîë¸ò?
738 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
739 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
741 // íåò, ýòî ñóïåðìåí!
742 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
744 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
748 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
749 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
751 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
755 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
757 TextureResource
:= cfg
.ReadStr('', 'resource', '');
758 if TextureResource
= '' then
760 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
764 _width
:= cfg
.ReadInt('', 'framewidth', 0);
765 _height
:= cfg
.ReadInt('', 'frameheight', 0);
766 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
767 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
768 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
773 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
774 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
776 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
783 SetLength(Textures
, Length(Textures
)+1);
784 with Textures
[High(Textures
)] do
786 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
787 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
789 TextureName
:= RecName
;
793 FramesCount
:= _framecount
;
795 result
:= High(Textures
);
799 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
805 // try animated image
807 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
808 if length(imgfmt) = 0 then
810 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
814 GlobalMetadata
.ClearMetaItems();
815 GlobalMetadata
.ClearMetaItemsForSaving();
816 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
818 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
821 if length(ia
) = 0 then
823 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
830 _width
:= ia
[0].width
;
831 _height
:= ia
[0].height
;
832 _framecount
:= length(ia
);
834 _backanimation
:= false;
837 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
839 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
841 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
843 if f
< 0 then f
:= 0;
846 if c
< 13 then c
:= 0 else c
:= 1;
848 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
853 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
855 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
857 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
859 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
863 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
864 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
865 f
:= ord(_backanimation
);
866 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
);
868 SetLength(Textures
, Length(Textures
)+1);
869 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
870 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
872 Textures
[High(Textures
)].TextureName
:= RecName
;
873 Textures
[High(Textures
)].Width
:= _width
;
874 Textures
[High(Textures
)].Height
:= _height
;
875 Textures
[High(Textures
)].Anim
:= True;
876 Textures
[High(Textures
)].FramesCount
:= length(ia
);
877 Textures
[High(Textures
)].Speed
:= _speed
;
878 result
:= High(Textures
);
879 //writeln(' CREATED!');
883 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
887 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
890 if TextureWAD
<> nil then FreeMem(TextureWAD
);
891 if TextData
<> nil then FreeMem(TextData
);
892 if TextureData
<> nil then FreeMem(TextureData
);
896 procedure CreateItem(Item
: TItemRec_1
);
898 if g_Game_IsClient
then Exit
;
900 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
901 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
904 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
905 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
908 procedure CreateArea(Area
: TAreaRec_1
);
913 case Area
.AreaType
of
914 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
915 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
917 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
918 with RespawnPoints
[High(RespawnPoints
)] do
922 Direction
:= TDirection(Area
.Direction
);
924 case Area
.AreaType
of
925 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
926 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
927 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
928 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
929 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
934 AREA_REDFLAG
, AREA_BLUEFLAG
:
936 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
938 if FlagPoints
[a
] <> nil then Exit
;
942 with FlagPoints
[a
]^ do
944 X
:= Area
.X
-FLAGRECT
.X
;
945 Y
:= Area
.Y
-FLAGRECT
.Y
;
946 Direction
:= TDirection(Area
.Direction
);
952 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
953 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
956 Animation
:= TAnimation
.Create(id
, True, 8);
957 Obj
.Rect
:= FLAGRECT
;
965 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
966 with DOMFlagPoints[High(DOMFlagPoints)] do
970 Direction := TDirection(Area.Direction);
973 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
978 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
982 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
988 Width
:= Trigger
.Width
;
989 Height
:= Trigger
.Height
;
990 Enabled
:= ByteBool(Trigger
.Enabled
);
991 TexturePanel
:= Trigger
.TexturePanel
;
992 TexturePanelType
:= fTexturePanel1Type
;
993 ShotPanelType
:= fTexturePanel2Type
;
994 TriggerType
:= Trigger
.TriggerType
;
995 ActivateType
:= Trigger
.ActivateType
;
996 Keys
:= Trigger
.Keys
;
997 Data
.Default
:= Trigger
.DATA
;
1000 g_Triggers_Create(_trigger
);
1003 procedure CreateMonster(monster
: TMonsterRec_1
);
1008 if g_Game_IsClient
then Exit
;
1010 if (gGameSettings
.GameType
= GT_SINGLE
)
1011 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1013 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1015 if gTriggers
<> nil then
1017 for a
:= 0 to High(gTriggers
) do
1019 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1021 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1026 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1030 procedure g_Map_ReAdd_DieTriggers();
1032 function monsDieTrig (mon
: TMonster
): Boolean;
1036 result
:= false; // don't stop
1037 mon
.ClearTriggers();
1038 for a
:= 0 to High(gTriggers
) do
1040 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1042 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1048 if g_Game_IsClient
then Exit
;
1050 g_Mons_ForEach(monsDieTrig
);
1053 function extractWadName(resourceName
: string): string;
1057 posN
:= Pos(':', resourceName
);
1059 Result
:= Copy(resourceName
, 0, posN
-1)
1064 procedure addResToExternalResList(res
: string);
1066 res
:= extractWadName(res
);
1067 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1068 gExternalResources
.Add(res
);
1071 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1073 textures
: TTexturesRec1Array
;
1074 mapHeader
: TMapHeaderRec_1
;
1076 resFile
: String = '';
1078 if gExternalResources
= nil then
1079 gExternalResources
:= TStringList
.Create
;
1081 gExternalResources
.Clear
;
1082 textures
:= mapReader
.GetTextures();
1083 for i
:= 0 to High(textures
) do
1085 addResToExternalResList(resFile
);
1090 mapHeader
:= mapReader
.GetMapHeader
;
1092 addResToExternalResList(mapHeader
.MusicName
);
1093 addResToExternalResList(mapHeader
.SkyName
);
1096 procedure mapCreateGrid ();
1098 mapX0
: Integer = $3fffffff;
1099 mapY0
: Integer = $3fffffff;
1100 mapX1
: Integer = -$3fffffff;
1101 mapY1
: Integer = -$3fffffff;
1103 procedure calcBoundingBox (constref panels
: TPanelArray
);
1108 for idx
:= 0 to High(panels
) do
1111 if not pan
.visvalid
then continue
;
1112 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1113 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1114 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1115 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1116 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1120 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1125 tag
:= panelTypeToTag(tag
);
1126 for idx
:= High(panels
) downto 0 do
1130 if not pan
.visvalid
then continue
;
1131 gMapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1132 mapTree
.insertObject(pan
, tag
, true); // as static object
1142 calcBoundingBox(gWalls
);
1143 calcBoundingBox(gRenderBackgrounds
);
1144 calcBoundingBox(gRenderForegrounds
);
1145 calcBoundingBox(gWater
);
1146 calcBoundingBox(gAcid1
);
1147 calcBoundingBox(gAcid2
);
1148 calcBoundingBox(gSteps
);
1149 calcBoundingBox(gLifts
);
1150 calcBoundingBox(gBlockMon
);
1152 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1154 gMapGrid
:= TPanelGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1155 mapTree
:= TDynAABBTreeMap
.Create();
1157 addPanelsToGrid(gWalls
, PANEL_WALL
);
1158 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1159 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1160 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1161 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1162 addPanelsToGrid(gWater
, PANEL_WATER
);
1163 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1164 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1165 addPanelsToGrid(gSteps
, PANEL_STEP
);
1166 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1167 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1169 gMapGrid
.dumpStats();
1170 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1171 mapTree
.forEachLeaf(nil);
1174 function g_Map_Load(Res
: String): Boolean;
1176 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1177 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1180 MapReader
: TMapReader_1
;
1181 Header
: TMapHeaderRec_1
;
1182 _textures
: TTexturesRec1Array
;
1183 _texnummap
: array of Integer; // `_textures` -> `Textures`
1184 panels
: TPanelsRec1Array
;
1185 items
: TItemsRec1Array
;
1186 monsters
: TMonsterRec1Array
;
1187 areas
: TAreasRec1Array
;
1188 triggers
: TTriggersRec1Array
;
1189 a
, b
, c
, k
: Integer;
1191 AddTextures
: TAddTextureArray
;
1192 texture
: TTextureRec_1
;
1193 TriggersTable
: Array of record
1194 TexturePanel
: Integer;
1199 FileName
, mapResName
, s
, TexName
: String;
1202 ok
, isAnim
, trigRef
: Boolean;
1203 CurTex
, ntn
: Integer;
1212 gMapInfo
.Map
:= Res
;
1213 TriggersTable
:= nil;
1214 FillChar(texture
, SizeOf(texture
), 0);
1216 sfsGCDisable(); // temporary disable removing of temporary volumes
1219 FileName
:= g_ExtractWadName(Res
);
1220 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1221 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1223 WAD
:= TWADFile
.Create();
1224 if not WAD
.ReadFile(FileName
) then
1226 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1230 //k8: why loader ignores path here?
1231 mapResName
:= g_ExtractFileName(Res
);
1232 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1234 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1242 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1243 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1244 MapReader
:= TMapReader_1
.Create();
1246 if not MapReader
.LoadMap(Data
) then
1248 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1255 generateExternalResourcesList(MapReader
);
1256 // Çàãðóçêà òåêñòóð:
1257 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1258 _textures
:= MapReader
.GetTextures();
1261 // Äîáàâëåíèå òåêñòóð â Textures[]:
1262 if _textures
<> nil then
1264 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1265 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1266 SetLength(_texnummap
, length(_textures
));
1268 for a
:= 0 to High(_textures
) do
1271 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1272 for b
:= 1 to Length(s
) do
1278 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1279 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1280 // Àíèìèðîâàííàÿ òåêñòóðà:
1281 if ByteBool(_textures
[a
].Anim
) then
1283 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1286 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1287 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1290 else // Îáû÷íàÿ òåêñòóðà:
1291 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1294 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1295 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1298 _texnummap
[a
] := ntn
; // fix texture number
1299 g_Game_StepLoading();
1303 // Çàãðóçêà òðèããåðîâ:
1304 gTriggerClientID
:= 0;
1305 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1306 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1307 triggers
:= MapReader
.GetTriggers();
1309 // Çàãðóçêà ïàíåëåé:
1310 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1311 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1312 panels
:= MapReader
.GetPanels();
1314 // check texture numbers for panels
1315 for a
:= 0 to High(panels
) do
1317 if panels
[a
].TextureNum
> High(_textures
) then
1319 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1323 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1326 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1327 if triggers
<> nil then
1329 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1330 SetLength(TriggersTable
, Length(triggers
));
1331 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1333 for a
:= 0 to High(TriggersTable
) do
1335 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1336 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1338 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1339 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1341 TriggersTable
[a
].LiftPanel
:= -1;
1343 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1344 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1345 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1346 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1348 TriggersTable
[a
].DoorPanel
:= -1;
1350 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1351 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1353 TriggersTable
[a
].ShotPanel
:= -1;
1355 g_Game_StepLoading();
1360 if panels
<> nil then
1362 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1363 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1365 for a
:= 0 to High(panels
) do
1367 SetLength(AddTextures
, 0);
1370 if _textures
<> nil then
1372 texture
:= _textures
[panels
[a
].TextureNum
];
1380 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1381 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1383 if (TriggersTable
<> nil) and (_textures
<> nil) then
1384 for b
:= 0 to High(TriggersTable
) do
1385 if (TriggersTable
[b
].TexturePanel
= a
)
1386 or (TriggersTable
[b
].ShotPanel
= a
) then
1395 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1397 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1400 for c
:= Len
downto 1 do
1408 // Ñïåö-òåêñòóðû çàïðåùåíû:
1409 if g_Map_IsSpecialTexture(s
) then
1412 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1413 ok
:= g_Texture_NumNameFindStart(s
);
1415 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1416 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1419 k
:= NNF_NAME_BEFORE
;
1420 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1421 while ok
or (k
= NNF_NAME_BEFORE
) or
1422 (k
= NNF_NAME_EQUALS
) do
1424 k
:= g_Texture_NumNameFindNext(TexName
);
1426 if (k
= NNF_NAME_BEFORE
) or
1427 (k
= NNF_NAME_AFTER
) then
1429 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1430 if ByteBool(texture
.Anim
) then
1431 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1433 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1435 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1437 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1441 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1443 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1445 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1447 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1451 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1454 for c
:= 0 to High(Textures
) do
1455 if Textures
[c
].TextureName
= TexName
then
1457 SetLength(AddTextures
, Length(AddTextures
)+1);
1458 AddTextures
[High(AddTextures
)].Texture
:= c
;
1459 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1465 if k
= NNF_NAME_EQUALS
then
1467 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1468 SetLength(AddTextures
, Length(AddTextures
)+1);
1469 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1470 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1471 CurTex
:= High(AddTextures
);
1479 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1480 end; // if ok - ññûëàþòñÿ òðèããåðû
1484 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1485 SetLength(AddTextures
, 1);
1486 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1487 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1491 //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);
1493 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1494 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1496 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1497 if TriggersTable
<> nil then
1498 for b
:= 0 to High(TriggersTable
) do
1500 // Òðèããåð äâåðè/ëèôòà:
1501 if (TriggersTable
[b
].LiftPanel
= a
) or
1502 (TriggersTable
[b
].DoorPanel
= a
) then
1503 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1504 // Òðèããåð ñìåíû òåêñòóðû:
1505 if TriggersTable
[b
].TexturePanel
= a
then
1506 triggers
[b
].TexturePanel
:= PanelID
;
1507 // Òðèããåð "Òóðåëü":
1508 if TriggersTable
[b
].ShotPanel
= a
then
1509 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1512 g_Game_StepLoading();
1516 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1517 if (triggers
<> nil) and not gLoadGameMode
then
1519 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1520 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1521 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1522 for a
:= 0 to High(triggers
) do
1524 if triggers
[a
].TexturePanel
<> -1 then
1525 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1528 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1529 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1530 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1533 CreateTrigger(triggers
[a
], b
, c
);
1537 // Çàãðóçêà ïðåäìåòîâ:
1538 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1539 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1540 items
:= MapReader
.GetItems();
1542 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1543 if (items
<> nil) and not gLoadGameMode
then
1545 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1546 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1547 for a
:= 0 to High(items
) do
1548 CreateItem(Items
[a
]);
1551 // Çàãðóçêà îáëàñòåé:
1552 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1553 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1554 areas
:= MapReader
.GetAreas();
1556 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1557 if areas
<> nil then
1559 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1560 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1561 for a
:= 0 to High(areas
) do
1562 CreateArea(areas
[a
]);
1565 // Çàãðóçêà ìîíñòðîâ:
1566 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1567 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1568 monsters
:= MapReader
.GetMonsters();
1570 gTotalMonsters
:= 0;
1572 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1573 if (monsters
<> nil) and not gLoadGameMode
then
1575 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1576 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1577 for a
:= 0 to High(monsters
) do
1578 CreateMonster(monsters
[a
]);
1581 // Çàãðóçêà îïèñàíèÿ êàðòû:
1582 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1583 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1584 Header
:= MapReader
.GetMapHeader();
1590 Name
:= Header
.MapName
;
1591 Description
:= Header
.MapDescription
;
1592 Author
:= Header
.MapAuthor
;
1593 MusicName
:= Header
.MusicName
;
1594 SkyName
:= Header
.SkyName
;
1595 Height
:= Header
.Height
;
1596 Width
:= Header
.Width
;
1600 if gMapInfo
.SkyName
<> '' then
1602 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1603 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1604 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1606 if FileName
<> '' then
1607 FileName
:= GameDir
+'/wads/'+FileName
1610 FileName
:= g_ExtractWadName(Res
);
1613 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1614 if g_Texture_CreateWAD(BackID
, s
) then
1616 g_Game_SetupScreenSize();
1619 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1624 if gMapInfo
.MusicName
<> '' then
1626 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1627 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1628 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1630 if FileName
<> '' then
1631 FileName
:= GameDir
+'/wads/'+FileName
1634 FileName
:= g_ExtractWadName(Res
);
1637 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1638 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1641 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1644 // Îñòàëüíûå óñòàíâêè:
1652 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1653 if not gLoadGameMode
then
1656 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1662 TriggersTable
:= nil;
1665 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1666 if ok
and (not gLoadGameMode
) then
1668 gMusic
.SetByName(gMapInfo
.MusicName
);
1672 gMusic
.SetByName('');
1674 sfsGCEnable(); // enable releasing unused volumes
1677 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1680 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1684 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1687 MapReader
: TMapReader_1
;
1688 Header
: TMapHeaderRec_1
;
1693 FillChar(Result
, SizeOf(Result
), 0);
1694 FileName
:= g_ExtractWadName(Res
);
1696 WAD
:= TWADFile
.Create();
1697 if not WAD
.ReadFile(FileName
) then
1703 //k8: it ignores path again
1704 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1712 MapReader
:= TMapReader_1
.Create();
1714 if not MapReader
.LoadMap(Data
) then
1716 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1717 ZeroMemory(@Header
, SizeOf(Header
));
1718 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1719 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1723 Header
:= MapReader
.GetMapHeader();
1724 Result
.Name
:= Header
.MapName
;
1725 Result
.Description
:= Header
.MapDescription
;
1732 Result
.Author
:= Header
.MapAuthor
;
1733 Result
.Height
:= Header
.Height
;
1734 Result
.Width
:= Header
.Width
;
1737 function g_Map_GetMapsList(WADName
: string): SArray
;
1744 WAD
:= TWADFile
.Create();
1745 if not WAD
.ReadFile(WADName
) then
1750 ResList
:= WAD
.GetMapResources();
1751 if ResList
<> nil then
1753 for a
:= 0 to High(ResList
) do
1755 SetLength(Result
, Length(Result
)+1);
1756 Result
[High(Result
)] := ResList
[a
];
1762 function g_Map_Exist(Res
: string): Boolean;
1765 FileName
, mnn
: string;
1771 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1773 WAD
:= TWADFile
.Create
;
1774 if not WAD
.ReadFile(FileName
) then
1780 ResList
:= WAD
.GetMapResources();
1783 mnn
:= g_ExtractFileName(Res
);
1784 if ResList
<> nil then
1785 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1792 procedure g_Map_Free();
1796 procedure FreePanelArray(var panels
: TPanelArray
);
1801 if panels
<> nil then
1803 for i
:= 0 to High(panels
) do
1816 RespawnPoints
:= nil;
1817 if FlagPoints
[FLAG_RED
] <> nil then
1819 Dispose(FlagPoints
[FLAG_RED
]);
1820 FlagPoints
[FLAG_RED
] := nil;
1822 if FlagPoints
[FLAG_BLUE
] <> nil then
1824 Dispose(FlagPoints
[FLAG_BLUE
]);
1825 FlagPoints
[FLAG_BLUE
] := nil;
1827 //DOMFlagPoints := nil;
1831 if Textures
<> nil then
1833 for a
:= 0 to High(Textures
) do
1834 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1835 if Textures
[a
].Anim
then
1836 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1838 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1839 e_DeleteTexture(Textures
[a
].TextureID
);
1844 FreePanelArray(gWalls
);
1845 FreePanelArray(gRenderBackgrounds
);
1846 FreePanelArray(gRenderForegrounds
);
1847 FreePanelArray(gWater
);
1848 FreePanelArray(gAcid1
);
1849 FreePanelArray(gAcid2
);
1850 FreePanelArray(gSteps
);
1851 FreePanelArray(gLifts
);
1852 FreePanelArray(gBlockMon
);
1854 if BackID
<> DWORD(-1) then
1858 e_DeleteTexture(BackID
);
1859 BackID
:= DWORD(-1);
1862 g_Game_StopAllSounds(False);
1864 g_Sound_Delete(gMapInfo
.MusicName
);
1866 gMapInfo
.Name
:= '';
1867 gMapInfo
.Description
:= '';
1868 gMapInfo
.MusicName
:= '';
1869 gMapInfo
.Height
:= 0;
1870 gMapInfo
.Width
:= 0;
1878 procedure g_Map_Update();
1884 procedure UpdatePanelArray(var panels
: TPanelArray
);
1889 if panels
<> nil then
1890 for i
:= 0 to High(panels
) do
1895 UpdatePanelArray(gWalls
);
1896 UpdatePanelArray(gRenderBackgrounds
);
1897 UpdatePanelArray(gRenderForegrounds
);
1898 UpdatePanelArray(gWater
);
1899 UpdatePanelArray(gAcid1
);
1900 UpdatePanelArray(gAcid2
);
1901 UpdatePanelArray(gSteps
);
1903 if gGameSettings
.GameMode
= GM_CTF
then
1905 for a
:= FLAG_RED
to FLAG_BLUE
do
1906 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1909 if gFlags
[a
].Animation
<> nil then
1910 gFlags
[a
].Animation
.Update();
1912 m
:= g_Obj_Move(@Obj
, True, True);
1914 if gTime
mod (GAME_TICK
*2) <> 0 then
1917 // Ñîïðîòèâëåíèå âîçäóõà:
1918 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1920 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1921 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1924 gFlags
[a
].CaptureTime
:= 0;
1925 if a
= FLAG_RED
then
1926 s
:= _lc
[I_PLAYER_FLAG_RED
]
1928 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1929 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1931 if g_Game_IsNet
then
1932 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1939 // Èãðîê áåðåò ôëàã:
1940 if gPlayers
<> nil then
1942 j
:= Random(Length(gPlayers
)) - 1;
1944 for d
:= 0 to High(gPlayers
) do
1947 if j
> High(gPlayers
) then
1950 if gPlayers
[j
] <> nil then
1951 if gPlayers
[j
].Live
and
1952 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1954 if gPlayers
[j
].GetFlag(a
) then
1965 procedure g_Map_DrawPanels (PanelType
: Word);
1967 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1971 if (panels
<> nil) then
1973 // alas, no visible set
1974 for idx
:= 0 to High(panels
) do
1976 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1983 PANEL_WALL
: DrawPanels(gWalls
);
1984 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1985 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1986 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1987 PANEL_WATER
: DrawPanels(gWater
);
1988 PANEL_ACID1
: DrawPanels(gAcid1
);
1989 PANEL_ACID2
: DrawPanels(gAcid2
);
1990 PANEL_STEP
: DrawPanels(gSteps
);
1996 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
1997 function checker (pan
: TPanel
; tag
: Integer): Boolean;
1999 result
:= false; // don't stop, ever
2000 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2001 gDrawPanelList
.insert(pan
);
2006 //tagmask := panelTypeToTag(PanelType);
2008 if gdbg_map_use_tree_draw
then
2010 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
2014 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
2016 // list will be rendered in `g_game.DrawPlayer()`
2020 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2021 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2023 result
:= false; // don't stop, ever
2024 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2028 if gdbg_map_use_tree_draw
then
2030 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2034 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2039 procedure g_Map_DrawBack(dx
, dy
: Integer);
2041 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2042 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2044 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2047 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2048 PanelType
: Word; b1x3
: Boolean): Boolean;
2054 if WordBool(PanelType
and PANEL_WALL
) then
2055 if gWalls
<> nil then
2060 if gWalls
[a
].Enabled
and
2061 g_Collide(X
, Y
, Width
, Height
,
2062 gWalls
[a
].X
, gWalls
[a
].Y
,
2063 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2070 if WordBool(PanelType
and PANEL_WATER
) then
2071 if gWater
<> nil then
2076 if g_Collide(X
, Y
, Width
, Height
,
2077 gWater
[a
].X
, gWater
[a
].Y
,
2078 gWater
[a
].Width
, gWater
[a
].Height
) then
2085 if WordBool(PanelType
and PANEL_ACID1
) then
2086 if gAcid1
<> nil then
2091 if g_Collide(X
, Y
, Width
, Height
,
2092 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2093 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2100 if WordBool(PanelType
and PANEL_ACID2
) then
2101 if gAcid2
<> nil then
2106 if g_Collide(X
, Y
, Width
, Height
,
2107 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2108 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2115 if WordBool(PanelType
and PANEL_STEP
) then
2116 if gSteps
<> nil then
2121 if g_Collide(X
, Y
, Width
, Height
,
2122 gSteps
[a
].X
, gSteps
[a
].Y
,
2123 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2130 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2131 if gLifts
<> nil then
2136 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2137 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2138 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2139 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2140 g_Collide(X
, Y
, Width
, Height
,
2141 gLifts
[a
].X
, gLifts
[a
].Y
,
2142 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2149 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2150 if gBlockMon
<> nil then
2152 h
:= High(gBlockMon
);
2156 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2157 g_Collide(X
, Y
, Width
, Height
,
2158 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2159 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2167 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2171 function checkPanels (constref panels
: TPanelArray
): Boolean;
2176 if panels
= nil then exit
;
2177 for a
:= 0 to High(panels
) do
2179 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2182 texid
:= panels
[a
].GetTextureID();
2189 texid
:= TEXTURE_NONE
;
2191 if not checkPanels(gWater
) then
2192 if not checkPanels(gAcid1
) then
2193 if not checkPanels(gAcid2
) then exit
;
2198 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2199 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2201 result
:= false; // don't stop, ever
2203 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
2205 if not pan
.Enabled
then exit
;
2208 if ((tag
and GridTagLift
) <> 0) then
2211 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2212 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2213 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2214 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) and
2215 g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2219 if ((tag
and GridTagBlockMon
) <> 0) then
2221 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)) and g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2226 result
:= g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2230 tagmask
: Integer = 0;
2232 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2233 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2234 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2235 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2236 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2237 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2238 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2240 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2242 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2243 if gdbg_map_use_accel_coldet
then
2245 if gdbg_map_use_tree_coldet
then
2247 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2248 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2249 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2251 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2252 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2257 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
);
2262 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2264 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2268 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2270 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2273 // slightly different from the old code, but meh...
2274 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2276 result
:= false; // don't stop, ever
2277 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2280 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2281 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2282 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2285 if not g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
) then exit
;
2287 texid
:= pan
.GetTextureID();
2288 // water? water has the highest priority, so stop right here
2289 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2291 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2293 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2297 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2298 if gdbg_map_use_accel_coldet
then
2300 texid
:= TEXTURE_NONE
;
2301 if gdbg_map_use_tree_coldet
then
2303 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2307 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2313 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2315 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2318 procedure g_Map_EnableWall(ID
: DWORD
);
2323 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2325 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2329 procedure g_Map_DisableWall(ID
: DWORD
);
2334 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2336 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2340 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2345 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2348 tp
:= gRenderForegrounds
[ID
];
2350 tp
:= gRenderBackgrounds
[ID
];
2363 tp
.NextTexture(AnimLoop
);
2364 if g_Game_IsServer
and g_Game_IsNet
then
2365 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2368 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2370 if gLifts
[ID
].LiftType
= t
then
2377 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2379 if LiftType
= 0 then
2380 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2381 else if LiftType
= 1 then
2382 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2383 else if LiftType
= 2 then
2384 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2385 else if LiftType
= 3 then
2386 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2388 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2392 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2395 PointsArray
: Array of TRespawnPoint
;
2398 SetLength(PointsArray
, 0);
2400 if RespawnPoints
= nil then
2403 for a
:= 0 to High(RespawnPoints
) do
2404 if RespawnPoints
[a
].PointType
= PointType
then
2406 SetLength(PointsArray
, Length(PointsArray
)+1);
2407 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2410 if PointsArray
= nil then
2413 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2417 function g_Map_GetPointCount(PointType
: Byte): Word;
2423 if RespawnPoints
= nil then
2426 for a
:= 0 to High(RespawnPoints
) do
2427 if RespawnPoints
[a
].PointType
= PointType
then
2428 Result
:= Result
+ 1;
2431 function g_Map_HaveFlagPoints(): Boolean;
2433 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2436 procedure g_Map_ResetFlag(Flag
: Byte);
2438 with gFlags
[Flag
] do
2444 Direction
:= D_LEFT
;
2445 State
:= FLAG_STATE_NONE
;
2446 if FlagPoints
[Flag
] <> nil then
2448 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2449 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2450 Direction
:= FlagPoints
[Flag
]^.Direction
;
2451 State
:= FLAG_STATE_NORMAL
;
2457 procedure g_Map_DrawFlags();
2460 Mirror
: TMirrorType
;
2462 if gGameSettings
.GameMode
<> GM_CTF
then
2465 for i
:= FLAG_RED
to FLAG_BLUE
do
2467 if State
<> FLAG_STATE_CAPTURED
then
2469 if State
= FLAG_STATE_NONE
then
2472 if Direction
= D_LEFT
then
2474 Mirror
:= M_HORIZONTAL
;
2483 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2485 if g_debug_Frames
then
2487 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2489 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2490 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2496 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2503 procedure SavePanelArray(var panels
: TPanelArray
);
2505 PAMem
: TBinMemoryWriter
;
2508 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2509 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2512 while i
< Length(panels
) do
2514 if panels
[i
].SaveIt
then
2518 // Ñîõðàíÿåì ïàíåëü:
2519 panels
[i
].SaveState(PAMem
);
2524 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2525 PAMem
.SaveToMemory(Mem
);
2529 procedure SaveFlag(flag
: PFlag
);
2532 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2534 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2535 Mem
.WriteByte(flag
^.RespawnType
);
2537 Mem
.WriteByte(flag
^.State
);
2538 // Íàïðàâëåíèå ôëàãà:
2539 if flag
^.Direction
= D_LEFT
then
2545 Obj_SaveState(@flag
^.Obj
, Mem
);
2549 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2551 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2552 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2553 SavePanelArray(gWalls
);
2554 // Ñîõðàíÿåì ïàíåëè ôîíà:
2555 SavePanelArray(gRenderBackgrounds
);
2556 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2557 SavePanelArray(gRenderForegrounds
);
2558 // Ñîõðàíÿåì ïàíåëè âîäû:
2559 SavePanelArray(gWater
);
2560 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2561 SavePanelArray(gAcid1
);
2562 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2563 SavePanelArray(gAcid2
);
2564 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2565 SavePanelArray(gSteps
);
2566 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2567 SavePanelArray(gLifts
);
2570 ///// Ñîõðàíÿåì ìóçûêó: /////
2571 // Ñèãíàòóðà ìóçûêè:
2572 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2575 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2576 if gMusic
.NoMusic
then
2580 Mem
.WriteString(str
, 64);
2581 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2582 dw
:= gMusic
.GetPosition();
2584 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2585 boo
:= gMusic
.SpecPause
;
2586 Mem
.WriteBoolean(boo
);
2589 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2590 Mem
.WriteInt(gTotalMonsters
);
2593 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2594 if gGameSettings
.GameMode
= GM_CTF
then
2596 // Ôëàã Êðàñíîé êîìàíäû:
2597 SaveFlag(@gFlags
[FLAG_RED
]);
2598 // Ôëàã Ñèíåé êîìàíäû:
2599 SaveFlag(@gFlags
[FLAG_BLUE
]);
2603 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2604 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2606 // Î÷êè Êðàñíîé êîìàíäû:
2607 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2608 // Î÷êè Ñèíåé êîìàíäû:
2609 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2614 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2621 procedure LoadPanelArray(var panels
: TPanelArray
);
2623 PAMem
: TBinMemoryReader
;
2626 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2627 PAMem
:= TBinMemoryReader
.Create();
2628 PAMem
.LoadFromMemory(Mem
);
2630 for i
:= 0 to Length(panels
)-1 do
2631 if panels
[i
].SaveIt
then
2637 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2639 // Çàãðóæàåì ïàíåëü:
2640 panels
[i
].LoadState(PAMem
);
2643 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2647 procedure LoadFlag(flag
: PFlag
);
2651 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2653 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2655 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2656 Mem
.ReadByte(flag
^.RespawnType
);
2658 Mem
.ReadByte(flag
^.State
);
2659 // Íàïðàâëåíèå ôëàãà:
2662 flag
^.Direction
:= D_LEFT
2664 flag
^.Direction
:= D_RIGHT
;
2666 Obj_LoadState(@flag
^.Obj
, Mem
);
2673 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2674 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2675 LoadPanelArray(gWalls
);
2676 // Çàãðóæàåì ïàíåëè ôîíà:
2677 LoadPanelArray(gRenderBackgrounds
);
2678 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2679 LoadPanelArray(gRenderForegrounds
);
2680 // Çàãðóæàåì ïàíåëè âîäû:
2681 LoadPanelArray(gWater
);
2682 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2683 LoadPanelArray(gAcid1
);
2684 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2685 LoadPanelArray(gAcid2
);
2686 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2687 LoadPanelArray(gSteps
);
2688 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2689 LoadPanelArray(gLifts
);
2692 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2696 ///// Çàãðóæàåì ìóçûêó: /////
2697 // Ñèãíàòóðà ìóçûêè:
2699 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2701 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2704 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2705 Mem
.ReadString(str
);
2706 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2708 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2709 Mem
.ReadBoolean(boo
);
2710 // Çàïóñêàåì ýòó ìóçûêó:
2711 gMusic
.SetByName(str
);
2712 gMusic
.SpecPause
:= boo
;
2715 gMusic
.SetPosition(dw
);
2718 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2719 Mem
.ReadInt(gTotalMonsters
);
2722 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2723 if gGameSettings
.GameMode
= GM_CTF
then
2725 // Ôëàã Êðàñíîé êîìàíäû:
2726 LoadFlag(@gFlags
[FLAG_RED
]);
2727 // Ôëàã Ñèíåé êîìàíäû:
2728 LoadFlag(@gFlags
[FLAG_BLUE
]);
2732 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2733 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2735 // Î÷êè Êðàñíîé êîìàíäû:
2736 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2737 // Î÷êè Ñèíåé êîìàíäû:
2738 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2743 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2748 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2749 Arr
:= PanelByID
[PanelID
].PWhere
^;
2750 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2751 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);