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
, MAPDEF
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
, binheap
, xprofiler
, xparser
, xdynrec
;
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(freeTextures
: Boolean=true);
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 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
89 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
91 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
93 // returns panel or nil
94 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
95 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
97 // returns panel or nil
98 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
99 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
102 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
104 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
105 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
107 // trace liquid, stepping by `dx` and `dy`
108 // return last seen liquid coords, and `false` if we're started outside of the liquid
109 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
112 procedure g_Map_ProfilersBegin ();
113 procedure g_Map_ProfilersEnd ();
116 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
124 function g_Texture_NumNameFindStart(name
: String): Boolean;
125 function g_Texture_NumNameFindNext(var newName
: String): Byte;
128 RESPAWNPOINT_PLAYER1
= 1;
129 RESPAWNPOINT_PLAYER2
= 2;
131 RESPAWNPOINT_RED
= 4;
132 RESPAWNPOINT_BLUE
= 5;
140 FLAG_STATE_NORMAL
= 1;
141 FLAG_STATE_DROPPED
= 2;
142 FLAG_STATE_CAPTURED
= 3;
143 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
144 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
146 FLAG_TIME
= 720; // 20 seconds
148 SKY_STRETCH
: Single = 1.5;
163 // sorted by draw priority
164 GridTagBack
= 1 shl 0;
165 GridTagStep
= 1 shl 1;
166 GridTagWall
= 1 shl 2;
167 GridTagDoor
= 1 shl 3;
168 GridTagAcid1
= 1 shl 4;
169 GridTagAcid2
= 1 shl 5;
170 GridTagWater
= 1 shl 6;
171 GridTagFore
= 1 shl 7;
172 // the following are invisible
173 GridTagLift
= 1 shl 8;
174 GridTagBlockMon
= 1 shl 9;
176 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
181 gRenderBackgrounds
: TPanelArray
;
182 gRenderForegrounds
: TPanelArray
;
183 gWater
, gAcid1
, gAcid2
: TPanelArray
;
186 gBlockMon
: TPanelArray
;
187 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
188 //gDOMFlags: array of TFlag;
191 gDoorMap
: array of array of DWORD
;
192 gLiftMap
: array of array of DWORD
;
193 gWADHash
: TMD5Digest
;
194 BackID
: DWORD
= DWORD(-1);
195 gExternalResources
: TStringList
;
196 gMovingWallIds
: array of Integer = nil;
198 gdbg_map_use_accel_render
: Boolean = true;
199 gdbg_map_use_accel_coldet
: Boolean = true;
200 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
201 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
203 gCurrentMap
: TDynRecord
= nil;
204 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
207 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
211 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
214 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
220 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
221 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
222 g_options
, g_triggers
, g_player
,
223 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
224 utils
, sfs
, xstreams
, hashtable
,
225 ImagingTypes
, Imaging
, ImagingUtility
,
226 ImagingGif
, ImagingNetworkGraphics
;
229 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
230 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
231 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
235 dfmapdef
: TDynMapDef
= nil;
237 procedure loadMapDefinition ();
239 pr
: TTextParser
= nil;
243 if (dfmapdef
<> nil) then exit
;
245 e_LogWritefln('parsing "mapdef.txt"...', []);
246 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
249 e_LogWritefln('local "%smapdef.txt" not found', [DataDir
]);
253 WAD
:= TWADFile
.Create();
254 if not WAD
.ReadFile(GameWAD
) then
256 //raise Exception.Create('cannot load "game.wad"');
261 st
:= WAD
.openFileStream('mapdef.txt');
267 //raise Exception.Create('cannot open "mapdef.txt"');
268 e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING
);
269 pr
:= TStrTextParser
.Create(defaultMapDef
);
273 pr
:= TFileTextParser
.Create(st
);
277 dfmapdef
:= TDynMapDef
.Create(pr
);
278 except on e
: Exception
do
279 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
287 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
289 wst
: TSFSMemoryChunkStream
= nil;
290 pr
: TTextParser
= nil;
293 if (dataLen
< 4) then exit
;
295 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
297 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
299 if (PAnsiChar(data
)[0] = 'M') and (PAnsiChar(data
)[1] = 'A') and (PAnsiChar(data
)[2] = 'P') and (PByte(data
)[3] = 1) then
303 result
:= dfmapdef
.parseBinMap(wst
);
304 except on e
: Exception
do
306 e_LogWritefln('ERROR: %s', [e
.message]);
317 pr
:= TFileTextParser
.Create(wst
);
319 result
:= dfmapdef
.parseMap(pr
);
320 except on e
: Exception
do
322 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message])
323 else e_LogWritefln('ERROR: %s', [e
.message]);
324 pr
.Free(); // will free `wst`
329 pr
.Free(); // will free `wst`
335 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
336 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
337 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
340 function g_Texture_NumNameFindStart(name
: String): Boolean;
348 NNF_CurrentNum
:= -1;
350 for i
:= Length(name
) downto 1 do
351 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
353 if i
= Length(name
) then
354 begin // Íåò öèôð â êîíöå ñòðîêè
359 NNF_PureName
:= Copy(name
, 1, i
);
365 // Íå ïåðåâåñòè â ÷èñëî:
366 if not TryStrToInt(name
, NNF_FirstNum
) then
375 function g_Texture_NumNameFindNext(var newName
: String): Byte;
377 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
380 Result
:= NNF_NO_NAME
;
384 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
386 if NNF_CurrentNum
< NNF_FirstNum
then
387 Result
:= NNF_NAME_BEFORE
389 if NNF_CurrentNum
> NNF_FirstNum
then
390 Result
:= NNF_NAME_AFTER
392 Result
:= NNF_NAME_EQUALS
;
398 function panelTypeToTag (panelType
: Word): Integer;
401 PANEL_WALL
: result
:= GridTagWall
; // gWalls
402 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
403 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
404 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
405 PANEL_WATER
: result
:= GridTagWater
; // gWater
406 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
407 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
408 PANEL_STEP
: result
:= GridTagStep
; // gSteps
409 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
410 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
411 else result
:= GridTagInvalid
;
416 function dplLess (a
, b
: TObject
): Boolean;
422 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
423 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
424 result
:= (pa
.arrIdx
< pb
.arrIdx
);
427 procedure dplClear ();
429 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
435 PWhere
: ^TPanelArray
;
440 PanelById
: array of TPanelID
;
441 Textures
: TLevelTextureArray
= nil;
442 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
443 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
444 RespawnPoints
: Array of TRespawnPoint
;
445 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
446 //DOMFlagPoints: Array of TFlagPoint;
449 procedure g_Map_ProfilersBegin ();
451 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
452 profMapCollision
.mainBegin(g_profile_collision
);
454 if g_profile_collision
then
456 profMapCollision
.sectionBegin('*solids');
457 profMapCollision
.sectionEnd();
458 profMapCollision
.sectionBegin('liquids');
459 profMapCollision
.sectionEnd();
463 procedure g_Map_ProfilersEnd ();
465 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
469 // wall index in `gWalls` or -1
470 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
474 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
475 if (result
<> nil) then
477 if (hitx
<> nil) then hitx
^ := ex
;
478 if (hity
<> nil) then hity
^ := ey
;
482 if (hitx
<> nil) then hitx
^ := x1
;
483 if (hity
<> nil) then hity
^ := y1
;
487 // returns panel or nil
488 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
492 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
493 if (result
<> nil) then
495 if (hitx
<> nil) then hitx
^ := ex
;
496 if (hity
<> nil) then hity
^ := ey
;
500 if (hitx
<> nil) then hitx
^ := x1
;
501 if (hity
<> nil) then hity
^ := y1
;
506 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
508 function checker (pan
: TPanel
; tag
: Integer): Boolean;
511 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
513 result := pan.Enabled; // stop if wall is enabled
518 if ((tag
and GridTagLift
) <> 0) then
520 // stop if the lift of the right type
522 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
523 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
524 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
525 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
529 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
533 tagmask
: Integer = 0;
537 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
538 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
539 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
540 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
541 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
542 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
543 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
545 if (tagmask
= 0) then exit
;// just in case
546 if ((tagmask
and GridTagLift
) <> 0) then
549 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
554 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
559 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
562 if (tagmask
= 0) then exit
;
563 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
567 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
569 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
570 (Texture
= TEXTURE_NAME_ACID1
) or
571 (Texture
= TEXTURE_NAME_ACID2
);
574 procedure CreateDoorMap();
576 PanelArray
: Array of record
582 a
, b
, c
, m
, i
, len
: Integer;
590 SetLength(PanelArray
, len
);
592 for a
:= 0 to High(gWalls
) do
593 if gWalls
[a
].Door
then
595 PanelArray
[i
].X
:= gWalls
[a
].X
;
596 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
597 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
598 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
599 PanelArray
[i
].Active
:= True;
600 PanelArray
[i
].PanelID
:= a
;
606 SetLength(PanelArray
, len
);
617 SetLength(gDoorMap
, 0);
619 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
622 if PanelArray
[a
].Active
then
624 PanelArray
[a
].Active
:= False;
625 m
:= Length(gDoorMap
);
626 SetLength(gDoorMap
, m
+1);
627 SetLength(gDoorMap
[m
], 1);
628 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
636 if PanelArray
[b
].Active
then
637 for c
:= 0 to High(gDoorMap
[m
]) do
638 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
639 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
640 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
641 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
642 gWalls
[gDoorMap
[m
, c
]].X
,
643 gWalls
[gDoorMap
[m
, c
]].Y
,
644 gWalls
[gDoorMap
[m
, c
]].Width
,
645 gWalls
[gDoorMap
[m
, c
]].Height
) then
647 PanelArray
[b
].Active
:= False;
648 SetLength(gDoorMap
[m
],
649 Length(gDoorMap
[m
])+1);
650 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
656 g_Game_StepLoading();
662 procedure CreateLiftMap();
664 PanelArray
: Array of record
669 a
, b
, c
, len
, i
, j
: Integer;
675 len
:= Length(gLifts
);
676 SetLength(PanelArray
, len
);
678 for a
:= 0 to len
-1 do
680 PanelArray
[a
].X
:= gLifts
[a
].X
;
681 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
682 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
683 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
684 PanelArray
[a
].Active
:= True;
687 SetLength(gLiftMap
, len
);
690 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
692 for a
:= 0 to len
-1 do
693 if PanelArray
[a
].Active
then
695 PanelArray
[a
].Active
:= False;
696 SetLength(gLiftMap
[i
], 32);
704 for b
:= 0 to len
-1 do
705 if PanelArray
[b
].Active
then
707 if g_CollideAround(PanelArray
[b
].X
,
710 PanelArray
[b
].Height
,
711 PanelArray
[gLiftMap
[i
, c
]].X
,
712 PanelArray
[gLiftMap
[i
, c
]].Y
,
713 PanelArray
[gLiftMap
[i
, c
]].Width
,
714 PanelArray
[gLiftMap
[i
, c
]].Height
) then
716 PanelArray
[b
].Active
:= False;
718 if j
> High(gLiftMap
[i
]) then
719 SetLength(gLiftMap
[i
],
720 Length(gLiftMap
[i
])+32);
729 SetLength(gLiftMap
[i
], j
+1);
732 g_Game_StepLoading();
735 SetLength(gLiftMap
, i
);
740 function CreatePanel(PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
;
741 CurTex
: Integer; sav
: Boolean): Integer;
744 panels
: ^TPanelArray
;
748 case PanelRec
.PanelType
of
749 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
752 panels
:= @gRenderBackgrounds
;
754 panels
:= @gRenderForegrounds
;
763 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
766 panels
:= @gBlockMon
;
771 len
:= Length(panels
^);
772 SetLength(panels
^, len
+ 1);
774 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
775 panels
^[len
].arrIdx
:= len
;
776 panels
^[len
].proxyId
:= -1;
777 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
779 panels
^[len
].SaveIt
:= True;
783 len
:= Length(PanelByID
);
784 SetLength(PanelByID
, len
+ 1);
785 PanelByID
[len
].PWhere
:= panels
;
786 PanelByID
[len
].PArrID
:= Result
;
790 function CreateNullTexture(RecName
: String): Integer;
792 RecName
:= toLowerCase1251(RecName
);
793 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
794 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
796 SetLength(Textures
, Length(Textures
)+1);
797 result
:= High(Textures
);
799 with Textures
[High(Textures
)] do
801 TextureName
:= RecName
;
805 TextureID
:= LongWord(TEXTURE_NONE
);
808 TextNameHash
.put(RecName
, result
);
812 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
815 TextureData
: Pointer;
817 a
, ResLength
: Integer;
819 RecName
:= toLowerCase1251(RecName
);
820 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
821 if TextNameHash
.get(RecName
, result
) then
824 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
830 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
833 if Textures <> nil then
835 for a := 0 to High(Textures) do
837 if (Textures[a].TextureName = RecName) then
838 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
839 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
847 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
848 if (RecName
= TEXTURE_NAME_WATER
) or
849 (RecName
= TEXTURE_NAME_ACID1
) or
850 (RecName
= TEXTURE_NAME_ACID2
) then
852 SetLength(Textures
, Length(Textures
)+1);
854 with Textures
[High(Textures
)] do
856 TextureName
:= RecName
;
857 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
858 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
859 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
864 result
:= High(Textures
);
865 TextNameHash
.put(RecName
, result
);
869 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
870 WADName
:= g_ExtractWadName(RecName
);
872 WAD
:= TWADFile
.Create();
874 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
876 WAD
.ReadFile(WADName
);
880 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
882 FreeMem(TextureData);
883 RecName := 'COMMON\ALIEN';
887 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
889 SetLength(Textures
, Length(Textures
)+1);
890 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
892 SetLength(Textures
, Length(Textures
)-1);
895 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
896 FreeMem(TextureData
);
897 Textures
[High(Textures
)].TextureName
:= RecName
;
898 Textures
[High(Textures
)].Anim
:= False;
900 result
:= High(Textures
);
901 TextNameHash
.put(RecName
, result
);
903 else // Íåò òàêîãî ðåóñðñà â WAD'å
905 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
906 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
907 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
909 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
910 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
912 BadTextNameHash
.put(RecName
, -1);
919 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
922 TextureWAD
: PChar = nil;
923 TextData
: Pointer = nil;
924 TextureData
: Pointer = nil;
928 TextureResource
: String;
929 _width
, _height
, _framecount
, _speed
: Integer;
930 _backanimation
: Boolean;
932 ia
: TDynImageDataArray
= nil;
933 f
, c
, frdelay
, frloop
: Integer;
935 RecName
:= toLowerCase1251(RecName
);
936 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
937 if TextNameHash
.get(RecName
, result
) then
940 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
946 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
948 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
949 if BadTextNameHash
.get(RecName
, f
) then
951 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
955 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
956 WADName
:= g_ExtractWadName(RecName
);
958 WAD
:= TWADFile
.Create();
960 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
962 WAD
.ReadFile(WADName
);
964 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
966 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
967 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
969 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
970 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
972 BadTextNameHash
.put(RecName
, -1);
977 if WADName = Map then
979 //FreeMem(TextureWAD);
980 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
986 if ResLength
< 6 then
988 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
989 BadTextNameHash
.put(RecName
, -1);
993 // ýòî ïòèöà? ýòî ñàìîë¸ò?
994 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
995 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
997 // íåò, ýòî ñóïåðìåí!
998 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1000 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1001 BadTextNameHash
.put(RecName
, -1);
1005 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1006 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1008 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1009 BadTextNameHash
.put(RecName
, -1);
1013 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1015 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1016 if TextureResource
= '' then
1018 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1019 BadTextNameHash
.put(RecName
, -1);
1023 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1024 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1025 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1026 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1027 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1032 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1033 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1035 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1036 BadTextNameHash
.put(RecName
, -1);
1043 SetLength(Textures
, Length(Textures
)+1);
1044 with Textures
[High(Textures
)] do
1046 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1047 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1049 TextureName
:= RecName
;
1053 FramesCount
:= _framecount
;
1055 result
:= High(Textures
);
1056 TextNameHash
.put(RecName
, result
);
1060 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1061 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1063 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1065 BadTextNameHash
.put(RecName
, -1);
1071 // try animated image
1073 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1074 if length(imgfmt) = 0 then
1076 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1080 GlobalMetadata
.ClearMetaItems();
1081 GlobalMetadata
.ClearMetaItemsForSaving();
1082 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1084 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1085 BadTextNameHash
.put(RecName
, -1);
1088 if length(ia
) = 0 then
1090 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1091 BadTextNameHash
.put(RecName
, -1);
1098 _width
:= ia
[0].width
;
1099 _height
:= ia
[0].height
;
1100 _framecount
:= length(ia
);
1102 _backanimation
:= false;
1105 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1107 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1109 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1111 if f
< 0 then f
:= 0;
1114 if c
< 13 then c
:= 0 else c
:= 1;
1116 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1121 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1123 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1125 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1127 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1131 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1132 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1133 f
:= ord(_backanimation
);
1134 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
);
1136 SetLength(Textures
, Length(Textures
)+1);
1137 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1138 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1140 Textures
[High(Textures
)].TextureName
:= RecName
;
1141 Textures
[High(Textures
)].Width
:= _width
;
1142 Textures
[High(Textures
)].Height
:= _height
;
1143 Textures
[High(Textures
)].Anim
:= True;
1144 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1145 Textures
[High(Textures
)].Speed
:= _speed
;
1146 result
:= High(Textures
);
1147 TextNameHash
.put(RecName
, result
);
1148 //writeln(' CREATED!');
1152 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1153 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1155 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1157 BadTextNameHash
.put(RecName
, -1);
1161 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1164 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1165 if (TextData
<> nil) then FreeMem(TextData
);
1166 if (TextureData
<> nil) then FreeMem(TextureData
);
1170 procedure CreateItem(Item
: TDynRecord
);
1172 if g_Game_IsClient
then Exit
;
1174 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1175 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1178 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1179 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1182 procedure CreateArea(Area
: TDynRecord
);
1187 case Area
.AreaType
of
1188 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1189 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1191 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1192 with RespawnPoints
[High(RespawnPoints
)] do
1196 Direction
:= TDirection(Area
.Direction
);
1198 case Area
.AreaType
of
1199 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1200 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1201 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1202 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1203 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1208 AREA_REDFLAG
, AREA_BLUEFLAG
:
1210 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1212 if FlagPoints
[a
] <> nil then Exit
;
1216 with FlagPoints
[a
]^ do
1218 X
:= Area
.X
-FLAGRECT
.X
;
1219 Y
:= Area
.Y
-FLAGRECT
.Y
;
1220 Direction
:= TDirection(Area
.Direction
);
1226 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1227 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1230 Animation
:= TAnimation
.Create(id
, True, 8);
1231 Obj
.Rect
:= FLAGRECT
;
1239 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1240 with DOMFlagPoints[High(DOMFlagPoints)] do
1244 Direction := TDirection(Area.Direction);
1247 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1252 procedure CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1256 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1260 mapId
:= Trigger
.id
;
1261 mapIndex
:= amapIdx
;
1264 Width
:= Trigger
.Width
;
1265 Height
:= Trigger
.Height
;
1266 Enabled
:= Trigger
.Enabled
;
1267 //TexturePanel := Trigger.TexturePanel;
1268 TexturePanel
:= atpanid
;
1269 TexturePanelType
:= fTexturePanel1Type
;
1270 ShotPanelType
:= fTexturePanel2Type
;
1271 TriggerType
:= Trigger
.TriggerType
;
1272 ActivateType
:= Trigger
.ActivateType
;
1273 Keys
:= Trigger
.Keys
;
1274 trigPanelId
:= atrigpanid
;
1275 //trigShotPanelId := ashotpanid;
1276 //Data.Default := Trigger.DATA;
1277 if (Trigger
.trigRec
= nil) then
1280 if (TriggerType
<> TRIGGER_SECRET
) then
1282 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1287 trigData
:= Trigger
.trigRec
.clone();
1291 g_Triggers_Create(_trigger
);
1294 procedure CreateMonster(monster
: TDynRecord
);
1299 if g_Game_IsClient
then Exit
;
1301 if (gGameSettings
.GameType
= GT_SINGLE
)
1302 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1304 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1306 if gTriggers
<> nil then
1308 for a
:= 0 to High(gTriggers
) do
1310 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1312 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1313 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1318 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1322 procedure g_Map_ReAdd_DieTriggers();
1324 function monsDieTrig (mon
: TMonster
): Boolean;
1327 //tw: TStrTextWriter;
1329 result
:= false; // don't stop
1330 mon
.ClearTriggers();
1331 for a
:= 0 to High(gTriggers
) do
1333 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1335 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1337 tw := TStrTextWriter.Create();
1339 gTriggers[a].trigData.writeTo(tw);
1340 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1345 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1351 if g_Game_IsClient
then Exit
;
1353 g_Mons_ForEach(monsDieTrig
);
1356 function extractWadName(resourceName
: string): string;
1360 posN
:= Pos(':', resourceName
);
1362 Result
:= Copy(resourceName
, 0, posN
-1)
1367 procedure addResToExternalResList(res
: string);
1369 res
:= extractWadName(res
);
1370 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1371 gExternalResources
.Add(res
);
1374 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1376 //textures: TTexturesRec1Array;
1377 //textures: TDynField;
1379 //mapHeader: TMapHeaderRec_1;
1381 //resFile: String = '';
1383 if gExternalResources
= nil then
1384 gExternalResources
:= TStringList
.Create
;
1386 gExternalResources
.Clear
;
1390 textures := GetTextures(map);
1391 for i := 0 to High(textures) do
1393 addResToExternalResList(resFile);
1397 textures := map['texture'];
1398 if (textures <> nil) then
1400 for trec in textures do
1402 addResToExternalResList(resFile);
1409 //mapHeader := GetMapHeader(map);
1411 addResToExternalResList(map
.MusicName
);
1412 addResToExternalResList(map
.SkyName
);
1416 procedure mapCreateGrid ();
1418 mapX0
: Integer = $3fffffff;
1419 mapY0
: Integer = $3fffffff;
1420 mapX1
: Integer = -$3fffffff;
1421 mapY1
: Integer = -$3fffffff;
1423 procedure calcBoundingBox (constref panels
: TPanelArray
);
1428 for idx
:= 0 to High(panels
) do
1431 if not pan
.visvalid
then continue
;
1432 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1433 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1434 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1435 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1436 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1440 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1446 //tag := panelTypeToTag(tag);
1447 for idx
:= 0 to High(panels
) do
1450 if not pan
.visvalid
then continue
;
1451 if (pan
.proxyId
<> -1) then
1453 {$IF DEFINED(D2F_DEBUG)}
1454 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
);
1458 case pan
.PanelType
of
1459 PANEL_WALL
: newtag
:= GridTagWall
;
1460 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1461 PANEL_BACK
: newtag
:= GridTagBack
;
1462 PANEL_FORE
: newtag
:= GridTagFore
;
1463 PANEL_WATER
: newtag
:= GridTagWater
;
1464 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1465 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1466 PANEL_STEP
: newtag
:= GridTagStep
;
1467 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1468 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1469 else continue
; // oops
1473 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1474 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1475 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1476 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1478 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1480 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1491 calcBoundingBox(gWalls
);
1492 calcBoundingBox(gRenderBackgrounds
);
1493 calcBoundingBox(gRenderForegrounds
);
1494 calcBoundingBox(gWater
);
1495 calcBoundingBox(gAcid1
);
1496 calcBoundingBox(gAcid2
);
1497 calcBoundingBox(gSteps
);
1498 calcBoundingBox(gLifts
);
1499 calcBoundingBox(gBlockMon
);
1501 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1503 if (mapX0
> 0) then mapX0
:= 0;
1504 if (mapY0
> 0) then mapY0
:= 0;
1506 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1507 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1509 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1510 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1512 addPanelsToGrid(gWalls
);
1513 addPanelsToGrid(gRenderBackgrounds
);
1514 addPanelsToGrid(gRenderForegrounds
);
1515 addPanelsToGrid(gWater
);
1516 addPanelsToGrid(gAcid1
);
1517 addPanelsToGrid(gAcid2
);
1518 addPanelsToGrid(gSteps
);
1519 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1520 addPanelsToGrid(gBlockMon
);
1522 mapGrid
.dumpStats();
1524 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1528 function g_Map_Load(Res
: String): Boolean;
1530 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1531 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1535 //TexturePanel: Integer;
1537 LiftPanelIdx
: Integer;
1538 DoorPanelIdx
: Integer;
1539 ShotPanelIdx
: Integer;
1540 trigrec
: TDynRecord
;
1542 liftPan
: TDynRecord
;
1543 doorPan
: TDynRecord
;
1544 shotPan
: TDynRecord
;
1548 mapReader
: TDynRecord
= nil;
1549 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1550 panels
: TDynField
= nil; //TPanelsRec1Array;
1551 items
: TDynField
= nil; //TItemsRec1Array;
1552 monsters
: TDynField
= nil; //TMonsterRec1Array;
1553 areas
: TDynField
= nil; //TAreasRec1Array;
1554 triggers
: TDynField
= nil; //TTriggersRec1Array;
1557 AddTextures
: TAddTextureArray
;
1558 TriggersTable
: array of TTRec
;
1559 FileName
, mapResName
, s
, TexName
: String;
1562 ok
, isAnim
, trigRef
: Boolean;
1563 CurTex
, ntn
: Integer;
1564 rec
, texrec
: TDynRecord
;
1566 pannum
, trignum
, cnt
, tgpid
: Integer;
1568 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1569 //moveActive: Boolean;
1578 gMapInfo
.Map
:= Res
;
1579 TriggersTable
:= nil;
1582 sfsGCDisable(); // temporary disable removing of temporary volumes
1585 FileName
:= g_ExtractWadName(Res
);
1586 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1587 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1589 WAD
:= TWADFile
.Create();
1590 if not WAD
.ReadFile(FileName
) then
1592 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1597 //k8: why loader ignores path here?
1598 mapResName
:= g_ExtractFileName(Res
);
1599 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1601 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1610 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1616 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1617 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1619 stt
:= curTimeMicro();
1622 mapReader
:= g_Map_ParseMap(Data
, Len
);
1625 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1632 generateExternalResourcesList(mapReader
);
1633 mapTextureList
:= mapReader
['texture'];
1634 // get all other lists here too
1635 panels
:= mapReader
['panel'];
1636 triggers
:= mapReader
['trigger'];
1637 items
:= mapReader
['item'];
1638 areas
:= mapReader
['area'];
1639 monsters
:= mapReader
['monster'];
1641 // Çàãðóçêà îïèñàíèÿ êàðòû:
1642 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1643 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1647 Name
:= mapReader
.MapName
;
1648 Description
:= mapReader
.MapDesc
;
1649 Author
:= mapReader
.MapAuthor
;
1650 MusicName
:= mapReader
.MusicName
;
1651 SkyName
:= mapReader
.SkyName
;
1652 Height
:= mapReader
.Height
;
1653 Width
:= mapReader
.Width
;
1656 // Çàãðóçêà òåêñòóð:
1657 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1658 // Äîáàâëåíèå òåêñòóð â Textures[]:
1659 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1661 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1662 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1665 for rec
in mapTextureList
do
1669 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1670 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1672 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1675 // Àíèìèðîâàííàÿ òåêñòóðà
1676 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1677 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1682 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1683 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1685 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1687 rec
.tagInt
:= ntn
; // remember texture number
1688 g_Game_StepLoading();
1691 // set panel tagInt to texture index
1692 if (panels
<> nil) then
1694 for rec
in panels
do
1696 texrec
:= rec
.TextureRec
;
1697 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1702 // Çàãðóçêà òðèããåðîâ
1703 gTriggerClientID
:= 0;
1704 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1705 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1708 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1709 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1711 // check texture numbers for panels
1712 if (panels
<> nil) and (panels
.count
> 0) then
1714 for rec
in panels
do
1716 if (rec
.tagInt
< 0) then
1718 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1725 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1726 if (triggers
<> nil) and (triggers
.count
> 0) then
1728 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1729 //SetLength(TriggersTable, triggers.count);
1730 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1732 for rec
in triggers
do
1734 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1735 pttit
:= @TriggersTable
[High(TriggersTable
)];
1736 pttit
.trigrec
:= rec
;
1737 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1738 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1739 pttit
.liftPan
:= nil;
1740 pttit
.doorPan
:= nil;
1741 pttit
.shotPan
:= nil;
1742 pttit
.texPanIdx
:= -1;
1743 pttit
.LiftPanelIdx
:= -1;
1744 pttit
.DoorPanelIdx
:= -1;
1745 pttit
.ShotPanelIdx
:= -1;
1747 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1749 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1752 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1754 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1757 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1759 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1762 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1763 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1764 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1765 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1767 g_Game_StepLoading();
1772 if (panels
<> nil) and (panels
.count
> 0) then
1774 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1775 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1778 for rec
in panels
do
1781 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1783 SetLength(AddTextures
, 0);
1788 if (mapTextureList
<> nil) then
1790 texrec
:= rec
.TextureRec
;
1791 ok
:= (texrec
<> nil);
1796 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1797 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1799 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1802 for b := 0 to High(TriggersTable) do
1804 if (TriggersTable[b].texPan = rec) or (TriggersTable[b].shotPan = rec) then
1812 if rec
.userPanelTrigRef
then
1814 // e_LogWritefln('trigref for panel %s', [pannum]);
1823 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1824 s
:= texrec
.Resource
;
1826 // Ñïåö-òåêñòóðû çàïðåùåíû
1827 if g_Map_IsSpecialTexture(s
) then
1833 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1834 ok
:= g_Texture_NumNameFindStart(s
);
1837 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1838 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1841 k
:= NNF_NAME_BEFORE
;
1842 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1843 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1845 k
:= g_Texture_NumNameFindNext(TexName
);
1847 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1849 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1852 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1854 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1855 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1856 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1859 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1861 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1862 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1863 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1868 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1870 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1871 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1872 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1875 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1877 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1878 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1879 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1883 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1887 for c := 0 to High(Textures) do
1889 if (Textures[c].TextureName = TexName) then
1891 SetLength(AddTextures, Length(AddTextures)+1);
1892 AddTextures[High(AddTextures)].Texture := c;
1893 AddTextures[High(AddTextures)].Anim := isAnim;
1898 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1900 SetLength(AddTextures
, Length(AddTextures
)+1);
1901 AddTextures
[High(AddTextures
)].Texture
:= c
;
1902 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1908 if k
= NNF_NAME_EQUALS
then
1910 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1911 SetLength(AddTextures
, Length(AddTextures
)+1);
1912 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1913 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1914 CurTex
:= High(AddTextures
);
1925 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1926 end; // if ok - ññûëàþòñÿ òðèããåðû
1930 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1931 SetLength(AddTextures
, 1);
1932 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1933 AddTextures
[0].Anim
:= false;
1934 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1938 //e_WriteLog(Format('panel #%d: TextureNum=%d; ht=%d; ht1=%d; atl=%d', [a, panels[a].TextureNum, High(mapTextureList), High(Textures), High(AddTextures)]), MSG_NOTIFY);
1940 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1942 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð
1943 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
, trigRef
);
1944 //e_LogWritefln('panel #%s of type %s got id #%s', [pannum, rec.PanelType, PanelID]);
1945 // set 'gamePanelId' field to panel id
1946 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
1949 moveSpeed
:= rec
.moveSpeed
;
1950 //moveStart := rec.moveStart;
1951 //moveEnd := rec.moveEnd;
1952 //moveActive := rec['move_active'].varvalue;
1953 if not moveSpeed
.isZero
then
1955 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
1956 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
1957 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
1960 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
1962 g_Game_StepLoading();
1966 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
1967 for b
:= 0 to High(TriggersTable
) do
1969 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
1970 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
1971 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
1972 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
1975 // create map grid, init other grids (for monsters, for example)
1976 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1979 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
1980 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
1982 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
1983 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1984 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
1986 for rec
in triggers
do
1989 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
1990 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
1991 // we can have only one of those
1992 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
1993 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
1994 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
1996 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
1997 CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
2001 // Çàãðóçêà ïðåäìåòîâ
2002 e_WriteLog(' Loading items...', MSG_NOTIFY
);
2003 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2005 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2006 if (items
<> nil) and not gLoadGameMode
then
2008 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
2009 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2010 for rec
in items
do CreateItem(rec
);
2013 // Çàãðóçêà îáëàñòåé
2014 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2015 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2017 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2018 if areas
<> nil then
2020 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2021 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2022 for rec
in areas
do CreateArea(rec
);
2025 // Çàãðóçêà ìîíñòðîâ
2026 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2027 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2029 gTotalMonsters
:= 0;
2031 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2032 if (monsters
<> nil) and not gLoadGameMode
then
2034 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2035 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2036 for rec
in monsters
do CreateMonster(rec
);
2039 gCurrentMap
:= mapReader
; // this will be our current map now
2040 gCurrentMapFileName
:= Res
;
2044 if gMapInfo
.SkyName
<> '' then
2046 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2047 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2048 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2050 if FileName
<> '' then
2051 FileName
:= GameDir
+'/wads/'+FileName
2054 FileName
:= g_ExtractWadName(Res
);
2057 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2058 if g_Texture_CreateWAD(BackID
, s
) then
2060 g_Game_SetupScreenSize();
2063 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2068 if gMapInfo
.MusicName
<> '' then
2070 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2071 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2072 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2074 if FileName
<> '' then
2075 FileName
:= GameDir
+'/wads/'+FileName
2078 FileName
:= g_ExtractWadName(Res
);
2081 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2082 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2085 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2088 // Îñòàëüíûå óñòàíâêè
2096 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2097 if not gLoadGameMode
then g_GFX_Init();
2099 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2100 mapTextureList
:= nil;
2105 TriggersTable
:= nil;
2108 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2109 if ok
and (not gLoadGameMode
) then
2111 gMusic
.SetByName(gMapInfo
.MusicName
);
2116 gMusic
.SetByName('');
2119 stt
:= curTimeMicro()-stt
;
2120 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2122 sfsGCEnable(); // enable releasing unused volumes
2124 e_ClearInputBuffer(); // why not?
2127 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2132 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2135 mapReader
: TDynRecord
;
2136 //Header: TMapHeaderRec_1;
2141 FillChar(Result
, SizeOf(Result
), 0);
2142 FileName
:= g_ExtractWadName(Res
);
2144 WAD
:= TWADFile
.Create();
2145 if not WAD
.ReadFile(FileName
) then
2151 //k8: it ignores path again
2152 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2161 mapReader
:= g_Map_ParseMap(Data
, Len
);
2168 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2170 Result
.Name
:= mapReader
.MapName
;
2171 Result
.Description
:= mapReader
.MapDesc
;
2173 Result
.Author
:= mapReader
.MapAuthor
;
2174 Result
.Height
:= mapReader
.Height
;
2175 Result
.Width
:= mapReader
.Width
;
2179 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2180 //ZeroMemory(@Header, SizeOf(Header));
2181 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2182 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2184 Result
.Author
:= '';
2192 function g_Map_GetMapsList(WADName
: string): SArray
;
2199 WAD
:= TWADFile
.Create();
2200 if not WAD
.ReadFile(WADName
) then
2205 ResList
:= WAD
.GetMapResources();
2206 if ResList
<> nil then
2208 for a
:= 0 to High(ResList
) do
2210 SetLength(Result
, Length(Result
)+1);
2211 Result
[High(Result
)] := ResList
[a
];
2217 function g_Map_Exist(Res
: string): Boolean;
2220 FileName
, mnn
: string;
2226 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2228 WAD
:= TWADFile
.Create
;
2229 if not WAD
.ReadFile(FileName
) then
2235 ResList
:= WAD
.GetMapResources();
2238 mnn
:= g_ExtractFileName(Res
);
2239 if ResList
<> nil then
2240 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2247 procedure g_Map_Free(freeTextures
: Boolean=true);
2251 procedure FreePanelArray(var panels
: TPanelArray
);
2256 if panels
<> nil then
2258 for i
:= 0 to High(panels
) do
2271 RespawnPoints
:= nil;
2272 if FlagPoints
[FLAG_RED
] <> nil then
2274 Dispose(FlagPoints
[FLAG_RED
]);
2275 FlagPoints
[FLAG_RED
] := nil;
2277 if FlagPoints
[FLAG_BLUE
] <> nil then
2279 Dispose(FlagPoints
[FLAG_BLUE
]);
2280 FlagPoints
[FLAG_BLUE
] := nil;
2282 //DOMFlagPoints := nil;
2286 if (Length(gCurrentMapFileName
) <> 0) then
2288 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2292 e_LogWritefln('g_Map_Free: no previous map.', []);
2294 if freeTextures
then
2296 e_LogWritefln('g_Map_Free: clearing textures...', []);
2297 if (Textures
<> nil) then
2299 for a
:= 0 to High(Textures
) do
2301 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2303 if Textures
[a
].Anim
then
2305 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2309 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2311 e_DeleteTexture(Textures
[a
].TextureID
);
2318 TextNameHash
.Free();
2319 TextNameHash
:= nil;
2320 BadTextNameHash
.Free();
2321 BadTextNameHash
:= nil;
2324 FreePanelArray(gWalls
);
2325 FreePanelArray(gRenderBackgrounds
);
2326 FreePanelArray(gRenderForegrounds
);
2327 FreePanelArray(gWater
);
2328 FreePanelArray(gAcid1
);
2329 FreePanelArray(gAcid2
);
2330 FreePanelArray(gSteps
);
2331 FreePanelArray(gLifts
);
2332 FreePanelArray(gBlockMon
);
2333 gMovingWallIds
:= nil;
2335 if BackID
<> DWORD(-1) then
2339 e_DeleteTexture(BackID
);
2340 BackID
:= DWORD(-1);
2343 g_Game_StopAllSounds(False);
2345 g_Sound_Delete(gMapInfo
.MusicName
);
2347 gMapInfo
.Name
:= '';
2348 gMapInfo
.Description
:= '';
2349 gMapInfo
.MusicName
:= '';
2350 gMapInfo
.Height
:= 0;
2351 gMapInfo
.Width
:= 0;
2359 procedure g_Map_Update();
2365 procedure UpdatePanelArray(var panels
: TPanelArray
);
2370 for i
:= 0 to High(panels
) do panels
[i
].Update();
2374 UpdatePanelArray(gWalls
);
2375 UpdatePanelArray(gRenderBackgrounds
);
2376 UpdatePanelArray(gRenderForegrounds
);
2377 UpdatePanelArray(gWater
);
2378 UpdatePanelArray(gAcid1
);
2379 UpdatePanelArray(gAcid2
);
2380 UpdatePanelArray(gSteps
);
2382 if gGameSettings
.GameMode
= GM_CTF
then
2384 for a
:= FLAG_RED
to FLAG_BLUE
do
2385 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2388 if gFlags
[a
].Animation
<> nil then
2389 gFlags
[a
].Animation
.Update();
2391 m
:= g_Obj_Move(@Obj
, True, True);
2393 if gTime
mod (GAME_TICK
*2) <> 0 then
2396 // Ñîïðîòèâëåíèå âîçäóõà:
2397 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2399 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
2400 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2403 gFlags
[a
].CaptureTime
:= 0;
2404 if a
= FLAG_RED
then
2405 s
:= _lc
[I_PLAYER_FLAG_RED
]
2407 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2408 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2410 if g_Game_IsNet
then
2411 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2418 // Èãðîê áåðåò ôëàã:
2419 if gPlayers
<> nil then
2421 j
:= Random(Length(gPlayers
)) - 1;
2423 for d
:= 0 to High(gPlayers
) do
2426 if j
> High(gPlayers
) then
2429 if gPlayers
[j
] <> nil then
2430 if gPlayers
[j
].Live
and
2431 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2433 if gPlayers
[j
].GetFlag(a
) then
2444 procedure g_Map_DrawPanels (PanelType
: Word);
2446 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2450 if (panels
<> nil) then
2452 // alas, no visible set
2453 for idx
:= 0 to High(panels
) do
2455 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2462 PANEL_WALL
: DrawPanels(gWalls
);
2463 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2464 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2465 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2466 PANEL_WATER
: DrawPanels(gWater
);
2467 PANEL_ACID1
: DrawPanels(gAcid1
);
2468 PANEL_ACID2
: DrawPanels(gAcid2
);
2469 PANEL_STEP
: DrawPanels(gSteps
);
2475 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2477 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2479 result
:= false; // don't stop, ever
2480 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2481 gDrawPanelList
.insert(pan
);
2486 //tagmask := panelTypeToTag(PanelType);
2487 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2488 // list will be rendered in `g_game.DrawPlayer()`
2492 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2494 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2496 result
:= false; // don't stop, ever
2497 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2501 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2505 procedure g_Map_DrawBack(dx
, dy
: Integer);
2507 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2508 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2510 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2513 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2514 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2520 if WordBool(PanelType
and PANEL_WALL
) then
2521 if gWalls
<> nil then
2526 if gWalls
[a
].Enabled
and
2527 g_Collide(X
, Y
, Width
, Height
,
2528 gWalls
[a
].X
, gWalls
[a
].Y
,
2529 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2536 if WordBool(PanelType
and PANEL_WATER
) then
2537 if gWater
<> nil then
2542 if g_Collide(X
, Y
, Width
, Height
,
2543 gWater
[a
].X
, gWater
[a
].Y
,
2544 gWater
[a
].Width
, gWater
[a
].Height
) then
2551 if WordBool(PanelType
and PANEL_ACID1
) then
2552 if gAcid1
<> nil then
2557 if g_Collide(X
, Y
, Width
, Height
,
2558 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2559 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2566 if WordBool(PanelType
and PANEL_ACID2
) then
2567 if gAcid2
<> nil then
2572 if g_Collide(X
, Y
, Width
, Height
,
2573 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2574 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2581 if WordBool(PanelType
and PANEL_STEP
) then
2582 if gSteps
<> nil then
2587 if g_Collide(X
, Y
, Width
, Height
,
2588 gSteps
[a
].X
, gSteps
[a
].Y
,
2589 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2596 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2597 if gLifts
<> nil then
2602 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2603 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2604 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2605 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2606 g_Collide(X
, Y
, Width
, Height
,
2607 gLifts
[a
].X
, gLifts
[a
].Y
,
2608 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2615 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2616 if gBlockMon
<> nil then
2618 h
:= High(gBlockMon
);
2622 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2623 g_Collide(X
, Y
, Width
, Height
,
2624 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2625 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2633 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2637 function checkPanels (constref panels
: TPanelArray
): Boolean;
2642 if panels
= nil then exit
;
2643 for a
:= 0 to High(panels
) do
2645 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2648 texid
:= panels
[a
].GetTextureID();
2655 texid
:= LongWord(TEXTURE_NONE
);
2657 if not checkPanels(gWater
) then
2658 if not checkPanels(gAcid1
) then
2659 if not checkPanels(gAcid2
) then exit
;
2664 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2666 SlowMask
= GridTagLift
or GridTagBlockMon
;
2667 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2670 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2672 result := pan.Enabled;
2677 if ((tag
and GridTagLift
) <> 0) then
2680 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2681 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2682 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2683 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2684 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2688 if ((tag
and GridTagBlockMon
) <> 0) then
2690 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2695 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2696 result
:= true; // i found her!
2700 tagmask
: Integer = 0;
2702 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2703 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2704 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2705 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2706 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2707 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2708 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2710 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2712 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2713 if gdbg_map_use_accel_coldet
then
2715 if (Width
= 1) and (Height
= 1) then
2717 if ((tagmask
and SlowMask
) <> 0) then
2720 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2725 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2730 if ((tagmask
and SlowMask
) <> 0) then
2733 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2738 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2744 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2746 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2750 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2752 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2755 // slightly different from the old code, but meh...
2756 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2758 result
:= false; // don't stop, ever
2759 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2762 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2763 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2764 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2767 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2769 texid
:= pan
.GetTextureID();
2770 // water? water has the highest priority, so stop right here
2771 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2773 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2775 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2779 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2780 if gdbg_map_use_accel_coldet
then
2782 texid
:= LongWord(TEXTURE_NONE
);
2783 if (Width
= 1) and (Height
= 1) then
2785 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2789 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2795 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2797 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2801 procedure g_Map_EnableWall(ID
: DWORD
);
2806 pan
.Enabled
:= True;
2807 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2809 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2810 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2811 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2813 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2815 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2816 //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);
2820 procedure g_Map_DisableWall(ID
: DWORD
);
2825 pan
.Enabled
:= False;
2826 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2828 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2829 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2831 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2833 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2834 //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);
2838 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2843 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2846 tp
:= gRenderForegrounds
[ID
];
2848 tp
:= gRenderBackgrounds
[ID
];
2861 tp
.NextTexture(AnimLoop
);
2862 if g_Game_IsServer
and g_Game_IsNet
then
2863 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2866 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2868 if gLifts
[ID
].LiftType
= t
then
2875 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2876 //TODO: make separate lift tags, and change tag here
2878 if LiftType
= 0 then
2879 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2880 else if LiftType
= 1 then
2881 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2882 else if LiftType
= 2 then
2883 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2884 else if LiftType
= 3 then
2885 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2887 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2891 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2894 PointsArray
: Array of TRespawnPoint
;
2897 SetLength(PointsArray
, 0);
2899 if RespawnPoints
= nil then
2902 for a
:= 0 to High(RespawnPoints
) do
2903 if RespawnPoints
[a
].PointType
= PointType
then
2905 SetLength(PointsArray
, Length(PointsArray
)+1);
2906 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2909 if PointsArray
= nil then
2912 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2916 function g_Map_GetPointCount(PointType
: Byte): Word;
2922 if RespawnPoints
= nil then
2925 for a
:= 0 to High(RespawnPoints
) do
2926 if RespawnPoints
[a
].PointType
= PointType
then
2927 Result
:= Result
+ 1;
2930 function g_Map_HaveFlagPoints(): Boolean;
2932 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2935 procedure g_Map_ResetFlag(Flag
: Byte);
2937 with gFlags
[Flag
] do
2943 Direction
:= D_LEFT
;
2944 State
:= FLAG_STATE_NONE
;
2945 if FlagPoints
[Flag
] <> nil then
2947 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2948 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2949 Direction
:= FlagPoints
[Flag
]^.Direction
;
2950 State
:= FLAG_STATE_NORMAL
;
2956 procedure g_Map_DrawFlags();
2959 Mirror
: TMirrorType
;
2961 if gGameSettings
.GameMode
<> GM_CTF
then
2964 for i
:= FLAG_RED
to FLAG_BLUE
do
2966 if State
<> FLAG_STATE_CAPTURED
then
2968 if State
= FLAG_STATE_NONE
then
2971 if Direction
= D_LEFT
then
2973 Mirror
:= M_HORIZONTAL
;
2982 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2984 if g_debug_Frames
then
2986 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2988 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2989 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2995 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
3002 procedure SavePanelArray(var panels
: TPanelArray
);
3004 PAMem
: TBinMemoryWriter
;
3007 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
3008 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
3011 while i
< Length(panels
) do
3013 if panels
[i
].SaveIt
then
3017 // Ñîõðàíÿåì ïàíåëü:
3018 panels
[i
].SaveState(PAMem
);
3023 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
3024 PAMem
.SaveToMemory(Mem
);
3028 procedure SaveFlag(flag
: PFlag
);
3031 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3033 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3034 Mem
.WriteByte(flag
^.RespawnType
);
3036 Mem
.WriteByte(flag
^.State
);
3037 // Íàïðàâëåíèå ôëàãà:
3038 if flag
^.Direction
= D_LEFT
then
3044 Obj_SaveState(@flag
^.Obj
, Mem
);
3048 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3050 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3051 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
3052 SavePanelArray(gWalls
);
3053 // Ñîõðàíÿåì ïàíåëè ôîíà:
3054 SavePanelArray(gRenderBackgrounds
);
3055 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
3056 SavePanelArray(gRenderForegrounds
);
3057 // Ñîõðàíÿåì ïàíåëè âîäû:
3058 SavePanelArray(gWater
);
3059 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
3060 SavePanelArray(gAcid1
);
3061 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
3062 SavePanelArray(gAcid2
);
3063 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
3064 SavePanelArray(gSteps
);
3065 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
3066 SavePanelArray(gLifts
);
3069 ///// Ñîõðàíÿåì ìóçûêó: /////
3070 // Ñèãíàòóðà ìóçûêè:
3071 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3074 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3075 if gMusic
.NoMusic
then
3079 Mem
.WriteString(str
, 64);
3080 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3081 dw
:= gMusic
.GetPosition();
3083 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3084 boo
:= gMusic
.SpecPause
;
3085 Mem
.WriteBoolean(boo
);
3088 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3089 Mem
.WriteInt(gTotalMonsters
);
3092 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3093 if gGameSettings
.GameMode
= GM_CTF
then
3095 // Ôëàã Êðàñíîé êîìàíäû:
3096 SaveFlag(@gFlags
[FLAG_RED
]);
3097 // Ôëàã Ñèíåé êîìàíäû:
3098 SaveFlag(@gFlags
[FLAG_BLUE
]);
3102 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3103 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3105 // Î÷êè Êðàñíîé êîìàíäû:
3106 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3107 // Î÷êè Ñèíåé êîìàíäû:
3108 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3113 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
3120 procedure LoadPanelArray(var panels
: TPanelArray
);
3122 PAMem
: TBinMemoryReader
;
3125 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
3126 PAMem
:= TBinMemoryReader
.Create();
3127 PAMem
.LoadFromMemory(Mem
);
3129 for i
:= 0 to Length(panels
)-1 do
3131 if panels
[i
].SaveIt
then
3137 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
3139 // Çàãðóæàåì ïàíåëü:
3140 panels
[i
].LoadState(PAMem
);
3141 if (panels
[i
].arrIdx
<> i
) then raise Exception
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
3142 if (panels
[i
].proxyId
>= 0) then mapGrid
.proxyEnabled
[panels
[i
].proxyId
] := panels
[i
].Enabled
;
3146 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
3150 procedure LoadFlag(flag
: PFlag
);
3154 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
3156 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3158 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3159 Mem
.ReadByte(flag
^.RespawnType
);
3161 Mem
.ReadByte(flag
^.State
);
3162 // Íàïðàâëåíèå ôëàãà:
3165 flag
^.Direction
:= D_LEFT
3167 flag
^.Direction
:= D_RIGHT
;
3169 Obj_LoadState(@flag
^.Obj
, Mem
);
3176 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3177 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
3178 LoadPanelArray(gWalls
);
3179 // Çàãðóæàåì ïàíåëè ôîíà:
3180 LoadPanelArray(gRenderBackgrounds
);
3181 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
3182 LoadPanelArray(gRenderForegrounds
);
3183 // Çàãðóæàåì ïàíåëè âîäû:
3184 LoadPanelArray(gWater
);
3185 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
3186 LoadPanelArray(gAcid1
);
3187 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
3188 LoadPanelArray(gAcid2
);
3189 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
3190 LoadPanelArray(gSteps
);
3191 // Çàãðóæàåì ïàíåëè ëèôòîâ:
3192 LoadPanelArray(gLifts
);
3195 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
3199 ///// Çàãðóæàåì ìóçûêó: /////
3200 // Ñèãíàòóðà ìóçûêè:
3202 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
3204 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3207 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3208 Mem
.ReadString(str
);
3209 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3211 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3212 Mem
.ReadBoolean(boo
);
3213 // Çàïóñêàåì ýòó ìóçûêó:
3214 gMusic
.SetByName(str
);
3215 gMusic
.SpecPause
:= boo
;
3218 gMusic
.SetPosition(dw
);
3221 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3222 Mem
.ReadInt(gTotalMonsters
);
3225 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3226 if gGameSettings
.GameMode
= GM_CTF
then
3228 // Ôëàã Êðàñíîé êîìàíäû:
3229 LoadFlag(@gFlags
[FLAG_RED
]);
3230 // Ôëàã Ñèíåé êîìàíäû:
3231 LoadFlag(@gFlags
[FLAG_BLUE
]);
3235 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3236 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3238 // Î÷êè Êðàñíîé êîìàíäû:
3239 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3240 // Î÷êè Ñèíåé êîìàíäû:
3241 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3247 // trace liquid, stepping by `dx` and `dy`
3248 // return last seen liquid coords, and `false` if we're started outside of the liquid
3249 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3251 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3255 // started outside of the liquid?
3256 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3257 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3263 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit