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}
24 e_graphics
, g_basic
, MAPDEF
, g_textures
,
25 g_phys
, wadreader
, g_panel
, g_grid
, md5
, binheap
, xprofiler
, xparser
, xdynrec
;
39 PRespawnPoint
= ^TRespawnPoint
;
40 TRespawnPoint
= record
42 Direction
: TDirection
;
46 PFlagPoint
= ^TFlagPoint
;
47 TFlagPoint
= TRespawnPoint
;
55 CaptureTime
: LongWord;
56 Animation
: TAnimation
;
57 Direction
: TDirection
;
60 function g_Map_Load(Res
: String): Boolean;
61 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
62 function g_Map_GetMapsList(WADName
: String): SArray
;
63 function g_Map_Exist(Res
: String): Boolean;
64 procedure g_Map_Free(freeTextures
: Boolean=true);
65 procedure g_Map_Update();
67 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
69 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
); // unaccelerated
70 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
72 procedure g_Map_DrawBack(dx
, dy
: Integer);
73 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
74 PanelType
: Word; b1x3
: Boolean=false): Boolean;
75 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
77 procedure g_Map_EnableWallGUID (pguid
: Integer);
78 procedure g_Map_DisableWallGUID (pguid
: Integer);
79 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
82 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
83 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
84 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
86 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
88 procedure g_Map_ReAdd_DieTriggers();
89 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
91 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
92 function g_Map_GetPointCount(PointType
: Byte): Word;
94 function g_Map_HaveFlagPoints(): Boolean;
96 procedure g_Map_ResetFlag(Flag
: Byte);
97 procedure g_Map_DrawFlags();
99 procedure g_Map_SaveState (st
: TStream
);
100 procedure g_Map_LoadState (st
: TStream
);
102 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
104 // returns panel or nil
105 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
106 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
108 // returns panel or nil
109 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
110 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
113 TForEachPanelCB
= function (pan
: TPanel
): Boolean is nested
; // return `true` to stop
115 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
116 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
118 // trace liquid, stepping by `dx` and `dy`
119 // return last seen liquid coords, and `false` if we're started outside of the liquid
120 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
123 // return `true` from `cb` to stop
124 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
126 procedure g_Map_NetSendInterestingPanels (); // yay!
129 procedure g_Map_ProfilersBegin ();
130 procedure g_Map_ProfilersEnd ();
133 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
136 function g_Map_MinX (): Integer; inline;
137 function g_Map_MinY (): Integer; inline;
138 function g_Map_MaxX (): Integer; inline;
139 function g_Map_MaxY (): Integer; inline;
147 function g_Texture_NumNameFindStart(name
: String): Boolean;
148 function g_Texture_NumNameFindNext(var newName
: String): Byte;
151 RESPAWNPOINT_PLAYER1
= 1;
152 RESPAWNPOINT_PLAYER2
= 2;
154 RESPAWNPOINT_RED
= 4;
155 RESPAWNPOINT_BLUE
= 5;
163 FLAG_STATE_NORMAL
= 1;
164 FLAG_STATE_DROPPED
= 2;
165 FLAG_STATE_CAPTURED
= 3;
166 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
167 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
169 FLAG_TIME
= 720; // 20 seconds
171 SKY_STRETCH
: Single = 1.5;
186 // sorted by draw priority
187 GridTagBack
= 1 shl 0; // gRenderBackgrounds
188 GridTagStep
= 1 shl 1; // gSteps
189 GridTagWall
= 1 shl 2; // gWalls
190 GridTagDoor
= 1 shl 3; // gWalls
191 GridTagAcid1
= 1 shl 4; // gAcid1
192 GridTagAcid2
= 1 shl 5; // gAcid2
193 GridTagWater
= 1 shl 6; // gWater
194 GridTagFore
= 1 shl 7; // gRenderForegrounds
195 // the following are invisible
196 GridTagLift
= 1 shl 8; // gLifts
197 GridTagBlockMon
= 1 shl 9; // gBlockMon
199 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
200 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
202 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
207 gRenderBackgrounds
: TPanelArray
;
208 gRenderForegrounds
: TPanelArray
;
209 gWater
, gAcid1
, gAcid2
: TPanelArray
;
212 gBlockMon
: TPanelArray
;
213 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
214 //gDOMFlags: array of TFlag;
217 gDoorMap
: array of array of DWORD
;
218 gLiftMap
: array of array of DWORD
;
219 gWADHash
: TMD5Digest
;
220 BackID
: DWORD
= DWORD(-1);
221 gExternalResources
: TStringList
;
222 gMovingWallIds
: array of Integer = nil;
224 gdbg_map_use_accel_render
: Boolean = true;
225 gdbg_map_use_accel_coldet
: Boolean = true;
226 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
227 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
229 gCurrentMap
: TDynRecord
= nil;
230 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
233 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
237 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
240 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
246 e_input
, g_main
, e_log
, e_texture
, g_items
, g_gfx
, g_console
,
247 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
248 g_options
, g_triggers
, g_player
,
249 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
250 utils
, sfs
, xstreams
, hashtable
,
251 ImagingTypes
, Imaging
, ImagingUtility
,
252 ImagingGif
, ImagingNetworkGraphics
;
255 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
256 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
257 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
260 // ////////////////////////////////////////////////////////////////////////// //
261 procedure mapWarningCB (const msg
: AnsiString; line
, col
: Integer);
265 e_LogWritefln('parse error at (%s,%s): %s', [line
, col
, msg
], TMsgType
.Warning
);
269 e_LogWritefln('parse error: %s', [msg
], TMsgType
.Warning
);
274 // ////////////////////////////////////////////////////////////////////////// //
276 panByGUID
: array of TPanel
= nil;
279 // ////////////////////////////////////////////////////////////////////////// //
280 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
282 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
283 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
287 // return `true` from `cb` to stop
288 function g_Map_ForEachPanel (cb
: TForEachPanelCB
): TPanel
;
293 if not assigned(cb
) then exit
;
294 for pan
in panByGUID
do
296 if cb(pan
) then begin result
:= pan
; exit
; end;
301 procedure g_Map_NetSendInterestingPanels ();
305 if g_Game_IsServer
and g_Game_IsNet
then
307 for pan
in panByGUID
do
309 if pan
.gncNeedSend
then MH_SEND_PanelState(pan
.guid
);
315 // ////////////////////////////////////////////////////////////////////////// //
316 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
317 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
318 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
319 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
322 // ////////////////////////////////////////////////////////////////////////// //
324 dfmapdef
: TDynMapDef
= nil;
327 procedure loadMapDefinition ();
329 pr
: TTextParser
= nil;
333 if (dfmapdef
<> nil) then exit
;
336 e_LogWritefln('parsing "mapdef.txt"...', []);
337 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
338 e_LogWritefln('found local "%smapdef.txt"', [DataDir
]);
345 WAD
:= TWADFile
.Create();
346 if not WAD
.ReadFile(GameWAD
) then
348 //raise Exception.Create('cannot load "game.wad"');
353 st
:= WAD
.openFileStream('mapdef.txt');
360 //raise Exception.Create('cannot open "mapdef.txt"');
361 e_LogWriteln('using default "mapdef.txt"...');
362 pr
:= TStrTextParser
.Create(defaultMapDef
);
366 pr
:= TFileTextParser
.Create(st
);
368 except on e
: Exception
do
370 e_LogWritefln('something is VERY wrong here! -- ', [e
.message]);
376 dfmapdef
:= TDynMapDef
.Create(pr
);
378 on e
: TDynParseException
do
379 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
381 raise Exception
.CreateFmt('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.tokLine
, pr
.tokCol
, e
.message]);
389 // ////////////////////////////////////////////////////////////////////////// //
390 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
392 wst
: TSFSMemoryChunkStream
= nil;
395 if (dataLen
< 4) then exit
;
397 if (dfmapdef
= nil) then writeln('need to load mapdef');
399 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
401 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
403 result
:= dfmapdef
.parseMap(wst
);
405 on e
: TDynParseException
do
407 e_LogWritefln('ERROR at (%s,%s): %s', [e
.tokLine
, e
.tokCol
, e
.message]);
414 e_LogWritefln('ERROR: %s', [e
.message]);
421 //e_LogWriteln('map parsed.');
425 // ////////////////////////////////////////////////////////////////////////// //
427 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
428 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
429 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
432 function g_Texture_NumNameFindStart(name
: String): Boolean;
440 NNF_CurrentNum
:= -1;
442 for i
:= Length(name
) downto 1 do
443 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
445 if i
= Length(name
) then
446 begin // Íåò öèôð â êîíöå ñòðîêè
451 NNF_PureName
:= Copy(name
, 1, i
);
457 // Íå ïåðåâåñòè â ÷èñëî:
458 if not TryStrToInt(name
, NNF_FirstNum
) then
467 function g_Texture_NumNameFindNext(var newName
: String): Byte;
469 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
472 Result
:= NNF_NO_NAME
;
476 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
478 if NNF_CurrentNum
< NNF_FirstNum
then
479 Result
:= NNF_NAME_BEFORE
481 if NNF_CurrentNum
> NNF_FirstNum
then
482 Result
:= NNF_NAME_AFTER
484 Result
:= NNF_NAME_EQUALS
;
490 // ////////////////////////////////////////////////////////////////////////// //
491 function panelTypeToTag (panelType
: Word): Integer;
494 PANEL_WALL
: result
:= GridTagWall
; // gWalls
495 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
496 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
497 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
498 PANEL_WATER
: result
:= GridTagWater
; // gWater
499 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
500 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
501 PANEL_STEP
: result
:= GridTagStep
; // gSteps
502 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
503 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
504 else result
:= GridTagInvalid
;
509 function dplLess (a
, b
: TObject
): Boolean;
515 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
516 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
517 result
:= (pa
.arrIdx
< pb
.arrIdx
);
520 procedure dplClear ();
522 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
527 Textures
: TLevelTextureArray
= nil;
528 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
529 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
530 RespawnPoints
: array of TRespawnPoint
;
531 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
532 //DOMFlagPoints: Array of TFlagPoint;
535 procedure g_Map_ProfilersBegin ();
537 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
538 profMapCollision
.mainBegin(g_profile_collision
);
540 if g_profile_collision
then
542 profMapCollision
.sectionBegin('*solids');
543 profMapCollision
.sectionEnd();
544 profMapCollision
.sectionBegin('liquids');
545 profMapCollision
.sectionEnd();
549 procedure g_Map_ProfilersEnd ();
551 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
555 // wall index in `gWalls` or -1
556 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
560 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
561 if (result
<> nil) then
563 if (hitx
<> nil) then hitx
^ := ex
;
564 if (hity
<> nil) then hity
^ := ey
;
568 if (hitx
<> nil) then hitx
^ := x1
;
569 if (hity
<> nil) then hity
^ := y1
;
573 // returns panel or nil
574 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
578 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
579 if (result
<> nil) then
581 if (hitx
<> nil) then hitx
^ := ex
;
582 if (hity
<> nil) then hity
^ := ey
;
586 if (hitx
<> nil) then hitx
^ := x1
;
587 if (hity
<> nil) then hity
^ := y1
;
592 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
594 function checker (pan
: TPanel
; tag
: Integer): Boolean;
597 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
599 result := pan.Enabled; // stop if wall is enabled
604 if ((tag
and GridTagLift
) <> 0) then
606 // stop if the lift of the right type
608 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
609 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
610 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
611 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
615 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
619 tagmask
: Integer = 0;
623 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
624 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
625 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
626 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
627 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
628 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
629 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
631 if (tagmask
= 0) then exit
;// just in case
632 if ((tagmask
and GridTagLift
) <> 0) then
635 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
640 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
645 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
648 if (tagmask
= 0) then exit
;
649 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
653 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
655 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
656 (Texture
= TEXTURE_NAME_ACID1
) or
657 (Texture
= TEXTURE_NAME_ACID2
);
660 procedure CreateDoorMap();
662 PanelArray
: Array of record
668 a
, b
, c
, m
, i
, len
: Integer;
676 SetLength(PanelArray
, len
);
678 for a
:= 0 to High(gWalls
) do
679 if gWalls
[a
].Door
then
681 PanelArray
[i
].X
:= gWalls
[a
].X
;
682 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
683 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
684 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
685 PanelArray
[i
].Active
:= True;
686 PanelArray
[i
].PanelID
:= a
;
692 SetLength(PanelArray
, len
);
703 SetLength(gDoorMap
, 0);
705 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
708 if PanelArray
[a
].Active
then
710 PanelArray
[a
].Active
:= False;
711 m
:= Length(gDoorMap
);
712 SetLength(gDoorMap
, m
+1);
713 SetLength(gDoorMap
[m
], 1);
714 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
722 if PanelArray
[b
].Active
then
723 for c
:= 0 to High(gDoorMap
[m
]) do
724 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
725 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
726 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
727 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
728 gWalls
[gDoorMap
[m
, c
]].X
,
729 gWalls
[gDoorMap
[m
, c
]].Y
,
730 gWalls
[gDoorMap
[m
, c
]].Width
,
731 gWalls
[gDoorMap
[m
, c
]].Height
) then
733 PanelArray
[b
].Active
:= False;
734 SetLength(gDoorMap
[m
],
735 Length(gDoorMap
[m
])+1);
736 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
742 g_Game_StepLoading();
748 procedure CreateLiftMap();
750 PanelArray
: Array of record
755 a
, b
, c
, len
, i
, j
: Integer;
761 len
:= Length(gLifts
);
762 SetLength(PanelArray
, len
);
764 for a
:= 0 to len
-1 do
766 PanelArray
[a
].X
:= gLifts
[a
].X
;
767 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
768 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
769 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
770 PanelArray
[a
].Active
:= True;
773 SetLength(gLiftMap
, len
);
776 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
778 for a
:= 0 to len
-1 do
779 if PanelArray
[a
].Active
then
781 PanelArray
[a
].Active
:= False;
782 SetLength(gLiftMap
[i
], 32);
790 for b
:= 0 to len
-1 do
791 if PanelArray
[b
].Active
then
793 if g_CollideAround(PanelArray
[b
].X
,
796 PanelArray
[b
].Height
,
797 PanelArray
[gLiftMap
[i
, c
]].X
,
798 PanelArray
[gLiftMap
[i
, c
]].Y
,
799 PanelArray
[gLiftMap
[i
, c
]].Width
,
800 PanelArray
[gLiftMap
[i
, c
]].Height
) then
802 PanelArray
[b
].Active
:= False;
804 if j
> High(gLiftMap
[i
]) then
805 SetLength(gLiftMap
[i
],
806 Length(gLiftMap
[i
])+32);
815 SetLength(gLiftMap
[i
], j
+1);
818 g_Game_StepLoading();
821 SetLength(gLiftMap
, i
);
826 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer): Integer;
829 panels
: ^TPanelArray
;
835 case PanelRec
.PanelType
of
836 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
837 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
838 PANEL_FORE
: panels
:= @gRenderForegrounds
;
839 PANEL_WATER
: panels
:= @gWater
;
840 PANEL_ACID1
: panels
:= @gAcid1
;
841 PANEL_ACID2
: panels
:= @gAcid2
;
842 PANEL_STEP
: panels
:= @gSteps
;
843 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
844 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
848 len
:= Length(panels
^);
849 SetLength(panels
^, len
+1);
851 pguid
:= Length(panByGUID
);
852 SetLength(panByGUID
, pguid
+1); //FIXME!
853 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
855 assert(pguid
< Length(panByGUID
));
856 panByGUID
[pguid
] := pan
;
860 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
862 PanelRec
.user
['panel_guid'] := pguid
;
869 function CreateNullTexture(RecName
: String): Integer;
871 RecName
:= toLowerCase1251(RecName
);
872 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
873 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
875 SetLength(Textures
, Length(Textures
)+1);
876 result
:= High(Textures
);
878 with Textures
[High(Textures
)] do
880 TextureName
:= RecName
;
884 TextureID
:= LongWord(TEXTURE_NONE
);
887 TextNameHash
.put(RecName
, result
);
891 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
894 TextureData
: Pointer;
896 a
, ResLength
: Integer;
898 RecName
:= toLowerCase1251(RecName
);
899 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
900 if TextNameHash
.get(RecName
, result
) then
903 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
909 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
912 if Textures <> nil then
914 for a := 0 to High(Textures) do
916 if (Textures[a].TextureName = RecName) then
917 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
918 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
926 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
927 if (RecName
= TEXTURE_NAME_WATER
) or
928 (RecName
= TEXTURE_NAME_ACID1
) or
929 (RecName
= TEXTURE_NAME_ACID2
) then
931 SetLength(Textures
, Length(Textures
)+1);
933 with Textures
[High(Textures
)] do
935 TextureName
:= RecName
;
936 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
937 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
938 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
943 result
:= High(Textures
);
944 TextNameHash
.put(RecName
, result
);
948 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
949 WADName
:= g_ExtractWadName(RecName
);
951 WAD
:= TWADFile
.Create();
953 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
955 WAD
.ReadFile(WADName
);
959 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
961 FreeMem(TextureData);
962 RecName := 'COMMON\ALIEN';
966 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
968 SetLength(Textures
, Length(Textures
)+1);
969 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
971 SetLength(Textures
, Length(Textures
)-1);
974 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
975 FreeMem(TextureData
);
976 Textures
[High(Textures
)].TextureName
:= RecName
;
977 Textures
[High(Textures
)].Anim
:= False;
979 result
:= High(Textures
);
980 TextNameHash
.put(RecName
, result
);
982 else // Íåò òàêîãî ðåóñðñà â WAD'å
984 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
985 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
986 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
988 e_WriteLog(Format('Error loading texture %s', [RecName
]), TMsgType
.Warning
);
989 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
991 BadTextNameHash
.put(RecName
, -1);
998 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
1001 TextureWAD
: PChar = nil;
1002 TextData
: Pointer = nil;
1003 TextureData
: Pointer = nil;
1007 TextureResource
: String;
1008 _width
, _height
, _framecount
, _speed
: Integer;
1009 _backanimation
: Boolean;
1011 ia
: TDynImageDataArray
= nil;
1012 f
, c
, frdelay
, frloop
: Integer;
1014 RecName
:= toLowerCase1251(RecName
);
1015 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
1016 if TextNameHash
.get(RecName
, result
) then
1019 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
1025 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
1027 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1028 if BadTextNameHash
.get(RecName
, f
) then
1030 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
1034 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
1035 WADName
:= g_ExtractWadName(RecName
);
1037 WAD
:= TWADFile
.Create();
1039 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
1041 WAD
.ReadFile(WADName
);
1043 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
1045 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1046 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1048 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1049 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1051 BadTextNameHash
.put(RecName
, -1);
1056 if WADName = Map then
1058 //FreeMem(TextureWAD);
1059 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1065 if ResLength
< 6 then
1067 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), TMsgType
.Warning
);
1068 BadTextNameHash
.put(RecName
, -1);
1072 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1073 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1074 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1076 // íåò, ýòî ñóïåðìåí!
1077 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1079 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), TMsgType
.Warning
);
1080 BadTextNameHash
.put(RecName
, -1);
1084 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1085 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1087 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), TMsgType
.Warning
);
1088 BadTextNameHash
.put(RecName
, -1);
1092 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1094 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1095 if TextureResource
= '' then
1097 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), TMsgType
.Warning
);
1098 BadTextNameHash
.put(RecName
, -1);
1102 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1103 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1104 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1105 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1106 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1111 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1112 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1114 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), TMsgType
.Warning
);
1115 BadTextNameHash
.put(RecName
, -1);
1122 SetLength(Textures
, Length(Textures
)+1);
1123 with Textures
[High(Textures
)] do
1125 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1126 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1128 TextureName
:= RecName
;
1132 FramesCount
:= _framecount
;
1134 result
:= High(Textures
);
1135 TextNameHash
.put(RecName
, result
);
1139 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1140 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1142 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), TMsgType
.Warning
);
1144 BadTextNameHash
.put(RecName
, -1);
1150 // try animated image
1152 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1153 if length(imgfmt) = 0 then
1155 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1159 GlobalMetadata
.ClearMetaItems();
1160 GlobalMetadata
.ClearMetaItemsForSaving();
1161 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1163 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), TMsgType
.Warning
);
1164 BadTextNameHash
.put(RecName
, -1);
1167 if length(ia
) = 0 then
1169 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), TMsgType
.Warning
);
1170 BadTextNameHash
.put(RecName
, -1);
1177 _width
:= ia
[0].width
;
1178 _height
:= ia
[0].height
;
1179 _framecount
:= length(ia
);
1181 _backanimation
:= false;
1184 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1186 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1188 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1190 if f
< 0 then f
:= 0;
1193 if c
< 13 then c
:= 0 else c
:= 1;
1195 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1200 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1202 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1204 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1206 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1210 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1211 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1212 f
:= ord(_backanimation
);
1213 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
]), TMsgType
.Notify
);
1215 SetLength(Textures
, Length(Textures
)+1);
1216 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1217 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1219 Textures
[High(Textures
)].TextureName
:= RecName
;
1220 Textures
[High(Textures
)].Width
:= _width
;
1221 Textures
[High(Textures
)].Height
:= _height
;
1222 Textures
[High(Textures
)].Anim
:= True;
1223 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1224 Textures
[High(Textures
)].Speed
:= _speed
;
1225 result
:= High(Textures
);
1226 TextNameHash
.put(RecName
, result
);
1227 //writeln(' CREATED!');
1231 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1232 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1234 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), TMsgType
.Warning
);
1236 BadTextNameHash
.put(RecName
, -1);
1240 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1243 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1244 if (TextData
<> nil) then FreeMem(TextData
);
1245 if (TextureData
<> nil) then FreeMem(TextureData
);
1249 procedure CreateItem(Item
: TDynRecord
);
1251 if g_Game_IsClient
then Exit
;
1253 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1254 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1257 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1258 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1261 procedure CreateArea(Area
: TDynRecord
);
1266 case Area
.AreaType
of
1267 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1268 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1270 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1271 with RespawnPoints
[High(RespawnPoints
)] do
1275 Direction
:= TDirection(Area
.Direction
);
1277 case Area
.AreaType
of
1278 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1279 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1280 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1281 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1282 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1287 AREA_REDFLAG
, AREA_BLUEFLAG
:
1289 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1291 if FlagPoints
[a
] <> nil then Exit
;
1295 with FlagPoints
[a
]^ do
1297 X
:= Area
.X
-FLAGRECT
.X
;
1298 Y
:= Area
.Y
-FLAGRECT
.Y
;
1299 Direction
:= TDirection(Area
.Direction
);
1305 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1306 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1309 Animation
:= TAnimation
.Create(id
, True, 8);
1310 Obj
.Rect
:= FLAGRECT
;
1318 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1319 with DOMFlagPoints[High(DOMFlagPoints)] do
1323 Direction := TDirection(Area.Direction);
1326 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1331 function CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer): Integer;
1336 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1340 mapId
:= Trigger
.id
;
1341 mapIndex
:= amapIdx
;
1344 Width
:= Trigger
.Width
;
1345 Height
:= Trigger
.Height
;
1346 Enabled
:= Trigger
.Enabled
;
1347 TexturePanelGUID
:= atpanid
;
1348 TriggerType
:= Trigger
.TriggerType
;
1349 ActivateType
:= Trigger
.ActivateType
;
1350 Keys
:= Trigger
.Keys
;
1351 trigPanelGUID
:= atrigpanid
;
1354 result
:= Integer(g_Triggers_Create(_trigger
, Trigger
));
1357 procedure CreateMonster(monster
: TDynRecord
);
1362 if g_Game_IsClient
then Exit
;
1364 if (gGameSettings
.GameType
= GT_SINGLE
)
1365 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1367 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1369 if gTriggers
<> nil then
1371 for a
:= 0 to High(gTriggers
) do
1373 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1375 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1376 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1381 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1385 procedure g_Map_ReAdd_DieTriggers();
1387 function monsDieTrig (mon
: TMonster
): Boolean;
1390 //tw: TStrTextWriter;
1392 result
:= false; // don't stop
1393 mon
.ClearTriggers();
1394 for a
:= 0 to High(gTriggers
) do
1396 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1398 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1400 tw := TStrTextWriter.Create();
1402 gTriggers[a].trigData.writeTo(tw);
1403 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1408 if (gTriggers
[a
].trigDataRec
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1414 if g_Game_IsClient
then Exit
;
1416 g_Mons_ForEach(monsDieTrig
);
1419 function extractWadName(resourceName
: string): string;
1423 posN
:= Pos(':', resourceName
);
1425 Result
:= Copy(resourceName
, 0, posN
-1)
1430 procedure addResToExternalResList(res
: string);
1432 res
:= extractWadName(res
);
1433 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1434 gExternalResources
.Add(res
);
1437 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1439 //textures: TTexturesRec1Array;
1440 //textures: TDynField;
1442 //mapHeader: TMapHeaderRec_1;
1444 //resFile: String = '';
1446 if gExternalResources
= nil then
1447 gExternalResources
:= TStringList
.Create
;
1449 gExternalResources
.Clear
;
1453 textures := GetTextures(map);
1454 for i := 0 to High(textures) do
1456 addResToExternalResList(resFile);
1460 textures := map['texture'];
1461 if (textures <> nil) then
1463 for trec in textures do
1465 addResToExternalResList(resFile);
1472 //mapHeader := GetMapHeader(map);
1474 addResToExternalResList(map
.MusicName
);
1475 addResToExternalResList(map
.SkyName
);
1479 procedure mapCreateGrid ();
1481 mapX0
: Integer = $3fffffff;
1482 mapY0
: Integer = $3fffffff;
1483 mapX1
: Integer = -$3fffffff;
1484 mapY1
: Integer = -$3fffffff;
1486 procedure calcBoundingBox (constref panels
: TPanelArray
);
1491 for idx
:= 0 to High(panels
) do
1494 if not pan
.visvalid
then continue
;
1495 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1496 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1497 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1498 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1499 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1503 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1509 //tag := panelTypeToTag(tag);
1510 for idx
:= 0 to High(panels
) do
1513 if not pan
.visvalid
then continue
;
1514 if (pan
.proxyId
<> -1) then
1516 {$IF DEFINED(D2F_DEBUG)}
1517 e_WriteLog(Format('DUPLICATE wall #%d(%d) enabled (%d); type:%08x', [Integer(idx
), Integer(pan
.proxyId
), Integer(mapGrid
.proxyEnabled
[pan
.proxyId
]), pan
.PanelType
]), TMsgType
.Notify
);
1521 case pan
.PanelType
of
1522 PANEL_WALL
: newtag
:= GridTagWall
;
1523 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1524 PANEL_BACK
: newtag
:= GridTagBack
;
1525 PANEL_FORE
: newtag
:= GridTagFore
;
1526 PANEL_WATER
: newtag
:= GridTagWater
;
1527 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1528 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1529 PANEL_STEP
: newtag
:= GridTagStep
;
1530 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1531 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1532 else continue
; // oops
1536 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1537 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1538 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1539 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1541 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1543 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1554 calcBoundingBox(gWalls
);
1555 calcBoundingBox(gRenderBackgrounds
);
1556 calcBoundingBox(gRenderForegrounds
);
1557 calcBoundingBox(gWater
);
1558 calcBoundingBox(gAcid1
);
1559 calcBoundingBox(gAcid2
);
1560 calcBoundingBox(gSteps
);
1561 calcBoundingBox(gLifts
);
1562 calcBoundingBox(gBlockMon
);
1564 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1566 if (mapX0
> 0) then mapX0
:= 0;
1567 if (mapY0
> 0) then mapY0
:= 0;
1569 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1570 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1572 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1573 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1575 addPanelsToGrid(gWalls
);
1576 addPanelsToGrid(gRenderBackgrounds
);
1577 addPanelsToGrid(gRenderForegrounds
);
1578 addPanelsToGrid(gWater
);
1579 addPanelsToGrid(gAcid1
);
1580 addPanelsToGrid(gAcid2
);
1581 addPanelsToGrid(gSteps
);
1582 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1583 addPanelsToGrid(gBlockMon
);
1585 mapGrid
.dumpStats();
1587 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1591 function g_Map_Load(Res
: String): Boolean;
1593 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1594 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1598 //TexturePanel: Integer;
1601 trigrec
: TDynRecord
;
1603 texPanelIdx
: Integer;
1604 texPanel
: TDynRecord
;
1606 actPanelIdx
: Integer;
1607 actPanel
: TDynRecord
;
1611 //mapReader: TDynRecord = nil;
1612 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1613 panels
: TDynField
= nil; //TPanelsRec1Array;
1614 items
: TDynField
= nil; //TItemsRec1Array;
1615 monsters
: TDynField
= nil; //TMonsterRec1Array;
1616 areas
: TDynField
= nil; //TAreasRec1Array;
1617 triggers
: TDynField
= nil; //TTriggersRec1Array;
1620 AddTextures
: TAddTextureArray
;
1621 TriggersTable
: array of TTRec
;
1622 FileName
, mapResName
, s
, TexName
: String;
1625 ok
, isAnim
: Boolean;
1626 CurTex
, ntn
: Integer;
1627 rec
, texrec
: TDynRecord
;
1629 pannum
, trignum
, cnt
, tgpid
: Integer;
1631 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1632 //moveActive: Boolean;
1634 mapOk
: Boolean = false;
1639 //gCurrentMap.Free();
1640 //gCurrentMap := nil;
1645 gMapInfo
.Map
:= Res
;
1646 TriggersTable
:= nil;
1649 sfsGCDisable(); // temporary disable removing of temporary volumes
1651 // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû)
1652 if (gCurrentMap
= nil) then
1654 FileName
:= g_ExtractWadName(Res
);
1655 e_WriteLog('Loading map WAD: '+FileName
, TMsgType
.Notify
);
1656 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1658 WAD
:= TWADFile
.Create();
1659 if not WAD
.ReadFile(FileName
) then
1661 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1666 //k8: why loader ignores path here?
1667 mapResName
:= g_ExtractFileName(Res
);
1668 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1670 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1679 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1685 e_LogWritefln('Loading map: %s', [mapResName
], TMsgType
.Notify
);
1686 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1688 stt
:= getTimeMicro();
1691 gCurrentMap
:= g_Map_ParseMap(Data
, Len
);
1694 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1696 gCurrentMapFileName
:= '';
1702 if (gCurrentMap
= nil) then
1704 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1705 gCurrentMapFileName
:= '';
1711 stt
:= getTimeMicro();
1714 //gCurrentMap := mapReader;
1716 generateExternalResourcesList(gCurrentMap
);
1717 mapTextureList
:= gCurrentMap
['texture'];
1718 // get all other lists here too
1719 panels
:= gCurrentMap
['panel'];
1720 triggers
:= gCurrentMap
['trigger'];
1721 items
:= gCurrentMap
['item'];
1722 areas
:= gCurrentMap
['area'];
1723 monsters
:= gCurrentMap
['monster'];
1725 // Çàãðóçêà îïèñàíèÿ êàðòû:
1726 e_WriteLog(' Reading map info...', TMsgType
.Notify
);
1727 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1731 Name
:= gCurrentMap
.MapName
;
1732 Description
:= gCurrentMap
.MapDesc
;
1733 Author
:= gCurrentMap
.MapAuthor
;
1734 MusicName
:= gCurrentMap
.MusicName
;
1735 SkyName
:= gCurrentMap
.SkyName
;
1736 Height
:= gCurrentMap
.Height
;
1737 Width
:= gCurrentMap
.Width
;
1740 // Çàãðóçêà òåêñòóð:
1741 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1742 // Äîáàâëåíèå òåêñòóð â Textures[]:
1743 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1745 e_WriteLog(' Loading textures:', TMsgType
.Notify
);
1746 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1749 for rec
in mapTextureList
do
1753 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1754 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), TMsgType
.Notify
);
1756 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1759 // Àíèìèðîâàííàÿ òåêñòóðà
1760 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1761 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1766 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1767 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1769 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1771 rec
.tagInt
:= ntn
; // remember texture number
1772 g_Game_StepLoading();
1775 // set panel tagInt to texture index
1776 if (panels
<> nil) then
1778 for rec
in panels
do
1780 texrec
:= rec
.TextureRec
;
1781 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1786 // Çàãðóçêà òðèããåðîâ
1787 gTriggerClientID
:= 0;
1788 e_WriteLog(' Loading triggers...', TMsgType
.Notify
);
1789 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1792 e_WriteLog(' Loading panels...', TMsgType
.Notify
);
1793 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1795 // check texture numbers for panels
1796 if (panels
<> nil) and (panels
.count
> 0) then
1798 for rec
in panels
do
1800 if (rec
.tagInt
< 0) then
1802 e_WriteLog('error loading map: invalid texture index for panel', TMsgType
.Fatal
);
1806 gCurrentMapFileName
:= '';
1812 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1813 if (triggers
<> nil) and (triggers
.count
> 0) then
1815 e_WriteLog(' Setting up trigger table...', TMsgType
.Notify
);
1816 //SetLength(TriggersTable, triggers.count);
1817 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1819 SetLength(TriggersTable
, triggers
.count
);
1821 for rec
in triggers
do
1824 pttit
:= @TriggersTable
[trignum
];
1825 pttit
.trigrec
:= rec
;
1826 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1827 pttit
.texPanelIdx
:= -1; // will be fixed later
1828 pttit
.texPanel
:= rec
.TexturePanelRec
;
1830 pttit
.actPanelIdx
:= -1;
1831 if (rec
.trigRec
<> nil) then pttit
.actPanel
:= rec
.trigRec
.tgPanelRec
else pttit
.actPanel
:= nil;
1833 if (pttit
.texPanel
<> nil) then pttit
.texPanel
.userPanelTrigRef
:= true;
1834 if (pttit
.actPanel
<> nil) then pttit
.actPanel
.userPanelTrigRef
:= true;
1836 g_Game_StepLoading();
1841 if (panels
<> nil) and (panels
.count
> 0) then
1843 e_WriteLog(' Setting up trigger links...', TMsgType
.Notify
);
1844 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1847 for rec
in panels
do
1850 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1852 SetLength(AddTextures
, 0);
1856 if (mapTextureList
<> nil) then
1858 texrec
:= rec
.TextureRec
;
1859 ok
:= (texrec
<> nil);
1864 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1865 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1867 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1869 if rec
.userPanelTrigRef
then
1871 // e_LogWritefln('trigref for panel %s', [pannum]);
1879 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1880 s
:= texrec
.Resource
;
1882 // Ñïåö-òåêñòóðû çàïðåùåíû
1883 if g_Map_IsSpecialTexture(s
) then
1889 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1890 ok
:= g_Texture_NumNameFindStart(s
);
1893 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1894 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1897 k
:= NNF_NAME_BEFORE
;
1898 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1899 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1901 k
:= g_Texture_NumNameFindNext(TexName
);
1903 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1905 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1908 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1910 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1911 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1912 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1915 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1917 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1918 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1919 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1924 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1926 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1927 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1928 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1931 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1933 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1934 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1935 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1939 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1943 for c := 0 to High(Textures) do
1945 if (Textures[c].TextureName = TexName) then
1947 SetLength(AddTextures, Length(AddTextures)+1);
1948 AddTextures[High(AddTextures)].Texture := c;
1949 AddTextures[High(AddTextures)].Anim := isAnim;
1954 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1956 SetLength(AddTextures
, Length(AddTextures
)+1);
1957 AddTextures
[High(AddTextures
)].Texture
:= c
;
1958 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1964 if k
= NNF_NAME_EQUALS
then
1966 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1967 SetLength(AddTextures
, Length(AddTextures
)+1);
1968 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1969 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1970 CurTex
:= High(AddTextures
);
1981 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1982 end; // if ok - ññûëàþòñÿ òðèããåðû
1986 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1987 SetLength(AddTextures
, 1);
1988 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1989 AddTextures
[0].Anim
:= false;
1990 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1994 //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);
1996 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1998 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
1999 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
);
2000 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
2001 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
2004 moveSpeed
:= rec
.moveSpeed
;
2005 //moveStart := rec.moveStart;
2006 //moveEnd := rec.moveEnd;
2007 //moveActive := rec['move_active'].value;
2008 if not moveSpeed
.isZero
then
2010 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
2011 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
2012 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2015 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2017 g_Game_StepLoading();
2021 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2022 for b
:= 0 to High(TriggersTable
) do
2024 if (TriggersTable
[b
].texPanel
<> nil) then TriggersTable
[b
].texPanelIdx
:= TriggersTable
[b
].texPanel
.userPanelId
;
2025 if (TriggersTable
[b
].actPanel
<> nil) then TriggersTable
[b
].actPanelIdx
:= TriggersTable
[b
].actPanel
.userPanelId
;
2028 // create map grid, init other grids (for monsters, for example)
2029 e_WriteLog('Creating map grid', TMsgType
.Notify
);
2032 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2033 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2035 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2036 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2037 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2039 for rec
in triggers
do
2042 tgpid
:= TriggersTable
[trignum
].actPanelIdx
;
2043 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2044 TriggersTable
[trignum
].tnum
:= trignum
;
2045 TriggersTable
[trignum
].id
:= CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanelIdx
, tgpid
);
2049 //FIXME: use hashtable!
2050 for pan
in panByGUID
do
2052 if (pan
.endPosTrigId
>= 0) and (pan
.endPosTrigId
< Length(TriggersTable
)) then
2054 pan
.endPosTrigId
:= TriggersTable
[pan
.endPosTrigId
].id
;
2056 if (pan
.endSizeTrigId
>= 0) and (pan
.endSizeTrigId
< Length(TriggersTable
)) then
2058 pan
.endSizeTrigId
:= TriggersTable
[pan
.endSizeTrigId
].id
;
2062 // Çàãðóçêà ïðåäìåòîâ
2063 e_WriteLog(' Loading items...', TMsgType
.Notify
);
2064 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2066 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2067 if (items
<> nil) and not gLoadGameMode
then
2069 e_WriteLog(' Spawning items...', TMsgType
.Notify
);
2070 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2071 for rec
in items
do CreateItem(rec
);
2074 // Çàãðóçêà îáëàñòåé
2075 e_WriteLog(' Loading areas...', TMsgType
.Notify
);
2076 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2078 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2079 if areas
<> nil then
2081 e_WriteLog(' Creating areas...', TMsgType
.Notify
);
2082 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2083 for rec
in areas
do CreateArea(rec
);
2086 // Çàãðóçêà ìîíñòðîâ
2087 e_WriteLog(' Loading monsters...', TMsgType
.Notify
);
2088 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2090 gTotalMonsters
:= 0;
2092 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2093 if (monsters
<> nil) and not gLoadGameMode
then
2095 e_WriteLog(' Spawning monsters...', TMsgType
.Notify
);
2096 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2097 for rec
in monsters
do CreateMonster(rec
);
2100 //gCurrentMap := mapReader; // this will be our current map now
2101 gCurrentMapFileName
:= Res
;
2105 if (gMapInfo
.SkyName
<> '') then
2107 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, TMsgType
.Notify
);
2108 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2109 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2111 if (FileName
<> '') then FileName
:= GameDir
+'/wads/'+FileName
else FileName
:= g_ExtractWadName(Res
);
2113 if gTextureFilter
then TEXTUREFILTER
:= GL_LINEAR
else TEXTUREFILTER
:= GL_NEAREST
;
2115 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2116 if g_Texture_CreateWAD(BackID
, s
) then
2118 g_Game_SetupScreenSize();
2122 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2125 TEXTUREFILTER
:= GL_NEAREST
;
2131 if gMapInfo
.MusicName
<> '' then
2133 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, TMsgType
.Notify
);
2134 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2135 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2137 if FileName
<> '' then
2138 FileName
:= GameDir
+'/wads/'+FileName
2141 FileName
:= g_ExtractWadName(Res
);
2144 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2145 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2148 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2151 // Îñòàëüíûå óñòàíâêè
2159 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2160 if not gLoadGameMode
then g_GFX_Init();
2162 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2163 mapTextureList
:= nil;
2168 TriggersTable
:= nil;
2171 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2172 if ok
and (not gLoadGameMode
) then
2174 gMusic
.SetByName(gMapInfo
.MusicName
);
2179 gMusic
.SetByName('');
2182 stt
:= getTimeMicro()-stt
;
2183 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2186 sfsGCEnable(); // enable releasing unused volumes
2188 e_ClearInputBuffer(); // why not?
2193 gCurrentMapFileName
:= '';
2197 e_WriteLog('Done loading map.', TMsgType
.Notify
);
2202 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2205 mapReader
: TDynRecord
;
2206 //Header: TMapHeaderRec_1;
2211 FillChar(Result
, SizeOf(Result
), 0);
2212 FileName
:= g_ExtractWadName(Res
);
2214 WAD
:= TWADFile
.Create();
2215 if not WAD
.ReadFile(FileName
) then
2221 //k8: it ignores path again
2222 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2231 mapReader
:= g_Map_ParseMap(Data
, Len
);
2240 if (mapReader
= nil) then exit
;
2242 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2244 Result
.Name
:= mapReader
.MapName
;
2245 Result
.Description
:= mapReader
.MapDesc
;
2247 Result
.Author
:= mapReader
.MapAuthor
;
2248 Result
.Height
:= mapReader
.Height
;
2249 Result
.Width
:= mapReader
.Width
;
2253 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2254 //ZeroMemory(@Header, SizeOf(Header));
2255 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2256 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2258 Result
.Author
:= '';
2266 function g_Map_GetMapsList(WADName
: string): SArray
;
2273 WAD
:= TWADFile
.Create();
2274 if not WAD
.ReadFile(WADName
) then
2279 ResList
:= WAD
.GetMapResources();
2280 if ResList
<> nil then
2282 for a
:= 0 to High(ResList
) do
2284 SetLength(Result
, Length(Result
)+1);
2285 Result
[High(Result
)] := ResList
[a
];
2291 function g_Map_Exist(Res
: string): Boolean;
2294 FileName
, mnn
: string;
2300 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2302 WAD
:= TWADFile
.Create
;
2303 if not WAD
.ReadFile(FileName
) then
2309 ResList
:= WAD
.GetMapResources();
2312 mnn
:= g_ExtractFileName(Res
);
2313 if ResList
<> nil then
2314 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2321 procedure g_Map_Free(freeTextures
: Boolean=true);
2325 procedure FreePanelArray(var panels
: TPanelArray
);
2330 if panels
<> nil then
2332 for i
:= 0 to High(panels
) do
2345 RespawnPoints
:= nil;
2346 if FlagPoints
[FLAG_RED
] <> nil then
2348 Dispose(FlagPoints
[FLAG_RED
]);
2349 FlagPoints
[FLAG_RED
] := nil;
2351 if FlagPoints
[FLAG_BLUE
] <> nil then
2353 Dispose(FlagPoints
[FLAG_BLUE
]);
2354 FlagPoints
[FLAG_BLUE
] := nil;
2356 //DOMFlagPoints := nil;
2360 if (Length(gCurrentMapFileName
) <> 0) then
2362 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2366 e_LogWritefln('g_Map_Free: no previous map.', []);
2369 if freeTextures
then
2371 e_LogWritefln('g_Map_Free: clearing textures...', []);
2372 if (Textures
<> nil) then
2374 for a
:= 0 to High(Textures
) do
2376 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2378 if Textures
[a
].Anim
then
2380 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2384 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2386 e_DeleteTexture(Textures
[a
].TextureID
);
2393 TextNameHash
.Free();
2394 TextNameHash
:= nil;
2395 BadTextNameHash
.Free();
2396 BadTextNameHash
:= nil;
2397 gCurrentMapFileName
:= '';
2404 FreePanelArray(gWalls
);
2405 FreePanelArray(gRenderBackgrounds
);
2406 FreePanelArray(gRenderForegrounds
);
2407 FreePanelArray(gWater
);
2408 FreePanelArray(gAcid1
);
2409 FreePanelArray(gAcid2
);
2410 FreePanelArray(gSteps
);
2411 FreePanelArray(gLifts
);
2412 FreePanelArray(gBlockMon
);
2413 gMovingWallIds
:= nil;
2415 if BackID
<> DWORD(-1) then
2419 e_DeleteTexture(BackID
);
2420 BackID
:= DWORD(-1);
2423 g_Game_StopAllSounds(False);
2425 g_Sound_Delete(gMapInfo
.MusicName
);
2427 gMapInfo
.Name
:= '';
2428 gMapInfo
.Description
:= '';
2429 gMapInfo
.MusicName
:= '';
2430 gMapInfo
.Height
:= 0;
2431 gMapInfo
.Width
:= 0;
2437 procedure g_Map_Update();
2443 procedure UpdatePanelArray(var panels
: TPanelArray
);
2448 for i
:= 0 to High(panels
) do panels
[i
].Update();
2452 if g_dbgpan_mplat_step
then g_dbgpan_mplat_active
:= true;
2454 UpdatePanelArray(gWalls
);
2455 UpdatePanelArray(gRenderBackgrounds
);
2456 UpdatePanelArray(gRenderForegrounds
);
2457 UpdatePanelArray(gWater
);
2458 UpdatePanelArray(gAcid1
);
2459 UpdatePanelArray(gAcid2
);
2460 UpdatePanelArray(gSteps
);
2462 if g_dbgpan_mplat_step
then begin g_dbgpan_mplat_step
:= false; g_dbgpan_mplat_active
:= false; end;
2464 if gGameSettings
.GameMode
= GM_CTF
then
2466 for a
:= FLAG_RED
to FLAG_BLUE
do
2468 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2472 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2474 m
:= g_Obj_Move(@Obj
, True, True);
2476 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2478 // Ñîïðîòèâëåíèå âîçäóõà
2479 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2481 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2482 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2485 gFlags
[a
].CaptureTime
:= 0;
2486 if a
= FLAG_RED
then
2487 s
:= _lc
[I_PLAYER_FLAG_RED
]
2489 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2490 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2492 if g_Game_IsNet
then
2493 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2497 if Count
> 0 then Count
-= 1;
2500 if gPlayers
<> nil then
2502 j
:= Random(Length(gPlayers
)) - 1;
2503 for d
:= 0 to High(gPlayers
) do
2506 if j
> High(gPlayers
) then j
:= 0;
2507 if gPlayers
[j
] <> nil then
2509 if gPlayers
[j
].alive
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2511 if gPlayers
[j
].GetFlag(a
) then Break
;
2524 procedure g_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2526 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2530 if (panels
<> nil) then
2532 // alas, no visible set
2533 for idx
:= 0 to High(panels
) do
2535 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw(hasAmbient
, ambColor
);
2542 PANEL_WALL
: DrawPanels(gWalls
);
2543 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2544 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2545 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2546 PANEL_WATER
: DrawPanels(gWater
);
2547 PANEL_ACID1
: DrawPanels(gAcid1
);
2548 PANEL_ACID2
: DrawPanels(gAcid2
);
2549 PANEL_STEP
: DrawPanels(gSteps
);
2555 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2557 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2559 result
:= false; // don't stop, ever
2560 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2561 gDrawPanelList
.insert(pan
);
2566 //tagmask := panelTypeToTag(PanelType);
2567 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2568 // list will be rendered in `g_game.DrawPlayer()`
2572 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2574 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2576 result
:= false; // don't stop, ever
2577 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2581 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2585 procedure g_Map_DrawBack(dx
, dy
: Integer);
2587 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2588 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2590 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2593 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2594 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2600 if WordBool(PanelType
and PANEL_WALL
) then
2601 if gWalls
<> nil then
2606 if gWalls
[a
].Enabled
and
2607 g_Collide(X
, Y
, Width
, Height
,
2608 gWalls
[a
].X
, gWalls
[a
].Y
,
2609 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2616 if WordBool(PanelType
and PANEL_WATER
) then
2617 if gWater
<> nil then
2622 if g_Collide(X
, Y
, Width
, Height
,
2623 gWater
[a
].X
, gWater
[a
].Y
,
2624 gWater
[a
].Width
, gWater
[a
].Height
) then
2631 if WordBool(PanelType
and PANEL_ACID1
) then
2632 if gAcid1
<> nil then
2637 if g_Collide(X
, Y
, Width
, Height
,
2638 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2639 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2646 if WordBool(PanelType
and PANEL_ACID2
) then
2647 if gAcid2
<> nil then
2652 if g_Collide(X
, Y
, Width
, Height
,
2653 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2654 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2661 if WordBool(PanelType
and PANEL_STEP
) then
2662 if gSteps
<> nil then
2667 if g_Collide(X
, Y
, Width
, Height
,
2668 gSteps
[a
].X
, gSteps
[a
].Y
,
2669 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2676 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2677 if gLifts
<> nil then
2682 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2683 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2684 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2685 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2686 g_Collide(X
, Y
, Width
, Height
,
2687 gLifts
[a
].X
, gLifts
[a
].Y
,
2688 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2695 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2696 if gBlockMon
<> nil then
2698 h
:= High(gBlockMon
);
2702 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2703 g_Collide(X
, Y
, Width
, Height
,
2704 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2705 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2713 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2717 function checkPanels (constref panels
: TPanelArray
): Boolean;
2722 if panels
= nil then exit
;
2723 for a
:= 0 to High(panels
) do
2725 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2728 texid
:= panels
[a
].GetTextureID();
2735 texid
:= LongWord(TEXTURE_NONE
);
2737 if not checkPanels(gWater
) then
2738 if not checkPanels(gAcid1
) then
2739 if not checkPanels(gAcid2
) then exit
;
2744 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2746 SlowMask
= GridTagLift
or GridTagBlockMon
;
2747 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2750 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2752 result := pan.Enabled;
2757 if ((tag
and GridTagLift
) <> 0) then
2760 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2761 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2762 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2763 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2764 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2768 if ((tag
and GridTagBlockMon
) <> 0) then
2770 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2775 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2776 result
:= true; // i found her!
2780 tagmask
: Integer = 0;
2782 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2783 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2784 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2785 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2786 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2787 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2788 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2790 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2792 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2793 if gdbg_map_use_accel_coldet
then
2795 if (Width
= 1) and (Height
= 1) then
2797 if ((tagmask
and SlowMask
) <> 0) then
2800 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2805 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2810 if ((tagmask
and SlowMask
) <> 0) then
2813 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2818 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2824 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2826 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2830 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2832 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2835 // slightly different from the old code, but meh...
2836 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2838 result
:= false; // don't stop, ever
2839 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2842 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2843 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2844 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2847 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2849 texid
:= pan
.GetTextureID();
2850 // water? water has the highest priority, so stop right here
2851 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2853 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2855 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2859 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2860 if gdbg_map_use_accel_coldet
then
2862 texid
:= LongWord(TEXTURE_NONE
);
2863 if (Width
= 1) and (Height
= 1) then
2865 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2869 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2875 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2877 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2881 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2882 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2883 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2886 procedure g_Map_EnableWallGUID (pguid
: Integer);
2890 //pan := gWalls[ID];
2891 pan
:= g_Map_PanelByGUID(pguid
);
2892 if (pan
= nil) then exit
;
2893 if pan
.Enabled
and mapGrid
.proxyEnabled
[pan
.proxyId
] then exit
;
2895 pan
.Enabled
:= True;
2896 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2898 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2899 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2900 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2902 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2903 // mark platform as interesting
2906 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2907 //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);
2912 procedure g_Map_DisableWallGUID (pguid
: Integer);
2916 //pan := gWalls[ID];
2917 pan
:= g_Map_PanelByGUID(pguid
);
2918 if (pan
= nil) then exit
;
2919 if (not pan
.Enabled
) and (not mapGrid
.proxyEnabled
[pan
.proxyId
]) then exit
;
2921 pan
.Enabled
:= False;
2922 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2924 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2925 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2927 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2928 // mark platform as interesting
2931 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2932 //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);
2937 procedure g_Map_SwitchTextureGUID (pguid
: Integer; AnimLoop
: Byte = 0);
2941 tp
:= g_Map_PanelByGUID(pguid
);
2942 if (tp
= nil) then exit
;
2943 tp
.NextTexture(AnimLoop
);
2944 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(pguid
, AnimLoop
);
2948 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2952 //pan := gLifts[ID];
2953 pan
:= g_Map_PanelByGUID(pguid
);
2954 if (pan
= nil) then exit
;
2955 if not pan
.isGLift
then exit
;
2957 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2959 with {gLifts[ID]} pan
do
2963 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2964 //TODO: make separate lift tags, and change tag here
2967 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2968 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2969 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2970 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
2973 //if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(pguid);
2974 // mark platform as interesting
2980 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2983 PointsArray
: Array of TRespawnPoint
;
2986 SetLength(PointsArray
, 0);
2988 if RespawnPoints
= nil then
2991 for a
:= 0 to High(RespawnPoints
) do
2992 if RespawnPoints
[a
].PointType
= PointType
then
2994 SetLength(PointsArray
, Length(PointsArray
)+1);
2995 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2998 if PointsArray
= nil then
3001 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
3005 function g_Map_GetPointCount(PointType
: Byte): Word;
3011 if RespawnPoints
= nil then
3014 for a
:= 0 to High(RespawnPoints
) do
3015 if RespawnPoints
[a
].PointType
= PointType
then
3016 Result
:= Result
+ 1;
3019 function g_Map_HaveFlagPoints(): Boolean;
3021 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
3024 procedure g_Map_ResetFlag(Flag
: Byte);
3026 with gFlags
[Flag
] do
3032 Direction
:= TDirection
.D_LEFT
;
3033 State
:= FLAG_STATE_NONE
;
3034 if FlagPoints
[Flag
] <> nil then
3036 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3037 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3038 Direction
:= FlagPoints
[Flag
]^.Direction
;
3039 State
:= FLAG_STATE_NORMAL
;
3045 procedure g_Map_DrawFlags();
3048 Mirror
: TMirrorType
;
3050 if gGameSettings
.GameMode
<> GM_CTF
then
3053 for i
:= FLAG_RED
to FLAG_BLUE
do
3055 if State
<> FLAG_STATE_CAPTURED
then
3057 if State
= FLAG_STATE_NONE
then
3060 if Direction
= TDirection
.D_LEFT
then
3062 Mirror
:= TMirrorType
.Horizontal
;
3067 Mirror
:= TMirrorType
.None
;
3071 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3073 if g_debug_Frames
then
3075 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3077 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3078 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3085 procedure g_Map_SaveState (st
: TStream
);
3089 procedure savePanels ();
3094 utils
.writeInt(st
, LongInt(Length(panByGUID
)));
3095 for pan
in panByGUID
do pan
.SaveState(st
);
3098 procedure saveFlag (flag
: PFlag
);
3102 utils
.writeSign(st
, 'FLAG');
3103 utils
.writeInt(st
, Byte(0)); // version
3104 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3105 utils
.writeInt(st
, Byte(flag
^.RespawnType
));
3107 utils
.writeInt(st
, Byte(flag
^.State
));
3108 // Íàïðàâëåíèå ôëàãà
3109 if flag
^.Direction
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3110 utils
.writeInt(st
, Byte(b
));
3112 Obj_SaveState(st
, @flag
^.Obj
);
3119 utils
.writeSign(st
, 'MUSI');
3120 utils
.writeInt(st
, Byte(0));
3122 assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3123 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3124 utils
.writeStr(st
, str
);
3125 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3126 utils
.writeInt(st
, LongWord(gMusic
.GetPosition()));
3127 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3128 utils
.writeBool(st
, gMusic
.SpecPause
);
3130 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3131 utils
.writeInt(st
, LongInt(gTotalMonsters
));
3134 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3135 if (gGameSettings
.GameMode
= GM_CTF
) then
3137 // Ôëàã Êðàñíîé êîìàíäû
3138 saveFlag(@gFlags
[FLAG_RED
]);
3139 // Ôëàã Ñèíåé êîìàíäû
3140 saveFlag(@gFlags
[FLAG_BLUE
]);
3144 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3145 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3147 // Î÷êè Êðàñíîé êîìàíäû
3148 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_RED
].Goals
));
3149 // Î÷êè Ñèíåé êîìàíäû
3150 utils
.writeInt(st
, SmallInt(gTeamStat
[TEAM_BLUE
].Goals
));
3156 procedure g_Map_LoadState (st
: TStream
);
3162 procedure loadPanels ();
3167 if (Length(panByGUID
) <> utils
.readLongInt(st
)) then raise XStreamError
.Create('invalid number of saved panels');
3168 for pan
in panByGUID
do
3171 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3175 procedure loadFlag (flag
: PFlag
);
3180 if not utils
.checkSign(st
, 'FLAG') then raise XStreamError
.Create('invalid flag signature');
3181 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid flag version');
3182 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3183 flag
^.RespawnType
:= utils
.readByte(st
);
3185 flag
^.State
:= utils
.readByte(st
);
3186 // Íàïðàâëåíèå ôëàãà
3187 b
:= utils
.readByte(st
);
3188 if (b
= 1) then flag
^.Direction
:= TDirection
.D_LEFT
else flag
^.Direction
:= TDirection
.D_RIGHT
; // b = 2
3190 Obj_LoadState(@flag
^.Obj
, st
);
3194 if (st
= nil) then exit
;
3196 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3200 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3204 ///// Çàãðóæàåì ìóçûêó: /////
3205 if not utils
.checkSign(st
, 'MUSI') then raise XStreamError
.Create('invalid music signature');
3206 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid music version');
3208 assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3209 str
:= utils
.readStr(st
);
3210 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3211 dw
:= utils
.readLongWord(st
);
3212 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3213 boo
:= utils
.readBool(st
);
3214 // Çàïóñêàåì ýòó ìóçûêó
3215 gMusic
.SetByName(str
);
3216 gMusic
.SpecPause
:= boo
;
3219 gMusic
.SetPosition(dw
);
3222 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3223 gTotalMonsters
:= utils
.readLongInt(st
);
3226 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3227 if (gGameSettings
.GameMode
= GM_CTF
) then
3229 // Ôëàã Êðàñíîé êîìàíäû
3230 loadFlag(@gFlags
[FLAG_RED
]);
3231 // Ôëàã Ñèíåé êîìàíäû
3232 loadFlag(@gFlags
[FLAG_BLUE
]);
3236 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3237 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3239 // Î÷êè Êðàñíîé êîìàíäû
3240 gTeamStat
[TEAM_RED
].Goals
:= utils
.readSmallInt(st
);
3241 // Î÷êè Ñèíåé êîìàíäû
3242 gTeamStat
[TEAM_BLUE
].Goals
:= utils
.readSmallInt(st
);
3248 // trace liquid, stepping by `dx` and `dy`
3249 // return last seen liquid coords, and `false` if we're started outside of the liquid
3250 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3252 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3256 // started outside of the liquid?
3257 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3258 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3264 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit
3272 DynWarningCB
:= mapWarningCB
;