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
, g_sap
, 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_sap
: Boolean = false;
140 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
145 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
146 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
147 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
148 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
150 ImagingTypes
, Imaging
, ImagingUtility
,
151 ImagingGif
, ImagingNetworkGraphics
;
154 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
155 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
156 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
170 function panelTypeToTag (panelType
: Word): Integer;
173 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
174 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
175 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
176 PANEL_WATER
: result
:= GridTagWater
; // gWater
177 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
178 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
179 PANEL_STEP
: result
:= GridTagStep
; // gSteps
180 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
181 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
182 else result
:= GridTagInvalid
;
189 PWhere
: ^TPanelArray
;
194 PanelById
: array of TPanelID
;
195 Textures
: TLevelTextureArray
;
196 RespawnPoints
: Array of TRespawnPoint
;
197 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
198 //DOMFlagPoints: Array of TFlagPoint;
199 gMapGrid
: TBodyGrid
= nil;
200 gMapSAP
: TSweepAndPrune
= nil;
203 procedure g_Map_ProfilersBegin ();
205 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
206 profMapCollision
.mainBegin(g_profile_collision
);
208 if g_profile_collision
then
210 profMapCollision
.sectionBegin('wall coldet');
211 profMapCollision
.sectionEnd();
212 profMapCollision
.sectionBegin('liquid coldet');
213 profMapCollision
.sectionEnd();
217 procedure g_Map_ProfilersEnd ();
219 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
223 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
225 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
226 (Texture
= TEXTURE_NAME_ACID1
) or
227 (Texture
= TEXTURE_NAME_ACID2
);
230 procedure CreateDoorMap();
232 PanelArray
: Array of record
238 a
, b
, c
, m
, i
, len
: Integer;
246 SetLength(PanelArray
, len
);
248 for a
:= 0 to High(gWalls
) do
249 if gWalls
[a
].Door
then
251 PanelArray
[i
].X
:= gWalls
[a
].X
;
252 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
253 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
254 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
255 PanelArray
[i
].Active
:= True;
256 PanelArray
[i
].PanelID
:= a
;
262 SetLength(PanelArray
, len
);
273 SetLength(gDoorMap
, 0);
275 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
278 if PanelArray
[a
].Active
then
280 PanelArray
[a
].Active
:= False;
281 m
:= Length(gDoorMap
);
282 SetLength(gDoorMap
, m
+1);
283 SetLength(gDoorMap
[m
], 1);
284 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
292 if PanelArray
[b
].Active
then
293 for c
:= 0 to High(gDoorMap
[m
]) do
294 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
295 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
296 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
297 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
298 gWalls
[gDoorMap
[m
, c
]].X
,
299 gWalls
[gDoorMap
[m
, c
]].Y
,
300 gWalls
[gDoorMap
[m
, c
]].Width
,
301 gWalls
[gDoorMap
[m
, c
]].Height
) then
303 PanelArray
[b
].Active
:= False;
304 SetLength(gDoorMap
[m
],
305 Length(gDoorMap
[m
])+1);
306 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
312 g_Game_StepLoading();
318 procedure CreateLiftMap();
320 PanelArray
: Array of record
325 a
, b
, c
, len
, i
, j
: Integer;
331 len
:= Length(gLifts
);
332 SetLength(PanelArray
, len
);
334 for a
:= 0 to len
-1 do
336 PanelArray
[a
].X
:= gLifts
[a
].X
;
337 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
338 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
339 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
340 PanelArray
[a
].Active
:= True;
343 SetLength(gLiftMap
, len
);
346 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
348 for a
:= 0 to len
-1 do
349 if PanelArray
[a
].Active
then
351 PanelArray
[a
].Active
:= False;
352 SetLength(gLiftMap
[i
], 32);
360 for b
:= 0 to len
-1 do
361 if PanelArray
[b
].Active
then
363 if g_CollideAround(PanelArray
[b
].X
,
366 PanelArray
[b
].Height
,
367 PanelArray
[gLiftMap
[i
, c
]].X
,
368 PanelArray
[gLiftMap
[i
, c
]].Y
,
369 PanelArray
[gLiftMap
[i
, c
]].Width
,
370 PanelArray
[gLiftMap
[i
, c
]].Height
) then
372 PanelArray
[b
].Active
:= False;
374 if j
> High(gLiftMap
[i
]) then
375 SetLength(gLiftMap
[i
],
376 Length(gLiftMap
[i
])+32);
385 SetLength(gLiftMap
[i
], j
+1);
388 g_Game_StepLoading();
391 SetLength(gLiftMap
, i
);
396 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
397 CurTex
: Integer; sav
: Boolean): Integer;
400 panels
: ^TPanelArray
;
404 case PanelRec
.PanelType
of
405 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
408 panels
:= @gRenderBackgrounds
;
410 panels
:= @gRenderForegrounds
;
419 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
422 panels
:= @gBlockMon
;
427 len
:= Length(panels
^);
428 SetLength(panels
^, len
+ 1);
430 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
431 panels
^[len
].ArrIdx
:= len
;
433 panels
^[len
].SaveIt
:= True;
437 len
:= Length(PanelByID
);
438 SetLength(PanelByID
, len
+ 1);
439 PanelByID
[len
].PWhere
:= panels
;
440 PanelByID
[len
].PArrID
:= Result
;
443 function CreateNullTexture(RecName
: String): Integer;
445 SetLength(Textures
, Length(Textures
)+1);
446 result
:= High(Textures
);
448 with Textures
[High(Textures
)] do
450 TextureName
:= RecName
;
454 TextureID
:= TEXTURE_NONE
;
458 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
461 TextureData
: Pointer;
462 WADName
, txname
: String;
463 a
, ResLength
: Integer;
467 if Textures
<> nil then
468 for a
:= 0 to High(Textures
) do
469 if Textures
[a
].TextureName
= RecName
then
470 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
475 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
476 if (RecName
= TEXTURE_NAME_WATER
) or
477 (RecName
= TEXTURE_NAME_ACID1
) or
478 (RecName
= TEXTURE_NAME_ACID2
) then
480 SetLength(Textures
, Length(Textures
)+1);
482 with Textures
[High(Textures
)] do
484 TextureName
:= RecName
;
486 if TextureName
= TEXTURE_NAME_WATER
then
487 TextureID
:= TEXTURE_SPECIAL_WATER
489 if TextureName
= TEXTURE_NAME_ACID1
then
490 TextureID
:= TEXTURE_SPECIAL_ACID1
492 if TextureName
= TEXTURE_NAME_ACID2
then
493 TextureID
:= TEXTURE_SPECIAL_ACID2
;
498 result
:= High(Textures
);
502 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
503 WADName
:= g_ExtractWadName(RecName
);
505 WAD
:= TWADFile
.Create();
507 if WADName
<> '' then
508 WADName
:= GameDir
+'/wads/'+WADName
512 WAD
.ReadFile(WADName
);
516 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
518 FreeMem(TextureData);
519 RecName := 'COMMON\ALIEN';
523 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
525 SetLength(Textures
, Length(Textures
)+1);
526 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
528 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
529 @Textures
[High(Textures
)].Width
,
530 @Textures
[High(Textures
)].Height
);
531 FreeMem(TextureData
);
532 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
533 Textures
[High(Textures
)].Anim
:= False;
535 result
:= High(Textures
);
537 else // Íåò òàêîãî ðåóñðñà â WAD'å
539 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
542 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
543 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
550 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
553 TextureWAD
: PChar = nil;
554 TextData
: Pointer = nil;
555 TextureData
: Pointer = nil;
559 TextureResource
: String;
560 _width
, _height
, _framecount
, _speed
: Integer;
561 _backanimation
: Boolean;
563 ia
: TDynImageDataArray
= nil;
564 f
, c
, frdelay
, frloop
: Integer;
568 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
570 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
571 WADName
:= g_ExtractWadName(RecName
);
573 WAD
:= TWADFile
.Create();
575 if WADName
<> '' then
576 WADName
:= GameDir
+'/wads/'+WADName
580 WAD
.ReadFile(WADName
);
582 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
586 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
587 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
593 if WADName = Map then
595 //FreeMem(TextureWAD);
596 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
602 if ResLength
< 6 then
604 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
608 // ýòî ïòèöà? ýòî ñàìîë¸ò?
609 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
610 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
612 // íåò, ýòî ñóïåðìåí!
613 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
615 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
619 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
620 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
622 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
626 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
628 TextureResource
:= cfg
.ReadStr('', 'resource', '');
629 if TextureResource
= '' then
631 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
635 _width
:= cfg
.ReadInt('', 'framewidth', 0);
636 _height
:= cfg
.ReadInt('', 'frameheight', 0);
637 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
638 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
639 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
644 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
645 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
647 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
654 SetLength(Textures
, Length(Textures
)+1);
655 with Textures
[High(Textures
)] do
657 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
658 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
660 TextureName
:= RecName
;
664 FramesCount
:= _framecount
;
666 result
:= High(Textures
);
670 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
676 // try animated image
678 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
679 if length(imgfmt) = 0 then
681 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
685 GlobalMetadata
.ClearMetaItems();
686 GlobalMetadata
.ClearMetaItemsForSaving();
687 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
689 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
692 if length(ia
) = 0 then
694 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
701 _width
:= ia
[0].width
;
702 _height
:= ia
[0].height
;
703 _framecount
:= length(ia
);
705 _backanimation
:= false;
708 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
710 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
712 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
714 if f
< 0 then f
:= 0;
717 if c
< 13 then c
:= 0 else c
:= 1;
719 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
724 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
726 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
728 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
730 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
734 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
735 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
736 f
:= ord(_backanimation
);
737 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
);
739 SetLength(Textures
, Length(Textures
)+1);
740 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
741 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
743 Textures
[High(Textures
)].TextureName
:= RecName
;
744 Textures
[High(Textures
)].Width
:= _width
;
745 Textures
[High(Textures
)].Height
:= _height
;
746 Textures
[High(Textures
)].Anim
:= True;
747 Textures
[High(Textures
)].FramesCount
:= length(ia
);
748 Textures
[High(Textures
)].Speed
:= _speed
;
749 result
:= High(Textures
);
750 //writeln(' CREATED!');
754 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
758 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
761 if TextureWAD
<> nil then FreeMem(TextureWAD
);
762 if TextData
<> nil then FreeMem(TextData
);
763 if TextureData
<> nil then FreeMem(TextureData
);
767 procedure CreateItem(Item
: TItemRec_1
);
769 if g_Game_IsClient
then Exit
;
771 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
772 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
775 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
776 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
779 procedure CreateArea(Area
: TAreaRec_1
);
784 case Area
.AreaType
of
785 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
786 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
788 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
789 with RespawnPoints
[High(RespawnPoints
)] do
793 Direction
:= TDirection(Area
.Direction
);
795 case Area
.AreaType
of
796 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
797 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
798 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
799 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
800 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
805 AREA_REDFLAG
, AREA_BLUEFLAG
:
807 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
809 if FlagPoints
[a
] <> nil then Exit
;
813 with FlagPoints
[a
]^ do
815 X
:= Area
.X
-FLAGRECT
.X
;
816 Y
:= Area
.Y
-FLAGRECT
.Y
;
817 Direction
:= TDirection(Area
.Direction
);
823 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
824 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
827 Animation
:= TAnimation
.Create(id
, True, 8);
828 Obj
.Rect
:= FLAGRECT
;
836 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
837 with DOMFlagPoints[High(DOMFlagPoints)] do
841 Direction := TDirection(Area.Direction);
844 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
849 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
853 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
859 Width
:= Trigger
.Width
;
860 Height
:= Trigger
.Height
;
861 Enabled
:= ByteBool(Trigger
.Enabled
);
862 TexturePanel
:= Trigger
.TexturePanel
;
863 TexturePanelType
:= fTexturePanel1Type
;
864 ShotPanelType
:= fTexturePanel2Type
;
865 TriggerType
:= Trigger
.TriggerType
;
866 ActivateType
:= Trigger
.ActivateType
;
867 Keys
:= Trigger
.Keys
;
868 Data
.Default
:= Trigger
.DATA
;
871 g_Triggers_Create(_trigger
);
874 procedure CreateMonster(monster
: TMonsterRec_1
);
878 if g_Game_IsClient
then Exit
;
880 if (gGameSettings
.GameType
= GT_SINGLE
)
881 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
883 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
884 TDirection(monster
.Direction
));
886 if gTriggers
<> nil then
887 for a
:= 0 to High(gTriggers
) do
888 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
889 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
890 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
891 gMonsters
[i
].AddTrigger(a
);
893 if monster
.MonsterType
<> MONSTER_BARREL
then
898 procedure g_Map_ReAdd_DieTriggers();
902 if g_Game_IsClient
then Exit
;
904 for i
:= 0 to High(gMonsters
) do
905 if gMonsters
[i
] <> nil then
907 gMonsters
[i
].ClearTriggers();
909 for a
:= 0 to High(gTriggers
) do
910 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
911 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
912 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
913 gMonsters
[i
].AddTrigger(a
);
917 function extractWadName(resourceName
: string): string;
921 posN
:= Pos(':', resourceName
);
923 Result
:= Copy(resourceName
, 0, posN
-1)
928 procedure addResToExternalResList(res
: string);
930 res
:= extractWadName(res
);
931 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
932 gExternalResources
.Add(res
);
935 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
937 textures
: TTexturesRec1Array
;
938 mapHeader
: TMapHeaderRec_1
;
940 resFile
: String = '';
942 if gExternalResources
= nil then
943 gExternalResources
:= TStringList
.Create
;
945 gExternalResources
.Clear
;
946 textures
:= mapReader
.GetTextures();
947 for i
:= 0 to High(textures
) do
949 addResToExternalResList(resFile
);
954 mapHeader
:= mapReader
.GetMapHeader
;
956 addResToExternalResList(mapHeader
.MusicName
);
957 addResToExternalResList(mapHeader
.SkyName
);
960 procedure mapCreateGrid ();
962 mapX0
: Integer = $3fffffff;
963 mapY0
: Integer = $3fffffff;
964 mapX1
: Integer = -$3fffffff;
965 mapY1
: Integer = -$3fffffff;
967 procedure fixMinMax (var panels
: TPanelArray
);
971 for idx
:= 0 to High(panels
) do
973 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
974 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
975 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
976 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
977 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
981 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
985 tag
:= panelTypeToTag(tag
);
986 for idx
:= High(panels
) downto 0 do
988 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
989 gMapSAP
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1000 fixMinMax(gRenderBackgrounds
);
1001 fixMinMax(gRenderForegrounds
);
1007 fixMinMax(gBlockMon
);
1009 if (mapX0
< 0) or (mapY0
< 0) then
1011 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1012 //raise Exception.Create('we are fucked');
1015 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1016 gMapSAP
:= TSweepAndPrune
.Create();
1018 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1019 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1020 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1021 addPanelsToGrid(gWater
, PANEL_WATER
);
1022 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1023 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1024 addPanelsToGrid(gSteps
, PANEL_STEP
);
1025 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1026 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1028 gMapGrid
.dumpStats();
1029 gMapSAP
.dumpStats();
1032 function g_Map_Load(Res
: String): Boolean;
1034 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1035 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1038 MapReader
: TMapReader_1
;
1039 Header
: TMapHeaderRec_1
;
1040 _textures
: TTexturesRec1Array
;
1041 _texnummap
: array of Integer; // `_textures` -> `Textures`
1042 panels
: TPanelsRec1Array
;
1043 items
: TItemsRec1Array
;
1044 monsters
: TMonsterRec1Array
;
1045 areas
: TAreasRec1Array
;
1046 triggers
: TTriggersRec1Array
;
1047 a
, b
, c
, k
: Integer;
1049 AddTextures
: TAddTextureArray
;
1050 texture
: TTextureRec_1
;
1051 TriggersTable
: Array of record
1052 TexturePanel
: Integer;
1057 FileName
, mapResName
, s
, TexName
: String;
1060 ok
, isAnim
, trigRef
: Boolean;
1061 CurTex
, ntn
: Integer;
1070 gMapInfo
.Map
:= Res
;
1071 TriggersTable
:= nil;
1072 FillChar(texture
, SizeOf(texture
), 0);
1074 sfsGCDisable(); // temporary disable removing of temporary volumes
1077 FileName
:= g_ExtractWadName(Res
);
1078 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1079 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1081 WAD
:= TWADFile
.Create();
1082 if not WAD
.ReadFile(FileName
) then
1084 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1088 //k8: why loader ignores path here?
1089 mapResName
:= g_ExtractFileName(Res
);
1090 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1092 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1100 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1101 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1102 MapReader
:= TMapReader_1
.Create();
1104 if not MapReader
.LoadMap(Data
) then
1106 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1113 generateExternalResourcesList(MapReader
);
1114 // Çàãðóçêà òåêñòóð:
1115 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1116 _textures
:= MapReader
.GetTextures();
1119 // Äîáàâëåíèå òåêñòóð â Textures[]:
1120 if _textures
<> nil then
1122 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1123 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1124 SetLength(_texnummap
, length(_textures
));
1126 for a
:= 0 to High(_textures
) do
1129 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1130 for b
:= 1 to Length(s
) do
1136 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1137 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1138 // Àíèìèðîâàííàÿ òåêñòóðà:
1139 if ByteBool(_textures
[a
].Anim
) then
1141 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1144 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1145 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1148 else // Îáû÷íàÿ òåêñòóðà:
1149 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1152 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1153 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1156 _texnummap
[a
] := ntn
; // fix texture number
1157 g_Game_StepLoading();
1161 // Çàãðóçêà òðèããåðîâ:
1162 gTriggerClientID
:= 0;
1163 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1164 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1165 triggers
:= MapReader
.GetTriggers();
1167 // Çàãðóçêà ïàíåëåé:
1168 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1169 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1170 panels
:= MapReader
.GetPanels();
1172 // check texture numbers for panels
1173 for a
:= 0 to High(panels
) do
1175 if panels
[a
].TextureNum
> High(_textures
) then
1177 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1181 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1184 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1185 if triggers
<> nil then
1187 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1188 SetLength(TriggersTable
, Length(triggers
));
1189 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1191 for a
:= 0 to High(TriggersTable
) do
1193 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1194 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1196 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1197 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1199 TriggersTable
[a
].LiftPanel
:= -1;
1201 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1202 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1203 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1204 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1206 TriggersTable
[a
].DoorPanel
:= -1;
1208 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1209 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1211 TriggersTable
[a
].ShotPanel
:= -1;
1213 g_Game_StepLoading();
1218 if panels
<> nil then
1220 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1221 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1223 for a
:= 0 to High(panels
) do
1225 SetLength(AddTextures
, 0);
1228 if _textures
<> nil then
1230 texture
:= _textures
[panels
[a
].TextureNum
];
1238 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1239 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1241 if (TriggersTable
<> nil) and (_textures
<> nil) then
1242 for b
:= 0 to High(TriggersTable
) do
1243 if (TriggersTable
[b
].TexturePanel
= a
)
1244 or (TriggersTable
[b
].ShotPanel
= a
) then
1253 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1255 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1258 for c
:= Len
downto 1 do
1266 // Ñïåö-òåêñòóðû çàïðåùåíû:
1267 if g_Map_IsSpecialTexture(s
) then
1270 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1271 ok
:= g_Texture_NumNameFindStart(s
);
1273 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1274 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1277 k
:= NNF_NAME_BEFORE
;
1278 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1279 while ok
or (k
= NNF_NAME_BEFORE
) or
1280 (k
= NNF_NAME_EQUALS
) do
1282 k
:= g_Texture_NumNameFindNext(TexName
);
1284 if (k
= NNF_NAME_BEFORE
) or
1285 (k
= NNF_NAME_AFTER
) then
1287 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1288 if ByteBool(texture
.Anim
) then
1289 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1291 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1293 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1295 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1299 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1301 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1303 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1305 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1309 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1312 for c
:= 0 to High(Textures
) do
1313 if Textures
[c
].TextureName
= TexName
then
1315 SetLength(AddTextures
, Length(AddTextures
)+1);
1316 AddTextures
[High(AddTextures
)].Texture
:= c
;
1317 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1323 if k
= NNF_NAME_EQUALS
then
1325 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1326 SetLength(AddTextures
, Length(AddTextures
)+1);
1327 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1328 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1329 CurTex
:= High(AddTextures
);
1337 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1338 end; // if ok - ññûëàþòñÿ òðèããåðû
1342 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1343 SetLength(AddTextures
, 1);
1344 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1345 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1349 //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);
1351 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1352 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1354 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1355 if TriggersTable
<> nil then
1356 for b
:= 0 to High(TriggersTable
) do
1358 // Òðèããåð äâåðè/ëèôòà:
1359 if (TriggersTable
[b
].LiftPanel
= a
) or
1360 (TriggersTable
[b
].DoorPanel
= a
) then
1361 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1362 // Òðèããåð ñìåíû òåêñòóðû:
1363 if TriggersTable
[b
].TexturePanel
= a
then
1364 triggers
[b
].TexturePanel
:= PanelID
;
1365 // Òðèããåð "Òóðåëü":
1366 if TriggersTable
[b
].ShotPanel
= a
then
1367 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1370 g_Game_StepLoading();
1374 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1375 if (triggers
<> nil) and not gLoadGameMode
then
1377 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1378 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1379 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1380 for a
:= 0 to High(triggers
) do
1382 if triggers
[a
].TexturePanel
<> -1 then
1383 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1386 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1387 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1388 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1391 CreateTrigger(triggers
[a
], b
, c
);
1395 // Çàãðóçêà ïðåäìåòîâ:
1396 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1397 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1398 items
:= MapReader
.GetItems();
1400 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1401 if (items
<> nil) and not gLoadGameMode
then
1403 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1404 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1405 for a
:= 0 to High(items
) do
1406 CreateItem(Items
[a
]);
1409 // Çàãðóçêà îáëàñòåé:
1410 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1411 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1412 areas
:= MapReader
.GetAreas();
1414 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1415 if areas
<> nil then
1417 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1418 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1419 for a
:= 0 to High(areas
) do
1420 CreateArea(areas
[a
]);
1423 // Çàãðóçêà ìîíñòðîâ:
1424 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1425 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1426 monsters
:= MapReader
.GetMonsters();
1428 gTotalMonsters
:= 0;
1430 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1431 if (monsters
<> nil) and not gLoadGameMode
then
1433 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1434 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1435 for a
:= 0 to High(monsters
) do
1436 CreateMonster(monsters
[a
]);
1439 // Çàãðóçêà îïèñàíèÿ êàðòû:
1440 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1441 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1442 Header
:= MapReader
.GetMapHeader();
1448 Name
:= Header
.MapName
;
1449 Description
:= Header
.MapDescription
;
1450 Author
:= Header
.MapAuthor
;
1451 MusicName
:= Header
.MusicName
;
1452 SkyName
:= Header
.SkyName
;
1453 Height
:= Header
.Height
;
1454 Width
:= Header
.Width
;
1458 if gMapInfo
.SkyName
<> '' then
1460 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1461 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1462 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1464 if FileName
<> '' then
1465 FileName
:= GameDir
+'/wads/'+FileName
1468 FileName
:= g_ExtractWadName(Res
);
1471 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1472 if g_Texture_CreateWAD(BackID
, s
) then
1474 g_Game_SetupScreenSize();
1477 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1482 if gMapInfo
.MusicName
<> '' then
1484 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1485 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1486 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1488 if FileName
<> '' then
1489 FileName
:= GameDir
+'/wads/'+FileName
1492 FileName
:= g_ExtractWadName(Res
);
1495 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1496 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1499 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1502 // Îñòàëüíûå óñòàíâêè:
1510 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1511 if not gLoadGameMode
then
1514 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1520 TriggersTable
:= nil;
1523 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1524 if ok
and (not gLoadGameMode
) then
1526 gMusic
.SetByName(gMapInfo
.MusicName
);
1530 gMusic
.SetByName('');
1532 sfsGCEnable(); // enable releasing unused volumes
1535 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1538 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1542 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1545 MapReader
: TMapReader_1
;
1546 Header
: TMapHeaderRec_1
;
1551 FillChar(Result
, SizeOf(Result
), 0);
1552 FileName
:= g_ExtractWadName(Res
);
1554 WAD
:= TWADFile
.Create();
1555 if not WAD
.ReadFile(FileName
) then
1561 //k8: it ignores path again
1562 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1570 MapReader
:= TMapReader_1
.Create();
1572 if not MapReader
.LoadMap(Data
) then
1574 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1575 ZeroMemory(@Header
, SizeOf(Header
));
1576 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1577 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1581 Header
:= MapReader
.GetMapHeader();
1582 Result
.Name
:= Header
.MapName
;
1583 Result
.Description
:= Header
.MapDescription
;
1590 Result
.Author
:= Header
.MapAuthor
;
1591 Result
.Height
:= Header
.Height
;
1592 Result
.Width
:= Header
.Width
;
1595 function g_Map_GetMapsList(WADName
: string): SArray
;
1602 WAD
:= TWADFile
.Create();
1603 if not WAD
.ReadFile(WADName
) then
1608 ResList
:= WAD
.GetMapResources();
1609 if ResList
<> nil then
1611 for a
:= 0 to High(ResList
) do
1613 SetLength(Result
, Length(Result
)+1);
1614 Result
[High(Result
)] := ResList
[a
];
1620 function g_Map_Exist(Res
: string): Boolean;
1623 FileName
, mnn
: string;
1629 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1631 WAD
:= TWADFile
.Create
;
1632 if not WAD
.ReadFile(FileName
) then
1638 ResList
:= WAD
.GetMapResources();
1641 mnn
:= g_ExtractFileName(Res
);
1642 if ResList
<> nil then
1643 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1650 procedure g_Map_Free();
1654 procedure FreePanelArray(var panels
: TPanelArray
);
1659 if panels
<> nil then
1661 for i
:= 0 to High(panels
) do
1674 RespawnPoints
:= nil;
1675 if FlagPoints
[FLAG_RED
] <> nil then
1677 Dispose(FlagPoints
[FLAG_RED
]);
1678 FlagPoints
[FLAG_RED
] := nil;
1680 if FlagPoints
[FLAG_BLUE
] <> nil then
1682 Dispose(FlagPoints
[FLAG_BLUE
]);
1683 FlagPoints
[FLAG_BLUE
] := nil;
1685 //DOMFlagPoints := nil;
1689 if Textures
<> nil then
1691 for a
:= 0 to High(Textures
) do
1692 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1693 if Textures
[a
].Anim
then
1694 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1696 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1697 e_DeleteTexture(Textures
[a
].TextureID
);
1702 FreePanelArray(gWalls
);
1703 FreePanelArray(gRenderBackgrounds
);
1704 FreePanelArray(gRenderForegrounds
);
1705 FreePanelArray(gWater
);
1706 FreePanelArray(gAcid1
);
1707 FreePanelArray(gAcid2
);
1708 FreePanelArray(gSteps
);
1709 FreePanelArray(gLifts
);
1710 FreePanelArray(gBlockMon
);
1712 if BackID
<> DWORD(-1) then
1716 e_DeleteTexture(BackID
);
1717 BackID
:= DWORD(-1);
1720 g_Game_StopAllSounds(False);
1722 g_Sound_Delete(gMapInfo
.MusicName
);
1724 gMapInfo
.Name
:= '';
1725 gMapInfo
.Description
:= '';
1726 gMapInfo
.MusicName
:= '';
1727 gMapInfo
.Height
:= 0;
1728 gMapInfo
.Width
:= 0;
1736 procedure g_Map_Update();
1742 procedure UpdatePanelArray(var panels
: TPanelArray
);
1747 if panels
<> nil then
1748 for i
:= 0 to High(panels
) do
1753 UpdatePanelArray(gWalls
);
1754 UpdatePanelArray(gRenderBackgrounds
);
1755 UpdatePanelArray(gRenderForegrounds
);
1756 UpdatePanelArray(gWater
);
1757 UpdatePanelArray(gAcid1
);
1758 UpdatePanelArray(gAcid2
);
1759 UpdatePanelArray(gSteps
);
1761 if gGameSettings
.GameMode
= GM_CTF
then
1763 for a
:= FLAG_RED
to FLAG_BLUE
do
1764 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1767 if gFlags
[a
].Animation
<> nil then
1768 gFlags
[a
].Animation
.Update();
1770 m
:= g_Obj_Move(@Obj
, True, True);
1772 if gTime
mod (GAME_TICK
*2) <> 0 then
1775 // Ñîïðîòèâëåíèå âîçäóõà:
1776 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1778 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1779 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1782 gFlags
[a
].CaptureTime
:= 0;
1783 if a
= FLAG_RED
then
1784 s
:= _lc
[I_PLAYER_FLAG_RED
]
1786 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1787 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1789 if g_Game_IsNet
then
1790 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1797 // Èãðîê áåðåò ôëàã:
1798 if gPlayers
<> nil then
1800 j
:= Random(Length(gPlayers
)) - 1;
1802 for d
:= 0 to High(gPlayers
) do
1805 if j
> High(gPlayers
) then
1808 if gPlayers
[j
] <> nil then
1809 if gPlayers
[j
].Live
and
1810 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1812 if gPlayers
[j
].GetFlag(a
) then
1822 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1824 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1828 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1830 // alas, no visible set
1831 for idx
:= 0 to High(panels
) do
1833 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1840 PANEL_WALL
: DrawPanels(0, gWalls
);
1841 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1842 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1843 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1844 PANEL_WATER
: DrawPanels(3, gWater
);
1845 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1846 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1847 PANEL_STEP
: DrawPanels(6, gSteps
);
1853 gDrawPanelList
: TBinaryHeapObj
= nil;
1855 function dplLess (a
, b
: TObject
): Boolean;
1857 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1860 procedure dplClear ();
1862 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1865 procedure dplAddPanel (pan
: TPanel
);
1867 if pan
= nil then exit
;
1868 gDrawPanelList
.insert(pan
);
1872 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1876 function checker (obj
: TObject
; tag
: Integer): Boolean;
1880 result
:= false; // don't stop, ever
1881 if (tag
<> ptag
) then exit
;
1882 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1884 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1885 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1886 //pan := (obj as TPanel);
1887 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1889 pan
:= (obj
as TPanel
);
1890 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1891 //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);
1895 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1900 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1902 // alas, no visible set
1903 for idx
:= 0 to High(panels
) do
1905 if not (drawDoors
xor panels
[idx
].Door
) then
1909 if (pan.Width < 1) or (pan.Height < 1) then continue;
1910 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1911 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1914 //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);
1921 //g_Map_DrawPanelsOld(PanelType); exit;
1922 //e_WriteLog('==================', MSG_NOTIFY);
1923 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1925 ptag
:= panelTypeToTag(PanelType
);
1927 if gdbg_map_use_grid_render
then
1929 if gdbg_map_use_sap
then
1931 gMapSAP
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1935 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1937 // sort and draw the list (we need to sort it, or rendering is fucked)
1938 while gDrawPanelList
.count
> 0 do
1940 (gDrawPanelList
.front() as TPanel
).Draw();
1941 gDrawPanelList
.popFront();
1946 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1948 PANEL_WALL
: DrawPanels(0, gWalls
);
1949 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1950 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1951 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1952 PANEL_WATER
: DrawPanels(3, gWater
);
1953 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1954 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1955 PANEL_STEP
: DrawPanels(6, gSteps
);
1959 //e_WriteLog('==================', MSG_NOTIFY);
1963 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1964 function checker (obj
: TObject
; tag
: Integer): Boolean;
1968 result
:= false; // don't stop, ever
1969 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1970 pan
:= (obj
as TPanel
);
1971 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1975 if gdbg_map_use_sap
then
1977 gMapSAP
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1981 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1986 procedure g_Map_DrawBack(dx
, dy
: Integer);
1988 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1989 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1991 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1994 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1995 PanelType
: Word; b1x3
: Boolean): Boolean;
2001 if WordBool(PanelType
and PANEL_WALL
) then
2002 if gWalls
<> nil then
2007 if gWalls
[a
].Enabled
and
2008 g_Collide(X
, Y
, Width
, Height
,
2009 gWalls
[a
].X
, gWalls
[a
].Y
,
2010 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2017 if WordBool(PanelType
and PANEL_WATER
) then
2018 if gWater
<> nil then
2023 if g_Collide(X
, Y
, Width
, Height
,
2024 gWater
[a
].X
, gWater
[a
].Y
,
2025 gWater
[a
].Width
, gWater
[a
].Height
) then
2032 if WordBool(PanelType
and PANEL_ACID1
) then
2033 if gAcid1
<> nil then
2038 if g_Collide(X
, Y
, Width
, Height
,
2039 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2040 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2047 if WordBool(PanelType
and PANEL_ACID2
) then
2048 if gAcid2
<> nil then
2053 if g_Collide(X
, Y
, Width
, Height
,
2054 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2055 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2062 if WordBool(PanelType
and PANEL_STEP
) then
2063 if gSteps
<> nil then
2068 if g_Collide(X
, Y
, Width
, Height
,
2069 gSteps
[a
].X
, gSteps
[a
].Y
,
2070 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2077 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2078 if gLifts
<> nil then
2083 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2084 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2085 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2086 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2087 g_Collide(X
, Y
, Width
, Height
,
2088 gLifts
[a
].X
, gLifts
[a
].Y
,
2089 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2096 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2097 if gBlockMon
<> nil then
2099 h
:= High(gBlockMon
);
2103 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2104 g_Collide(X
, Y
, Width
, Height
,
2105 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2106 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2114 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2118 function checkPanels (var panels
: TPanelArray
): Boolean;
2123 if panels
= nil then exit
;
2124 for a
:= 0 to High(panels
) do
2126 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2129 texid
:= panels
[a
].GetTextureID();
2136 texid
:= TEXTURE_NONE
;
2138 if not checkPanels(gWater
) then
2139 if not checkPanels(gAcid1
) then
2140 if not checkPanels(gAcid2
) then exit
;
2145 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2147 function checker (obj
: TObject
; tag
: Integer): Boolean;
2152 result
:= false; // don't stop, ever
2154 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2158 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2160 if not (obj
is TPanel
) then
2162 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2166 pan
:= (obj
as TPanel
);
2169 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2171 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2178 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2180 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2187 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2189 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2196 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2198 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2205 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2207 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2214 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2216 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2217 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2218 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2219 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2220 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2227 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2229 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2230 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2239 //TODO: detailed profile
2240 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2242 if gdbg_map_use_grid_coldet
then
2244 if gdbg_map_use_sap
then
2246 gMapSAP
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2250 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2255 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2258 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2263 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2265 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2268 // slightly different from the old code, but meh...
2269 function checker (obj
: TObject
; tag
: Integer): Boolean;
2274 result
:= false; // don't stop, ever
2275 pan
:= (obj
as TPanel
);
2278 if (tag
= GridTagWater
) then
2280 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2282 result
:= true; // water has highest priority, so stop right here
2283 texid
:= gWater
[a
].GetTextureID();
2288 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2290 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2293 texid
:= gAcid1
[a
].GetTextureID();
2298 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2300 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2303 texid
:= gAcid2
[a
].GetTextureID();
2310 //TODO: detailed profile?
2311 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2313 if gdbg_map_use_grid_coldet
then
2315 texid
:= TEXTURE_NONE
;
2316 if gdbg_map_use_sap
then
2318 gMapSAP
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2322 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2328 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2331 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2335 procedure g_Map_EnableWall(ID
: DWORD
);
2340 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2342 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2346 procedure g_Map_DisableWall(ID
: DWORD
);
2351 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2353 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2357 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2362 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2365 tp
:= gRenderForegrounds
[ID
];
2367 tp
:= gRenderBackgrounds
[ID
];
2380 tp
.NextTexture(AnimLoop
);
2381 if g_Game_IsServer
and g_Game_IsNet
then
2382 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2385 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2387 if gLifts
[ID
].LiftType
= t
then
2394 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2396 if LiftType
= 0 then
2397 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2398 else if LiftType
= 1 then
2399 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2400 else if LiftType
= 2 then
2401 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2402 else if LiftType
= 3 then
2403 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2405 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2409 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2412 PointsArray
: Array of TRespawnPoint
;
2415 SetLength(PointsArray
, 0);
2417 if RespawnPoints
= nil then
2420 for a
:= 0 to High(RespawnPoints
) do
2421 if RespawnPoints
[a
].PointType
= PointType
then
2423 SetLength(PointsArray
, Length(PointsArray
)+1);
2424 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2427 if PointsArray
= nil then
2430 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2434 function g_Map_GetPointCount(PointType
: Byte): Word;
2440 if RespawnPoints
= nil then
2443 for a
:= 0 to High(RespawnPoints
) do
2444 if RespawnPoints
[a
].PointType
= PointType
then
2445 Result
:= Result
+ 1;
2448 function g_Map_HaveFlagPoints(): Boolean;
2450 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2453 procedure g_Map_ResetFlag(Flag
: Byte);
2455 with gFlags
[Flag
] do
2461 Direction
:= D_LEFT
;
2462 State
:= FLAG_STATE_NONE
;
2463 if FlagPoints
[Flag
] <> nil then
2465 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2466 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2467 Direction
:= FlagPoints
[Flag
]^.Direction
;
2468 State
:= FLAG_STATE_NORMAL
;
2474 procedure g_Map_DrawFlags();
2477 Mirror
: TMirrorType
;
2479 if gGameSettings
.GameMode
<> GM_CTF
then
2482 for i
:= FLAG_RED
to FLAG_BLUE
do
2484 if State
<> FLAG_STATE_CAPTURED
then
2486 if State
= FLAG_STATE_NONE
then
2489 if Direction
= D_LEFT
then
2491 Mirror
:= M_HORIZONTAL
;
2500 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2502 if g_debug_Frames
then
2504 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2506 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2507 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2513 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2520 procedure SavePanelArray(var panels
: TPanelArray
);
2522 PAMem
: TBinMemoryWriter
;
2525 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2526 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2529 while i
< Length(panels
) do
2531 if panels
[i
].SaveIt
then
2535 // Ñîõðàíÿåì ïàíåëü:
2536 panels
[i
].SaveState(PAMem
);
2541 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2542 PAMem
.SaveToMemory(Mem
);
2546 procedure SaveFlag(flag
: PFlag
);
2549 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2551 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2552 Mem
.WriteByte(flag
^.RespawnType
);
2554 Mem
.WriteByte(flag
^.State
);
2555 // Íàïðàâëåíèå ôëàãà:
2556 if flag
^.Direction
= D_LEFT
then
2562 Obj_SaveState(@flag
^.Obj
, Mem
);
2566 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2568 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2569 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2570 SavePanelArray(gWalls
);
2571 // Ñîõðàíÿåì ïàíåëè ôîíà:
2572 SavePanelArray(gRenderBackgrounds
);
2573 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2574 SavePanelArray(gRenderForegrounds
);
2575 // Ñîõðàíÿåì ïàíåëè âîäû:
2576 SavePanelArray(gWater
);
2577 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2578 SavePanelArray(gAcid1
);
2579 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2580 SavePanelArray(gAcid2
);
2581 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2582 SavePanelArray(gSteps
);
2583 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2584 SavePanelArray(gLifts
);
2587 ///// Ñîõðàíÿåì ìóçûêó: /////
2588 // Ñèãíàòóðà ìóçûêè:
2589 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2592 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2593 if gMusic
.NoMusic
then
2597 Mem
.WriteString(str
, 64);
2598 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2599 dw
:= gMusic
.GetPosition();
2601 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2602 boo
:= gMusic
.SpecPause
;
2603 Mem
.WriteBoolean(boo
);
2606 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2607 Mem
.WriteInt(gTotalMonsters
);
2610 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2611 if gGameSettings
.GameMode
= GM_CTF
then
2613 // Ôëàã Êðàñíîé êîìàíäû:
2614 SaveFlag(@gFlags
[FLAG_RED
]);
2615 // Ôëàã Ñèíåé êîìàíäû:
2616 SaveFlag(@gFlags
[FLAG_BLUE
]);
2620 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2621 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2623 // Î÷êè Êðàñíîé êîìàíäû:
2624 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2625 // Î÷êè Ñèíåé êîìàíäû:
2626 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2631 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2638 procedure LoadPanelArray(var panels
: TPanelArray
);
2640 PAMem
: TBinMemoryReader
;
2643 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2644 PAMem
:= TBinMemoryReader
.Create();
2645 PAMem
.LoadFromMemory(Mem
);
2647 for i
:= 0 to Length(panels
)-1 do
2648 if panels
[i
].SaveIt
then
2654 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2656 // Çàãðóæàåì ïàíåëü:
2657 panels
[i
].LoadState(PAMem
);
2660 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2664 procedure LoadFlag(flag
: PFlag
);
2668 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2670 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2672 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2673 Mem
.ReadByte(flag
^.RespawnType
);
2675 Mem
.ReadByte(flag
^.State
);
2676 // Íàïðàâëåíèå ôëàãà:
2679 flag
^.Direction
:= D_LEFT
2681 flag
^.Direction
:= D_RIGHT
;
2683 Obj_LoadState(@flag
^.Obj
, Mem
);
2690 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2691 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2692 LoadPanelArray(gWalls
);
2693 // Çàãðóæàåì ïàíåëè ôîíà:
2694 LoadPanelArray(gRenderBackgrounds
);
2695 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2696 LoadPanelArray(gRenderForegrounds
);
2697 // Çàãðóæàåì ïàíåëè âîäû:
2698 LoadPanelArray(gWater
);
2699 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2700 LoadPanelArray(gAcid1
);
2701 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2702 LoadPanelArray(gAcid2
);
2703 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2704 LoadPanelArray(gSteps
);
2705 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2706 LoadPanelArray(gLifts
);
2709 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2713 ///// Çàãðóæàåì ìóçûêó: /////
2714 // Ñèãíàòóðà ìóçûêè:
2716 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2718 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2721 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2722 Mem
.ReadString(str
);
2723 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2725 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2726 Mem
.ReadBoolean(boo
);
2727 // Çàïóñêàåì ýòó ìóçûêó:
2728 gMusic
.SetByName(str
);
2729 gMusic
.SpecPause
:= boo
;
2732 gMusic
.SetPosition(dw
);
2735 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2736 Mem
.ReadInt(gTotalMonsters
);
2739 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2740 if gGameSettings
.GameMode
= GM_CTF
then
2742 // Ôëàã Êðàñíîé êîìàíäû:
2743 LoadFlag(@gFlags
[FLAG_RED
]);
2744 // Ôëàã Ñèíåé êîìàíäû:
2745 LoadFlag(@gFlags
[FLAG_BLUE
]);
2749 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2750 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2752 // Î÷êè Êðàñíîé êîìàíäû:
2753 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2754 // Î÷êè Ñèíåé êîìàíäû:
2755 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2760 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2765 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2766 Arr
:= PanelByID
[PanelID
].PWhere
^;
2767 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2768 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);