1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {$DEFINE MAP_DEBUG_ENABLED_FLAG}
23 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
, binheap
, xprofiler
;
38 PRespawnPoint
= ^TRespawnPoint
;
39 TRespawnPoint
= record
41 Direction
: TDirection
;
45 PFlagPoint
= ^TFlagPoint
;
46 TFlagPoint
= TRespawnPoint
;
54 CaptureTime
: LongWord;
55 Animation
: TAnimation
;
56 Direction
: TDirection
;
59 function g_Map_Load(Res
: String): Boolean;
60 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
61 function g_Map_GetMapsList(WADName
: String): SArray
;
62 function g_Map_Exist(Res
: String): Boolean;
63 procedure g_Map_Free();
64 procedure g_Map_Update();
66 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
67 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
69 procedure g_Map_DrawBack(dx
, dy
: Integer);
70 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
71 PanelType
: Word; b1x3
: Boolean=false): Boolean;
72 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
73 procedure g_Map_EnableWall(ID
: DWORD
);
74 procedure g_Map_DisableWall(ID
: DWORD
);
75 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
76 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
77 procedure g_Map_ReAdd_DieTriggers();
78 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
80 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
81 function g_Map_GetPointCount(PointType
: Byte): Word;
83 function g_Map_HaveFlagPoints(): Boolean;
85 procedure g_Map_ResetFlag(Flag
: Byte);
86 procedure g_Map_DrawFlags();
88 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
90 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
91 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
93 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
95 // returns wall index in `gWalls` or -1
96 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
99 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
101 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
103 // trace liquid, stepping by `dx` and `dy`
104 // return last seen liquid coords, and `false` if we're started outside of the liquid
105 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
108 procedure g_Map_ProfilersBegin ();
109 procedure g_Map_ProfilersEnd ();
113 RESPAWNPOINT_PLAYER1
= 1;
114 RESPAWNPOINT_PLAYER2
= 2;
116 RESPAWNPOINT_RED
= 4;
117 RESPAWNPOINT_BLUE
= 5;
125 FLAG_STATE_NORMAL
= 1;
126 FLAG_STATE_DROPPED
= 2;
127 FLAG_STATE_CAPTURED
= 3;
128 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
129 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
131 FLAG_TIME
= 720; // 20 seconds
133 SKY_STRETCH
: Single = 1.5;
148 // sorted by draw priority
149 GridTagBack
= 1 shl 0;
150 GridTagStep
= 1 shl 1;
151 GridTagWall
= 1 shl 2;
152 GridTagDoor
= 1 shl 3;
153 GridTagAcid1
= 1 shl 4;
154 GridTagAcid2
= 1 shl 5;
155 GridTagWater
= 1 shl 6;
156 GridTagFore
= 1 shl 7;
157 // the following are invisible
158 GridTagLift
= 1 shl 8;
159 GridTagBlockMon
= 1 shl 9;
161 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
166 gRenderBackgrounds
: TPanelArray
;
167 gRenderForegrounds
: TPanelArray
;
168 gWater
, gAcid1
, gAcid2
: TPanelArray
;
171 gBlockMon
: TPanelArray
;
172 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
173 //gDOMFlags: array of TFlag;
176 gDoorMap
: array of array of DWORD
;
177 gLiftMap
: array of array of DWORD
;
178 gWADHash
: TMD5Digest
;
179 BackID
: DWORD
= DWORD(-1);
180 gExternalResources
: TStringList
;
182 gdbg_map_use_accel_render
: Boolean = true;
183 gdbg_map_use_accel_coldet
: Boolean = true;
184 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
185 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
188 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
192 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
195 mapGrid
: TPanelGrid
= nil;
201 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
202 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
203 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
204 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
206 ImagingTypes
, Imaging
, ImagingUtility
,
207 ImagingGif
, ImagingNetworkGraphics
;
210 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
211 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
212 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
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;
239 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
240 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
241 result
:= (pa
.arrIdx
< pb
.arrIdx
);
244 procedure dplClear ();
246 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
252 PWhere
: ^TPanelArray
;
257 PanelById
: array of TPanelID
;
258 Textures
: TLevelTextureArray
;
259 RespawnPoints
: Array of TRespawnPoint
;
260 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
261 //DOMFlagPoints: Array of TFlagPoint;
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 // wall index in `gWalls` or -1
285 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
289 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
290 if (result
<> nil) then
292 if (hitx
<> nil) then hitx
^ := ex
;
293 if (hity
<> nil) then hity
^ := ey
;
297 if (hitx
<> nil) then hitx
^ := x1
;
298 if (hity
<> nil) then hity
^ := y1
;
303 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
305 function checker (pan
: TPanel
; tag
: Integer): Boolean;
308 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
310 result := pan.Enabled; // stop if wall is enabled
315 if ((tag
and GridTagLift
) <> 0) then
317 // stop if the lift of the right type
319 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
320 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
321 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
322 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
326 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
330 tagmask
: Integer = 0;
334 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
335 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
336 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
337 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
338 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
339 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
340 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
342 if (tagmask
= 0) then exit
;// just in case
343 if ((tagmask
and GridTagLift
) <> 0) then
346 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
351 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
356 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
358 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
359 (Texture
= TEXTURE_NAME_ACID1
) or
360 (Texture
= TEXTURE_NAME_ACID2
);
363 procedure CreateDoorMap();
365 PanelArray
: Array of record
371 a
, b
, c
, m
, i
, len
: Integer;
379 SetLength(PanelArray
, len
);
381 for a
:= 0 to High(gWalls
) do
382 if gWalls
[a
].Door
then
384 PanelArray
[i
].X
:= gWalls
[a
].X
;
385 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
386 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
387 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
388 PanelArray
[i
].Active
:= True;
389 PanelArray
[i
].PanelID
:= a
;
395 SetLength(PanelArray
, len
);
406 SetLength(gDoorMap
, 0);
408 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
411 if PanelArray
[a
].Active
then
413 PanelArray
[a
].Active
:= False;
414 m
:= Length(gDoorMap
);
415 SetLength(gDoorMap
, m
+1);
416 SetLength(gDoorMap
[m
], 1);
417 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
425 if PanelArray
[b
].Active
then
426 for c
:= 0 to High(gDoorMap
[m
]) do
427 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
428 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
429 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
430 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
431 gWalls
[gDoorMap
[m
, c
]].X
,
432 gWalls
[gDoorMap
[m
, c
]].Y
,
433 gWalls
[gDoorMap
[m
, c
]].Width
,
434 gWalls
[gDoorMap
[m
, c
]].Height
) then
436 PanelArray
[b
].Active
:= False;
437 SetLength(gDoorMap
[m
],
438 Length(gDoorMap
[m
])+1);
439 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
445 g_Game_StepLoading();
451 procedure CreateLiftMap();
453 PanelArray
: Array of record
458 a
, b
, c
, len
, i
, j
: Integer;
464 len
:= Length(gLifts
);
465 SetLength(PanelArray
, len
);
467 for a
:= 0 to len
-1 do
469 PanelArray
[a
].X
:= gLifts
[a
].X
;
470 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
471 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
472 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
473 PanelArray
[a
].Active
:= True;
476 SetLength(gLiftMap
, len
);
479 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
481 for a
:= 0 to len
-1 do
482 if PanelArray
[a
].Active
then
484 PanelArray
[a
].Active
:= False;
485 SetLength(gLiftMap
[i
], 32);
493 for b
:= 0 to len
-1 do
494 if PanelArray
[b
].Active
then
496 if g_CollideAround(PanelArray
[b
].X
,
499 PanelArray
[b
].Height
,
500 PanelArray
[gLiftMap
[i
, c
]].X
,
501 PanelArray
[gLiftMap
[i
, c
]].Y
,
502 PanelArray
[gLiftMap
[i
, c
]].Width
,
503 PanelArray
[gLiftMap
[i
, c
]].Height
) then
505 PanelArray
[b
].Active
:= False;
507 if j
> High(gLiftMap
[i
]) then
508 SetLength(gLiftMap
[i
],
509 Length(gLiftMap
[i
])+32);
518 SetLength(gLiftMap
[i
], j
+1);
521 g_Game_StepLoading();
524 SetLength(gLiftMap
, i
);
529 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
530 CurTex
: Integer; sav
: Boolean): Integer;
533 panels
: ^TPanelArray
;
537 case PanelRec
.PanelType
of
538 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
541 panels
:= @gRenderBackgrounds
;
543 panels
:= @gRenderForegrounds
;
552 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
555 panels
:= @gBlockMon
;
560 len
:= Length(panels
^);
561 SetLength(panels
^, len
+ 1);
563 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
564 panels
^[len
].arrIdx
:= len
;
565 panels
^[len
].proxyId
:= -1;
566 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
568 panels
^[len
].SaveIt
:= True;
572 len
:= Length(PanelByID
);
573 SetLength(PanelByID
, len
+ 1);
574 PanelByID
[len
].PWhere
:= panels
;
575 PanelByID
[len
].PArrID
:= Result
;
578 function CreateNullTexture(RecName
: String): Integer;
580 SetLength(Textures
, Length(Textures
)+1);
581 result
:= High(Textures
);
583 with Textures
[High(Textures
)] do
585 TextureName
:= RecName
;
589 TextureID
:= TEXTURE_NONE
;
593 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
596 TextureData
: Pointer;
597 WADName
, txname
: String;
598 a
, ResLength
: Integer;
602 if Textures
<> nil then
603 for a
:= 0 to High(Textures
) do
604 if Textures
[a
].TextureName
= RecName
then
605 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
610 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
611 if (RecName
= TEXTURE_NAME_WATER
) or
612 (RecName
= TEXTURE_NAME_ACID1
) or
613 (RecName
= TEXTURE_NAME_ACID2
) then
615 SetLength(Textures
, Length(Textures
)+1);
617 with Textures
[High(Textures
)] do
619 TextureName
:= RecName
;
621 if TextureName
= TEXTURE_NAME_WATER
then
622 TextureID
:= TEXTURE_SPECIAL_WATER
624 if TextureName
= TEXTURE_NAME_ACID1
then
625 TextureID
:= TEXTURE_SPECIAL_ACID1
627 if TextureName
= TEXTURE_NAME_ACID2
then
628 TextureID
:= TEXTURE_SPECIAL_ACID2
;
633 result
:= High(Textures
);
637 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
638 WADName
:= g_ExtractWadName(RecName
);
640 WAD
:= TWADFile
.Create();
642 if WADName
<> '' then
643 WADName
:= GameDir
+'/wads/'+WADName
647 WAD
.ReadFile(WADName
);
651 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
653 FreeMem(TextureData);
654 RecName := 'COMMON\ALIEN';
658 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
660 SetLength(Textures
, Length(Textures
)+1);
661 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
663 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
664 @Textures
[High(Textures
)].Width
,
665 @Textures
[High(Textures
)].Height
);
666 FreeMem(TextureData
);
667 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
668 Textures
[High(Textures
)].Anim
:= False;
670 result
:= High(Textures
);
672 else // Íåò òàêîãî ðåóñðñà â WAD'å
674 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
677 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
678 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
685 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
688 TextureWAD
: PChar = nil;
689 TextData
: Pointer = nil;
690 TextureData
: Pointer = nil;
694 TextureResource
: String;
695 _width
, _height
, _framecount
, _speed
: Integer;
696 _backanimation
: Boolean;
698 ia
: TDynImageDataArray
= nil;
699 f
, c
, frdelay
, frloop
: Integer;
703 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
705 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
706 WADName
:= g_ExtractWadName(RecName
);
708 WAD
:= TWADFile
.Create();
710 if WADName
<> '' then
711 WADName
:= GameDir
+'/wads/'+WADName
715 WAD
.ReadFile(WADName
);
717 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
721 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
722 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
728 if WADName = Map then
730 //FreeMem(TextureWAD);
731 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
737 if ResLength
< 6 then
739 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
743 // ýòî ïòèöà? ýòî ñàìîë¸ò?
744 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
745 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
747 // íåò, ýòî ñóïåðìåí!
748 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
750 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
754 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
755 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
757 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
761 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
763 TextureResource
:= cfg
.ReadStr('', 'resource', '');
764 if TextureResource
= '' then
766 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
770 _width
:= cfg
.ReadInt('', 'framewidth', 0);
771 _height
:= cfg
.ReadInt('', 'frameheight', 0);
772 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
773 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
774 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
779 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
780 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
782 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
789 SetLength(Textures
, Length(Textures
)+1);
790 with Textures
[High(Textures
)] do
792 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
793 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
795 TextureName
:= RecName
;
799 FramesCount
:= _framecount
;
801 result
:= High(Textures
);
805 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
811 // try animated image
813 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
814 if length(imgfmt) = 0 then
816 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
820 GlobalMetadata
.ClearMetaItems();
821 GlobalMetadata
.ClearMetaItemsForSaving();
822 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
824 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
827 if length(ia
) = 0 then
829 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
836 _width
:= ia
[0].width
;
837 _height
:= ia
[0].height
;
838 _framecount
:= length(ia
);
840 _backanimation
:= false;
843 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
845 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
847 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
849 if f
< 0 then f
:= 0;
852 if c
< 13 then c
:= 0 else c
:= 1;
854 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
859 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
861 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
863 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
865 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
869 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
870 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
871 f
:= ord(_backanimation
);
872 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
);
874 SetLength(Textures
, Length(Textures
)+1);
875 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
876 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
878 Textures
[High(Textures
)].TextureName
:= RecName
;
879 Textures
[High(Textures
)].Width
:= _width
;
880 Textures
[High(Textures
)].Height
:= _height
;
881 Textures
[High(Textures
)].Anim
:= True;
882 Textures
[High(Textures
)].FramesCount
:= length(ia
);
883 Textures
[High(Textures
)].Speed
:= _speed
;
884 result
:= High(Textures
);
885 //writeln(' CREATED!');
889 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
893 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
896 if TextureWAD
<> nil then FreeMem(TextureWAD
);
897 if TextData
<> nil then FreeMem(TextData
);
898 if TextureData
<> nil then FreeMem(TextureData
);
902 procedure CreateItem(Item
: TItemRec_1
);
904 if g_Game_IsClient
then Exit
;
906 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
907 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
910 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
911 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
914 procedure CreateArea(Area
: TAreaRec_1
);
919 case Area
.AreaType
of
920 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
921 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
923 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
924 with RespawnPoints
[High(RespawnPoints
)] do
928 Direction
:= TDirection(Area
.Direction
);
930 case Area
.AreaType
of
931 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
932 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
933 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
934 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
935 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
940 AREA_REDFLAG
, AREA_BLUEFLAG
:
942 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
944 if FlagPoints
[a
] <> nil then Exit
;
948 with FlagPoints
[a
]^ do
950 X
:= Area
.X
-FLAGRECT
.X
;
951 Y
:= Area
.Y
-FLAGRECT
.Y
;
952 Direction
:= TDirection(Area
.Direction
);
958 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
959 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
962 Animation
:= TAnimation
.Create(id
, True, 8);
963 Obj
.Rect
:= FLAGRECT
;
971 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
972 with DOMFlagPoints[High(DOMFlagPoints)] do
976 Direction := TDirection(Area.Direction);
979 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
984 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
988 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
994 Width
:= Trigger
.Width
;
995 Height
:= Trigger
.Height
;
996 Enabled
:= ByteBool(Trigger
.Enabled
);
997 TexturePanel
:= Trigger
.TexturePanel
;
998 TexturePanelType
:= fTexturePanel1Type
;
999 ShotPanelType
:= fTexturePanel2Type
;
1000 TriggerType
:= Trigger
.TriggerType
;
1001 ActivateType
:= Trigger
.ActivateType
;
1002 Keys
:= Trigger
.Keys
;
1003 Data
.Default
:= Trigger
.DATA
;
1006 g_Triggers_Create(_trigger
);
1009 procedure CreateMonster(monster
: TMonsterRec_1
);
1014 if g_Game_IsClient
then Exit
;
1016 if (gGameSettings
.GameType
= GT_SINGLE
)
1017 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1019 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1021 if gTriggers
<> nil then
1023 for a
:= 0 to High(gTriggers
) do
1025 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1027 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1032 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1036 procedure g_Map_ReAdd_DieTriggers();
1038 function monsDieTrig (mon
: TMonster
): Boolean;
1042 result
:= false; // don't stop
1043 mon
.ClearTriggers();
1044 for a
:= 0 to High(gTriggers
) do
1046 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1048 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1054 if g_Game_IsClient
then Exit
;
1056 g_Mons_ForEach(monsDieTrig
);
1059 function extractWadName(resourceName
: string): string;
1063 posN
:= Pos(':', resourceName
);
1065 Result
:= Copy(resourceName
, 0, posN
-1)
1070 procedure addResToExternalResList(res
: string);
1072 res
:= extractWadName(res
);
1073 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1074 gExternalResources
.Add(res
);
1077 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1079 textures
: TTexturesRec1Array
;
1080 mapHeader
: TMapHeaderRec_1
;
1082 resFile
: String = '';
1084 if gExternalResources
= nil then
1085 gExternalResources
:= TStringList
.Create
;
1087 gExternalResources
.Clear
;
1088 textures
:= mapReader
.GetTextures();
1089 for i
:= 0 to High(textures
) do
1091 addResToExternalResList(resFile
);
1096 mapHeader
:= mapReader
.GetMapHeader
;
1098 addResToExternalResList(mapHeader
.MusicName
);
1099 addResToExternalResList(mapHeader
.SkyName
);
1103 procedure mapCreateGrid ();
1105 mapX0
: Integer = $3fffffff;
1106 mapY0
: Integer = $3fffffff;
1107 mapX1
: Integer = -$3fffffff;
1108 mapY1
: Integer = -$3fffffff;
1110 procedure calcBoundingBox (constref panels
: TPanelArray
);
1115 for idx
:= 0 to High(panels
) do
1118 if not pan
.visvalid
then continue
;
1119 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1120 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1121 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1122 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1123 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1127 procedure addPanelsToGrid (constref panels
: TPanelArray
; tag
: Integer);
1132 tag
:= panelTypeToTag(tag
);
1133 for idx
:= High(panels
) downto 0 do
1137 if not pan
.visvalid
then continue
;
1138 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1139 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1140 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1141 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1142 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
1144 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
])]), MSG_NOTIFY
);
1154 calcBoundingBox(gWalls
);
1155 calcBoundingBox(gRenderBackgrounds
);
1156 calcBoundingBox(gRenderForegrounds
);
1157 calcBoundingBox(gWater
);
1158 calcBoundingBox(gAcid1
);
1159 calcBoundingBox(gAcid2
);
1160 calcBoundingBox(gSteps
);
1161 calcBoundingBox(gLifts
);
1162 calcBoundingBox(gBlockMon
);
1164 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]), MSG_WARNING
);
1166 if (mapX0
> 0) then mapX0
:= 0;
1167 if (mapY0
> 0) then mapY0
:= 0;
1169 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1170 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1172 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1174 addPanelsToGrid(gWalls
, PANEL_WALL
);
1175 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1176 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1177 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1178 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1179 addPanelsToGrid(gWater
, PANEL_WATER
);
1180 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1181 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1182 addPanelsToGrid(gSteps
, PANEL_STEP
);
1183 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1184 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1186 mapGrid
.dumpStats();
1188 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1192 function g_Map_Load(Res
: String): Boolean;
1194 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1195 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1198 MapReader
: TMapReader_1
;
1199 Header
: TMapHeaderRec_1
;
1200 _textures
: TTexturesRec1Array
;
1201 _texnummap
: array of Integer; // `_textures` -> `Textures`
1202 panels
: TPanelsRec1Array
;
1203 items
: TItemsRec1Array
;
1204 monsters
: TMonsterRec1Array
;
1205 areas
: TAreasRec1Array
;
1206 triggers
: TTriggersRec1Array
;
1207 a
, b
, c
, k
: Integer;
1209 AddTextures
: TAddTextureArray
;
1210 texture
: TTextureRec_1
;
1211 TriggersTable
: Array of record
1212 TexturePanel
: Integer;
1217 FileName
, mapResName
, s
, TexName
: String;
1220 ok
, isAnim
, trigRef
: Boolean;
1221 CurTex
, ntn
: Integer;
1230 gMapInfo
.Map
:= Res
;
1231 TriggersTable
:= nil;
1232 FillChar(texture
, SizeOf(texture
), 0);
1234 sfsGCDisable(); // temporary disable removing of temporary volumes
1237 FileName
:= g_ExtractWadName(Res
);
1238 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1239 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1241 WAD
:= TWADFile
.Create();
1242 if not WAD
.ReadFile(FileName
) then
1244 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1248 //k8: why loader ignores path here?
1249 mapResName
:= g_ExtractFileName(Res
);
1250 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1252 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1260 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1261 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1262 MapReader
:= TMapReader_1
.Create();
1264 if not MapReader
.LoadMap(Data
) then
1266 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1273 generateExternalResourcesList(MapReader
);
1274 // Çàãðóçêà òåêñòóð:
1275 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1276 _textures
:= MapReader
.GetTextures();
1279 // Çàãðóçêà îïèñàíèÿ êàðòû:
1280 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1281 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1282 Header
:= MapReader
.GetMapHeader();
1286 Name
:= Header
.MapName
;
1287 Description
:= Header
.MapDescription
;
1288 Author
:= Header
.MapAuthor
;
1289 MusicName
:= Header
.MusicName
;
1290 SkyName
:= Header
.SkyName
;
1291 Height
:= Header
.Height
;
1292 Width
:= Header
.Width
;
1295 // Äîáàâëåíèå òåêñòóð â Textures[]:
1296 if _textures
<> nil then
1298 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1299 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1300 SetLength(_texnummap
, length(_textures
));
1302 for a
:= 0 to High(_textures
) do
1305 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1306 for b
:= 1 to Length(s
) do
1312 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1313 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1314 // Àíèìèðîâàííàÿ òåêñòóðà:
1315 if ByteBool(_textures
[a
].Anim
) then
1317 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1320 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1321 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1324 else // Îáû÷íàÿ òåêñòóðà:
1325 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1328 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1329 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1332 _texnummap
[a
] := ntn
; // fix texture number
1333 g_Game_StepLoading();
1337 // Çàãðóçêà òðèããåðîâ:
1338 gTriggerClientID
:= 0;
1339 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1340 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1341 triggers
:= MapReader
.GetTriggers();
1343 // Çàãðóçêà ïàíåëåé:
1344 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1345 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1346 panels
:= MapReader
.GetPanels();
1348 // check texture numbers for panels
1349 for a
:= 0 to High(panels
) do
1351 if panels
[a
].TextureNum
> High(_textures
) then
1353 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1357 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1360 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1361 if triggers
<> nil then
1363 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1364 SetLength(TriggersTable
, Length(triggers
));
1365 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1367 for a
:= 0 to High(TriggersTable
) do
1369 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1370 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1372 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1373 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1375 TriggersTable
[a
].LiftPanel
:= -1;
1377 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1378 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1379 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1380 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1382 TriggersTable
[a
].DoorPanel
:= -1;
1384 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1385 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1387 TriggersTable
[a
].ShotPanel
:= -1;
1389 g_Game_StepLoading();
1394 if panels
<> nil then
1396 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1397 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1399 for a
:= 0 to High(panels
) do
1401 SetLength(AddTextures
, 0);
1404 if _textures
<> nil then
1406 texture
:= _textures
[panels
[a
].TextureNum
];
1414 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1415 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1417 if (TriggersTable
<> nil) and (_textures
<> nil) then
1418 for b
:= 0 to High(TriggersTable
) do
1419 if (TriggersTable
[b
].TexturePanel
= a
)
1420 or (TriggersTable
[b
].ShotPanel
= a
) then
1429 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1431 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1434 for c
:= Len
downto 1 do
1442 // Ñïåö-òåêñòóðû çàïðåùåíû:
1443 if g_Map_IsSpecialTexture(s
) then
1446 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1447 ok
:= g_Texture_NumNameFindStart(s
);
1449 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1450 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1453 k
:= NNF_NAME_BEFORE
;
1454 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1455 while ok
or (k
= NNF_NAME_BEFORE
) or
1456 (k
= NNF_NAME_EQUALS
) do
1458 k
:= g_Texture_NumNameFindNext(TexName
);
1460 if (k
= NNF_NAME_BEFORE
) or
1461 (k
= NNF_NAME_AFTER
) then
1463 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1464 if ByteBool(texture
.Anim
) then
1465 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1467 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1469 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1471 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1475 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1477 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1479 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1481 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1485 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1488 for c
:= 0 to High(Textures
) do
1489 if Textures
[c
].TextureName
= TexName
then
1491 SetLength(AddTextures
, Length(AddTextures
)+1);
1492 AddTextures
[High(AddTextures
)].Texture
:= c
;
1493 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1499 if k
= NNF_NAME_EQUALS
then
1501 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1502 SetLength(AddTextures
, Length(AddTextures
)+1);
1503 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1504 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1505 CurTex
:= High(AddTextures
);
1513 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1514 end; // if ok - ññûëàþòñÿ òðèããåðû
1518 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1519 SetLength(AddTextures
, 1);
1520 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1521 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1525 //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);
1527 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1528 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1530 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1531 if TriggersTable
<> nil then
1532 for b
:= 0 to High(TriggersTable
) do
1534 // Òðèããåð äâåðè/ëèôòà:
1535 if (TriggersTable
[b
].LiftPanel
= a
) or
1536 (TriggersTable
[b
].DoorPanel
= a
) then
1537 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1538 // Òðèããåð ñìåíû òåêñòóðû:
1539 if TriggersTable
[b
].TexturePanel
= a
then
1540 triggers
[b
].TexturePanel
:= PanelID
;
1541 // Òðèããåð "Òóðåëü":
1542 if TriggersTable
[b
].ShotPanel
= a
then
1543 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1546 g_Game_StepLoading();
1550 // create map grid, init other grids (for monsters, for example)
1551 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1554 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1555 if (triggers
<> nil) and not gLoadGameMode
then
1557 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1558 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1559 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1560 for a
:= 0 to High(triggers
) do
1562 if triggers
[a
].TexturePanel
<> -1 then
1563 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1566 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1567 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1568 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1571 CreateTrigger(triggers
[a
], b
, c
);
1575 // Çàãðóçêà ïðåäìåòîâ:
1576 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1577 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1578 items
:= MapReader
.GetItems();
1580 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1581 if (items
<> nil) and not gLoadGameMode
then
1583 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1584 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1585 for a
:= 0 to High(items
) do
1586 CreateItem(Items
[a
]);
1589 // Çàãðóçêà îáëàñòåé:
1590 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1591 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1592 areas
:= MapReader
.GetAreas();
1594 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1595 if areas
<> nil then
1597 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1598 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1599 for a
:= 0 to High(areas
) do
1600 CreateArea(areas
[a
]);
1603 // Çàãðóçêà ìîíñòðîâ:
1604 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1605 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1606 monsters
:= MapReader
.GetMonsters();
1608 gTotalMonsters
:= 0;
1610 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1611 if (monsters
<> nil) and not gLoadGameMode
then
1613 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1614 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1615 for a
:= 0 to High(monsters
) do
1616 CreateMonster(monsters
[a
]);
1622 if gMapInfo
.SkyName
<> '' then
1624 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1625 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1626 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1628 if FileName
<> '' then
1629 FileName
:= GameDir
+'/wads/'+FileName
1632 FileName
:= g_ExtractWadName(Res
);
1635 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1636 if g_Texture_CreateWAD(BackID
, s
) then
1638 g_Game_SetupScreenSize();
1641 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1646 if gMapInfo
.MusicName
<> '' then
1648 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1649 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1650 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1652 if FileName
<> '' then
1653 FileName
:= GameDir
+'/wads/'+FileName
1656 FileName
:= g_ExtractWadName(Res
);
1659 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1660 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1663 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1666 // Îñòàëüíûå óñòàíâêè:
1674 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1675 if not gLoadGameMode
then
1678 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1684 TriggersTable
:= nil;
1687 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1688 if ok
and (not gLoadGameMode
) then
1690 gMusic
.SetByName(gMapInfo
.MusicName
);
1694 gMusic
.SetByName('');
1696 sfsGCEnable(); // enable releasing unused volumes
1699 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1703 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1706 MapReader
: TMapReader_1
;
1707 Header
: TMapHeaderRec_1
;
1712 FillChar(Result
, SizeOf(Result
), 0);
1713 FileName
:= g_ExtractWadName(Res
);
1715 WAD
:= TWADFile
.Create();
1716 if not WAD
.ReadFile(FileName
) then
1722 //k8: it ignores path again
1723 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1731 MapReader
:= TMapReader_1
.Create();
1733 if not MapReader
.LoadMap(Data
) then
1735 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1736 ZeroMemory(@Header
, SizeOf(Header
));
1737 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1738 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1742 Header
:= MapReader
.GetMapHeader();
1743 Result
.Name
:= Header
.MapName
;
1744 Result
.Description
:= Header
.MapDescription
;
1751 Result
.Author
:= Header
.MapAuthor
;
1752 Result
.Height
:= Header
.Height
;
1753 Result
.Width
:= Header
.Width
;
1756 function g_Map_GetMapsList(WADName
: string): SArray
;
1763 WAD
:= TWADFile
.Create();
1764 if not WAD
.ReadFile(WADName
) then
1769 ResList
:= WAD
.GetMapResources();
1770 if ResList
<> nil then
1772 for a
:= 0 to High(ResList
) do
1774 SetLength(Result
, Length(Result
)+1);
1775 Result
[High(Result
)] := ResList
[a
];
1781 function g_Map_Exist(Res
: string): Boolean;
1784 FileName
, mnn
: string;
1790 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1792 WAD
:= TWADFile
.Create
;
1793 if not WAD
.ReadFile(FileName
) then
1799 ResList
:= WAD
.GetMapResources();
1802 mnn
:= g_ExtractFileName(Res
);
1803 if ResList
<> nil then
1804 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1811 procedure g_Map_Free();
1815 procedure FreePanelArray(var panels
: TPanelArray
);
1820 if panels
<> nil then
1822 for i
:= 0 to High(panels
) do
1835 RespawnPoints
:= nil;
1836 if FlagPoints
[FLAG_RED
] <> nil then
1838 Dispose(FlagPoints
[FLAG_RED
]);
1839 FlagPoints
[FLAG_RED
] := nil;
1841 if FlagPoints
[FLAG_BLUE
] <> nil then
1843 Dispose(FlagPoints
[FLAG_BLUE
]);
1844 FlagPoints
[FLAG_BLUE
] := nil;
1846 //DOMFlagPoints := nil;
1850 if Textures
<> nil then
1852 for a
:= 0 to High(Textures
) do
1853 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1854 if Textures
[a
].Anim
then
1855 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1857 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1858 e_DeleteTexture(Textures
[a
].TextureID
);
1863 FreePanelArray(gWalls
);
1864 FreePanelArray(gRenderBackgrounds
);
1865 FreePanelArray(gRenderForegrounds
);
1866 FreePanelArray(gWater
);
1867 FreePanelArray(gAcid1
);
1868 FreePanelArray(gAcid2
);
1869 FreePanelArray(gSteps
);
1870 FreePanelArray(gLifts
);
1871 FreePanelArray(gBlockMon
);
1873 if BackID
<> DWORD(-1) then
1877 e_DeleteTexture(BackID
);
1878 BackID
:= DWORD(-1);
1881 g_Game_StopAllSounds(False);
1883 g_Sound_Delete(gMapInfo
.MusicName
);
1885 gMapInfo
.Name
:= '';
1886 gMapInfo
.Description
:= '';
1887 gMapInfo
.MusicName
:= '';
1888 gMapInfo
.Height
:= 0;
1889 gMapInfo
.Width
:= 0;
1897 procedure g_Map_Update();
1903 procedure UpdatePanelArray(var panels
: TPanelArray
);
1908 if panels
<> nil then
1909 for i
:= 0 to High(panels
) do
1914 UpdatePanelArray(gWalls
);
1915 UpdatePanelArray(gRenderBackgrounds
);
1916 UpdatePanelArray(gRenderForegrounds
);
1917 UpdatePanelArray(gWater
);
1918 UpdatePanelArray(gAcid1
);
1919 UpdatePanelArray(gAcid2
);
1920 UpdatePanelArray(gSteps
);
1922 if gGameSettings
.GameMode
= GM_CTF
then
1924 for a
:= FLAG_RED
to FLAG_BLUE
do
1925 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1928 if gFlags
[a
].Animation
<> nil then
1929 gFlags
[a
].Animation
.Update();
1931 m
:= g_Obj_Move(@Obj
, True, True);
1933 if gTime
mod (GAME_TICK
*2) <> 0 then
1936 // Ñîïðîòèâëåíèå âîçäóõà:
1937 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1939 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1940 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1943 gFlags
[a
].CaptureTime
:= 0;
1944 if a
= FLAG_RED
then
1945 s
:= _lc
[I_PLAYER_FLAG_RED
]
1947 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1948 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1950 if g_Game_IsNet
then
1951 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1958 // Èãðîê áåðåò ôëàã:
1959 if gPlayers
<> nil then
1961 j
:= Random(Length(gPlayers
)) - 1;
1963 for d
:= 0 to High(gPlayers
) do
1966 if j
> High(gPlayers
) then
1969 if gPlayers
[j
] <> nil then
1970 if gPlayers
[j
].Live
and
1971 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1973 if gPlayers
[j
].GetFlag(a
) then
1984 procedure g_Map_DrawPanels (PanelType
: Word);
1986 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1990 if (panels
<> nil) then
1992 // alas, no visible set
1993 for idx
:= 0 to High(panels
) do
1995 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2002 PANEL_WALL
: DrawPanels(gWalls
);
2003 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2004 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2005 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2006 PANEL_WATER
: DrawPanels(gWater
);
2007 PANEL_ACID1
: DrawPanels(gAcid1
);
2008 PANEL_ACID2
: DrawPanels(gAcid2
);
2009 PANEL_STEP
: DrawPanels(gSteps
);
2015 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2017 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2019 result
:= false; // don't stop, ever
2020 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2021 gDrawPanelList
.insert(pan
);
2026 //tagmask := panelTypeToTag(PanelType);
2028 {if gdbg_map_use_tree_draw then
2030 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2034 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
, true);
2036 // list will be rendered in `g_game.DrawPlayer()`
2040 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2042 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2044 result
:= false; // don't stop, ever
2045 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2049 {if gdbg_map_use_tree_draw then
2051 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2055 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
), true);
2060 procedure g_Map_DrawBack(dx
, dy
: Integer);
2062 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2063 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2065 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2068 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2069 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2075 if WordBool(PanelType
and PANEL_WALL
) then
2076 if gWalls
<> nil then
2081 if gWalls
[a
].Enabled
and
2082 g_Collide(X
, Y
, Width
, Height
,
2083 gWalls
[a
].X
, gWalls
[a
].Y
,
2084 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2091 if WordBool(PanelType
and PANEL_WATER
) then
2092 if gWater
<> nil then
2097 if g_Collide(X
, Y
, Width
, Height
,
2098 gWater
[a
].X
, gWater
[a
].Y
,
2099 gWater
[a
].Width
, gWater
[a
].Height
) then
2106 if WordBool(PanelType
and PANEL_ACID1
) then
2107 if gAcid1
<> nil then
2112 if g_Collide(X
, Y
, Width
, Height
,
2113 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2114 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2121 if WordBool(PanelType
and PANEL_ACID2
) then
2122 if gAcid2
<> nil then
2127 if g_Collide(X
, Y
, Width
, Height
,
2128 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2129 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2136 if WordBool(PanelType
and PANEL_STEP
) then
2137 if gSteps
<> nil then
2142 if g_Collide(X
, Y
, Width
, Height
,
2143 gSteps
[a
].X
, gSteps
[a
].Y
,
2144 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2151 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2152 if gLifts
<> nil then
2157 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2158 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2159 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2160 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2161 g_Collide(X
, Y
, Width
, Height
,
2162 gLifts
[a
].X
, gLifts
[a
].Y
,
2163 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2170 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2171 if gBlockMon
<> nil then
2173 h
:= High(gBlockMon
);
2177 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2178 g_Collide(X
, Y
, Width
, Height
,
2179 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2180 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2188 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2192 function checkPanels (constref panels
: TPanelArray
): Boolean;
2197 if panels
= nil then exit
;
2198 for a
:= 0 to High(panels
) do
2200 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2203 texid
:= panels
[a
].GetTextureID();
2210 texid
:= TEXTURE_NONE
;
2212 if not checkPanels(gWater
) then
2213 if not checkPanels(gAcid1
) then
2214 if not checkPanels(gAcid2
) then exit
;
2219 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2221 SlowMask
= GridTagLift
or GridTagBlockMon
;
2222 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2225 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2227 result := pan.Enabled;
2232 if ((tag
and GridTagLift
) <> 0) then
2235 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2236 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2237 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2238 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2239 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2243 if ((tag
and GridTagBlockMon
) <> 0) then
2245 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2250 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2251 result
:= true; // i found her!
2255 tagmask
: Integer = 0;
2257 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2258 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2259 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2260 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2261 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2262 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2263 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2265 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2267 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2268 if gdbg_map_use_accel_coldet
then
2270 {if gdbg_map_use_tree_coldet then
2272 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2273 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2274 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2276 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2277 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2282 if (Width
= 1) and (Height
= 1) then
2284 if ((tagmask
and SlowMask
) <> 0) then
2287 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2292 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2297 if ((tagmask
and SlowMask
) <> 0) then
2300 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2305 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2312 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2314 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2318 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2320 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2323 // slightly different from the old code, but meh...
2324 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2326 result
:= false; // don't stop, ever
2327 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2330 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2331 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2332 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2335 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2337 texid
:= pan
.GetTextureID();
2338 // water? water has the highest priority, so stop right here
2339 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2341 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2343 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2347 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2348 if gdbg_map_use_accel_coldet
then
2350 texid
:= TEXTURE_NONE
;
2351 {if gdbg_map_use_tree_coldet then
2353 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2357 if (Width
= 1) and (Height
= 1) then
2359 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2363 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2370 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2372 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2376 procedure g_Map_EnableWall(ID
: DWORD
);
2381 pan
.Enabled
:= True;
2382 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2384 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2385 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2386 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2388 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2390 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2391 //e_WriteLog(Format('wall #%d(%d) enabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
2395 procedure g_Map_DisableWall(ID
: DWORD
);
2400 pan
.Enabled
:= False;
2401 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2403 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2404 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2406 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2408 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2409 //e_WriteLog(Format('wall #%d(%d) disabled (%d) (%d,%d)-(%d,%d)', [Integer(ID), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.x, pan.y, pan.width, pan.height]), MSG_NOTIFY);
2413 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2418 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2421 tp
:= gRenderForegrounds
[ID
];
2423 tp
:= gRenderBackgrounds
[ID
];
2436 tp
.NextTexture(AnimLoop
);
2437 if g_Game_IsServer
and g_Game_IsNet
then
2438 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2441 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2443 if gLifts
[ID
].LiftType
= t
then
2450 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2451 //TODO: make separate lift tags, and change tag here
2453 if LiftType
= 0 then
2454 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2455 else if LiftType
= 1 then
2456 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2457 else if LiftType
= 2 then
2458 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2459 else if LiftType
= 3 then
2460 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2462 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2466 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2469 PointsArray
: Array of TRespawnPoint
;
2472 SetLength(PointsArray
, 0);
2474 if RespawnPoints
= nil then
2477 for a
:= 0 to High(RespawnPoints
) do
2478 if RespawnPoints
[a
].PointType
= PointType
then
2480 SetLength(PointsArray
, Length(PointsArray
)+1);
2481 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2484 if PointsArray
= nil then
2487 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2491 function g_Map_GetPointCount(PointType
: Byte): Word;
2497 if RespawnPoints
= nil then
2500 for a
:= 0 to High(RespawnPoints
) do
2501 if RespawnPoints
[a
].PointType
= PointType
then
2502 Result
:= Result
+ 1;
2505 function g_Map_HaveFlagPoints(): Boolean;
2507 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2510 procedure g_Map_ResetFlag(Flag
: Byte);
2512 with gFlags
[Flag
] do
2518 Direction
:= D_LEFT
;
2519 State
:= FLAG_STATE_NONE
;
2520 if FlagPoints
[Flag
] <> nil then
2522 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2523 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2524 Direction
:= FlagPoints
[Flag
]^.Direction
;
2525 State
:= FLAG_STATE_NORMAL
;
2531 procedure g_Map_DrawFlags();
2534 Mirror
: TMirrorType
;
2536 if gGameSettings
.GameMode
<> GM_CTF
then
2539 for i
:= FLAG_RED
to FLAG_BLUE
do
2541 if State
<> FLAG_STATE_CAPTURED
then
2543 if State
= FLAG_STATE_NONE
then
2546 if Direction
= D_LEFT
then
2548 Mirror
:= M_HORIZONTAL
;
2557 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2559 if g_debug_Frames
then
2561 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2563 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2564 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2570 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2577 procedure SavePanelArray(var panels
: TPanelArray
);
2579 PAMem
: TBinMemoryWriter
;
2582 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2583 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2586 while i
< Length(panels
) do
2588 if panels
[i
].SaveIt
then
2592 // Ñîõðàíÿåì ïàíåëü:
2593 panels
[i
].SaveState(PAMem
);
2598 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2599 PAMem
.SaveToMemory(Mem
);
2603 procedure SaveFlag(flag
: PFlag
);
2606 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2608 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2609 Mem
.WriteByte(flag
^.RespawnType
);
2611 Mem
.WriteByte(flag
^.State
);
2612 // Íàïðàâëåíèå ôëàãà:
2613 if flag
^.Direction
= D_LEFT
then
2619 Obj_SaveState(@flag
^.Obj
, Mem
);
2623 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2625 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2626 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2627 SavePanelArray(gWalls
);
2628 // Ñîõðàíÿåì ïàíåëè ôîíà:
2629 SavePanelArray(gRenderBackgrounds
);
2630 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2631 SavePanelArray(gRenderForegrounds
);
2632 // Ñîõðàíÿåì ïàíåëè âîäû:
2633 SavePanelArray(gWater
);
2634 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2635 SavePanelArray(gAcid1
);
2636 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2637 SavePanelArray(gAcid2
);
2638 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2639 SavePanelArray(gSteps
);
2640 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2641 SavePanelArray(gLifts
);
2644 ///// Ñîõðàíÿåì ìóçûêó: /////
2645 // Ñèãíàòóðà ìóçûêè:
2646 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2649 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2650 if gMusic
.NoMusic
then
2654 Mem
.WriteString(str
, 64);
2655 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2656 dw
:= gMusic
.GetPosition();
2658 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2659 boo
:= gMusic
.SpecPause
;
2660 Mem
.WriteBoolean(boo
);
2663 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2664 Mem
.WriteInt(gTotalMonsters
);
2667 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2668 if gGameSettings
.GameMode
= GM_CTF
then
2670 // Ôëàã Êðàñíîé êîìàíäû:
2671 SaveFlag(@gFlags
[FLAG_RED
]);
2672 // Ôëàã Ñèíåé êîìàíäû:
2673 SaveFlag(@gFlags
[FLAG_BLUE
]);
2677 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2678 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2680 // Î÷êè Êðàñíîé êîìàíäû:
2681 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2682 // Î÷êè Ñèíåé êîìàíäû:
2683 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2688 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2695 procedure LoadPanelArray(var panels
: TPanelArray
);
2697 PAMem
: TBinMemoryReader
;
2700 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2701 PAMem
:= TBinMemoryReader
.Create();
2702 PAMem
.LoadFromMemory(Mem
);
2704 for i
:= 0 to Length(panels
)-1 do
2705 if panels
[i
].SaveIt
then
2711 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2713 // Çàãðóæàåì ïàíåëü:
2714 panels
[i
].LoadState(PAMem
);
2717 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2721 procedure LoadFlag(flag
: PFlag
);
2725 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2727 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2729 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2730 Mem
.ReadByte(flag
^.RespawnType
);
2732 Mem
.ReadByte(flag
^.State
);
2733 // Íàïðàâëåíèå ôëàãà:
2736 flag
^.Direction
:= D_LEFT
2738 flag
^.Direction
:= D_RIGHT
;
2740 Obj_LoadState(@flag
^.Obj
, Mem
);
2747 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2748 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2749 LoadPanelArray(gWalls
);
2750 // Çàãðóæàåì ïàíåëè ôîíà:
2751 LoadPanelArray(gRenderBackgrounds
);
2752 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2753 LoadPanelArray(gRenderForegrounds
);
2754 // Çàãðóæàåì ïàíåëè âîäû:
2755 LoadPanelArray(gWater
);
2756 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2757 LoadPanelArray(gAcid1
);
2758 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2759 LoadPanelArray(gAcid2
);
2760 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2761 LoadPanelArray(gSteps
);
2762 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2763 LoadPanelArray(gLifts
);
2766 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2770 ///// Çàãðóæàåì ìóçûêó: /////
2771 // Ñèãíàòóðà ìóçûêè:
2773 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2775 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2778 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2779 Mem
.ReadString(str
);
2780 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2782 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2783 Mem
.ReadBoolean(boo
);
2784 // Çàïóñêàåì ýòó ìóçûêó:
2785 gMusic
.SetByName(str
);
2786 gMusic
.SpecPause
:= boo
;
2789 gMusic
.SetPosition(dw
);
2792 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2793 Mem
.ReadInt(gTotalMonsters
);
2796 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2797 if gGameSettings
.GameMode
= GM_CTF
then
2799 // Ôëàã Êðàñíîé êîìàíäû:
2800 LoadFlag(@gFlags
[FLAG_RED
]);
2801 // Ôëàã Ñèíåé êîìàíäû:
2802 LoadFlag(@gFlags
[FLAG_BLUE
]);
2806 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2807 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2809 // Î÷êè Êðàñíîé êîìàíäû:
2810 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2811 // Î÷êè Ñèíåé êîìàíäû:
2812 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2817 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2822 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2823 Arr
:= PanelByID
[PanelID
].PWhere
^;
2824 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2825 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2829 // trace liquid, stepping by `dx` and `dy`
2830 // return last seen liquid coords, and `false` if we're started outside of the liquid
2831 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2833 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2837 // started outside of the liquid?
2838 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2839 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2845 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit