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}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, z_aabbtree
, md5
, xprofiler
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
67 procedure g_Map_DrawBack(dx
, dy
: Integer);
68 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
69 PanelType
: Word; b1x3
: Boolean): Boolean;
70 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
71 procedure g_Map_EnableWall(ID
: DWORD
);
72 procedure g_Map_DisableWall(ID
: DWORD
);
73 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
74 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
75 procedure g_Map_ReAdd_DieTriggers();
76 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
78 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
79 function g_Map_GetPointCount(PointType
: Byte): Word;
81 function g_Map_HaveFlagPoints(): Boolean;
83 procedure g_Map_ResetFlag(Flag
: Byte);
84 procedure g_Map_DrawFlags();
86 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
88 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
89 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
91 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
93 procedure g_Map_ProfilersBegin ();
94 procedure g_Map_ProfilersEnd ();
97 RESPAWNPOINT_PLAYER1
= 1;
98 RESPAWNPOINT_PLAYER2
= 2;
100 RESPAWNPOINT_RED
= 4;
101 RESPAWNPOINT_BLUE
= 5;
109 FLAG_STATE_NORMAL
= 1;
110 FLAG_STATE_DROPPED
= 2;
111 FLAG_STATE_CAPTURED
= 3;
112 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
115 FLAG_TIME
= 720; // 20 seconds
117 SKY_STRETCH
: Single = 1.5;
121 gRenderBackgrounds
: TPanelArray
;
122 gRenderForegrounds
: TPanelArray
;
123 gWater
, gAcid1
, gAcid2
: TPanelArray
;
126 gBlockMon
: TPanelArray
;
127 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
128 //gDOMFlags: array of TFlag;
131 gDoorMap
: array of array of DWORD
;
132 gLiftMap
: array of array of DWORD
;
133 gWADHash
: TMD5Digest
;
134 BackID
: DWORD
= DWORD(-1);
135 gExternalResources
: TStringList
;
137 gdbg_map_use_grid_render
: Boolean = true;
138 gdbg_map_use_grid_coldet
: Boolean = true;
139 gdbg_map_use_tree_draw
: Boolean = true;
140 gdbg_map_use_tree_coldet
: Boolean = false;
141 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
146 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
147 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
148 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
149 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
151 ImagingTypes
, Imaging
, ImagingUtility
,
152 ImagingGif
, ImagingNetworkGraphics
;
155 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
156 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
157 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
171 function panelTypeToTag (panelType
: Word): Integer;
174 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
175 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
176 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
177 PANEL_WATER
: result
:= GridTagWater
; // gWater
178 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
179 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
180 PANEL_STEP
: result
:= GridTagStep
; // gSteps
181 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
182 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
183 else result
:= GridTagInvalid
;
190 PWhere
: ^TPanelArray
;
195 TDynAABBTreeMap
= class(TDynAABBTree
)
196 function getFleshAABB (var aabb
: AABB2D
; flesh
: TTreeFlesh
): Boolean; override;
199 function TDynAABBTreeMap
.getFleshAABB (var aabb
: AABB2D
; flesh
: TTreeFlesh
): Boolean;
203 pan
:= (flesh
as TPanel
);
204 aabb
.setXYWH(pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
);
209 PanelById
: array of TPanelID
;
210 Textures
: TLevelTextureArray
;
211 RespawnPoints
: Array of TRespawnPoint
;
212 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
213 //DOMFlagPoints: Array of TFlagPoint;
214 gMapGrid
: TBodyGrid
= nil;
215 mapTree
: TDynAABBTree
= nil;
218 procedure g_Map_ProfilersBegin ();
220 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
221 profMapCollision
.mainBegin(g_profile_collision
);
223 if g_profile_collision
then
225 profMapCollision
.sectionBegin('wall coldet');
226 profMapCollision
.sectionEnd();
227 profMapCollision
.sectionBegin('liquid coldet');
228 profMapCollision
.sectionEnd();
232 procedure g_Map_ProfilersEnd ();
234 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
238 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
240 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
241 (Texture
= TEXTURE_NAME_ACID1
) or
242 (Texture
= TEXTURE_NAME_ACID2
);
245 procedure CreateDoorMap();
247 PanelArray
: Array of record
253 a
, b
, c
, m
, i
, len
: Integer;
261 SetLength(PanelArray
, len
);
263 for a
:= 0 to High(gWalls
) do
264 if gWalls
[a
].Door
then
266 PanelArray
[i
].X
:= gWalls
[a
].X
;
267 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
268 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
269 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
270 PanelArray
[i
].Active
:= True;
271 PanelArray
[i
].PanelID
:= a
;
277 SetLength(PanelArray
, len
);
288 SetLength(gDoorMap
, 0);
290 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
293 if PanelArray
[a
].Active
then
295 PanelArray
[a
].Active
:= False;
296 m
:= Length(gDoorMap
);
297 SetLength(gDoorMap
, m
+1);
298 SetLength(gDoorMap
[m
], 1);
299 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
307 if PanelArray
[b
].Active
then
308 for c
:= 0 to High(gDoorMap
[m
]) do
309 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
310 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
311 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
312 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
313 gWalls
[gDoorMap
[m
, c
]].X
,
314 gWalls
[gDoorMap
[m
, c
]].Y
,
315 gWalls
[gDoorMap
[m
, c
]].Width
,
316 gWalls
[gDoorMap
[m
, c
]].Height
) then
318 PanelArray
[b
].Active
:= False;
319 SetLength(gDoorMap
[m
],
320 Length(gDoorMap
[m
])+1);
321 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
327 g_Game_StepLoading();
333 procedure CreateLiftMap();
335 PanelArray
: Array of record
340 a
, b
, c
, len
, i
, j
: Integer;
346 len
:= Length(gLifts
);
347 SetLength(PanelArray
, len
);
349 for a
:= 0 to len
-1 do
351 PanelArray
[a
].X
:= gLifts
[a
].X
;
352 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
353 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
354 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
355 PanelArray
[a
].Active
:= True;
358 SetLength(gLiftMap
, len
);
361 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
363 for a
:= 0 to len
-1 do
364 if PanelArray
[a
].Active
then
366 PanelArray
[a
].Active
:= False;
367 SetLength(gLiftMap
[i
], 32);
375 for b
:= 0 to len
-1 do
376 if PanelArray
[b
].Active
then
378 if g_CollideAround(PanelArray
[b
].X
,
381 PanelArray
[b
].Height
,
382 PanelArray
[gLiftMap
[i
, c
]].X
,
383 PanelArray
[gLiftMap
[i
, c
]].Y
,
384 PanelArray
[gLiftMap
[i
, c
]].Width
,
385 PanelArray
[gLiftMap
[i
, c
]].Height
) then
387 PanelArray
[b
].Active
:= False;
389 if j
> High(gLiftMap
[i
]) then
390 SetLength(gLiftMap
[i
],
391 Length(gLiftMap
[i
])+32);
400 SetLength(gLiftMap
[i
], j
+1);
403 g_Game_StepLoading();
406 SetLength(gLiftMap
, i
);
411 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
412 CurTex
: Integer; sav
: Boolean): Integer;
415 panels
: ^TPanelArray
;
419 case PanelRec
.PanelType
of
420 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
423 panels
:= @gRenderBackgrounds
;
425 panels
:= @gRenderForegrounds
;
434 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
437 panels
:= @gBlockMon
;
442 len
:= Length(panels
^);
443 SetLength(panels
^, len
+ 1);
445 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
446 panels
^[len
].ArrIdx
:= len
;
447 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
449 panels
^[len
].SaveIt
:= True;
453 len
:= Length(PanelByID
);
454 SetLength(PanelByID
, len
+ 1);
455 PanelByID
[len
].PWhere
:= panels
;
456 PanelByID
[len
].PArrID
:= Result
;
459 function CreateNullTexture(RecName
: String): Integer;
461 SetLength(Textures
, Length(Textures
)+1);
462 result
:= High(Textures
);
464 with Textures
[High(Textures
)] do
466 TextureName
:= RecName
;
470 TextureID
:= TEXTURE_NONE
;
474 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
477 TextureData
: Pointer;
478 WADName
, txname
: String;
479 a
, ResLength
: Integer;
483 if Textures
<> nil then
484 for a
:= 0 to High(Textures
) do
485 if Textures
[a
].TextureName
= RecName
then
486 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
491 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
492 if (RecName
= TEXTURE_NAME_WATER
) or
493 (RecName
= TEXTURE_NAME_ACID1
) or
494 (RecName
= TEXTURE_NAME_ACID2
) then
496 SetLength(Textures
, Length(Textures
)+1);
498 with Textures
[High(Textures
)] do
500 TextureName
:= RecName
;
502 if TextureName
= TEXTURE_NAME_WATER
then
503 TextureID
:= TEXTURE_SPECIAL_WATER
505 if TextureName
= TEXTURE_NAME_ACID1
then
506 TextureID
:= TEXTURE_SPECIAL_ACID1
508 if TextureName
= TEXTURE_NAME_ACID2
then
509 TextureID
:= TEXTURE_SPECIAL_ACID2
;
514 result
:= High(Textures
);
518 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
519 WADName
:= g_ExtractWadName(RecName
);
521 WAD
:= TWADFile
.Create();
523 if WADName
<> '' then
524 WADName
:= GameDir
+'/wads/'+WADName
528 WAD
.ReadFile(WADName
);
532 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
534 FreeMem(TextureData);
535 RecName := 'COMMON\ALIEN';
539 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
541 SetLength(Textures
, Length(Textures
)+1);
542 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
544 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
545 @Textures
[High(Textures
)].Width
,
546 @Textures
[High(Textures
)].Height
);
547 FreeMem(TextureData
);
548 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
549 Textures
[High(Textures
)].Anim
:= False;
551 result
:= High(Textures
);
553 else // Íåò òàêîãî ðåóñðñà â WAD'å
555 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
558 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
559 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
566 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
569 TextureWAD
: PChar = nil;
570 TextData
: Pointer = nil;
571 TextureData
: Pointer = nil;
575 TextureResource
: String;
576 _width
, _height
, _framecount
, _speed
: Integer;
577 _backanimation
: Boolean;
579 ia
: TDynImageDataArray
= nil;
580 f
, c
, frdelay
, frloop
: Integer;
584 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
586 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
587 WADName
:= g_ExtractWadName(RecName
);
589 WAD
:= TWADFile
.Create();
591 if WADName
<> '' then
592 WADName
:= GameDir
+'/wads/'+WADName
596 WAD
.ReadFile(WADName
);
598 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
602 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
603 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
609 if WADName = Map then
611 //FreeMem(TextureWAD);
612 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
618 if ResLength
< 6 then
620 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
624 // ýòî ïòèöà? ýòî ñàìîë¸ò?
625 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
626 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
628 // íåò, ýòî ñóïåðìåí!
629 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
631 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
635 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
636 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
638 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
642 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
644 TextureResource
:= cfg
.ReadStr('', 'resource', '');
645 if TextureResource
= '' then
647 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
651 _width
:= cfg
.ReadInt('', 'framewidth', 0);
652 _height
:= cfg
.ReadInt('', 'frameheight', 0);
653 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
654 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
655 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
660 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
661 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
663 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
670 SetLength(Textures
, Length(Textures
)+1);
671 with Textures
[High(Textures
)] do
673 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
674 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
676 TextureName
:= RecName
;
680 FramesCount
:= _framecount
;
682 result
:= High(Textures
);
686 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
692 // try animated image
694 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
695 if length(imgfmt) = 0 then
697 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
701 GlobalMetadata
.ClearMetaItems();
702 GlobalMetadata
.ClearMetaItemsForSaving();
703 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
705 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
708 if length(ia
) = 0 then
710 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
717 _width
:= ia
[0].width
;
718 _height
:= ia
[0].height
;
719 _framecount
:= length(ia
);
721 _backanimation
:= false;
724 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
726 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
728 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
730 if f
< 0 then f
:= 0;
733 if c
< 13 then c
:= 0 else c
:= 1;
735 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
740 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
742 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
744 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
746 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
750 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
751 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
752 f
:= ord(_backanimation
);
753 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
);
755 SetLength(Textures
, Length(Textures
)+1);
756 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
757 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
759 Textures
[High(Textures
)].TextureName
:= RecName
;
760 Textures
[High(Textures
)].Width
:= _width
;
761 Textures
[High(Textures
)].Height
:= _height
;
762 Textures
[High(Textures
)].Anim
:= True;
763 Textures
[High(Textures
)].FramesCount
:= length(ia
);
764 Textures
[High(Textures
)].Speed
:= _speed
;
765 result
:= High(Textures
);
766 //writeln(' CREATED!');
770 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
774 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
777 if TextureWAD
<> nil then FreeMem(TextureWAD
);
778 if TextData
<> nil then FreeMem(TextData
);
779 if TextureData
<> nil then FreeMem(TextureData
);
783 procedure CreateItem(Item
: TItemRec_1
);
785 if g_Game_IsClient
then Exit
;
787 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
788 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
791 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
792 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
795 procedure CreateArea(Area
: TAreaRec_1
);
800 case Area
.AreaType
of
801 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
802 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
804 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
805 with RespawnPoints
[High(RespawnPoints
)] do
809 Direction
:= TDirection(Area
.Direction
);
811 case Area
.AreaType
of
812 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
813 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
814 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
815 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
816 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
821 AREA_REDFLAG
, AREA_BLUEFLAG
:
823 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
825 if FlagPoints
[a
] <> nil then Exit
;
829 with FlagPoints
[a
]^ do
831 X
:= Area
.X
-FLAGRECT
.X
;
832 Y
:= Area
.Y
-FLAGRECT
.Y
;
833 Direction
:= TDirection(Area
.Direction
);
839 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
840 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
843 Animation
:= TAnimation
.Create(id
, True, 8);
844 Obj
.Rect
:= FLAGRECT
;
852 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
853 with DOMFlagPoints[High(DOMFlagPoints)] do
857 Direction := TDirection(Area.Direction);
860 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
865 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
869 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
875 Width
:= Trigger
.Width
;
876 Height
:= Trigger
.Height
;
877 Enabled
:= ByteBool(Trigger
.Enabled
);
878 TexturePanel
:= Trigger
.TexturePanel
;
879 TexturePanelType
:= fTexturePanel1Type
;
880 ShotPanelType
:= fTexturePanel2Type
;
881 TriggerType
:= Trigger
.TriggerType
;
882 ActivateType
:= Trigger
.ActivateType
;
883 Keys
:= Trigger
.Keys
;
884 Data
.Default
:= Trigger
.DATA
;
887 g_Triggers_Create(_trigger
);
890 procedure CreateMonster(monster
: TMonsterRec_1
);
894 if g_Game_IsClient
then Exit
;
896 if (gGameSettings
.GameType
= GT_SINGLE
)
897 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
899 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
900 TDirection(monster
.Direction
));
902 if gTriggers
<> nil then
903 for a
:= 0 to High(gTriggers
) do
904 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
905 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
906 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
907 gMonsters
[i
].AddTrigger(a
);
909 if monster
.MonsterType
<> MONSTER_BARREL
then
914 procedure g_Map_ReAdd_DieTriggers();
918 if g_Game_IsClient
then Exit
;
920 for i
:= 0 to High(gMonsters
) do
921 if gMonsters
[i
] <> nil then
923 gMonsters
[i
].ClearTriggers();
925 for a
:= 0 to High(gTriggers
) do
926 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
927 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
928 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
929 gMonsters
[i
].AddTrigger(a
);
933 function extractWadName(resourceName
: string): string;
937 posN
:= Pos(':', resourceName
);
939 Result
:= Copy(resourceName
, 0, posN
-1)
944 procedure addResToExternalResList(res
: string);
946 res
:= extractWadName(res
);
947 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
948 gExternalResources
.Add(res
);
951 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
953 textures
: TTexturesRec1Array
;
954 mapHeader
: TMapHeaderRec_1
;
956 resFile
: String = '';
958 if gExternalResources
= nil then
959 gExternalResources
:= TStringList
.Create
;
961 gExternalResources
.Clear
;
962 textures
:= mapReader
.GetTextures();
963 for i
:= 0 to High(textures
) do
965 addResToExternalResList(resFile
);
970 mapHeader
:= mapReader
.GetMapHeader
;
972 addResToExternalResList(mapHeader
.MusicName
);
973 addResToExternalResList(mapHeader
.SkyName
);
976 procedure mapCreateGrid ();
978 mapX0
: Integer = $3fffffff;
979 mapY0
: Integer = $3fffffff;
980 mapX1
: Integer = -$3fffffff;
981 mapY1
: Integer = -$3fffffff;
983 procedure fixMinMax (var panels
: TPanelArray
);
987 for idx
:= 0 to High(panels
) do
989 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
990 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
991 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
992 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
993 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
997 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
1001 tag
:= panelTypeToTag(tag
);
1002 for idx
:= High(panels
) downto 0 do
1004 panels
[idx
].tag
:= tag
;
1005 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1006 mapTree
.insertObject(panels
[idx
], true); // as static object
1017 fixMinMax(gRenderBackgrounds
);
1018 fixMinMax(gRenderForegrounds
);
1024 fixMinMax(gBlockMon
);
1026 if (mapX0
< 0) or (mapY0
< 0) then
1028 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1029 //raise Exception.Create('we are fucked');
1032 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1033 mapTree
:= TDynAABBTreeMap
.Create();
1035 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1036 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1037 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1038 addPanelsToGrid(gWater
, PANEL_WATER
);
1039 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1040 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1041 addPanelsToGrid(gSteps
, PANEL_STEP
);
1042 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1043 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1045 gMapGrid
.dumpStats();
1046 //gMapSAP.dumpStats();
1049 function g_Map_Load(Res
: String): Boolean;
1051 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1052 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1055 MapReader
: TMapReader_1
;
1056 Header
: TMapHeaderRec_1
;
1057 _textures
: TTexturesRec1Array
;
1058 _texnummap
: array of Integer; // `_textures` -> `Textures`
1059 panels
: TPanelsRec1Array
;
1060 items
: TItemsRec1Array
;
1061 monsters
: TMonsterRec1Array
;
1062 areas
: TAreasRec1Array
;
1063 triggers
: TTriggersRec1Array
;
1064 a
, b
, c
, k
: Integer;
1066 AddTextures
: TAddTextureArray
;
1067 texture
: TTextureRec_1
;
1068 TriggersTable
: Array of record
1069 TexturePanel
: Integer;
1074 FileName
, mapResName
, s
, TexName
: String;
1077 ok
, isAnim
, trigRef
: Boolean;
1078 CurTex
, ntn
: Integer;
1087 gMapInfo
.Map
:= Res
;
1088 TriggersTable
:= nil;
1089 FillChar(texture
, SizeOf(texture
), 0);
1091 sfsGCDisable(); // temporary disable removing of temporary volumes
1094 FileName
:= g_ExtractWadName(Res
);
1095 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1096 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1098 WAD
:= TWADFile
.Create();
1099 if not WAD
.ReadFile(FileName
) then
1101 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1105 //k8: why loader ignores path here?
1106 mapResName
:= g_ExtractFileName(Res
);
1107 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1109 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1117 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1118 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1119 MapReader
:= TMapReader_1
.Create();
1121 if not MapReader
.LoadMap(Data
) then
1123 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1130 generateExternalResourcesList(MapReader
);
1131 // Çàãðóçêà òåêñòóð:
1132 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1133 _textures
:= MapReader
.GetTextures();
1136 // Äîáàâëåíèå òåêñòóð â Textures[]:
1137 if _textures
<> nil then
1139 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1140 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1141 SetLength(_texnummap
, length(_textures
));
1143 for a
:= 0 to High(_textures
) do
1146 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1147 for b
:= 1 to Length(s
) do
1153 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1154 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1155 // Àíèìèðîâàííàÿ òåêñòóðà:
1156 if ByteBool(_textures
[a
].Anim
) then
1158 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1161 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1162 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1165 else // Îáû÷íàÿ òåêñòóðà:
1166 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1169 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1170 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1173 _texnummap
[a
] := ntn
; // fix texture number
1174 g_Game_StepLoading();
1178 // Çàãðóçêà òðèããåðîâ:
1179 gTriggerClientID
:= 0;
1180 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1181 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1182 triggers
:= MapReader
.GetTriggers();
1184 // Çàãðóçêà ïàíåëåé:
1185 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1186 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1187 panels
:= MapReader
.GetPanels();
1189 // check texture numbers for panels
1190 for a
:= 0 to High(panels
) do
1192 if panels
[a
].TextureNum
> High(_textures
) then
1194 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1198 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1201 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1202 if triggers
<> nil then
1204 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1205 SetLength(TriggersTable
, Length(triggers
));
1206 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1208 for a
:= 0 to High(TriggersTable
) do
1210 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1211 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1213 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1214 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1216 TriggersTable
[a
].LiftPanel
:= -1;
1218 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1219 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1220 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1221 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1223 TriggersTable
[a
].DoorPanel
:= -1;
1225 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1226 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1228 TriggersTable
[a
].ShotPanel
:= -1;
1230 g_Game_StepLoading();
1235 if panels
<> nil then
1237 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1238 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1240 for a
:= 0 to High(panels
) do
1242 SetLength(AddTextures
, 0);
1245 if _textures
<> nil then
1247 texture
:= _textures
[panels
[a
].TextureNum
];
1255 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1256 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1258 if (TriggersTable
<> nil) and (_textures
<> nil) then
1259 for b
:= 0 to High(TriggersTable
) do
1260 if (TriggersTable
[b
].TexturePanel
= a
)
1261 or (TriggersTable
[b
].ShotPanel
= a
) then
1270 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1272 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1275 for c
:= Len
downto 1 do
1283 // Ñïåö-òåêñòóðû çàïðåùåíû:
1284 if g_Map_IsSpecialTexture(s
) then
1287 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1288 ok
:= g_Texture_NumNameFindStart(s
);
1290 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1291 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1294 k
:= NNF_NAME_BEFORE
;
1295 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1296 while ok
or (k
= NNF_NAME_BEFORE
) or
1297 (k
= NNF_NAME_EQUALS
) do
1299 k
:= g_Texture_NumNameFindNext(TexName
);
1301 if (k
= NNF_NAME_BEFORE
) or
1302 (k
= NNF_NAME_AFTER
) then
1304 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1305 if ByteBool(texture
.Anim
) then
1306 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1308 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1310 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1312 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1316 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1318 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1320 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1322 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1326 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1329 for c
:= 0 to High(Textures
) do
1330 if Textures
[c
].TextureName
= TexName
then
1332 SetLength(AddTextures
, Length(AddTextures
)+1);
1333 AddTextures
[High(AddTextures
)].Texture
:= c
;
1334 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1340 if k
= NNF_NAME_EQUALS
then
1342 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1343 SetLength(AddTextures
, Length(AddTextures
)+1);
1344 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1345 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1346 CurTex
:= High(AddTextures
);
1354 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1355 end; // if ok - ññûëàþòñÿ òðèããåðû
1359 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1360 SetLength(AddTextures
, 1);
1361 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1362 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1366 //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);
1368 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1369 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1371 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1372 if TriggersTable
<> nil then
1373 for b
:= 0 to High(TriggersTable
) do
1375 // Òðèããåð äâåðè/ëèôòà:
1376 if (TriggersTable
[b
].LiftPanel
= a
) or
1377 (TriggersTable
[b
].DoorPanel
= a
) then
1378 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1379 // Òðèããåð ñìåíû òåêñòóðû:
1380 if TriggersTable
[b
].TexturePanel
= a
then
1381 triggers
[b
].TexturePanel
:= PanelID
;
1382 // Òðèããåð "Òóðåëü":
1383 if TriggersTable
[b
].ShotPanel
= a
then
1384 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1387 g_Game_StepLoading();
1391 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1392 if (triggers
<> nil) and not gLoadGameMode
then
1394 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1395 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1396 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1397 for a
:= 0 to High(triggers
) do
1399 if triggers
[a
].TexturePanel
<> -1 then
1400 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1403 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1404 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1405 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1408 CreateTrigger(triggers
[a
], b
, c
);
1412 // Çàãðóçêà ïðåäìåòîâ:
1413 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1414 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1415 items
:= MapReader
.GetItems();
1417 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1418 if (items
<> nil) and not gLoadGameMode
then
1420 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1421 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1422 for a
:= 0 to High(items
) do
1423 CreateItem(Items
[a
]);
1426 // Çàãðóçêà îáëàñòåé:
1427 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1428 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1429 areas
:= MapReader
.GetAreas();
1431 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1432 if areas
<> nil then
1434 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1435 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1436 for a
:= 0 to High(areas
) do
1437 CreateArea(areas
[a
]);
1440 // Çàãðóçêà ìîíñòðîâ:
1441 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1442 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1443 monsters
:= MapReader
.GetMonsters();
1445 gTotalMonsters
:= 0;
1447 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1448 if (monsters
<> nil) and not gLoadGameMode
then
1450 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1451 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1452 for a
:= 0 to High(monsters
) do
1453 CreateMonster(monsters
[a
]);
1456 // Çàãðóçêà îïèñàíèÿ êàðòû:
1457 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1458 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1459 Header
:= MapReader
.GetMapHeader();
1465 Name
:= Header
.MapName
;
1466 Description
:= Header
.MapDescription
;
1467 Author
:= Header
.MapAuthor
;
1468 MusicName
:= Header
.MusicName
;
1469 SkyName
:= Header
.SkyName
;
1470 Height
:= Header
.Height
;
1471 Width
:= Header
.Width
;
1475 if gMapInfo
.SkyName
<> '' then
1477 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1478 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1479 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1481 if FileName
<> '' then
1482 FileName
:= GameDir
+'/wads/'+FileName
1485 FileName
:= g_ExtractWadName(Res
);
1488 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1489 if g_Texture_CreateWAD(BackID
, s
) then
1491 g_Game_SetupScreenSize();
1494 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1499 if gMapInfo
.MusicName
<> '' then
1501 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1502 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1503 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1505 if FileName
<> '' then
1506 FileName
:= GameDir
+'/wads/'+FileName
1509 FileName
:= g_ExtractWadName(Res
);
1512 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1513 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1516 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1519 // Îñòàëüíûå óñòàíâêè:
1527 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1528 if not gLoadGameMode
then
1531 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1537 TriggersTable
:= nil;
1540 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1541 if ok
and (not gLoadGameMode
) then
1543 gMusic
.SetByName(gMapInfo
.MusicName
);
1547 gMusic
.SetByName('');
1549 sfsGCEnable(); // enable releasing unused volumes
1552 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1555 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1559 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1562 MapReader
: TMapReader_1
;
1563 Header
: TMapHeaderRec_1
;
1568 FillChar(Result
, SizeOf(Result
), 0);
1569 FileName
:= g_ExtractWadName(Res
);
1571 WAD
:= TWADFile
.Create();
1572 if not WAD
.ReadFile(FileName
) then
1578 //k8: it ignores path again
1579 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1587 MapReader
:= TMapReader_1
.Create();
1589 if not MapReader
.LoadMap(Data
) then
1591 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1592 ZeroMemory(@Header
, SizeOf(Header
));
1593 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1594 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1598 Header
:= MapReader
.GetMapHeader();
1599 Result
.Name
:= Header
.MapName
;
1600 Result
.Description
:= Header
.MapDescription
;
1607 Result
.Author
:= Header
.MapAuthor
;
1608 Result
.Height
:= Header
.Height
;
1609 Result
.Width
:= Header
.Width
;
1612 function g_Map_GetMapsList(WADName
: string): SArray
;
1619 WAD
:= TWADFile
.Create();
1620 if not WAD
.ReadFile(WADName
) then
1625 ResList
:= WAD
.GetMapResources();
1626 if ResList
<> nil then
1628 for a
:= 0 to High(ResList
) do
1630 SetLength(Result
, Length(Result
)+1);
1631 Result
[High(Result
)] := ResList
[a
];
1637 function g_Map_Exist(Res
: string): Boolean;
1640 FileName
, mnn
: string;
1646 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1648 WAD
:= TWADFile
.Create
;
1649 if not WAD
.ReadFile(FileName
) then
1655 ResList
:= WAD
.GetMapResources();
1658 mnn
:= g_ExtractFileName(Res
);
1659 if ResList
<> nil then
1660 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1667 procedure g_Map_Free();
1671 procedure FreePanelArray(var panels
: TPanelArray
);
1676 if panels
<> nil then
1678 for i
:= 0 to High(panels
) do
1691 RespawnPoints
:= nil;
1692 if FlagPoints
[FLAG_RED
] <> nil then
1694 Dispose(FlagPoints
[FLAG_RED
]);
1695 FlagPoints
[FLAG_RED
] := nil;
1697 if FlagPoints
[FLAG_BLUE
] <> nil then
1699 Dispose(FlagPoints
[FLAG_BLUE
]);
1700 FlagPoints
[FLAG_BLUE
] := nil;
1702 //DOMFlagPoints := nil;
1706 if Textures
<> nil then
1708 for a
:= 0 to High(Textures
) do
1709 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1710 if Textures
[a
].Anim
then
1711 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1713 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1714 e_DeleteTexture(Textures
[a
].TextureID
);
1719 FreePanelArray(gWalls
);
1720 FreePanelArray(gRenderBackgrounds
);
1721 FreePanelArray(gRenderForegrounds
);
1722 FreePanelArray(gWater
);
1723 FreePanelArray(gAcid1
);
1724 FreePanelArray(gAcid2
);
1725 FreePanelArray(gSteps
);
1726 FreePanelArray(gLifts
);
1727 FreePanelArray(gBlockMon
);
1729 if BackID
<> DWORD(-1) then
1733 e_DeleteTexture(BackID
);
1734 BackID
:= DWORD(-1);
1737 g_Game_StopAllSounds(False);
1739 g_Sound_Delete(gMapInfo
.MusicName
);
1741 gMapInfo
.Name
:= '';
1742 gMapInfo
.Description
:= '';
1743 gMapInfo
.MusicName
:= '';
1744 gMapInfo
.Height
:= 0;
1745 gMapInfo
.Width
:= 0;
1753 procedure g_Map_Update();
1759 procedure UpdatePanelArray(var panels
: TPanelArray
);
1764 if panels
<> nil then
1765 for i
:= 0 to High(panels
) do
1770 UpdatePanelArray(gWalls
);
1771 UpdatePanelArray(gRenderBackgrounds
);
1772 UpdatePanelArray(gRenderForegrounds
);
1773 UpdatePanelArray(gWater
);
1774 UpdatePanelArray(gAcid1
);
1775 UpdatePanelArray(gAcid2
);
1776 UpdatePanelArray(gSteps
);
1778 if gGameSettings
.GameMode
= GM_CTF
then
1780 for a
:= FLAG_RED
to FLAG_BLUE
do
1781 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1784 if gFlags
[a
].Animation
<> nil then
1785 gFlags
[a
].Animation
.Update();
1787 m
:= g_Obj_Move(@Obj
, True, True);
1789 if gTime
mod (GAME_TICK
*2) <> 0 then
1792 // Ñîïðîòèâëåíèå âîçäóõà:
1793 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1795 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1796 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1799 gFlags
[a
].CaptureTime
:= 0;
1800 if a
= FLAG_RED
then
1801 s
:= _lc
[I_PLAYER_FLAG_RED
]
1803 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1804 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1806 if g_Game_IsNet
then
1807 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1814 // Èãðîê áåðåò ôëàã:
1815 if gPlayers
<> nil then
1817 j
:= Random(Length(gPlayers
)) - 1;
1819 for d
:= 0 to High(gPlayers
) do
1822 if j
> High(gPlayers
) then
1825 if gPlayers
[j
] <> nil then
1826 if gPlayers
[j
].Live
and
1827 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1829 if gPlayers
[j
].GetFlag(a
) then
1839 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1841 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1845 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1847 // alas, no visible set
1848 for idx
:= 0 to High(panels
) do
1850 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1857 PANEL_WALL
: DrawPanels(0, gWalls
);
1858 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1859 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1860 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1861 PANEL_WATER
: DrawPanels(3, gWater
);
1862 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1863 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1864 PANEL_STEP
: DrawPanels(6, gSteps
);
1870 gDrawPanelList
: TBinaryHeapObj
= nil;
1872 function dplLess (a
, b
: TObject
): Boolean;
1874 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1877 procedure dplClear ();
1879 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1882 procedure dplAddPanel (pan
: TPanel
);
1884 if pan
= nil then exit
;
1885 gDrawPanelList
.insert(pan
);
1889 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1893 function checker (obj
: TObject
; tag
: Integer): Boolean;
1897 result
:= false; // don't stop, ever
1898 if (tag
<> ptag
) then exit
;
1899 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1901 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1902 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1903 //pan := (obj as TPanel);
1904 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1906 pan
:= (obj
as TPanel
);
1907 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1908 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1912 function checkerTree (obj
: TObject
): Boolean;
1916 result
:= false; // don't stop, ever
1917 pan
:= (obj
as TPanel
);
1918 if (pan
.tag
<> ptag
) then exit
;
1919 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1920 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1924 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1929 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1931 // alas, no visible set
1932 for idx
:= 0 to High(panels
) do
1934 if not (drawDoors
xor panels
[idx
].Door
) then
1938 if (pan.Width < 1) or (pan.Height < 1) then continue;
1939 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1940 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1943 //e_WriteLog(Format(' *body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, PanelType, PanelType]), MSG_NOTIFY);
1950 //g_Map_DrawPanelsOld(PanelType); exit;
1951 //e_WriteLog('==================', MSG_NOTIFY);
1952 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1954 ptag
:= panelTypeToTag(PanelType
);
1956 if gdbg_map_use_grid_render
then
1958 if gdbg_map_use_tree_draw
then
1960 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checkerTree
);
1964 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1966 // sort and draw the list (we need to sort it, or rendering is fucked)
1967 while gDrawPanelList
.count
> 0 do
1969 (gDrawPanelList
.front() as TPanel
).Draw();
1970 gDrawPanelList
.popFront();
1975 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1977 PANEL_WALL
: DrawPanels(0, gWalls
);
1978 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1979 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1980 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1981 PANEL_WATER
: DrawPanels(3, gWater
);
1982 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1983 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1984 PANEL_STEP
: DrawPanels(6, gSteps
);
1988 //e_WriteLog('==================', MSG_NOTIFY);
1992 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1993 function checker (obj
: TObject
; tag
: Integer): Boolean;
1997 result
:= false; // don't stop, ever
1998 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1999 pan
:= (obj
as TPanel
);
2000 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2003 function checkerTree (obj
: TObject
): Boolean;
2007 result
:= false; // don't stop, ever
2008 pan
:= (obj
as TPanel
);
2009 if (pan
.tag
<> GridTagWallDoor
) then exit
; // only walls
2010 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2014 if gdbg_map_use_tree_draw
then
2016 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checkerTree
);
2020 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
2025 procedure g_Map_DrawBack(dx
, dy
: Integer);
2027 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2028 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2030 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2033 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2034 PanelType
: Word; b1x3
: Boolean): Boolean;
2040 if WordBool(PanelType
and PANEL_WALL
) then
2041 if gWalls
<> nil then
2046 if gWalls
[a
].Enabled
and
2047 g_Collide(X
, Y
, Width
, Height
,
2048 gWalls
[a
].X
, gWalls
[a
].Y
,
2049 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2056 if WordBool(PanelType
and PANEL_WATER
) then
2057 if gWater
<> nil then
2062 if g_Collide(X
, Y
, Width
, Height
,
2063 gWater
[a
].X
, gWater
[a
].Y
,
2064 gWater
[a
].Width
, gWater
[a
].Height
) then
2071 if WordBool(PanelType
and PANEL_ACID1
) then
2072 if gAcid1
<> nil then
2077 if g_Collide(X
, Y
, Width
, Height
,
2078 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2079 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2086 if WordBool(PanelType
and PANEL_ACID2
) then
2087 if gAcid2
<> nil then
2092 if g_Collide(X
, Y
, Width
, Height
,
2093 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2094 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2101 if WordBool(PanelType
and PANEL_STEP
) then
2102 if gSteps
<> nil then
2107 if g_Collide(X
, Y
, Width
, Height
,
2108 gSteps
[a
].X
, gSteps
[a
].Y
,
2109 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2116 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2117 if gLifts
<> nil then
2122 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2123 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2124 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2125 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2126 g_Collide(X
, Y
, Width
, Height
,
2127 gLifts
[a
].X
, gLifts
[a
].Y
,
2128 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2135 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2136 if gBlockMon
<> nil then
2138 h
:= High(gBlockMon
);
2142 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2143 g_Collide(X
, Y
, Width
, Height
,
2144 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2145 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2153 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2157 function checkPanels (var panels
: TPanelArray
): Boolean;
2162 if panels
= nil then exit
;
2163 for a
:= 0 to High(panels
) do
2165 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2168 texid
:= panels
[a
].GetTextureID();
2175 texid
:= TEXTURE_NONE
;
2177 if not checkPanels(gWater
) then
2178 if not checkPanels(gAcid1
) then
2179 if not checkPanels(gAcid2
) then exit
;
2184 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2186 function checker (obj
: TObject
; tag
: Integer): Boolean;
2191 result
:= false; // don't stop, ever
2193 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2197 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2199 if not (obj
is TPanel
) then
2201 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2205 pan
:= (obj
as TPanel
);
2208 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2210 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2217 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2219 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2226 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2228 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2235 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2237 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2244 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2246 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2253 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2255 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2256 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2257 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2258 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2259 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2266 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2268 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2269 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2277 function checkerTree (obj
: TObject
): Boolean;
2281 pan
:= (obj
as TPanel
);
2282 result
:= checker(obj
, pan
.tag
);
2286 //TODO: detailed profile
2287 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2289 if gdbg_map_use_grid_coldet
then
2291 if gdbg_map_use_tree_coldet
then
2293 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checkerTree
);
2297 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2302 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2305 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2310 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2312 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2315 // slightly different from the old code, but meh...
2316 function checker (obj
: TObject
; tag
: Integer): Boolean;
2321 result
:= false; // don't stop, ever
2322 pan
:= (obj
as TPanel
);
2325 if (tag
= GridTagWater
) then
2327 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2329 result
:= true; // water has highest priority, so stop right here
2330 texid
:= gWater
[a
].GetTextureID();
2335 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2337 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2340 texid
:= gAcid1
[a
].GetTextureID();
2345 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2347 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2350 texid
:= gAcid2
[a
].GetTextureID();
2356 function checkerTree (obj
: TObject
): Boolean;
2360 pan
:= (obj
as TPanel
);
2361 result
:= checker(obj
, pan
.tag
);
2365 //TODO: detailed profile?
2366 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2368 if gdbg_map_use_grid_coldet
then
2370 texid
:= TEXTURE_NONE
;
2371 if gdbg_map_use_tree_coldet
then
2373 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checkerTree
);
2377 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2383 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2386 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2390 procedure g_Map_EnableWall(ID
: DWORD
);
2395 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2397 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2401 procedure g_Map_DisableWall(ID
: DWORD
);
2406 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2408 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2412 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2417 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2420 tp
:= gRenderForegrounds
[ID
];
2422 tp
:= gRenderBackgrounds
[ID
];
2435 tp
.NextTexture(AnimLoop
);
2436 if g_Game_IsServer
and g_Game_IsNet
then
2437 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2440 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2442 if gLifts
[ID
].LiftType
= t
then
2449 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2451 if LiftType
= 0 then
2452 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2453 else if LiftType
= 1 then
2454 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2455 else if LiftType
= 2 then
2456 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2457 else if LiftType
= 3 then
2458 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2460 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2464 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2467 PointsArray
: Array of TRespawnPoint
;
2470 SetLength(PointsArray
, 0);
2472 if RespawnPoints
= nil then
2475 for a
:= 0 to High(RespawnPoints
) do
2476 if RespawnPoints
[a
].PointType
= PointType
then
2478 SetLength(PointsArray
, Length(PointsArray
)+1);
2479 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2482 if PointsArray
= nil then
2485 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2489 function g_Map_GetPointCount(PointType
: Byte): Word;
2495 if RespawnPoints
= nil then
2498 for a
:= 0 to High(RespawnPoints
) do
2499 if RespawnPoints
[a
].PointType
= PointType
then
2500 Result
:= Result
+ 1;
2503 function g_Map_HaveFlagPoints(): Boolean;
2505 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2508 procedure g_Map_ResetFlag(Flag
: Byte);
2510 with gFlags
[Flag
] do
2516 Direction
:= D_LEFT
;
2517 State
:= FLAG_STATE_NONE
;
2518 if FlagPoints
[Flag
] <> nil then
2520 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2521 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2522 Direction
:= FlagPoints
[Flag
]^.Direction
;
2523 State
:= FLAG_STATE_NORMAL
;
2529 procedure g_Map_DrawFlags();
2532 Mirror
: TMirrorType
;
2534 if gGameSettings
.GameMode
<> GM_CTF
then
2537 for i
:= FLAG_RED
to FLAG_BLUE
do
2539 if State
<> FLAG_STATE_CAPTURED
then
2541 if State
= FLAG_STATE_NONE
then
2544 if Direction
= D_LEFT
then
2546 Mirror
:= M_HORIZONTAL
;
2555 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2557 if g_debug_Frames
then
2559 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2561 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2562 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2568 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2575 procedure SavePanelArray(var panels
: TPanelArray
);
2577 PAMem
: TBinMemoryWriter
;
2580 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2581 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2584 while i
< Length(panels
) do
2586 if panels
[i
].SaveIt
then
2590 // Ñîõðàíÿåì ïàíåëü:
2591 panels
[i
].SaveState(PAMem
);
2596 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2597 PAMem
.SaveToMemory(Mem
);
2601 procedure SaveFlag(flag
: PFlag
);
2604 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2606 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2607 Mem
.WriteByte(flag
^.RespawnType
);
2609 Mem
.WriteByte(flag
^.State
);
2610 // Íàïðàâëåíèå ôëàãà:
2611 if flag
^.Direction
= D_LEFT
then
2617 Obj_SaveState(@flag
^.Obj
, Mem
);
2621 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2623 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2624 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2625 SavePanelArray(gWalls
);
2626 // Ñîõðàíÿåì ïàíåëè ôîíà:
2627 SavePanelArray(gRenderBackgrounds
);
2628 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2629 SavePanelArray(gRenderForegrounds
);
2630 // Ñîõðàíÿåì ïàíåëè âîäû:
2631 SavePanelArray(gWater
);
2632 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2633 SavePanelArray(gAcid1
);
2634 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2635 SavePanelArray(gAcid2
);
2636 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2637 SavePanelArray(gSteps
);
2638 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2639 SavePanelArray(gLifts
);
2642 ///// Ñîõðàíÿåì ìóçûêó: /////
2643 // Ñèãíàòóðà ìóçûêè:
2644 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2647 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2648 if gMusic
.NoMusic
then
2652 Mem
.WriteString(str
, 64);
2653 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2654 dw
:= gMusic
.GetPosition();
2656 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2657 boo
:= gMusic
.SpecPause
;
2658 Mem
.WriteBoolean(boo
);
2661 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2662 Mem
.WriteInt(gTotalMonsters
);
2665 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2666 if gGameSettings
.GameMode
= GM_CTF
then
2668 // Ôëàã Êðàñíîé êîìàíäû:
2669 SaveFlag(@gFlags
[FLAG_RED
]);
2670 // Ôëàã Ñèíåé êîìàíäû:
2671 SaveFlag(@gFlags
[FLAG_BLUE
]);
2675 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2676 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2678 // Î÷êè Êðàñíîé êîìàíäû:
2679 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2680 // Î÷êè Ñèíåé êîìàíäû:
2681 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2686 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2693 procedure LoadPanelArray(var panels
: TPanelArray
);
2695 PAMem
: TBinMemoryReader
;
2698 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2699 PAMem
:= TBinMemoryReader
.Create();
2700 PAMem
.LoadFromMemory(Mem
);
2702 for i
:= 0 to Length(panels
)-1 do
2703 if panels
[i
].SaveIt
then
2709 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2711 // Çàãðóæàåì ïàíåëü:
2712 panels
[i
].LoadState(PAMem
);
2715 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2719 procedure LoadFlag(flag
: PFlag
);
2723 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2725 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2727 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2728 Mem
.ReadByte(flag
^.RespawnType
);
2730 Mem
.ReadByte(flag
^.State
);
2731 // Íàïðàâëåíèå ôëàãà:
2734 flag
^.Direction
:= D_LEFT
2736 flag
^.Direction
:= D_RIGHT
;
2738 Obj_LoadState(@flag
^.Obj
, Mem
);
2745 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2746 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2747 LoadPanelArray(gWalls
);
2748 // Çàãðóæàåì ïàíåëè ôîíà:
2749 LoadPanelArray(gRenderBackgrounds
);
2750 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2751 LoadPanelArray(gRenderForegrounds
);
2752 // Çàãðóæàåì ïàíåëè âîäû:
2753 LoadPanelArray(gWater
);
2754 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2755 LoadPanelArray(gAcid1
);
2756 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2757 LoadPanelArray(gAcid2
);
2758 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2759 LoadPanelArray(gSteps
);
2760 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2761 LoadPanelArray(gLifts
);
2764 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2768 ///// Çàãðóæàåì ìóçûêó: /////
2769 // Ñèãíàòóðà ìóçûêè:
2771 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2773 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2776 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2777 Mem
.ReadString(str
);
2778 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2780 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2781 Mem
.ReadBoolean(boo
);
2782 // Çàïóñêàåì ýòó ìóçûêó:
2783 gMusic
.SetByName(str
);
2784 gMusic
.SpecPause
:= boo
;
2787 gMusic
.SetPosition(dw
);
2790 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2791 Mem
.ReadInt(gTotalMonsters
);
2794 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2795 if gGameSettings
.GameMode
= GM_CTF
then
2797 // Ôëàã Êðàñíîé êîìàíäû:
2798 LoadFlag(@gFlags
[FLAG_RED
]);
2799 // Ôëàã Ñèíåé êîìàíäû:
2800 LoadFlag(@gFlags
[FLAG_BLUE
]);
2804 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2805 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2807 // Î÷êè Êðàñíîé êîìàíäû:
2808 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2809 // Î÷êè Ñèíåé êîìàíäû:
2810 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2815 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2820 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2821 Arr
:= PanelByID
[PanelID
].PWhere
^;
2822 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2823 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);