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
178 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
179 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
180 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
181 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
183 ImagingTypes
, Imaging
, ImagingUtility
,
184 ImagingGif
, ImagingNetworkGraphics
;
187 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
188 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
189 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
193 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
195 TDynAABBTreePanelBase
= specialize TDynAABBTreeBase
<TPanel
>;
197 TDynAABBTreeMap
= class(TDynAABBTreePanelBase
)
198 function getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean; override;
201 function TDynAABBTreeMap
.getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean;
204 if (pan
= nil) then begin aabb
:= AABB2D
.Create(0, 0, 0, 0); exit
; end;
205 aabb
:= AABB2D
.Create(pan
.X
, pan
.Y
, pan
.X
+pan
.Width
-1, pan
.Y
+pan
.Height
-1);
206 if (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
207 if not aabb
.valid
then raise Exception
.Create('wutafuuuuuuu?!');
212 function panelTypeToTag (panelType
: Word): Integer;
215 PANEL_WALL
: result
:= GridTagWall
; // gWalls
216 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
217 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
218 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
219 PANEL_WATER
: result
:= GridTagWater
; // gWater
220 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
221 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
222 PANEL_STEP
: result
:= GridTagStep
; // gSteps
223 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
224 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
225 else result
:= GridTagInvalid
;
230 function dplLess (a
, b
: TObject
): Boolean;
234 //result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
237 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
238 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
239 result
:= (pa
.ArrIdx
< pb
.ArrIdx
);
242 procedure dplClear ();
244 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
250 PWhere
: ^TPanelArray
;
255 PanelById
: array of TPanelID
;
256 Textures
: TLevelTextureArray
;
257 RespawnPoints
: Array of TRespawnPoint
;
258 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
259 //DOMFlagPoints: Array of TFlagPoint;
260 gMapGrid
: TPanelGrid
= nil;
261 mapTree
: TDynAABBTreeMap
= nil;
264 procedure g_Map_ProfilersBegin ();
266 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
267 profMapCollision
.mainBegin(g_profile_collision
);
269 if g_profile_collision
then
271 profMapCollision
.sectionBegin('*solids');
272 profMapCollision
.sectionEnd();
273 profMapCollision
.sectionBegin('liquids');
274 profMapCollision
.sectionEnd();
278 procedure g_Map_ProfilersEnd ();
280 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
284 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
286 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
287 (Texture
= TEXTURE_NAME_ACID1
) or
288 (Texture
= TEXTURE_NAME_ACID2
);
291 procedure CreateDoorMap();
293 PanelArray
: Array of record
299 a
, b
, c
, m
, i
, len
: Integer;
307 SetLength(PanelArray
, len
);
309 for a
:= 0 to High(gWalls
) do
310 if gWalls
[a
].Door
then
312 PanelArray
[i
].X
:= gWalls
[a
].X
;
313 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
314 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
315 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
316 PanelArray
[i
].Active
:= True;
317 PanelArray
[i
].PanelID
:= a
;
323 SetLength(PanelArray
, len
);
334 SetLength(gDoorMap
, 0);
336 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
339 if PanelArray
[a
].Active
then
341 PanelArray
[a
].Active
:= False;
342 m
:= Length(gDoorMap
);
343 SetLength(gDoorMap
, m
+1);
344 SetLength(gDoorMap
[m
], 1);
345 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
353 if PanelArray
[b
].Active
then
354 for c
:= 0 to High(gDoorMap
[m
]) do
355 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
356 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
357 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
358 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
359 gWalls
[gDoorMap
[m
, c
]].X
,
360 gWalls
[gDoorMap
[m
, c
]].Y
,
361 gWalls
[gDoorMap
[m
, c
]].Width
,
362 gWalls
[gDoorMap
[m
, c
]].Height
) then
364 PanelArray
[b
].Active
:= False;
365 SetLength(gDoorMap
[m
],
366 Length(gDoorMap
[m
])+1);
367 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
373 g_Game_StepLoading();
379 procedure CreateLiftMap();
381 PanelArray
: Array of record
386 a
, b
, c
, len
, i
, j
: Integer;
392 len
:= Length(gLifts
);
393 SetLength(PanelArray
, len
);
395 for a
:= 0 to len
-1 do
397 PanelArray
[a
].X
:= gLifts
[a
].X
;
398 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
399 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
400 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
401 PanelArray
[a
].Active
:= True;
404 SetLength(gLiftMap
, len
);
407 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
409 for a
:= 0 to len
-1 do
410 if PanelArray
[a
].Active
then
412 PanelArray
[a
].Active
:= False;
413 SetLength(gLiftMap
[i
], 32);
421 for b
:= 0 to len
-1 do
422 if PanelArray
[b
].Active
then
424 if g_CollideAround(PanelArray
[b
].X
,
427 PanelArray
[b
].Height
,
428 PanelArray
[gLiftMap
[i
, c
]].X
,
429 PanelArray
[gLiftMap
[i
, c
]].Y
,
430 PanelArray
[gLiftMap
[i
, c
]].Width
,
431 PanelArray
[gLiftMap
[i
, c
]].Height
) then
433 PanelArray
[b
].Active
:= False;
435 if j
> High(gLiftMap
[i
]) then
436 SetLength(gLiftMap
[i
],
437 Length(gLiftMap
[i
])+32);
446 SetLength(gLiftMap
[i
], j
+1);
449 g_Game_StepLoading();
452 SetLength(gLiftMap
, i
);
457 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
458 CurTex
: Integer; sav
: Boolean): Integer;
461 panels
: ^TPanelArray
;
465 case PanelRec
.PanelType
of
466 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
469 panels
:= @gRenderBackgrounds
;
471 panels
:= @gRenderForegrounds
;
480 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
483 panels
:= @gBlockMon
;
488 len
:= Length(panels
^);
489 SetLength(panels
^, len
+ 1);
491 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
492 panels
^[len
].ArrIdx
:= len
;
493 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
495 panels
^[len
].SaveIt
:= True;
499 len
:= Length(PanelByID
);
500 SetLength(PanelByID
, len
+ 1);
501 PanelByID
[len
].PWhere
:= panels
;
502 PanelByID
[len
].PArrID
:= Result
;
505 function CreateNullTexture(RecName
: String): Integer;
507 SetLength(Textures
, Length(Textures
)+1);
508 result
:= High(Textures
);
510 with Textures
[High(Textures
)] do
512 TextureName
:= RecName
;
516 TextureID
:= TEXTURE_NONE
;
520 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
523 TextureData
: Pointer;
524 WADName
, txname
: String;
525 a
, ResLength
: Integer;
529 if Textures
<> nil then
530 for a
:= 0 to High(Textures
) do
531 if Textures
[a
].TextureName
= RecName
then
532 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
537 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
538 if (RecName
= TEXTURE_NAME_WATER
) or
539 (RecName
= TEXTURE_NAME_ACID1
) or
540 (RecName
= TEXTURE_NAME_ACID2
) then
542 SetLength(Textures
, Length(Textures
)+1);
544 with Textures
[High(Textures
)] do
546 TextureName
:= RecName
;
548 if TextureName
= TEXTURE_NAME_WATER
then
549 TextureID
:= TEXTURE_SPECIAL_WATER
551 if TextureName
= TEXTURE_NAME_ACID1
then
552 TextureID
:= TEXTURE_SPECIAL_ACID1
554 if TextureName
= TEXTURE_NAME_ACID2
then
555 TextureID
:= TEXTURE_SPECIAL_ACID2
;
560 result
:= High(Textures
);
564 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
565 WADName
:= g_ExtractWadName(RecName
);
567 WAD
:= TWADFile
.Create();
569 if WADName
<> '' then
570 WADName
:= GameDir
+'/wads/'+WADName
574 WAD
.ReadFile(WADName
);
578 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
580 FreeMem(TextureData);
581 RecName := 'COMMON\ALIEN';
585 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
587 SetLength(Textures
, Length(Textures
)+1);
588 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
590 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
591 @Textures
[High(Textures
)].Width
,
592 @Textures
[High(Textures
)].Height
);
593 FreeMem(TextureData
);
594 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
595 Textures
[High(Textures
)].Anim
:= False;
597 result
:= High(Textures
);
599 else // Íåò òàêîãî ðåóñðñà â WAD'å
601 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
604 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
605 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
612 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
615 TextureWAD
: PChar = nil;
616 TextData
: Pointer = nil;
617 TextureData
: Pointer = nil;
621 TextureResource
: String;
622 _width
, _height
, _framecount
, _speed
: Integer;
623 _backanimation
: Boolean;
625 ia
: TDynImageDataArray
= nil;
626 f
, c
, frdelay
, frloop
: Integer;
630 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
632 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
633 WADName
:= g_ExtractWadName(RecName
);
635 WAD
:= TWADFile
.Create();
637 if WADName
<> '' then
638 WADName
:= GameDir
+'/wads/'+WADName
642 WAD
.ReadFile(WADName
);
644 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
648 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
649 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
655 if WADName = Map then
657 //FreeMem(TextureWAD);
658 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
664 if ResLength
< 6 then
666 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
670 // ýòî ïòèöà? ýòî ñàìîë¸ò?
671 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
672 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
674 // íåò, ýòî ñóïåðìåí!
675 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
677 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
681 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
682 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
684 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
688 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
690 TextureResource
:= cfg
.ReadStr('', 'resource', '');
691 if TextureResource
= '' then
693 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
697 _width
:= cfg
.ReadInt('', 'framewidth', 0);
698 _height
:= cfg
.ReadInt('', 'frameheight', 0);
699 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
700 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
701 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
706 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
707 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
709 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
716 SetLength(Textures
, Length(Textures
)+1);
717 with Textures
[High(Textures
)] do
719 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
720 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
722 TextureName
:= RecName
;
726 FramesCount
:= _framecount
;
728 result
:= High(Textures
);
732 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
738 // try animated image
740 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
741 if length(imgfmt) = 0 then
743 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
747 GlobalMetadata
.ClearMetaItems();
748 GlobalMetadata
.ClearMetaItemsForSaving();
749 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
751 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
754 if length(ia
) = 0 then
756 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
763 _width
:= ia
[0].width
;
764 _height
:= ia
[0].height
;
765 _framecount
:= length(ia
);
767 _backanimation
:= false;
770 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
772 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
774 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
776 if f
< 0 then f
:= 0;
779 if c
< 13 then c
:= 0 else c
:= 1;
781 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
786 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
788 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
790 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
792 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
796 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
797 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
798 f
:= ord(_backanimation
);
799 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
);
801 SetLength(Textures
, Length(Textures
)+1);
802 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
803 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
805 Textures
[High(Textures
)].TextureName
:= RecName
;
806 Textures
[High(Textures
)].Width
:= _width
;
807 Textures
[High(Textures
)].Height
:= _height
;
808 Textures
[High(Textures
)].Anim
:= True;
809 Textures
[High(Textures
)].FramesCount
:= length(ia
);
810 Textures
[High(Textures
)].Speed
:= _speed
;
811 result
:= High(Textures
);
812 //writeln(' CREATED!');
816 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
820 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
823 if TextureWAD
<> nil then FreeMem(TextureWAD
);
824 if TextData
<> nil then FreeMem(TextData
);
825 if TextureData
<> nil then FreeMem(TextureData
);
829 procedure CreateItem(Item
: TItemRec_1
);
831 if g_Game_IsClient
then Exit
;
833 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
834 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
837 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
838 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
841 procedure CreateArea(Area
: TAreaRec_1
);
846 case Area
.AreaType
of
847 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
848 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
850 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
851 with RespawnPoints
[High(RespawnPoints
)] do
855 Direction
:= TDirection(Area
.Direction
);
857 case Area
.AreaType
of
858 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
859 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
860 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
861 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
862 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
867 AREA_REDFLAG
, AREA_BLUEFLAG
:
869 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
871 if FlagPoints
[a
] <> nil then Exit
;
875 with FlagPoints
[a
]^ do
877 X
:= Area
.X
-FLAGRECT
.X
;
878 Y
:= Area
.Y
-FLAGRECT
.Y
;
879 Direction
:= TDirection(Area
.Direction
);
885 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
886 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
889 Animation
:= TAnimation
.Create(id
, True, 8);
890 Obj
.Rect
:= FLAGRECT
;
898 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
899 with DOMFlagPoints[High(DOMFlagPoints)] do
903 Direction := TDirection(Area.Direction);
906 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
911 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
915 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
921 Width
:= Trigger
.Width
;
922 Height
:= Trigger
.Height
;
923 Enabled
:= ByteBool(Trigger
.Enabled
);
924 TexturePanel
:= Trigger
.TexturePanel
;
925 TexturePanelType
:= fTexturePanel1Type
;
926 ShotPanelType
:= fTexturePanel2Type
;
927 TriggerType
:= Trigger
.TriggerType
;
928 ActivateType
:= Trigger
.ActivateType
;
929 Keys
:= Trigger
.Keys
;
930 Data
.Default
:= Trigger
.DATA
;
933 g_Triggers_Create(_trigger
);
936 procedure CreateMonster(monster
: TMonsterRec_1
);
940 if g_Game_IsClient
then Exit
;
942 if (gGameSettings
.GameType
= GT_SINGLE
)
943 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
945 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
946 TDirection(monster
.Direction
));
948 if gTriggers
<> nil then
949 for a
:= 0 to High(gTriggers
) do
950 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
951 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
952 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
953 gMonsters
[i
].AddTrigger(a
);
955 if monster
.MonsterType
<> MONSTER_BARREL
then
960 procedure g_Map_ReAdd_DieTriggers();
964 if g_Game_IsClient
then Exit
;
966 for i
:= 0 to High(gMonsters
) do
967 if gMonsters
[i
] <> nil then
969 gMonsters
[i
].ClearTriggers();
971 for a
:= 0 to High(gTriggers
) do
972 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
973 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
974 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
975 gMonsters
[i
].AddTrigger(a
);
979 function extractWadName(resourceName
: string): string;
983 posN
:= Pos(':', resourceName
);
985 Result
:= Copy(resourceName
, 0, posN
-1)
990 procedure addResToExternalResList(res
: string);
992 res
:= extractWadName(res
);
993 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
994 gExternalResources
.Add(res
);
997 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
999 textures
: TTexturesRec1Array
;
1000 mapHeader
: TMapHeaderRec_1
;
1002 resFile
: String = '';
1004 if gExternalResources
= nil then
1005 gExternalResources
:= TStringList
.Create
;
1007 gExternalResources
.Clear
;
1008 textures
:= mapReader
.GetTextures();
1009 for i
:= 0 to High(textures
) do
1011 addResToExternalResList(resFile
);
1016 mapHeader
:= mapReader
.GetMapHeader
;
1018 addResToExternalResList(mapHeader
.MusicName
);
1019 addResToExternalResList(mapHeader
.SkyName
);
1022 procedure mapCreateGrid ();
1024 mapX0
: Integer = $3fffffff;
1025 mapY0
: Integer = $3fffffff;
1026 mapX1
: Integer = -$3fffffff;
1027 mapY1
: Integer = -$3fffffff;
1029 procedure calcBoundingBox (var panels
: TPanelArray
);
1034 for idx
:= 0 to High(panels
) do
1037 if not pan
.visvalid
then continue
;
1038 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1039 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1040 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1041 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1042 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1046 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
1051 tag
:= panelTypeToTag(tag
);
1052 for idx
:= High(panels
) downto 0 do
1056 if not pan
.visvalid
then continue
;
1057 gMapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1058 mapTree
.insertObject(pan
, tag
, true); // as static object
1068 calcBoundingBox(gWalls
);
1069 calcBoundingBox(gRenderBackgrounds
);
1070 calcBoundingBox(gRenderForegrounds
);
1071 calcBoundingBox(gWater
);
1072 calcBoundingBox(gAcid1
);
1073 calcBoundingBox(gAcid2
);
1074 calcBoundingBox(gSteps
);
1075 calcBoundingBox(gLifts
);
1076 calcBoundingBox(gBlockMon
);
1078 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1080 gMapGrid
:= TPanelGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1081 mapTree
:= TDynAABBTreeMap
.Create();
1083 addPanelsToGrid(gWalls
, PANEL_WALL
);
1084 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1085 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1086 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1087 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1088 addPanelsToGrid(gWater
, PANEL_WATER
);
1089 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1090 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1091 addPanelsToGrid(gSteps
, PANEL_STEP
);
1092 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1093 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1095 gMapGrid
.dumpStats();
1096 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1097 mapTree
.forEachLeaf(nil);
1100 function g_Map_Load(Res
: String): Boolean;
1102 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1103 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1106 MapReader
: TMapReader_1
;
1107 Header
: TMapHeaderRec_1
;
1108 _textures
: TTexturesRec1Array
;
1109 _texnummap
: array of Integer; // `_textures` -> `Textures`
1110 panels
: TPanelsRec1Array
;
1111 items
: TItemsRec1Array
;
1112 monsters
: TMonsterRec1Array
;
1113 areas
: TAreasRec1Array
;
1114 triggers
: TTriggersRec1Array
;
1115 a
, b
, c
, k
: Integer;
1117 AddTextures
: TAddTextureArray
;
1118 texture
: TTextureRec_1
;
1119 TriggersTable
: Array of record
1120 TexturePanel
: Integer;
1125 FileName
, mapResName
, s
, TexName
: String;
1128 ok
, isAnim
, trigRef
: Boolean;
1129 CurTex
, ntn
: Integer;
1138 gMapInfo
.Map
:= Res
;
1139 TriggersTable
:= nil;
1140 FillChar(texture
, SizeOf(texture
), 0);
1142 sfsGCDisable(); // temporary disable removing of temporary volumes
1145 FileName
:= g_ExtractWadName(Res
);
1146 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1147 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1149 WAD
:= TWADFile
.Create();
1150 if not WAD
.ReadFile(FileName
) then
1152 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1156 //k8: why loader ignores path here?
1157 mapResName
:= g_ExtractFileName(Res
);
1158 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1160 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1168 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1169 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1170 MapReader
:= TMapReader_1
.Create();
1172 if not MapReader
.LoadMap(Data
) then
1174 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1181 generateExternalResourcesList(MapReader
);
1182 // Çàãðóçêà òåêñòóð:
1183 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1184 _textures
:= MapReader
.GetTextures();
1187 // Äîáàâëåíèå òåêñòóð â Textures[]:
1188 if _textures
<> nil then
1190 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1191 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1192 SetLength(_texnummap
, length(_textures
));
1194 for a
:= 0 to High(_textures
) do
1197 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1198 for b
:= 1 to Length(s
) do
1204 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1205 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1206 // Àíèìèðîâàííàÿ òåêñòóðà:
1207 if ByteBool(_textures
[a
].Anim
) then
1209 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1212 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1213 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1216 else // Îáû÷íàÿ òåêñòóðà:
1217 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1220 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1221 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1224 _texnummap
[a
] := ntn
; // fix texture number
1225 g_Game_StepLoading();
1229 // Çàãðóçêà òðèããåðîâ:
1230 gTriggerClientID
:= 0;
1231 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1232 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1233 triggers
:= MapReader
.GetTriggers();
1235 // Çàãðóçêà ïàíåëåé:
1236 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1237 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1238 panels
:= MapReader
.GetPanels();
1240 // check texture numbers for panels
1241 for a
:= 0 to High(panels
) do
1243 if panels
[a
].TextureNum
> High(_textures
) then
1245 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1249 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1252 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1253 if triggers
<> nil then
1255 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1256 SetLength(TriggersTable
, Length(triggers
));
1257 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1259 for a
:= 0 to High(TriggersTable
) do
1261 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1262 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1264 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1265 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1267 TriggersTable
[a
].LiftPanel
:= -1;
1269 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1270 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1271 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1272 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1274 TriggersTable
[a
].DoorPanel
:= -1;
1276 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1277 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1279 TriggersTable
[a
].ShotPanel
:= -1;
1281 g_Game_StepLoading();
1286 if panels
<> nil then
1288 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1289 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1291 for a
:= 0 to High(panels
) do
1293 SetLength(AddTextures
, 0);
1296 if _textures
<> nil then
1298 texture
:= _textures
[panels
[a
].TextureNum
];
1306 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1307 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1309 if (TriggersTable
<> nil) and (_textures
<> nil) then
1310 for b
:= 0 to High(TriggersTable
) do
1311 if (TriggersTable
[b
].TexturePanel
= a
)
1312 or (TriggersTable
[b
].ShotPanel
= a
) then
1321 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1323 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1326 for c
:= Len
downto 1 do
1334 // Ñïåö-òåêñòóðû çàïðåùåíû:
1335 if g_Map_IsSpecialTexture(s
) then
1338 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1339 ok
:= g_Texture_NumNameFindStart(s
);
1341 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1342 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1345 k
:= NNF_NAME_BEFORE
;
1346 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1347 while ok
or (k
= NNF_NAME_BEFORE
) or
1348 (k
= NNF_NAME_EQUALS
) do
1350 k
:= g_Texture_NumNameFindNext(TexName
);
1352 if (k
= NNF_NAME_BEFORE
) or
1353 (k
= NNF_NAME_AFTER
) then
1355 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1356 if ByteBool(texture
.Anim
) then
1357 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1359 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1361 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1363 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1367 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1369 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1371 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1373 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1377 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1380 for c
:= 0 to High(Textures
) do
1381 if Textures
[c
].TextureName
= TexName
then
1383 SetLength(AddTextures
, Length(AddTextures
)+1);
1384 AddTextures
[High(AddTextures
)].Texture
:= c
;
1385 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1391 if k
= NNF_NAME_EQUALS
then
1393 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1394 SetLength(AddTextures
, Length(AddTextures
)+1);
1395 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1396 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1397 CurTex
:= High(AddTextures
);
1405 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1406 end; // if ok - ññûëàþòñÿ òðèããåðû
1410 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1411 SetLength(AddTextures
, 1);
1412 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1413 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1417 //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);
1419 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1420 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1422 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1423 if TriggersTable
<> nil then
1424 for b
:= 0 to High(TriggersTable
) do
1426 // Òðèããåð äâåðè/ëèôòà:
1427 if (TriggersTable
[b
].LiftPanel
= a
) or
1428 (TriggersTable
[b
].DoorPanel
= a
) then
1429 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1430 // Òðèããåð ñìåíû òåêñòóðû:
1431 if TriggersTable
[b
].TexturePanel
= a
then
1432 triggers
[b
].TexturePanel
:= PanelID
;
1433 // Òðèããåð "Òóðåëü":
1434 if TriggersTable
[b
].ShotPanel
= a
then
1435 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1438 g_Game_StepLoading();
1442 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1443 if (triggers
<> nil) and not gLoadGameMode
then
1445 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1446 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1447 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1448 for a
:= 0 to High(triggers
) do
1450 if triggers
[a
].TexturePanel
<> -1 then
1451 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1454 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1455 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1456 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1459 CreateTrigger(triggers
[a
], b
, c
);
1463 // Çàãðóçêà ïðåäìåòîâ:
1464 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1465 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1466 items
:= MapReader
.GetItems();
1468 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1469 if (items
<> nil) and not gLoadGameMode
then
1471 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1472 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1473 for a
:= 0 to High(items
) do
1474 CreateItem(Items
[a
]);
1477 // Çàãðóçêà îáëàñòåé:
1478 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1479 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1480 areas
:= MapReader
.GetAreas();
1482 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1483 if areas
<> nil then
1485 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1486 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1487 for a
:= 0 to High(areas
) do
1488 CreateArea(areas
[a
]);
1491 // Çàãðóçêà ìîíñòðîâ:
1492 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1493 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1494 monsters
:= MapReader
.GetMonsters();
1496 gTotalMonsters
:= 0;
1498 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1499 if (monsters
<> nil) and not gLoadGameMode
then
1501 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1502 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1503 for a
:= 0 to High(monsters
) do
1504 CreateMonster(monsters
[a
]);
1507 // Çàãðóçêà îïèñàíèÿ êàðòû:
1508 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1509 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1510 Header
:= MapReader
.GetMapHeader();
1516 Name
:= Header
.MapName
;
1517 Description
:= Header
.MapDescription
;
1518 Author
:= Header
.MapAuthor
;
1519 MusicName
:= Header
.MusicName
;
1520 SkyName
:= Header
.SkyName
;
1521 Height
:= Header
.Height
;
1522 Width
:= Header
.Width
;
1526 if gMapInfo
.SkyName
<> '' then
1528 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1529 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1530 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1532 if FileName
<> '' then
1533 FileName
:= GameDir
+'/wads/'+FileName
1536 FileName
:= g_ExtractWadName(Res
);
1539 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1540 if g_Texture_CreateWAD(BackID
, s
) then
1542 g_Game_SetupScreenSize();
1545 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1550 if gMapInfo
.MusicName
<> '' then
1552 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1553 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1554 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1556 if FileName
<> '' then
1557 FileName
:= GameDir
+'/wads/'+FileName
1560 FileName
:= g_ExtractWadName(Res
);
1563 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1564 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1567 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1570 // Îñòàëüíûå óñòàíâêè:
1578 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1579 if not gLoadGameMode
then
1582 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1588 TriggersTable
:= nil;
1591 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1592 if ok
and (not gLoadGameMode
) then
1594 gMusic
.SetByName(gMapInfo
.MusicName
);
1598 gMusic
.SetByName('');
1600 sfsGCEnable(); // enable releasing unused volumes
1603 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1606 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1610 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1613 MapReader
: TMapReader_1
;
1614 Header
: TMapHeaderRec_1
;
1619 FillChar(Result
, SizeOf(Result
), 0);
1620 FileName
:= g_ExtractWadName(Res
);
1622 WAD
:= TWADFile
.Create();
1623 if not WAD
.ReadFile(FileName
) then
1629 //k8: it ignores path again
1630 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1638 MapReader
:= TMapReader_1
.Create();
1640 if not MapReader
.LoadMap(Data
) then
1642 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1643 ZeroMemory(@Header
, SizeOf(Header
));
1644 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1645 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1649 Header
:= MapReader
.GetMapHeader();
1650 Result
.Name
:= Header
.MapName
;
1651 Result
.Description
:= Header
.MapDescription
;
1658 Result
.Author
:= Header
.MapAuthor
;
1659 Result
.Height
:= Header
.Height
;
1660 Result
.Width
:= Header
.Width
;
1663 function g_Map_GetMapsList(WADName
: string): SArray
;
1670 WAD
:= TWADFile
.Create();
1671 if not WAD
.ReadFile(WADName
) then
1676 ResList
:= WAD
.GetMapResources();
1677 if ResList
<> nil then
1679 for a
:= 0 to High(ResList
) do
1681 SetLength(Result
, Length(Result
)+1);
1682 Result
[High(Result
)] := ResList
[a
];
1688 function g_Map_Exist(Res
: string): Boolean;
1691 FileName
, mnn
: string;
1697 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1699 WAD
:= TWADFile
.Create
;
1700 if not WAD
.ReadFile(FileName
) then
1706 ResList
:= WAD
.GetMapResources();
1709 mnn
:= g_ExtractFileName(Res
);
1710 if ResList
<> nil then
1711 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1718 procedure g_Map_Free();
1722 procedure FreePanelArray(var panels
: TPanelArray
);
1727 if panels
<> nil then
1729 for i
:= 0 to High(panels
) do
1742 RespawnPoints
:= nil;
1743 if FlagPoints
[FLAG_RED
] <> nil then
1745 Dispose(FlagPoints
[FLAG_RED
]);
1746 FlagPoints
[FLAG_RED
] := nil;
1748 if FlagPoints
[FLAG_BLUE
] <> nil then
1750 Dispose(FlagPoints
[FLAG_BLUE
]);
1751 FlagPoints
[FLAG_BLUE
] := nil;
1753 //DOMFlagPoints := nil;
1757 if Textures
<> nil then
1759 for a
:= 0 to High(Textures
) do
1760 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1761 if Textures
[a
].Anim
then
1762 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1764 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1765 e_DeleteTexture(Textures
[a
].TextureID
);
1770 FreePanelArray(gWalls
);
1771 FreePanelArray(gRenderBackgrounds
);
1772 FreePanelArray(gRenderForegrounds
);
1773 FreePanelArray(gWater
);
1774 FreePanelArray(gAcid1
);
1775 FreePanelArray(gAcid2
);
1776 FreePanelArray(gSteps
);
1777 FreePanelArray(gLifts
);
1778 FreePanelArray(gBlockMon
);
1780 if BackID
<> DWORD(-1) then
1784 e_DeleteTexture(BackID
);
1785 BackID
:= DWORD(-1);
1788 g_Game_StopAllSounds(False);
1790 g_Sound_Delete(gMapInfo
.MusicName
);
1792 gMapInfo
.Name
:= '';
1793 gMapInfo
.Description
:= '';
1794 gMapInfo
.MusicName
:= '';
1795 gMapInfo
.Height
:= 0;
1796 gMapInfo
.Width
:= 0;
1804 procedure g_Map_Update();
1810 procedure UpdatePanelArray(var panels
: TPanelArray
);
1815 if panels
<> nil then
1816 for i
:= 0 to High(panels
) do
1821 UpdatePanelArray(gWalls
);
1822 UpdatePanelArray(gRenderBackgrounds
);
1823 UpdatePanelArray(gRenderForegrounds
);
1824 UpdatePanelArray(gWater
);
1825 UpdatePanelArray(gAcid1
);
1826 UpdatePanelArray(gAcid2
);
1827 UpdatePanelArray(gSteps
);
1829 if gGameSettings
.GameMode
= GM_CTF
then
1831 for a
:= FLAG_RED
to FLAG_BLUE
do
1832 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1835 if gFlags
[a
].Animation
<> nil then
1836 gFlags
[a
].Animation
.Update();
1838 m
:= g_Obj_Move(@Obj
, True, True);
1840 if gTime
mod (GAME_TICK
*2) <> 0 then
1843 // Ñîïðîòèâëåíèå âîçäóõà:
1844 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1846 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1847 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1850 gFlags
[a
].CaptureTime
:= 0;
1851 if a
= FLAG_RED
then
1852 s
:= _lc
[I_PLAYER_FLAG_RED
]
1854 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1855 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1857 if g_Game_IsNet
then
1858 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1865 // Èãðîê áåðåò ôëàã:
1866 if gPlayers
<> nil then
1868 j
:= Random(Length(gPlayers
)) - 1;
1870 for d
:= 0 to High(gPlayers
) do
1873 if j
> High(gPlayers
) then
1876 if gPlayers
[j
] <> nil then
1877 if gPlayers
[j
].Live
and
1878 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1880 if gPlayers
[j
].GetFlag(a
) then
1891 procedure g_Map_DrawPanels (PanelType
: Word);
1893 procedure DrawPanels (var panels
: TPanelArray
; drawDoors
: Boolean=False);
1897 if (panels
<> nil) then
1899 // alas, no visible set
1900 for idx
:= 0 to High(panels
) do
1902 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1909 PANEL_WALL
: DrawPanels(gWalls
);
1910 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1911 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1912 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1913 PANEL_WATER
: DrawPanels(gWater
);
1914 PANEL_ACID1
: DrawPanels(gAcid1
);
1915 PANEL_ACID2
: DrawPanels(gAcid2
);
1916 PANEL_STEP
: DrawPanels(gSteps
);
1922 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
1923 function checker (pan
: TPanel
; tag
: Integer): Boolean;
1925 result
:= false; // don't stop, ever
1926 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
1927 gDrawPanelList
.insert(pan
);
1932 //tagmask := panelTypeToTag(PanelType);
1934 if gdbg_map_use_tree_draw
then
1936 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
1940 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
1942 // list will be rendered in `g_game.DrawPlayer()`
1946 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1947 function checker (pan
: TPanel
; tag
: Integer): Boolean;
1949 result
:= false; // don't stop, ever
1950 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1954 if gdbg_map_use_tree_draw
then
1956 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
1960 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
1965 procedure g_Map_DrawBack(dx
, dy
: Integer);
1967 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1968 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1970 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1973 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1974 PanelType
: Word; b1x3
: Boolean): Boolean;
1980 if WordBool(PanelType
and PANEL_WALL
) then
1981 if gWalls
<> nil then
1986 if gWalls
[a
].Enabled
and
1987 g_Collide(X
, Y
, Width
, Height
,
1988 gWalls
[a
].X
, gWalls
[a
].Y
,
1989 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1996 if WordBool(PanelType
and PANEL_WATER
) then
1997 if gWater
<> nil then
2002 if g_Collide(X
, Y
, Width
, Height
,
2003 gWater
[a
].X
, gWater
[a
].Y
,
2004 gWater
[a
].Width
, gWater
[a
].Height
) then
2011 if WordBool(PanelType
and PANEL_ACID1
) then
2012 if gAcid1
<> nil then
2017 if g_Collide(X
, Y
, Width
, Height
,
2018 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2019 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2026 if WordBool(PanelType
and PANEL_ACID2
) then
2027 if gAcid2
<> nil then
2032 if g_Collide(X
, Y
, Width
, Height
,
2033 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2034 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2041 if WordBool(PanelType
and PANEL_STEP
) then
2042 if gSteps
<> nil then
2047 if g_Collide(X
, Y
, Width
, Height
,
2048 gSteps
[a
].X
, gSteps
[a
].Y
,
2049 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2056 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2057 if gLifts
<> nil then
2062 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2063 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2064 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2065 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2066 g_Collide(X
, Y
, Width
, Height
,
2067 gLifts
[a
].X
, gLifts
[a
].Y
,
2068 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2075 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2076 if gBlockMon
<> nil then
2078 h
:= High(gBlockMon
);
2082 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2083 g_Collide(X
, Y
, Width
, Height
,
2084 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2085 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2093 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2097 function checkPanels (var panels
: TPanelArray
): Boolean;
2102 if panels
= nil then exit
;
2103 for a
:= 0 to High(panels
) do
2105 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2108 texid
:= panels
[a
].GetTextureID();
2115 texid
:= TEXTURE_NONE
;
2117 if not checkPanels(gWater
) then
2118 if not checkPanels(gAcid1
) then
2119 if not checkPanels(gAcid2
) then exit
;
2124 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2125 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2127 result
:= false; // don't stop, ever
2129 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
2131 if not pan
.Enabled
then exit
;
2134 if ((tag
and GridTagLift
) <> 0) then
2137 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2138 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2139 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2140 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) and
2141 g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2145 if ((tag
and GridTagBlockMon
) <> 0) then
2147 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)) and g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2152 result
:= g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2156 tagmask
: Integer = 0;
2158 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2159 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2160 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2161 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2162 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2163 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2164 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2166 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2168 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2169 if gdbg_map_use_accel_coldet
then
2171 if gdbg_map_use_tree_coldet
then
2173 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2174 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2175 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2177 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2178 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2183 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
);
2188 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2190 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2194 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2196 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2199 // slightly different from the old code, but meh...
2200 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2202 result
:= false; // don't stop, ever
2203 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2206 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2207 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2208 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2211 if not g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
) then exit
;
2213 texid
:= pan
.GetTextureID();
2214 // water? water has the highest priority, so stop right here
2215 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2217 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2219 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2223 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2224 if gdbg_map_use_accel_coldet
then
2226 texid
:= TEXTURE_NONE
;
2227 if gdbg_map_use_tree_coldet
then
2229 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2233 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2239 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2241 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2244 procedure g_Map_EnableWall(ID
: DWORD
);
2249 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2251 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2255 procedure g_Map_DisableWall(ID
: DWORD
);
2260 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2262 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2266 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2271 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2274 tp
:= gRenderForegrounds
[ID
];
2276 tp
:= gRenderBackgrounds
[ID
];
2289 tp
.NextTexture(AnimLoop
);
2290 if g_Game_IsServer
and g_Game_IsNet
then
2291 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2294 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2296 if gLifts
[ID
].LiftType
= t
then
2303 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2305 if LiftType
= 0 then
2306 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2307 else if LiftType
= 1 then
2308 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2309 else if LiftType
= 2 then
2310 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2311 else if LiftType
= 3 then
2312 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2314 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2318 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2321 PointsArray
: Array of TRespawnPoint
;
2324 SetLength(PointsArray
, 0);
2326 if RespawnPoints
= nil then
2329 for a
:= 0 to High(RespawnPoints
) do
2330 if RespawnPoints
[a
].PointType
= PointType
then
2332 SetLength(PointsArray
, Length(PointsArray
)+1);
2333 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2336 if PointsArray
= nil then
2339 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2343 function g_Map_GetPointCount(PointType
: Byte): Word;
2349 if RespawnPoints
= nil then
2352 for a
:= 0 to High(RespawnPoints
) do
2353 if RespawnPoints
[a
].PointType
= PointType
then
2354 Result
:= Result
+ 1;
2357 function g_Map_HaveFlagPoints(): Boolean;
2359 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2362 procedure g_Map_ResetFlag(Flag
: Byte);
2364 with gFlags
[Flag
] do
2370 Direction
:= D_LEFT
;
2371 State
:= FLAG_STATE_NONE
;
2372 if FlagPoints
[Flag
] <> nil then
2374 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2375 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2376 Direction
:= FlagPoints
[Flag
]^.Direction
;
2377 State
:= FLAG_STATE_NORMAL
;
2383 procedure g_Map_DrawFlags();
2386 Mirror
: TMirrorType
;
2388 if gGameSettings
.GameMode
<> GM_CTF
then
2391 for i
:= FLAG_RED
to FLAG_BLUE
do
2393 if State
<> FLAG_STATE_CAPTURED
then
2395 if State
= FLAG_STATE_NONE
then
2398 if Direction
= D_LEFT
then
2400 Mirror
:= M_HORIZONTAL
;
2409 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2411 if g_debug_Frames
then
2413 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2415 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2416 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2422 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2429 procedure SavePanelArray(var panels
: TPanelArray
);
2431 PAMem
: TBinMemoryWriter
;
2434 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2435 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2438 while i
< Length(panels
) do
2440 if panels
[i
].SaveIt
then
2444 // Ñîõðàíÿåì ïàíåëü:
2445 panels
[i
].SaveState(PAMem
);
2450 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2451 PAMem
.SaveToMemory(Mem
);
2455 procedure SaveFlag(flag
: PFlag
);
2458 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2460 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2461 Mem
.WriteByte(flag
^.RespawnType
);
2463 Mem
.WriteByte(flag
^.State
);
2464 // Íàïðàâëåíèå ôëàãà:
2465 if flag
^.Direction
= D_LEFT
then
2471 Obj_SaveState(@flag
^.Obj
, Mem
);
2475 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2477 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2478 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2479 SavePanelArray(gWalls
);
2480 // Ñîõðàíÿåì ïàíåëè ôîíà:
2481 SavePanelArray(gRenderBackgrounds
);
2482 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2483 SavePanelArray(gRenderForegrounds
);
2484 // Ñîõðàíÿåì ïàíåëè âîäû:
2485 SavePanelArray(gWater
);
2486 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2487 SavePanelArray(gAcid1
);
2488 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2489 SavePanelArray(gAcid2
);
2490 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2491 SavePanelArray(gSteps
);
2492 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2493 SavePanelArray(gLifts
);
2496 ///// Ñîõðàíÿåì ìóçûêó: /////
2497 // Ñèãíàòóðà ìóçûêè:
2498 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2501 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2502 if gMusic
.NoMusic
then
2506 Mem
.WriteString(str
, 64);
2507 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2508 dw
:= gMusic
.GetPosition();
2510 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2511 boo
:= gMusic
.SpecPause
;
2512 Mem
.WriteBoolean(boo
);
2515 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2516 Mem
.WriteInt(gTotalMonsters
);
2519 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2520 if gGameSettings
.GameMode
= GM_CTF
then
2522 // Ôëàã Êðàñíîé êîìàíäû:
2523 SaveFlag(@gFlags
[FLAG_RED
]);
2524 // Ôëàã Ñèíåé êîìàíäû:
2525 SaveFlag(@gFlags
[FLAG_BLUE
]);
2529 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2530 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2532 // Î÷êè Êðàñíîé êîìàíäû:
2533 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2534 // Î÷êè Ñèíåé êîìàíäû:
2535 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2540 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2547 procedure LoadPanelArray(var panels
: TPanelArray
);
2549 PAMem
: TBinMemoryReader
;
2552 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2553 PAMem
:= TBinMemoryReader
.Create();
2554 PAMem
.LoadFromMemory(Mem
);
2556 for i
:= 0 to Length(panels
)-1 do
2557 if panels
[i
].SaveIt
then
2563 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2565 // Çàãðóæàåì ïàíåëü:
2566 panels
[i
].LoadState(PAMem
);
2569 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2573 procedure LoadFlag(flag
: PFlag
);
2577 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2579 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2581 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2582 Mem
.ReadByte(flag
^.RespawnType
);
2584 Mem
.ReadByte(flag
^.State
);
2585 // Íàïðàâëåíèå ôëàãà:
2588 flag
^.Direction
:= D_LEFT
2590 flag
^.Direction
:= D_RIGHT
;
2592 Obj_LoadState(@flag
^.Obj
, Mem
);
2599 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2600 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2601 LoadPanelArray(gWalls
);
2602 // Çàãðóæàåì ïàíåëè ôîíà:
2603 LoadPanelArray(gRenderBackgrounds
);
2604 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2605 LoadPanelArray(gRenderForegrounds
);
2606 // Çàãðóæàåì ïàíåëè âîäû:
2607 LoadPanelArray(gWater
);
2608 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2609 LoadPanelArray(gAcid1
);
2610 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2611 LoadPanelArray(gAcid2
);
2612 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2613 LoadPanelArray(gSteps
);
2614 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2615 LoadPanelArray(gLifts
);
2618 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2622 ///// Çàãðóæàåì ìóçûêó: /////
2623 // Ñèãíàòóðà ìóçûêè:
2625 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2627 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2630 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2631 Mem
.ReadString(str
);
2632 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2634 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2635 Mem
.ReadBoolean(boo
);
2636 // Çàïóñêàåì ýòó ìóçûêó:
2637 gMusic
.SetByName(str
);
2638 gMusic
.SpecPause
:= boo
;
2641 gMusic
.SetPosition(dw
);
2644 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2645 Mem
.ReadInt(gTotalMonsters
);
2648 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2649 if gGameSettings
.GameMode
= GM_CTF
then
2651 // Ôëàã Êðàñíîé êîìàíäû:
2652 LoadFlag(@gFlags
[FLAG_RED
]);
2653 // Ôëàã Ñèíåé êîìàíäû:
2654 LoadFlag(@gFlags
[FLAG_BLUE
]);
2658 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2659 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2661 // Î÷êè Êðàñíîé êîìàíäû:
2662 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2663 // Î÷êè Ñèíåé êîìàíäû:
2664 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2669 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2674 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2675 Arr
:= PanelByID
[PanelID
].PWhere
^;
2676 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2677 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);