1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {$DEFINE MAP_DEBUG_ENABLED_FLAG}
23 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
, binheap
, xprofiler
;
38 PRespawnPoint
= ^TRespawnPoint
;
39 TRespawnPoint
= record
41 Direction
: TDirection
;
45 PFlagPoint
= ^TFlagPoint
;
46 TFlagPoint
= TRespawnPoint
;
54 CaptureTime
: LongWord;
55 Animation
: TAnimation
;
56 Direction
: TDirection
;
59 function g_Map_Load(Res
: String): Boolean;
60 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
61 function g_Map_GetMapsList(WADName
: String): SArray
;
62 function g_Map_Exist(Res
: String): Boolean;
63 procedure g_Map_Free();
64 procedure g_Map_Update();
66 procedure g_Map_DrawPanels (PanelType
: Word); // unaccelerated
67 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
69 procedure g_Map_DrawBack(dx
, dy
: Integer);
70 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
71 PanelType
: Word; b1x3
: Boolean=false): Boolean;
72 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
73 procedure g_Map_EnableWall(ID
: DWORD
);
74 procedure g_Map_DisableWall(ID
: DWORD
);
75 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
76 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
77 procedure g_Map_ReAdd_DieTriggers();
78 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
80 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
81 function g_Map_GetPointCount(PointType
: Byte): Word;
83 function g_Map_HaveFlagPoints(): Boolean;
85 procedure g_Map_ResetFlag(Flag
: Byte);
86 procedure g_Map_DrawFlags();
88 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
90 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
91 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
93 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
95 // returns panel or nil
96 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
97 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
99 // returns panel or nil
100 // sets `ex` and `ey` to `x1` and `y1` when no hit was detected
101 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
104 TForEachPanelCB
= function (pan
: TPanel
): Boolean; // return `true` to stop
106 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
107 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
109 // trace liquid, stepping by `dx` and `dy`
110 // return last seen liquid coords, and `false` if we're started outside of the liquid
111 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
114 procedure g_Map_ProfilersBegin ();
115 procedure g_Map_ProfilersEnd ();
119 RESPAWNPOINT_PLAYER1
= 1;
120 RESPAWNPOINT_PLAYER2
= 2;
122 RESPAWNPOINT_RED
= 4;
123 RESPAWNPOINT_BLUE
= 5;
131 FLAG_STATE_NORMAL
= 1;
132 FLAG_STATE_DROPPED
= 2;
133 FLAG_STATE_CAPTURED
= 3;
134 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
135 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
137 FLAG_TIME
= 720; // 20 seconds
139 SKY_STRETCH
: Single = 1.5;
154 // sorted by draw priority
155 GridTagBack
= 1 shl 0;
156 GridTagStep
= 1 shl 1;
157 GridTagWall
= 1 shl 2;
158 GridTagDoor
= 1 shl 3;
159 GridTagAcid1
= 1 shl 4;
160 GridTagAcid2
= 1 shl 5;
161 GridTagWater
= 1 shl 6;
162 GridTagFore
= 1 shl 7;
163 // the following are invisible
164 GridTagLift
= 1 shl 8;
165 GridTagBlockMon
= 1 shl 9;
167 GridDrawableMask
= (GridTagBack
or GridTagStep
or GridTagWall
or GridTagDoor
or GridTagAcid1
or GridTagAcid2
or GridTagWater
or GridTagFore
);
172 gRenderBackgrounds
: TPanelArray
;
173 gRenderForegrounds
: TPanelArray
;
174 gWater
, gAcid1
, gAcid2
: TPanelArray
;
177 gBlockMon
: TPanelArray
;
178 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
179 //gDOMFlags: array of TFlag;
182 gDoorMap
: array of array of DWORD
;
183 gLiftMap
: array of array of DWORD
;
184 gWADHash
: TMD5Digest
;
185 BackID
: DWORD
= DWORD(-1);
186 gExternalResources
: TStringList
;
188 gdbg_map_use_accel_render
: Boolean = true;
189 gdbg_map_use_accel_coldet
: Boolean = true;
190 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
191 gDrawPanelList
: TBinaryHeapObj
= nil; // binary heap of all walls we have to render, populated by `g_Map_CollectDrawPanels()`
194 function panelTypeToTag (panelType
: Word): Integer; // returns GridTagXXX
198 TPanelGrid
= specialize TBodyGridBase
<TPanel
>;
201 mapGrid
: TPanelGrid
= nil; // DO NOT USE! public for debugging only!
207 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
208 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
209 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
210 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
211 utils
, sfs
, xparser
, xdynrec
, xstreams
,
212 ImagingTypes
, Imaging
, ImagingUtility
,
213 ImagingGif
, ImagingNetworkGraphics
;
216 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
217 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
218 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
221 {$IF DEFINED(D2D_NEW_MAP_READER)}
223 dfmapdef
: TDynMapDef
= nil;
226 procedure loadMapDefinition ();
228 pr
: TTextParser
= nil;
232 if (dfmapdef
<> nil) then exit
;
234 e_LogWritefln('parsing "mapdef.txt"...', []);
235 st
:= openDiskFileRO(DataDir
+'mapdef.txt');
238 e_LogWritefln('local "%smapdef.txt" not found', [DataDir
]);
242 WAD
:= TWADFile
.Create();
243 if not WAD
.ReadFile(GameWAD
) then raise Exception
.Create('cannot load "game.wad"');
244 st
:= WAD
.openFileStream('mapdef.txt');
247 if (st
= nil) then raise Exception
.Create('cannot open "mapdef.txt"');
248 pr
:= TFileTextParser
.Create(st
);
251 dfmapdef
:= TDynMapDef
.Create(pr
);
252 except on e
: Exception
do
253 raise Exception
.Create(Format('ERROR in "mapdef.txt" at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message]));
262 function panelTypeToTag (panelType
: Word): Integer;
265 PANEL_WALL
: result
:= GridTagWall
; // gWalls
266 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagDoor
; // gWalls
267 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
268 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
269 PANEL_WATER
: result
:= GridTagWater
; // gWater
270 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
271 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
272 PANEL_STEP
: result
:= GridTagStep
; // gSteps
273 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
274 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
275 else result
:= GridTagInvalid
;
280 function dplLess (a
, b
: TObject
): Boolean;
286 if (pa
.tag
< pb
.tag
) then begin result
:= true; exit
; end;
287 if (pa
.tag
> pb
.tag
) then begin result
:= false; exit
; end;
288 result
:= (pa
.arrIdx
< pb
.arrIdx
);
291 procedure dplClear ();
293 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
299 PWhere
: ^TPanelArray
;
304 PanelById
: array of TPanelID
;
305 Textures
: TLevelTextureArray
;
306 RespawnPoints
: Array of TRespawnPoint
;
307 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
308 //DOMFlagPoints: Array of TFlagPoint;
311 procedure g_Map_ProfilersBegin ();
313 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('COLSOLID', g_profile_history_size
);
314 profMapCollision
.mainBegin(g_profile_collision
);
316 if g_profile_collision
then
318 profMapCollision
.sectionBegin('*solids');
319 profMapCollision
.sectionEnd();
320 profMapCollision
.sectionBegin('liquids');
321 profMapCollision
.sectionEnd();
325 procedure g_Map_ProfilersEnd ();
327 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
331 // wall index in `gWalls` or -1
332 function g_Map_traceToNearestWall (x0
, y0
, x1
, y1
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
336 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, (GridTagWall
or GridTagDoor
));
337 if (result
<> nil) then
339 if (hitx
<> nil) then hitx
^ := ex
;
340 if (hity
<> nil) then hity
^ := ey
;
344 if (hitx
<> nil) then hitx
^ := x1
;
345 if (hity
<> nil) then hity
^ := y1
;
349 // returns panel or nil
350 function g_Map_traceToNearest (x0
, y0
, x1
, y1
: Integer; tag
: Integer; hitx
: PInteger=nil; hity
: PInteger=nil): TPanel
;
354 result
:= mapGrid
.traceRay(ex
, ey
, x0
, y0
, x1
, y1
, nil, tag
);
355 if (result
<> nil) then
357 if (hitx
<> nil) then hitx
^ := ex
;
358 if (hity
<> nil) then hity
^ := ey
;
362 if (hitx
<> nil) then hitx
^ := x1
;
363 if (hity
<> nil) then hity
^ := y1
;
368 function g_Map_HasAnyPanelAtPoint (x
, y
: Integer; panelType
: Word): Boolean;
370 function checker (pan
: TPanel
; tag
: Integer): Boolean;
373 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
375 result := pan.Enabled; // stop if wall is enabled
380 if ((tag
and GridTagLift
) <> 0) then
382 // stop if the lift of the right type
384 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
385 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
386 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
387 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3)));
391 result
:= true; // otherwise, stop anyway, 'cause `forEachAtPoint()` is guaranteed to call this only for correct panels
395 tagmask
: Integer = 0;
399 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
400 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
401 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
402 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
403 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
404 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
405 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
407 if (tagmask
= 0) then exit
;// just in case
408 if ((tagmask
and GridTagLift
) <> 0) then
411 result
:= (mapGrid
.forEachAtPoint(x
, y
, checker
, tagmask
) <> nil);
416 result
:= (mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
) <> nil);
421 function g_Map_PanelAtPoint (x
, y
: Integer; tagmask
: Integer=-1): TPanel
;
424 if (tagmask
= 0) then exit
;
425 result
:= mapGrid
.forEachAtPoint(x
, y
, nil, tagmask
);
429 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
431 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
432 (Texture
= TEXTURE_NAME_ACID1
) or
433 (Texture
= TEXTURE_NAME_ACID2
);
436 procedure CreateDoorMap();
438 PanelArray
: Array of record
444 a
, b
, c
, m
, i
, len
: Integer;
452 SetLength(PanelArray
, len
);
454 for a
:= 0 to High(gWalls
) do
455 if gWalls
[a
].Door
then
457 PanelArray
[i
].X
:= gWalls
[a
].X
;
458 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
459 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
460 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
461 PanelArray
[i
].Active
:= True;
462 PanelArray
[i
].PanelID
:= a
;
468 SetLength(PanelArray
, len
);
479 SetLength(gDoorMap
, 0);
481 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
484 if PanelArray
[a
].Active
then
486 PanelArray
[a
].Active
:= False;
487 m
:= Length(gDoorMap
);
488 SetLength(gDoorMap
, m
+1);
489 SetLength(gDoorMap
[m
], 1);
490 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
498 if PanelArray
[b
].Active
then
499 for c
:= 0 to High(gDoorMap
[m
]) do
500 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
501 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
502 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
503 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
504 gWalls
[gDoorMap
[m
, c
]].X
,
505 gWalls
[gDoorMap
[m
, c
]].Y
,
506 gWalls
[gDoorMap
[m
, c
]].Width
,
507 gWalls
[gDoorMap
[m
, c
]].Height
) then
509 PanelArray
[b
].Active
:= False;
510 SetLength(gDoorMap
[m
],
511 Length(gDoorMap
[m
])+1);
512 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
518 g_Game_StepLoading();
524 procedure CreateLiftMap();
526 PanelArray
: Array of record
531 a
, b
, c
, len
, i
, j
: Integer;
537 len
:= Length(gLifts
);
538 SetLength(PanelArray
, len
);
540 for a
:= 0 to len
-1 do
542 PanelArray
[a
].X
:= gLifts
[a
].X
;
543 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
544 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
545 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
546 PanelArray
[a
].Active
:= True;
549 SetLength(gLiftMap
, len
);
552 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
554 for a
:= 0 to len
-1 do
555 if PanelArray
[a
].Active
then
557 PanelArray
[a
].Active
:= False;
558 SetLength(gLiftMap
[i
], 32);
566 for b
:= 0 to len
-1 do
567 if PanelArray
[b
].Active
then
569 if g_CollideAround(PanelArray
[b
].X
,
572 PanelArray
[b
].Height
,
573 PanelArray
[gLiftMap
[i
, c
]].X
,
574 PanelArray
[gLiftMap
[i
, c
]].Y
,
575 PanelArray
[gLiftMap
[i
, c
]].Width
,
576 PanelArray
[gLiftMap
[i
, c
]].Height
) then
578 PanelArray
[b
].Active
:= False;
580 if j
> High(gLiftMap
[i
]) then
581 SetLength(gLiftMap
[i
],
582 Length(gLiftMap
[i
])+32);
591 SetLength(gLiftMap
[i
], j
+1);
594 g_Game_StepLoading();
597 SetLength(gLiftMap
, i
);
602 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
603 CurTex
: Integer; sav
: Boolean): Integer;
606 panels
: ^TPanelArray
;
610 case PanelRec
.PanelType
of
611 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
614 panels
:= @gRenderBackgrounds
;
616 panels
:= @gRenderForegrounds
;
625 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
628 panels
:= @gBlockMon
;
633 len
:= Length(panels
^);
634 SetLength(panels
^, len
+ 1);
636 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
637 panels
^[len
].arrIdx
:= len
;
638 panels
^[len
].proxyId
:= -1;
639 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
641 panels
^[len
].SaveIt
:= True;
645 len
:= Length(PanelByID
);
646 SetLength(PanelByID
, len
+ 1);
647 PanelByID
[len
].PWhere
:= panels
;
648 PanelByID
[len
].PArrID
:= Result
;
651 function CreateNullTexture(RecName
: String): Integer;
653 SetLength(Textures
, Length(Textures
)+1);
654 result
:= High(Textures
);
656 with Textures
[High(Textures
)] do
658 TextureName
:= RecName
;
662 TextureID
:= TEXTURE_NONE
;
666 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
669 TextureData
: Pointer;
670 WADName
, txname
: String;
671 a
, ResLength
: Integer;
675 if Textures
<> nil then
676 for a
:= 0 to High(Textures
) do
677 if Textures
[a
].TextureName
= RecName
then
678 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
683 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
684 if (RecName
= TEXTURE_NAME_WATER
) or
685 (RecName
= TEXTURE_NAME_ACID1
) or
686 (RecName
= TEXTURE_NAME_ACID2
) then
688 SetLength(Textures
, Length(Textures
)+1);
690 with Textures
[High(Textures
)] do
692 TextureName
:= RecName
;
694 if TextureName
= TEXTURE_NAME_WATER
then
695 TextureID
:= TEXTURE_SPECIAL_WATER
697 if TextureName
= TEXTURE_NAME_ACID1
then
698 TextureID
:= TEXTURE_SPECIAL_ACID1
700 if TextureName
= TEXTURE_NAME_ACID2
then
701 TextureID
:= TEXTURE_SPECIAL_ACID2
;
706 result
:= High(Textures
);
710 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
711 WADName
:= g_ExtractWadName(RecName
);
713 WAD
:= TWADFile
.Create();
715 if WADName
<> '' then
716 WADName
:= GameDir
+'/wads/'+WADName
720 WAD
.ReadFile(WADName
);
724 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
726 FreeMem(TextureData);
727 RecName := 'COMMON\ALIEN';
731 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
733 SetLength(Textures
, Length(Textures
)+1);
734 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
736 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
737 @Textures
[High(Textures
)].Width
,
738 @Textures
[High(Textures
)].Height
);
739 FreeMem(TextureData
);
740 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
741 Textures
[High(Textures
)].Anim
:= False;
743 result
:= High(Textures
);
745 else // Íåò òàêîãî ðåóñðñà â WAD'å
747 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
750 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
751 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
758 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
761 TextureWAD
: PChar = nil;
762 TextData
: Pointer = nil;
763 TextureData
: Pointer = nil;
767 TextureResource
: String;
768 _width
, _height
, _framecount
, _speed
: Integer;
769 _backanimation
: Boolean;
771 ia
: TDynImageDataArray
= nil;
772 f
, c
, frdelay
, frloop
: Integer;
776 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
778 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
779 WADName
:= g_ExtractWadName(RecName
);
781 WAD
:= TWADFile
.Create();
783 if WADName
<> '' then
784 WADName
:= GameDir
+'/wads/'+WADName
788 WAD
.ReadFile(WADName
);
790 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
794 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
795 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
801 if WADName = Map then
803 //FreeMem(TextureWAD);
804 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
810 if ResLength
< 6 then
812 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
816 // ýòî ïòèöà? ýòî ñàìîë¸ò?
817 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
818 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
820 // íåò, ýòî ñóïåðìåí!
821 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
823 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
827 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
828 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
830 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
834 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
836 TextureResource
:= cfg
.ReadStr('', 'resource', '');
837 if TextureResource
= '' then
839 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
843 _width
:= cfg
.ReadInt('', 'framewidth', 0);
844 _height
:= cfg
.ReadInt('', 'frameheight', 0);
845 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
846 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
847 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
852 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
853 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
855 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
862 SetLength(Textures
, Length(Textures
)+1);
863 with Textures
[High(Textures
)] do
865 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
866 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
868 TextureName
:= RecName
;
872 FramesCount
:= _framecount
;
874 result
:= High(Textures
);
878 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
884 // try animated image
886 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
887 if length(imgfmt) = 0 then
889 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
893 GlobalMetadata
.ClearMetaItems();
894 GlobalMetadata
.ClearMetaItemsForSaving();
895 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
897 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
900 if length(ia
) = 0 then
902 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
909 _width
:= ia
[0].width
;
910 _height
:= ia
[0].height
;
911 _framecount
:= length(ia
);
913 _backanimation
:= false;
916 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
918 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
920 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
922 if f
< 0 then f
:= 0;
925 if c
< 13 then c
:= 0 else c
:= 1;
927 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
932 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
934 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
936 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
938 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
942 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
943 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
944 f
:= ord(_backanimation
);
945 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
);
947 SetLength(Textures
, Length(Textures
)+1);
948 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
949 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
951 Textures
[High(Textures
)].TextureName
:= RecName
;
952 Textures
[High(Textures
)].Width
:= _width
;
953 Textures
[High(Textures
)].Height
:= _height
;
954 Textures
[High(Textures
)].Anim
:= True;
955 Textures
[High(Textures
)].FramesCount
:= length(ia
);
956 Textures
[High(Textures
)].Speed
:= _speed
;
957 result
:= High(Textures
);
958 //writeln(' CREATED!');
962 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
966 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
969 if TextureWAD
<> nil then FreeMem(TextureWAD
);
970 if TextData
<> nil then FreeMem(TextData
);
971 if TextureData
<> nil then FreeMem(TextureData
);
975 procedure CreateItem(Item
: TItemRec_1
);
977 if g_Game_IsClient
then Exit
;
979 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
980 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
983 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
984 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
987 procedure CreateArea(Area
: TAreaRec_1
);
992 case Area
.AreaType
of
993 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
994 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
996 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
997 with RespawnPoints
[High(RespawnPoints
)] do
1001 Direction
:= TDirection(Area
.Direction
);
1003 case Area
.AreaType
of
1004 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
1005 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
1006 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
1007 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
1008 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
1013 AREA_REDFLAG
, AREA_BLUEFLAG
:
1015 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
1017 if FlagPoints
[a
] <> nil then Exit
;
1021 with FlagPoints
[a
]^ do
1023 X
:= Area
.X
-FLAGRECT
.X
;
1024 Y
:= Area
.Y
-FLAGRECT
.Y
;
1025 Direction
:= TDirection(Area
.Direction
);
1031 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
1032 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
1035 Animation
:= TAnimation
.Create(id
, True, 8);
1036 Obj
.Rect
:= FLAGRECT
;
1044 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
1045 with DOMFlagPoints[High(DOMFlagPoints)] do
1049 Direction := TDirection(Area.Direction);
1052 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
1057 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
1061 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
1067 Width
:= Trigger
.Width
;
1068 Height
:= Trigger
.Height
;
1069 Enabled
:= ByteBool(Trigger
.Enabled
);
1070 TexturePanel
:= Trigger
.TexturePanel
;
1071 TexturePanelType
:= fTexturePanel1Type
;
1072 ShotPanelType
:= fTexturePanel2Type
;
1073 TriggerType
:= Trigger
.TriggerType
;
1074 ActivateType
:= Trigger
.ActivateType
;
1075 Keys
:= Trigger
.Keys
;
1076 Data
.Default
:= Trigger
.DATA
;
1079 g_Triggers_Create(_trigger
);
1082 procedure CreateMonster(monster
: TMonsterRec_1
);
1087 if g_Game_IsClient
then Exit
;
1089 if (gGameSettings
.GameType
= GT_SINGLE
)
1090 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
1092 mon
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
, TDirection(monster
.Direction
));
1094 if gTriggers
<> nil then
1096 for a
:= 0 to High(gTriggers
) do
1098 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1100 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1105 if monster
.MonsterType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1109 procedure g_Map_ReAdd_DieTriggers();
1111 function monsDieTrig (mon
: TMonster
): Boolean;
1115 result
:= false; // don't stop
1116 mon
.ClearTriggers();
1117 for a
:= 0 to High(gTriggers
) do
1119 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
1121 if (gTriggers
[a
].Data
.MonsterID
-1) = mon
.StartID
then mon
.AddTrigger(a
);
1127 if g_Game_IsClient
then Exit
;
1129 g_Mons_ForEach(monsDieTrig
);
1132 function extractWadName(resourceName
: string): string;
1136 posN
:= Pos(':', resourceName
);
1138 Result
:= Copy(resourceName
, 0, posN
-1)
1143 procedure addResToExternalResList(res
: string);
1145 res
:= extractWadName(res
);
1146 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
1147 gExternalResources
.Add(res
);
1150 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
1152 textures
: TTexturesRec1Array
;
1153 mapHeader
: TMapHeaderRec_1
;
1155 resFile
: String = '';
1157 if gExternalResources
= nil then
1158 gExternalResources
:= TStringList
.Create
;
1160 gExternalResources
.Clear
;
1161 textures
:= mapReader
.GetTextures();
1162 for i
:= 0 to High(textures
) do
1164 addResToExternalResList(resFile
);
1169 mapHeader
:= mapReader
.GetMapHeader
;
1171 addResToExternalResList(mapHeader
.MusicName
);
1172 addResToExternalResList(mapHeader
.SkyName
);
1176 procedure mapCreateGrid ();
1178 mapX0
: Integer = $3fffffff;
1179 mapY0
: Integer = $3fffffff;
1180 mapX1
: Integer = -$3fffffff;
1181 mapY1
: Integer = -$3fffffff;
1183 procedure calcBoundingBox (constref panels
: TPanelArray
);
1188 for idx
:= 0 to High(panels
) do
1191 if not pan
.visvalid
then continue
;
1192 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1193 if (mapX0
> pan
.x0
) then mapX0
:= pan
.x0
;
1194 if (mapY0
> pan
.y0
) then mapY0
:= pan
.y0
;
1195 if (mapX1
< pan
.x1
) then mapX1
:= pan
.x1
;
1196 if (mapY1
< pan
.y1
) then mapY1
:= pan
.y1
;
1200 procedure addPanelsToGrid (constref panels
: TPanelArray
);
1206 //tag := panelTypeToTag(tag);
1207 for idx
:= 0 to High(panels
) do
1210 if not pan
.visvalid
then continue
;
1211 if (pan
.proxyId
<> -1) then
1213 {$IF DEFINED(D2F_DEBUG)}
1214 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
);
1218 case pan
.PanelType
of
1219 PANEL_WALL
: newtag
:= GridTagWall
;
1220 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: newtag
:= GridTagDoor
;
1221 PANEL_BACK
: newtag
:= GridTagBack
;
1222 PANEL_FORE
: newtag
:= GridTagFore
;
1223 PANEL_WATER
: newtag
:= GridTagWater
;
1224 PANEL_ACID1
: newtag
:= GridTagAcid1
;
1225 PANEL_ACID2
: newtag
:= GridTagAcid2
;
1226 PANEL_STEP
: newtag
:= GridTagStep
;
1227 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: newtag
:= GridTagLift
;
1228 PANEL_BLOCKMON
: newtag
:= GridTagBlockMon
;
1229 else continue
; // oops
1233 pan
.proxyId
:= mapGrid
.insertBody(pan
, pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, newtag
);
1234 // "enabled" flag has meaning only for doors and walls (engine assumes it); but meh...
1235 mapGrid
.proxyEnabled
[pan
.proxyId
] := pan
.Enabled
;
1236 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
1238 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
1240 e_WriteLog(Format('INSERTED wall #%d(%d) enabled (%d)', [Integer(idx), Integer(pan.proxyId), Integer(mapGrid.proxyEnabled[pan.proxyId])]), MSG_NOTIFY);
1251 calcBoundingBox(gWalls
);
1252 calcBoundingBox(gRenderBackgrounds
);
1253 calcBoundingBox(gRenderForegrounds
);
1254 calcBoundingBox(gWater
);
1255 calcBoundingBox(gAcid1
);
1256 calcBoundingBox(gAcid2
);
1257 calcBoundingBox(gSteps
);
1258 calcBoundingBox(gLifts
);
1259 calcBoundingBox(gBlockMon
);
1261 e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
, gMapInfo
.Width
, gMapInfo
.Height
]);
1263 if (mapX0
> 0) then mapX0
:= 0;
1264 if (mapY0
> 0) then mapY0
:= 0;
1266 if (mapX1
< gMapInfo
.Width
-1) then mapX1
:= gMapInfo
.Width
-1;
1267 if (mapY1
< gMapInfo
.Height
-1) then mapY1
:= gMapInfo
.Height
-1;
1269 mapGrid
:= TPanelGrid
.Create(mapX0
-128, mapY0
-128, mapX1
-mapX0
+1+128*2, mapY1
-mapY0
+1+128*2);
1270 //mapGrid := TPanelGrid.Create(0, 0, gMapInfo.Width, gMapInfo.Height);
1272 addPanelsToGrid(gWalls
);
1273 addPanelsToGrid(gRenderBackgrounds
);
1274 addPanelsToGrid(gRenderForegrounds
);
1275 addPanelsToGrid(gWater
);
1276 addPanelsToGrid(gAcid1
);
1277 addPanelsToGrid(gAcid2
);
1278 addPanelsToGrid(gSteps
);
1279 addPanelsToGrid(gLifts
); // it doesn't matter which LIFT type is used here
1280 addPanelsToGrid(gBlockMon
);
1282 mapGrid
.dumpStats();
1284 g_Mons_InitTree(mapGrid
.gridX0
, mapGrid
.gridY0
, mapGrid
.gridWidth
, mapGrid
.gridHeight
);
1288 function g_Map_Load(Res
: String): Boolean;
1290 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1291 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1294 MapReader
: TMapReader_1
;
1295 Header
: TMapHeaderRec_1
;
1296 _textures
: TTexturesRec1Array
;
1297 _texnummap
: array of Integer; // `_textures` -> `Textures`
1298 panels
: TPanelsRec1Array
;
1299 items
: TItemsRec1Array
;
1300 monsters
: TMonsterRec1Array
;
1301 areas
: TAreasRec1Array
;
1302 triggers
: TTriggersRec1Array
;
1303 a
, b
, c
, k
: Integer;
1305 AddTextures
: TAddTextureArray
;
1306 texture
: TTextureRec_1
;
1307 TriggersTable
: Array of record
1308 TexturePanel
: Integer;
1313 FileName
, mapResName
, s
, TexName
: String;
1316 ok
, isAnim
, trigRef
: Boolean;
1317 CurTex
, ntn
: Integer;
1318 {$IF DEFINED(D2D_NEW_MAP_READER)}
1319 pr
: TTextParser
= nil;
1321 wst
: TSFSMemoryChunkStream
= nil;
1329 gMapInfo
.Map
:= Res
;
1330 TriggersTable
:= nil;
1331 FillChar(texture
, SizeOf(texture
), 0);
1333 sfsGCDisable(); // temporary disable removing of temporary volumes
1336 FileName
:= g_ExtractWadName(Res
);
1337 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1338 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1340 WAD
:= TWADFile
.Create();
1341 if not WAD
.ReadFile(FileName
) then
1343 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1348 //k8: why loader ignores path here?
1349 mapResName
:= g_ExtractFileName(Res
);
1350 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1352 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1361 e_LogWritefln('invalid map file: ''%s''', [mapResName
]);
1367 e_LogWritefln('Loading map: %s', [mapResName
], MSG_NOTIFY
);
1368 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1370 {$IF DEFINED(D2D_NEW_MAP_READER)}
1371 if (PChar(Data
)[0] = 'M') and (PChar(Data
)[1] = 'A') and (PChar(Data
)[2] = 'P') and (PByte(Data
)[3] = 1) then
1377 e_LogWritefln('Loading text map: %s', [mapResName
]);
1378 loadMapDefinition();
1379 if (dfmapdef
= nil) then raise Exception
.Create('internal map loader error');
1380 //e_LogWritefln('***'#10'%s'#10'***', [dfmapdef.headerType.definition]);
1381 wst
:= TSFSMemoryChunkStream
.Create(Data
, Len
);
1383 pr
:= TFileTextParser
.Create(wst
);
1384 e_LogWritefln('parsing text map: %s', [mapResName
]);
1385 rec
:= dfmapdef
.parseMap(pr
);
1386 except on e
: Exception
do
1388 if (pr
<> nil) then e_LogWritefln('ERROR at (%s,%s): %s', [pr
.line
, pr
.col
, e
.message])
1389 else e_LogWritefln('ERROR: %s', [e
.message]);
1397 //wst.Free(); // pr will do it
1398 e_LogWritefln('writing text map to temporary bin storage...', []);
1399 st
:= TMemoryStream
.Create();
1402 Len
:= Integer(st
.position
);
1406 st
.ReadBuffer(Data
^, Len
);
1407 except on e
: Exception
do
1411 e_LogWritefln('ERROR: %s', [e
.message]);
1420 MapReader
:= TMapReader_1
.Create();
1422 if not MapReader
.LoadMap(Data
) then
1424 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1431 generateExternalResourcesList(MapReader
);
1432 // Çàãðóçêà òåêñòóð:
1433 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1434 _textures
:= MapReader
.GetTextures();
1437 // Çàãðóçêà îïèñàíèÿ êàðòû:
1438 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1439 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1440 Header
:= MapReader
.GetMapHeader();
1444 Name
:= Header
.MapName
;
1445 Description
:= Header
.MapDescription
;
1446 Author
:= Header
.MapAuthor
;
1447 MusicName
:= Header
.MusicName
;
1448 SkyName
:= Header
.SkyName
;
1449 Height
:= Header
.Height
;
1450 Width
:= Header
.Width
;
1453 // Äîáàâëåíèå òåêñòóð â Textures[]:
1454 if _textures
<> nil then
1456 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1457 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1458 SetLength(_texnummap
, length(_textures
));
1460 for a
:= 0 to High(_textures
) do
1463 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1464 for b
:= 1 to Length(s
) do
1472 {$IF DEFINED(D2F_DEBUG)}
1473 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1475 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1476 // Àíèìèðîâàííàÿ òåêñòóðà:
1477 if ByteBool(_textures
[a
].Anim
) then
1479 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1482 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1483 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1486 else // Îáû÷íàÿ òåêñòóðà:
1487 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1490 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1491 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1494 _texnummap
[a
] := ntn
; // fix texture number
1495 g_Game_StepLoading();
1499 // Çàãðóçêà òðèããåðîâ:
1500 gTriggerClientID
:= 0;
1501 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1502 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1503 triggers
:= MapReader
.GetTriggers();
1505 // Çàãðóçêà ïàíåëåé:
1506 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1507 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1508 panels
:= MapReader
.GetPanels();
1510 // check texture numbers for panels
1511 for a
:= 0 to High(panels
) do
1513 if panels
[a
].TextureNum
> High(_textures
) then
1515 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1519 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1522 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1523 if triggers
<> nil then
1525 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1526 SetLength(TriggersTable
, Length(triggers
));
1527 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1529 for a
:= 0 to High(TriggersTable
) do
1531 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1532 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1534 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1535 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1537 TriggersTable
[a
].LiftPanel
:= -1;
1539 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1540 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1541 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1542 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1544 TriggersTable
[a
].DoorPanel
:= -1;
1546 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1547 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1549 TriggersTable
[a
].ShotPanel
:= -1;
1551 g_Game_StepLoading();
1556 if panels
<> nil then
1558 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1559 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1561 for a
:= 0 to High(panels
) do
1563 SetLength(AddTextures
, 0);
1566 if _textures
<> nil then
1568 texture
:= _textures
[panels
[a
].TextureNum
];
1576 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1577 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1579 if (TriggersTable
<> nil) and (_textures
<> nil) then
1580 for b
:= 0 to High(TriggersTable
) do
1581 if (TriggersTable
[b
].TexturePanel
= a
)
1582 or (TriggersTable
[b
].ShotPanel
= a
) then
1591 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1593 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1596 for c
:= Len
downto 1 do
1604 // Ñïåö-òåêñòóðû çàïðåùåíû:
1605 if g_Map_IsSpecialTexture(s
) then
1608 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1609 ok
:= g_Texture_NumNameFindStart(s
);
1611 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1612 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1615 k
:= NNF_NAME_BEFORE
;
1616 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1617 while ok
or (k
= NNF_NAME_BEFORE
) or
1618 (k
= NNF_NAME_EQUALS
) do
1620 k
:= g_Texture_NumNameFindNext(TexName
);
1622 if (k
= NNF_NAME_BEFORE
) or
1623 (k
= NNF_NAME_AFTER
) then
1625 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1626 if ByteBool(texture
.Anim
) then
1627 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1629 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1631 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1633 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1637 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1639 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1641 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1643 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1647 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1650 for c
:= 0 to High(Textures
) do
1651 if Textures
[c
].TextureName
= TexName
then
1653 SetLength(AddTextures
, Length(AddTextures
)+1);
1654 AddTextures
[High(AddTextures
)].Texture
:= c
;
1655 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1661 if k
= NNF_NAME_EQUALS
then
1663 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1664 SetLength(AddTextures
, Length(AddTextures
)+1);
1665 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1666 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1667 CurTex
:= High(AddTextures
);
1675 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1676 end; // if ok - ññûëàþòñÿ òðèããåðû
1680 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1681 SetLength(AddTextures
, 1);
1682 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1683 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1687 //e_WriteLog(Format('panel #%d: TextureNum=%d; ht=%d; ht1=%d; atl=%d', [a, panels[a].TextureNum, High(_textures), High(Textures), High(AddTextures)]), MSG_NOTIFY);
1689 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1690 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1692 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1693 if TriggersTable
<> nil then
1694 for b
:= 0 to High(TriggersTable
) do
1696 // Òðèããåð äâåðè/ëèôòà:
1697 if (TriggersTable
[b
].LiftPanel
= a
) or
1698 (TriggersTable
[b
].DoorPanel
= a
) then
1699 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1700 // Òðèããåð ñìåíû òåêñòóðû:
1701 if TriggersTable
[b
].TexturePanel
= a
then
1702 triggers
[b
].TexturePanel
:= PanelID
;
1703 // Òðèããåð "Òóðåëü":
1704 if TriggersTable
[b
].ShotPanel
= a
then
1705 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1708 g_Game_StepLoading();
1712 // create map grid, init other grids (for monsters, for example)
1713 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1716 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1717 if (triggers
<> nil) and not gLoadGameMode
then
1719 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1720 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1721 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1722 for a
:= 0 to High(triggers
) do
1724 if triggers
[a
].TexturePanel
<> -1 then
1725 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1728 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1729 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1730 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1733 CreateTrigger(triggers
[a
], b
, c
);
1737 // Çàãðóçêà ïðåäìåòîâ:
1738 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1739 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1740 items
:= MapReader
.GetItems();
1742 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1743 if (items
<> nil) and not gLoadGameMode
then
1745 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1746 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1747 for a
:= 0 to High(items
) do
1748 CreateItem(Items
[a
]);
1751 // Çàãðóçêà îáëàñòåé:
1752 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1753 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1754 areas
:= MapReader
.GetAreas();
1756 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1757 if areas
<> nil then
1759 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1760 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1761 for a
:= 0 to High(areas
) do
1762 CreateArea(areas
[a
]);
1765 // Çàãðóçêà ìîíñòðîâ:
1766 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1767 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1768 monsters
:= MapReader
.GetMonsters();
1770 gTotalMonsters
:= 0;
1772 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1773 if (monsters
<> nil) and not gLoadGameMode
then
1775 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1776 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1777 for a
:= 0 to High(monsters
) do
1778 CreateMonster(monsters
[a
]);
1784 if gMapInfo
.SkyName
<> '' then
1786 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1787 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1788 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1790 if FileName
<> '' then
1791 FileName
:= GameDir
+'/wads/'+FileName
1794 FileName
:= g_ExtractWadName(Res
);
1797 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1798 if g_Texture_CreateWAD(BackID
, s
) then
1800 g_Game_SetupScreenSize();
1803 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1808 if gMapInfo
.MusicName
<> '' then
1810 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1811 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1812 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1814 if FileName
<> '' then
1815 FileName
:= GameDir
+'/wads/'+FileName
1818 FileName
:= g_ExtractWadName(Res
);
1821 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1822 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1825 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1828 // Îñòàëüíûå óñòàíâêè:
1836 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1837 if not gLoadGameMode
then
1840 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1846 TriggersTable
:= nil;
1849 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1850 if ok
and (not gLoadGameMode
) then
1852 gMusic
.SetByName(gMapInfo
.MusicName
);
1856 gMusic
.SetByName('');
1858 sfsGCEnable(); // enable releasing unused volumes
1861 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1865 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1868 MapReader
: TMapReader_1
;
1869 Header
: TMapHeaderRec_1
;
1874 FillChar(Result
, SizeOf(Result
), 0);
1875 FileName
:= g_ExtractWadName(Res
);
1877 WAD
:= TWADFile
.Create();
1878 if not WAD
.ReadFile(FileName
) then
1884 //k8: it ignores path again
1885 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1893 MapReader
:= TMapReader_1
.Create();
1895 if not MapReader
.LoadMap(Data
) then
1897 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1898 ZeroMemory(@Header
, SizeOf(Header
));
1899 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1900 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1904 Header
:= MapReader
.GetMapHeader();
1905 Result
.Name
:= Header
.MapName
;
1906 Result
.Description
:= Header
.MapDescription
;
1913 Result
.Author
:= Header
.MapAuthor
;
1914 Result
.Height
:= Header
.Height
;
1915 Result
.Width
:= Header
.Width
;
1918 function g_Map_GetMapsList(WADName
: string): SArray
;
1925 WAD
:= TWADFile
.Create();
1926 if not WAD
.ReadFile(WADName
) then
1931 ResList
:= WAD
.GetMapResources();
1932 if ResList
<> nil then
1934 for a
:= 0 to High(ResList
) do
1936 SetLength(Result
, Length(Result
)+1);
1937 Result
[High(Result
)] := ResList
[a
];
1943 function g_Map_Exist(Res
: string): Boolean;
1946 FileName
, mnn
: string;
1952 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1954 WAD
:= TWADFile
.Create
;
1955 if not WAD
.ReadFile(FileName
) then
1961 ResList
:= WAD
.GetMapResources();
1964 mnn
:= g_ExtractFileName(Res
);
1965 if ResList
<> nil then
1966 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1973 procedure g_Map_Free();
1977 procedure FreePanelArray(var panels
: TPanelArray
);
1982 if panels
<> nil then
1984 for i
:= 0 to High(panels
) do
1997 RespawnPoints
:= nil;
1998 if FlagPoints
[FLAG_RED
] <> nil then
2000 Dispose(FlagPoints
[FLAG_RED
]);
2001 FlagPoints
[FLAG_RED
] := nil;
2003 if FlagPoints
[FLAG_BLUE
] <> nil then
2005 Dispose(FlagPoints
[FLAG_BLUE
]);
2006 FlagPoints
[FLAG_BLUE
] := nil;
2008 //DOMFlagPoints := nil;
2012 if Textures
<> nil then
2014 for a
:= 0 to High(Textures
) do
2015 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
2016 if Textures
[a
].Anim
then
2017 g_Frames_DeleteByID(Textures
[a
].FramesID
)
2019 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
2020 e_DeleteTexture(Textures
[a
].TextureID
);
2025 FreePanelArray(gWalls
);
2026 FreePanelArray(gRenderBackgrounds
);
2027 FreePanelArray(gRenderForegrounds
);
2028 FreePanelArray(gWater
);
2029 FreePanelArray(gAcid1
);
2030 FreePanelArray(gAcid2
);
2031 FreePanelArray(gSteps
);
2032 FreePanelArray(gLifts
);
2033 FreePanelArray(gBlockMon
);
2035 if BackID
<> DWORD(-1) then
2039 e_DeleteTexture(BackID
);
2040 BackID
:= DWORD(-1);
2043 g_Game_StopAllSounds(False);
2045 g_Sound_Delete(gMapInfo
.MusicName
);
2047 gMapInfo
.Name
:= '';
2048 gMapInfo
.Description
:= '';
2049 gMapInfo
.MusicName
:= '';
2050 gMapInfo
.Height
:= 0;
2051 gMapInfo
.Width
:= 0;
2059 procedure g_Map_Update();
2065 procedure UpdatePanelArray(var panels
: TPanelArray
);
2070 if panels
<> nil then
2071 for i
:= 0 to High(panels
) do
2076 UpdatePanelArray(gWalls
);
2077 UpdatePanelArray(gRenderBackgrounds
);
2078 UpdatePanelArray(gRenderForegrounds
);
2079 UpdatePanelArray(gWater
);
2080 UpdatePanelArray(gAcid1
);
2081 UpdatePanelArray(gAcid2
);
2082 UpdatePanelArray(gSteps
);
2084 if gGameSettings
.GameMode
= GM_CTF
then
2086 for a
:= FLAG_RED
to FLAG_BLUE
do
2087 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
2090 if gFlags
[a
].Animation
<> nil then
2091 gFlags
[a
].Animation
.Update();
2093 m
:= g_Obj_Move(@Obj
, True, True);
2095 if gTime
mod (GAME_TICK
*2) <> 0 then
2098 // Ñîïðîòèâëåíèå âîçäóõà:
2099 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
2101 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
2102 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
2105 gFlags
[a
].CaptureTime
:= 0;
2106 if a
= FLAG_RED
then
2107 s
:= _lc
[I_PLAYER_FLAG_RED
]
2109 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
2110 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
2112 if g_Game_IsNet
then
2113 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
2120 // Èãðîê áåðåò ôëàã:
2121 if gPlayers
<> nil then
2123 j
:= Random(Length(gPlayers
)) - 1;
2125 for d
:= 0 to High(gPlayers
) do
2128 if j
> High(gPlayers
) then
2131 if gPlayers
[j
] <> nil then
2132 if gPlayers
[j
].Live
and
2133 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
2135 if gPlayers
[j
].GetFlag(a
) then
2146 procedure g_Map_DrawPanels (PanelType
: Word);
2148 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
2152 if (panels
<> nil) then
2154 // alas, no visible set
2155 for idx
:= 0 to High(panels
) do
2157 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
2164 PANEL_WALL
: DrawPanels(gWalls
);
2165 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
2166 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
2167 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
2168 PANEL_WATER
: DrawPanels(gWater
);
2169 PANEL_ACID1
: DrawPanels(gAcid1
);
2170 PANEL_ACID2
: DrawPanels(gAcid2
);
2171 PANEL_STEP
: DrawPanels(gSteps
);
2177 procedure g_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
2179 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2181 result
:= false; // don't stop, ever
2182 if ((tag
and GridTagDoor
) <> 0) <> pan
.Door
then exit
;
2183 gDrawPanelList
.insert(pan
);
2188 //tagmask := panelTypeToTag(PanelType);
2189 mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, GridDrawableMask
);
2190 // list will be rendered in `g_game.DrawPlayer()`
2194 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2196 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2198 result
:= false; // don't stop, ever
2199 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2203 mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, (GridTagWall
or GridTagDoor
));
2207 procedure g_Map_DrawBack(dx
, dy
: Integer);
2209 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2210 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2212 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2215 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2216 PanelType
: Word; b1x3
: Boolean=false): Boolean;
2222 if WordBool(PanelType
and PANEL_WALL
) then
2223 if gWalls
<> nil then
2228 if gWalls
[a
].Enabled
and
2229 g_Collide(X
, Y
, Width
, Height
,
2230 gWalls
[a
].X
, gWalls
[a
].Y
,
2231 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2238 if WordBool(PanelType
and PANEL_WATER
) then
2239 if gWater
<> nil then
2244 if g_Collide(X
, Y
, Width
, Height
,
2245 gWater
[a
].X
, gWater
[a
].Y
,
2246 gWater
[a
].Width
, gWater
[a
].Height
) then
2253 if WordBool(PanelType
and PANEL_ACID1
) then
2254 if gAcid1
<> nil then
2259 if g_Collide(X
, Y
, Width
, Height
,
2260 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2261 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2268 if WordBool(PanelType
and PANEL_ACID2
) then
2269 if gAcid2
<> nil then
2274 if g_Collide(X
, Y
, Width
, Height
,
2275 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2276 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2283 if WordBool(PanelType
and PANEL_STEP
) then
2284 if gSteps
<> nil then
2289 if g_Collide(X
, Y
, Width
, Height
,
2290 gSteps
[a
].X
, gSteps
[a
].Y
,
2291 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2298 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2299 if gLifts
<> nil then
2304 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2305 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2306 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2307 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2308 g_Collide(X
, Y
, Width
, Height
,
2309 gLifts
[a
].X
, gLifts
[a
].Y
,
2310 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2317 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2318 if gBlockMon
<> nil then
2320 h
:= High(gBlockMon
);
2324 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2325 g_Collide(X
, Y
, Width
, Height
,
2326 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2327 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2335 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2339 function checkPanels (constref panels
: TPanelArray
): Boolean;
2344 if panels
= nil then exit
;
2345 for a
:= 0 to High(panels
) do
2347 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2350 texid
:= panels
[a
].GetTextureID();
2357 texid
:= TEXTURE_NONE
;
2359 if not checkPanels(gWater
) then
2360 if not checkPanels(gAcid1
) then
2361 if not checkPanels(gAcid2
) then exit
;
2366 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2368 SlowMask
= GridTagLift
or GridTagBlockMon
;
2369 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2372 if ((tag and (GridTagWall or GridTagDoor)) <> 0) then
2374 result := pan.Enabled;
2379 if ((tag
and GridTagLift
) <> 0) then
2382 ((WordBool(PanelType
and PANEL_LIFTUP
) and (pan
.LiftType
= 0)) or
2383 (WordBool(PanelType
and PANEL_LIFTDOWN
) and (pan
.LiftType
= 1)) or
2384 (WordBool(PanelType
and PANEL_LIFTLEFT
) and (pan
.LiftType
= 2)) or
2385 (WordBool(PanelType
and PANEL_LIFTRIGHT
) and (pan
.LiftType
= 3))) {and
2386 g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height)};
2390 if ((tag
and GridTagBlockMon
) <> 0) then
2392 result
:= ((not b1x3
) or (pan
.Width
+pan
.Height
>= 64)); //and g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2397 //result := g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height);
2398 result
:= true; // i found her!
2402 tagmask
: Integer = 0;
2404 if WordBool(PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or PANEL_OPENDOOR
)) then tagmask
:= tagmask
or (GridTagWall
or GridTagDoor
);
2405 if WordBool(PanelType
and PANEL_WATER
) then tagmask
:= tagmask
or GridTagWater
;
2406 if WordBool(PanelType
and PANEL_ACID1
) then tagmask
:= tagmask
or GridTagAcid1
;
2407 if WordBool(PanelType
and PANEL_ACID2
) then tagmask
:= tagmask
or GridTagAcid2
;
2408 if WordBool(PanelType
and PANEL_STEP
) then tagmask
:= tagmask
or GridTagStep
;
2409 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then tagmask
:= tagmask
or GridTagLift
;
2410 if WordBool(PanelType
and PANEL_BLOCKMON
) then tagmask
:= tagmask
or GridTagBlockMon
;
2412 if (tagmask
= 0) then begin result
:= false; exit
; end; // just in case
2414 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('*solids');
2415 if gdbg_map_use_accel_coldet
then
2417 if (Width
= 1) and (Height
= 1) then
2419 if ((tagmask
and SlowMask
) <> 0) then
2422 result
:= (mapGrid
.forEachAtPoint(X
, Y
, checker
, tagmask
) <> nil);
2427 result
:= (mapGrid
.forEachAtPoint(X
, Y
, nil, tagmask
) <> nil);
2432 if ((tagmask
and SlowMask
) <> 0) then
2435 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, tagmask
) <> nil);
2440 result
:= (mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, nil, tagmask
) <> nil);
2446 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2448 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2452 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2454 cctype
: Integer = 3; // priority: 0: water was hit, 1: acid1 was hit, 2: acid2 was hit; 3: nothing was hit
2457 // slightly different from the old code, but meh...
2458 function checker (pan
: TPanel
; tag
: Integer): Boolean;
2460 result
:= false; // don't stop, ever
2461 //if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2)) = 0) then exit;
2464 0: if ((tag
and GridTagWater
) = 0) then exit
; // allowed: water
2465 1: if ((tag
and (GridTagWater
or GridTagAcid1
)) = 0) then exit
; // allowed: water, acid1
2466 //2: if ((tag and (GridTagWater or GridTagAcid1 or GridTagAcid2) = 0) then exit; // allowed: water, acid1, acid2
2469 //if not g_Collide(X, Y, Width, Height, pan.X, pan.Y, pan.Width, pan.Height) then exit;
2471 texid
:= pan
.GetTextureID();
2472 // water? water has the highest priority, so stop right here
2473 if ((tag
and GridTagWater
) <> 0) then begin cctype
:= 0; result
:= true; exit
; end;
2475 if ((tag
and GridTagAcid2
) <> 0) then cctype
:= 2;
2477 if ((tag
and GridTagAcid1
) <> 0) then cctype
:= 1;
2481 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquids');
2482 if gdbg_map_use_accel_coldet
then
2484 texid
:= TEXTURE_NONE
;
2485 if (Width
= 1) and (Height
= 1) then
2487 mapGrid
.forEachAtPoint(X
, Y
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2491 mapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2497 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2499 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2503 procedure g_Map_EnableWall(ID
: DWORD
);
2508 pan
.Enabled
:= True;
2509 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, True);
2511 mapGrid
.proxyEnabled
[pan
.proxyId
] := true;
2512 //if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := true
2513 //else pan.proxyId := mapGrid.insertBody(pan, pan.X, pan.Y, pan.Width, pan.Height, GridTagDoor);
2515 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(gWalls
[ID
].PanelType
, ID
);
2517 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2518 //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);
2522 procedure g_Map_DisableWall(ID
: DWORD
);
2527 pan
.Enabled
:= False;
2528 g_Mark(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, MARK_DOOR
, False);
2530 mapGrid
.proxyEnabled
[pan
.proxyId
] := false;
2531 //if (pan.proxyId >= 0) then begin mapGrid.removeBody(pan.proxyId); pan.proxyId := -1; end;
2533 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(pan
.PanelType
, ID
);
2535 {$IFDEF MAP_DEBUG_ENABLED_FLAG}
2536 //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);
2540 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2545 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2548 tp
:= gRenderForegrounds
[ID
];
2550 tp
:= gRenderBackgrounds
[ID
];
2563 tp
.NextTexture(AnimLoop
);
2564 if g_Game_IsServer
and g_Game_IsNet
then
2565 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2568 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2570 if gLifts
[ID
].LiftType
= t
then
2577 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2578 //TODO: make separate lift tags, and change tag here
2580 if LiftType
= 0 then
2581 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2582 else if LiftType
= 1 then
2583 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2584 else if LiftType
= 2 then
2585 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2586 else if LiftType
= 3 then
2587 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2589 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2593 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2596 PointsArray
: Array of TRespawnPoint
;
2599 SetLength(PointsArray
, 0);
2601 if RespawnPoints
= nil then
2604 for a
:= 0 to High(RespawnPoints
) do
2605 if RespawnPoints
[a
].PointType
= PointType
then
2607 SetLength(PointsArray
, Length(PointsArray
)+1);
2608 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2611 if PointsArray
= nil then
2614 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2618 function g_Map_GetPointCount(PointType
: Byte): Word;
2624 if RespawnPoints
= nil then
2627 for a
:= 0 to High(RespawnPoints
) do
2628 if RespawnPoints
[a
].PointType
= PointType
then
2629 Result
:= Result
+ 1;
2632 function g_Map_HaveFlagPoints(): Boolean;
2634 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2637 procedure g_Map_ResetFlag(Flag
: Byte);
2639 with gFlags
[Flag
] do
2645 Direction
:= D_LEFT
;
2646 State
:= FLAG_STATE_NONE
;
2647 if FlagPoints
[Flag
] <> nil then
2649 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2650 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2651 Direction
:= FlagPoints
[Flag
]^.Direction
;
2652 State
:= FLAG_STATE_NORMAL
;
2658 procedure g_Map_DrawFlags();
2661 Mirror
: TMirrorType
;
2663 if gGameSettings
.GameMode
<> GM_CTF
then
2666 for i
:= FLAG_RED
to FLAG_BLUE
do
2668 if State
<> FLAG_STATE_CAPTURED
then
2670 if State
= FLAG_STATE_NONE
then
2673 if Direction
= D_LEFT
then
2675 Mirror
:= M_HORIZONTAL
;
2684 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2686 if g_debug_Frames
then
2688 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2690 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2691 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2697 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2704 procedure SavePanelArray(var panels
: TPanelArray
);
2706 PAMem
: TBinMemoryWriter
;
2709 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2710 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2713 while i
< Length(panels
) do
2715 if panels
[i
].SaveIt
then
2719 // Ñîõðàíÿåì ïàíåëü:
2720 panels
[i
].SaveState(PAMem
);
2725 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2726 PAMem
.SaveToMemory(Mem
);
2730 procedure SaveFlag(flag
: PFlag
);
2733 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2735 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2736 Mem
.WriteByte(flag
^.RespawnType
);
2738 Mem
.WriteByte(flag
^.State
);
2739 // Íàïðàâëåíèå ôëàãà:
2740 if flag
^.Direction
= D_LEFT
then
2746 Obj_SaveState(@flag
^.Obj
, Mem
);
2750 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2752 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2753 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2754 SavePanelArray(gWalls
);
2755 // Ñîõðàíÿåì ïàíåëè ôîíà:
2756 SavePanelArray(gRenderBackgrounds
);
2757 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2758 SavePanelArray(gRenderForegrounds
);
2759 // Ñîõðàíÿåì ïàíåëè âîäû:
2760 SavePanelArray(gWater
);
2761 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2762 SavePanelArray(gAcid1
);
2763 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2764 SavePanelArray(gAcid2
);
2765 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2766 SavePanelArray(gSteps
);
2767 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2768 SavePanelArray(gLifts
);
2771 ///// Ñîõðàíÿåì ìóçûêó: /////
2772 // Ñèãíàòóðà ìóçûêè:
2773 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2776 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2777 if gMusic
.NoMusic
then
2781 Mem
.WriteString(str
, 64);
2782 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2783 dw
:= gMusic
.GetPosition();
2785 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2786 boo
:= gMusic
.SpecPause
;
2787 Mem
.WriteBoolean(boo
);
2790 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2791 Mem
.WriteInt(gTotalMonsters
);
2794 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2795 if gGameSettings
.GameMode
= GM_CTF
then
2797 // Ôëàã Êðàñíîé êîìàíäû:
2798 SaveFlag(@gFlags
[FLAG_RED
]);
2799 // Ôëàã Ñèíåé êîìàíäû:
2800 SaveFlag(@gFlags
[FLAG_BLUE
]);
2804 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2805 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2807 // Î÷êè Êðàñíîé êîìàíäû:
2808 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2809 // Î÷êè Ñèíåé êîìàíäû:
2810 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2815 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2822 procedure LoadPanelArray(var panels
: TPanelArray
);
2824 PAMem
: TBinMemoryReader
;
2827 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2828 PAMem
:= TBinMemoryReader
.Create();
2829 PAMem
.LoadFromMemory(Mem
);
2831 for i
:= 0 to Length(panels
)-1 do
2833 if panels
[i
].SaveIt
then
2839 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2841 // Çàãðóæàåì ïàíåëü:
2842 panels
[i
].LoadState(PAMem
);
2843 if (panels
[i
].arrIdx
<> i
) then raise Exception
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx');
2844 if (panels
[i
].proxyId
>= 0) then mapGrid
.proxyEnabled
[panels
[i
].proxyId
] := panels
[i
].Enabled
;
2848 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2852 procedure LoadFlag(flag
: PFlag
);
2856 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2858 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2860 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2861 Mem
.ReadByte(flag
^.RespawnType
);
2863 Mem
.ReadByte(flag
^.State
);
2864 // Íàïðàâëåíèå ôëàãà:
2867 flag
^.Direction
:= D_LEFT
2869 flag
^.Direction
:= D_RIGHT
;
2871 Obj_LoadState(@flag
^.Obj
, Mem
);
2878 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2879 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2880 LoadPanelArray(gWalls
);
2881 // Çàãðóæàåì ïàíåëè ôîíà:
2882 LoadPanelArray(gRenderBackgrounds
);
2883 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2884 LoadPanelArray(gRenderForegrounds
);
2885 // Çàãðóæàåì ïàíåëè âîäû:
2886 LoadPanelArray(gWater
);
2887 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2888 LoadPanelArray(gAcid1
);
2889 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2890 LoadPanelArray(gAcid2
);
2891 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2892 LoadPanelArray(gSteps
);
2893 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2894 LoadPanelArray(gLifts
);
2897 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2901 ///// Çàãðóæàåì ìóçûêó: /////
2902 // Ñèãíàòóðà ìóçûêè:
2904 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2906 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2909 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2910 Mem
.ReadString(str
);
2911 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2913 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2914 Mem
.ReadBoolean(boo
);
2915 // Çàïóñêàåì ýòó ìóçûêó:
2916 gMusic
.SetByName(str
);
2917 gMusic
.SpecPause
:= boo
;
2920 gMusic
.SetPosition(dw
);
2923 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2924 Mem
.ReadInt(gTotalMonsters
);
2927 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2928 if gGameSettings
.GameMode
= GM_CTF
then
2930 // Ôëàã Êðàñíîé êîìàíäû:
2931 LoadFlag(@gFlags
[FLAG_RED
]);
2932 // Ôëàã Ñèíåé êîìàíäû:
2933 LoadFlag(@gFlags
[FLAG_BLUE
]);
2937 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2938 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2940 // Î÷êè Êðàñíîé êîìàíäû:
2941 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2942 // Î÷êè Ñèíåé êîìàíäû:
2943 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2948 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2953 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2954 Arr
:= PanelByID
[PanelID
].PWhere
^;
2955 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2956 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);
2960 // trace liquid, stepping by `dx` and `dy`
2961 // return last seen liquid coords, and `false` if we're started outside of the liquid
2962 function g_Map_TraceLiquidNonPrecise (x
, y
, dx
, dy
: Integer; out topx
, topy
: Integer): Boolean;
2964 MaskLiquid
= GridTagWater
or GridTagAcid1
or GridTagAcid2
;
2968 // started outside of the liquid?
2969 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then begin result
:= false; exit
; end;
2970 if (dx
= 0) and (dy
= 0) then begin result
:= false; exit
; end; // sanity check
2976 if (mapGrid
.forEachAtPoint(x
, y
, nil, MaskLiquid
) = nil) then exit
; // out of the water, just exit