1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, z_aabbtree
, md5
, binheap
, xprofiler
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
66 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
68 procedure g_Map_DrawBack(dx
, dy
: Integer);
69 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
70 PanelType
: Word; b1x3
: Boolean): Boolean;
71 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
72 procedure g_Map_EnableWall(ID
: DWORD
);
73 procedure g_Map_DisableWall(ID
: DWORD
);
74 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
75 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
76 procedure g_Map_ReAdd_DieTriggers();
77 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
79 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
80 function g_Map_GetPointCount(PointType
: Byte): Word;
82 function g_Map_HaveFlagPoints(): Boolean;
84 procedure g_Map_ResetFlag(Flag
: Byte);
85 procedure g_Map_DrawFlags();
87 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
89 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
90 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
92 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
94 procedure g_Map_ProfilersBegin ();
95 procedure g_Map_ProfilersEnd ();
98 RESPAWNPOINT_PLAYER1
= 1;
99 RESPAWNPOINT_PLAYER2
= 2;
101 RESPAWNPOINT_RED
= 4;
102 RESPAWNPOINT_BLUE
= 5;
110 FLAG_STATE_NORMAL
= 1;
111 FLAG_STATE_DROPPED
= 2;
112 FLAG_STATE_CAPTURED
= 3;
113 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
114 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
116 FLAG_TIME
= 720; // 20 seconds
118 SKY_STRETCH
: Single = 1.5;
133 // sorted by draw priority
134 GridTagBack
= 1 shl 0;
135 GridTagStep
= 1 shl 1;
136 GridTagWall
= 1 shl 2;
137 GridTagDoor
= 1 shl 3;
138 GridTagAcid1
= 1 shl 4;
139 GridTagAcid2
= 1 shl 5;
140 GridTagWater
= 1 shl 6;
141 GridTagFore
= 1 shl 7;
142 // the following are invisible
143 GridTagLift
= 1 shl 8;
144 GridTagBlockMon
= 1 shl 9;
149 gRenderBackgrounds
: TPanelArray
;
150 gRenderForegrounds
: TPanelArray
;
151 gWater
, gAcid1
, gAcid2
: TPanelArray
;
154 gBlockMon
: TPanelArray
;
155 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
156 //gDOMFlags: array of TFlag;
159 gDoorMap
: array of array of DWORD
;
160 gLiftMap
: array of array of DWORD
;
161 gWADHash
: TMD5Digest
;
162 BackID
: DWORD
= DWORD(-1);
163 gExternalResources
: TStringList
;
165 gdbg_map_use_accel_render
: Boolean = true;
166 gdbg_map_use_accel_coldet
: Boolean = true;
167 gdbg_map_use_tree_draw
: Boolean = false;
168 gdbg_map_use_tree_coldet
: Boolean = false;
169 gdbg_map_dump_coldet_tree_queries
: Boolean = false;
170 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
171 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
173 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
175 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Integer;
181 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
182 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
183 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
184 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
186 ImagingTypes
, Imaging
, ImagingUtility
,
187 ImagingGif
, ImagingNetworkGraphics
;
190 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
191 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
192 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
196 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
198 TDynAABBTreePanelBase
= specialize TDynAABBTreeBase
<TPanel
>;
200 TDynAABBTreeMap
= class(TDynAABBTreePanelBase
)
201 function getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean; override;
204 function TDynAABBTreeMap
.getFleshAABB (out aabb
: AABB2D
; pan
: TPanel
; tag
: Integer): Boolean;
207 if (pan
= nil) then begin aabb
:= AABB2D
.Create(0, 0, 0, 0); exit
; end;
208 aabb
:= AABB2D
.Create(pan
.X
, pan
.Y
, pan
.X
+pan
.Width
-1, pan
.Y
+pan
.Height
-1);
209 if (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
210 if not aabb
.valid
then raise Exception
.Create('wutafuuuuuuu?!');
215 function panelTypeToTag (panelType
: Word): Integer;
218 PANEL_WALL
: result
:= GridTagWall
; // gWalls
219 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
220 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
221 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
222 PANEL_WATER
: result
:= GridTagWater
; // gWater
223 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
224 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
225 PANEL_STEP
: result
:= GridTagStep
; // gSteps
226 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
227 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
228 else result
:= GridTagInvalid
;
233 function dplLess (a
, b
: TObject
): Boolean;
237 //result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
240 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
241 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
242 result
:= (pa
.ArrIdx
< pb
.ArrIdx
);
245 procedure dplClear ();
247 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
253 PWhere
: ^TPanelArray
;
258 PanelById
: array of TPanelID
;
259 Textures
: TLevelTextureArray
;
260 RespawnPoints
: Array of TRespawnPoint
;
261 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
262 //DOMFlagPoints: Array of TFlagPoint;
263 gMapGrid
: TPanelGrid
= nil;
264 mapTree
: TDynAABBTreeMap
= nil;
267 procedure g_Map_ProfilersBegin ();
269 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
270 profMapCollision
.mainBegin(g_profile_collision
);
272 if g_profile_collision
then
274 profMapCollision
.sectionBegin('*solids');
275 profMapCollision
.sectionEnd();
276 profMapCollision
.sectionBegin('liquids');
277 profMapCollision
.sectionEnd();
281 procedure g_Map_ProfilersEnd ();
283 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
287 // wall index in `gWalls` or -1
288 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Integer;
292 function sqchecker (pan
: TPanel
; var ray
: Ray2D
): Single;
297 result
:= -666.0; // invalid
298 if not pan
.Enabled
then exit
;
299 aabb
:= AABB2D
.CreateWH(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
300 if not aabb
.valid
then exit
;
301 if aabb
.intersects(ray
, @tmin
) then
303 //if (tmin*tmin > maxDistSq) then exit;
304 if (tmin
>= 0.0) then
306 //e_WriteLog(Format('sqchecker(%d,%d,%d,%d): panel #%d (%d,%d)-(%d,%d); tmin=%f', [x0, y0, x1, y1, pan.arrIdx, pan.X, pan.Y, pan.Width, pan.Height, tmin]), MSG_NOTIFY);
307 //if (tmin < 0.0) then tmin := 0.0;
314 qr
: TDynAABBTreeMap
.TSegmentQueryResult
;
320 if (mapTree
= nil) then exit
;
321 maxDistSq
:= (x1
-x0
)*(x1
-x0
)+(y1
-y0
)*(y1
-y0
);
322 if mapTree
.segmentQuery(qr
, x0
, y0
, x1
, y1
, sqchecker
, (GridTagWall
or GridTagDoor
)) then
324 if (qr
.flesh
<> nil) and (qr
.time
*qr
.time
<= maxDistSq
) then
326 result
:= qr
.flesh
.arrIdx
;
327 if (hitx
<> nil) or (hity
<> nil) then
329 ray
:= Ray2D
.Create(x0
, y0
, x1
, y1
);
330 hxf
:= ray
.origX
+ray
.dirX
*qr
.time
;
331 hyf
:= ray
.origY
+ray
.dirY
*qr
.time
;
336 if (hx
>= qr
.flesh
.X
) and (hy
>= qr
.flesh
.Y
) and (hx
< qr
.flesh
.X
+qr
.flesh
.Width
) and (hy
< qr
.flesh
.Y
+qr
.flesh
.Height
) then
347 if (hitx
<> nil) then hitx
^ := hx
;
348 if (hity
<> nil) then hity
^ := hy
;
355 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
357 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
358 (Texture
= TEXTURE_NAME_ACID1
) or
359 (Texture
= TEXTURE_NAME_ACID2
);
362 procedure CreateDoorMap();
364 PanelArray
: Array of record
370 a
, b
, c
, m
, i
, len
: Integer;
378 SetLength(PanelArray
, len
);
380 for a
:= 0 to High(gWalls
) do
381 if gWalls
[a
].Door
then
383 PanelArray
[i
].X
:= gWalls
[a
].X
;
384 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
385 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
386 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
387 PanelArray
[i
].Active
:= True;
388 PanelArray
[i
].PanelID
:= a
;
394 SetLength(PanelArray
, len
);
405 SetLength(gDoorMap
, 0);
407 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
410 if PanelArray
[a
].Active
then
412 PanelArray
[a
].Active
:= False;
413 m
:= Length(gDoorMap
);
414 SetLength(gDoorMap
, m
+1);
415 SetLength(gDoorMap
[m
], 1);
416 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
424 if PanelArray
[b
].Active
then
425 for c
:= 0 to High(gDoorMap
[m
]) do
426 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
427 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
428 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
429 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
430 gWalls
[gDoorMap
[m
, c
]].X
,
431 gWalls
[gDoorMap
[m
, c
]].Y
,
432 gWalls
[gDoorMap
[m
, c
]].Width
,
433 gWalls
[gDoorMap
[m
, c
]].Height
) then
435 PanelArray
[b
].Active
:= False;
436 SetLength(gDoorMap
[m
],
437 Length(gDoorMap
[m
])+1);
438 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
444 g_Game_StepLoading();
450 procedure CreateLiftMap();
452 PanelArray
: Array of record
457 a
, b
, c
, len
, i
, j
: Integer;
463 len
:= Length(gLifts
);
464 SetLength(PanelArray
, len
);
466 for a
:= 0 to len
-1 do
468 PanelArray
[a
].X
:= gLifts
[a
].X
;
469 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
470 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
471 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
472 PanelArray
[a
].Active
:= True;
475 SetLength(gLiftMap
, len
);
478 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
480 for a
:= 0 to len
-1 do
481 if PanelArray
[a
].Active
then
483 PanelArray
[a
].Active
:= False;
484 SetLength(gLiftMap
[i
], 32);
492 for b
:= 0 to len
-1 do
493 if PanelArray
[b
].Active
then
495 if g_CollideAround(PanelArray
[b
].X
,
498 PanelArray
[b
].Height
,
499 PanelArray
[gLiftMap
[i
, c
]].X
,
500 PanelArray
[gLiftMap
[i
, c
]].Y
,
501 PanelArray
[gLiftMap
[i
, c
]].Width
,
502 PanelArray
[gLiftMap
[i
, c
]].Height
) then
504 PanelArray
[b
].Active
:= False;
506 if j
> High(gLiftMap
[i
]) then
507 SetLength(gLiftMap
[i
],
508 Length(gLiftMap
[i
])+32);
517 SetLength(gLiftMap
[i
], j
+1);
520 g_Game_StepLoading();
523 SetLength(gLiftMap
, i
);
528 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
529 CurTex
: Integer; sav
: Boolean): Integer;
532 panels
: ^TPanelArray
;
536 case PanelRec
.PanelType
of
537 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
540 panels
:= @gRenderBackgrounds
;
542 panels
:= @gRenderForegrounds
;
551 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
554 panels
:= @gBlockMon
;
559 len
:= Length(panels
^);
560 SetLength(panels
^, len
+ 1);
562 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
563 panels
^[len
].ArrIdx
:= len
;
564 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
566 panels
^[len
].SaveIt
:= True;
570 len
:= Length(PanelByID
);
571 SetLength(PanelByID
, len
+ 1);
572 PanelByID
[len
].PWhere
:= panels
;
573 PanelByID
[len
].PArrID
:= Result
;
576 function CreateNullTexture(RecName
: String): Integer;
578 SetLength(Textures
, Length(Textures
)+1);
579 result
:= High(Textures
);
581 with Textures
[High(Textures
)] do
583 TextureName
:= RecName
;
587 TextureID
:= TEXTURE_NONE
;
591 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
594 TextureData
: Pointer;
595 WADName
, txname
: String;
596 a
, ResLength
: Integer;
600 if Textures
<> nil then
601 for a
:= 0 to High(Textures
) do
602 if Textures
[a
].TextureName
= RecName
then
603 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
608 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
609 if (RecName
= TEXTURE_NAME_WATER
) or
610 (RecName
= TEXTURE_NAME_ACID1
) or
611 (RecName
= TEXTURE_NAME_ACID2
) then
613 SetLength(Textures
, Length(Textures
)+1);
615 with Textures
[High(Textures
)] do
617 TextureName
:= RecName
;
619 if TextureName
= TEXTURE_NAME_WATER
then
620 TextureID
:= TEXTURE_SPECIAL_WATER
622 if TextureName
= TEXTURE_NAME_ACID1
then
623 TextureID
:= TEXTURE_SPECIAL_ACID1
625 if TextureName
= TEXTURE_NAME_ACID2
then
626 TextureID
:= TEXTURE_SPECIAL_ACID2
;
631 result
:= High(Textures
);
635 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
636 WADName
:= g_ExtractWadName(RecName
);
638 WAD
:= TWADFile
.Create();
640 if WADName
<> '' then
641 WADName
:= GameDir
+'/wads/'+WADName
645 WAD
.ReadFile(WADName
);
649 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
651 FreeMem(TextureData);
652 RecName := 'COMMON\ALIEN';
656 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
658 SetLength(Textures
, Length(Textures
)+1);
659 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
661 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
662 @Textures
[High(Textures
)].Width
,
663 @Textures
[High(Textures
)].Height
);
664 FreeMem(TextureData
);
665 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
666 Textures
[High(Textures
)].Anim
:= False;
668 result
:= High(Textures
);
670 else // Íåò òàêîãî ðåóñðñà â WAD'å
672 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
675 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
676 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
683 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
686 TextureWAD
: PChar = nil;
687 TextData
: Pointer = nil;
688 TextureData
: Pointer = nil;
692 TextureResource
: String;
693 _width
, _height
, _framecount
, _speed
: Integer;
694 _backanimation
: Boolean;
696 ia
: TDynImageDataArray
= nil;
697 f
, c
, frdelay
, frloop
: Integer;
701 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
703 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
704 WADName
:= g_ExtractWadName(RecName
);
706 WAD
:= TWADFile
.Create();
708 if WADName
<> '' then
709 WADName
:= GameDir
+'/wads/'+WADName
713 WAD
.ReadFile(WADName
);
715 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
719 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
720 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
726 if WADName = Map then
728 //FreeMem(TextureWAD);
729 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
735 if ResLength
< 6 then
737 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
741 // ýòî ïòèöà? ýòî ñàìîë¸ò?
742 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
743 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
745 // íåò, ýòî ñóïåðìåí!
746 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
748 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
752 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
753 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
755 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
759 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
761 TextureResource
:= cfg
.ReadStr('', 'resource', '');
762 if TextureResource
= '' then
764 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
768 _width
:= cfg
.ReadInt('', 'framewidth', 0);
769 _height
:= cfg
.ReadInt('', 'frameheight', 0);
770 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
771 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
772 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
777 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
778 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
780 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
787 SetLength(Textures
, Length(Textures
)+1);
788 with Textures
[High(Textures
)] do
790 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
791 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
793 TextureName
:= RecName
;
797 FramesCount
:= _framecount
;
799 result
:= High(Textures
);
803 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
809 // try animated image
811 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
812 if length(imgfmt) = 0 then
814 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
818 GlobalMetadata
.ClearMetaItems();
819 GlobalMetadata
.ClearMetaItemsForSaving();
820 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
822 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
825 if length(ia
) = 0 then
827 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
834 _width
:= ia
[0].width
;
835 _height
:= ia
[0].height
;
836 _framecount
:= length(ia
);
838 _backanimation
:= false;
841 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
843 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
845 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
847 if f
< 0 then f
:= 0;
850 if c
< 13 then c
:= 0 else c
:= 1;
852 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
857 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
859 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
861 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
863 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
867 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
868 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
869 f
:= ord(_backanimation
);
870 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
);
872 SetLength(Textures
, Length(Textures
)+1);
873 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
874 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
876 Textures
[High(Textures
)].TextureName
:= RecName
;
877 Textures
[High(Textures
)].Width
:= _width
;
878 Textures
[High(Textures
)].Height
:= _height
;
879 Textures
[High(Textures
)].Anim
:= True;
880 Textures
[High(Textures
)].FramesCount
:= length(ia
);
881 Textures
[High(Textures
)].Speed
:= _speed
;
882 result
:= High(Textures
);
883 //writeln(' CREATED!');
887 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
891 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
894 if TextureWAD
<> nil then FreeMem(TextureWAD
);
895 if TextData
<> nil then FreeMem(TextData
);
896 if TextureData
<> nil then FreeMem(TextureData
);
900 procedure CreateItem(Item
: TItemRec_1
);
902 if g_Game_IsClient
then Exit
;
904 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
905 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
908 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
909 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
912 procedure CreateArea(Area
: TAreaRec_1
);
917 case Area
.AreaType
of
918 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
919 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
921 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
922 with RespawnPoints
[High(RespawnPoints
)] do
926 Direction
:= TDirection(Area
.Direction
);
928 case Area
.AreaType
of
929 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
930 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
931 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
932 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
933 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
938 AREA_REDFLAG
, AREA_BLUEFLAG
:
940 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
942 if FlagPoints
[a
] <> nil then Exit
;
946 with FlagPoints
[a
]^ do
948 X
:= Area
.X
-FLAGRECT
.X
;
949 Y
:= Area
.Y
-FLAGRECT
.Y
;
950 Direction
:= TDirection(Area
.Direction
);
956 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
957 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
960 Animation
:= TAnimation
.Create(id
, True, 8);
961 Obj
.Rect
:= FLAGRECT
;
969 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
970 with DOMFlagPoints[High(DOMFlagPoints)] do
974 Direction := TDirection(Area.Direction);
977 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
982 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
986 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
992 Width
:= Trigger
.Width
;
993 Height
:= Trigger
.Height
;
994 Enabled
:= ByteBool(Trigger
.Enabled
);
995 TexturePanel
:= Trigger
.TexturePanel
;
996 TexturePanelType
:= fTexturePanel1Type
;
997 ShotPanelType
:= fTexturePanel2Type
;
998 TriggerType
:= Trigger
.TriggerType
;
999 ActivateType
:= Trigger
.ActivateType
;
1000 Keys
:= Trigger
.Keys
;
1001 Data
.Default
:= Trigger
.DATA
;
1004 g_Triggers_Create(_trigger
);
1007 procedure CreateMonster(monster
: TMonsterRec_1
);
1012 if g_Game_IsClient
then Exit
;
1014 if (gGameSettings
.GameType
= GT_SINGLE
)
1015 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1017 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1019 if gTriggers
<> nil then
1021 for a
:= 0 to High(gTriggers
) do
1023 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1025 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1030 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1034 procedure g_Map_ReAdd_DieTriggers();
1036 function monsDieTrig (mon
: TMonster
): Boolean;
1040 result
:= false; // don't stop
1041 mon
.ClearTriggers();
1042 for a
:= 0 to High(gTriggers
) do
1044 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1046 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1052 if g_Game_IsClient
then Exit
;
1054 g_Mons_ForEach(monsDieTrig
);
1057 function extractWadName(resourceName
: string): string;
1061 posN
:= Pos(':', resourceName
);
1063 Result
:= Copy(resourceName
, 0, posN
-1)
1068 procedure addResToExternalResList(res
: string);
1070 res
:= extractWadName(res
);
1071 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1072 gExternalResources
.Add(res
);
1075 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1077 textures
: TTexturesRec1Array
;
1078 mapHeader
: TMapHeaderRec_1
;
1080 resFile
: String = '';
1082 if gExternalResources
= nil then
1083 gExternalResources
:= TStringList
.Create
;
1085 gExternalResources
.Clear
;
1086 textures
:= mapReader
.GetTextures();
1087 for i
:= 0 to High(textures
) do
1089 addResToExternalResList(resFile
);
1094 mapHeader
:= mapReader
.GetMapHeader
;
1096 addResToExternalResList(mapHeader
.MusicName
);
1097 addResToExternalResList(mapHeader
.SkyName
);
1100 procedure mapCreateGrid ();
1102 mapX0
: Integer = $3fffffff;
1103 mapY0
: Integer = $3fffffff;
1104 mapX1
: Integer = -$3fffffff;
1105 mapY1
: Integer = -$3fffffff;
1107 procedure calcBoundingBox (constref panels
: TPanelArray
);
1112 for idx
:= 0 to High(panels
) do
1115 if not pan
.visvalid
then continue
;
1116 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1117 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1118 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1119 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1120 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1124 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1129 tag
:= panelTypeToTag(tag
);
1130 for idx
:= High(panels
) downto 0 do
1134 if not pan
.visvalid
then continue
;
1135 gMapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1136 mapTree
.insertObject(pan
, tag
, true); // as static object
1146 calcBoundingBox(gWalls
);
1147 calcBoundingBox(gRenderBackgrounds
);
1148 calcBoundingBox(gRenderForegrounds
);
1149 calcBoundingBox(gWater
);
1150 calcBoundingBox(gAcid1
);
1151 calcBoundingBox(gAcid2
);
1152 calcBoundingBox(gSteps
);
1153 calcBoundingBox(gLifts
);
1154 calcBoundingBox(gBlockMon
);
1156 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1158 gMapGrid
:= TPanelGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1159 mapTree
:= TDynAABBTreeMap
.Create();
1161 addPanelsToGrid(gWalls
, PANEL_WALL
);
1162 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1163 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1164 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1165 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1166 addPanelsToGrid(gWater
, PANEL_WATER
);
1167 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1168 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1169 addPanelsToGrid(gSteps
, PANEL_STEP
);
1170 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1171 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1173 gMapGrid
.dumpStats();
1174 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1175 mapTree
.forEachLeaf(nil);
1178 function g_Map_Load(Res
: String): Boolean;
1180 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1181 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1184 MapReader
: TMapReader_1
;
1185 Header
: TMapHeaderRec_1
;
1186 _textures
: TTexturesRec1Array
;
1187 _texnummap
: array of Integer; // `_textures` -> `Textures`
1188 panels
: TPanelsRec1Array
;
1189 items
: TItemsRec1Array
;
1190 monsters
: TMonsterRec1Array
;
1191 areas
: TAreasRec1Array
;
1192 triggers
: TTriggersRec1Array
;
1193 a
, b
, c
, k
: Integer;
1195 AddTextures
: TAddTextureArray
;
1196 texture
: TTextureRec_1
;
1197 TriggersTable
: Array of record
1198 TexturePanel
: Integer;
1203 FileName
, mapResName
, s
, TexName
: String;
1206 ok
, isAnim
, trigRef
: Boolean;
1207 CurTex
, ntn
: Integer;
1216 gMapInfo
.Map
:= Res
;
1217 TriggersTable
:= nil;
1218 FillChar(texture
, SizeOf(texture
), 0);
1220 sfsGCDisable(); // temporary disable removing of temporary volumes
1223 FileName
:= g_ExtractWadName(Res
);
1224 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1225 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1227 WAD
:= TWADFile
.Create();
1228 if not WAD
.ReadFile(FileName
) then
1230 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1234 //k8: why loader ignores path here?
1235 mapResName
:= g_ExtractFileName(Res
);
1236 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1238 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1246 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1247 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1248 MapReader
:= TMapReader_1
.Create();
1250 if not MapReader
.LoadMap(Data
) then
1252 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1259 generateExternalResourcesList(MapReader
);
1260 // Çàãðóçêà òåêñòóð:
1261 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1262 _textures
:= MapReader
.GetTextures();
1265 // Äîáàâëåíèå òåêñòóð â Textures[]:
1266 if _textures
<> nil then
1268 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1269 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1270 SetLength(_texnummap
, length(_textures
));
1272 for a
:= 0 to High(_textures
) do
1275 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1276 for b
:= 1 to Length(s
) do
1282 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1283 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1284 // Àíèìèðîâàííàÿ òåêñòóðà:
1285 if ByteBool(_textures
[a
].Anim
) then
1287 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1290 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1291 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1294 else // Îáû÷íàÿ òåêñòóðà:
1295 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1298 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1299 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1302 _texnummap
[a
] := ntn
; // fix texture number
1303 g_Game_StepLoading();
1307 // Çàãðóçêà òðèããåðîâ:
1308 gTriggerClientID
:= 0;
1309 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1310 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1311 triggers
:= MapReader
.GetTriggers();
1313 // Çàãðóçêà ïàíåëåé:
1314 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1315 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1316 panels
:= MapReader
.GetPanels();
1318 // check texture numbers for panels
1319 for a
:= 0 to High(panels
) do
1321 if panels
[a
].TextureNum
> High(_textures
) then
1323 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1327 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1330 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1331 if triggers
<> nil then
1333 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1334 SetLength(TriggersTable
, Length(triggers
));
1335 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1337 for a
:= 0 to High(TriggersTable
) do
1339 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1340 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1342 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1343 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1345 TriggersTable
[a
].LiftPanel
:= -1;
1347 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1348 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1349 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1350 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1352 TriggersTable
[a
].DoorPanel
:= -1;
1354 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1355 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1357 TriggersTable
[a
].ShotPanel
:= -1;
1359 g_Game_StepLoading();
1364 if panels
<> nil then
1366 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1367 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1369 for a
:= 0 to High(panels
) do
1371 SetLength(AddTextures
, 0);
1374 if _textures
<> nil then
1376 texture
:= _textures
[panels
[a
].TextureNum
];
1384 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1385 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1387 if (TriggersTable
<> nil) and (_textures
<> nil) then
1388 for b
:= 0 to High(TriggersTable
) do
1389 if (TriggersTable
[b
].TexturePanel
= a
)
1390 or (TriggersTable
[b
].ShotPanel
= a
) then
1399 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1401 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1404 for c
:= Len
downto 1 do
1412 // Ñïåö-òåêñòóðû çàïðåùåíû:
1413 if g_Map_IsSpecialTexture(s
) then
1416 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1417 ok
:= g_Texture_NumNameFindStart(s
);
1419 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1420 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1423 k
:= NNF_NAME_BEFORE
;
1424 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1425 while ok
or (k
= NNF_NAME_BEFORE
) or
1426 (k
= NNF_NAME_EQUALS
) do
1428 k
:= g_Texture_NumNameFindNext(TexName
);
1430 if (k
= NNF_NAME_BEFORE
) or
1431 (k
= NNF_NAME_AFTER
) then
1433 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1434 if ByteBool(texture
.Anim
) then
1435 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1437 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1439 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1441 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1445 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1447 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1449 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1451 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1455 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1458 for c
:= 0 to High(Textures
) do
1459 if Textures
[c
].TextureName
= TexName
then
1461 SetLength(AddTextures
, Length(AddTextures
)+1);
1462 AddTextures
[High(AddTextures
)].Texture
:= c
;
1463 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1469 if k
= NNF_NAME_EQUALS
then
1471 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1472 SetLength(AddTextures
, Length(AddTextures
)+1);
1473 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1474 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1475 CurTex
:= High(AddTextures
);
1483 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1484 end; // if ok - ññûëàþòñÿ òðèããåðû
1488 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1489 SetLength(AddTextures
, 1);
1490 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1491 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1495 //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);
1497 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1498 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1500 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1501 if TriggersTable
<> nil then
1502 for b
:= 0 to High(TriggersTable
) do
1504 // Òðèããåð äâåðè/ëèôòà:
1505 if (TriggersTable
[b
].LiftPanel
= a
) or
1506 (TriggersTable
[b
].DoorPanel
= a
) then
1507 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1508 // Òðèããåð ñìåíû òåêñòóðû:
1509 if TriggersTable
[b
].TexturePanel
= a
then
1510 triggers
[b
].TexturePanel
:= PanelID
;
1511 // Òðèããåð "Òóðåëü":
1512 if TriggersTable
[b
].ShotPanel
= a
then
1513 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1516 g_Game_StepLoading();
1520 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1521 if (triggers
<> nil) and not gLoadGameMode
then
1523 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1524 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1525 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1526 for a
:= 0 to High(triggers
) do
1528 if triggers
[a
].TexturePanel
<> -1 then
1529 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1532 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1533 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1534 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1537 CreateTrigger(triggers
[a
], b
, c
);
1541 // Çàãðóçêà ïðåäìåòîâ:
1542 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1543 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1544 items
:= MapReader
.GetItems();
1546 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1547 if (items
<> nil) and not gLoadGameMode
then
1549 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1550 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1551 for a
:= 0 to High(items
) do
1552 CreateItem(Items
[a
]);
1555 // Çàãðóçêà îáëàñòåé:
1556 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1557 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1558 areas
:= MapReader
.GetAreas();
1560 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1561 if areas
<> nil then
1563 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1564 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1565 for a
:= 0 to High(areas
) do
1566 CreateArea(areas
[a
]);
1569 // Çàãðóçêà ìîíñòðîâ:
1570 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1571 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1572 monsters
:= MapReader
.GetMonsters();
1574 gTotalMonsters
:= 0;
1576 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1577 if (monsters
<> nil) and not gLoadGameMode
then
1579 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1580 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1581 for a
:= 0 to High(monsters
) do
1582 CreateMonster(monsters
[a
]);
1585 // Çàãðóçêà îïèñàíèÿ êàðòû:
1586 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1587 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1588 Header
:= MapReader
.GetMapHeader();
1594 Name
:= Header
.MapName
;
1595 Description
:= Header
.MapDescription
;
1596 Author
:= Header
.MapAuthor
;
1597 MusicName
:= Header
.MusicName
;
1598 SkyName
:= Header
.SkyName
;
1599 Height
:= Header
.Height
;
1600 Width
:= Header
.Width
;
1604 if gMapInfo
.SkyName
<> '' then
1606 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1607 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1608 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1610 if FileName
<> '' then
1611 FileName
:= GameDir
+'/wads/'+FileName
1614 FileName
:= g_ExtractWadName(Res
);
1617 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1618 if g_Texture_CreateWAD(BackID
, s
) then
1620 g_Game_SetupScreenSize();
1623 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1628 if gMapInfo
.MusicName
<> '' then
1630 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1631 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1632 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1634 if FileName
<> '' then
1635 FileName
:= GameDir
+'/wads/'+FileName
1638 FileName
:= g_ExtractWadName(Res
);
1641 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1642 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1645 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1648 // Îñòàëüíûå óñòàíâêè:
1656 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1657 if not gLoadGameMode
then
1660 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1666 TriggersTable
:= nil;
1669 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1670 if ok
and (not gLoadGameMode
) then
1672 gMusic
.SetByName(gMapInfo
.MusicName
);
1676 gMusic
.SetByName('');
1678 sfsGCEnable(); // enable releasing unused volumes
1681 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1684 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1688 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1691 MapReader
: TMapReader_1
;
1692 Header
: TMapHeaderRec_1
;
1697 FillChar(Result
, SizeOf(Result
), 0);
1698 FileName
:= g_ExtractWadName(Res
);
1700 WAD
:= TWADFile
.Create();
1701 if not WAD
.ReadFile(FileName
) then
1707 //k8: it ignores path again
1708 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1716 MapReader
:= TMapReader_1
.Create();
1718 if not MapReader
.LoadMap(Data
) then
1720 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1721 ZeroMemory(@Header
, SizeOf(Header
));
1722 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1723 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1727 Header
:= MapReader
.GetMapHeader();
1728 Result
.Name
:= Header
.MapName
;
1729 Result
.Description
:= Header
.MapDescription
;
1736 Result
.Author
:= Header
.MapAuthor
;
1737 Result
.Height
:= Header
.Height
;
1738 Result
.Width
:= Header
.Width
;
1741 function g_Map_GetMapsList(WADName
: string): SArray
;
1748 WAD
:= TWADFile
.Create();
1749 if not WAD
.ReadFile(WADName
) then
1754 ResList
:= WAD
.GetMapResources();
1755 if ResList
<> nil then
1757 for a
:= 0 to High(ResList
) do
1759 SetLength(Result
, Length(Result
)+1);
1760 Result
[High(Result
)] := ResList
[a
];
1766 function g_Map_Exist(Res
: string): Boolean;
1769 FileName
, mnn
: string;
1775 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1777 WAD
:= TWADFile
.Create
;
1778 if not WAD
.ReadFile(FileName
) then
1784 ResList
:= WAD
.GetMapResources();
1787 mnn
:= g_ExtractFileName(Res
);
1788 if ResList
<> nil then
1789 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1796 procedure g_Map_Free();
1800 procedure FreePanelArray(var panels
: TPanelArray
);
1805 if panels
<> nil then
1807 for i
:= 0 to High(panels
) do
1820 RespawnPoints
:= nil;
1821 if FlagPoints
[FLAG_RED
] <> nil then
1823 Dispose(FlagPoints
[FLAG_RED
]);
1824 FlagPoints
[FLAG_RED
] := nil;
1826 if FlagPoints
[FLAG_BLUE
] <> nil then
1828 Dispose(FlagPoints
[FLAG_BLUE
]);
1829 FlagPoints
[FLAG_BLUE
] := nil;
1831 //DOMFlagPoints := nil;
1835 if Textures
<> nil then
1837 for a
:= 0 to High(Textures
) do
1838 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1839 if Textures
[a
].Anim
then
1840 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1842 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1843 e_DeleteTexture(Textures
[a
].TextureID
);
1848 FreePanelArray(gWalls
);
1849 FreePanelArray(gRenderBackgrounds
);
1850 FreePanelArray(gRenderForegrounds
);
1851 FreePanelArray(gWater
);
1852 FreePanelArray(gAcid1
);
1853 FreePanelArray(gAcid2
);
1854 FreePanelArray(gSteps
);
1855 FreePanelArray(gLifts
);
1856 FreePanelArray(gBlockMon
);
1858 if BackID
<> DWORD(-1) then
1862 e_DeleteTexture(BackID
);
1863 BackID
:= DWORD(-1);
1866 g_Game_StopAllSounds(False);
1868 g_Sound_Delete(gMapInfo
.MusicName
);
1870 gMapInfo
.Name
:= '';
1871 gMapInfo
.Description
:= '';
1872 gMapInfo
.MusicName
:= '';
1873 gMapInfo
.Height
:= 0;
1874 gMapInfo
.Width
:= 0;
1882 procedure g_Map_Update();
1888 procedure UpdatePanelArray(var panels
: TPanelArray
);
1893 if panels
<> nil then
1894 for i
:= 0 to High(panels
) do
1899 UpdatePanelArray(gWalls
);
1900 UpdatePanelArray(gRenderBackgrounds
);
1901 UpdatePanelArray(gRenderForegrounds
);
1902 UpdatePanelArray(gWater
);
1903 UpdatePanelArray(gAcid1
);
1904 UpdatePanelArray(gAcid2
);
1905 UpdatePanelArray(gSteps
);
1907 if gGameSettings
.GameMode
= GM_CTF
then
1909 for a
:= FLAG_RED
to FLAG_BLUE
do
1910 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1913 if gFlags
[a
].Animation
<> nil then
1914 gFlags
[a
].Animation
.Update();
1916 m
:= g_Obj_Move(@Obj
, True, True);
1918 if gTime
mod (GAME_TICK
*2) <> 0 then
1921 // Ñîïðîòèâëåíèå âîçäóõà:
1922 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1924 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1925 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1928 gFlags
[a
].CaptureTime
:= 0;
1929 if a
= FLAG_RED
then
1930 s
:= _lc
[I_PLAYER_FLAG_RED
]
1932 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1933 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1935 if g_Game_IsNet
then
1936 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1943 // Èãðîê áåðåò ôëàã:
1944 if gPlayers
<> nil then
1946 j
:= Random(Length(gPlayers
)) - 1;
1948 for d
:= 0 to High(gPlayers
) do
1951 if j
> High(gPlayers
) then
1954 if gPlayers
[j
] <> nil then
1955 if gPlayers
[j
].Live
and
1956 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1958 if gPlayers
[j
].GetFlag(a
) then
1969 procedure g_Map_DrawPanels (PanelType
: Word);
1971 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1975 if (panels
<> nil) then
1977 // alas, no visible set
1978 for idx
:= 0 to High(panels
) do
1980 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1987 PANEL_WALL
: DrawPanels(gWalls
);
1988 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1989 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1990 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1991 PANEL_WATER
: DrawPanels(gWater
);
1992 PANEL_ACID1
: DrawPanels(gAcid1
);
1993 PANEL_ACID2
: DrawPanels(gAcid2
);
1994 PANEL_STEP
: DrawPanels(gSteps
);
2000 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2001 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2003 result
:= false; // don't stop, ever
2004 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2005 gDrawPanelList
.insert(pan
);
2010 //tagmask := panelTypeToTag(PanelType);
2012 if gdbg_map_use_tree_draw
then
2014 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
2018 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
));
2020 // list will be rendered in `g_game.DrawPlayer()`
2024 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2025 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2027 result
:= false; // don't stop, ever
2028 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2032 if gdbg_map_use_tree_draw
then
2034 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2038 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2043 procedure g_Map_DrawBack(dx
, dy
: Integer);
2045 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2046 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2048 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2051 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2052 PanelType
: Word; b1x3
: Boolean): Boolean;
2058 if WordBool(PanelType
and PANEL_WALL
) then
2059 if gWalls
<> nil then
2064 if gWalls
[a
].Enabled
and
2065 g_Collide(X
, Y
, Width
, Height
,
2066 gWalls
[a
].X
, gWalls
[a
].Y
,
2067 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2074 if WordBool(PanelType
and PANEL_WATER
) then
2075 if gWater
<> nil then
2080 if g_Collide(X
, Y
, Width
, Height
,
2081 gWater
[a
].X
, gWater
[a
].Y
,
2082 gWater
[a
].Width
, gWater
[a
].Height
) then
2089 if WordBool(PanelType
and PANEL_ACID1
) then
2090 if gAcid1
<> nil then
2095 if g_Collide(X
, Y
, Width
, Height
,
2096 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2097 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2104 if WordBool(PanelType
and PANEL_ACID2
) then
2105 if gAcid2
<> nil then
2110 if g_Collide(X
, Y
, Width
, Height
,
2111 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2112 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2119 if WordBool(PanelType
and PANEL_STEP
) then
2120 if gSteps
<> nil then
2125 if g_Collide(X
, Y
, Width
, Height
,
2126 gSteps
[a
].X
, gSteps
[a
].Y
,
2127 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2134 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2135 if gLifts
<> nil then
2140 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2141 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2142 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2143 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2144 g_Collide(X
, Y
, Width
, Height
,
2145 gLifts
[a
].X
, gLifts
[a
].Y
,
2146 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2153 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2154 if gBlockMon
<> nil then
2156 h
:= High(gBlockMon
);
2160 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2161 g_Collide(X
, Y
, Width
, Height
,
2162 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2163 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2171 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2175 function checkPanels (constref panels
: TPanelArray
): Boolean;
2180 if panels
= nil then exit
;
2181 for a
:= 0 to High(panels
) do
2183 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2186 texid
:= panels
[a
].GetTextureID();
2193 texid
:= TEXTURE_NONE
;
2195 if not checkPanels(gWater
) then
2196 if not checkPanels(gAcid1
) then
2197 if not checkPanels(gAcid2
) then exit
;
2202 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2203 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2205 result
:= false; // don't stop, ever
2207 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
2209 if not pan
.Enabled
then exit
;
2212 if ((tag
and GridTagLift
) <> 0) then
2215 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2216 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2217 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2218 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) and
2219 g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2223 if ((tag
and GridTagBlockMon
) <> 0) then
2225 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)) and g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2230 result
:= g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
2234 tagmask
: Integer = 0;
2236 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2237 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2238 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2239 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2240 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2241 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2242 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2244 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2246 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2247 if gdbg_map_use_accel_coldet
then
2249 if gdbg_map_use_tree_coldet
then
2251 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2252 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2253 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2255 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2256 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2261 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
);
2266 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2268 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2272 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2274 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2277 // slightly different from the old code, but meh...
2278 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2280 result
:= false; // don't stop, ever
2281 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2284 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2285 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2286 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2289 if not g_Collide(X
, Y
, Width
, Height
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
) then exit
;
2291 texid
:= pan
.GetTextureID();
2292 // water? water has the highest priority, so stop right here
2293 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2295 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2297 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2301 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2302 if gdbg_map_use_accel_coldet
then
2304 texid
:= TEXTURE_NONE
;
2305 if gdbg_map_use_tree_coldet
then
2307 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2311 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2317 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2319 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2322 procedure g_Map_EnableWall(ID
: DWORD
);
2327 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2329 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2333 procedure g_Map_DisableWall(ID
: DWORD
);
2338 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2340 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2344 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2349 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2352 tp
:= gRenderForegrounds
[ID
];
2354 tp
:= gRenderBackgrounds
[ID
];
2367 tp
.NextTexture(AnimLoop
);
2368 if g_Game_IsServer
and g_Game_IsNet
then
2369 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2372 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2374 if gLifts
[ID
].LiftType
= t
then
2381 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2383 if LiftType
= 0 then
2384 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2385 else if LiftType
= 1 then
2386 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2387 else if LiftType
= 2 then
2388 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2389 else if LiftType
= 3 then
2390 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2392 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2396 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2399 PointsArray
: Array of TRespawnPoint
;
2402 SetLength(PointsArray
, 0);
2404 if RespawnPoints
= nil then
2407 for a
:= 0 to High(RespawnPoints
) do
2408 if RespawnPoints
[a
].PointType
= PointType
then
2410 SetLength(PointsArray
, Length(PointsArray
)+1);
2411 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2414 if PointsArray
= nil then
2417 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2421 function g_Map_GetPointCount(PointType
: Byte): Word;
2427 if RespawnPoints
= nil then
2430 for a
:= 0 to High(RespawnPoints
) do
2431 if RespawnPoints
[a
].PointType
= PointType
then
2432 Result
:= Result
+ 1;
2435 function g_Map_HaveFlagPoints(): Boolean;
2437 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2440 procedure g_Map_ResetFlag(Flag
: Byte);
2442 with gFlags
[Flag
] do
2448 Direction
:= D_LEFT
;
2449 State
:= FLAG_STATE_NONE
;
2450 if FlagPoints
[Flag
] <> nil then
2452 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2453 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2454 Direction
:= FlagPoints
[Flag
]^.Direction
;
2455 State
:= FLAG_STATE_NORMAL
;
2461 procedure g_Map_DrawFlags();
2464 Mirror
: TMirrorType
;
2466 if gGameSettings
.GameMode
<> GM_CTF
then
2469 for i
:= FLAG_RED
to FLAG_BLUE
do
2471 if State
<> FLAG_STATE_CAPTURED
then
2473 if State
= FLAG_STATE_NONE
then
2476 if Direction
= D_LEFT
then
2478 Mirror
:= M_HORIZONTAL
;
2487 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2489 if g_debug_Frames
then
2491 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2493 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2494 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2500 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2507 procedure SavePanelArray(var panels
: TPanelArray
);
2509 PAMem
: TBinMemoryWriter
;
2512 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2513 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2516 while i
< Length(panels
) do
2518 if panels
[i
].SaveIt
then
2522 // Ñîõðàíÿåì ïàíåëü:
2523 panels
[i
].SaveState(PAMem
);
2528 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2529 PAMem
.SaveToMemory(Mem
);
2533 procedure SaveFlag(flag
: PFlag
);
2536 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2538 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2539 Mem
.WriteByte(flag
^.RespawnType
);
2541 Mem
.WriteByte(flag
^.State
);
2542 // Íàïðàâëåíèå ôëàãà:
2543 if flag
^.Direction
= D_LEFT
then
2549 Obj_SaveState(@flag
^.Obj
, Mem
);
2553 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2555 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2556 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2557 SavePanelArray(gWalls
);
2558 // Ñîõðàíÿåì ïàíåëè ôîíà:
2559 SavePanelArray(gRenderBackgrounds
);
2560 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2561 SavePanelArray(gRenderForegrounds
);
2562 // Ñîõðàíÿåì ïàíåëè âîäû:
2563 SavePanelArray(gWater
);
2564 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2565 SavePanelArray(gAcid1
);
2566 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2567 SavePanelArray(gAcid2
);
2568 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2569 SavePanelArray(gSteps
);
2570 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2571 SavePanelArray(gLifts
);
2574 ///// Ñîõðàíÿåì ìóçûêó: /////
2575 // Ñèãíàòóðà ìóçûêè:
2576 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2579 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2580 if gMusic
.NoMusic
then
2584 Mem
.WriteString(str
, 64);
2585 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2586 dw
:= gMusic
.GetPosition();
2588 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2589 boo
:= gMusic
.SpecPause
;
2590 Mem
.WriteBoolean(boo
);
2593 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2594 Mem
.WriteInt(gTotalMonsters
);
2597 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2598 if gGameSettings
.GameMode
= GM_CTF
then
2600 // Ôëàã Êðàñíîé êîìàíäû:
2601 SaveFlag(@gFlags
[FLAG_RED
]);
2602 // Ôëàã Ñèíåé êîìàíäû:
2603 SaveFlag(@gFlags
[FLAG_BLUE
]);
2607 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2608 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2610 // Î÷êè Êðàñíîé êîìàíäû:
2611 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2612 // Î÷êè Ñèíåé êîìàíäû:
2613 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2618 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2625 procedure LoadPanelArray(var panels
: TPanelArray
);
2627 PAMem
: TBinMemoryReader
;
2630 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2631 PAMem
:= TBinMemoryReader
.Create();
2632 PAMem
.LoadFromMemory(Mem
);
2634 for i
:= 0 to Length(panels
)-1 do
2635 if panels
[i
].SaveIt
then
2641 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2643 // Çàãðóæàåì ïàíåëü:
2644 panels
[i
].LoadState(PAMem
);
2647 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2651 procedure LoadFlag(flag
: PFlag
);
2655 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2657 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2659 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2660 Mem
.ReadByte(flag
^.RespawnType
);
2662 Mem
.ReadByte(flag
^.State
);
2663 // Íàïðàâëåíèå ôëàãà:
2666 flag
^.Direction
:= D_LEFT
2668 flag
^.Direction
:= D_RIGHT
;
2670 Obj_LoadState(@flag
^.Obj
, Mem
);
2677 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2678 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2679 LoadPanelArray(gWalls
);
2680 // Çàãðóæàåì ïàíåëè ôîíà:
2681 LoadPanelArray(gRenderBackgrounds
);
2682 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2683 LoadPanelArray(gRenderForegrounds
);
2684 // Çàãðóæàåì ïàíåëè âîäû:
2685 LoadPanelArray(gWater
);
2686 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2687 LoadPanelArray(gAcid1
);
2688 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2689 LoadPanelArray(gAcid2
);
2690 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2691 LoadPanelArray(gSteps
);
2692 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2693 LoadPanelArray(gLifts
);
2696 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2700 ///// Çàãðóæàåì ìóçûêó: /////
2701 // Ñèãíàòóðà ìóçûêè:
2703 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2705 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2708 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2709 Mem
.ReadString(str
);
2710 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2712 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2713 Mem
.ReadBoolean(boo
);
2714 // Çàïóñêàåì ýòó ìóçûêó:
2715 gMusic
.SetByName(str
);
2716 gMusic
.SpecPause
:= boo
;
2719 gMusic
.SetPosition(dw
);
2722 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2723 Mem
.ReadInt(gTotalMonsters
);
2726 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2727 if gGameSettings
.GameMode
= GM_CTF
then
2729 // Ôëàã Êðàñíîé êîìàíäû:
2730 LoadFlag(@gFlags
[FLAG_RED
]);
2731 // Ôëàã Ñèíåé êîìàíäû:
2732 LoadFlag(@gFlags
[FLAG_BLUE
]);
2736 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2737 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2739 // Î÷êè Êðàñíîé êîìàíäû:
2740 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2741 // Î÷êè Ñèíåé êîìàíäû:
2742 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2747 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2752 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2753 Arr
:= PanelByID
[PanelID
].PWhere
^;
2754 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2755 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);