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 panel or nil
96 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
97 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
99 // returns panel or nil
100 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
101 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
104 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
106 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
108 // trace liquid, stepping by `dx` and `dy`
109 // return last seen liquid coords, and `false` if we're started outside of the liquid
110 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
113 procedure g_Map_ProfilersBegin ();
114 procedure g_Map_ProfilersEnd ();
118 RESPAWNPOINT_PLAYER1
= 1;
119 RESPAWNPOINT_PLAYER2
= 2;
121 RESPAWNPOINT_RED
= 4;
122 RESPAWNPOINT_BLUE
= 5;
130 FLAG_STATE_NORMAL
= 1;
131 FLAG_STATE_DROPPED
= 2;
132 FLAG_STATE_CAPTURED
= 3;
133 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
134 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
136 FLAG_TIME
= 720; // 20 seconds
138 SKY_STRETCH
: Single = 1.5;
153 // sorted by draw priority
154 GridTagBack
= 1 shl 0;
155 GridTagStep
= 1 shl 1;
156 GridTagWall
= 1 shl 2;
157 GridTagDoor
= 1 shl 3;
158 GridTagAcid1
= 1 shl 4;
159 GridTagAcid2
= 1 shl 5;
160 GridTagWater
= 1 shl 6;
161 GridTagFore
= 1 shl 7;
162 // the following are invisible
163 GridTagLift
= 1 shl 8;
164 GridTagBlockMon
= 1 shl 9;
166 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
171 gRenderBackgrounds
: TPanelArray
;
172 gRenderForegrounds
: TPanelArray
;
173 gWater
, gAcid1
, gAcid2
: TPanelArray
;
176 gBlockMon
: TPanelArray
;
177 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
178 //gDOMFlags: array of TFlag;
181 gDoorMap
: array of array of DWORD
;
182 gLiftMap
: array of array of DWORD
;
183 gWADHash
: TMD5Digest
;
184 BackID
: DWORD
= DWORD(-1);
185 gExternalResources
: TStringList
;
187 gdbg_map_use_accel_render
: Boolean = true;
188 gdbg_map_use_accel_coldet
: Boolean = true;
189 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
190 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
193 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
197 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
200 mapGrid
: TPanelGrid
= nil;
206 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
207 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
208 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
209 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
211 ImagingTypes
, Imaging
, ImagingUtility
,
212 ImagingGif
, ImagingNetworkGraphics
;
215 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
216 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
217 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
220 function panelTypeToTag (panelType
: Word): Integer;
223 PANEL_WALL
: result
:= GridTagWall
; // gWalls
224 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
225 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
226 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
227 PANEL_WATER
: result
:= GridTagWater
; // gWater
228 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
229 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
230 PANEL_STEP
: result
:= GridTagStep
; // gSteps
231 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
232 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
233 else result
:= GridTagInvalid
;
238 function dplLess (a
, b
: TObject
): Boolean;
244 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
245 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
246 result
:= (pa
.arrIdx
< pb
.arrIdx
);
249 procedure dplClear ();
251 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
257 PWhere
: ^TPanelArray
;
262 PanelById
: array of TPanelID
;
263 Textures
: TLevelTextureArray
;
264 RespawnPoints
: Array of TRespawnPoint
;
265 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
266 //DOMFlagPoints: Array of TFlagPoint;
269 procedure g_Map_ProfilersBegin ();
271 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
272 profMapCollision
.mainBegin(g_profile_collision
);
274 if g_profile_collision
then
276 profMapCollision
.sectionBegin('*solids');
277 profMapCollision
.sectionEnd();
278 profMapCollision
.sectionBegin('liquids');
279 profMapCollision
.sectionEnd();
283 procedure g_Map_ProfilersEnd ();
285 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
289 // wall index in `gWalls` or -1
290 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
294 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
295 if (result
<> nil) then
297 if (hitx
<> nil) then hitx
^ := ex
;
298 if (hity
<> nil) then hity
^ := ey
;
302 if (hitx
<> nil) then hitx
^ := x1
;
303 if (hity
<> nil) then hity
^ := y1
;
307 // returns panel or nil
308 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
312 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
313 if (result
<> nil) then
315 if (hitx
<> nil) then hitx
^ := ex
;
316 if (hity
<> nil) then hity
^ := ey
;
320 if (hitx
<> nil) then hitx
^ := x1
;
321 if (hity
<> nil) then hity
^ := y1
;
326 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
328 function checker (pan
: TPanel
; tag
: Integer): Boolean;
331 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
333 result := pan.Enabled; // stop if wall is enabled
338 if ((tag
and GridTagLift
) <> 0) then
340 // stop if the lift of the right type
342 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
343 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
344 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
345 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
349 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
353 tagmask
: Integer = 0;
357 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
358 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
359 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
360 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
361 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
362 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
363 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
365 if (tagmask
= 0) then exit
;// just in case
366 if ((tagmask
and GridTagLift
) <> 0) then
369 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
374 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
379 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
381 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
382 (Texture
= TEXTURE_NAME_ACID1
) or
383 (Texture
= TEXTURE_NAME_ACID2
);
386 procedure CreateDoorMap();
388 PanelArray
: Array of record
394 a
, b
, c
, m
, i
, len
: Integer;
402 SetLength(PanelArray
, len
);
404 for a
:= 0 to High(gWalls
) do
405 if gWalls
[a
].Door
then
407 PanelArray
[i
].X
:= gWalls
[a
].X
;
408 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
409 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
410 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
411 PanelArray
[i
].Active
:= True;
412 PanelArray
[i
].PanelID
:= a
;
418 SetLength(PanelArray
, len
);
429 SetLength(gDoorMap
, 0);
431 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
434 if PanelArray
[a
].Active
then
436 PanelArray
[a
].Active
:= False;
437 m
:= Length(gDoorMap
);
438 SetLength(gDoorMap
, m
+1);
439 SetLength(gDoorMap
[m
], 1);
440 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
448 if PanelArray
[b
].Active
then
449 for c
:= 0 to High(gDoorMap
[m
]) do
450 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
451 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
452 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
453 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
454 gWalls
[gDoorMap
[m
, c
]].X
,
455 gWalls
[gDoorMap
[m
, c
]].Y
,
456 gWalls
[gDoorMap
[m
, c
]].Width
,
457 gWalls
[gDoorMap
[m
, c
]].Height
) then
459 PanelArray
[b
].Active
:= False;
460 SetLength(gDoorMap
[m
],
461 Length(gDoorMap
[m
])+1);
462 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
468 g_Game_StepLoading();
474 procedure CreateLiftMap();
476 PanelArray
: Array of record
481 a
, b
, c
, len
, i
, j
: Integer;
487 len
:= Length(gLifts
);
488 SetLength(PanelArray
, len
);
490 for a
:= 0 to len
-1 do
492 PanelArray
[a
].X
:= gLifts
[a
].X
;
493 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
494 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
495 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
496 PanelArray
[a
].Active
:= True;
499 SetLength(gLiftMap
, len
);
502 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
504 for a
:= 0 to len
-1 do
505 if PanelArray
[a
].Active
then
507 PanelArray
[a
].Active
:= False;
508 SetLength(gLiftMap
[i
], 32);
516 for b
:= 0 to len
-1 do
517 if PanelArray
[b
].Active
then
519 if g_CollideAround(PanelArray
[b
].X
,
522 PanelArray
[b
].Height
,
523 PanelArray
[gLiftMap
[i
, c
]].X
,
524 PanelArray
[gLiftMap
[i
, c
]].Y
,
525 PanelArray
[gLiftMap
[i
, c
]].Width
,
526 PanelArray
[gLiftMap
[i
, c
]].Height
) then
528 PanelArray
[b
].Active
:= False;
530 if j
> High(gLiftMap
[i
]) then
531 SetLength(gLiftMap
[i
],
532 Length(gLiftMap
[i
])+32);
541 SetLength(gLiftMap
[i
], j
+1);
544 g_Game_StepLoading();
547 SetLength(gLiftMap
, i
);
552 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
553 CurTex
: Integer; sav
: Boolean): Integer;
556 panels
: ^TPanelArray
;
560 case PanelRec
.PanelType
of
561 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
564 panels
:= @gRenderBackgrounds
;
566 panels
:= @gRenderForegrounds
;
575 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
578 panels
:= @gBlockMon
;
583 len
:= Length(panels
^);
584 SetLength(panels
^, len
+ 1);
586 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
587 panels
^[len
].arrIdx
:= len
;
588 panels
^[len
].proxyId
:= -1;
589 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
591 panels
^[len
].SaveIt
:= True;
595 len
:= Length(PanelByID
);
596 SetLength(PanelByID
, len
+ 1);
597 PanelByID
[len
].PWhere
:= panels
;
598 PanelByID
[len
].PArrID
:= Result
;
601 function CreateNullTexture(RecName
: String): Integer;
603 SetLength(Textures
, Length(Textures
)+1);
604 result
:= High(Textures
);
606 with Textures
[High(Textures
)] do
608 TextureName
:= RecName
;
612 TextureID
:= TEXTURE_NONE
;
616 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
619 TextureData
: Pointer;
620 WADName
, txname
: String;
621 a
, ResLength
: Integer;
625 if Textures
<> nil then
626 for a
:= 0 to High(Textures
) do
627 if Textures
[a
].TextureName
= RecName
then
628 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
633 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
634 if (RecName
= TEXTURE_NAME_WATER
) or
635 (RecName
= TEXTURE_NAME_ACID1
) or
636 (RecName
= TEXTURE_NAME_ACID2
) then
638 SetLength(Textures
, Length(Textures
)+1);
640 with Textures
[High(Textures
)] do
642 TextureName
:= RecName
;
644 if TextureName
= TEXTURE_NAME_WATER
then
645 TextureID
:= TEXTURE_SPECIAL_WATER
647 if TextureName
= TEXTURE_NAME_ACID1
then
648 TextureID
:= TEXTURE_SPECIAL_ACID1
650 if TextureName
= TEXTURE_NAME_ACID2
then
651 TextureID
:= TEXTURE_SPECIAL_ACID2
;
656 result
:= High(Textures
);
660 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
661 WADName
:= g_ExtractWadName(RecName
);
663 WAD
:= TWADFile
.Create();
665 if WADName
<> '' then
666 WADName
:= GameDir
+'/wads/'+WADName
670 WAD
.ReadFile(WADName
);
674 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
676 FreeMem(TextureData);
677 RecName := 'COMMON\ALIEN';
681 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
683 SetLength(Textures
, Length(Textures
)+1);
684 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
686 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
687 @Textures
[High(Textures
)].Width
,
688 @Textures
[High(Textures
)].Height
);
689 FreeMem(TextureData
);
690 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
691 Textures
[High(Textures
)].Anim
:= False;
693 result
:= High(Textures
);
695 else // Íåò òàêîãî ðåóñðñà â WAD'å
697 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
700 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
701 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
708 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
711 TextureWAD
: PChar = nil;
712 TextData
: Pointer = nil;
713 TextureData
: Pointer = nil;
717 TextureResource
: String;
718 _width
, _height
, _framecount
, _speed
: Integer;
719 _backanimation
: Boolean;
721 ia
: TDynImageDataArray
= nil;
722 f
, c
, frdelay
, frloop
: Integer;
726 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
728 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
729 WADName
:= g_ExtractWadName(RecName
);
731 WAD
:= TWADFile
.Create();
733 if WADName
<> '' then
734 WADName
:= GameDir
+'/wads/'+WADName
738 WAD
.ReadFile(WADName
);
740 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
744 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
745 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
751 if WADName = Map then
753 //FreeMem(TextureWAD);
754 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
760 if ResLength
< 6 then
762 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
766 // ýòî ïòèöà? ýòî ñàìîë¸ò?
767 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
768 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
770 // íåò, ýòî ñóïåðìåí!
771 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
773 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
777 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
778 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
780 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
784 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
786 TextureResource
:= cfg
.ReadStr('', 'resource', '');
787 if TextureResource
= '' then
789 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
793 _width
:= cfg
.ReadInt('', 'framewidth', 0);
794 _height
:= cfg
.ReadInt('', 'frameheight', 0);
795 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
796 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
797 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
802 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
803 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
805 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
812 SetLength(Textures
, Length(Textures
)+1);
813 with Textures
[High(Textures
)] do
815 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
816 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
818 TextureName
:= RecName
;
822 FramesCount
:= _framecount
;
824 result
:= High(Textures
);
828 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
834 // try animated image
836 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
837 if length(imgfmt) = 0 then
839 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
843 GlobalMetadata
.ClearMetaItems();
844 GlobalMetadata
.ClearMetaItemsForSaving();
845 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
847 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
850 if length(ia
) = 0 then
852 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
859 _width
:= ia
[0].width
;
860 _height
:= ia
[0].height
;
861 _framecount
:= length(ia
);
863 _backanimation
:= false;
866 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
868 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
870 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
872 if f
< 0 then f
:= 0;
875 if c
< 13 then c
:= 0 else c
:= 1;
877 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
882 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
884 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
886 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
888 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
892 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
893 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
894 f
:= ord(_backanimation
);
895 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
);
897 SetLength(Textures
, Length(Textures
)+1);
898 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
899 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
901 Textures
[High(Textures
)].TextureName
:= RecName
;
902 Textures
[High(Textures
)].Width
:= _width
;
903 Textures
[High(Textures
)].Height
:= _height
;
904 Textures
[High(Textures
)].Anim
:= True;
905 Textures
[High(Textures
)].FramesCount
:= length(ia
);
906 Textures
[High(Textures
)].Speed
:= _speed
;
907 result
:= High(Textures
);
908 //writeln(' CREATED!');
912 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
916 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
919 if TextureWAD
<> nil then FreeMem(TextureWAD
);
920 if TextData
<> nil then FreeMem(TextData
);
921 if TextureData
<> nil then FreeMem(TextureData
);
925 procedure CreateItem(Item
: TItemRec_1
);
927 if g_Game_IsClient
then Exit
;
929 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
930 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
933 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
934 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
937 procedure CreateArea(Area
: TAreaRec_1
);
942 case Area
.AreaType
of
943 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
944 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
946 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
947 with RespawnPoints
[High(RespawnPoints
)] do
951 Direction
:= TDirection(Area
.Direction
);
953 case Area
.AreaType
of
954 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
955 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
956 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
957 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
958 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
963 AREA_REDFLAG
, AREA_BLUEFLAG
:
965 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
967 if FlagPoints
[a
] <> nil then Exit
;
971 with FlagPoints
[a
]^ do
973 X
:= Area
.X
-FLAGRECT
.X
;
974 Y
:= Area
.Y
-FLAGRECT
.Y
;
975 Direction
:= TDirection(Area
.Direction
);
981 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
982 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
985 Animation
:= TAnimation
.Create(id
, True, 8);
986 Obj
.Rect
:= FLAGRECT
;
994 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
995 with DOMFlagPoints[High(DOMFlagPoints)] do
999 Direction := TDirection(Area.Direction);
1002 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1007 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1011 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1017 Width
:= Trigger
.Width
;
1018 Height
:= Trigger
.Height
;
1019 Enabled
:= ByteBool(Trigger
.Enabled
);
1020 TexturePanel
:= Trigger
.TexturePanel
;
1021 TexturePanelType
:= fTexturePanel1Type
;
1022 ShotPanelType
:= fTexturePanel2Type
;
1023 TriggerType
:= Trigger
.TriggerType
;
1024 ActivateType
:= Trigger
.ActivateType
;
1025 Keys
:= Trigger
.Keys
;
1026 Data
.Default
:= Trigger
.DATA
;
1029 g_Triggers_Create(_trigger
);
1032 procedure CreateMonster(monster
: TMonsterRec_1
);
1037 if g_Game_IsClient
then Exit
;
1039 if (gGameSettings
.GameType
= GT_SINGLE
)
1040 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1042 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1044 if gTriggers
<> nil then
1046 for a
:= 0 to High(gTriggers
) do
1048 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1050 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1055 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1059 procedure g_Map_ReAdd_DieTriggers();
1061 function monsDieTrig (mon
: TMonster
): Boolean;
1065 result
:= false; // don't stop
1066 mon
.ClearTriggers();
1067 for a
:= 0 to High(gTriggers
) do
1069 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1071 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1077 if g_Game_IsClient
then Exit
;
1079 g_Mons_ForEach(monsDieTrig
);
1082 function extractWadName(resourceName
: string): string;
1086 posN
:= Pos(':', resourceName
);
1088 Result
:= Copy(resourceName
, 0, posN
-1)
1093 procedure addResToExternalResList(res
: string);
1095 res
:= extractWadName(res
);
1096 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1097 gExternalResources
.Add(res
);
1100 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1102 textures
: TTexturesRec1Array
;
1103 mapHeader
: TMapHeaderRec_1
;
1105 resFile
: String = '';
1107 if gExternalResources
= nil then
1108 gExternalResources
:= TStringList
.Create
;
1110 gExternalResources
.Clear
;
1111 textures
:= mapReader
.GetTextures();
1112 for i
:= 0 to High(textures
) do
1114 addResToExternalResList(resFile
);
1119 mapHeader
:= mapReader
.GetMapHeader
;
1121 addResToExternalResList(mapHeader
.MusicName
);
1122 addResToExternalResList(mapHeader
.SkyName
);
1126 procedure mapCreateGrid ();
1128 mapX0
: Integer = $3fffffff;
1129 mapY0
: Integer = $3fffffff;
1130 mapX1
: Integer = -$3fffffff;
1131 mapY1
: Integer = -$3fffffff;
1133 procedure calcBoundingBox (constref panels
: TPanelArray
);
1138 for idx
:= 0 to High(panels
) do
1141 if not pan
.visvalid
then continue
;
1142 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1143 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1144 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1145 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1146 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1150 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1156 //tag := panelTypeToTag(tag);
1157 for idx
:= 0 to High(panels
) do
1160 if not pan
.visvalid
then continue
;
1161 if (pan
.proxyId
<> -1) then
1163 {$IF DEFINED(D2F_DEBUG)}
1164 e_WriteLog(Format('DUPLICATE wall #%d(%d) enabled (%d); type:%08x', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.PanelType
]), MSG_NOTIFY
);
1168 case pan
.PanelType
of
1169 PANEL_WALL
: newtag
:= GridTagWall
;
1170 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1171 PANEL_BACK
: newtag
:= GridTagBack
;
1172 PANEL_FORE
: newtag
:= GridTagFore
;
1173 PANEL_WATER
: newtag
:= GridTagWater
;
1174 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1175 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1176 PANEL_STEP
: newtag
:= GridTagStep
;
1177 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1178 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1179 else continue
; // oops
1183 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1184 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1185 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1186 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1188 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1190 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1201 calcBoundingBox(gWalls
);
1202 calcBoundingBox(gRenderBackgrounds
);
1203 calcBoundingBox(gRenderForegrounds
);
1204 calcBoundingBox(gWater
);
1205 calcBoundingBox(gAcid1
);
1206 calcBoundingBox(gAcid2
);
1207 calcBoundingBox(gSteps
);
1208 calcBoundingBox(gLifts
);
1209 calcBoundingBox(gBlockMon
);
1211 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
);
1213 if (mapX0
> 0) then mapX0
:= 0;
1214 if (mapY0
> 0) then mapY0
:= 0;
1216 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1217 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1219 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1221 addPanelsToGrid(gWalls
);
1222 addPanelsToGrid(gRenderBackgrounds
);
1223 addPanelsToGrid(gRenderForegrounds
);
1224 addPanelsToGrid(gWater
);
1225 addPanelsToGrid(gAcid1
);
1226 addPanelsToGrid(gAcid2
);
1227 addPanelsToGrid(gSteps
);
1228 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1229 addPanelsToGrid(gBlockMon
);
1231 mapGrid
.dumpStats();
1233 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1237 function g_Map_Load(Res
: String): Boolean;
1239 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1240 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1243 MapReader
: TMapReader_1
;
1244 Header
: TMapHeaderRec_1
;
1245 _textures
: TTexturesRec1Array
;
1246 _texnummap
: array of Integer; // `_textures` -> `Textures`
1247 panels
: TPanelsRec1Array
;
1248 items
: TItemsRec1Array
;
1249 monsters
: TMonsterRec1Array
;
1250 areas
: TAreasRec1Array
;
1251 triggers
: TTriggersRec1Array
;
1252 a
, b
, c
, k
: Integer;
1254 AddTextures
: TAddTextureArray
;
1255 texture
: TTextureRec_1
;
1256 TriggersTable
: Array of record
1257 TexturePanel
: Integer;
1262 FileName
, mapResName
, s
, TexName
: String;
1265 ok
, isAnim
, trigRef
: Boolean;
1266 CurTex
, ntn
: Integer;
1275 gMapInfo
.Map
:= Res
;
1276 TriggersTable
:= nil;
1277 FillChar(texture
, SizeOf(texture
), 0);
1279 sfsGCDisable(); // temporary disable removing of temporary volumes
1282 FileName
:= g_ExtractWadName(Res
);
1283 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1284 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1286 WAD
:= TWADFile
.Create();
1287 if not WAD
.ReadFile(FileName
) then
1289 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1293 //k8: why loader ignores path here?
1294 mapResName
:= g_ExtractFileName(Res
);
1295 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1297 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1305 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1306 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1307 MapReader
:= TMapReader_1
.Create();
1309 if not MapReader
.LoadMap(Data
) then
1311 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1318 generateExternalResourcesList(MapReader
);
1319 // Çàãðóçêà òåêñòóð:
1320 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1321 _textures
:= MapReader
.GetTextures();
1324 // Çàãðóçêà îïèñàíèÿ êàðòû:
1325 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1326 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1327 Header
:= MapReader
.GetMapHeader();
1331 Name
:= Header
.MapName
;
1332 Description
:= Header
.MapDescription
;
1333 Author
:= Header
.MapAuthor
;
1334 MusicName
:= Header
.MusicName
;
1335 SkyName
:= Header
.SkyName
;
1336 Height
:= Header
.Height
;
1337 Width
:= Header
.Width
;
1340 // Äîáàâëåíèå òåêñòóð â Textures[]:
1341 if _textures
<> nil then
1343 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1344 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1345 SetLength(_texnummap
, length(_textures
));
1347 for a
:= 0 to High(_textures
) do
1350 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1351 for b
:= 1 to Length(s
) do
1357 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1358 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1359 // Àíèìèðîâàííàÿ òåêñòóðà:
1360 if ByteBool(_textures
[a
].Anim
) then
1362 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1365 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1366 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1369 else // Îáû÷íàÿ òåêñòóðà:
1370 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1373 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1374 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1377 _texnummap
[a
] := ntn
; // fix texture number
1378 g_Game_StepLoading();
1382 // Çàãðóçêà òðèããåðîâ:
1383 gTriggerClientID
:= 0;
1384 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1385 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1386 triggers
:= MapReader
.GetTriggers();
1388 // Çàãðóçêà ïàíåëåé:
1389 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1390 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1391 panels
:= MapReader
.GetPanels();
1393 // check texture numbers for panels
1394 for a
:= 0 to High(panels
) do
1396 if panels
[a
].TextureNum
> High(_textures
) then
1398 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1402 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1405 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1406 if triggers
<> nil then
1408 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1409 SetLength(TriggersTable
, Length(triggers
));
1410 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1412 for a
:= 0 to High(TriggersTable
) do
1414 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1415 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1417 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1418 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1420 TriggersTable
[a
].LiftPanel
:= -1;
1422 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1423 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1424 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1425 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1427 TriggersTable
[a
].DoorPanel
:= -1;
1429 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1430 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1432 TriggersTable
[a
].ShotPanel
:= -1;
1434 g_Game_StepLoading();
1439 if panels
<> nil then
1441 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1442 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1444 for a
:= 0 to High(panels
) do
1446 SetLength(AddTextures
, 0);
1449 if _textures
<> nil then
1451 texture
:= _textures
[panels
[a
].TextureNum
];
1459 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1460 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1462 if (TriggersTable
<> nil) and (_textures
<> nil) then
1463 for b
:= 0 to High(TriggersTable
) do
1464 if (TriggersTable
[b
].TexturePanel
= a
)
1465 or (TriggersTable
[b
].ShotPanel
= a
) then
1474 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1476 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1479 for c
:= Len
downto 1 do
1487 // Ñïåö-òåêñòóðû çàïðåùåíû:
1488 if g_Map_IsSpecialTexture(s
) then
1491 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1492 ok
:= g_Texture_NumNameFindStart(s
);
1494 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1495 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1498 k
:= NNF_NAME_BEFORE
;
1499 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1500 while ok
or (k
= NNF_NAME_BEFORE
) or
1501 (k
= NNF_NAME_EQUALS
) do
1503 k
:= g_Texture_NumNameFindNext(TexName
);
1505 if (k
= NNF_NAME_BEFORE
) or
1506 (k
= NNF_NAME_AFTER
) then
1508 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1509 if ByteBool(texture
.Anim
) then
1510 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1512 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1514 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1516 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1520 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1522 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1524 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1526 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1530 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1533 for c
:= 0 to High(Textures
) do
1534 if Textures
[c
].TextureName
= TexName
then
1536 SetLength(AddTextures
, Length(AddTextures
)+1);
1537 AddTextures
[High(AddTextures
)].Texture
:= c
;
1538 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1544 if k
= NNF_NAME_EQUALS
then
1546 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1547 SetLength(AddTextures
, Length(AddTextures
)+1);
1548 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1549 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1550 CurTex
:= High(AddTextures
);
1558 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1559 end; // if ok - ññûëàþòñÿ òðèããåðû
1563 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1564 SetLength(AddTextures
, 1);
1565 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1566 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1570 //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);
1572 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1573 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1575 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1576 if TriggersTable
<> nil then
1577 for b
:= 0 to High(TriggersTable
) do
1579 // Òðèããåð äâåðè/ëèôòà:
1580 if (TriggersTable
[b
].LiftPanel
= a
) or
1581 (TriggersTable
[b
].DoorPanel
= a
) then
1582 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1583 // Òðèããåð ñìåíû òåêñòóðû:
1584 if TriggersTable
[b
].TexturePanel
= a
then
1585 triggers
[b
].TexturePanel
:= PanelID
;
1586 // Òðèããåð "Òóðåëü":
1587 if TriggersTable
[b
].ShotPanel
= a
then
1588 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1591 g_Game_StepLoading();
1595 // create map grid, init other grids (for monsters, for example)
1596 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1599 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1600 if (triggers
<> nil) and not gLoadGameMode
then
1602 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1603 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1604 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1605 for a
:= 0 to High(triggers
) do
1607 if triggers
[a
].TexturePanel
<> -1 then
1608 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1611 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1612 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1613 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1616 CreateTrigger(triggers
[a
], b
, c
);
1620 // Çàãðóçêà ïðåäìåòîâ:
1621 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1622 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1623 items
:= MapReader
.GetItems();
1625 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1626 if (items
<> nil) and not gLoadGameMode
then
1628 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1629 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1630 for a
:= 0 to High(items
) do
1631 CreateItem(Items
[a
]);
1634 // Çàãðóçêà îáëàñòåé:
1635 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1636 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1637 areas
:= MapReader
.GetAreas();
1639 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1640 if areas
<> nil then
1642 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1643 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1644 for a
:= 0 to High(areas
) do
1645 CreateArea(areas
[a
]);
1648 // Çàãðóçêà ìîíñòðîâ:
1649 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1650 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1651 monsters
:= MapReader
.GetMonsters();
1653 gTotalMonsters
:= 0;
1655 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1656 if (monsters
<> nil) and not gLoadGameMode
then
1658 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1659 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1660 for a
:= 0 to High(monsters
) do
1661 CreateMonster(monsters
[a
]);
1667 if gMapInfo
.SkyName
<> '' then
1669 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1670 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1671 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1673 if FileName
<> '' then
1674 FileName
:= GameDir
+'/wads/'+FileName
1677 FileName
:= g_ExtractWadName(Res
);
1680 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1681 if g_Texture_CreateWAD(BackID
, s
) then
1683 g_Game_SetupScreenSize();
1686 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1691 if gMapInfo
.MusicName
<> '' then
1693 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1694 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1695 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1697 if FileName
<> '' then
1698 FileName
:= GameDir
+'/wads/'+FileName
1701 FileName
:= g_ExtractWadName(Res
);
1704 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1705 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1708 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1711 // Îñòàëüíûå óñòàíâêè:
1719 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1720 if not gLoadGameMode
then
1723 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1729 TriggersTable
:= nil;
1732 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1733 if ok
and (not gLoadGameMode
) then
1735 gMusic
.SetByName(gMapInfo
.MusicName
);
1739 gMusic
.SetByName('');
1741 sfsGCEnable(); // enable releasing unused volumes
1744 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1748 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1751 MapReader
: TMapReader_1
;
1752 Header
: TMapHeaderRec_1
;
1757 FillChar(Result
, SizeOf(Result
), 0);
1758 FileName
:= g_ExtractWadName(Res
);
1760 WAD
:= TWADFile
.Create();
1761 if not WAD
.ReadFile(FileName
) then
1767 //k8: it ignores path again
1768 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1776 MapReader
:= TMapReader_1
.Create();
1778 if not MapReader
.LoadMap(Data
) then
1780 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1781 ZeroMemory(@Header
, SizeOf(Header
));
1782 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1783 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1787 Header
:= MapReader
.GetMapHeader();
1788 Result
.Name
:= Header
.MapName
;
1789 Result
.Description
:= Header
.MapDescription
;
1796 Result
.Author
:= Header
.MapAuthor
;
1797 Result
.Height
:= Header
.Height
;
1798 Result
.Width
:= Header
.Width
;
1801 function g_Map_GetMapsList(WADName
: string): SArray
;
1808 WAD
:= TWADFile
.Create();
1809 if not WAD
.ReadFile(WADName
) then
1814 ResList
:= WAD
.GetMapResources();
1815 if ResList
<> nil then
1817 for a
:= 0 to High(ResList
) do
1819 SetLength(Result
, Length(Result
)+1);
1820 Result
[High(Result
)] := ResList
[a
];
1826 function g_Map_Exist(Res
: string): Boolean;
1829 FileName
, mnn
: string;
1835 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1837 WAD
:= TWADFile
.Create
;
1838 if not WAD
.ReadFile(FileName
) then
1844 ResList
:= WAD
.GetMapResources();
1847 mnn
:= g_ExtractFileName(Res
);
1848 if ResList
<> nil then
1849 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1856 procedure g_Map_Free();
1860 procedure FreePanelArray(var panels
: TPanelArray
);
1865 if panels
<> nil then
1867 for i
:= 0 to High(panels
) do
1880 RespawnPoints
:= nil;
1881 if FlagPoints
[FLAG_RED
] <> nil then
1883 Dispose(FlagPoints
[FLAG_RED
]);
1884 FlagPoints
[FLAG_RED
] := nil;
1886 if FlagPoints
[FLAG_BLUE
] <> nil then
1888 Dispose(FlagPoints
[FLAG_BLUE
]);
1889 FlagPoints
[FLAG_BLUE
] := nil;
1891 //DOMFlagPoints := nil;
1895 if Textures
<> nil then
1897 for a
:= 0 to High(Textures
) do
1898 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1899 if Textures
[a
].Anim
then
1900 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1902 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1903 e_DeleteTexture(Textures
[a
].TextureID
);
1908 FreePanelArray(gWalls
);
1909 FreePanelArray(gRenderBackgrounds
);
1910 FreePanelArray(gRenderForegrounds
);
1911 FreePanelArray(gWater
);
1912 FreePanelArray(gAcid1
);
1913 FreePanelArray(gAcid2
);
1914 FreePanelArray(gSteps
);
1915 FreePanelArray(gLifts
);
1916 FreePanelArray(gBlockMon
);
1918 if BackID
<> DWORD(-1) then
1922 e_DeleteTexture(BackID
);
1923 BackID
:= DWORD(-1);
1926 g_Game_StopAllSounds(False);
1928 g_Sound_Delete(gMapInfo
.MusicName
);
1930 gMapInfo
.Name
:= '';
1931 gMapInfo
.Description
:= '';
1932 gMapInfo
.MusicName
:= '';
1933 gMapInfo
.Height
:= 0;
1934 gMapInfo
.Width
:= 0;
1942 procedure g_Map_Update();
1948 procedure UpdatePanelArray(var panels
: TPanelArray
);
1953 if panels
<> nil then
1954 for i
:= 0 to High(panels
) do
1959 UpdatePanelArray(gWalls
);
1960 UpdatePanelArray(gRenderBackgrounds
);
1961 UpdatePanelArray(gRenderForegrounds
);
1962 UpdatePanelArray(gWater
);
1963 UpdatePanelArray(gAcid1
);
1964 UpdatePanelArray(gAcid2
);
1965 UpdatePanelArray(gSteps
);
1967 if gGameSettings
.GameMode
= GM_CTF
then
1969 for a
:= FLAG_RED
to FLAG_BLUE
do
1970 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1973 if gFlags
[a
].Animation
<> nil then
1974 gFlags
[a
].Animation
.Update();
1976 m
:= g_Obj_Move(@Obj
, True, True);
1978 if gTime
mod (GAME_TICK
*2) <> 0 then
1981 // Ñîïðîòèâëåíèå âîçäóõà:
1982 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1984 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1985 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1988 gFlags
[a
].CaptureTime
:= 0;
1989 if a
= FLAG_RED
then
1990 s
:= _lc
[I_PLAYER_FLAG_RED
]
1992 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1993 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1995 if g_Game_IsNet
then
1996 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2003 // Èãðîê áåðåò ôëàã:
2004 if gPlayers
<> nil then
2006 j
:= Random(Length(gPlayers
)) - 1;
2008 for d
:= 0 to High(gPlayers
) do
2011 if j
> High(gPlayers
) then
2014 if gPlayers
[j
] <> nil then
2015 if gPlayers
[j
].Live
and
2016 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2018 if gPlayers
[j
].GetFlag(a
) then
2029 procedure g_Map_DrawPanels (PanelType
: Word);
2031 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2035 if (panels
<> nil) then
2037 // alas, no visible set
2038 for idx
:= 0 to High(panels
) do
2040 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2047 PANEL_WALL
: DrawPanels(gWalls
);
2048 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2049 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2050 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2051 PANEL_WATER
: DrawPanels(gWater
);
2052 PANEL_ACID1
: DrawPanels(gAcid1
);
2053 PANEL_ACID2
: DrawPanels(gAcid2
);
2054 PANEL_STEP
: DrawPanels(gSteps
);
2060 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2062 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2064 result
:= false; // don't stop, ever
2065 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2066 gDrawPanelList
.insert(pan
);
2071 //tagmask := panelTypeToTag(PanelType);
2073 {if gdbg_map_use_tree_draw then
2075 mapTree.aabbQuery(x0, y0, wdt, hgt, checker, (GridTagBack or GridTagStep or GridTagWall or GridTagDoor or GridTagAcid1 or GridTagAcid2 or GridTagWater or GridTagFore));
2079 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2081 // list will be rendered in `g_game.DrawPlayer()`
2085 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2087 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2089 result
:= false; // don't stop, ever
2090 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2094 {if gdbg_map_use_tree_draw then
2096 mapTree.aabbQuery(lightX-radius, lightY-radius, radius*2, radius*2, checker, (GridTagWall or GridTagDoor));
2100 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2105 procedure g_Map_DrawBack(dx
, dy
: Integer);
2107 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2108 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2110 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2113 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2114 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2120 if WordBool(PanelType
and PANEL_WALL
) then
2121 if gWalls
<> nil then
2126 if gWalls
[a
].Enabled
and
2127 g_Collide(X
, Y
, Width
, Height
,
2128 gWalls
[a
].X
, gWalls
[a
].Y
,
2129 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2136 if WordBool(PanelType
and PANEL_WATER
) then
2137 if gWater
<> nil then
2142 if g_Collide(X
, Y
, Width
, Height
,
2143 gWater
[a
].X
, gWater
[a
].Y
,
2144 gWater
[a
].Width
, gWater
[a
].Height
) then
2151 if WordBool(PanelType
and PANEL_ACID1
) then
2152 if gAcid1
<> nil then
2157 if g_Collide(X
, Y
, Width
, Height
,
2158 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2159 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2166 if WordBool(PanelType
and PANEL_ACID2
) then
2167 if gAcid2
<> nil then
2172 if g_Collide(X
, Y
, Width
, Height
,
2173 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2174 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2181 if WordBool(PanelType
and PANEL_STEP
) then
2182 if gSteps
<> nil then
2187 if g_Collide(X
, Y
, Width
, Height
,
2188 gSteps
[a
].X
, gSteps
[a
].Y
,
2189 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2196 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2197 if gLifts
<> nil then
2202 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2203 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2204 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2205 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2206 g_Collide(X
, Y
, Width
, Height
,
2207 gLifts
[a
].X
, gLifts
[a
].Y
,
2208 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2215 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2216 if gBlockMon
<> nil then
2218 h
:= High(gBlockMon
);
2222 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2223 g_Collide(X
, Y
, Width
, Height
,
2224 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2225 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2233 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2237 function checkPanels (constref panels
: TPanelArray
): Boolean;
2242 if panels
= nil then exit
;
2243 for a
:= 0 to High(panels
) do
2245 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2248 texid
:= panels
[a
].GetTextureID();
2255 texid
:= TEXTURE_NONE
;
2257 if not checkPanels(gWater
) then
2258 if not checkPanels(gAcid1
) then
2259 if not checkPanels(gAcid2
) then exit
;
2264 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2266 SlowMask
= GridTagLift
or GridTagBlockMon
;
2267 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2270 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2272 result := pan.Enabled;
2277 if ((tag
and GridTagLift
) <> 0) then
2280 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2281 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2282 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2283 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2284 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2288 if ((tag
and GridTagBlockMon
) <> 0) then
2290 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2295 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2296 result
:= true; // i found her!
2300 tagmask
: Integer = 0;
2302 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2303 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2304 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2305 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2306 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2307 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2308 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2310 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2312 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2313 if gdbg_map_use_accel_coldet
then
2315 {if gdbg_map_use_tree_coldet then
2317 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2318 result := (mapTree.aabbQuery(X, Y, Width, Height, checker, tagmask) <> nil);
2319 if (gdbg_map_dump_coldet_tree_queries) and (mapTree.nodesVisited <> 0) then
2321 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2322 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]));
2327 if (Width
= 1) and (Height
= 1) then
2329 if ((tagmask
and SlowMask
) <> 0) then
2332 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2337 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2342 if ((tagmask
and SlowMask
) <> 0) then
2345 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2350 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2357 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2359 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2363 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2365 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2368 // slightly different from the old code, but meh...
2369 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2371 result
:= false; // don't stop, ever
2372 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2375 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2376 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2377 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2380 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2382 texid
:= pan
.GetTextureID();
2383 // water? water has the highest priority, so stop right here
2384 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2386 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2388 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2392 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2393 if gdbg_map_use_accel_coldet
then
2395 texid
:= TEXTURE_NONE
;
2396 {if gdbg_map_use_tree_coldet then
2398 mapTree.aabbQuery(X, Y, Width, Height, checker, (GridTagWater or GridTagAcid1 or GridTagAcid2));
2402 if (Width
= 1) and (Height
= 1) then
2404 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2408 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2415 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2417 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2421 procedure g_Map_EnableWall(ID
: DWORD
);
2426 pan
.Enabled
:= True;
2427 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2429 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2430 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2431 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2433 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2435 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2436 //e_WriteLog(Format('ENABLE: 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);
2440 procedure g_Map_DisableWall(ID
: DWORD
);
2445 pan
.Enabled
:= False;
2446 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2448 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2449 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2451 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2453 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2454 //e_WriteLog(Format('DISABLE: 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);
2458 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2463 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2466 tp
:= gRenderForegrounds
[ID
];
2468 tp
:= gRenderBackgrounds
[ID
];
2481 tp
.NextTexture(AnimLoop
);
2482 if g_Game_IsServer
and g_Game_IsNet
then
2483 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2486 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2488 if gLifts
[ID
].LiftType
= t
then
2495 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2496 //TODO: make separate lift tags, and change tag here
2498 if LiftType
= 0 then
2499 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2500 else if LiftType
= 1 then
2501 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2502 else if LiftType
= 2 then
2503 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2504 else if LiftType
= 3 then
2505 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2507 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2511 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2514 PointsArray
: Array of TRespawnPoint
;
2517 SetLength(PointsArray
, 0);
2519 if RespawnPoints
= nil then
2522 for a
:= 0 to High(RespawnPoints
) do
2523 if RespawnPoints
[a
].PointType
= PointType
then
2525 SetLength(PointsArray
, Length(PointsArray
)+1);
2526 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2529 if PointsArray
= nil then
2532 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2536 function g_Map_GetPointCount(PointType
: Byte): Word;
2542 if RespawnPoints
= nil then
2545 for a
:= 0 to High(RespawnPoints
) do
2546 if RespawnPoints
[a
].PointType
= PointType
then
2547 Result
:= Result
+ 1;
2550 function g_Map_HaveFlagPoints(): Boolean;
2552 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2555 procedure g_Map_ResetFlag(Flag
: Byte);
2557 with gFlags
[Flag
] do
2563 Direction
:= D_LEFT
;
2564 State
:= FLAG_STATE_NONE
;
2565 if FlagPoints
[Flag
] <> nil then
2567 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2568 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2569 Direction
:= FlagPoints
[Flag
]^.Direction
;
2570 State
:= FLAG_STATE_NORMAL
;
2576 procedure g_Map_DrawFlags();
2579 Mirror
: TMirrorType
;
2581 if gGameSettings
.GameMode
<> GM_CTF
then
2584 for i
:= FLAG_RED
to FLAG_BLUE
do
2586 if State
<> FLAG_STATE_CAPTURED
then
2588 if State
= FLAG_STATE_NONE
then
2591 if Direction
= D_LEFT
then
2593 Mirror
:= M_HORIZONTAL
;
2602 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2604 if g_debug_Frames
then
2606 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2608 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2609 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2615 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2622 procedure SavePanelArray(var panels
: TPanelArray
);
2624 PAMem
: TBinMemoryWriter
;
2627 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2628 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2631 while i
< Length(panels
) do
2633 if panels
[i
].SaveIt
then
2637 // Ñîõðàíÿåì ïàíåëü:
2638 panels
[i
].SaveState(PAMem
);
2643 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2644 PAMem
.SaveToMemory(Mem
);
2648 procedure SaveFlag(flag
: PFlag
);
2651 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2653 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2654 Mem
.WriteByte(flag
^.RespawnType
);
2656 Mem
.WriteByte(flag
^.State
);
2657 // Íàïðàâëåíèå ôëàãà:
2658 if flag
^.Direction
= D_LEFT
then
2664 Obj_SaveState(@flag
^.Obj
, Mem
);
2668 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2670 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2671 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2672 SavePanelArray(gWalls
);
2673 // Ñîõðàíÿåì ïàíåëè ôîíà:
2674 SavePanelArray(gRenderBackgrounds
);
2675 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2676 SavePanelArray(gRenderForegrounds
);
2677 // Ñîõðàíÿåì ïàíåëè âîäû:
2678 SavePanelArray(gWater
);
2679 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2680 SavePanelArray(gAcid1
);
2681 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2682 SavePanelArray(gAcid2
);
2683 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2684 SavePanelArray(gSteps
);
2685 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2686 SavePanelArray(gLifts
);
2689 ///// Ñîõðàíÿåì ìóçûêó: /////
2690 // Ñèãíàòóðà ìóçûêè:
2691 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2694 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2695 if gMusic
.NoMusic
then
2699 Mem
.WriteString(str
, 64);
2700 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2701 dw
:= gMusic
.GetPosition();
2703 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2704 boo
:= gMusic
.SpecPause
;
2705 Mem
.WriteBoolean(boo
);
2708 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2709 Mem
.WriteInt(gTotalMonsters
);
2712 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2713 if gGameSettings
.GameMode
= GM_CTF
then
2715 // Ôëàã Êðàñíîé êîìàíäû:
2716 SaveFlag(@gFlags
[FLAG_RED
]);
2717 // Ôëàã Ñèíåé êîìàíäû:
2718 SaveFlag(@gFlags
[FLAG_BLUE
]);
2722 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2723 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2725 // Î÷êè Êðàñíîé êîìàíäû:
2726 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2727 // Î÷êè Ñèíåé êîìàíäû:
2728 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2733 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2740 procedure LoadPanelArray(var panels
: TPanelArray
);
2742 PAMem
: TBinMemoryReader
;
2745 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2746 PAMem
:= TBinMemoryReader
.Create();
2747 PAMem
.LoadFromMemory(Mem
);
2749 for i
:= 0 to Length(panels
)-1 do
2750 if panels
[i
].SaveIt
then
2756 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2758 // Çàãðóæàåì ïàíåëü:
2759 panels
[i
].LoadState(PAMem
);
2762 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2766 procedure LoadFlag(flag
: PFlag
);
2770 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2772 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2774 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2775 Mem
.ReadByte(flag
^.RespawnType
);
2777 Mem
.ReadByte(flag
^.State
);
2778 // Íàïðàâëåíèå ôëàãà:
2781 flag
^.Direction
:= D_LEFT
2783 flag
^.Direction
:= D_RIGHT
;
2785 Obj_LoadState(@flag
^.Obj
, Mem
);
2792 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2793 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2794 LoadPanelArray(gWalls
);
2795 // Çàãðóæàåì ïàíåëè ôîíà:
2796 LoadPanelArray(gRenderBackgrounds
);
2797 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2798 LoadPanelArray(gRenderForegrounds
);
2799 // Çàãðóæàåì ïàíåëè âîäû:
2800 LoadPanelArray(gWater
);
2801 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2802 LoadPanelArray(gAcid1
);
2803 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2804 LoadPanelArray(gAcid2
);
2805 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2806 LoadPanelArray(gSteps
);
2807 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2808 LoadPanelArray(gLifts
);
2811 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2815 ///// Çàãðóæàåì ìóçûêó: /////
2816 // Ñèãíàòóðà ìóçûêè:
2818 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2820 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2823 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2824 Mem
.ReadString(str
);
2825 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2827 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2828 Mem
.ReadBoolean(boo
);
2829 // Çàïóñêàåì ýòó ìóçûêó:
2830 gMusic
.SetByName(str
);
2831 gMusic
.SpecPause
:= boo
;
2834 gMusic
.SetPosition(dw
);
2837 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2838 Mem
.ReadInt(gTotalMonsters
);
2841 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2842 if gGameSettings
.GameMode
= GM_CTF
then
2844 // Ôëàã Êðàñíîé êîìàíäû:
2845 LoadFlag(@gFlags
[FLAG_RED
]);
2846 // Ôëàã Ñèíåé êîìàíäû:
2847 LoadFlag(@gFlags
[FLAG_BLUE
]);
2851 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2852 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2854 // Î÷êè Êðàñíîé êîìàíäû:
2855 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2856 // Î÷êè Ñèíåé êîìàíäû:
2857 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2862 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2867 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2868 Arr
:= PanelByID
[PanelID
].PWhere
^;
2869 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2870 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2874 // trace liquid, stepping by `dx` and `dy`
2875 // return last seen liquid coords, and `false` if we're started outside of the liquid
2876 function g_Map_TraceLiquid (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2878 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2882 // started outside of the liquid?
2883 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2884 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2890 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit