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_accel_render
: Boolean = true;
138 gdbg_map_use_accel_coldet
: Boolean = true;
139 gdbg_map_use_tree_draw
: Boolean = false;
140 gdbg_map_use_tree_coldet
: Boolean = false;
141 gdbg_map_dump_coldet_tree_queries
: Boolean = false;
142 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
147 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
148 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
149 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
150 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
152 ImagingTypes
, Imaging
, ImagingUtility
,
153 ImagingGif
, ImagingNetworkGraphics
;
156 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
157 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
158 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
161 GridTagWallDoor
= $0001;
164 GridTagWater
= $0008;
165 GridTagAcid1
= $0010;
166 GridTagAcid2
= $0020;
169 GridTagBlockMon
= $0100;
172 function panelTypeToTag (panelType
: Word): Integer;
175 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
176 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
177 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
178 PANEL_WATER
: result
:= GridTagWater
; // gWater
179 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
180 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
181 PANEL_STEP
: result
:= GridTagStep
; // gSteps
182 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
183 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
184 else result
:= GridTagInvalid
;
191 PWhere
: ^TPanelArray
;
196 TDynAABBTreeMap
= class(TDynAABBTree
)
197 function getFleshAABB (var aabb
: AABB2D
; flesh
: TTreeFlesh
): Boolean; override;
200 function TDynAABBTreeMap
.getFleshAABB (var aabb
: AABB2D
; flesh
: TTreeFlesh
): Boolean;
205 if (flesh
= nil) then begin aabb
:= AABB2D
.Create(0, 0, 0, 0); exit
; end;
206 pan
:= (flesh
as TPanel
);
207 aabb
:= AABB2D
.Create(pan
.X
, pan
.Y
, pan
.X
+pan
.Width
, pan
.Y
+pan
.Height
);
208 if (pan
.Width
< 1) or (pan
.Height
< 1) then exit
;
209 //if (pan.Width = 1) then aabb.maxX += 1;
210 //if (pan.Height = 1) then aabb.maxY += 1;
211 if not aabb
.valid
then raise Exception
.Create('wutafuuuuuuu?!');
212 result
:= aabb
.valid
;
216 PanelById
: array of TPanelID
;
217 Textures
: TLevelTextureArray
;
218 RespawnPoints
: Array of TRespawnPoint
;
219 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
220 //DOMFlagPoints: Array of TFlagPoint;
221 gMapGrid
: TBodyGrid
= nil;
222 mapTree
: TDynAABBTree
= nil;
225 procedure g_Map_ProfilersBegin ();
227 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
228 profMapCollision
.mainBegin(g_profile_collision
);
230 if g_profile_collision
then
232 profMapCollision
.sectionBegin('wall coldet');
233 profMapCollision
.sectionEnd();
234 profMapCollision
.sectionBegin('liquid coldet');
235 profMapCollision
.sectionEnd();
239 procedure g_Map_ProfilersEnd ();
241 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
245 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
247 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
248 (Texture
= TEXTURE_NAME_ACID1
) or
249 (Texture
= TEXTURE_NAME_ACID2
);
252 procedure CreateDoorMap();
254 PanelArray
: Array of record
260 a
, b
, c
, m
, i
, len
: Integer;
268 SetLength(PanelArray
, len
);
270 for a
:= 0 to High(gWalls
) do
271 if gWalls
[a
].Door
then
273 PanelArray
[i
].X
:= gWalls
[a
].X
;
274 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
275 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
276 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
277 PanelArray
[i
].Active
:= True;
278 PanelArray
[i
].PanelID
:= a
;
284 SetLength(PanelArray
, len
);
295 SetLength(gDoorMap
, 0);
297 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
300 if PanelArray
[a
].Active
then
302 PanelArray
[a
].Active
:= False;
303 m
:= Length(gDoorMap
);
304 SetLength(gDoorMap
, m
+1);
305 SetLength(gDoorMap
[m
], 1);
306 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
314 if PanelArray
[b
].Active
then
315 for c
:= 0 to High(gDoorMap
[m
]) do
316 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
317 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
318 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
319 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
320 gWalls
[gDoorMap
[m
, c
]].X
,
321 gWalls
[gDoorMap
[m
, c
]].Y
,
322 gWalls
[gDoorMap
[m
, c
]].Width
,
323 gWalls
[gDoorMap
[m
, c
]].Height
) then
325 PanelArray
[b
].Active
:= False;
326 SetLength(gDoorMap
[m
],
327 Length(gDoorMap
[m
])+1);
328 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
334 g_Game_StepLoading();
340 procedure CreateLiftMap();
342 PanelArray
: Array of record
347 a
, b
, c
, len
, i
, j
: Integer;
353 len
:= Length(gLifts
);
354 SetLength(PanelArray
, len
);
356 for a
:= 0 to len
-1 do
358 PanelArray
[a
].X
:= gLifts
[a
].X
;
359 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
360 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
361 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
362 PanelArray
[a
].Active
:= True;
365 SetLength(gLiftMap
, len
);
368 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
370 for a
:= 0 to len
-1 do
371 if PanelArray
[a
].Active
then
373 PanelArray
[a
].Active
:= False;
374 SetLength(gLiftMap
[i
], 32);
382 for b
:= 0 to len
-1 do
383 if PanelArray
[b
].Active
then
385 if g_CollideAround(PanelArray
[b
].X
,
388 PanelArray
[b
].Height
,
389 PanelArray
[gLiftMap
[i
, c
]].X
,
390 PanelArray
[gLiftMap
[i
, c
]].Y
,
391 PanelArray
[gLiftMap
[i
, c
]].Width
,
392 PanelArray
[gLiftMap
[i
, c
]].Height
) then
394 PanelArray
[b
].Active
:= False;
396 if j
> High(gLiftMap
[i
]) then
397 SetLength(gLiftMap
[i
],
398 Length(gLiftMap
[i
])+32);
407 SetLength(gLiftMap
[i
], j
+1);
410 g_Game_StepLoading();
413 SetLength(gLiftMap
, i
);
418 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
419 CurTex
: Integer; sav
: Boolean): Integer;
422 panels
: ^TPanelArray
;
426 case PanelRec
.PanelType
of
427 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
430 panels
:= @gRenderBackgrounds
;
432 panels
:= @gRenderForegrounds
;
441 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
444 panels
:= @gBlockMon
;
449 len
:= Length(panels
^);
450 SetLength(panels
^, len
+ 1);
452 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
453 panels
^[len
].ArrIdx
:= len
;
454 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
456 panels
^[len
].SaveIt
:= True;
460 len
:= Length(PanelByID
);
461 SetLength(PanelByID
, len
+ 1);
462 PanelByID
[len
].PWhere
:= panels
;
463 PanelByID
[len
].PArrID
:= Result
;
466 function CreateNullTexture(RecName
: String): Integer;
468 SetLength(Textures
, Length(Textures
)+1);
469 result
:= High(Textures
);
471 with Textures
[High(Textures
)] do
473 TextureName
:= RecName
;
477 TextureID
:= TEXTURE_NONE
;
481 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
484 TextureData
: Pointer;
485 WADName
, txname
: String;
486 a
, ResLength
: Integer;
490 if Textures
<> nil then
491 for a
:= 0 to High(Textures
) do
492 if Textures
[a
].TextureName
= RecName
then
493 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
498 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
499 if (RecName
= TEXTURE_NAME_WATER
) or
500 (RecName
= TEXTURE_NAME_ACID1
) or
501 (RecName
= TEXTURE_NAME_ACID2
) then
503 SetLength(Textures
, Length(Textures
)+1);
505 with Textures
[High(Textures
)] do
507 TextureName
:= RecName
;
509 if TextureName
= TEXTURE_NAME_WATER
then
510 TextureID
:= TEXTURE_SPECIAL_WATER
512 if TextureName
= TEXTURE_NAME_ACID1
then
513 TextureID
:= TEXTURE_SPECIAL_ACID1
515 if TextureName
= TEXTURE_NAME_ACID2
then
516 TextureID
:= TEXTURE_SPECIAL_ACID2
;
521 result
:= High(Textures
);
525 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
526 WADName
:= g_ExtractWadName(RecName
);
528 WAD
:= TWADFile
.Create();
530 if WADName
<> '' then
531 WADName
:= GameDir
+'/wads/'+WADName
535 WAD
.ReadFile(WADName
);
539 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
541 FreeMem(TextureData);
542 RecName := 'COMMON\ALIEN';
546 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
548 SetLength(Textures
, Length(Textures
)+1);
549 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
551 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
552 @Textures
[High(Textures
)].Width
,
553 @Textures
[High(Textures
)].Height
);
554 FreeMem(TextureData
);
555 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
556 Textures
[High(Textures
)].Anim
:= False;
558 result
:= High(Textures
);
560 else // Íåò òàêîãî ðåóñðñà â WAD'å
562 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
565 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
566 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
573 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
576 TextureWAD
: PChar = nil;
577 TextData
: Pointer = nil;
578 TextureData
: Pointer = nil;
582 TextureResource
: String;
583 _width
, _height
, _framecount
, _speed
: Integer;
584 _backanimation
: Boolean;
586 ia
: TDynImageDataArray
= nil;
587 f
, c
, frdelay
, frloop
: Integer;
591 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
593 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
594 WADName
:= g_ExtractWadName(RecName
);
596 WAD
:= TWADFile
.Create();
598 if WADName
<> '' then
599 WADName
:= GameDir
+'/wads/'+WADName
603 WAD
.ReadFile(WADName
);
605 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
609 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
610 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
616 if WADName = Map then
618 //FreeMem(TextureWAD);
619 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
625 if ResLength
< 6 then
627 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
631 // ýòî ïòèöà? ýòî ñàìîë¸ò?
632 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
633 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
635 // íåò, ýòî ñóïåðìåí!
636 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
638 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
642 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
643 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
645 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
649 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
651 TextureResource
:= cfg
.ReadStr('', 'resource', '');
652 if TextureResource
= '' then
654 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
658 _width
:= cfg
.ReadInt('', 'framewidth', 0);
659 _height
:= cfg
.ReadInt('', 'frameheight', 0);
660 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
661 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
662 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
667 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
668 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
670 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
677 SetLength(Textures
, Length(Textures
)+1);
678 with Textures
[High(Textures
)] do
680 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
681 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
683 TextureName
:= RecName
;
687 FramesCount
:= _framecount
;
689 result
:= High(Textures
);
693 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
699 // try animated image
701 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
702 if length(imgfmt) = 0 then
704 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
708 GlobalMetadata
.ClearMetaItems();
709 GlobalMetadata
.ClearMetaItemsForSaving();
710 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
712 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
715 if length(ia
) = 0 then
717 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
724 _width
:= ia
[0].width
;
725 _height
:= ia
[0].height
;
726 _framecount
:= length(ia
);
728 _backanimation
:= false;
731 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
733 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
735 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
737 if f
< 0 then f
:= 0;
740 if c
< 13 then c
:= 0 else c
:= 1;
742 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
747 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
749 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
751 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
753 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
757 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
758 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
759 f
:= ord(_backanimation
);
760 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
);
762 SetLength(Textures
, Length(Textures
)+1);
763 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
764 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
766 Textures
[High(Textures
)].TextureName
:= RecName
;
767 Textures
[High(Textures
)].Width
:= _width
;
768 Textures
[High(Textures
)].Height
:= _height
;
769 Textures
[High(Textures
)].Anim
:= True;
770 Textures
[High(Textures
)].FramesCount
:= length(ia
);
771 Textures
[High(Textures
)].Speed
:= _speed
;
772 result
:= High(Textures
);
773 //writeln(' CREATED!');
777 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
781 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
784 if TextureWAD
<> nil then FreeMem(TextureWAD
);
785 if TextData
<> nil then FreeMem(TextData
);
786 if TextureData
<> nil then FreeMem(TextureData
);
790 procedure CreateItem(Item
: TItemRec_1
);
792 if g_Game_IsClient
then Exit
;
794 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
795 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
798 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
799 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
802 procedure CreateArea(Area
: TAreaRec_1
);
807 case Area
.AreaType
of
808 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
809 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
811 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
812 with RespawnPoints
[High(RespawnPoints
)] do
816 Direction
:= TDirection(Area
.Direction
);
818 case Area
.AreaType
of
819 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
820 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
821 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
822 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
823 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
828 AREA_REDFLAG
, AREA_BLUEFLAG
:
830 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
832 if FlagPoints
[a
] <> nil then Exit
;
836 with FlagPoints
[a
]^ do
838 X
:= Area
.X
-FLAGRECT
.X
;
839 Y
:= Area
.Y
-FLAGRECT
.Y
;
840 Direction
:= TDirection(Area
.Direction
);
846 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
847 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
850 Animation
:= TAnimation
.Create(id
, True, 8);
851 Obj
.Rect
:= FLAGRECT
;
859 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
860 with DOMFlagPoints[High(DOMFlagPoints)] do
864 Direction := TDirection(Area.Direction);
867 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
872 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
876 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
882 Width
:= Trigger
.Width
;
883 Height
:= Trigger
.Height
;
884 Enabled
:= ByteBool(Trigger
.Enabled
);
885 TexturePanel
:= Trigger
.TexturePanel
;
886 TexturePanelType
:= fTexturePanel1Type
;
887 ShotPanelType
:= fTexturePanel2Type
;
888 TriggerType
:= Trigger
.TriggerType
;
889 ActivateType
:= Trigger
.ActivateType
;
890 Keys
:= Trigger
.Keys
;
891 Data
.Default
:= Trigger
.DATA
;
894 g_Triggers_Create(_trigger
);
897 procedure CreateMonster(monster
: TMonsterRec_1
);
901 if g_Game_IsClient
then Exit
;
903 if (gGameSettings
.GameType
= GT_SINGLE
)
904 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
906 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
907 TDirection(monster
.Direction
));
909 if gTriggers
<> nil then
910 for a
:= 0 to High(gTriggers
) do
911 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
912 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
913 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
914 gMonsters
[i
].AddTrigger(a
);
916 if monster
.MonsterType
<> MONSTER_BARREL
then
921 procedure g_Map_ReAdd_DieTriggers();
925 if g_Game_IsClient
then Exit
;
927 for i
:= 0 to High(gMonsters
) do
928 if gMonsters
[i
] <> nil then
930 gMonsters
[i
].ClearTriggers();
932 for a
:= 0 to High(gTriggers
) do
933 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
934 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
935 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
936 gMonsters
[i
].AddTrigger(a
);
940 function extractWadName(resourceName
: string): string;
944 posN
:= Pos(':', resourceName
);
946 Result
:= Copy(resourceName
, 0, posN
-1)
951 procedure addResToExternalResList(res
: string);
953 res
:= extractWadName(res
);
954 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
955 gExternalResources
.Add(res
);
958 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
960 textures
: TTexturesRec1Array
;
961 mapHeader
: TMapHeaderRec_1
;
963 resFile
: String = '';
965 if gExternalResources
= nil then
966 gExternalResources
:= TStringList
.Create
;
968 gExternalResources
.Clear
;
969 textures
:= mapReader
.GetTextures();
970 for i
:= 0 to High(textures
) do
972 addResToExternalResList(resFile
);
977 mapHeader
:= mapReader
.GetMapHeader
;
979 addResToExternalResList(mapHeader
.MusicName
);
980 addResToExternalResList(mapHeader
.SkyName
);
983 procedure mapCreateGrid ();
985 mapX0
: Integer = $3fffffff;
986 mapY0
: Integer = $3fffffff;
987 mapX1
: Integer = -$3fffffff;
988 mapY1
: Integer = -$3fffffff;
990 procedure fixMinMax (var panels
: TPanelArray
);
994 for idx
:= 0 to High(panels
) do
996 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
997 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
998 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
999 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
1000 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
1004 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
1008 tag
:= panelTypeToTag(tag
);
1009 for idx
:= High(panels
) downto 0 do
1011 panels
[idx
].tag
:= tag
;
1012 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1013 mapTree
.insertObject(panels
[idx
], tag
, true); // as static object
1024 fixMinMax(gRenderBackgrounds
);
1025 fixMinMax(gRenderForegrounds
);
1031 fixMinMax(gBlockMon
);
1033 if (mapX0
< 0) or (mapY0
< 0) then
1035 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1036 //raise Exception.Create('we are fucked');
1039 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1040 mapTree
:= TDynAABBTreeMap
.Create();
1042 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1043 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1044 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1045 addPanelsToGrid(gWater
, PANEL_WATER
);
1046 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1047 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1048 addPanelsToGrid(gSteps
, PANEL_STEP
);
1049 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1050 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1052 gMapGrid
.dumpStats();
1053 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1054 mapTree
.forEachLeaf(nil);
1057 function g_Map_Load(Res
: String): Boolean;
1059 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1060 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1063 MapReader
: TMapReader_1
;
1064 Header
: TMapHeaderRec_1
;
1065 _textures
: TTexturesRec1Array
;
1066 _texnummap
: array of Integer; // `_textures` -> `Textures`
1067 panels
: TPanelsRec1Array
;
1068 items
: TItemsRec1Array
;
1069 monsters
: TMonsterRec1Array
;
1070 areas
: TAreasRec1Array
;
1071 triggers
: TTriggersRec1Array
;
1072 a
, b
, c
, k
: Integer;
1074 AddTextures
: TAddTextureArray
;
1075 texture
: TTextureRec_1
;
1076 TriggersTable
: Array of record
1077 TexturePanel
: Integer;
1082 FileName
, mapResName
, s
, TexName
: String;
1085 ok
, isAnim
, trigRef
: Boolean;
1086 CurTex
, ntn
: Integer;
1095 gMapInfo
.Map
:= Res
;
1096 TriggersTable
:= nil;
1097 FillChar(texture
, SizeOf(texture
), 0);
1099 sfsGCDisable(); // temporary disable removing of temporary volumes
1102 FileName
:= g_ExtractWadName(Res
);
1103 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1104 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1106 WAD
:= TWADFile
.Create();
1107 if not WAD
.ReadFile(FileName
) then
1109 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1113 //k8: why loader ignores path here?
1114 mapResName
:= g_ExtractFileName(Res
);
1115 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1117 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1125 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1126 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1127 MapReader
:= TMapReader_1
.Create();
1129 if not MapReader
.LoadMap(Data
) then
1131 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1138 generateExternalResourcesList(MapReader
);
1139 // Çàãðóçêà òåêñòóð:
1140 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1141 _textures
:= MapReader
.GetTextures();
1144 // Äîáàâëåíèå òåêñòóð â Textures[]:
1145 if _textures
<> nil then
1147 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1148 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1149 SetLength(_texnummap
, length(_textures
));
1151 for a
:= 0 to High(_textures
) do
1154 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1155 for b
:= 1 to Length(s
) do
1161 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1162 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1163 // Àíèìèðîâàííàÿ òåêñòóðà:
1164 if ByteBool(_textures
[a
].Anim
) then
1166 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1169 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1170 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1173 else // Îáû÷íàÿ òåêñòóðà:
1174 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1177 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1178 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1181 _texnummap
[a
] := ntn
; // fix texture number
1182 g_Game_StepLoading();
1186 // Çàãðóçêà òðèããåðîâ:
1187 gTriggerClientID
:= 0;
1188 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1189 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1190 triggers
:= MapReader
.GetTriggers();
1192 // Çàãðóçêà ïàíåëåé:
1193 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1194 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1195 panels
:= MapReader
.GetPanels();
1197 // check texture numbers for panels
1198 for a
:= 0 to High(panels
) do
1200 if panels
[a
].TextureNum
> High(_textures
) then
1202 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1206 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1209 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1210 if triggers
<> nil then
1212 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1213 SetLength(TriggersTable
, Length(triggers
));
1214 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1216 for a
:= 0 to High(TriggersTable
) do
1218 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1219 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1221 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1222 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1224 TriggersTable
[a
].LiftPanel
:= -1;
1226 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1227 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1228 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1229 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1231 TriggersTable
[a
].DoorPanel
:= -1;
1233 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1234 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1236 TriggersTable
[a
].ShotPanel
:= -1;
1238 g_Game_StepLoading();
1243 if panels
<> nil then
1245 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1246 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1248 for a
:= 0 to High(panels
) do
1250 SetLength(AddTextures
, 0);
1253 if _textures
<> nil then
1255 texture
:= _textures
[panels
[a
].TextureNum
];
1263 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1264 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1266 if (TriggersTable
<> nil) and (_textures
<> nil) then
1267 for b
:= 0 to High(TriggersTable
) do
1268 if (TriggersTable
[b
].TexturePanel
= a
)
1269 or (TriggersTable
[b
].ShotPanel
= a
) then
1278 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1280 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1283 for c
:= Len
downto 1 do
1291 // Ñïåö-òåêñòóðû çàïðåùåíû:
1292 if g_Map_IsSpecialTexture(s
) then
1295 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1296 ok
:= g_Texture_NumNameFindStart(s
);
1298 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1299 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1302 k
:= NNF_NAME_BEFORE
;
1303 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1304 while ok
or (k
= NNF_NAME_BEFORE
) or
1305 (k
= NNF_NAME_EQUALS
) do
1307 k
:= g_Texture_NumNameFindNext(TexName
);
1309 if (k
= NNF_NAME_BEFORE
) or
1310 (k
= NNF_NAME_AFTER
) then
1312 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1313 if ByteBool(texture
.Anim
) then
1314 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1316 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1318 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1320 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1324 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1326 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1328 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1330 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1334 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1337 for c
:= 0 to High(Textures
) do
1338 if Textures
[c
].TextureName
= TexName
then
1340 SetLength(AddTextures
, Length(AddTextures
)+1);
1341 AddTextures
[High(AddTextures
)].Texture
:= c
;
1342 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1348 if k
= NNF_NAME_EQUALS
then
1350 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1351 SetLength(AddTextures
, Length(AddTextures
)+1);
1352 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1353 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1354 CurTex
:= High(AddTextures
);
1362 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1363 end; // if ok - ññûëàþòñÿ òðèããåðû
1367 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1368 SetLength(AddTextures
, 1);
1369 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1370 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1374 //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);
1376 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1377 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1379 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1380 if TriggersTable
<> nil then
1381 for b
:= 0 to High(TriggersTable
) do
1383 // Òðèããåð äâåðè/ëèôòà:
1384 if (TriggersTable
[b
].LiftPanel
= a
) or
1385 (TriggersTable
[b
].DoorPanel
= a
) then
1386 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1387 // Òðèããåð ñìåíû òåêñòóðû:
1388 if TriggersTable
[b
].TexturePanel
= a
then
1389 triggers
[b
].TexturePanel
:= PanelID
;
1390 // Òðèããåð "Òóðåëü":
1391 if TriggersTable
[b
].ShotPanel
= a
then
1392 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1395 g_Game_StepLoading();
1399 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1400 if (triggers
<> nil) and not gLoadGameMode
then
1402 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1403 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1404 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1405 for a
:= 0 to High(triggers
) do
1407 if triggers
[a
].TexturePanel
<> -1 then
1408 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1411 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1412 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1413 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1416 CreateTrigger(triggers
[a
], b
, c
);
1420 // Çàãðóçêà ïðåäìåòîâ:
1421 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1422 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1423 items
:= MapReader
.GetItems();
1425 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1426 if (items
<> nil) and not gLoadGameMode
then
1428 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1429 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1430 for a
:= 0 to High(items
) do
1431 CreateItem(Items
[a
]);
1434 // Çàãðóçêà îáëàñòåé:
1435 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1436 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1437 areas
:= MapReader
.GetAreas();
1439 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1440 if areas
<> nil then
1442 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1443 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1444 for a
:= 0 to High(areas
) do
1445 CreateArea(areas
[a
]);
1448 // Çàãðóçêà ìîíñòðîâ:
1449 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1450 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1451 monsters
:= MapReader
.GetMonsters();
1453 gTotalMonsters
:= 0;
1455 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1456 if (monsters
<> nil) and not gLoadGameMode
then
1458 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1459 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1460 for a
:= 0 to High(monsters
) do
1461 CreateMonster(monsters
[a
]);
1464 // Çàãðóçêà îïèñàíèÿ êàðòû:
1465 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1466 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1467 Header
:= MapReader
.GetMapHeader();
1473 Name
:= Header
.MapName
;
1474 Description
:= Header
.MapDescription
;
1475 Author
:= Header
.MapAuthor
;
1476 MusicName
:= Header
.MusicName
;
1477 SkyName
:= Header
.SkyName
;
1478 Height
:= Header
.Height
;
1479 Width
:= Header
.Width
;
1483 if gMapInfo
.SkyName
<> '' then
1485 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1486 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1487 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1489 if FileName
<> '' then
1490 FileName
:= GameDir
+'/wads/'+FileName
1493 FileName
:= g_ExtractWadName(Res
);
1496 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1497 if g_Texture_CreateWAD(BackID
, s
) then
1499 g_Game_SetupScreenSize();
1502 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1507 if gMapInfo
.MusicName
<> '' then
1509 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1510 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1511 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1513 if FileName
<> '' then
1514 FileName
:= GameDir
+'/wads/'+FileName
1517 FileName
:= g_ExtractWadName(Res
);
1520 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1521 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1524 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1527 // Îñòàëüíûå óñòàíâêè:
1535 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1536 if not gLoadGameMode
then
1539 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1545 TriggersTable
:= nil;
1548 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1549 if ok
and (not gLoadGameMode
) then
1551 gMusic
.SetByName(gMapInfo
.MusicName
);
1555 gMusic
.SetByName('');
1557 sfsGCEnable(); // enable releasing unused volumes
1560 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1563 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1567 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1570 MapReader
: TMapReader_1
;
1571 Header
: TMapHeaderRec_1
;
1576 FillChar(Result
, SizeOf(Result
), 0);
1577 FileName
:= g_ExtractWadName(Res
);
1579 WAD
:= TWADFile
.Create();
1580 if not WAD
.ReadFile(FileName
) then
1586 //k8: it ignores path again
1587 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1595 MapReader
:= TMapReader_1
.Create();
1597 if not MapReader
.LoadMap(Data
) then
1599 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1600 ZeroMemory(@Header
, SizeOf(Header
));
1601 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1602 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1606 Header
:= MapReader
.GetMapHeader();
1607 Result
.Name
:= Header
.MapName
;
1608 Result
.Description
:= Header
.MapDescription
;
1615 Result
.Author
:= Header
.MapAuthor
;
1616 Result
.Height
:= Header
.Height
;
1617 Result
.Width
:= Header
.Width
;
1620 function g_Map_GetMapsList(WADName
: string): SArray
;
1627 WAD
:= TWADFile
.Create();
1628 if not WAD
.ReadFile(WADName
) then
1633 ResList
:= WAD
.GetMapResources();
1634 if ResList
<> nil then
1636 for a
:= 0 to High(ResList
) do
1638 SetLength(Result
, Length(Result
)+1);
1639 Result
[High(Result
)] := ResList
[a
];
1645 function g_Map_Exist(Res
: string): Boolean;
1648 FileName
, mnn
: string;
1654 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1656 WAD
:= TWADFile
.Create
;
1657 if not WAD
.ReadFile(FileName
) then
1663 ResList
:= WAD
.GetMapResources();
1666 mnn
:= g_ExtractFileName(Res
);
1667 if ResList
<> nil then
1668 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1675 procedure g_Map_Free();
1679 procedure FreePanelArray(var panels
: TPanelArray
);
1684 if panels
<> nil then
1686 for i
:= 0 to High(panels
) do
1699 RespawnPoints
:= nil;
1700 if FlagPoints
[FLAG_RED
] <> nil then
1702 Dispose(FlagPoints
[FLAG_RED
]);
1703 FlagPoints
[FLAG_RED
] := nil;
1705 if FlagPoints
[FLAG_BLUE
] <> nil then
1707 Dispose(FlagPoints
[FLAG_BLUE
]);
1708 FlagPoints
[FLAG_BLUE
] := nil;
1710 //DOMFlagPoints := nil;
1714 if Textures
<> nil then
1716 for a
:= 0 to High(Textures
) do
1717 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1718 if Textures
[a
].Anim
then
1719 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1721 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1722 e_DeleteTexture(Textures
[a
].TextureID
);
1727 FreePanelArray(gWalls
);
1728 FreePanelArray(gRenderBackgrounds
);
1729 FreePanelArray(gRenderForegrounds
);
1730 FreePanelArray(gWater
);
1731 FreePanelArray(gAcid1
);
1732 FreePanelArray(gAcid2
);
1733 FreePanelArray(gSteps
);
1734 FreePanelArray(gLifts
);
1735 FreePanelArray(gBlockMon
);
1737 if BackID
<> DWORD(-1) then
1741 e_DeleteTexture(BackID
);
1742 BackID
:= DWORD(-1);
1745 g_Game_StopAllSounds(False);
1747 g_Sound_Delete(gMapInfo
.MusicName
);
1749 gMapInfo
.Name
:= '';
1750 gMapInfo
.Description
:= '';
1751 gMapInfo
.MusicName
:= '';
1752 gMapInfo
.Height
:= 0;
1753 gMapInfo
.Width
:= 0;
1761 procedure g_Map_Update();
1767 procedure UpdatePanelArray(var panels
: TPanelArray
);
1772 if panels
<> nil then
1773 for i
:= 0 to High(panels
) do
1778 UpdatePanelArray(gWalls
);
1779 UpdatePanelArray(gRenderBackgrounds
);
1780 UpdatePanelArray(gRenderForegrounds
);
1781 UpdatePanelArray(gWater
);
1782 UpdatePanelArray(gAcid1
);
1783 UpdatePanelArray(gAcid2
);
1784 UpdatePanelArray(gSteps
);
1786 if gGameSettings
.GameMode
= GM_CTF
then
1788 for a
:= FLAG_RED
to FLAG_BLUE
do
1789 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1792 if gFlags
[a
].Animation
<> nil then
1793 gFlags
[a
].Animation
.Update();
1795 m
:= g_Obj_Move(@Obj
, True, True);
1797 if gTime
mod (GAME_TICK
*2) <> 0 then
1800 // Ñîïðîòèâëåíèå âîçäóõà:
1801 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1803 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1804 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1807 gFlags
[a
].CaptureTime
:= 0;
1808 if a
= FLAG_RED
then
1809 s
:= _lc
[I_PLAYER_FLAG_RED
]
1811 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1812 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1814 if g_Game_IsNet
then
1815 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1822 // Èãðîê áåðåò ôëàã:
1823 if gPlayers
<> nil then
1825 j
:= Random(Length(gPlayers
)) - 1;
1827 for d
:= 0 to High(gPlayers
) do
1830 if j
> High(gPlayers
) then
1833 if gPlayers
[j
] <> nil then
1834 if gPlayers
[j
].Live
and
1835 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1837 if gPlayers
[j
].GetFlag(a
) then
1847 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1849 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1853 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1855 // alas, no visible set
1856 for idx
:= 0 to High(panels
) do
1858 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1865 PANEL_WALL
: DrawPanels(0, gWalls
);
1866 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1867 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1868 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1869 PANEL_WATER
: DrawPanels(3, gWater
);
1870 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1871 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1872 PANEL_STEP
: DrawPanels(6, gSteps
);
1878 gDrawPanelList
: TBinaryHeapObj
= nil;
1880 function dplLess (a
, b
: TObject
): Boolean;
1882 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1885 procedure dplClear ();
1887 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1890 procedure dplAddPanel (pan
: TPanel
);
1892 if pan
= nil then exit
;
1893 gDrawPanelList
.insert(pan
);
1897 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1901 function checker (obj
: TObject
; tag
: Integer): Boolean;
1905 result
:= false; // don't stop, ever
1906 //e_WriteLog(Format(' *body: tag:%d; ptag:%d; pantype=%d', [tag, ptag, PanelType]), MSG_NOTIFY);
1907 if (tag
<> ptag
) then exit
;
1909 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1910 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1911 //pan := (obj as TPanel);
1912 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1914 pan
:= (obj
as TPanel
);
1915 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1916 //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);
1920 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1925 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1927 // alas, no visible set
1928 for idx
:= 0 to High(panels
) do
1930 if not (drawDoors
xor panels
[idx
].Door
) then
1934 if (pan.Width < 1) or (pan.Height < 1) then continue;
1935 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1936 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1939 //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);
1946 //g_Map_DrawPanelsOld(PanelType); exit;
1947 //e_WriteLog('==================', MSG_NOTIFY);
1948 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1950 ptag
:= panelTypeToTag(PanelType
);
1952 if gdbg_map_use_accel_render
then
1954 if gdbg_map_use_tree_draw
then
1956 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, ptag
);
1960 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, ptag
);
1962 // sort and draw the list (we need to sort it, or rendering is fucked)
1963 while gDrawPanelList
.count
> 0 do
1965 (gDrawPanelList
.front() as TPanel
).Draw();
1966 gDrawPanelList
.popFront();
1971 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1973 PANEL_WALL
: DrawPanels(0, gWalls
);
1974 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1975 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1976 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1977 PANEL_WATER
: DrawPanels(3, gWater
);
1978 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1979 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1980 PANEL_STEP
: DrawPanels(6, gSteps
);
1984 //e_WriteLog('==================', MSG_NOTIFY);
1988 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1989 function checker (obj
: TObject
; tag
: Integer): Boolean;
1993 result
:= false; // don't stop, ever
1994 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1995 pan
:= (obj
as TPanel
);
1996 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2000 if gdbg_map_use_tree_draw
then
2002 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, GridTagWallDoor
);
2006 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, GridTagWallDoor
);
2011 procedure g_Map_DrawBack(dx
, dy
: Integer);
2013 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2014 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2016 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2019 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2020 PanelType
: Word; b1x3
: Boolean): Boolean;
2026 if WordBool(PanelType
and PANEL_WALL
) then
2027 if gWalls
<> nil then
2032 if gWalls
[a
].Enabled
and
2033 g_Collide(X
, Y
, Width
, Height
,
2034 gWalls
[a
].X
, gWalls
[a
].Y
,
2035 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2042 if WordBool(PanelType
and PANEL_WATER
) then
2043 if gWater
<> nil then
2048 if g_Collide(X
, Y
, Width
, Height
,
2049 gWater
[a
].X
, gWater
[a
].Y
,
2050 gWater
[a
].Width
, gWater
[a
].Height
) then
2057 if WordBool(PanelType
and PANEL_ACID1
) then
2058 if gAcid1
<> nil then
2063 if g_Collide(X
, Y
, Width
, Height
,
2064 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2065 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2072 if WordBool(PanelType
and PANEL_ACID2
) then
2073 if gAcid2
<> nil then
2078 if g_Collide(X
, Y
, Width
, Height
,
2079 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2080 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2087 if WordBool(PanelType
and PANEL_STEP
) then
2088 if gSteps
<> nil then
2093 if g_Collide(X
, Y
, Width
, Height
,
2094 gSteps
[a
].X
, gSteps
[a
].Y
,
2095 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2102 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2103 if gLifts
<> nil then
2108 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2109 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2110 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2111 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2112 g_Collide(X
, Y
, Width
, Height
,
2113 gLifts
[a
].X
, gLifts
[a
].Y
,
2114 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2121 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2122 if gBlockMon
<> nil then
2124 h
:= High(gBlockMon
);
2128 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2129 g_Collide(X
, Y
, Width
, Height
,
2130 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2131 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2139 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2143 function checkPanels (var panels
: TPanelArray
): Boolean;
2148 if panels
= nil then exit
;
2149 for a
:= 0 to High(panels
) do
2151 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2154 texid
:= panels
[a
].GetTextureID();
2161 texid
:= TEXTURE_NONE
;
2163 if not checkPanels(gWater
) then
2164 if not checkPanels(gAcid1
) then
2165 if not checkPanels(gAcid2
) then exit
;
2170 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2172 function checker (obj
: TObject
; tag
: Integer): Boolean;
2177 result
:= false; // don't stop, ever
2179 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2183 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2185 if not (obj
is TPanel
) then
2187 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2191 pan
:= (obj
as TPanel
);
2194 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2196 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2203 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2205 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2212 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2214 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2221 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2223 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2230 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2232 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2239 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2241 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2242 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2243 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2244 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2245 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2252 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2254 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2255 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2264 //TODO: detailed profile
2265 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2266 if gdbg_map_use_accel_coldet
then
2268 if gdbg_map_use_tree_coldet
then
2270 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWallDoor
or GridTagWater
or GridTagAcid1
or GridTagAcid2
or GridTagStep
or GridTagLift
or GridTagBlockMon
)) <> nil);
2271 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2273 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2274 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2279 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWallDoor
or GridTagWater
or GridTagAcid1
or GridTagAcid2
or GridTagStep
or GridTagLift
or GridTagBlockMon
));
2284 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2286 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2290 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2292 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2295 // slightly different from the old code, but meh...
2296 function checker (obj
: TObject
; tag
: Integer): Boolean;
2301 result
:= false; // don't stop, ever
2302 if (tag
<> GridTagWater
) and (tag
<> GridTagAcid1
) and (tag
<> GridTagAcid2
) then exit
;
2303 pan
:= (obj
as TPanel
);
2306 if (tag
= GridTagWater
) then
2308 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2310 result
:= true; // water has highest priority, so stop right here
2311 texid
:= gWater
[a
].GetTextureID();
2316 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2318 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2321 texid
:= gAcid1
[a
].GetTextureID();
2326 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2328 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2331 texid
:= gAcid2
[a
].GetTextureID();
2338 //TODO: detailed profile?
2339 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2340 if gdbg_map_use_accel_coldet
then
2342 texid
:= TEXTURE_NONE
;
2343 if gdbg_map_use_tree_coldet
then
2345 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2349 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2355 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2357 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2360 procedure g_Map_EnableWall(ID
: DWORD
);
2365 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2367 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2371 procedure g_Map_DisableWall(ID
: DWORD
);
2376 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2378 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2382 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2387 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2390 tp
:= gRenderForegrounds
[ID
];
2392 tp
:= gRenderBackgrounds
[ID
];
2405 tp
.NextTexture(AnimLoop
);
2406 if g_Game_IsServer
and g_Game_IsNet
then
2407 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2410 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2412 if gLifts
[ID
].LiftType
= t
then
2419 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2421 if LiftType
= 0 then
2422 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2423 else if LiftType
= 1 then
2424 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2425 else if LiftType
= 2 then
2426 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2427 else if LiftType
= 3 then
2428 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2430 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2434 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2437 PointsArray
: Array of TRespawnPoint
;
2440 SetLength(PointsArray
, 0);
2442 if RespawnPoints
= nil then
2445 for a
:= 0 to High(RespawnPoints
) do
2446 if RespawnPoints
[a
].PointType
= PointType
then
2448 SetLength(PointsArray
, Length(PointsArray
)+1);
2449 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2452 if PointsArray
= nil then
2455 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2459 function g_Map_GetPointCount(PointType
: Byte): Word;
2465 if RespawnPoints
= nil then
2468 for a
:= 0 to High(RespawnPoints
) do
2469 if RespawnPoints
[a
].PointType
= PointType
then
2470 Result
:= Result
+ 1;
2473 function g_Map_HaveFlagPoints(): Boolean;
2475 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2478 procedure g_Map_ResetFlag(Flag
: Byte);
2480 with gFlags
[Flag
] do
2486 Direction
:= D_LEFT
;
2487 State
:= FLAG_STATE_NONE
;
2488 if FlagPoints
[Flag
] <> nil then
2490 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2491 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2492 Direction
:= FlagPoints
[Flag
]^.Direction
;
2493 State
:= FLAG_STATE_NORMAL
;
2499 procedure g_Map_DrawFlags();
2502 Mirror
: TMirrorType
;
2504 if gGameSettings
.GameMode
<> GM_CTF
then
2507 for i
:= FLAG_RED
to FLAG_BLUE
do
2509 if State
<> FLAG_STATE_CAPTURED
then
2511 if State
= FLAG_STATE_NONE
then
2514 if Direction
= D_LEFT
then
2516 Mirror
:= M_HORIZONTAL
;
2525 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2527 if g_debug_Frames
then
2529 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2531 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2532 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2538 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2545 procedure SavePanelArray(var panels
: TPanelArray
);
2547 PAMem
: TBinMemoryWriter
;
2550 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2551 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2554 while i
< Length(panels
) do
2556 if panels
[i
].SaveIt
then
2560 // Ñîõðàíÿåì ïàíåëü:
2561 panels
[i
].SaveState(PAMem
);
2566 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2567 PAMem
.SaveToMemory(Mem
);
2571 procedure SaveFlag(flag
: PFlag
);
2574 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2576 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2577 Mem
.WriteByte(flag
^.RespawnType
);
2579 Mem
.WriteByte(flag
^.State
);
2580 // Íàïðàâëåíèå ôëàãà:
2581 if flag
^.Direction
= D_LEFT
then
2587 Obj_SaveState(@flag
^.Obj
, Mem
);
2591 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2593 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2594 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2595 SavePanelArray(gWalls
);
2596 // Ñîõðàíÿåì ïàíåëè ôîíà:
2597 SavePanelArray(gRenderBackgrounds
);
2598 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2599 SavePanelArray(gRenderForegrounds
);
2600 // Ñîõðàíÿåì ïàíåëè âîäû:
2601 SavePanelArray(gWater
);
2602 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2603 SavePanelArray(gAcid1
);
2604 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2605 SavePanelArray(gAcid2
);
2606 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2607 SavePanelArray(gSteps
);
2608 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2609 SavePanelArray(gLifts
);
2612 ///// Ñîõðàíÿåì ìóçûêó: /////
2613 // Ñèãíàòóðà ìóçûêè:
2614 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2617 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2618 if gMusic
.NoMusic
then
2622 Mem
.WriteString(str
, 64);
2623 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2624 dw
:= gMusic
.GetPosition();
2626 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2627 boo
:= gMusic
.SpecPause
;
2628 Mem
.WriteBoolean(boo
);
2631 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2632 Mem
.WriteInt(gTotalMonsters
);
2635 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2636 if gGameSettings
.GameMode
= GM_CTF
then
2638 // Ôëàã Êðàñíîé êîìàíäû:
2639 SaveFlag(@gFlags
[FLAG_RED
]);
2640 // Ôëàã Ñèíåé êîìàíäû:
2641 SaveFlag(@gFlags
[FLAG_BLUE
]);
2645 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2646 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2648 // Î÷êè Êðàñíîé êîìàíäû:
2649 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2650 // Î÷êè Ñèíåé êîìàíäû:
2651 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2656 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2663 procedure LoadPanelArray(var panels
: TPanelArray
);
2665 PAMem
: TBinMemoryReader
;
2668 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2669 PAMem
:= TBinMemoryReader
.Create();
2670 PAMem
.LoadFromMemory(Mem
);
2672 for i
:= 0 to Length(panels
)-1 do
2673 if panels
[i
].SaveIt
then
2679 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2681 // Çàãðóæàåì ïàíåëü:
2682 panels
[i
].LoadState(PAMem
);
2685 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2689 procedure LoadFlag(flag
: PFlag
);
2693 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2695 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2697 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2698 Mem
.ReadByte(flag
^.RespawnType
);
2700 Mem
.ReadByte(flag
^.State
);
2701 // Íàïðàâëåíèå ôëàãà:
2704 flag
^.Direction
:= D_LEFT
2706 flag
^.Direction
:= D_RIGHT
;
2708 Obj_LoadState(@flag
^.Obj
, Mem
);
2715 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2716 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2717 LoadPanelArray(gWalls
);
2718 // Çàãðóæàåì ïàíåëè ôîíà:
2719 LoadPanelArray(gRenderBackgrounds
);
2720 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2721 LoadPanelArray(gRenderForegrounds
);
2722 // Çàãðóæàåì ïàíåëè âîäû:
2723 LoadPanelArray(gWater
);
2724 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2725 LoadPanelArray(gAcid1
);
2726 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2727 LoadPanelArray(gAcid2
);
2728 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2729 LoadPanelArray(gSteps
);
2730 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2731 LoadPanelArray(gLifts
);
2734 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2738 ///// Çàãðóæàåì ìóçûêó: /////
2739 // Ñèãíàòóðà ìóçûêè:
2741 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2743 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2746 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2747 Mem
.ReadString(str
);
2748 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2750 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2751 Mem
.ReadBoolean(boo
);
2752 // Çàïóñêàåì ýòó ìóçûêó:
2753 gMusic
.SetByName(str
);
2754 gMusic
.SpecPause
:= boo
;
2757 gMusic
.SetPosition(dw
);
2760 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2761 Mem
.ReadInt(gTotalMonsters
);
2764 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2765 if gGameSettings
.GameMode
= GM_CTF
then
2767 // Ôëàã Êðàñíîé êîìàíäû:
2768 LoadFlag(@gFlags
[FLAG_RED
]);
2769 // Ôëàã Ñèíåé êîìàíäû:
2770 LoadFlag(@gFlags
[FLAG_BLUE
]);
2774 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2775 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2777 // Î÷êè Êðàñíîé êîìàíäû:
2778 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2779 // Î÷êè Ñèíåé êîìàíäû:
2780 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2785 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2790 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2791 Arr
:= PanelByID
[PanelID
].PWhere
^;
2792 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2793 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);