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
;
197 gdbg_map_use_accel_render
: Boolean = true;
198 gdbg_map_use_accel_coldet
: Boolean = true;
199 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
200 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
202 gCurrentMap
: TDynRecord
= nil;
203 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
206 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
210 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
213 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
219 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
220 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
221 g_options
, g_triggers
, g_player
,
222 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
223 utils
, sfs
, xstreams
, hashtable
,
224 ImagingTypes
, Imaging
, ImagingUtility
,
225 ImagingGif
, ImagingNetworkGraphics
;
228 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
229 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
230 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
234 dfmapdef
: TDynMapDef
= nil;
236 procedure loadMapDefinition ();
238 pr
: TTextParser
= nil;
242 if (dfmapdef
<> nil) then exit
;
244 e_LogWritefln('parsing "mapdef.txt"...', []);
245 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
248 e_LogWritefln('local "%smapdef.txt" not found', [DataDir
]);
252 WAD
:= TWADFile
.Create();
253 if not WAD
.ReadFile(GameWAD
) then
255 //raise Exception.Create('cannot load "game.wad"');
260 st
:= WAD
.openFileStream('mapdef.txt');
266 //raise Exception.Create('cannot open "mapdef.txt"');
267 e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING
);
268 pr
:= TStrTextParser
.Create(defaultMapDef
);
272 pr
:= TFileTextParser
.Create(st
);
276 dfmapdef
:= TDynMapDef
.Create(pr
);
277 except on e
: Exception
do
278 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
286 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
288 wst
: TSFSMemoryChunkStream
= nil;
289 pr
: TTextParser
= nil;
292 if (dataLen
< 4) then exit
;
294 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
296 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
298 if (PAnsiChar(data
)[0] = 'M') and (PAnsiChar(data
)[1] = 'A') and (PAnsiChar(data
)[2] = 'P') and (PByte(data
)[3] = 1) then
302 result
:= dfmapdef
.parseBinMap(wst
);
303 except on e
: Exception
do
305 e_LogWritefln('ERROR: %s', [e
.message]);
316 pr
:= TFileTextParser
.Create(wst
);
318 result
:= dfmapdef
.parseMap(pr
);
319 except on e
: Exception
do
321 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message])
322 else e_LogWritefln('ERROR: %s', [e
.message]);
323 pr
.Free(); // will free `wst`
328 pr
.Free(); // will free `wst`
334 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
335 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
336 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
339 function g_Texture_NumNameFindStart(name
: String): Boolean;
347 NNF_CurrentNum
:= -1;
349 for i
:= Length(name
) downto 1 do
350 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
352 if i
= Length(name
) then
353 begin // Íåò öèôð â êîíöå ñòðîêè
358 NNF_PureName
:= Copy(name
, 1, i
);
364 // Íå ïåðåâåñòè â ÷èñëî:
365 if not TryStrToInt(name
, NNF_FirstNum
) then
374 function g_Texture_NumNameFindNext(var newName
: String): Byte;
376 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
379 Result
:= NNF_NO_NAME
;
383 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
385 if NNF_CurrentNum
< NNF_FirstNum
then
386 Result
:= NNF_NAME_BEFORE
388 if NNF_CurrentNum
> NNF_FirstNum
then
389 Result
:= NNF_NAME_AFTER
391 Result
:= NNF_NAME_EQUALS
;
397 function panelTypeToTag (panelType
: Word): Integer;
400 PANEL_WALL
: result
:= GridTagWall
; // gWalls
401 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
402 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
403 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
404 PANEL_WATER
: result
:= GridTagWater
; // gWater
405 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
406 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
407 PANEL_STEP
: result
:= GridTagStep
; // gSteps
408 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
409 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
410 else result
:= GridTagInvalid
;
415 function dplLess (a
, b
: TObject
): Boolean;
421 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
422 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
423 result
:= (pa
.arrIdx
< pb
.arrIdx
);
426 procedure dplClear ();
428 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
434 PWhere
: ^TPanelArray
;
439 PanelById
: array of TPanelID
;
440 Textures
: TLevelTextureArray
= nil;
441 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
442 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
443 RespawnPoints
: Array of TRespawnPoint
;
444 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
445 //DOMFlagPoints: Array of TFlagPoint;
448 procedure g_Map_ProfilersBegin ();
450 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
451 profMapCollision
.mainBegin(g_profile_collision
);
453 if g_profile_collision
then
455 profMapCollision
.sectionBegin('*solids');
456 profMapCollision
.sectionEnd();
457 profMapCollision
.sectionBegin('liquids');
458 profMapCollision
.sectionEnd();
462 procedure g_Map_ProfilersEnd ();
464 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
468 // wall index in `gWalls` or -1
469 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
473 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
474 if (result
<> nil) then
476 if (hitx
<> nil) then hitx
^ := ex
;
477 if (hity
<> nil) then hity
^ := ey
;
481 if (hitx
<> nil) then hitx
^ := x1
;
482 if (hity
<> nil) then hity
^ := y1
;
486 // returns panel or nil
487 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
491 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
492 if (result
<> nil) then
494 if (hitx
<> nil) then hitx
^ := ex
;
495 if (hity
<> nil) then hity
^ := ey
;
499 if (hitx
<> nil) then hitx
^ := x1
;
500 if (hity
<> nil) then hity
^ := y1
;
505 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
507 function checker (pan
: TPanel
; tag
: Integer): Boolean;
510 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
512 result := pan.Enabled; // stop if wall is enabled
517 if ((tag
and GridTagLift
) <> 0) then
519 // stop if the lift of the right type
521 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
522 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
523 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
524 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
528 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
532 tagmask
: Integer = 0;
536 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
537 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
538 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
539 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
540 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
541 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
542 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
544 if (tagmask
= 0) then exit
;// just in case
545 if ((tagmask
and GridTagLift
) <> 0) then
548 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
553 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
558 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
561 if (tagmask
= 0) then exit
;
562 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
566 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
568 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
569 (Texture
= TEXTURE_NAME_ACID1
) or
570 (Texture
= TEXTURE_NAME_ACID2
);
573 procedure CreateDoorMap();
575 PanelArray
: Array of record
581 a
, b
, c
, m
, i
, len
: Integer;
589 SetLength(PanelArray
, len
);
591 for a
:= 0 to High(gWalls
) do
592 if gWalls
[a
].Door
then
594 PanelArray
[i
].X
:= gWalls
[a
].X
;
595 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
596 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
597 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
598 PanelArray
[i
].Active
:= True;
599 PanelArray
[i
].PanelID
:= a
;
605 SetLength(PanelArray
, len
);
616 SetLength(gDoorMap
, 0);
618 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
621 if PanelArray
[a
].Active
then
623 PanelArray
[a
].Active
:= False;
624 m
:= Length(gDoorMap
);
625 SetLength(gDoorMap
, m
+1);
626 SetLength(gDoorMap
[m
], 1);
627 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
635 if PanelArray
[b
].Active
then
636 for c
:= 0 to High(gDoorMap
[m
]) do
637 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
638 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
639 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
640 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
641 gWalls
[gDoorMap
[m
, c
]].X
,
642 gWalls
[gDoorMap
[m
, c
]].Y
,
643 gWalls
[gDoorMap
[m
, c
]].Width
,
644 gWalls
[gDoorMap
[m
, c
]].Height
) then
646 PanelArray
[b
].Active
:= False;
647 SetLength(gDoorMap
[m
],
648 Length(gDoorMap
[m
])+1);
649 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
655 g_Game_StepLoading();
661 procedure CreateLiftMap();
663 PanelArray
: Array of record
668 a
, b
, c
, len
, i
, j
: Integer;
674 len
:= Length(gLifts
);
675 SetLength(PanelArray
, len
);
677 for a
:= 0 to len
-1 do
679 PanelArray
[a
].X
:= gLifts
[a
].X
;
680 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
681 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
682 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
683 PanelArray
[a
].Active
:= True;
686 SetLength(gLiftMap
, len
);
689 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
691 for a
:= 0 to len
-1 do
692 if PanelArray
[a
].Active
then
694 PanelArray
[a
].Active
:= False;
695 SetLength(gLiftMap
[i
], 32);
703 for b
:= 0 to len
-1 do
704 if PanelArray
[b
].Active
then
706 if g_CollideAround(PanelArray
[b
].X
,
709 PanelArray
[b
].Height
,
710 PanelArray
[gLiftMap
[i
, c
]].X
,
711 PanelArray
[gLiftMap
[i
, c
]].Y
,
712 PanelArray
[gLiftMap
[i
, c
]].Width
,
713 PanelArray
[gLiftMap
[i
, c
]].Height
) then
715 PanelArray
[b
].Active
:= False;
717 if j
> High(gLiftMap
[i
]) then
718 SetLength(gLiftMap
[i
],
719 Length(gLiftMap
[i
])+32);
728 SetLength(gLiftMap
[i
], j
+1);
731 g_Game_StepLoading();
734 SetLength(gLiftMap
, i
);
739 function CreatePanel(PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
;
740 CurTex
: Integer; sav
: Boolean): Integer;
743 panels
: ^TPanelArray
;
747 case PanelRec
.PanelType
of
748 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
751 panels
:= @gRenderBackgrounds
;
753 panels
:= @gRenderForegrounds
;
762 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
765 panels
:= @gBlockMon
;
770 len
:= Length(panels
^);
771 SetLength(panels
^, len
+ 1);
773 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
774 panels
^[len
].arrIdx
:= len
;
775 panels
^[len
].proxyId
:= -1;
776 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
778 panels
^[len
].SaveIt
:= True;
782 len
:= Length(PanelByID
);
783 SetLength(PanelByID
, len
+ 1);
784 PanelByID
[len
].PWhere
:= panels
;
785 PanelByID
[len
].PArrID
:= Result
;
789 function CreateNullTexture(RecName
: String): Integer;
791 RecName
:= toLowerCase1251(RecName
);
792 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
793 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
795 SetLength(Textures
, Length(Textures
)+1);
796 result
:= High(Textures
);
798 with Textures
[High(Textures
)] do
800 TextureName
:= RecName
;
804 TextureID
:= LongWord(TEXTURE_NONE
);
807 TextNameHash
.put(RecName
, result
);
811 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
814 TextureData
: Pointer;
816 a
, ResLength
: Integer;
818 RecName
:= toLowerCase1251(RecName
);
819 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
820 if TextNameHash
.get(RecName
, result
) then
823 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
829 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
832 if Textures <> nil then
834 for a := 0 to High(Textures) do
836 if (Textures[a].TextureName = RecName) then
837 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
838 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
846 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
847 if (RecName
= TEXTURE_NAME_WATER
) or
848 (RecName
= TEXTURE_NAME_ACID1
) or
849 (RecName
= TEXTURE_NAME_ACID2
) then
851 SetLength(Textures
, Length(Textures
)+1);
853 with Textures
[High(Textures
)] do
855 TextureName
:= RecName
;
856 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
857 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
858 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
863 result
:= High(Textures
);
864 TextNameHash
.put(RecName
, result
);
868 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
869 WADName
:= g_ExtractWadName(RecName
);
871 WAD
:= TWADFile
.Create();
873 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
875 WAD
.ReadFile(WADName
);
879 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
881 FreeMem(TextureData);
882 RecName := 'COMMON\ALIEN';
886 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
888 SetLength(Textures
, Length(Textures
)+1);
889 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
891 SetLength(Textures
, Length(Textures
)-1);
894 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
895 FreeMem(TextureData
);
896 Textures
[High(Textures
)].TextureName
:= RecName
;
897 Textures
[High(Textures
)].Anim
:= False;
899 result
:= High(Textures
);
900 TextNameHash
.put(RecName
, result
);
902 else // Íåò òàêîãî ðåóñðñà â WAD'å
904 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
905 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
906 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
908 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
909 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
911 BadTextNameHash
.put(RecName
, -1);
918 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
921 TextureWAD
: PChar = nil;
922 TextData
: Pointer = nil;
923 TextureData
: Pointer = nil;
927 TextureResource
: String;
928 _width
, _height
, _framecount
, _speed
: Integer;
929 _backanimation
: Boolean;
931 ia
: TDynImageDataArray
= nil;
932 f
, c
, frdelay
, frloop
: Integer;
934 RecName
:= toLowerCase1251(RecName
);
935 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
936 if TextNameHash
.get(RecName
, result
) then
939 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
945 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
947 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
948 if BadTextNameHash
.get(RecName
, f
) then
950 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
954 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
955 WADName
:= g_ExtractWadName(RecName
);
957 WAD
:= TWADFile
.Create();
959 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
961 WAD
.ReadFile(WADName
);
963 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
965 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
966 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
968 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
969 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
971 BadTextNameHash
.put(RecName
, -1);
976 if WADName = Map then
978 //FreeMem(TextureWAD);
979 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
985 if ResLength
< 6 then
987 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
988 BadTextNameHash
.put(RecName
, -1);
992 // ýòî ïòèöà? ýòî ñàìîë¸ò?
993 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
994 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
996 // íåò, ýòî ñóïåðìåí!
997 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
999 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1000 BadTextNameHash
.put(RecName
, -1);
1004 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1005 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1007 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1008 BadTextNameHash
.put(RecName
, -1);
1012 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1014 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1015 if TextureResource
= '' then
1017 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1018 BadTextNameHash
.put(RecName
, -1);
1022 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1023 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1024 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1025 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1026 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1031 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1032 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1034 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1035 BadTextNameHash
.put(RecName
, -1);
1042 SetLength(Textures
, Length(Textures
)+1);
1043 with Textures
[High(Textures
)] do
1045 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1046 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1048 TextureName
:= RecName
;
1052 FramesCount
:= _framecount
;
1054 result
:= High(Textures
);
1055 TextNameHash
.put(RecName
, result
);
1059 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1060 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1062 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1064 BadTextNameHash
.put(RecName
, -1);
1070 // try animated image
1072 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1073 if length(imgfmt) = 0 then
1075 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1079 GlobalMetadata
.ClearMetaItems();
1080 GlobalMetadata
.ClearMetaItemsForSaving();
1081 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1083 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1084 BadTextNameHash
.put(RecName
, -1);
1087 if length(ia
) = 0 then
1089 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1090 BadTextNameHash
.put(RecName
, -1);
1097 _width
:= ia
[0].width
;
1098 _height
:= ia
[0].height
;
1099 _framecount
:= length(ia
);
1101 _backanimation
:= false;
1104 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1106 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1108 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1110 if f
< 0 then f
:= 0;
1113 if c
< 13 then c
:= 0 else c
:= 1;
1115 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1120 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1122 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1124 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1126 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1130 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1131 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1132 f
:= ord(_backanimation
);
1133 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
);
1135 SetLength(Textures
, Length(Textures
)+1);
1136 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1137 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1139 Textures
[High(Textures
)].TextureName
:= RecName
;
1140 Textures
[High(Textures
)].Width
:= _width
;
1141 Textures
[High(Textures
)].Height
:= _height
;
1142 Textures
[High(Textures
)].Anim
:= True;
1143 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1144 Textures
[High(Textures
)].Speed
:= _speed
;
1145 result
:= High(Textures
);
1146 TextNameHash
.put(RecName
, result
);
1147 //writeln(' CREATED!');
1151 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1152 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1154 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1156 BadTextNameHash
.put(RecName
, -1);
1160 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1163 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1164 if (TextData
<> nil) then FreeMem(TextData
);
1165 if (TextureData
<> nil) then FreeMem(TextureData
);
1169 procedure CreateItem(Item
: TDynRecord
);
1171 if g_Game_IsClient
then Exit
;
1173 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1174 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1177 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1178 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1181 procedure CreateArea(Area
: TDynRecord
);
1186 case Area
.AreaType
of
1187 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1188 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1190 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1191 with RespawnPoints
[High(RespawnPoints
)] do
1195 Direction
:= TDirection(Area
.Direction
);
1197 case Area
.AreaType
of
1198 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1199 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1200 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1201 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1202 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1207 AREA_REDFLAG
, AREA_BLUEFLAG
:
1209 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1211 if FlagPoints
[a
] <> nil then Exit
;
1215 with FlagPoints
[a
]^ do
1217 X
:= Area
.X
-FLAGRECT
.X
;
1218 Y
:= Area
.Y
-FLAGRECT
.Y
;
1219 Direction
:= TDirection(Area
.Direction
);
1225 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1226 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1229 Animation
:= TAnimation
.Create(id
, True, 8);
1230 Obj
.Rect
:= FLAGRECT
;
1238 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1239 with DOMFlagPoints[High(DOMFlagPoints)] do
1243 Direction := TDirection(Area.Direction);
1246 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1251 procedure CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1255 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1259 mapId
:= Trigger
.id
;
1260 mapIndex
:= amapIdx
;
1263 Width
:= Trigger
.Width
;
1264 Height
:= Trigger
.Height
;
1265 Enabled
:= Trigger
.Enabled
;
1266 //TexturePanel := Trigger.TexturePanel;
1267 TexturePanel
:= atpanid
;
1268 TexturePanelType
:= fTexturePanel1Type
;
1269 ShotPanelType
:= fTexturePanel2Type
;
1270 TriggerType
:= Trigger
.TriggerType
;
1271 ActivateType
:= Trigger
.ActivateType
;
1272 Keys
:= Trigger
.Keys
;
1273 trigPanelId
:= atrigpanid
;
1274 //trigShotPanelId := ashotpanid;
1275 //Data.Default := Trigger.DATA;
1276 if (Trigger
.trigRec
= nil) then
1279 if (TriggerType
<> TRIGGER_SECRET
) then
1281 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1286 trigData
:= Trigger
.trigRec
.clone();
1290 g_Triggers_Create(_trigger
);
1293 procedure CreateMonster(monster
: TDynRecord
);
1298 if g_Game_IsClient
then Exit
;
1300 if (gGameSettings
.GameType
= GT_SINGLE
)
1301 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1303 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1305 if gTriggers
<> nil then
1307 for a
:= 0 to High(gTriggers
) do
1309 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1311 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1312 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1317 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1321 procedure g_Map_ReAdd_DieTriggers();
1323 function monsDieTrig (mon
: TMonster
): Boolean;
1326 //tw: TStrTextWriter;
1328 result
:= false; // don't stop
1329 mon
.ClearTriggers();
1330 for a
:= 0 to High(gTriggers
) do
1332 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1334 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1336 tw := TStrTextWriter.Create();
1338 gTriggers[a].trigData.writeTo(tw);
1339 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1344 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1350 if g_Game_IsClient
then Exit
;
1352 g_Mons_ForEach(monsDieTrig
);
1355 function extractWadName(resourceName
: string): string;
1359 posN
:= Pos(':', resourceName
);
1361 Result
:= Copy(resourceName
, 0, posN
-1)
1366 procedure addResToExternalResList(res
: string);
1368 res
:= extractWadName(res
);
1369 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1370 gExternalResources
.Add(res
);
1373 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1375 //textures: TTexturesRec1Array;
1376 //textures: TDynField;
1378 //mapHeader: TMapHeaderRec_1;
1380 //resFile: String = '';
1382 if gExternalResources
= nil then
1383 gExternalResources
:= TStringList
.Create
;
1385 gExternalResources
.Clear
;
1389 textures := GetTextures(map);
1390 for i := 0 to High(textures) do
1392 addResToExternalResList(resFile);
1396 textures := map['texture'];
1397 if (textures <> nil) then
1399 for trec in textures do
1401 addResToExternalResList(resFile);
1408 //mapHeader := GetMapHeader(map);
1410 addResToExternalResList(map
.MusicName
);
1411 addResToExternalResList(map
.SkyName
);
1415 procedure mapCreateGrid ();
1417 mapX0
: Integer = $3fffffff;
1418 mapY0
: Integer = $3fffffff;
1419 mapX1
: Integer = -$3fffffff;
1420 mapY1
: Integer = -$3fffffff;
1422 procedure calcBoundingBox (constref panels
: TPanelArray
);
1427 for idx
:= 0 to High(panels
) do
1430 if not pan
.visvalid
then continue
;
1431 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1432 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1433 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1434 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1435 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1439 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1445 //tag := panelTypeToTag(tag);
1446 for idx
:= 0 to High(panels
) do
1449 if not pan
.visvalid
then continue
;
1450 if (pan
.proxyId
<> -1) then
1452 {$IF DEFINED(D2F_DEBUG)}
1453 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
);
1457 case pan
.PanelType
of
1458 PANEL_WALL
: newtag
:= GridTagWall
;
1459 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1460 PANEL_BACK
: newtag
:= GridTagBack
;
1461 PANEL_FORE
: newtag
:= GridTagFore
;
1462 PANEL_WATER
: newtag
:= GridTagWater
;
1463 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1464 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1465 PANEL_STEP
: newtag
:= GridTagStep
;
1466 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1467 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1468 else continue
; // oops
1472 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1473 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1474 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1475 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1477 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1479 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1490 calcBoundingBox(gWalls
);
1491 calcBoundingBox(gRenderBackgrounds
);
1492 calcBoundingBox(gRenderForegrounds
);
1493 calcBoundingBox(gWater
);
1494 calcBoundingBox(gAcid1
);
1495 calcBoundingBox(gAcid2
);
1496 calcBoundingBox(gSteps
);
1497 calcBoundingBox(gLifts
);
1498 calcBoundingBox(gBlockMon
);
1500 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1502 if (mapX0
> 0) then mapX0
:= 0;
1503 if (mapY0
> 0) then mapY0
:= 0;
1505 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1506 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1508 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1509 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1511 addPanelsToGrid(gWalls
);
1512 addPanelsToGrid(gRenderBackgrounds
);
1513 addPanelsToGrid(gRenderForegrounds
);
1514 addPanelsToGrid(gWater
);
1515 addPanelsToGrid(gAcid1
);
1516 addPanelsToGrid(gAcid2
);
1517 addPanelsToGrid(gSteps
);
1518 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1519 addPanelsToGrid(gBlockMon
);
1521 mapGrid
.dumpStats();
1523 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1527 function g_Map_Load(Res
: String): Boolean;
1529 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1530 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1534 //TexturePanel: Integer;
1536 LiftPanelIdx
: Integer;
1537 DoorPanelIdx
: Integer;
1538 ShotPanelIdx
: Integer;
1539 trigrec
: TDynRecord
;
1541 liftPan
: TDynRecord
;
1542 doorPan
: TDynRecord
;
1543 shotPan
: TDynRecord
;
1547 mapReader
: TDynRecord
= nil;
1548 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1549 panels
: TDynField
= nil; //TPanelsRec1Array;
1550 items
: TDynField
= nil; //TItemsRec1Array;
1551 monsters
: TDynField
= nil; //TMonsterRec1Array;
1552 areas
: TDynField
= nil; //TAreasRec1Array;
1553 triggers
: TDynField
= nil; //TTriggersRec1Array;
1556 AddTextures
: TAddTextureArray
;
1557 TriggersTable
: array of TTRec
;
1558 FileName
, mapResName
, s
, TexName
: String;
1561 ok
, isAnim
, trigRef
: Boolean;
1562 CurTex
, ntn
: Integer;
1563 rec
, texrec
: TDynRecord
;
1565 pannum
, trignum
, cnt
, tgpid
: Integer;
1575 gMapInfo
.Map
:= Res
;
1576 TriggersTable
:= nil;
1579 sfsGCDisable(); // temporary disable removing of temporary volumes
1582 FileName
:= g_ExtractWadName(Res
);
1583 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1584 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1586 WAD
:= TWADFile
.Create();
1587 if not WAD
.ReadFile(FileName
) then
1589 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1594 //k8: why loader ignores path here?
1595 mapResName
:= g_ExtractFileName(Res
);
1596 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1598 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1607 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1613 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1614 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1616 stt
:= curTimeMicro();
1619 mapReader
:= g_Map_ParseMap(Data
, Len
);
1622 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1629 generateExternalResourcesList(mapReader
);
1630 mapTextureList
:= mapReader
['texture'];
1631 // get all other lists here too
1632 panels
:= mapReader
['panel'];
1633 triggers
:= mapReader
['trigger'];
1634 items
:= mapReader
['item'];
1635 areas
:= mapReader
['area'];
1636 monsters
:= mapReader
['monster'];
1638 // Çàãðóçêà îïèñàíèÿ êàðòû:
1639 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1640 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1644 Name
:= mapReader
.MapName
;
1645 Description
:= mapReader
.MapDesc
;
1646 Author
:= mapReader
.MapAuthor
;
1647 MusicName
:= mapReader
.MusicName
;
1648 SkyName
:= mapReader
.SkyName
;
1649 Height
:= mapReader
.Height
;
1650 Width
:= mapReader
.Width
;
1653 // Çàãðóçêà òåêñòóð:
1654 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1655 // Äîáàâëåíèå òåêñòóð â Textures[]:
1656 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1658 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1659 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1662 for rec
in mapTextureList
do
1666 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1667 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1669 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1672 // Àíèìèðîâàííàÿ òåêñòóðà
1673 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1674 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1679 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1680 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1682 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1684 rec
.tagInt
:= ntn
; // remember texture number
1685 g_Game_StepLoading();
1688 // set panel tagInt to texture index
1689 if (panels
<> nil) then
1691 for rec
in panels
do
1693 texrec
:= rec
.TextureRec
;
1694 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1699 // Çàãðóçêà òðèããåðîâ
1700 gTriggerClientID
:= 0;
1701 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1702 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1705 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1706 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1708 // check texture numbers for panels
1709 if (panels
<> nil) and (panels
.count
> 0) then
1711 for rec
in panels
do
1713 if (rec
.tagInt
< 0) then
1715 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1722 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1723 if (triggers
<> nil) and (triggers
.count
> 0) then
1725 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1726 //SetLength(TriggersTable, triggers.count);
1727 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1729 for rec
in triggers
do
1731 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1732 pttit
:= @TriggersTable
[High(TriggersTable
)];
1733 pttit
.trigrec
:= rec
;
1734 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1735 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1736 pttit
.liftPan
:= nil;
1737 pttit
.doorPan
:= nil;
1738 pttit
.shotPan
:= nil;
1739 pttit
.texPanIdx
:= -1;
1740 pttit
.LiftPanelIdx
:= -1;
1741 pttit
.DoorPanelIdx
:= -1;
1742 pttit
.ShotPanelIdx
:= -1;
1744 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1746 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1749 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1751 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1754 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1756 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1759 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1760 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1761 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1762 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1764 g_Game_StepLoading();
1769 if (panels
<> nil) and (panels
.count
> 0) then
1771 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1772 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1775 for rec
in panels
do
1778 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1780 SetLength(AddTextures
, 0);
1785 if (mapTextureList
<> nil) then
1787 texrec
:= rec
.TextureRec
;
1788 ok
:= (texrec
<> nil);
1793 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1794 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1796 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1799 for b := 0 to High(TriggersTable) do
1801 if (TriggersTable[b].texPan = rec) or (TriggersTable[b].shotPan = rec) then
1809 if rec
.userPanelTrigRef
then
1811 // e_LogWritefln('trigref for panel %s', [pannum]);
1820 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1821 s
:= texrec
.Resource
;
1823 // Ñïåö-òåêñòóðû çàïðåùåíû
1824 if g_Map_IsSpecialTexture(s
) then
1830 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1831 ok
:= g_Texture_NumNameFindStart(s
);
1834 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1835 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1838 k
:= NNF_NAME_BEFORE
;
1839 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1840 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1842 k
:= g_Texture_NumNameFindNext(TexName
);
1844 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1846 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1849 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1851 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1852 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1853 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1856 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1858 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1859 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1860 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1865 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1867 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1868 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1869 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1872 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1874 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1875 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1876 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1880 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1884 for c := 0 to High(Textures) do
1886 if (Textures[c].TextureName = TexName) then
1888 SetLength(AddTextures, Length(AddTextures)+1);
1889 AddTextures[High(AddTextures)].Texture := c;
1890 AddTextures[High(AddTextures)].Anim := isAnim;
1895 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1897 SetLength(AddTextures
, Length(AddTextures
)+1);
1898 AddTextures
[High(AddTextures
)].Texture
:= c
;
1899 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1905 if k
= NNF_NAME_EQUALS
then
1907 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1908 SetLength(AddTextures
, Length(AddTextures
)+1);
1909 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1910 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1911 CurTex
:= High(AddTextures
);
1922 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1923 end; // if ok - ññûëàþòñÿ òðèããåðû
1927 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1928 SetLength(AddTextures
, 1);
1929 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1930 AddTextures
[0].Anim
:= false;
1931 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1935 //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);
1937 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1939 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð
1940 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
, trigRef
);
1941 //e_LogWritefln('panel #%s of type %s got id #%s', [pannum, rec.PanelType, PanelID]);
1942 // set 'gamePanelId' field to panel id
1943 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
1945 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
1947 g_Game_StepLoading();
1951 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
1952 for b
:= 0 to High(TriggersTable
) do
1954 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
1955 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
1956 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
1957 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
1960 // create map grid, init other grids (for monsters, for example)
1961 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1964 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
1965 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
1967 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
1968 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1969 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
1971 for rec
in triggers
do
1974 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
1975 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
1976 // we can have only one of those
1977 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
1978 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
1979 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
1981 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
1982 CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
1986 // Çàãðóçêà ïðåäìåòîâ
1987 e_WriteLog(' Loading items...', MSG_NOTIFY
);
1988 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1990 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
1991 if (items
<> nil) and not gLoadGameMode
then
1993 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1994 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1995 for rec
in items
do CreateItem(rec
);
1998 // Çàãðóçêà îáëàñòåé
1999 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2000 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2002 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2003 if areas
<> nil then
2005 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2006 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2007 for rec
in areas
do CreateArea(rec
);
2010 // Çàãðóçêà ìîíñòðîâ
2011 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2012 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2014 gTotalMonsters
:= 0;
2016 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2017 if (monsters
<> nil) and not gLoadGameMode
then
2019 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2020 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2021 for rec
in monsters
do CreateMonster(rec
);
2024 gCurrentMap
:= mapReader
; // this will be our current map now
2025 gCurrentMapFileName
:= Res
;
2029 if gMapInfo
.SkyName
<> '' then
2031 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2032 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2033 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2035 if FileName
<> '' then
2036 FileName
:= GameDir
+'/wads/'+FileName
2039 FileName
:= g_ExtractWadName(Res
);
2042 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2043 if g_Texture_CreateWAD(BackID
, s
) then
2045 g_Game_SetupScreenSize();
2048 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2053 if gMapInfo
.MusicName
<> '' then
2055 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2056 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2057 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2059 if FileName
<> '' then
2060 FileName
:= GameDir
+'/wads/'+FileName
2063 FileName
:= g_ExtractWadName(Res
);
2066 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2067 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2070 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2073 // Îñòàëüíûå óñòàíâêè
2081 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2082 if not gLoadGameMode
then g_GFX_Init();
2084 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2085 mapTextureList
:= nil;
2090 TriggersTable
:= nil;
2093 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2094 if ok
and (not gLoadGameMode
) then
2096 gMusic
.SetByName(gMapInfo
.MusicName
);
2101 gMusic
.SetByName('');
2104 stt
:= curTimeMicro()-stt
;
2105 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2107 sfsGCEnable(); // enable releasing unused volumes
2109 e_ClearInputBuffer(); // why not?
2112 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2117 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2120 mapReader
: TDynRecord
;
2121 //Header: TMapHeaderRec_1;
2126 FillChar(Result
, SizeOf(Result
), 0);
2127 FileName
:= g_ExtractWadName(Res
);
2129 WAD
:= TWADFile
.Create();
2130 if not WAD
.ReadFile(FileName
) then
2136 //k8: it ignores path again
2137 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2146 mapReader
:= g_Map_ParseMap(Data
, Len
);
2153 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2155 Result
.Name
:= mapReader
.MapName
;
2156 Result
.Description
:= mapReader
.MapDesc
;
2158 Result
.Author
:= mapReader
.MapAuthor
;
2159 Result
.Height
:= mapReader
.Height
;
2160 Result
.Width
:= mapReader
.Width
;
2164 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2165 //ZeroMemory(@Header, SizeOf(Header));
2166 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2167 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2169 Result
.Author
:= '';
2177 function g_Map_GetMapsList(WADName
: string): SArray
;
2184 WAD
:= TWADFile
.Create();
2185 if not WAD
.ReadFile(WADName
) then
2190 ResList
:= WAD
.GetMapResources();
2191 if ResList
<> nil then
2193 for a
:= 0 to High(ResList
) do
2195 SetLength(Result
, Length(Result
)+1);
2196 Result
[High(Result
)] := ResList
[a
];
2202 function g_Map_Exist(Res
: string): Boolean;
2205 FileName
, mnn
: string;
2211 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2213 WAD
:= TWADFile
.Create
;
2214 if not WAD
.ReadFile(FileName
) then
2220 ResList
:= WAD
.GetMapResources();
2223 mnn
:= g_ExtractFileName(Res
);
2224 if ResList
<> nil then
2225 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2232 procedure g_Map_Free(freeTextures
: Boolean=true);
2236 procedure FreePanelArray(var panels
: TPanelArray
);
2241 if panels
<> nil then
2243 for i
:= 0 to High(panels
) do
2256 RespawnPoints
:= nil;
2257 if FlagPoints
[FLAG_RED
] <> nil then
2259 Dispose(FlagPoints
[FLAG_RED
]);
2260 FlagPoints
[FLAG_RED
] := nil;
2262 if FlagPoints
[FLAG_BLUE
] <> nil then
2264 Dispose(FlagPoints
[FLAG_BLUE
]);
2265 FlagPoints
[FLAG_BLUE
] := nil;
2267 //DOMFlagPoints := nil;
2271 if (Length(gCurrentMapFileName
) <> 0) then
2273 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2277 e_LogWritefln('g_Map_Free: no previous map.', []);
2279 if freeTextures
then
2281 e_LogWritefln('g_Map_Free: clearing textures...', []);
2282 if (Textures
<> nil) then
2284 for a
:= 0 to High(Textures
) do
2286 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2288 if Textures
[a
].Anim
then
2290 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2294 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2296 e_DeleteTexture(Textures
[a
].TextureID
);
2303 TextNameHash
.Free();
2304 TextNameHash
:= nil;
2305 BadTextNameHash
.Free();
2306 BadTextNameHash
:= nil;
2309 FreePanelArray(gWalls
);
2310 FreePanelArray(gRenderBackgrounds
);
2311 FreePanelArray(gRenderForegrounds
);
2312 FreePanelArray(gWater
);
2313 FreePanelArray(gAcid1
);
2314 FreePanelArray(gAcid2
);
2315 FreePanelArray(gSteps
);
2316 FreePanelArray(gLifts
);
2317 FreePanelArray(gBlockMon
);
2319 if BackID
<> DWORD(-1) then
2323 e_DeleteTexture(BackID
);
2324 BackID
:= DWORD(-1);
2327 g_Game_StopAllSounds(False);
2329 g_Sound_Delete(gMapInfo
.MusicName
);
2331 gMapInfo
.Name
:= '';
2332 gMapInfo
.Description
:= '';
2333 gMapInfo
.MusicName
:= '';
2334 gMapInfo
.Height
:= 0;
2335 gMapInfo
.Width
:= 0;
2343 procedure g_Map_Update();
2349 procedure UpdatePanelArray(var panels
: TPanelArray
);
2354 if panels
<> nil then
2355 for i
:= 0 to High(panels
) do
2360 UpdatePanelArray(gWalls
);
2361 UpdatePanelArray(gRenderBackgrounds
);
2362 UpdatePanelArray(gRenderForegrounds
);
2363 UpdatePanelArray(gWater
);
2364 UpdatePanelArray(gAcid1
);
2365 UpdatePanelArray(gAcid2
);
2366 UpdatePanelArray(gSteps
);
2368 if gGameSettings
.GameMode
= GM_CTF
then
2370 for a
:= FLAG_RED
to FLAG_BLUE
do
2371 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2374 if gFlags
[a
].Animation
<> nil then
2375 gFlags
[a
].Animation
.Update();
2377 m
:= g_Obj_Move(@Obj
, True, True);
2379 if gTime
mod (GAME_TICK
*2) <> 0 then
2382 // Ñîïðîòèâëåíèå âîçäóõà:
2383 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2385 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
2386 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2389 gFlags
[a
].CaptureTime
:= 0;
2390 if a
= FLAG_RED
then
2391 s
:= _lc
[I_PLAYER_FLAG_RED
]
2393 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2394 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2396 if g_Game_IsNet
then
2397 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2404 // Èãðîê áåðåò ôëàã:
2405 if gPlayers
<> nil then
2407 j
:= Random(Length(gPlayers
)) - 1;
2409 for d
:= 0 to High(gPlayers
) do
2412 if j
> High(gPlayers
) then
2415 if gPlayers
[j
] <> nil then
2416 if gPlayers
[j
].Live
and
2417 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2419 if gPlayers
[j
].GetFlag(a
) then
2430 procedure g_Map_DrawPanels (PanelType
: Word);
2432 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2436 if (panels
<> nil) then
2438 // alas, no visible set
2439 for idx
:= 0 to High(panels
) do
2441 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2448 PANEL_WALL
: DrawPanels(gWalls
);
2449 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2450 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2451 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2452 PANEL_WATER
: DrawPanels(gWater
);
2453 PANEL_ACID1
: DrawPanels(gAcid1
);
2454 PANEL_ACID2
: DrawPanels(gAcid2
);
2455 PANEL_STEP
: DrawPanels(gSteps
);
2461 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2463 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2465 result
:= false; // don't stop, ever
2466 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2467 gDrawPanelList
.insert(pan
);
2472 //tagmask := panelTypeToTag(PanelType);
2473 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2474 // list will be rendered in `g_game.DrawPlayer()`
2478 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2480 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2482 result
:= false; // don't stop, ever
2483 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2487 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2491 procedure g_Map_DrawBack(dx
, dy
: Integer);
2493 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2494 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2496 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2499 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2500 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2506 if WordBool(PanelType
and PANEL_WALL
) then
2507 if gWalls
<> nil then
2512 if gWalls
[a
].Enabled
and
2513 g_Collide(X
, Y
, Width
, Height
,
2514 gWalls
[a
].X
, gWalls
[a
].Y
,
2515 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2522 if WordBool(PanelType
and PANEL_WATER
) then
2523 if gWater
<> nil then
2528 if g_Collide(X
, Y
, Width
, Height
,
2529 gWater
[a
].X
, gWater
[a
].Y
,
2530 gWater
[a
].Width
, gWater
[a
].Height
) then
2537 if WordBool(PanelType
and PANEL_ACID1
) then
2538 if gAcid1
<> nil then
2543 if g_Collide(X
, Y
, Width
, Height
,
2544 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2545 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2552 if WordBool(PanelType
and PANEL_ACID2
) then
2553 if gAcid2
<> nil then
2558 if g_Collide(X
, Y
, Width
, Height
,
2559 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2560 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2567 if WordBool(PanelType
and PANEL_STEP
) then
2568 if gSteps
<> nil then
2573 if g_Collide(X
, Y
, Width
, Height
,
2574 gSteps
[a
].X
, gSteps
[a
].Y
,
2575 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2582 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2583 if gLifts
<> nil then
2588 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2589 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2590 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2591 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2592 g_Collide(X
, Y
, Width
, Height
,
2593 gLifts
[a
].X
, gLifts
[a
].Y
,
2594 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2601 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2602 if gBlockMon
<> nil then
2604 h
:= High(gBlockMon
);
2608 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2609 g_Collide(X
, Y
, Width
, Height
,
2610 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2611 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2619 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2623 function checkPanels (constref panels
: TPanelArray
): Boolean;
2628 if panels
= nil then exit
;
2629 for a
:= 0 to High(panels
) do
2631 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2634 texid
:= panels
[a
].GetTextureID();
2641 texid
:= LongWord(TEXTURE_NONE
);
2643 if not checkPanels(gWater
) then
2644 if not checkPanels(gAcid1
) then
2645 if not checkPanels(gAcid2
) then exit
;
2650 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2652 SlowMask
= GridTagLift
or GridTagBlockMon
;
2653 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2656 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2658 result := pan.Enabled;
2663 if ((tag
and GridTagLift
) <> 0) then
2666 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2667 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2668 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2669 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2670 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2674 if ((tag
and GridTagBlockMon
) <> 0) then
2676 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2681 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2682 result
:= true; // i found her!
2686 tagmask
: Integer = 0;
2688 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2689 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2690 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2691 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2692 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2693 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2694 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2696 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2698 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2699 if gdbg_map_use_accel_coldet
then
2701 if (Width
= 1) and (Height
= 1) then
2703 if ((tagmask
and SlowMask
) <> 0) then
2706 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2711 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2716 if ((tagmask
and SlowMask
) <> 0) then
2719 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2724 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2730 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2732 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2736 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2738 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2741 // slightly different from the old code, but meh...
2742 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2744 result
:= false; // don't stop, ever
2745 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2748 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2749 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2750 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2753 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2755 texid
:= pan
.GetTextureID();
2756 // water? water has the highest priority, so stop right here
2757 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2759 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2761 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2765 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2766 if gdbg_map_use_accel_coldet
then
2768 texid
:= LongWord(TEXTURE_NONE
);
2769 if (Width
= 1) and (Height
= 1) then
2771 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2775 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2781 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2783 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2787 procedure g_Map_EnableWall(ID
: DWORD
);
2792 pan
.Enabled
:= True;
2793 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2795 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2796 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2797 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2799 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2801 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2802 //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);
2806 procedure g_Map_DisableWall(ID
: DWORD
);
2811 pan
.Enabled
:= False;
2812 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2814 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2815 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2817 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2819 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2820 //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);
2824 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2829 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2832 tp
:= gRenderForegrounds
[ID
];
2834 tp
:= gRenderBackgrounds
[ID
];
2847 tp
.NextTexture(AnimLoop
);
2848 if g_Game_IsServer
and g_Game_IsNet
then
2849 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2852 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2854 if gLifts
[ID
].LiftType
= t
then
2861 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2862 //TODO: make separate lift tags, and change tag here
2864 if LiftType
= 0 then
2865 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2866 else if LiftType
= 1 then
2867 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2868 else if LiftType
= 2 then
2869 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2870 else if LiftType
= 3 then
2871 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2873 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2877 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2880 PointsArray
: Array of TRespawnPoint
;
2883 SetLength(PointsArray
, 0);
2885 if RespawnPoints
= nil then
2888 for a
:= 0 to High(RespawnPoints
) do
2889 if RespawnPoints
[a
].PointType
= PointType
then
2891 SetLength(PointsArray
, Length(PointsArray
)+1);
2892 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2895 if PointsArray
= nil then
2898 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2902 function g_Map_GetPointCount(PointType
: Byte): Word;
2908 if RespawnPoints
= nil then
2911 for a
:= 0 to High(RespawnPoints
) do
2912 if RespawnPoints
[a
].PointType
= PointType
then
2913 Result
:= Result
+ 1;
2916 function g_Map_HaveFlagPoints(): Boolean;
2918 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2921 procedure g_Map_ResetFlag(Flag
: Byte);
2923 with gFlags
[Flag
] do
2929 Direction
:= D_LEFT
;
2930 State
:= FLAG_STATE_NONE
;
2931 if FlagPoints
[Flag
] <> nil then
2933 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2934 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2935 Direction
:= FlagPoints
[Flag
]^.Direction
;
2936 State
:= FLAG_STATE_NORMAL
;
2942 procedure g_Map_DrawFlags();
2945 Mirror
: TMirrorType
;
2947 if gGameSettings
.GameMode
<> GM_CTF
then
2950 for i
:= FLAG_RED
to FLAG_BLUE
do
2952 if State
<> FLAG_STATE_CAPTURED
then
2954 if State
= FLAG_STATE_NONE
then
2957 if Direction
= D_LEFT
then
2959 Mirror
:= M_HORIZONTAL
;
2968 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2970 if g_debug_Frames
then
2972 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2974 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2975 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2981 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2988 procedure SavePanelArray(var panels
: TPanelArray
);
2990 PAMem
: TBinMemoryWriter
;
2993 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2994 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2997 while i
< Length(panels
) do
2999 if panels
[i
].SaveIt
then
3003 // Ñîõðàíÿåì ïàíåëü:
3004 panels
[i
].SaveState(PAMem
);
3009 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
3010 PAMem
.SaveToMemory(Mem
);
3014 procedure SaveFlag(flag
: PFlag
);
3017 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3019 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3020 Mem
.WriteByte(flag
^.RespawnType
);
3022 Mem
.WriteByte(flag
^.State
);
3023 // Íàïðàâëåíèå ôëàãà:
3024 if flag
^.Direction
= D_LEFT
then
3030 Obj_SaveState(@flag
^.Obj
, Mem
);
3034 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3036 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3037 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
3038 SavePanelArray(gWalls
);
3039 // Ñîõðàíÿåì ïàíåëè ôîíà:
3040 SavePanelArray(gRenderBackgrounds
);
3041 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
3042 SavePanelArray(gRenderForegrounds
);
3043 // Ñîõðàíÿåì ïàíåëè âîäû:
3044 SavePanelArray(gWater
);
3045 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
3046 SavePanelArray(gAcid1
);
3047 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
3048 SavePanelArray(gAcid2
);
3049 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
3050 SavePanelArray(gSteps
);
3051 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
3052 SavePanelArray(gLifts
);
3055 ///// Ñîõðàíÿåì ìóçûêó: /////
3056 // Ñèãíàòóðà ìóçûêè:
3057 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3060 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3061 if gMusic
.NoMusic
then
3065 Mem
.WriteString(str
, 64);
3066 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3067 dw
:= gMusic
.GetPosition();
3069 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3070 boo
:= gMusic
.SpecPause
;
3071 Mem
.WriteBoolean(boo
);
3074 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3075 Mem
.WriteInt(gTotalMonsters
);
3078 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3079 if gGameSettings
.GameMode
= GM_CTF
then
3081 // Ôëàã Êðàñíîé êîìàíäû:
3082 SaveFlag(@gFlags
[FLAG_RED
]);
3083 // Ôëàã Ñèíåé êîìàíäû:
3084 SaveFlag(@gFlags
[FLAG_BLUE
]);
3088 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3089 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3091 // Î÷êè Êðàñíîé êîìàíäû:
3092 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3093 // Î÷êè Ñèíåé êîìàíäû:
3094 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3099 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
3106 procedure LoadPanelArray(var panels
: TPanelArray
);
3108 PAMem
: TBinMemoryReader
;
3111 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
3112 PAMem
:= TBinMemoryReader
.Create();
3113 PAMem
.LoadFromMemory(Mem
);
3115 for i
:= 0 to Length(panels
)-1 do
3117 if panels
[i
].SaveIt
then
3123 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
3125 // Çàãðóæàåì ïàíåëü:
3126 panels
[i
].LoadState(PAMem
);
3127 if (panels
[i
].arrIdx
<> i
) then raise Exception
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
3128 if (panels
[i
].proxyId
>= 0) then mapGrid
.proxyEnabled
[panels
[i
].proxyId
] := panels
[i
].Enabled
;
3132 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
3136 procedure LoadFlag(flag
: PFlag
);
3140 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
3142 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3144 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
3145 Mem
.ReadByte(flag
^.RespawnType
);
3147 Mem
.ReadByte(flag
^.State
);
3148 // Íàïðàâëåíèå ôëàãà:
3151 flag
^.Direction
:= D_LEFT
3153 flag
^.Direction
:= D_RIGHT
;
3155 Obj_LoadState(@flag
^.Obj
, Mem
);
3162 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3163 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
3164 LoadPanelArray(gWalls
);
3165 // Çàãðóæàåì ïàíåëè ôîíà:
3166 LoadPanelArray(gRenderBackgrounds
);
3167 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
3168 LoadPanelArray(gRenderForegrounds
);
3169 // Çàãðóæàåì ïàíåëè âîäû:
3170 LoadPanelArray(gWater
);
3171 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
3172 LoadPanelArray(gAcid1
);
3173 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
3174 LoadPanelArray(gAcid2
);
3175 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
3176 LoadPanelArray(gSteps
);
3177 // Çàãðóæàåì ïàíåëè ëèôòîâ:
3178 LoadPanelArray(gLifts
);
3181 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
3185 ///// Çàãðóæàåì ìóçûêó: /////
3186 // Ñèãíàòóðà ìóçûêè:
3188 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
3190 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3193 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3194 Mem
.ReadString(str
);
3195 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
3197 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
3198 Mem
.ReadBoolean(boo
);
3199 // Çàïóñêàåì ýòó ìóçûêó:
3200 gMusic
.SetByName(str
);
3201 gMusic
.SpecPause
:= boo
;
3204 gMusic
.SetPosition(dw
);
3207 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3208 Mem
.ReadInt(gTotalMonsters
);
3211 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3212 if gGameSettings
.GameMode
= GM_CTF
then
3214 // Ôëàã Êðàñíîé êîìàíäû:
3215 LoadFlag(@gFlags
[FLAG_RED
]);
3216 // Ôëàã Ñèíåé êîìàíäû:
3217 LoadFlag(@gFlags
[FLAG_BLUE
]);
3221 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3222 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3224 // Î÷êè Êðàñíîé êîìàíäû:
3225 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3226 // Î÷êè Ñèíåé êîìàíäû:
3227 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3233 // trace liquid, stepping by `dx` and `dy`
3234 // return last seen liquid coords, and `false` if we're started outside of the liquid
3235 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3237 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3241 // started outside of the liquid?
3242 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3243 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3249 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit