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
);
941 if g_Game_IsClient
then Exit
;
943 if (gGameSettings
.GameType
= GT_SINGLE
)
944 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
946 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
948 if gTriggers
<> nil then
950 for a
:= 0 to High(gTriggers
) do
952 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
954 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
959 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
963 procedure g_Map_ReAdd_DieTriggers();
965 function monsDieTrig (monidx
: Integer; mon
: TMonster
): Boolean;
969 result
:= false; // don't stop
971 for a
:= 0 to High(gTriggers
) do
973 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
975 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
981 if g_Game_IsClient
then Exit
;
983 g_Mons_ForEach(monsDieTrig
);
986 function extractWadName(resourceName
: string): string;
990 posN
:= Pos(':', resourceName
);
992 Result
:= Copy(resourceName
, 0, posN
-1)
997 procedure addResToExternalResList(res
: string);
999 res
:= extractWadName(res
);
1000 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1001 gExternalResources
.Add(res
);
1004 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1006 textures
: TTexturesRec1Array
;
1007 mapHeader
: TMapHeaderRec_1
;
1009 resFile
: String = '';
1011 if gExternalResources
= nil then
1012 gExternalResources
:= TStringList
.Create
;
1014 gExternalResources
.Clear
;
1015 textures
:= mapReader
.GetTextures();
1016 for i
:= 0 to High(textures
) do
1018 addResToExternalResList(resFile
);
1023 mapHeader
:= mapReader
.GetMapHeader
;
1025 addResToExternalResList(mapHeader
.MusicName
);
1026 addResToExternalResList(mapHeader
.SkyName
);
1029 procedure mapCreateGrid ();
1031 mapX0
: Integer = $3fffffff;
1032 mapY0
: Integer = $3fffffff;
1033 mapX1
: Integer = -$3fffffff;
1034 mapY1
: Integer = -$3fffffff;
1036 procedure calcBoundingBox (constref panels
: TPanelArray
);
1041 for idx
:= 0 to High(panels
) do
1044 if not pan
.visvalid
then continue
;
1045 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1046 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1047 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1048 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1049 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1053 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1058 tag
:= panelTypeToTag(tag
);
1059 for idx
:= High(panels
) downto 0 do
1063 if not pan
.visvalid
then continue
;
1064 gMapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1065 mapTree
.insertObject(pan
, tag
, true); // as static object
1075 calcBoundingBox(gWalls
);
1076 calcBoundingBox(gRenderBackgrounds
);
1077 calcBoundingBox(gRenderForegrounds
);
1078 calcBoundingBox(gWater
);
1079 calcBoundingBox(gAcid1
);
1080 calcBoundingBox(gAcid2
);
1081 calcBoundingBox(gSteps
);
1082 calcBoundingBox(gLifts
);
1083 calcBoundingBox(gBlockMon
);
1085 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1087 gMapGrid
:= TPanelGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1088 mapTree
:= TDynAABBTreeMap
.Create();
1090 addPanelsToGrid(gWalls
, PANEL_WALL
);
1091 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1092 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1093 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1094 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1095 addPanelsToGrid(gWater
, PANEL_WATER
);
1096 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1097 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1098 addPanelsToGrid(gSteps
, PANEL_STEP
);
1099 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1100 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1102 gMapGrid
.dumpStats();
1103 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1104 mapTree
.forEachLeaf(nil);
1107 function g_Map_Load(Res
: String): Boolean;
1109 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1110 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1113 MapReader
: TMapReader_1
;
1114 Header
: TMapHeaderRec_1
;
1115 _textures
: TTexturesRec1Array
;
1116 _texnummap
: array of Integer; // `_textures` -> `Textures`
1117 panels
: TPanelsRec1Array
;
1118 items
: TItemsRec1Array
;
1119 monsters
: TMonsterRec1Array
;
1120 areas
: TAreasRec1Array
;
1121 triggers
: TTriggersRec1Array
;
1122 a
, b
, c
, k
: Integer;
1124 AddTextures
: TAddTextureArray
;
1125 texture
: TTextureRec_1
;
1126 TriggersTable
: Array of record
1127 TexturePanel
: Integer;
1132 FileName
, mapResName
, s
, TexName
: String;
1135 ok
, isAnim
, trigRef
: Boolean;
1136 CurTex
, ntn
: Integer;
1145 gMapInfo
.Map
:= Res
;
1146 TriggersTable
:= nil;
1147 FillChar(texture
, SizeOf(texture
), 0);
1149 sfsGCDisable(); // temporary disable removing of temporary volumes
1152 FileName
:= g_ExtractWadName(Res
);
1153 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1154 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1156 WAD
:= TWADFile
.Create();
1157 if not WAD
.ReadFile(FileName
) then
1159 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1163 //k8: why loader ignores path here?
1164 mapResName
:= g_ExtractFileName(Res
);
1165 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1167 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1175 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1176 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1177 MapReader
:= TMapReader_1
.Create();
1179 if not MapReader
.LoadMap(Data
) then
1181 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1188 generateExternalResourcesList(MapReader
);
1189 // Çàãðóçêà òåêñòóð:
1190 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1191 _textures
:= MapReader
.GetTextures();
1194 // Äîáàâëåíèå òåêñòóð â Textures[]:
1195 if _textures
<> nil then
1197 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1198 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1199 SetLength(_texnummap
, length(_textures
));
1201 for a
:= 0 to High(_textures
) do
1204 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1205 for b
:= 1 to Length(s
) do
1211 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1212 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1213 // Àíèìèðîâàííàÿ òåêñòóðà:
1214 if ByteBool(_textures
[a
].Anim
) then
1216 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1219 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1220 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1223 else // Îáû÷íàÿ òåêñòóðà:
1224 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1227 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1228 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1231 _texnummap
[a
] := ntn
; // fix texture number
1232 g_Game_StepLoading();
1236 // Çàãðóçêà òðèããåðîâ:
1237 gTriggerClientID
:= 0;
1238 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1239 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1240 triggers
:= MapReader
.GetTriggers();
1242 // Çàãðóçêà ïàíåëåé:
1243 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1244 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1245 panels
:= MapReader
.GetPanels();
1247 // check texture numbers for panels
1248 for a
:= 0 to High(panels
) do
1250 if panels
[a
].TextureNum
> High(_textures
) then
1252 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1256 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1259 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1260 if triggers
<> nil then
1262 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1263 SetLength(TriggersTable
, Length(triggers
));
1264 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1266 for a
:= 0 to High(TriggersTable
) do
1268 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1269 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1271 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1272 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1274 TriggersTable
[a
].LiftPanel
:= -1;
1276 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1277 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1278 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1279 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1281 TriggersTable
[a
].DoorPanel
:= -1;
1283 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1284 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1286 TriggersTable
[a
].ShotPanel
:= -1;
1288 g_Game_StepLoading();
1293 if panels
<> nil then
1295 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1296 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1298 for a
:= 0 to High(panels
) do
1300 SetLength(AddTextures
, 0);
1303 if _textures
<> nil then
1305 texture
:= _textures
[panels
[a
].TextureNum
];
1313 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1314 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1316 if (TriggersTable
<> nil) and (_textures
<> nil) then
1317 for b
:= 0 to High(TriggersTable
) do
1318 if (TriggersTable
[b
].TexturePanel
= a
)
1319 or (TriggersTable
[b
].ShotPanel
= a
) then
1328 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1330 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1333 for c
:= Len
downto 1 do
1341 // Ñïåö-òåêñòóðû çàïðåùåíû:
1342 if g_Map_IsSpecialTexture(s
) then
1345 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1346 ok
:= g_Texture_NumNameFindStart(s
);
1348 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1349 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1352 k
:= NNF_NAME_BEFORE
;
1353 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1354 while ok
or (k
= NNF_NAME_BEFORE
) or
1355 (k
= NNF_NAME_EQUALS
) do
1357 k
:= g_Texture_NumNameFindNext(TexName
);
1359 if (k
= NNF_NAME_BEFORE
) or
1360 (k
= NNF_NAME_AFTER
) then
1362 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1363 if ByteBool(texture
.Anim
) then
1364 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1366 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1368 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1370 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1374 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1376 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1378 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1380 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1384 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1387 for c
:= 0 to High(Textures
) do
1388 if Textures
[c
].TextureName
= TexName
then
1390 SetLength(AddTextures
, Length(AddTextures
)+1);
1391 AddTextures
[High(AddTextures
)].Texture
:= c
;
1392 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1398 if k
= NNF_NAME_EQUALS
then
1400 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1401 SetLength(AddTextures
, Length(AddTextures
)+1);
1402 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1403 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1404 CurTex
:= High(AddTextures
);
1412 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1413 end; // if ok - ññûëàþòñÿ òðèããåðû
1417 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1418 SetLength(AddTextures
, 1);
1419 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1420 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1424 //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);
1426 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1427 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1429 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1430 if TriggersTable
<> nil then
1431 for b
:= 0 to High(TriggersTable
) do
1433 // Òðèããåð äâåðè/ëèôòà:
1434 if (TriggersTable
[b
].LiftPanel
= a
) or
1435 (TriggersTable
[b
].DoorPanel
= a
) then
1436 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1437 // Òðèããåð ñìåíû òåêñòóðû:
1438 if TriggersTable
[b
].TexturePanel
= a
then
1439 triggers
[b
].TexturePanel
:= PanelID
;
1440 // Òðèããåð "Òóðåëü":
1441 if TriggersTable
[b
].ShotPanel
= a
then
1442 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1445 g_Game_StepLoading();
1449 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1450 if (triggers
<> nil) and not gLoadGameMode
then
1452 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1453 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1454 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1455 for a
:= 0 to High(triggers
) do
1457 if triggers
[a
].TexturePanel
<> -1 then
1458 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1461 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1462 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1463 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1466 CreateTrigger(triggers
[a
], b
, c
);
1470 // Çàãðóçêà ïðåäìåòîâ:
1471 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1472 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1473 items
:= MapReader
.GetItems();
1475 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1476 if (items
<> nil) and not gLoadGameMode
then
1478 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1479 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1480 for a
:= 0 to High(items
) do
1481 CreateItem(Items
[a
]);
1484 // Çàãðóçêà îáëàñòåé:
1485 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1486 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1487 areas
:= MapReader
.GetAreas();
1489 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1490 if areas
<> nil then
1492 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1493 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1494 for a
:= 0 to High(areas
) do
1495 CreateArea(areas
[a
]);
1498 // Çàãðóçêà ìîíñòðîâ:
1499 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1500 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1501 monsters
:= MapReader
.GetMonsters();
1503 gTotalMonsters
:= 0;
1505 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1506 if (monsters
<> nil) and not gLoadGameMode
then
1508 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1509 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1510 for a
:= 0 to High(monsters
) do
1511 CreateMonster(monsters
[a
]);
1514 // Çàãðóçêà îïèñàíèÿ êàðòû:
1515 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1516 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1517 Header
:= MapReader
.GetMapHeader();
1523 Name
:= Header
.MapName
;
1524 Description
:= Header
.MapDescription
;
1525 Author
:= Header
.MapAuthor
;
1526 MusicName
:= Header
.MusicName
;
1527 SkyName
:= Header
.SkyName
;
1528 Height
:= Header
.Height
;
1529 Width
:= Header
.Width
;
1533 if gMapInfo
.SkyName
<> '' then
1535 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1536 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1537 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1539 if FileName
<> '' then
1540 FileName
:= GameDir
+'/wads/'+FileName
1543 FileName
:= g_ExtractWadName(Res
);
1546 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1547 if g_Texture_CreateWAD(BackID
, s
) then
1549 g_Game_SetupScreenSize();
1552 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1557 if gMapInfo
.MusicName
<> '' then
1559 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1560 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1561 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1563 if FileName
<> '' then
1564 FileName
:= GameDir
+'/wads/'+FileName
1567 FileName
:= g_ExtractWadName(Res
);
1570 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1571 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1574 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1577 // Îñòàëüíûå óñòàíâêè:
1585 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1586 if not gLoadGameMode
then
1589 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1595 TriggersTable
:= nil;
1598 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1599 if ok
and (not gLoadGameMode
) then
1601 gMusic
.SetByName(gMapInfo
.MusicName
);
1605 gMusic
.SetByName('');
1607 sfsGCEnable(); // enable releasing unused volumes
1610 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1613 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1617 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1620 MapReader
: TMapReader_1
;
1621 Header
: TMapHeaderRec_1
;
1626 FillChar(Result
, SizeOf(Result
), 0);
1627 FileName
:= g_ExtractWadName(Res
);
1629 WAD
:= TWADFile
.Create();
1630 if not WAD
.ReadFile(FileName
) then
1636 //k8: it ignores path again
1637 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1645 MapReader
:= TMapReader_1
.Create();
1647 if not MapReader
.LoadMap(Data
) then
1649 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1650 ZeroMemory(@Header
, SizeOf(Header
));
1651 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1652 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1656 Header
:= MapReader
.GetMapHeader();
1657 Result
.Name
:= Header
.MapName
;
1658 Result
.Description
:= Header
.MapDescription
;
1665 Result
.Author
:= Header
.MapAuthor
;
1666 Result
.Height
:= Header
.Height
;
1667 Result
.Width
:= Header
.Width
;
1670 function g_Map_GetMapsList(WADName
: string): SArray
;
1677 WAD
:= TWADFile
.Create();
1678 if not WAD
.ReadFile(WADName
) then
1683 ResList
:= WAD
.GetMapResources();
1684 if ResList
<> nil then
1686 for a
:= 0 to High(ResList
) do
1688 SetLength(Result
, Length(Result
)+1);
1689 Result
[High(Result
)] := ResList
[a
];
1695 function g_Map_Exist(Res
: string): Boolean;
1698 FileName
, mnn
: string;
1704 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1706 WAD
:= TWADFile
.Create
;
1707 if not WAD
.ReadFile(FileName
) then
1713 ResList
:= WAD
.GetMapResources();
1716 mnn
:= g_ExtractFileName(Res
);
1717 if ResList
<> nil then
1718 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1725 procedure g_Map_Free();
1729 procedure FreePanelArray(var panels
: TPanelArray
);
1734 if panels
<> nil then
1736 for i
:= 0 to High(panels
) do
1749 RespawnPoints
:= nil;
1750 if FlagPoints
[FLAG_RED
] <> nil then
1752 Dispose(FlagPoints
[FLAG_RED
]);
1753 FlagPoints
[FLAG_RED
] := nil;
1755 if FlagPoints
[FLAG_BLUE
] <> nil then
1757 Dispose(FlagPoints
[FLAG_BLUE
]);
1758 FlagPoints
[FLAG_BLUE
] := nil;
1760 //DOMFlagPoints := nil;
1764 if Textures
<> nil then
1766 for a
:= 0 to High(Textures
) do
1767 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1768 if Textures
[a
].Anim
then
1769 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1771 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1772 e_DeleteTexture(Textures
[a
].TextureID
);
1777 FreePanelArray(gWalls
);
1778 FreePanelArray(gRenderBackgrounds
);
1779 FreePanelArray(gRenderForegrounds
);
1780 FreePanelArray(gWater
);
1781 FreePanelArray(gAcid1
);
1782 FreePanelArray(gAcid2
);
1783 FreePanelArray(gSteps
);
1784 FreePanelArray(gLifts
);
1785 FreePanelArray(gBlockMon
);
1787 if BackID
<> DWORD(-1) then
1791 e_DeleteTexture(BackID
);
1792 BackID
:= DWORD(-1);
1795 g_Game_StopAllSounds(False);
1797 g_Sound_Delete(gMapInfo
.MusicName
);
1799 gMapInfo
.Name
:= '';
1800 gMapInfo
.Description
:= '';
1801 gMapInfo
.MusicName
:= '';
1802 gMapInfo
.Height
:= 0;
1803 gMapInfo
.Width
:= 0;
1811 procedure g_Map_Update();
1817 procedure UpdatePanelArray(var panels
: TPanelArray
);
1822 if panels
<> nil then
1823 for i
:= 0 to High(panels
) do
1828 UpdatePanelArray(gWalls
);
1829 UpdatePanelArray(gRenderBackgrounds
);
1830 UpdatePanelArray(gRenderForegrounds
);
1831 UpdatePanelArray(gWater
);
1832 UpdatePanelArray(gAcid1
);
1833 UpdatePanelArray(gAcid2
);
1834 UpdatePanelArray(gSteps
);
1836 if gGameSettings
.GameMode
= GM_CTF
then
1838 for a
:= FLAG_RED
to FLAG_BLUE
do
1839 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1842 if gFlags
[a
].Animation
<> nil then
1843 gFlags
[a
].Animation
.Update();
1845 m
:= g_Obj_Move(@Obj
, True, True);
1847 if gTime
mod (GAME_TICK
*2) <> 0 then
1850 // Ñîïðîòèâëåíèå âîçäóõà:
1851 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1853 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1854 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1857 gFlags
[a
].CaptureTime
:= 0;
1858 if a
= FLAG_RED
then
1859 s
:= _lc
[I_PLAYER_FLAG_RED
]
1861 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1862 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1864 if g_Game_IsNet
then
1865 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1872 // Èãðîê áåðåò ôëàã:
1873 if gPlayers
<> nil then
1875 j
:= Random(Length(gPlayers
)) - 1;
1877 for d
:= 0 to High(gPlayers
) do
1880 if j
> High(gPlayers
) then
1883 if gPlayers
[j
] <> nil then
1884 if gPlayers
[j
].Live
and
1885 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1887 if gPlayers
[j
].GetFlag(a
) then
1898 procedure g_Map_DrawPanels (PanelType
: Word);
1900 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1904 if (panels
<> nil) then
1906 // alas, no visible set
1907 for idx
:= 0 to High(panels
) do
1909 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1916 PANEL_WALL
: DrawPanels(gWalls
);
1917 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1918 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1919 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1920 PANEL_WATER
: DrawPanels(gWater
);
1921 PANEL_ACID1
: DrawPanels(gAcid1
);
1922 PANEL_ACID2
: DrawPanels(gAcid2
);
1923 PANEL_STEP
: DrawPanels(gSteps
);
1929 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
1930 function checker (pan
: TPanel
; tag
: Integer): Boolean;
1932 result
:= false; // don't stop, ever
1933 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
1934 gDrawPanelList
.insert(pan
);
1939 //tagmask := panelTypeToTag(PanelType);
1941 if gdbg_map_use_tree_draw
then
1943 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
1947 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
1949 // list will be rendered in `g_game.DrawPlayer()`
1953 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1954 function checker (pan
: TPanel
; tag
: Integer): Boolean;
1956 result
:= false; // don't stop, ever
1957 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1961 if gdbg_map_use_tree_draw
then
1963 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
1967 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
1972 procedure g_Map_DrawBack(dx
, dy
: Integer);
1974 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1975 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1977 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1980 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1981 PanelType
: Word; b1x3
: Boolean): Boolean;
1987 if WordBool(PanelType
and PANEL_WALL
) then
1988 if gWalls
<> nil then
1993 if gWalls
[a
].Enabled
and
1994 g_Collide(X
, Y
, Width
, Height
,
1995 gWalls
[a
].X
, gWalls
[a
].Y
,
1996 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2003 if WordBool(PanelType
and PANEL_WATER
) then
2004 if gWater
<> nil then
2009 if g_Collide(X
, Y
, Width
, Height
,
2010 gWater
[a
].X
, gWater
[a
].Y
,
2011 gWater
[a
].Width
, gWater
[a
].Height
) then
2018 if WordBool(PanelType
and PANEL_ACID1
) then
2019 if gAcid1
<> nil then
2024 if g_Collide(X
, Y
, Width
, Height
,
2025 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2026 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2033 if WordBool(PanelType
and PANEL_ACID2
) then
2034 if gAcid2
<> nil then
2039 if g_Collide(X
, Y
, Width
, Height
,
2040 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2041 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2048 if WordBool(PanelType
and PANEL_STEP
) then
2049 if gSteps
<> nil then
2054 if g_Collide(X
, Y
, Width
, Height
,
2055 gSteps
[a
].X
, gSteps
[a
].Y
,
2056 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2063 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2064 if gLifts
<> nil then
2069 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2070 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2071 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2072 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2073 g_Collide(X
, Y
, Width
, Height
,
2074 gLifts
[a
].X
, gLifts
[a
].Y
,
2075 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2082 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2083 if gBlockMon
<> nil then
2085 h
:= High(gBlockMon
);
2089 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2090 g_Collide(X
, Y
, Width
, Height
,
2091 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2092 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2100 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2104 function checkPanels (constref panels
: TPanelArray
): Boolean;
2109 if panels
= nil then exit
;
2110 for a
:= 0 to High(panels
) do
2112 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2115 texid
:= panels
[a
].GetTextureID();
2122 texid
:= TEXTURE_NONE
;
2124 if not checkPanels(gWater
) then
2125 if not checkPanels(gAcid1
) then
2126 if not checkPanels(gAcid2
) then exit
;
2131 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2132 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2134 result
:= false; // don't stop, ever
2136 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
2138 if not pan
.Enabled
then exit
;
2141 if ((tag
and GridTagLift
) <> 0) then
2144 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2145 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2146 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2147 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) and
2148 g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2152 if ((tag
and GridTagBlockMon
) <> 0) then
2154 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)) and g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2159 result
:= g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2163 tagmask
: Integer = 0;
2165 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2166 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2167 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2168 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2169 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2170 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2171 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2173 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2175 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2176 if gdbg_map_use_accel_coldet
then
2178 if gdbg_map_use_tree_coldet
then
2180 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2181 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2182 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2184 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2185 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2190 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
);
2195 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2197 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2201 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2203 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2206 // slightly different from the old code, but meh...
2207 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2209 result
:= false; // don't stop, ever
2210 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2213 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2214 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2215 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2218 if not g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
) then exit
;
2220 texid
:= pan
.GetTextureID();
2221 // water? water has the highest priority, so stop right here
2222 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2224 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2226 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2230 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2231 if gdbg_map_use_accel_coldet
then
2233 texid
:= TEXTURE_NONE
;
2234 if gdbg_map_use_tree_coldet
then
2236 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2240 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2246 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2248 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2251 procedure g_Map_EnableWall(ID
: DWORD
);
2256 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2258 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2262 procedure g_Map_DisableWall(ID
: DWORD
);
2267 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2269 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2273 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2278 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2281 tp
:= gRenderForegrounds
[ID
];
2283 tp
:= gRenderBackgrounds
[ID
];
2296 tp
.NextTexture(AnimLoop
);
2297 if g_Game_IsServer
and g_Game_IsNet
then
2298 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2301 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2303 if gLifts
[ID
].LiftType
= t
then
2310 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2312 if LiftType
= 0 then
2313 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2314 else if LiftType
= 1 then
2315 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2316 else if LiftType
= 2 then
2317 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2318 else if LiftType
= 3 then
2319 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2321 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2325 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2328 PointsArray
: Array of TRespawnPoint
;
2331 SetLength(PointsArray
, 0);
2333 if RespawnPoints
= nil then
2336 for a
:= 0 to High(RespawnPoints
) do
2337 if RespawnPoints
[a
].PointType
= PointType
then
2339 SetLength(PointsArray
, Length(PointsArray
)+1);
2340 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2343 if PointsArray
= nil then
2346 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2350 function g_Map_GetPointCount(PointType
: Byte): Word;
2356 if RespawnPoints
= nil then
2359 for a
:= 0 to High(RespawnPoints
) do
2360 if RespawnPoints
[a
].PointType
= PointType
then
2361 Result
:= Result
+ 1;
2364 function g_Map_HaveFlagPoints(): Boolean;
2366 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2369 procedure g_Map_ResetFlag(Flag
: Byte);
2371 with gFlags
[Flag
] do
2377 Direction
:= D_LEFT
;
2378 State
:= FLAG_STATE_NONE
;
2379 if FlagPoints
[Flag
] <> nil then
2381 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2382 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2383 Direction
:= FlagPoints
[Flag
]^.Direction
;
2384 State
:= FLAG_STATE_NORMAL
;
2390 procedure g_Map_DrawFlags();
2393 Mirror
: TMirrorType
;
2395 if gGameSettings
.GameMode
<> GM_CTF
then
2398 for i
:= FLAG_RED
to FLAG_BLUE
do
2400 if State
<> FLAG_STATE_CAPTURED
then
2402 if State
= FLAG_STATE_NONE
then
2405 if Direction
= D_LEFT
then
2407 Mirror
:= M_HORIZONTAL
;
2416 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2418 if g_debug_Frames
then
2420 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2422 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2423 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2429 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2436 procedure SavePanelArray(var panels
: TPanelArray
);
2438 PAMem
: TBinMemoryWriter
;
2441 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2442 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2445 while i
< Length(panels
) do
2447 if panels
[i
].SaveIt
then
2451 // Ñîõðàíÿåì ïàíåëü:
2452 panels
[i
].SaveState(PAMem
);
2457 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2458 PAMem
.SaveToMemory(Mem
);
2462 procedure SaveFlag(flag
: PFlag
);
2465 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2467 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2468 Mem
.WriteByte(flag
^.RespawnType
);
2470 Mem
.WriteByte(flag
^.State
);
2471 // Íàïðàâëåíèå ôëàãà:
2472 if flag
^.Direction
= D_LEFT
then
2478 Obj_SaveState(@flag
^.Obj
, Mem
);
2482 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2484 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2485 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2486 SavePanelArray(gWalls
);
2487 // Ñîõðàíÿåì ïàíåëè ôîíà:
2488 SavePanelArray(gRenderBackgrounds
);
2489 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2490 SavePanelArray(gRenderForegrounds
);
2491 // Ñîõðàíÿåì ïàíåëè âîäû:
2492 SavePanelArray(gWater
);
2493 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2494 SavePanelArray(gAcid1
);
2495 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2496 SavePanelArray(gAcid2
);
2497 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2498 SavePanelArray(gSteps
);
2499 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2500 SavePanelArray(gLifts
);
2503 ///// Ñîõðàíÿåì ìóçûêó: /////
2504 // Ñèãíàòóðà ìóçûêè:
2505 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2508 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2509 if gMusic
.NoMusic
then
2513 Mem
.WriteString(str
, 64);
2514 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2515 dw
:= gMusic
.GetPosition();
2517 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2518 boo
:= gMusic
.SpecPause
;
2519 Mem
.WriteBoolean(boo
);
2522 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2523 Mem
.WriteInt(gTotalMonsters
);
2526 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2527 if gGameSettings
.GameMode
= GM_CTF
then
2529 // Ôëàã Êðàñíîé êîìàíäû:
2530 SaveFlag(@gFlags
[FLAG_RED
]);
2531 // Ôëàã Ñèíåé êîìàíäû:
2532 SaveFlag(@gFlags
[FLAG_BLUE
]);
2536 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2537 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2539 // Î÷êè Êðàñíîé êîìàíäû:
2540 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2541 // Î÷êè Ñèíåé êîìàíäû:
2542 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2547 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2554 procedure LoadPanelArray(var panels
: TPanelArray
);
2556 PAMem
: TBinMemoryReader
;
2559 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2560 PAMem
:= TBinMemoryReader
.Create();
2561 PAMem
.LoadFromMemory(Mem
);
2563 for i
:= 0 to Length(panels
)-1 do
2564 if panels
[i
].SaveIt
then
2570 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2572 // Çàãðóæàåì ïàíåëü:
2573 panels
[i
].LoadState(PAMem
);
2576 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2580 procedure LoadFlag(flag
: PFlag
);
2584 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2586 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2588 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2589 Mem
.ReadByte(flag
^.RespawnType
);
2591 Mem
.ReadByte(flag
^.State
);
2592 // Íàïðàâëåíèå ôëàãà:
2595 flag
^.Direction
:= D_LEFT
2597 flag
^.Direction
:= D_RIGHT
;
2599 Obj_LoadState(@flag
^.Obj
, Mem
);
2606 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2607 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2608 LoadPanelArray(gWalls
);
2609 // Çàãðóæàåì ïàíåëè ôîíà:
2610 LoadPanelArray(gRenderBackgrounds
);
2611 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2612 LoadPanelArray(gRenderForegrounds
);
2613 // Çàãðóæàåì ïàíåëè âîäû:
2614 LoadPanelArray(gWater
);
2615 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2616 LoadPanelArray(gAcid1
);
2617 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2618 LoadPanelArray(gAcid2
);
2619 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2620 LoadPanelArray(gSteps
);
2621 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2622 LoadPanelArray(gLifts
);
2625 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2629 ///// Çàãðóæàåì ìóçûêó: /////
2630 // Ñèãíàòóðà ìóçûêè:
2632 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2634 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2637 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2638 Mem
.ReadString(str
);
2639 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2641 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2642 Mem
.ReadBoolean(boo
);
2643 // Çàïóñêàåì ýòó ìóçûêó:
2644 gMusic
.SetByName(str
);
2645 gMusic
.SpecPause
:= boo
;
2648 gMusic
.SetPosition(dw
);
2651 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2652 Mem
.ReadInt(gTotalMonsters
);
2655 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2656 if gGameSettings
.GameMode
= GM_CTF
then
2658 // Ôëàã Êðàñíîé êîìàíäû:
2659 LoadFlag(@gFlags
[FLAG_RED
]);
2660 // Ôëàã Ñèíåé êîìàíäû:
2661 LoadFlag(@gFlags
[FLAG_BLUE
]);
2665 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2666 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2668 // Î÷êè Êðàñíîé êîìàíäû:
2669 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2670 // Î÷êè Ñèíåé êîìàíäû:
2671 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2676 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2681 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2682 Arr
:= PanelByID
[PanelID
].PWhere
^;
2683 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2684 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);