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): Boolean;
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()`
187 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
193 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
194 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
195 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
196 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
198 ImagingTypes
, Imaging
, ImagingUtility
,
199 ImagingGif
, ImagingNetworkGraphics
;
202 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
203 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
204 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
208 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
211 function panelTypeToTag (panelType
: Word): Integer;
214 PANEL_WALL
: result
:= GridTagWall
; // gWalls
215 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
216 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
217 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
218 PANEL_WATER
: result
:= GridTagWater
; // gWater
219 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
220 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
221 PANEL_STEP
: result
:= GridTagStep
; // gSteps
222 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
223 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
224 else result
:= GridTagInvalid
;
229 function dplLess (a
, b
: TObject
): Boolean;
235 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
236 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
237 result
:= (pa
.arrIdx
< pb
.arrIdx
);
240 procedure dplClear ();
242 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
248 PWhere
: ^TPanelArray
;
253 PanelById
: array of TPanelID
;
254 Textures
: TLevelTextureArray
;
255 RespawnPoints
: Array of TRespawnPoint
;
256 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
257 //DOMFlagPoints: Array of TFlagPoint;
258 mapGrid
: TPanelGrid
= nil;
261 procedure g_Map_ProfilersBegin ();
263 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
264 profMapCollision
.mainBegin(g_profile_collision
);
266 if g_profile_collision
then
268 profMapCollision
.sectionBegin('*solids');
269 profMapCollision
.sectionEnd();
270 profMapCollision
.sectionBegin('liquids');
271 profMapCollision
.sectionEnd();
275 procedure g_Map_ProfilersEnd ();
277 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
281 // wall index in `gWalls` or -1
282 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): Boolean;
286 result
:= (mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
)) <> nil);
289 if (hitx
<> nil) then hitx
^ := ex
;
290 if (hity
<> nil) then hity
^ := ey
;
294 if (hitx
<> nil) then hitx
^ := x1
;
295 if (hity
<> nil) then hity
^ := y1
;
300 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
302 function checker (pan
: TPanel
; tag
: Integer): Boolean;
305 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
307 result := pan.Enabled; // stop if wall is enabled
312 if ((tag
and GridTagLift
) <> 0) then
314 // stop if the lift of the right type
316 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
317 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
318 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
319 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
323 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
327 tagmask
: Integer = 0;
331 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
332 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
333 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
334 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
335 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
336 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
337 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
339 if (tagmask
= 0) then exit
;// just in case
340 if ((tagmask
and GridTagLift
) <> 0) then
343 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
348 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
353 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
355 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
356 (Texture
= TEXTURE_NAME_ACID1
) or
357 (Texture
= TEXTURE_NAME_ACID2
);
360 procedure CreateDoorMap();
362 PanelArray
: Array of record
368 a
, b
, c
, m
, i
, len
: Integer;
376 SetLength(PanelArray
, len
);
378 for a
:= 0 to High(gWalls
) do
379 if gWalls
[a
].Door
then
381 PanelArray
[i
].X
:= gWalls
[a
].X
;
382 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
383 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
384 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
385 PanelArray
[i
].Active
:= True;
386 PanelArray
[i
].PanelID
:= a
;
392 SetLength(PanelArray
, len
);
403 SetLength(gDoorMap
, 0);
405 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
408 if PanelArray
[a
].Active
then
410 PanelArray
[a
].Active
:= False;
411 m
:= Length(gDoorMap
);
412 SetLength(gDoorMap
, m
+1);
413 SetLength(gDoorMap
[m
], 1);
414 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
422 if PanelArray
[b
].Active
then
423 for c
:= 0 to High(gDoorMap
[m
]) do
424 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
425 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
426 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
427 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
428 gWalls
[gDoorMap
[m
, c
]].X
,
429 gWalls
[gDoorMap
[m
, c
]].Y
,
430 gWalls
[gDoorMap
[m
, c
]].Width
,
431 gWalls
[gDoorMap
[m
, c
]].Height
) then
433 PanelArray
[b
].Active
:= False;
434 SetLength(gDoorMap
[m
],
435 Length(gDoorMap
[m
])+1);
436 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
442 g_Game_StepLoading();
448 procedure CreateLiftMap();
450 PanelArray
: Array of record
455 a
, b
, c
, len
, i
, j
: Integer;
461 len
:= Length(gLifts
);
462 SetLength(PanelArray
, len
);
464 for a
:= 0 to len
-1 do
466 PanelArray
[a
].X
:= gLifts
[a
].X
;
467 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
468 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
469 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
470 PanelArray
[a
].Active
:= True;
473 SetLength(gLiftMap
, len
);
476 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
478 for a
:= 0 to len
-1 do
479 if PanelArray
[a
].Active
then
481 PanelArray
[a
].Active
:= False;
482 SetLength(gLiftMap
[i
], 32);
490 for b
:= 0 to len
-1 do
491 if PanelArray
[b
].Active
then
493 if g_CollideAround(PanelArray
[b
].X
,
496 PanelArray
[b
].Height
,
497 PanelArray
[gLiftMap
[i
, c
]].X
,
498 PanelArray
[gLiftMap
[i
, c
]].Y
,
499 PanelArray
[gLiftMap
[i
, c
]].Width
,
500 PanelArray
[gLiftMap
[i
, c
]].Height
) then
502 PanelArray
[b
].Active
:= False;
504 if j
> High(gLiftMap
[i
]) then
505 SetLength(gLiftMap
[i
],
506 Length(gLiftMap
[i
])+32);
515 SetLength(gLiftMap
[i
], j
+1);
518 g_Game_StepLoading();
521 SetLength(gLiftMap
, i
);
526 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
527 CurTex
: Integer; sav
: Boolean): Integer;
530 panels
: ^TPanelArray
;
534 case PanelRec
.PanelType
of
535 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
538 panels
:= @gRenderBackgrounds
;
540 panels
:= @gRenderForegrounds
;
549 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
552 panels
:= @gBlockMon
;
557 len
:= Length(panels
^);
558 SetLength(panels
^, len
+ 1);
560 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
561 panels
^[len
].arrIdx
:= len
;
562 panels
^[len
].proxyId
:= -1;
563 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
565 panels
^[len
].SaveIt
:= True;
569 len
:= Length(PanelByID
);
570 SetLength(PanelByID
, len
+ 1);
571 PanelByID
[len
].PWhere
:= panels
;
572 PanelByID
[len
].PArrID
:= Result
;
575 function CreateNullTexture(RecName
: String): Integer;
577 SetLength(Textures
, Length(Textures
)+1);
578 result
:= High(Textures
);
580 with Textures
[High(Textures
)] do
582 TextureName
:= RecName
;
586 TextureID
:= TEXTURE_NONE
;
590 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
593 TextureData
: Pointer;
594 WADName
, txname
: String;
595 a
, ResLength
: Integer;
599 if Textures
<> nil then
600 for a
:= 0 to High(Textures
) do
601 if Textures
[a
].TextureName
= RecName
then
602 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
607 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
608 if (RecName
= TEXTURE_NAME_WATER
) or
609 (RecName
= TEXTURE_NAME_ACID1
) or
610 (RecName
= TEXTURE_NAME_ACID2
) then
612 SetLength(Textures
, Length(Textures
)+1);
614 with Textures
[High(Textures
)] do
616 TextureName
:= RecName
;
618 if TextureName
= TEXTURE_NAME_WATER
then
619 TextureID
:= TEXTURE_SPECIAL_WATER
621 if TextureName
= TEXTURE_NAME_ACID1
then
622 TextureID
:= TEXTURE_SPECIAL_ACID1
624 if TextureName
= TEXTURE_NAME_ACID2
then
625 TextureID
:= TEXTURE_SPECIAL_ACID2
;
630 result
:= High(Textures
);
634 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
635 WADName
:= g_ExtractWadName(RecName
);
637 WAD
:= TWADFile
.Create();
639 if WADName
<> '' then
640 WADName
:= GameDir
+'/wads/'+WADName
644 WAD
.ReadFile(WADName
);
648 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
650 FreeMem(TextureData);
651 RecName := 'COMMON\ALIEN';
655 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
657 SetLength(Textures
, Length(Textures
)+1);
658 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
660 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
661 @Textures
[High(Textures
)].Width
,
662 @Textures
[High(Textures
)].Height
);
663 FreeMem(TextureData
);
664 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
665 Textures
[High(Textures
)].Anim
:= False;
667 result
:= High(Textures
);
669 else // Íåò òàêîãî ðåóñðñà â WAD'å
671 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
674 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
675 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
682 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
685 TextureWAD
: PChar = nil;
686 TextData
: Pointer = nil;
687 TextureData
: Pointer = nil;
691 TextureResource
: String;
692 _width
, _height
, _framecount
, _speed
: Integer;
693 _backanimation
: Boolean;
695 ia
: TDynImageDataArray
= nil;
696 f
, c
, frdelay
, frloop
: Integer;
700 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
702 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
703 WADName
:= g_ExtractWadName(RecName
);
705 WAD
:= TWADFile
.Create();
707 if WADName
<> '' then
708 WADName
:= GameDir
+'/wads/'+WADName
712 WAD
.ReadFile(WADName
);
714 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
718 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
719 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
725 if WADName = Map then
727 //FreeMem(TextureWAD);
728 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
734 if ResLength
< 6 then
736 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
740 // ýòî ïòèöà? ýòî ñàìîë¸ò?
741 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
742 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
744 // íåò, ýòî ñóïåðìåí!
745 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
747 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
751 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
752 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
754 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
758 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
760 TextureResource
:= cfg
.ReadStr('', 'resource', '');
761 if TextureResource
= '' then
763 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
767 _width
:= cfg
.ReadInt('', 'framewidth', 0);
768 _height
:= cfg
.ReadInt('', 'frameheight', 0);
769 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
770 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
771 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
776 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
777 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
779 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
786 SetLength(Textures
, Length(Textures
)+1);
787 with Textures
[High(Textures
)] do
789 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
790 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
792 TextureName
:= RecName
;
796 FramesCount
:= _framecount
;
798 result
:= High(Textures
);
802 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
808 // try animated image
810 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
811 if length(imgfmt) = 0 then
813 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
817 GlobalMetadata
.ClearMetaItems();
818 GlobalMetadata
.ClearMetaItemsForSaving();
819 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
821 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
824 if length(ia
) = 0 then
826 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
833 _width
:= ia
[0].width
;
834 _height
:= ia
[0].height
;
835 _framecount
:= length(ia
);
837 _backanimation
:= false;
840 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
842 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
844 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
846 if f
< 0 then f
:= 0;
849 if c
< 13 then c
:= 0 else c
:= 1;
851 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
856 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
858 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
860 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
862 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
866 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
867 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
868 f
:= ord(_backanimation
);
869 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
);
871 SetLength(Textures
, Length(Textures
)+1);
872 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
873 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
875 Textures
[High(Textures
)].TextureName
:= RecName
;
876 Textures
[High(Textures
)].Width
:= _width
;
877 Textures
[High(Textures
)].Height
:= _height
;
878 Textures
[High(Textures
)].Anim
:= True;
879 Textures
[High(Textures
)].FramesCount
:= length(ia
);
880 Textures
[High(Textures
)].Speed
:= _speed
;
881 result
:= High(Textures
);
882 //writeln(' CREATED!');
886 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
890 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
893 if TextureWAD
<> nil then FreeMem(TextureWAD
);
894 if TextData
<> nil then FreeMem(TextData
);
895 if TextureData
<> nil then FreeMem(TextureData
);
899 procedure CreateItem(Item
: TItemRec_1
);
901 if g_Game_IsClient
then Exit
;
903 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
904 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
907 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
908 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
911 procedure CreateArea(Area
: TAreaRec_1
);
916 case Area
.AreaType
of
917 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
918 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
920 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
921 with RespawnPoints
[High(RespawnPoints
)] do
925 Direction
:= TDirection(Area
.Direction
);
927 case Area
.AreaType
of
928 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
929 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
930 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
931 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
932 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
937 AREA_REDFLAG
, AREA_BLUEFLAG
:
939 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
941 if FlagPoints
[a
] <> nil then Exit
;
945 with FlagPoints
[a
]^ do
947 X
:= Area
.X
-FLAGRECT
.X
;
948 Y
:= Area
.Y
-FLAGRECT
.Y
;
949 Direction
:= TDirection(Area
.Direction
);
955 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
956 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
959 Animation
:= TAnimation
.Create(id
, True, 8);
960 Obj
.Rect
:= FLAGRECT
;
968 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
969 with DOMFlagPoints[High(DOMFlagPoints)] do
973 Direction := TDirection(Area.Direction);
976 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
981 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
985 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
991 Width
:= Trigger
.Width
;
992 Height
:= Trigger
.Height
;
993 Enabled
:= ByteBool(Trigger
.Enabled
);
994 TexturePanel
:= Trigger
.TexturePanel
;
995 TexturePanelType
:= fTexturePanel1Type
;
996 ShotPanelType
:= fTexturePanel2Type
;
997 TriggerType
:= Trigger
.TriggerType
;
998 ActivateType
:= Trigger
.ActivateType
;
999 Keys
:= Trigger
.Keys
;
1000 Data
.Default
:= Trigger
.DATA
;
1003 g_Triggers_Create(_trigger
);
1006 procedure CreateMonster(monster
: TMonsterRec_1
);
1011 if g_Game_IsClient
then Exit
;
1013 if (gGameSettings
.GameType
= GT_SINGLE
)
1014 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1016 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1018 if gTriggers
<> nil then
1020 for a
:= 0 to High(gTriggers
) do
1022 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1024 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1029 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1033 procedure g_Map_ReAdd_DieTriggers();
1035 function monsDieTrig (mon
: TMonster
): Boolean;
1039 result
:= false; // don't stop
1040 mon
.ClearTriggers();
1041 for a
:= 0 to High(gTriggers
) do
1043 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1045 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1051 if g_Game_IsClient
then Exit
;
1053 g_Mons_ForEach(monsDieTrig
);
1056 function extractWadName(resourceName
: string): string;
1060 posN
:= Pos(':', resourceName
);
1062 Result
:= Copy(resourceName
, 0, posN
-1)
1067 procedure addResToExternalResList(res
: string);
1069 res
:= extractWadName(res
);
1070 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1071 gExternalResources
.Add(res
);
1074 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1076 textures
: TTexturesRec1Array
;
1077 mapHeader
: TMapHeaderRec_1
;
1079 resFile
: String = '';
1081 if gExternalResources
= nil then
1082 gExternalResources
:= TStringList
.Create
;
1084 gExternalResources
.Clear
;
1085 textures
:= mapReader
.GetTextures();
1086 for i
:= 0 to High(textures
) do
1088 addResToExternalResList(resFile
);
1093 mapHeader
:= mapReader
.GetMapHeader
;
1095 addResToExternalResList(mapHeader
.MusicName
);
1096 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 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, tag
);
1136 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1137 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1138 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1139 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
1141 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
])]), MSG_NOTIFY
);
1151 calcBoundingBox(gWalls
);
1152 calcBoundingBox(gRenderBackgrounds
);
1153 calcBoundingBox(gRenderForegrounds
);
1154 calcBoundingBox(gWater
);
1155 calcBoundingBox(gAcid1
);
1156 calcBoundingBox(gAcid2
);
1157 calcBoundingBox(gSteps
);
1158 calcBoundingBox(gLifts
);
1159 calcBoundingBox(gBlockMon
);
1161 e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1163 mapGrid
:= TPanelGrid
.Create(mapX0
-512, mapY0
-512, mapX1
-mapX0
+1+512*2, mapY1
-mapY0
+1+512*2);
1165 addPanelsToGrid(gWalls
, PANEL_WALL
);
1166 addPanelsToGrid(gWalls
, PANEL_CLOSEDOOR
);
1167 addPanelsToGrid(gWalls
, PANEL_OPENDOOR
);
1168 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1169 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1170 addPanelsToGrid(gWater
, PANEL_WATER
);
1171 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1172 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1173 addPanelsToGrid(gSteps
, PANEL_STEP
);
1174 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1175 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1177 mapGrid
.dumpStats();
1179 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1183 function g_Map_Load(Res
: String): Boolean;
1185 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1186 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1189 MapReader
: TMapReader_1
;
1190 Header
: TMapHeaderRec_1
;
1191 _textures
: TTexturesRec1Array
;
1192 _texnummap
: array of Integer; // `_textures` -> `Textures`
1193 panels
: TPanelsRec1Array
;
1194 items
: TItemsRec1Array
;
1195 monsters
: TMonsterRec1Array
;
1196 areas
: TAreasRec1Array
;
1197 triggers
: TTriggersRec1Array
;
1198 a
, b
, c
, k
: Integer;
1200 AddTextures
: TAddTextureArray
;
1201 texture
: TTextureRec_1
;
1202 TriggersTable
: Array of record
1203 TexturePanel
: Integer;
1208 FileName
, mapResName
, s
, TexName
: String;
1211 ok
, isAnim
, trigRef
: Boolean;
1212 CurTex
, ntn
: Integer;
1221 gMapInfo
.Map
:= Res
;
1222 TriggersTable
:= nil;
1223 FillChar(texture
, SizeOf(texture
), 0);
1225 sfsGCDisable(); // temporary disable removing of temporary volumes
1228 FileName
:= g_ExtractWadName(Res
);
1229 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1230 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1232 WAD
:= TWADFile
.Create();
1233 if not WAD
.ReadFile(FileName
) then
1235 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1239 //k8: why loader ignores path here?
1240 mapResName
:= g_ExtractFileName(Res
);
1241 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1243 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1251 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1252 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1253 MapReader
:= TMapReader_1
.Create();
1255 if not MapReader
.LoadMap(Data
) then
1257 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1264 generateExternalResourcesList(MapReader
);
1265 // Çàãðóçêà òåêñòóð:
1266 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1267 _textures
:= MapReader
.GetTextures();
1270 // Äîáàâëåíèå òåêñòóð â Textures[]:
1271 if _textures
<> nil then
1273 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1274 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1275 SetLength(_texnummap
, length(_textures
));
1277 for a
:= 0 to High(_textures
) do
1280 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1281 for b
:= 1 to Length(s
) do
1287 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1288 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1289 // Àíèìèðîâàííàÿ òåêñòóðà:
1290 if ByteBool(_textures
[a
].Anim
) then
1292 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1295 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1296 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1299 else // Îáû÷íàÿ òåêñòóðà:
1300 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1303 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1304 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1307 _texnummap
[a
] := ntn
; // fix texture number
1308 g_Game_StepLoading();
1312 // Çàãðóçêà òðèããåðîâ:
1313 gTriggerClientID
:= 0;
1314 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1315 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1316 triggers
:= MapReader
.GetTriggers();
1318 // Çàãðóçêà ïàíåëåé:
1319 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1320 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1321 panels
:= MapReader
.GetPanels();
1323 // check texture numbers for panels
1324 for a
:= 0 to High(panels
) do
1326 if panels
[a
].TextureNum
> High(_textures
) then
1328 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1332 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1335 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1336 if triggers
<> nil then
1338 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1339 SetLength(TriggersTable
, Length(triggers
));
1340 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1342 for a
:= 0 to High(TriggersTable
) do
1344 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1345 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1347 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1348 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1350 TriggersTable
[a
].LiftPanel
:= -1;
1352 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1353 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1354 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1355 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1357 TriggersTable
[a
].DoorPanel
:= -1;
1359 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1360 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1362 TriggersTable
[a
].ShotPanel
:= -1;
1364 g_Game_StepLoading();
1369 if panels
<> nil then
1371 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1372 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1374 for a
:= 0 to High(panels
) do
1376 SetLength(AddTextures
, 0);
1379 if _textures
<> nil then
1381 texture
:= _textures
[panels
[a
].TextureNum
];
1389 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1390 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1392 if (TriggersTable
<> nil) and (_textures
<> nil) then
1393 for b
:= 0 to High(TriggersTable
) do
1394 if (TriggersTable
[b
].TexturePanel
= a
)
1395 or (TriggersTable
[b
].ShotPanel
= a
) then
1404 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1406 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1409 for c
:= Len
downto 1 do
1417 // Ñïåö-òåêñòóðû çàïðåùåíû:
1418 if g_Map_IsSpecialTexture(s
) then
1421 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1422 ok
:= g_Texture_NumNameFindStart(s
);
1424 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1425 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1428 k
:= NNF_NAME_BEFORE
;
1429 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1430 while ok
or (k
= NNF_NAME_BEFORE
) or
1431 (k
= NNF_NAME_EQUALS
) do
1433 k
:= g_Texture_NumNameFindNext(TexName
);
1435 if (k
= NNF_NAME_BEFORE
) or
1436 (k
= NNF_NAME_AFTER
) then
1438 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1439 if ByteBool(texture
.Anim
) then
1440 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1442 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1444 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1446 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1450 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1452 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1454 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1456 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1460 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1463 for c
:= 0 to High(Textures
) do
1464 if Textures
[c
].TextureName
= TexName
then
1466 SetLength(AddTextures
, Length(AddTextures
)+1);
1467 AddTextures
[High(AddTextures
)].Texture
:= c
;
1468 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1474 if k
= NNF_NAME_EQUALS
then
1476 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1477 SetLength(AddTextures
, Length(AddTextures
)+1);
1478 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1479 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1480 CurTex
:= High(AddTextures
);
1488 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1489 end; // if ok - ññûëàþòñÿ òðèããåðû
1493 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1494 SetLength(AddTextures
, 1);
1495 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1496 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1500 //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);
1502 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1503 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1505 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1506 if TriggersTable
<> nil then
1507 for b
:= 0 to High(TriggersTable
) do
1509 // Òðèããåð äâåðè/ëèôòà:
1510 if (TriggersTable
[b
].LiftPanel
= a
) or
1511 (TriggersTable
[b
].DoorPanel
= a
) then
1512 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1513 // Òðèããåð ñìåíû òåêñòóðû:
1514 if TriggersTable
[b
].TexturePanel
= a
then
1515 triggers
[b
].TexturePanel
:= PanelID
;
1516 // Òðèããåð "Òóðåëü":
1517 if TriggersTable
[b
].ShotPanel
= a
then
1518 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1521 g_Game_StepLoading();
1525 // create map grid, init other grids (for monsters, for example)
1526 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1530 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1531 if (triggers
<> nil) and not gLoadGameMode
then
1533 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1534 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1535 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1536 for a
:= 0 to High(triggers
) do
1538 if triggers
[a
].TexturePanel
<> -1 then
1539 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1542 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1543 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1544 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1547 CreateTrigger(triggers
[a
], b
, c
);
1551 // Çàãðóçêà ïðåäìåòîâ:
1552 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1553 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1554 items
:= MapReader
.GetItems();
1556 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1557 if (items
<> nil) and not gLoadGameMode
then
1559 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1560 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1561 for a
:= 0 to High(items
) do
1562 CreateItem(Items
[a
]);
1565 // Çàãðóçêà îáëàñòåé:
1566 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1567 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1568 areas
:= MapReader
.GetAreas();
1570 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1571 if areas
<> nil then
1573 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1574 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1575 for a
:= 0 to High(areas
) do
1576 CreateArea(areas
[a
]);
1579 // Çàãðóçêà ìîíñòðîâ:
1580 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1581 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1582 monsters
:= MapReader
.GetMonsters();
1584 gTotalMonsters
:= 0;
1586 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1587 if (monsters
<> nil) and not gLoadGameMode
then
1589 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1590 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1591 for a
:= 0 to High(monsters
) do
1592 CreateMonster(monsters
[a
]);
1595 // Çàãðóçêà îïèñàíèÿ êàðòû:
1596 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1597 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1598 Header
:= MapReader
.GetMapHeader();
1604 Name
:= Header
.MapName
;
1605 Description
:= Header
.MapDescription
;
1606 Author
:= Header
.MapAuthor
;
1607 MusicName
:= Header
.MusicName
;
1608 SkyName
:= Header
.SkyName
;
1609 Height
:= Header
.Height
;
1610 Width
:= Header
.Width
;
1614 if gMapInfo
.SkyName
<> '' then
1616 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1617 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1618 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1620 if FileName
<> '' then
1621 FileName
:= GameDir
+'/wads/'+FileName
1624 FileName
:= g_ExtractWadName(Res
);
1627 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1628 if g_Texture_CreateWAD(BackID
, s
) then
1630 g_Game_SetupScreenSize();
1633 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1638 if gMapInfo
.MusicName
<> '' then
1640 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1641 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1642 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1644 if FileName
<> '' then
1645 FileName
:= GameDir
+'/wads/'+FileName
1648 FileName
:= g_ExtractWadName(Res
);
1651 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1652 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1655 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1658 // Îñòàëüíûå óñòàíâêè:
1666 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1667 if not gLoadGameMode
then
1670 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1676 TriggersTable
:= nil;
1679 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1680 if ok
and (not gLoadGameMode
) then
1682 gMusic
.SetByName(gMapInfo
.MusicName
);
1686 gMusic
.SetByName('');
1688 sfsGCEnable(); // enable releasing unused volumes
1691 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1695 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1698 MapReader
: TMapReader_1
;
1699 Header
: TMapHeaderRec_1
;
1704 FillChar(Result
, SizeOf(Result
), 0);
1705 FileName
:= g_ExtractWadName(Res
);
1707 WAD
:= TWADFile
.Create();
1708 if not WAD
.ReadFile(FileName
) then
1714 //k8: it ignores path again
1715 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1723 MapReader
:= TMapReader_1
.Create();
1725 if not MapReader
.LoadMap(Data
) then
1727 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1728 ZeroMemory(@Header
, SizeOf(Header
));
1729 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1730 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1734 Header
:= MapReader
.GetMapHeader();
1735 Result
.Name
:= Header
.MapName
;
1736 Result
.Description
:= Header
.MapDescription
;
1743 Result
.Author
:= Header
.MapAuthor
;
1744 Result
.Height
:= Header
.Height
;
1745 Result
.Width
:= Header
.Width
;
1748 function g_Map_GetMapsList(WADName
: string): SArray
;
1755 WAD
:= TWADFile
.Create();
1756 if not WAD
.ReadFile(WADName
) then
1761 ResList
:= WAD
.GetMapResources();
1762 if ResList
<> nil then
1764 for a
:= 0 to High(ResList
) do
1766 SetLength(Result
, Length(Result
)+1);
1767 Result
[High(Result
)] := ResList
[a
];
1773 function g_Map_Exist(Res
: string): Boolean;
1776 FileName
, mnn
: string;
1782 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1784 WAD
:= TWADFile
.Create
;
1785 if not WAD
.ReadFile(FileName
) then
1791 ResList
:= WAD
.GetMapResources();
1794 mnn
:= g_ExtractFileName(Res
);
1795 if ResList
<> nil then
1796 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1803 procedure g_Map_Free();
1807 procedure FreePanelArray(var panels
: TPanelArray
);
1812 if panels
<> nil then
1814 for i
:= 0 to High(panels
) do
1827 RespawnPoints
:= nil;
1828 if FlagPoints
[FLAG_RED
] <> nil then
1830 Dispose(FlagPoints
[FLAG_RED
]);
1831 FlagPoints
[FLAG_RED
] := nil;
1833 if FlagPoints
[FLAG_BLUE
] <> nil then
1835 Dispose(FlagPoints
[FLAG_BLUE
]);
1836 FlagPoints
[FLAG_BLUE
] := nil;
1838 //DOMFlagPoints := nil;
1842 if Textures
<> nil then
1844 for a
:= 0 to High(Textures
) do
1845 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1846 if Textures
[a
].Anim
then
1847 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1849 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1850 e_DeleteTexture(Textures
[a
].TextureID
);
1855 FreePanelArray(gWalls
);
1856 FreePanelArray(gRenderBackgrounds
);
1857 FreePanelArray(gRenderForegrounds
);
1858 FreePanelArray(gWater
);
1859 FreePanelArray(gAcid1
);
1860 FreePanelArray(gAcid2
);
1861 FreePanelArray(gSteps
);
1862 FreePanelArray(gLifts
);
1863 FreePanelArray(gBlockMon
);
1865 if BackID
<> DWORD(-1) then
1869 e_DeleteTexture(BackID
);
1870 BackID
:= DWORD(-1);
1873 g_Game_StopAllSounds(False);
1875 g_Sound_Delete(gMapInfo
.MusicName
);
1877 gMapInfo
.Name
:= '';
1878 gMapInfo
.Description
:= '';
1879 gMapInfo
.MusicName
:= '';
1880 gMapInfo
.Height
:= 0;
1881 gMapInfo
.Width
:= 0;
1889 procedure g_Map_Update();
1895 procedure UpdatePanelArray(var panels
: TPanelArray
);
1900 if panels
<> nil then
1901 for i
:= 0 to High(panels
) do
1906 UpdatePanelArray(gWalls
);
1907 UpdatePanelArray(gRenderBackgrounds
);
1908 UpdatePanelArray(gRenderForegrounds
);
1909 UpdatePanelArray(gWater
);
1910 UpdatePanelArray(gAcid1
);
1911 UpdatePanelArray(gAcid2
);
1912 UpdatePanelArray(gSteps
);
1914 if gGameSettings
.GameMode
= GM_CTF
then
1916 for a
:= FLAG_RED
to FLAG_BLUE
do
1917 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1920 if gFlags
[a
].Animation
<> nil then
1921 gFlags
[a
].Animation
.Update();
1923 m
:= g_Obj_Move(@Obj
, True, True);
1925 if gTime
mod (GAME_TICK
*2) <> 0 then
1928 // Ñîïðîòèâëåíèå âîçäóõà:
1929 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1931 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1932 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1935 gFlags
[a
].CaptureTime
:= 0;
1936 if a
= FLAG_RED
then
1937 s
:= _lc
[I_PLAYER_FLAG_RED
]
1939 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1940 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1942 if g_Game_IsNet
then
1943 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1950 // Èãðîê áåðåò ôëàã:
1951 if gPlayers
<> nil then
1953 j
:= Random(Length(gPlayers
)) - 1;
1955 for d
:= 0 to High(gPlayers
) do
1958 if j
> High(gPlayers
) then
1961 if gPlayers
[j
] <> nil then
1962 if gPlayers
[j
].Live
and
1963 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1965 if gPlayers
[j
].GetFlag(a
) then
1976 procedure g_Map_DrawPanels (PanelType
: Word);
1978 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
1982 if (panels
<> nil) then
1984 // alas, no visible set
1985 for idx
:= 0 to High(panels
) do
1987 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1994 PANEL_WALL
: DrawPanels(gWalls
);
1995 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1996 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1997 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1998 PANEL_WATER
: DrawPanels(gWater
);
1999 PANEL_ACID1
: DrawPanels(gAcid1
);
2000 PANEL_ACID2
: DrawPanels(gAcid2
);
2001 PANEL_STEP
: DrawPanels(gSteps
);
2007 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2009 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2011 result
:= false; // don't stop, ever
2012 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2013 gDrawPanelList
.insert(pan
);
2018 //tagmask := panelTypeToTag(PanelType);
2020 {if gdbg_map_use_tree_draw then
2022 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2026 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
, true);
2028 // list will be rendered in `g_game.DrawPlayer()`
2032 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2034 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2036 result
:= false; // don't stop, ever
2037 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2041 {if gdbg_map_use_tree_draw then
2043 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2047 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
), true);
2052 procedure g_Map_DrawBack(dx
, dy
: Integer);
2054 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2055 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2057 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2060 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2061 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2067 if WordBool(PanelType
and PANEL_WALL
) then
2068 if gWalls
<> nil then
2073 if gWalls
[a
].Enabled
and
2074 g_Collide(X
, Y
, Width
, Height
,
2075 gWalls
[a
].X
, gWalls
[a
].Y
,
2076 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2083 if WordBool(PanelType
and PANEL_WATER
) then
2084 if gWater
<> nil then
2089 if g_Collide(X
, Y
, Width
, Height
,
2090 gWater
[a
].X
, gWater
[a
].Y
,
2091 gWater
[a
].Width
, gWater
[a
].Height
) then
2098 if WordBool(PanelType
and PANEL_ACID1
) then
2099 if gAcid1
<> nil then
2104 if g_Collide(X
, Y
, Width
, Height
,
2105 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2106 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2113 if WordBool(PanelType
and PANEL_ACID2
) then
2114 if gAcid2
<> nil then
2119 if g_Collide(X
, Y
, Width
, Height
,
2120 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2121 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2128 if WordBool(PanelType
and PANEL_STEP
) then
2129 if gSteps
<> nil then
2134 if g_Collide(X
, Y
, Width
, Height
,
2135 gSteps
[a
].X
, gSteps
[a
].Y
,
2136 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2143 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2144 if gLifts
<> nil then
2149 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2150 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2151 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2152 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2153 g_Collide(X
, Y
, Width
, Height
,
2154 gLifts
[a
].X
, gLifts
[a
].Y
,
2155 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2162 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2163 if gBlockMon
<> nil then
2165 h
:= High(gBlockMon
);
2169 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2170 g_Collide(X
, Y
, Width
, Height
,
2171 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2172 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2180 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2184 function checkPanels (constref panels
: TPanelArray
): Boolean;
2189 if panels
= nil then exit
;
2190 for a
:= 0 to High(panels
) do
2192 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2195 texid
:= panels
[a
].GetTextureID();
2202 texid
:= TEXTURE_NONE
;
2204 if not checkPanels(gWater
) then
2205 if not checkPanels(gAcid1
) then
2206 if not checkPanels(gAcid2
) then exit
;
2211 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2213 SlowMask
= GridTagLift
or GridTagBlockMon
;
2214 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2217 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2219 result := pan.Enabled;
2224 if ((tag
and GridTagLift
) <> 0) then
2227 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2228 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2229 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2230 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2231 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2235 if ((tag
and GridTagBlockMon
) <> 0) then
2237 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2242 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2243 result
:= true; // i found her!
2247 tagmask
: Integer = 0;
2249 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2250 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2251 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2252 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2253 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2254 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2255 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2257 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2259 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2260 if gdbg_map_use_accel_coldet
then
2262 {if gdbg_map_use_tree_coldet then
2264 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2265 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2266 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2268 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2269 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2274 if (Width
= 1) and (Height
= 1) then
2276 if ((tagmask
and SlowMask
) <> 0) then
2279 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2284 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2289 if ((tagmask
and SlowMask
) <> 0) then
2292 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2297 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2304 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2306 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2310 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2312 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2315 // slightly different from the old code, but meh...
2316 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2318 result
:= false; // don't stop, ever
2319 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2322 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2323 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2324 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2327 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2329 texid
:= pan
.GetTextureID();
2330 // water? water has the highest priority, so stop right here
2331 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2333 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2335 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2339 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2340 if gdbg_map_use_accel_coldet
then
2342 texid
:= TEXTURE_NONE
;
2343 {if gdbg_map_use_tree_coldet then
2345 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2349 if (Width
= 1) and (Height
= 1) then
2351 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2355 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2362 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2364 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2368 procedure g_Map_EnableWall(ID
: DWORD
);
2373 pan
.Enabled
:= True;
2374 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2376 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2377 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2378 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2380 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2382 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2383 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
);
2387 procedure g_Map_DisableWall(ID
: DWORD
);
2392 pan
.Enabled
:= False;
2393 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2395 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2396 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2398 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2400 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2401 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
);
2405 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2410 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2413 tp
:= gRenderForegrounds
[ID
];
2415 tp
:= gRenderBackgrounds
[ID
];
2428 tp
.NextTexture(AnimLoop
);
2429 if g_Game_IsServer
and g_Game_IsNet
then
2430 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2433 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2435 if gLifts
[ID
].LiftType
= t
then
2442 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2443 //TODO: make separate lift tags, and change tag here
2445 if LiftType
= 0 then
2446 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2447 else if LiftType
= 1 then
2448 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2449 else if LiftType
= 2 then
2450 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2451 else if LiftType
= 3 then
2452 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2454 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2458 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2461 PointsArray
: Array of TRespawnPoint
;
2464 SetLength(PointsArray
, 0);
2466 if RespawnPoints
= nil then
2469 for a
:= 0 to High(RespawnPoints
) do
2470 if RespawnPoints
[a
].PointType
= PointType
then
2472 SetLength(PointsArray
, Length(PointsArray
)+1);
2473 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2476 if PointsArray
= nil then
2479 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2483 function g_Map_GetPointCount(PointType
: Byte): Word;
2489 if RespawnPoints
= nil then
2492 for a
:= 0 to High(RespawnPoints
) do
2493 if RespawnPoints
[a
].PointType
= PointType
then
2494 Result
:= Result
+ 1;
2497 function g_Map_HaveFlagPoints(): Boolean;
2499 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2502 procedure g_Map_ResetFlag(Flag
: Byte);
2504 with gFlags
[Flag
] do
2510 Direction
:= D_LEFT
;
2511 State
:= FLAG_STATE_NONE
;
2512 if FlagPoints
[Flag
] <> nil then
2514 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2515 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2516 Direction
:= FlagPoints
[Flag
]^.Direction
;
2517 State
:= FLAG_STATE_NORMAL
;
2523 procedure g_Map_DrawFlags();
2526 Mirror
: TMirrorType
;
2528 if gGameSettings
.GameMode
<> GM_CTF
then
2531 for i
:= FLAG_RED
to FLAG_BLUE
do
2533 if State
<> FLAG_STATE_CAPTURED
then
2535 if State
= FLAG_STATE_NONE
then
2538 if Direction
= D_LEFT
then
2540 Mirror
:= M_HORIZONTAL
;
2549 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2551 if g_debug_Frames
then
2553 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2555 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2556 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2562 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2569 procedure SavePanelArray(var panels
: TPanelArray
);
2571 PAMem
: TBinMemoryWriter
;
2574 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2575 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2578 while i
< Length(panels
) do
2580 if panels
[i
].SaveIt
then
2584 // Ñîõðàíÿåì ïàíåëü:
2585 panels
[i
].SaveState(PAMem
);
2590 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2591 PAMem
.SaveToMemory(Mem
);
2595 procedure SaveFlag(flag
: PFlag
);
2598 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2600 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2601 Mem
.WriteByte(flag
^.RespawnType
);
2603 Mem
.WriteByte(flag
^.State
);
2604 // Íàïðàâëåíèå ôëàãà:
2605 if flag
^.Direction
= D_LEFT
then
2611 Obj_SaveState(@flag
^.Obj
, Mem
);
2615 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2617 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2618 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2619 SavePanelArray(gWalls
);
2620 // Ñîõðàíÿåì ïàíåëè ôîíà:
2621 SavePanelArray(gRenderBackgrounds
);
2622 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2623 SavePanelArray(gRenderForegrounds
);
2624 // Ñîõðàíÿåì ïàíåëè âîäû:
2625 SavePanelArray(gWater
);
2626 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2627 SavePanelArray(gAcid1
);
2628 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2629 SavePanelArray(gAcid2
);
2630 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2631 SavePanelArray(gSteps
);
2632 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2633 SavePanelArray(gLifts
);
2636 ///// Ñîõðàíÿåì ìóçûêó: /////
2637 // Ñèãíàòóðà ìóçûêè:
2638 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2641 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2642 if gMusic
.NoMusic
then
2646 Mem
.WriteString(str
, 64);
2647 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2648 dw
:= gMusic
.GetPosition();
2650 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2651 boo
:= gMusic
.SpecPause
;
2652 Mem
.WriteBoolean(boo
);
2655 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2656 Mem
.WriteInt(gTotalMonsters
);
2659 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2660 if gGameSettings
.GameMode
= GM_CTF
then
2662 // Ôëàã Êðàñíîé êîìàíäû:
2663 SaveFlag(@gFlags
[FLAG_RED
]);
2664 // Ôëàã Ñèíåé êîìàíäû:
2665 SaveFlag(@gFlags
[FLAG_BLUE
]);
2669 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2670 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2672 // Î÷êè Êðàñíîé êîìàíäû:
2673 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2674 // Î÷êè Ñèíåé êîìàíäû:
2675 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2680 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2687 procedure LoadPanelArray(var panels
: TPanelArray
);
2689 PAMem
: TBinMemoryReader
;
2692 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2693 PAMem
:= TBinMemoryReader
.Create();
2694 PAMem
.LoadFromMemory(Mem
);
2696 for i
:= 0 to Length(panels
)-1 do
2697 if panels
[i
].SaveIt
then
2703 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2705 // Çàãðóæàåì ïàíåëü:
2706 panels
[i
].LoadState(PAMem
);
2709 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2713 procedure LoadFlag(flag
: PFlag
);
2717 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2719 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2721 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2722 Mem
.ReadByte(flag
^.RespawnType
);
2724 Mem
.ReadByte(flag
^.State
);
2725 // Íàïðàâëåíèå ôëàãà:
2728 flag
^.Direction
:= D_LEFT
2730 flag
^.Direction
:= D_RIGHT
;
2732 Obj_LoadState(@flag
^.Obj
, Mem
);
2739 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2740 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2741 LoadPanelArray(gWalls
);
2742 // Çàãðóæàåì ïàíåëè ôîíà:
2743 LoadPanelArray(gRenderBackgrounds
);
2744 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2745 LoadPanelArray(gRenderForegrounds
);
2746 // Çàãðóæàåì ïàíåëè âîäû:
2747 LoadPanelArray(gWater
);
2748 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2749 LoadPanelArray(gAcid1
);
2750 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2751 LoadPanelArray(gAcid2
);
2752 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2753 LoadPanelArray(gSteps
);
2754 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2755 LoadPanelArray(gLifts
);
2758 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2762 ///// Çàãðóæàåì ìóçûêó: /////
2763 // Ñèãíàòóðà ìóçûêè:
2765 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2767 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2770 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2771 Mem
.ReadString(str
);
2772 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2774 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2775 Mem
.ReadBoolean(boo
);
2776 // Çàïóñêàåì ýòó ìóçûêó:
2777 gMusic
.SetByName(str
);
2778 gMusic
.SpecPause
:= boo
;
2781 gMusic
.SetPosition(dw
);
2784 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2785 Mem
.ReadInt(gTotalMonsters
);
2788 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2789 if gGameSettings
.GameMode
= GM_CTF
then
2791 // Ôëàã Êðàñíîé êîìàíäû:
2792 LoadFlag(@gFlags
[FLAG_RED
]);
2793 // Ôëàã Ñèíåé êîìàíäû:
2794 LoadFlag(@gFlags
[FLAG_BLUE
]);
2798 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2799 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2801 // Î÷êè Êðàñíîé êîìàíäû:
2802 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2803 // Î÷êè Ñèíåé êîìàíäû:
2804 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2809 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2814 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2815 Arr
:= PanelByID
[PanelID
].PWhere
^;
2816 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2817 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2821 // trace liquid, stepping by `dx` and `dy`
2822 // return last seen liquid coords, and `false` if we're started outside of the liquid
2823 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2825 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2829 // started outside of the liquid?
2830 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2831 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2837 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit