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 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
68 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
69 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
71 procedure g_Map_DrawBack(dx
, dy
: Integer);
72 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
73 PanelType
: Word; b1x3
: Boolean=false): Boolean;
74 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
76 procedure g_Map_EnableWallGUID (pguid
: Integer);
77 procedure g_Map_DisableWallGUID (pguid
: Integer);
78 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
81 procedure g_Map_EnableWall_XXX (ID
: DWORD
);
82 procedure g_Map_DisableWall_XXX (ID
: DWORD
);
83 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer);
85 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
87 procedure g_Map_ReAdd_DieTriggers();
88 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
90 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
91 function g_Map_GetPointCount(PointType
: Byte): Word;
93 function g_Map_HaveFlagPoints(): Boolean;
95 procedure g_Map_ResetFlag(Flag
: Byte);
96 procedure g_Map_DrawFlags();
98 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
99 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
101 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
103 // returns panel or nil
104 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
105 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
107 // returns panel or nil
108 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
109 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
112 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
114 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
115 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
117 // trace liquid, stepping by `dx` and `dy`
118 // return last seen liquid coords, and `false` if we're started outside of the liquid
119 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
122 procedure g_Map_ProfilersBegin ();
123 procedure g_Map_ProfilersEnd ();
126 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
129 function g_Map_MinX (): Integer; inline;
130 function g_Map_MinY (): Integer; inline;
131 function g_Map_MaxX (): Integer; inline;
132 function g_Map_MaxY (): Integer; inline;
140 function g_Texture_NumNameFindStart(name
: String): Boolean;
141 function g_Texture_NumNameFindNext(var newName
: String): Byte;
144 RESPAWNPOINT_PLAYER1
= 1;
145 RESPAWNPOINT_PLAYER2
= 2;
147 RESPAWNPOINT_RED
= 4;
148 RESPAWNPOINT_BLUE
= 5;
156 FLAG_STATE_NORMAL
= 1;
157 FLAG_STATE_DROPPED
= 2;
158 FLAG_STATE_CAPTURED
= 3;
159 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
160 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
162 FLAG_TIME
= 720; // 20 seconds
164 SKY_STRETCH
: Single = 1.5;
179 // sorted by draw priority
180 GridTagBack
= 1 shl 0; // gRenderBackgrounds
181 GridTagStep
= 1 shl 1; // gSteps
182 GridTagWall
= 1 shl 2; // gWalls
183 GridTagDoor
= 1 shl 3; // gWalls
184 GridTagAcid1
= 1 shl 4; // gAcid1
185 GridTagAcid2
= 1 shl 5; // gAcid2
186 GridTagWater
= 1 shl 6; // gWater
187 GridTagFore
= 1 shl 7; // gRenderForegrounds
188 // the following are invisible
189 GridTagLift
= 1 shl 8; // gLifts
190 GridTagBlockMon
= 1 shl 9; // gBlockMon
192 GridTagObstacle
= (GridTagStep
or GridTagWall
or GridTagDoor
);
193 GridTagLiquid
= (GridTagAcid1
or GridTagAcid2
or GridTagWater
);
195 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
200 gRenderBackgrounds
: TPanelArray
;
201 gRenderForegrounds
: TPanelArray
;
202 gWater
, gAcid1
, gAcid2
: TPanelArray
;
205 gBlockMon
: TPanelArray
;
206 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
207 //gDOMFlags: array of TFlag;
210 gDoorMap
: array of array of DWORD
;
211 gLiftMap
: array of array of DWORD
;
212 gWADHash
: TMD5Digest
;
213 BackID
: DWORD
= DWORD(-1);
214 gExternalResources
: TStringList
;
215 gMovingWallIds
: array of Integer = nil;
217 gdbg_map_use_accel_render
: Boolean = true;
218 gdbg_map_use_accel_coldet
: Boolean = true;
219 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
220 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
222 gCurrentMap
: TDynRecord
= nil;
223 gCurrentMapFileName
: AnsiString = ''; // so we can skip texture reloading
226 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
230 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
233 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
239 e_input
, g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
240 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
241 g_options
, g_triggers
, g_player
,
242 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
243 utils
, sfs
, xstreams
, hashtable
,
244 ImagingTypes
, Imaging
, ImagingUtility
,
245 ImagingGif
, ImagingNetworkGraphics
;
248 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
249 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
250 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
254 panByGUID
: array of TPanel
= nil;
257 // ////////////////////////////////////////////////////////////////////////// //
258 function g_Map_PanelByGUID (aguid
: Integer): TPanel
; inline;
260 //if (panByGUID = nil) or (not panByGUID.get(aguid, result)) then result := nil;
261 if (aguid
>= 0) and (aguid
< Length(panByGUID
)) then result
:= panByGUID
[aguid
] else result
:= nil;
265 // ////////////////////////////////////////////////////////////////////////// //
266 function g_Map_MinX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
else result
:= 0; end;
267 function g_Map_MinY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
else result
:= 0; end;
268 function g_Map_MaxX (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridX0
+mapGrid
.gridWidth
-1 else result
:= 0; end;
269 function g_Map_MaxY (): Integer; inline; begin if (mapGrid
<> nil) then result
:= mapGrid
.gridY0
+mapGrid
.gridHeight
-1 else result
:= 0; end;
272 // ////////////////////////////////////////////////////////////////////////// //
274 dfmapdef
: TDynMapDef
= nil;
276 procedure loadMapDefinition ();
278 pr
: TTextParser
= nil;
282 if (dfmapdef
<> nil) then exit
;
284 e_LogWritefln('parsing "mapdef.txt"...', []);
285 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
288 e_LogWritefln('local "%smapdef.txt" not found', [DataDir
]);
292 WAD
:= TWADFile
.Create();
293 if not WAD
.ReadFile(GameWAD
) then
295 //raise Exception.Create('cannot load "game.wad"');
300 st
:= WAD
.openFileStream('mapdef.txt');
306 //raise Exception.Create('cannot open "mapdef.txt"');
307 e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING
);
308 pr
:= TStrTextParser
.Create(defaultMapDef
);
312 pr
:= TFileTextParser
.Create(st
);
316 dfmapdef
:= TDynMapDef
.Create(pr
);
317 except on e
: Exception
do
318 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
326 // ////////////////////////////////////////////////////////////////////////// //
327 function g_Map_ParseMap (data
: Pointer; dataLen
: Integer): TDynRecord
;
329 wst
: TSFSMemoryChunkStream
= nil;
330 pr
: TTextParser
= nil;
333 if (dataLen
< 4) then exit
;
335 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
337 wst
:= TSFSMemoryChunkStream
.Create(data
, dataLen
);
339 if (PAnsiChar(data
)[0] = 'M') and (PAnsiChar(data
)[1] = 'A') and (PAnsiChar(data
)[2] = 'P') and (PByte(data
)[3] = 1) then
343 result
:= dfmapdef
.parseBinMap(wst
);
344 except on e
: Exception
do
346 e_LogWritefln('ERROR: %s', [e
.message]);
357 pr
:= TFileTextParser
.Create(wst
);
359 result
:= dfmapdef
.parseMap(pr
);
360 except on e
: Exception
do
362 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message])
363 else e_LogWritefln('ERROR: %s', [e
.message]);
364 pr
.Free(); // will free `wst`
369 pr
.Free(); // will free `wst`
374 // ////////////////////////////////////////////////////////////////////////// //
376 NNF_PureName
: String; // Èìÿ òåêñòóðû áåç öèôð â êîíöå
377 NNF_FirstNum
: Integer; // ×èñëî ó íà÷àëüíîé òåêñòóðû
378 NNF_CurrentNum
: Integer; // Ñëåäóþùåå ÷èñëî ó òåêñòóðû
381 function g_Texture_NumNameFindStart(name
: String): Boolean;
389 NNF_CurrentNum
:= -1;
391 for i
:= Length(name
) downto 1 do
392 if (name
[i
] = '_') then // "_" - ñèìâîë íà÷àëà íîìåðíîãî ïîñòôèêñà
394 if i
= Length(name
) then
395 begin // Íåò öèôð â êîíöå ñòðîêè
400 NNF_PureName
:= Copy(name
, 1, i
);
406 // Íå ïåðåâåñòè â ÷èñëî:
407 if not TryStrToInt(name
, NNF_FirstNum
) then
416 function g_Texture_NumNameFindNext(var newName
: String): Byte;
418 if (NNF_PureName
= '') or (NNF_CurrentNum
< 0) then
421 Result
:= NNF_NO_NAME
;
425 newName
:= NNF_PureName
+ IntToStr(NNF_CurrentNum
);
427 if NNF_CurrentNum
< NNF_FirstNum
then
428 Result
:= NNF_NAME_BEFORE
430 if NNF_CurrentNum
> NNF_FirstNum
then
431 Result
:= NNF_NAME_AFTER
433 Result
:= NNF_NAME_EQUALS
;
439 // ////////////////////////////////////////////////////////////////////////// //
440 function panelTypeToTag (panelType
: Word): Integer;
443 PANEL_WALL
: result
:= GridTagWall
; // gWalls
444 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
445 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
446 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
447 PANEL_WATER
: result
:= GridTagWater
; // gWater
448 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
449 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
450 PANEL_STEP
: result
:= GridTagStep
; // gSteps
451 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
452 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
453 else result
:= GridTagInvalid
;
458 function dplLess (a
, b
: TObject
): Boolean;
464 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
465 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
466 result
:= (pa
.arrIdx
< pb
.arrIdx
);
469 procedure dplClear ();
471 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
476 Textures
: TLevelTextureArray
= nil;
477 TextNameHash
: THashStrInt
= nil; // key: texture name; value: index in `Textures`
478 BadTextNameHash
: THashStrInt
= nil; // set; so we won't spam with non-existing texture messages
479 RespawnPoints
: array of TRespawnPoint
;
480 FlagPoints
: array[FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
481 //DOMFlagPoints: Array of TFlagPoint;
484 procedure g_Map_ProfilersBegin ();
486 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
487 profMapCollision
.mainBegin(g_profile_collision
);
489 if g_profile_collision
then
491 profMapCollision
.sectionBegin('*solids');
492 profMapCollision
.sectionEnd();
493 profMapCollision
.sectionBegin('liquids');
494 profMapCollision
.sectionEnd();
498 procedure g_Map_ProfilersEnd ();
500 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
504 // wall index in `gWalls` or -1
505 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
509 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
510 if (result
<> nil) then
512 if (hitx
<> nil) then hitx
^ := ex
;
513 if (hity
<> nil) then hity
^ := ey
;
517 if (hitx
<> nil) then hitx
^ := x1
;
518 if (hity
<> nil) then hity
^ := y1
;
522 // returns panel or nil
523 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
527 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
528 if (result
<> nil) then
530 if (hitx
<> nil) then hitx
^ := ex
;
531 if (hity
<> nil) then hity
^ := ey
;
535 if (hitx
<> nil) then hitx
^ := x1
;
536 if (hity
<> nil) then hity
^ := y1
;
541 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
543 function checker (pan
: TPanel
; tag
: Integer): Boolean;
546 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
548 result := pan.Enabled; // stop if wall is enabled
553 if ((tag
and GridTagLift
) <> 0) then
555 // stop if the lift of the right type
557 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
558 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
559 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
560 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
564 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
568 tagmask
: Integer = 0;
572 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
573 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
574 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
575 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
576 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
577 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
578 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
580 if (tagmask
= 0) then exit
;// just in case
581 if ((tagmask
and GridTagLift
) <> 0) then
584 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
589 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
594 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
597 if (tagmask
= 0) then exit
;
598 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
602 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
604 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
605 (Texture
= TEXTURE_NAME_ACID1
) or
606 (Texture
= TEXTURE_NAME_ACID2
);
609 procedure CreateDoorMap();
611 PanelArray
: Array of record
617 a
, b
, c
, m
, i
, len
: Integer;
625 SetLength(PanelArray
, len
);
627 for a
:= 0 to High(gWalls
) do
628 if gWalls
[a
].Door
then
630 PanelArray
[i
].X
:= gWalls
[a
].X
;
631 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
632 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
633 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
634 PanelArray
[i
].Active
:= True;
635 PanelArray
[i
].PanelID
:= a
;
641 SetLength(PanelArray
, len
);
652 SetLength(gDoorMap
, 0);
654 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
657 if PanelArray
[a
].Active
then
659 PanelArray
[a
].Active
:= False;
660 m
:= Length(gDoorMap
);
661 SetLength(gDoorMap
, m
+1);
662 SetLength(gDoorMap
[m
], 1);
663 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
671 if PanelArray
[b
].Active
then
672 for c
:= 0 to High(gDoorMap
[m
]) do
673 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
674 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
675 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
676 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
677 gWalls
[gDoorMap
[m
, c
]].X
,
678 gWalls
[gDoorMap
[m
, c
]].Y
,
679 gWalls
[gDoorMap
[m
, c
]].Width
,
680 gWalls
[gDoorMap
[m
, c
]].Height
) then
682 PanelArray
[b
].Active
:= False;
683 SetLength(gDoorMap
[m
],
684 Length(gDoorMap
[m
])+1);
685 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
691 g_Game_StepLoading();
697 procedure CreateLiftMap();
699 PanelArray
: Array of record
704 a
, b
, c
, len
, i
, j
: Integer;
710 len
:= Length(gLifts
);
711 SetLength(PanelArray
, len
);
713 for a
:= 0 to len
-1 do
715 PanelArray
[a
].X
:= gLifts
[a
].X
;
716 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
717 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
718 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
719 PanelArray
[a
].Active
:= True;
722 SetLength(gLiftMap
, len
);
725 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
727 for a
:= 0 to len
-1 do
728 if PanelArray
[a
].Active
then
730 PanelArray
[a
].Active
:= False;
731 SetLength(gLiftMap
[i
], 32);
739 for b
:= 0 to len
-1 do
740 if PanelArray
[b
].Active
then
742 if g_CollideAround(PanelArray
[b
].X
,
745 PanelArray
[b
].Height
,
746 PanelArray
[gLiftMap
[i
, c
]].X
,
747 PanelArray
[gLiftMap
[i
, c
]].Y
,
748 PanelArray
[gLiftMap
[i
, c
]].Width
,
749 PanelArray
[gLiftMap
[i
, c
]].Height
) then
751 PanelArray
[b
].Active
:= False;
753 if j
> High(gLiftMap
[i
]) then
754 SetLength(gLiftMap
[i
],
755 Length(gLiftMap
[i
])+32);
764 SetLength(gLiftMap
[i
], j
+1);
767 g_Game_StepLoading();
770 SetLength(gLiftMap
, i
);
775 function CreatePanel (PanelRec
: TDynRecord
; AddTextures
: TAddTextureArray
; CurTex
: Integer; sav
: Boolean): Integer;
778 panels
: ^TPanelArray
;
784 case PanelRec
.PanelType
of
785 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: panels
:= @gWalls
;
786 PANEL_BACK
: panels
:= @gRenderBackgrounds
;
787 PANEL_FORE
: panels
:= @gRenderForegrounds
;
788 PANEL_WATER
: panels
:= @gWater
;
789 PANEL_ACID1
: panels
:= @gAcid1
;
790 PANEL_ACID2
: panels
:= @gAcid2
;
791 PANEL_STEP
: panels
:= @gSteps
;
792 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: panels
:= @gLifts
;
793 PANEL_BLOCKMON
: panels
:= @gBlockMon
;
797 len
:= Length(panels
^);
798 SetLength(panels
^, len
+1);
800 pguid
:= Length(panByGUID
);
801 SetLength(panByGUID
, pguid
+1); //FIXME!
802 pan
:= TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
, pguid
);
804 assert(pguid
< Length(panByGUID
));
805 panByGUID
[pguid
] := pan
;
809 pan
.tag
:= panelTypeToTag(PanelRec
.PanelType
);
810 if sav
then pan
.SaveIt
:= True;
812 PanelRec
.user
['panel_guid'] := pguid
;
819 function CreateNullTexture(RecName
: String): Integer;
821 RecName
:= toLowerCase1251(RecName
);
822 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
823 if TextNameHash
.get(RecName
, result
) then exit
; // i found her!
825 SetLength(Textures
, Length(Textures
)+1);
826 result
:= High(Textures
);
828 with Textures
[High(Textures
)] do
830 TextureName
:= RecName
;
834 TextureID
:= LongWord(TEXTURE_NONE
);
837 TextNameHash
.put(RecName
, result
);
841 function CreateTexture(RecName
: AnsiString; Map
: string; log
: Boolean): Integer;
844 TextureData
: Pointer;
846 a
, ResLength
: Integer;
848 RecName
:= toLowerCase1251(RecName
);
849 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
850 if TextNameHash
.get(RecName
, result
) then
853 //e_LogWritefln('texture ''%s'' already loaded', [RecName]);
859 if (BadTextNameHash
<> nil) and BadTextNameHash
.has(RecName
) then exit
; // don't do it again and again
862 if Textures <> nil then
864 for a := 0 to High(Textures) do
866 if (Textures[a].TextureName = RecName) then
867 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
868 e_LogWritefln('texture ''%s'' already loaded', [RecName]);
876 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
877 if (RecName
= TEXTURE_NAME_WATER
) or
878 (RecName
= TEXTURE_NAME_ACID1
) or
879 (RecName
= TEXTURE_NAME_ACID2
) then
881 SetLength(Textures
, Length(Textures
)+1);
883 with Textures
[High(Textures
)] do
885 TextureName
:= RecName
;
886 if (TextureName
= TEXTURE_NAME_WATER
) then TextureID
:= LongWord(TEXTURE_SPECIAL_WATER
)
887 else if (TextureName
= TEXTURE_NAME_ACID1
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID1
)
888 else if (TextureName
= TEXTURE_NAME_ACID2
) then TextureID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
893 result
:= High(Textures
);
894 TextNameHash
.put(RecName
, result
);
898 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
899 WADName
:= g_ExtractWadName(RecName
);
901 WAD
:= TWADFile
.Create();
903 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
905 WAD
.ReadFile(WADName
);
909 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
911 FreeMem(TextureData);
912 RecName := 'COMMON\ALIEN';
916 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
, log
) then
918 SetLength(Textures
, Length(Textures
)+1);
919 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
921 SetLength(Textures
, Length(Textures
)-1);
924 e_GetTextureSize(Textures
[High(Textures
)].TextureID
, @Textures
[High(Textures
)].Width
, @Textures
[High(Textures
)].Height
);
925 FreeMem(TextureData
);
926 Textures
[High(Textures
)].TextureName
:= RecName
;
927 Textures
[High(Textures
)].Anim
:= False;
929 result
:= High(Textures
);
930 TextNameHash
.put(RecName
, result
);
932 else // Íåò òàêîãî ðåóñðñà â WAD'å
934 //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
935 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
936 if log
and (not BadTextNameHash
.get(RecName
, a
)) then
938 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
939 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
941 BadTextNameHash
.put(RecName
, -1);
948 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
951 TextureWAD
: PChar = nil;
952 TextData
: Pointer = nil;
953 TextureData
: Pointer = nil;
957 TextureResource
: String;
958 _width
, _height
, _framecount
, _speed
: Integer;
959 _backanimation
: Boolean;
961 ia
: TDynImageDataArray
= nil;
962 f
, c
, frdelay
, frloop
: Integer;
964 RecName
:= toLowerCase1251(RecName
);
965 if (TextNameHash
= nil) then TextNameHash
:= hashNewStrInt();
966 if TextNameHash
.get(RecName
, result
) then
969 //e_LogWritefln('animated texture ''%s'' already loaded', [RecName]);
975 //e_LogWritefln('*** Loading animated texture "%s"', [RecName]);
977 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
978 if BadTextNameHash
.get(RecName
, f
) then
980 //e_WriteLog(Format('no animation texture %s (don''t worry)', [RecName]), MSG_NOTIFY);
984 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
985 WADName
:= g_ExtractWadName(RecName
);
987 WAD
:= TWADFile
.Create();
989 if WADName
<> '' then WADName
:= GameDir
+'/wads/'+WADName
else WADName
:= Map
;
991 WAD
.ReadFile(WADName
);
993 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
, log
) then
995 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
996 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
998 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
999 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
1001 BadTextNameHash
.put(RecName
, -1);
1006 if WADName = Map then
1008 //FreeMem(TextureWAD);
1009 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
1015 if ResLength
< 6 then
1017 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
1018 BadTextNameHash
.put(RecName
, -1);
1022 // ýòî ïòèöà? ýòî ñàìîë¸ò?
1023 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
1024 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
1026 // íåò, ýòî ñóïåðìåí!
1027 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
1029 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
1030 BadTextNameHash
.put(RecName
, -1);
1034 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
1035 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
1037 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
1038 BadTextNameHash
.put(RecName
, -1);
1042 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
1044 TextureResource
:= cfg
.ReadStr('', 'resource', '');
1045 if TextureResource
= '' then
1047 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
1048 BadTextNameHash
.put(RecName
, -1);
1052 _width
:= cfg
.ReadInt('', 'framewidth', 0);
1053 _height
:= cfg
.ReadInt('', 'frameheight', 0);
1054 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
1055 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
1056 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
1061 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
1062 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
1064 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
1065 BadTextNameHash
.put(RecName
, -1);
1072 SetLength(Textures
, Length(Textures
)+1);
1073 with Textures
[High(Textures
)] do
1075 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
1076 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
1078 TextureName
:= RecName
;
1082 FramesCount
:= _framecount
;
1084 result
:= High(Textures
);
1085 TextNameHash
.put(RecName
, result
);
1089 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1090 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1092 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
1094 BadTextNameHash
.put(RecName
, -1);
1100 // try animated image
1102 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
1103 if length(imgfmt) = 0 then
1105 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
1109 GlobalMetadata
.ClearMetaItems();
1110 GlobalMetadata
.ClearMetaItemsForSaving();
1111 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
1113 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
1114 BadTextNameHash
.put(RecName
, -1);
1117 if length(ia
) = 0 then
1119 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
1120 BadTextNameHash
.put(RecName
, -1);
1127 _width
:= ia
[0].width
;
1128 _height
:= ia
[0].height
;
1129 _framecount
:= length(ia
);
1131 _backanimation
:= false;
1134 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
1136 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
1138 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
1140 if f
< 0 then f
:= 0;
1143 if c
< 13 then c
:= 0 else c
:= 1;
1145 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
1150 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
1152 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
1154 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
1156 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
1160 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
1161 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
1162 f
:= ord(_backanimation
);
1163 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
);
1165 SetLength(Textures
, Length(Textures
)+1);
1166 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
1167 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
1169 Textures
[High(Textures
)].TextureName
:= RecName
;
1170 Textures
[High(Textures
)].Width
:= _width
;
1171 Textures
[High(Textures
)].Height
:= _height
;
1172 Textures
[High(Textures
)].Anim
:= True;
1173 Textures
[High(Textures
)].FramesCount
:= length(ia
);
1174 Textures
[High(Textures
)].Speed
:= _speed
;
1175 result
:= High(Textures
);
1176 TextNameHash
.put(RecName
, result
);
1177 //writeln(' CREATED!');
1181 if (BadTextNameHash
= nil) then BadTextNameHash
:= hashNewStrInt();
1182 if log
and (not BadTextNameHash
.get(RecName
, f
)) then
1184 e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
1186 BadTextNameHash
.put(RecName
, -1);
1190 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
1193 if (TextureWAD
<> nil) then FreeMem(TextureWAD
);
1194 if (TextData
<> nil) then FreeMem(TextData
);
1195 if (TextureData
<> nil) then FreeMem(TextureData
);
1199 procedure CreateItem(Item
: TDynRecord
);
1201 if g_Game_IsClient
then Exit
;
1203 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
1204 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
1207 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
1208 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
1211 procedure CreateArea(Area
: TDynRecord
);
1216 case Area
.AreaType
of
1217 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
1218 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
1220 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
1221 with RespawnPoints
[High(RespawnPoints
)] do
1225 Direction
:= TDirection(Area
.Direction
);
1227 case Area
.AreaType
of
1228 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1229 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1230 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1231 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1232 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1237 AREA_REDFLAG
, AREA_BLUEFLAG
:
1239 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1241 if FlagPoints
[a
] <> nil then Exit
;
1245 with FlagPoints
[a
]^ do
1247 X
:= Area
.X
-FLAGRECT
.X
;
1248 Y
:= Area
.Y
-FLAGRECT
.Y
;
1249 Direction
:= TDirection(Area
.Direction
);
1255 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1256 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1259 Animation
:= TAnimation
.Create(id
, True, 8);
1260 Obj
.Rect
:= FLAGRECT
;
1268 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1269 with DOMFlagPoints[High(DOMFlagPoints)] do
1273 Direction := TDirection(Area.Direction);
1276 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1281 procedure CreateTrigger (amapIdx
: Integer; Trigger
: TDynRecord
; atpanid
, atrigpanid
: Integer; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1285 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1289 mapId
:= Trigger
.id
;
1290 mapIndex
:= amapIdx
;
1293 Width
:= Trigger
.Width
;
1294 Height
:= Trigger
.Height
;
1295 Enabled
:= Trigger
.Enabled
;
1296 //TexturePanel := Trigger.TexturePanel;
1297 TexturePanelGUID
:= atpanid
;
1298 TexturePanelType
:= fTexturePanel1Type
;
1299 ShotPanelType
:= fTexturePanel2Type
;
1300 TriggerType
:= Trigger
.TriggerType
;
1301 ActivateType
:= Trigger
.ActivateType
;
1302 Keys
:= Trigger
.Keys
;
1303 trigPanelGUID
:= atrigpanid
;
1304 //trigShotPanelId := ashotpanid;
1305 //Data.Default := Trigger.DATA;
1306 if (Trigger
.trigRec
= nil) then
1309 if (TriggerType
<> TRIGGER_SECRET
) then
1311 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [TriggerType
], MSG_WARNING
);
1316 trigData
:= Trigger
.trigRec
.clone();
1320 g_Triggers_Create(_trigger
);
1323 procedure CreateMonster(monster
: TDynRecord
);
1328 if g_Game_IsClient
then Exit
;
1330 if (gGameSettings
.GameType
= GT_SINGLE
)
1331 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1333 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1335 if gTriggers
<> nil then
1337 for a
:= 0 to High(gTriggers
) do
1339 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1341 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1342 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1347 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1351 procedure g_Map_ReAdd_DieTriggers();
1353 function monsDieTrig (mon
: TMonster
): Boolean;
1356 //tw: TStrTextWriter;
1358 result
:= false; // don't stop
1359 mon
.ClearTriggers();
1360 for a
:= 0 to High(gTriggers
) do
1362 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1364 //if (gTriggers[a].Data.MonsterID-1) = Integer(mon.StartID) then mon.AddTrigger(a);
1366 tw := TStrTextWriter.Create();
1368 gTriggers[a].trigData.writeTo(tw);
1369 e_LogWritefln('=== trigger #%s ==='#10'%s'#10'---', [a, tw.str]);
1374 if (gTriggers
[a
].trigData
.trigMonsterId
) = Integer(mon
.StartID
) then mon
.AddTrigger(a
);
1380 if g_Game_IsClient
then Exit
;
1382 g_Mons_ForEach(monsDieTrig
);
1385 function extractWadName(resourceName
: string): string;
1389 posN
:= Pos(':', resourceName
);
1391 Result
:= Copy(resourceName
, 0, posN
-1)
1396 procedure addResToExternalResList(res
: string);
1398 res
:= extractWadName(res
);
1399 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1400 gExternalResources
.Add(res
);
1403 procedure generateExternalResourcesList({mapReader: TMapReader_1}map
: TDynRecord
);
1405 //textures: TTexturesRec1Array;
1406 //textures: TDynField;
1408 //mapHeader: TMapHeaderRec_1;
1410 //resFile: String = '';
1412 if gExternalResources
= nil then
1413 gExternalResources
:= TStringList
.Create
;
1415 gExternalResources
.Clear
;
1419 textures := GetTextures(map);
1420 for i := 0 to High(textures) do
1422 addResToExternalResList(resFile);
1426 textures := map['texture'];
1427 if (textures <> nil) then
1429 for trec in textures do
1431 addResToExternalResList(resFile);
1438 //mapHeader := GetMapHeader(map);
1440 addResToExternalResList(map
.MusicName
);
1441 addResToExternalResList(map
.SkyName
);
1445 procedure mapCreateGrid ();
1447 mapX0
: Integer = $3fffffff;
1448 mapY0
: Integer = $3fffffff;
1449 mapX1
: Integer = -$3fffffff;
1450 mapY1
: Integer = -$3fffffff;
1452 procedure calcBoundingBox (constref panels
: TPanelArray
);
1457 for idx
:= 0 to High(panels
) do
1460 if not pan
.visvalid
then continue
;
1461 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1462 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1463 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1464 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1465 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1469 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1475 //tag := panelTypeToTag(tag);
1476 for idx
:= 0 to High(panels
) do
1479 if not pan
.visvalid
then continue
;
1480 if (pan
.proxyId
<> -1) then
1482 {$IF DEFINED(D2F_DEBUG)}
1483 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
);
1487 case pan
.PanelType
of
1488 PANEL_WALL
: newtag
:= GridTagWall
;
1489 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1490 PANEL_BACK
: newtag
:= GridTagBack
;
1491 PANEL_FORE
: newtag
:= GridTagFore
;
1492 PANEL_WATER
: newtag
:= GridTagWater
;
1493 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1494 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1495 PANEL_STEP
: newtag
:= GridTagStep
;
1496 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1497 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1498 else continue
; // oops
1502 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1503 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1504 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1505 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1507 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1509 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1520 calcBoundingBox(gWalls
);
1521 calcBoundingBox(gRenderBackgrounds
);
1522 calcBoundingBox(gRenderForegrounds
);
1523 calcBoundingBox(gWater
);
1524 calcBoundingBox(gAcid1
);
1525 calcBoundingBox(gAcid2
);
1526 calcBoundingBox(gSteps
);
1527 calcBoundingBox(gLifts
);
1528 calcBoundingBox(gBlockMon
);
1530 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1532 if (mapX0
> 0) then mapX0
:= 0;
1533 if (mapY0
> 0) then mapY0
:= 0;
1535 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1536 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1538 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1539 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1541 addPanelsToGrid(gWalls
);
1542 addPanelsToGrid(gRenderBackgrounds
);
1543 addPanelsToGrid(gRenderForegrounds
);
1544 addPanelsToGrid(gWater
);
1545 addPanelsToGrid(gAcid1
);
1546 addPanelsToGrid(gAcid2
);
1547 addPanelsToGrid(gSteps
);
1548 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1549 addPanelsToGrid(gBlockMon
);
1551 mapGrid
.dumpStats();
1553 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1557 function g_Map_Load(Res
: String): Boolean;
1559 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1560 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1564 //TexturePanel: Integer;
1566 LiftPanelIdx
: Integer;
1567 DoorPanelIdx
: Integer;
1568 ShotPanelIdx
: Integer;
1569 MPlatPanelIdx
: Integer;
1570 trigrec
: TDynRecord
;
1572 liftPan
: TDynRecord
;
1573 doorPan
: TDynRecord
;
1574 shotPan
: TDynRecord
;
1575 mplatPan
: TDynRecord
;
1579 mapReader
: TDynRecord
= nil;
1580 mapTextureList
: TDynField
= nil; //TTexturesRec1Array; tagInt: texture index
1581 panels
: TDynField
= nil; //TPanelsRec1Array;
1582 items
: TDynField
= nil; //TItemsRec1Array;
1583 monsters
: TDynField
= nil; //TMonsterRec1Array;
1584 areas
: TDynField
= nil; //TAreasRec1Array;
1585 triggers
: TDynField
= nil; //TTriggersRec1Array;
1588 AddTextures
: TAddTextureArray
;
1589 TriggersTable
: array of TTRec
;
1590 FileName
, mapResName
, s
, TexName
: String;
1593 ok
, isAnim
, trigRef
: Boolean;
1594 CurTex
, ntn
: Integer;
1595 rec
, texrec
: TDynRecord
;
1597 pannum
, trignum
, cnt
, tgpid
: Integer;
1599 moveSpeed
{, moveStart, moveEnd}: TDFPoint
;
1600 //moveActive: Boolean;
1611 gMapInfo
.Map
:= Res
;
1612 TriggersTable
:= nil;
1615 sfsGCDisable(); // temporary disable removing of temporary volumes
1618 FileName
:= g_ExtractWadName(Res
);
1619 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1620 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1622 WAD
:= TWADFile
.Create();
1623 if not WAD
.ReadFile(FileName
) then
1625 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1630 //k8: why loader ignores path here?
1631 mapResName
:= g_ExtractFileName(Res
);
1632 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1634 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1643 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1649 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1650 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1652 stt
:= curTimeMicro();
1655 mapReader
:= g_Map_ParseMap(Data
, Len
);
1658 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1665 generateExternalResourcesList(mapReader
);
1666 mapTextureList
:= mapReader
['texture'];
1667 // get all other lists here too
1668 panels
:= mapReader
['panel'];
1669 triggers
:= mapReader
['trigger'];
1670 items
:= mapReader
['item'];
1671 areas
:= mapReader
['area'];
1672 monsters
:= mapReader
['monster'];
1674 // Çàãðóçêà îïèñàíèÿ êàðòû:
1675 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1676 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1680 Name
:= mapReader
.MapName
;
1681 Description
:= mapReader
.MapDesc
;
1682 Author
:= mapReader
.MapAuthor
;
1683 MusicName
:= mapReader
.MusicName
;
1684 SkyName
:= mapReader
.SkyName
;
1685 Height
:= mapReader
.Height
;
1686 Width
:= mapReader
.Width
;
1689 // Çàãðóçêà òåêñòóð:
1690 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1691 // Äîáàâëåíèå òåêñòóð â Textures[]:
1692 if (mapTextureList
<> nil) and (mapTextureList
.count
> 0) then
1694 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1695 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], mapTextureList
.count
-1, False);
1698 for rec
in mapTextureList
do
1702 {$IF DEFINED(D2F_DEBUG_TXLOAD)}
1703 e_WriteLog(Format(' Loading texture #%d: %s', [cnt
, s
]), MSG_NOTIFY
);
1705 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1708 // Àíèìèðîâàííàÿ òåêñòóðà
1709 ntn
:= CreateAnimTexture(rec
.Resource
, FileName
, True);
1710 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1715 ntn
:= CreateTexture(rec
.Resource
, FileName
, True);
1716 if (ntn
< 0) then g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1718 if (ntn
< 0) then ntn
:= CreateNullTexture(rec
.Resource
);
1720 rec
.tagInt
:= ntn
; // remember texture number
1721 g_Game_StepLoading();
1724 // set panel tagInt to texture index
1725 if (panels
<> nil) then
1727 for rec
in panels
do
1729 texrec
:= rec
.TextureRec
;
1730 if (texrec
= nil) then rec
.tagInt
:= -1 else rec
.tagInt
:= texrec
.tagInt
;
1735 // Çàãðóçêà òðèããåðîâ
1736 gTriggerClientID
:= 0;
1737 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1738 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1741 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1742 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1744 // check texture numbers for panels
1745 if (panels
<> nil) and (panels
.count
> 0) then
1747 for rec
in panels
do
1749 if (rec
.tagInt
< 0) then
1751 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1758 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì)
1759 if (triggers
<> nil) and (triggers
.count
> 0) then
1761 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1762 //SetLength(TriggersTable, triggers.count);
1763 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], triggers
.count
-1, False);
1765 for rec
in triggers
do
1767 SetLength(TriggersTable
, Length(TriggersTable
)+1);
1768 pttit
:= @TriggersTable
[High(TriggersTable
)];
1769 pttit
.trigrec
:= rec
;
1770 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè)
1771 pttit
.texPan
:= mapReader
.panel
[rec
.TexturePanel
];
1772 pttit
.liftPan
:= nil;
1773 pttit
.doorPan
:= nil;
1774 pttit
.shotPan
:= nil;
1775 pttit
.mplatPan
:= nil;
1776 pttit
.texPanIdx
:= -1;
1777 pttit
.LiftPanelIdx
:= -1;
1778 pttit
.DoorPanelIdx
:= -1;
1779 pttit
.ShotPanelIdx
:= -1;
1780 pttit
.MPlatPanelIdx
:= -1;
1782 if rec
.TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1784 pttit
.liftPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1787 if rec
.TriggerType
in [TRIGGER_OPENDOOR
, TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
, TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1789 pttit
.doorPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1792 if (rec
.TriggerType
= TRIGGER_SHOT
) then
1794 pttit
.shotPan
:= mapReader
.panel
[rec
.trigRec
.tgShotPanelID
];
1797 if rec
.TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1799 pttit
.mplatPan
:= mapReader
.panel
[rec
.trigRec
.tgPanelID
];
1802 if (pttit
.texPan
<> nil) then pttit
.texPan
.userPanelTrigRef
:= true;
1803 if (pttit
.liftPan
<> nil) then pttit
.liftPan
.userPanelTrigRef
:= true;
1804 if (pttit
.doorPan
<> nil) then pttit
.doorPan
.userPanelTrigRef
:= true;
1805 if (pttit
.shotPan
<> nil) then pttit
.shotPan
.userPanelTrigRef
:= true;
1806 if (pttit
.mplatPan
<> nil) then pttit
.mplatPan
.userPanelTrigRef
:= true;
1808 g_Game_StepLoading();
1813 if (panels
<> nil) and (panels
.count
> 0) then
1815 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1816 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], panels
.count
-1, False);
1819 for rec
in panels
do
1822 //e_LogWritefln('PANSTART: pannum=%s', [pannum]);
1824 SetLength(AddTextures
, 0);
1829 if (mapTextureList
<> nil) then
1831 texrec
:= rec
.TextureRec
;
1832 ok
:= (texrec
<> nil);
1837 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1838 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð
1840 if (TriggersTable
<> nil) and (mapTextureList
<> nil) then
1843 for b := 0 to High(TriggersTable) do
1845 if (TriggersTable[b].texPan = rec) or (TriggersTable[b].shotPan = rec) then
1853 if rec
.userPanelTrigRef
then
1855 // e_LogWritefln('trigref for panel %s', [pannum]);
1864 // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1865 s
:= texrec
.Resource
;
1867 // Ñïåö-òåêñòóðû çàïðåùåíû
1868 if g_Map_IsSpecialTexture(s
) then
1874 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè
1875 ok
:= g_Texture_NumNameFindStart(s
);
1878 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1879 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #
1882 k
:= NNF_NAME_BEFORE
;
1883 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû
1884 while ok
or (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_EQUALS
) do
1886 k
:= g_Texture_NumNameFindNext(TexName
);
1888 if (k
= NNF_NAME_BEFORE
) or (k
= NNF_NAME_AFTER
) then
1890 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó
1893 // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1895 //e_LogWritefln('000: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1896 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1897 //e_LogWritefln('001: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1900 // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1902 //e_LogWritefln('002: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1903 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1904 //e_LogWritefln('003: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1909 // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1911 //e_LogWritefln('004: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1912 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1913 //e_LogWritefln('005: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1916 // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1918 //e_LogWritefln('006: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1919 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1920 //e_LogWritefln('007: pannum=%s; TexName=[%s]; FileName=[%s]', [pannum, TexName, FileName]);
1924 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè
1928 for c := 0 to High(Textures) do
1930 if (Textures[c].TextureName = TexName) then
1932 SetLength(AddTextures, Length(AddTextures)+1);
1933 AddTextures[High(AddTextures)].Texture := c;
1934 AddTextures[High(AddTextures)].Anim := isAnim;
1939 if (TextNameHash
<> nil) and TextNameHash
.get(toLowerCase1251(TexName
), c
) then
1941 SetLength(AddTextures
, Length(AddTextures
)+1);
1942 AddTextures
[High(AddTextures
)].Texture
:= c
;
1943 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1949 if k
= NNF_NAME_EQUALS
then
1951 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî
1952 SetLength(AddTextures
, Length(AddTextures
)+1);
1953 AddTextures
[High(AddTextures
)].Texture
:= rec
.tagInt
; // internal texture number, not map index
1954 AddTextures
[High(AddTextures
)].Anim
:= texrec
.Anim
;
1955 CurTex
:= High(AddTextures
);
1966 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1967 end; // if ok - ññûëàþòñÿ òðèããåðû
1971 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó
1972 SetLength(AddTextures
, 1);
1973 AddTextures
[0].Texture
:= rec
.tagInt
; // internal texture number, not map index
1974 AddTextures
[0].Anim
:= false;
1975 if (texrec
<> nil) then AddTextures
[0].Anim
:= texrec
.Anim
;
1979 //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);
1981 //e_LogWritefln('PANADD: pannum=%s', [pannum]);
1983 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå GUID
1984 PanelID
:= CreatePanel(rec
, AddTextures
, CurTex
, trigRef
);
1985 //e_LogWritefln('panel #%s of type %s got guid #%s', [pannum, rec.PanelType, PanelID]);
1986 rec
.userPanelId
:= PanelID
; // remember game panel id, we'll fix triggers later
1989 moveSpeed
:= rec
.moveSpeed
;
1990 //moveStart := rec.moveStart;
1991 //moveEnd := rec.moveEnd;
1992 //moveActive := rec['move_active'].varvalue;
1993 if not moveSpeed
.isZero
then
1995 SetLength(gMovingWallIds
, Length(gMovingWallIds
)+1);
1996 gMovingWallIds
[High(gMovingWallIds
)] := PanelID
;
1997 //e_LogWritefln('found moving panel ''%s'' (idx=%s; id=%s)', [rec.id, pannum, PanelID]);
2000 //e_LogWritefln('PANEND: pannum=%s', [pannum]);
2002 g_Game_StepLoading();
2006 // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ
2007 for b
:= 0 to High(TriggersTable
) do
2009 if (TriggersTable
[b
].texPan
<> nil) then TriggersTable
[b
].texPanIdx
:= TriggersTable
[b
].texPan
.userPanelId
;
2010 if (TriggersTable
[b
].liftPan
<> nil) then TriggersTable
[b
].LiftPanelIdx
:= TriggersTable
[b
].liftPan
.userPanelId
;
2011 if (TriggersTable
[b
].doorPan
<> nil) then TriggersTable
[b
].DoorPanelIdx
:= TriggersTable
[b
].doorPan
.userPanelId
;
2012 if (TriggersTable
[b
].shotPan
<> nil) then TriggersTable
[b
].ShotPanelIdx
:= TriggersTable
[b
].shotPan
.userPanelId
;
2013 if (TriggersTable
[b
].mplatPan
<> nil) then TriggersTable
[b
].MPlatPanelIdx
:= TriggersTable
[b
].mplatPan
.userPanelId
;
2016 // create map grid, init other grids (for monsters, for example)
2017 e_WriteLog('Creating map grid', MSG_NOTIFY
);
2020 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû
2021 if (triggers
<> nil) and (panels
<> nil) and (not gLoadGameMode
) then
2023 e_LogWritefln(' Creating triggers (%d)...', [triggers
.count
]);
2024 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
2025 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü
2027 for rec
in triggers
do
2030 if (TriggersTable
[trignum
].texPan
<> nil) then b
:= TriggersTable
[trignum
].texPan
.PanelType
else b
:= 0;
2031 if (TriggersTable
[trignum
].shotPan
<> nil) then c
:= TriggersTable
[trignum
].shotPan
.PanelType
else c
:= 0;
2032 // we can have only one of those
2033 if (TriggersTable
[trignum
].LiftPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].LiftPanelIdx
2034 else if (TriggersTable
[trignum
].DoorPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].DoorPanelIdx
2035 else if (TriggersTable
[trignum
].ShotPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].ShotPanelIdx
2036 else if (TriggersTable
[trignum
].MPlatPanelIdx
<> -1) then tgpid
:= TriggersTable
[trignum
].MPlatPanelIdx
2038 //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]);
2039 CreateTrigger(trignum
, rec
, TriggersTable
[trignum
].texPanIdx
, tgpid
, Word(b
), Word(c
));
2043 // Çàãðóçêà ïðåäìåòîâ
2044 e_WriteLog(' Loading items...', MSG_NOTIFY
);
2045 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
2047 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû
2048 if (items
<> nil) and not gLoadGameMode
then
2050 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
2051 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
2052 for rec
in items
do CreateItem(rec
);
2055 // Çàãðóçêà îáëàñòåé
2056 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
2057 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
2059 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè
2060 if areas
<> nil then
2062 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
2063 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
2064 for rec
in areas
do CreateArea(rec
);
2067 // Çàãðóçêà ìîíñòðîâ
2068 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
2069 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
2071 gTotalMonsters
:= 0;
2073 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ
2074 if (monsters
<> nil) and not gLoadGameMode
then
2076 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
2077 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
2078 for rec
in monsters
do CreateMonster(rec
);
2081 gCurrentMap
:= mapReader
; // this will be our current map now
2082 gCurrentMapFileName
:= Res
;
2086 if gMapInfo
.SkyName
<> '' then
2088 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
2089 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
2090 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
2092 if FileName
<> '' then
2093 FileName
:= GameDir
+'/wads/'+FileName
2096 FileName
:= g_ExtractWadName(Res
);
2099 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
2100 if g_Texture_CreateWAD(BackID
, s
) then
2102 g_Game_SetupScreenSize();
2105 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
2110 if gMapInfo
.MusicName
<> '' then
2112 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
2113 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
2114 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
2116 if FileName
<> '' then
2117 FileName
:= GameDir
+'/wads/'+FileName
2120 FileName
:= g_ExtractWadName(Res
);
2123 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
2124 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
2127 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
2130 // Îñòàëüíûå óñòàíâêè
2138 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
2139 if not gLoadGameMode
then g_GFX_Init();
2141 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
2142 mapTextureList
:= nil;
2147 TriggersTable
:= nil;
2150 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
2151 if ok
and (not gLoadGameMode
) then
2153 gMusic
.SetByName(gMapInfo
.MusicName
);
2158 gMusic
.SetByName('');
2161 stt
:= curTimeMicro()-stt
;
2162 e_LogWritefln('map loaded in %s.%s milliseconds', [Integer(stt
div 1000), Integer(stt
mod 1000)]);
2164 sfsGCEnable(); // enable releasing unused volumes
2166 e_ClearInputBuffer(); // why not?
2169 e_WriteLog('Done loading map.', MSG_NOTIFY
);
2174 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
2177 mapReader
: TDynRecord
;
2178 //Header: TMapHeaderRec_1;
2183 FillChar(Result
, SizeOf(Result
), 0);
2184 FileName
:= g_ExtractWadName(Res
);
2186 WAD
:= TWADFile
.Create();
2187 if not WAD
.ReadFile(FileName
) then
2193 //k8: it ignores path again
2194 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2203 mapReader
:= g_Map_ParseMap(Data
, Len
);
2210 if (mapReader
.Width
> 0) and (mapReader
.Height
> 0) then
2212 Result
.Name
:= mapReader
.MapName
;
2213 Result
.Description
:= mapReader
.MapDesc
;
2215 Result
.Author
:= mapReader
.MapAuthor
;
2216 Result
.Height
:= mapReader
.Height
;
2217 Result
.Width
:= mapReader
.Width
;
2221 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
2222 //ZeroMemory(@Header, SizeOf(Header));
2223 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2224 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
2226 Result
.Author
:= '';
2234 function g_Map_GetMapsList(WADName
: string): SArray
;
2241 WAD
:= TWADFile
.Create();
2242 if not WAD
.ReadFile(WADName
) then
2247 ResList
:= WAD
.GetMapResources();
2248 if ResList
<> nil then
2250 for a
:= 0 to High(ResList
) do
2252 SetLength(Result
, Length(Result
)+1);
2253 Result
[High(Result
)] := ResList
[a
];
2259 function g_Map_Exist(Res
: string): Boolean;
2262 FileName
, mnn
: string;
2268 FileName
:= addWadExtension(g_ExtractWadName(Res
));
2270 WAD
:= TWADFile
.Create
;
2271 if not WAD
.ReadFile(FileName
) then
2277 ResList
:= WAD
.GetMapResources();
2280 mnn
:= g_ExtractFileName(Res
);
2281 if ResList
<> nil then
2282 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
2289 procedure g_Map_Free(freeTextures
: Boolean=true);
2293 procedure FreePanelArray(var panels
: TPanelArray
);
2298 if panels
<> nil then
2300 for i
:= 0 to High(panels
) do
2313 RespawnPoints
:= nil;
2314 if FlagPoints
[FLAG_RED
] <> nil then
2316 Dispose(FlagPoints
[FLAG_RED
]);
2317 FlagPoints
[FLAG_RED
] := nil;
2319 if FlagPoints
[FLAG_BLUE
] <> nil then
2321 Dispose(FlagPoints
[FLAG_BLUE
]);
2322 FlagPoints
[FLAG_BLUE
] := nil;
2324 //DOMFlagPoints := nil;
2328 if (Length(gCurrentMapFileName
) <> 0) then
2330 e_LogWritefln('g_Map_Free: previous map was ''%s''...', [gCurrentMapFileName
]);
2334 e_LogWritefln('g_Map_Free: no previous map.', []);
2336 if freeTextures
then
2338 e_LogWritefln('g_Map_Free: clearing textures...', []);
2339 if (Textures
<> nil) then
2341 for a
:= 0 to High(Textures
) do
2343 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2345 if Textures
[a
].Anim
then
2347 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2351 if (Textures
[a
].TextureID
<> LongWord(TEXTURE_NONE
)) then
2353 e_DeleteTexture(Textures
[a
].TextureID
);
2360 TextNameHash
.Free();
2361 TextNameHash
:= nil;
2362 BadTextNameHash
.Free();
2363 BadTextNameHash
:= nil;
2368 FreePanelArray(gWalls
);
2369 FreePanelArray(gRenderBackgrounds
);
2370 FreePanelArray(gRenderForegrounds
);
2371 FreePanelArray(gWater
);
2372 FreePanelArray(gAcid1
);
2373 FreePanelArray(gAcid2
);
2374 FreePanelArray(gSteps
);
2375 FreePanelArray(gLifts
);
2376 FreePanelArray(gBlockMon
);
2377 gMovingWallIds
:= nil;
2379 if BackID
<> DWORD(-1) then
2383 e_DeleteTexture(BackID
);
2384 BackID
:= DWORD(-1);
2387 g_Game_StopAllSounds(False);
2389 g_Sound_Delete(gMapInfo
.MusicName
);
2391 gMapInfo
.Name
:= '';
2392 gMapInfo
.Description
:= '';
2393 gMapInfo
.MusicName
:= '';
2394 gMapInfo
.Height
:= 0;
2395 gMapInfo
.Width
:= 0;
2401 procedure g_Map_Update();
2407 procedure UpdatePanelArray(var panels
: TPanelArray
);
2412 for i
:= 0 to High(panels
) do panels
[i
].Update();
2416 UpdatePanelArray(gWalls
);
2417 UpdatePanelArray(gRenderBackgrounds
);
2418 UpdatePanelArray(gRenderForegrounds
);
2419 UpdatePanelArray(gWater
);
2420 UpdatePanelArray(gAcid1
);
2421 UpdatePanelArray(gAcid2
);
2422 UpdatePanelArray(gSteps
);
2424 if gGameSettings
.GameMode
= GM_CTF
then
2426 for a
:= FLAG_RED
to FLAG_BLUE
do
2428 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2432 if gFlags
[a
].Animation
<> nil then gFlags
[a
].Animation
.Update();
2434 m
:= g_Obj_Move(@Obj
, True, True);
2436 if gTime
mod (GAME_TICK
*2) <> 0 then Continue
;
2438 // Ñîïðîòèâëåíèå âîçäóõà
2439 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2441 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó
2442 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2445 gFlags
[a
].CaptureTime
:= 0;
2446 if a
= FLAG_RED
then
2447 s
:= _lc
[I_PLAYER_FLAG_RED
]
2449 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2450 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2452 if g_Game_IsNet
then
2453 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2457 if Count
> 0 then Count
-= 1;
2460 if gPlayers
<> nil then
2462 j
:= Random(Length(gPlayers
)) - 1;
2463 for d
:= 0 to High(gPlayers
) do
2466 if j
> High(gPlayers
) then j
:= 0;
2467 if gPlayers
[j
] <> nil then
2469 if gPlayers
[j
].Live
and g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2471 if gPlayers
[j
].GetFlag(a
) then Break
;
2484 procedure g_Map_DrawPanels (PanelType
: Word);
2486 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2490 if (panels
<> nil) then
2492 // alas, no visible set
2493 for idx
:= 0 to High(panels
) do
2495 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2502 PANEL_WALL
: DrawPanels(gWalls
);
2503 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2504 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2505 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2506 PANEL_WATER
: DrawPanels(gWater
);
2507 PANEL_ACID1
: DrawPanels(gAcid1
);
2508 PANEL_ACID2
: DrawPanels(gAcid2
);
2509 PANEL_STEP
: DrawPanels(gSteps
);
2515 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2517 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2519 result
:= false; // don't stop, ever
2520 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2521 gDrawPanelList
.insert(pan
);
2526 //tagmask := panelTypeToTag(PanelType);
2527 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2528 // list will be rendered in `g_game.DrawPlayer()`
2532 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2534 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2536 result
:= false; // don't stop, ever
2537 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2541 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2545 procedure g_Map_DrawBack(dx
, dy
: Integer);
2547 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2548 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2550 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2553 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2554 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2560 if WordBool(PanelType
and PANEL_WALL
) then
2561 if gWalls
<> nil then
2566 if gWalls
[a
].Enabled
and
2567 g_Collide(X
, Y
, Width
, Height
,
2568 gWalls
[a
].X
, gWalls
[a
].Y
,
2569 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2576 if WordBool(PanelType
and PANEL_WATER
) then
2577 if gWater
<> nil then
2582 if g_Collide(X
, Y
, Width
, Height
,
2583 gWater
[a
].X
, gWater
[a
].Y
,
2584 gWater
[a
].Width
, gWater
[a
].Height
) then
2591 if WordBool(PanelType
and PANEL_ACID1
) then
2592 if gAcid1
<> nil then
2597 if g_Collide(X
, Y
, Width
, Height
,
2598 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2599 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2606 if WordBool(PanelType
and PANEL_ACID2
) then
2607 if gAcid2
<> nil then
2612 if g_Collide(X
, Y
, Width
, Height
,
2613 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2614 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2621 if WordBool(PanelType
and PANEL_STEP
) then
2622 if gSteps
<> nil then
2627 if g_Collide(X
, Y
, Width
, Height
,
2628 gSteps
[a
].X
, gSteps
[a
].Y
,
2629 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2636 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2637 if gLifts
<> nil then
2642 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2643 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2644 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2645 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2646 g_Collide(X
, Y
, Width
, Height
,
2647 gLifts
[a
].X
, gLifts
[a
].Y
,
2648 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2655 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2656 if gBlockMon
<> nil then
2658 h
:= High(gBlockMon
);
2662 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2663 g_Collide(X
, Y
, Width
, Height
,
2664 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2665 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2673 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2677 function checkPanels (constref panels
: TPanelArray
): Boolean;
2682 if panels
= nil then exit
;
2683 for a
:= 0 to High(panels
) do
2685 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2688 texid
:= panels
[a
].GetTextureID();
2695 texid
:= LongWord(TEXTURE_NONE
);
2697 if not checkPanels(gWater
) then
2698 if not checkPanels(gAcid1
) then
2699 if not checkPanels(gAcid2
) then exit
;
2704 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2706 SlowMask
= GridTagLift
or GridTagBlockMon
;
2707 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2710 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2712 result := pan.Enabled;
2717 if ((tag
and GridTagLift
) <> 0) then
2720 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2721 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2722 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2723 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2724 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2728 if ((tag
and GridTagBlockMon
) <> 0) then
2730 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2735 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2736 result
:= true; // i found her!
2740 tagmask
: Integer = 0;
2742 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2743 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2744 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2745 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2746 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2747 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2748 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2750 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2752 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2753 if gdbg_map_use_accel_coldet
then
2755 if (Width
= 1) and (Height
= 1) then
2757 if ((tagmask
and SlowMask
) <> 0) then
2760 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2765 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2770 if ((tagmask
and SlowMask
) <> 0) then
2773 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2778 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2784 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2786 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2790 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2792 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2795 // slightly different from the old code, but meh...
2796 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2798 result
:= false; // don't stop, ever
2799 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2802 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2803 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2804 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2807 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2809 texid
:= pan
.GetTextureID();
2810 // water? water has the highest priority, so stop right here
2811 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2813 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2815 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2819 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2820 if gdbg_map_use_accel_coldet
then
2822 texid
:= LongWord(TEXTURE_NONE
);
2823 if (Width
= 1) and (Height
= 1) then
2825 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2829 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2835 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2837 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2841 procedure g_Map_EnableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_EnableWallGUID(gWalls
[ID
].guid
); end;
2842 procedure g_Map_DisableWall_XXX (ID
: DWORD
); begin if (ID
< Length(gWalls
)) then g_Map_DisableWallGUID(gWalls
[ID
].guid
); end;
2843 procedure g_Map_SetLift_XXX (ID
: DWORD
; t
: Integer); begin if (ID
< Length(gLifts
)) then g_Map_SetLiftGUID(gLifts
[ID
].guid
, t
); end;
2846 procedure g_Map_EnableWallGUID (pguid
: Integer);
2850 //pan := gWalls[ID];
2851 pan
:= g_Map_PanelByGUID(pguid
);
2852 if (pan
= nil) then exit
;
2853 pan
.Enabled
:= True;
2854 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, true);
2856 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2857 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2858 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2860 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState({gWalls[ID]}pan
.PanelType
, pguid
);
2862 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2863 //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);
2868 procedure g_Map_DisableWallGUID (pguid
: Integer);
2872 //pan := gWalls[ID];
2873 pan
:= g_Map_PanelByGUID(pguid
);
2874 if (pan
= nil) then exit
;
2875 pan
.Enabled
:= False;
2876 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, false);
2878 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2879 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2881 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, pguid
);
2883 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2884 //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);
2889 procedure g_Map_SwitchTextureGUID (PanelType
: Word; pguid
: Integer; AnimLoop
: Byte = 0);
2893 tp
:= g_Map_PanelByGUID(pguid
);
2894 if (tp
= nil) then exit
;
2897 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: tp := gWalls[ID];
2898 PANEL_FORE: tp := gRenderForegrounds[ID];
2899 PANEL_BACK: tp := gRenderBackgrounds[ID];
2900 PANEL_WATER: tp := gWater[ID];
2901 PANEL_ACID1: tp := gAcid1[ID];
2902 PANEL_ACID2: tp := gAcid2[ID];
2903 PANEL_STEP: tp := gSteps[ID];
2908 tp
.NextTexture(AnimLoop
);
2909 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelTexture(PanelType
, pguid
, AnimLoop
);
2913 procedure g_Map_SetLiftGUID (pguid
: Integer; t
: Integer);
2917 //pan := gLifts[ID];
2918 pan
:= g_Map_PanelByGUID(pguid
);
2919 if (pan
= nil) then exit
;
2920 if not pan
.isGLift
then exit
;
2922 if ({gLifts[ID]}pan
.LiftType
= t
) then exit
; //!FIXME!TRIGANY!
2924 with {gLifts[ID]} pan
do
2928 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, false);
2929 //TODO: make separate lift tags, and change tag here
2932 0: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
);
2933 1: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
);
2934 2: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
);
2935 3: g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
);
2938 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, pguid
);
2943 function g_Map_GetPoint (PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2946 PointsArray
: Array of TRespawnPoint
;
2949 SetLength(PointsArray
, 0);
2951 if RespawnPoints
= nil then
2954 for a
:= 0 to High(RespawnPoints
) do
2955 if RespawnPoints
[a
].PointType
= PointType
then
2957 SetLength(PointsArray
, Length(PointsArray
)+1);
2958 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2961 if PointsArray
= nil then
2964 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2968 function g_Map_GetPointCount(PointType
: Byte): Word;
2974 if RespawnPoints
= nil then
2977 for a
:= 0 to High(RespawnPoints
) do
2978 if RespawnPoints
[a
].PointType
= PointType
then
2979 Result
:= Result
+ 1;
2982 function g_Map_HaveFlagPoints(): Boolean;
2984 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2987 procedure g_Map_ResetFlag(Flag
: Byte);
2989 with gFlags
[Flag
] do
2995 Direction
:= D_LEFT
;
2996 State
:= FLAG_STATE_NONE
;
2997 if FlagPoints
[Flag
] <> nil then
2999 Obj
.X
:= FlagPoints
[Flag
]^.X
;
3000 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
3001 Direction
:= FlagPoints
[Flag
]^.Direction
;
3002 State
:= FLAG_STATE_NORMAL
;
3008 procedure g_Map_DrawFlags();
3011 Mirror
: TMirrorType
;
3013 if gGameSettings
.GameMode
<> GM_CTF
then
3016 for i
:= FLAG_RED
to FLAG_BLUE
do
3018 if State
<> FLAG_STATE_CAPTURED
then
3020 if State
= FLAG_STATE_NONE
then
3023 if Direction
= D_LEFT
then
3025 Mirror
:= M_HORIZONTAL
;
3034 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
3036 if g_debug_Frames
then
3038 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
3040 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
3041 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
3048 procedure g_Map_SaveState (var Mem
: TBinMemoryWriter
);
3055 procedure savePanels ();
3057 PAMem
: TBinMemoryWriter
;
3060 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé
3061 PAMem
:= TBinMemoryWriter
.Create((Length(panByGUID
)+1) * 40);
3063 for pan
in panByGUID
do
3065 if true{pan.SaveIt} then
3068 //PAMem.WriteInt(i);
3070 pan
.SaveState(PAMem
);
3074 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé
3075 PAMem
.SaveToMemory(Mem
);
3079 procedure SaveFlag (flag
: PFlag
);
3082 dw
:= FLAG_SIGNATURE
; // 'FLAG'
3084 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3085 Mem
.WriteByte(flag
^.RespawnType
);
3087 Mem
.WriteByte(flag
^.State
);
3088 // Íàïðàâëåíèå ôëàãà
3089 if flag
^.Direction
= D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
3092 Obj_SaveState(@flag
^.Obj
, Mem
);
3096 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
3098 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
3102 ///// Ñîõðàíÿåì ìóçûêó: /////
3103 // Ñèãíàòóðà ìóçûêè:
3104 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
3107 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
3108 if gMusic
.NoMusic
then str
:= '' else str
:= gMusic
.Name
;
3109 Mem
.WriteString(str
, 64);
3110 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3111 dw
:= gMusic
.GetPosition();
3113 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3114 boo
:= gMusic
.SpecPause
;
3115 Mem
.WriteBoolean(boo
);
3118 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
3119 Mem
.WriteInt(gTotalMonsters
);
3122 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
3123 if gGameSettings
.GameMode
= GM_CTF
then
3125 // Ôëàã Êðàñíîé êîìàíäû
3126 SaveFlag(@gFlags
[FLAG_RED
]);
3127 // Ôëàã Ñèíåé êîìàíäû
3128 SaveFlag(@gFlags
[FLAG_BLUE
]);
3132 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3133 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3135 // Î÷êè Êðàñíîé êîìàíäû
3136 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3137 // Î÷êè Ñèíåé êîìàíäû
3138 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3144 procedure g_Map_LoadState (var Mem
: TBinMemoryReader
);
3151 procedure loadPanels ();
3153 PAMem
: TBinMemoryReader
;
3156 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé
3157 PAMem
:= TBinMemoryReader
.Create();
3158 PAMem
.LoadFromMemory(Mem
);
3160 for pan
in panByGUID
do
3162 if true{pan.SaveIt} then
3165 //PAMem.ReadInt(id);
3167 if id <> i then raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
3170 pan
.LoadState(PAMem
);
3171 //if (panels[i].arrIdx <> i) then raise Exception.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
3172 if (pan
.proxyId
>= 0) then mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
3176 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí
3180 procedure LoadFlag(flag
: PFlag
);
3185 if dw
<> FLAG_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
3186 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà
3187 Mem
.ReadByte(flag
^.RespawnType
);
3189 Mem
.ReadByte(flag
^.State
);
3190 // Íàïðàâëåíèå ôëàãà
3192 if b
= 1 then flag
^.Direction
:= D_LEFT
else flag
^.Direction
:= D_RIGHT
; // b = 2
3194 Obj_LoadState(@flag
^.Obj
, Mem
);
3198 if Mem
= nil then Exit
;
3200 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
3204 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó
3208 ///// Çàãðóæàåì ìóçûêó: /////
3212 if dw
<> MUSIC_SIGNATURE
then raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
3214 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
3215 Mem
.ReadString(str
);
3216 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè
3218 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå
3219 Mem
.ReadBoolean(boo
);
3220 // Çàïóñêàåì ýòó ìóçûêó
3221 gMusic
.SetByName(str
);
3222 gMusic
.SpecPause
:= boo
;
3225 gMusic
.SetPosition(dw
);
3228 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
3229 Mem
.ReadInt(gTotalMonsters
);
3232 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
3233 if gGameSettings
.GameMode
= GM_CTF
then
3235 // Ôëàã Êðàñíîé êîìàíäû
3236 LoadFlag(@gFlags
[FLAG_RED
]);
3237 // Ôëàã Ñèíåé êîìàíäû
3238 LoadFlag(@gFlags
[FLAG_BLUE
]);
3242 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
3243 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3245 // Î÷êè Êðàñíîé êîìàíäû
3246 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
3247 // Î÷êè Ñèíåé êîìàíäû
3248 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
3254 // trace liquid, stepping by `dx` and `dy`
3255 // return last seen liquid coords, and `false` if we're started outside of the liquid
3256 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
3258 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
3262 // started outside of the liquid?
3263 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
3264 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
3270 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit