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 (pan.Width < 3) or (pan.Height < 3) then exit;
212 //aabb := AABB2D.Create(pan.X, pan.Y, pan.X+pan.Width-2, pan.Y+pan.Height-2);
213 if not aabb
.valid
then raise Exception
.Create('wutafuuuuuuu?!');
214 result
:= aabb
.valid
;
218 PanelById
: array of TPanelID
;
219 Textures
: TLevelTextureArray
;
220 RespawnPoints
: Array of TRespawnPoint
;
221 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
222 //DOMFlagPoints: Array of TFlagPoint;
223 gMapGrid
: TBodyGrid
= nil;
224 mapTree
: TDynAABBTree
= nil;
227 procedure g_Map_ProfilersBegin ();
229 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
230 profMapCollision
.mainBegin(g_profile_collision
);
232 if g_profile_collision
then
234 profMapCollision
.sectionBegin('wall coldet');
235 profMapCollision
.sectionEnd();
236 profMapCollision
.sectionBegin('liquid coldet');
237 profMapCollision
.sectionEnd();
241 procedure g_Map_ProfilersEnd ();
243 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
247 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
249 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
250 (Texture
= TEXTURE_NAME_ACID1
) or
251 (Texture
= TEXTURE_NAME_ACID2
);
254 procedure CreateDoorMap();
256 PanelArray
: Array of record
262 a
, b
, c
, m
, i
, len
: Integer;
270 SetLength(PanelArray
, len
);
272 for a
:= 0 to High(gWalls
) do
273 if gWalls
[a
].Door
then
275 PanelArray
[i
].X
:= gWalls
[a
].X
;
276 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
277 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
278 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
279 PanelArray
[i
].Active
:= True;
280 PanelArray
[i
].PanelID
:= a
;
286 SetLength(PanelArray
, len
);
297 SetLength(gDoorMap
, 0);
299 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
302 if PanelArray
[a
].Active
then
304 PanelArray
[a
].Active
:= False;
305 m
:= Length(gDoorMap
);
306 SetLength(gDoorMap
, m
+1);
307 SetLength(gDoorMap
[m
], 1);
308 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
316 if PanelArray
[b
].Active
then
317 for c
:= 0 to High(gDoorMap
[m
]) do
318 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
319 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
320 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
321 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
322 gWalls
[gDoorMap
[m
, c
]].X
,
323 gWalls
[gDoorMap
[m
, c
]].Y
,
324 gWalls
[gDoorMap
[m
, c
]].Width
,
325 gWalls
[gDoorMap
[m
, c
]].Height
) then
327 PanelArray
[b
].Active
:= False;
328 SetLength(gDoorMap
[m
],
329 Length(gDoorMap
[m
])+1);
330 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
336 g_Game_StepLoading();
342 procedure CreateLiftMap();
344 PanelArray
: Array of record
349 a
, b
, c
, len
, i
, j
: Integer;
355 len
:= Length(gLifts
);
356 SetLength(PanelArray
, len
);
358 for a
:= 0 to len
-1 do
360 PanelArray
[a
].X
:= gLifts
[a
].X
;
361 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
362 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
363 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
364 PanelArray
[a
].Active
:= True;
367 SetLength(gLiftMap
, len
);
370 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
372 for a
:= 0 to len
-1 do
373 if PanelArray
[a
].Active
then
375 PanelArray
[a
].Active
:= False;
376 SetLength(gLiftMap
[i
], 32);
384 for b
:= 0 to len
-1 do
385 if PanelArray
[b
].Active
then
387 if g_CollideAround(PanelArray
[b
].X
,
390 PanelArray
[b
].Height
,
391 PanelArray
[gLiftMap
[i
, c
]].X
,
392 PanelArray
[gLiftMap
[i
, c
]].Y
,
393 PanelArray
[gLiftMap
[i
, c
]].Width
,
394 PanelArray
[gLiftMap
[i
, c
]].Height
) then
396 PanelArray
[b
].Active
:= False;
398 if j
> High(gLiftMap
[i
]) then
399 SetLength(gLiftMap
[i
],
400 Length(gLiftMap
[i
])+32);
409 SetLength(gLiftMap
[i
], j
+1);
412 g_Game_StepLoading();
415 SetLength(gLiftMap
, i
);
420 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
421 CurTex
: Integer; sav
: Boolean): Integer;
424 panels
: ^TPanelArray
;
428 case PanelRec
.PanelType
of
429 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
432 panels
:= @gRenderBackgrounds
;
434 panels
:= @gRenderForegrounds
;
443 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
446 panels
:= @gBlockMon
;
451 len
:= Length(panels
^);
452 SetLength(panels
^, len
+ 1);
454 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
455 panels
^[len
].ArrIdx
:= len
;
456 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
458 panels
^[len
].SaveIt
:= True;
462 len
:= Length(PanelByID
);
463 SetLength(PanelByID
, len
+ 1);
464 PanelByID
[len
].PWhere
:= panels
;
465 PanelByID
[len
].PArrID
:= Result
;
468 function CreateNullTexture(RecName
: String): Integer;
470 SetLength(Textures
, Length(Textures
)+1);
471 result
:= High(Textures
);
473 with Textures
[High(Textures
)] do
475 TextureName
:= RecName
;
479 TextureID
:= TEXTURE_NONE
;
483 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
486 TextureData
: Pointer;
487 WADName
, txname
: String;
488 a
, ResLength
: Integer;
492 if Textures
<> nil then
493 for a
:= 0 to High(Textures
) do
494 if Textures
[a
].TextureName
= RecName
then
495 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
500 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
501 if (RecName
= TEXTURE_NAME_WATER
) or
502 (RecName
= TEXTURE_NAME_ACID1
) or
503 (RecName
= TEXTURE_NAME_ACID2
) then
505 SetLength(Textures
, Length(Textures
)+1);
507 with Textures
[High(Textures
)] do
509 TextureName
:= RecName
;
511 if TextureName
= TEXTURE_NAME_WATER
then
512 TextureID
:= TEXTURE_SPECIAL_WATER
514 if TextureName
= TEXTURE_NAME_ACID1
then
515 TextureID
:= TEXTURE_SPECIAL_ACID1
517 if TextureName
= TEXTURE_NAME_ACID2
then
518 TextureID
:= TEXTURE_SPECIAL_ACID2
;
523 result
:= High(Textures
);
527 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
528 WADName
:= g_ExtractWadName(RecName
);
530 WAD
:= TWADFile
.Create();
532 if WADName
<> '' then
533 WADName
:= GameDir
+'/wads/'+WADName
537 WAD
.ReadFile(WADName
);
541 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
543 FreeMem(TextureData);
544 RecName := 'COMMON\ALIEN';
548 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
550 SetLength(Textures
, Length(Textures
)+1);
551 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
553 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
554 @Textures
[High(Textures
)].Width
,
555 @Textures
[High(Textures
)].Height
);
556 FreeMem(TextureData
);
557 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
558 Textures
[High(Textures
)].Anim
:= False;
560 result
:= High(Textures
);
562 else // Íåò òàêîãî ðåóñðñà â WAD'å
564 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
567 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
568 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
575 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
578 TextureWAD
: PChar = nil;
579 TextData
: Pointer = nil;
580 TextureData
: Pointer = nil;
584 TextureResource
: String;
585 _width
, _height
, _framecount
, _speed
: Integer;
586 _backanimation
: Boolean;
588 ia
: TDynImageDataArray
= nil;
589 f
, c
, frdelay
, frloop
: Integer;
593 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
595 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
596 WADName
:= g_ExtractWadName(RecName
);
598 WAD
:= TWADFile
.Create();
600 if WADName
<> '' then
601 WADName
:= GameDir
+'/wads/'+WADName
605 WAD
.ReadFile(WADName
);
607 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
611 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
612 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
618 if WADName = Map then
620 //FreeMem(TextureWAD);
621 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
627 if ResLength
< 6 then
629 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
633 // ýòî ïòèöà? ýòî ñàìîë¸ò?
634 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
635 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
637 // íåò, ýòî ñóïåðìåí!
638 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
640 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
644 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
645 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
647 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
651 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
653 TextureResource
:= cfg
.ReadStr('', 'resource', '');
654 if TextureResource
= '' then
656 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
660 _width
:= cfg
.ReadInt('', 'framewidth', 0);
661 _height
:= cfg
.ReadInt('', 'frameheight', 0);
662 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
663 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
664 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
669 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
670 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
672 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
679 SetLength(Textures
, Length(Textures
)+1);
680 with Textures
[High(Textures
)] do
682 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
683 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
685 TextureName
:= RecName
;
689 FramesCount
:= _framecount
;
691 result
:= High(Textures
);
695 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
701 // try animated image
703 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
704 if length(imgfmt) = 0 then
706 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
710 GlobalMetadata
.ClearMetaItems();
711 GlobalMetadata
.ClearMetaItemsForSaving();
712 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
714 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
717 if length(ia
) = 0 then
719 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
726 _width
:= ia
[0].width
;
727 _height
:= ia
[0].height
;
728 _framecount
:= length(ia
);
730 _backanimation
:= false;
733 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
735 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
737 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
739 if f
< 0 then f
:= 0;
742 if c
< 13 then c
:= 0 else c
:= 1;
744 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
749 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
751 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
753 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
755 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
759 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
760 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
761 f
:= ord(_backanimation
);
762 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
);
764 SetLength(Textures
, Length(Textures
)+1);
765 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
766 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
768 Textures
[High(Textures
)].TextureName
:= RecName
;
769 Textures
[High(Textures
)].Width
:= _width
;
770 Textures
[High(Textures
)].Height
:= _height
;
771 Textures
[High(Textures
)].Anim
:= True;
772 Textures
[High(Textures
)].FramesCount
:= length(ia
);
773 Textures
[High(Textures
)].Speed
:= _speed
;
774 result
:= High(Textures
);
775 //writeln(' CREATED!');
779 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
783 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
786 if TextureWAD
<> nil then FreeMem(TextureWAD
);
787 if TextData
<> nil then FreeMem(TextData
);
788 if TextureData
<> nil then FreeMem(TextureData
);
792 procedure CreateItem(Item
: TItemRec_1
);
794 if g_Game_IsClient
then Exit
;
796 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
797 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
800 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
801 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
804 procedure CreateArea(Area
: TAreaRec_1
);
809 case Area
.AreaType
of
810 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
811 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
813 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
814 with RespawnPoints
[High(RespawnPoints
)] do
818 Direction
:= TDirection(Area
.Direction
);
820 case Area
.AreaType
of
821 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
822 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
823 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
824 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
825 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
830 AREA_REDFLAG
, AREA_BLUEFLAG
:
832 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
834 if FlagPoints
[a
] <> nil then Exit
;
838 with FlagPoints
[a
]^ do
840 X
:= Area
.X
-FLAGRECT
.X
;
841 Y
:= Area
.Y
-FLAGRECT
.Y
;
842 Direction
:= TDirection(Area
.Direction
);
848 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
849 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
852 Animation
:= TAnimation
.Create(id
, True, 8);
853 Obj
.Rect
:= FLAGRECT
;
861 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
862 with DOMFlagPoints[High(DOMFlagPoints)] do
866 Direction := TDirection(Area.Direction);
869 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
874 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
878 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
884 Width
:= Trigger
.Width
;
885 Height
:= Trigger
.Height
;
886 Enabled
:= ByteBool(Trigger
.Enabled
);
887 TexturePanel
:= Trigger
.TexturePanel
;
888 TexturePanelType
:= fTexturePanel1Type
;
889 ShotPanelType
:= fTexturePanel2Type
;
890 TriggerType
:= Trigger
.TriggerType
;
891 ActivateType
:= Trigger
.ActivateType
;
892 Keys
:= Trigger
.Keys
;
893 Data
.Default
:= Trigger
.DATA
;
896 g_Triggers_Create(_trigger
);
899 procedure CreateMonster(monster
: TMonsterRec_1
);
903 if g_Game_IsClient
then Exit
;
905 if (gGameSettings
.GameType
= GT_SINGLE
)
906 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
908 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
909 TDirection(monster
.Direction
));
911 if gTriggers
<> nil then
912 for a
:= 0 to High(gTriggers
) do
913 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
914 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
915 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
916 gMonsters
[i
].AddTrigger(a
);
918 if monster
.MonsterType
<> MONSTER_BARREL
then
923 procedure g_Map_ReAdd_DieTriggers();
927 if g_Game_IsClient
then Exit
;
929 for i
:= 0 to High(gMonsters
) do
930 if gMonsters
[i
] <> nil then
932 gMonsters
[i
].ClearTriggers();
934 for a
:= 0 to High(gTriggers
) do
935 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
936 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
937 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
938 gMonsters
[i
].AddTrigger(a
);
942 function extractWadName(resourceName
: string): string;
946 posN
:= Pos(':', resourceName
);
948 Result
:= Copy(resourceName
, 0, posN
-1)
953 procedure addResToExternalResList(res
: string);
955 res
:= extractWadName(res
);
956 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
957 gExternalResources
.Add(res
);
960 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
962 textures
: TTexturesRec1Array
;
963 mapHeader
: TMapHeaderRec_1
;
965 resFile
: String = '';
967 if gExternalResources
= nil then
968 gExternalResources
:= TStringList
.Create
;
970 gExternalResources
.Clear
;
971 textures
:= mapReader
.GetTextures();
972 for i
:= 0 to High(textures
) do
974 addResToExternalResList(resFile
);
979 mapHeader
:= mapReader
.GetMapHeader
;
981 addResToExternalResList(mapHeader
.MusicName
);
982 addResToExternalResList(mapHeader
.SkyName
);
985 procedure mapCreateGrid ();
987 mapX0
: Integer = $3fffffff;
988 mapY0
: Integer = $3fffffff;
989 mapX1
: Integer = -$3fffffff;
990 mapY1
: Integer = -$3fffffff;
992 procedure fixMinMax (var panels
: TPanelArray
);
996 for idx
:= 0 to High(panels
) do
998 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
999 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
1000 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
1001 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
1002 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
1006 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
1010 tag
:= panelTypeToTag(tag
);
1011 for idx
:= High(panels
) downto 0 do
1013 panels
[idx
].tag
:= tag
;
1014 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1015 mapTree
.insertObject(panels
[idx
], tag
, true); // as static object
1026 fixMinMax(gRenderBackgrounds
);
1027 fixMinMax(gRenderForegrounds
);
1033 fixMinMax(gBlockMon
);
1035 if (mapX0
< 0) or (mapY0
< 0) then
1037 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1038 //raise Exception.Create('we are fucked');
1041 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1042 mapTree
:= TDynAABBTreeMap
.Create();
1044 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1045 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1046 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1047 addPanelsToGrid(gWater
, PANEL_WATER
);
1048 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1049 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1050 addPanelsToGrid(gSteps
, PANEL_STEP
);
1051 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1052 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1054 gMapGrid
.dumpStats();
1055 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1056 mapTree
.forEachLeaf(nil);
1059 function g_Map_Load(Res
: String): Boolean;
1061 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1062 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1065 MapReader
: TMapReader_1
;
1066 Header
: TMapHeaderRec_1
;
1067 _textures
: TTexturesRec1Array
;
1068 _texnummap
: array of Integer; // `_textures` -> `Textures`
1069 panels
: TPanelsRec1Array
;
1070 items
: TItemsRec1Array
;
1071 monsters
: TMonsterRec1Array
;
1072 areas
: TAreasRec1Array
;
1073 triggers
: TTriggersRec1Array
;
1074 a
, b
, c
, k
: Integer;
1076 AddTextures
: TAddTextureArray
;
1077 texture
: TTextureRec_1
;
1078 TriggersTable
: Array of record
1079 TexturePanel
: Integer;
1084 FileName
, mapResName
, s
, TexName
: String;
1087 ok
, isAnim
, trigRef
: Boolean;
1088 CurTex
, ntn
: Integer;
1097 gMapInfo
.Map
:= Res
;
1098 TriggersTable
:= nil;
1099 FillChar(texture
, SizeOf(texture
), 0);
1101 sfsGCDisable(); // temporary disable removing of temporary volumes
1104 FileName
:= g_ExtractWadName(Res
);
1105 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1106 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1108 WAD
:= TWADFile
.Create();
1109 if not WAD
.ReadFile(FileName
) then
1111 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1115 //k8: why loader ignores path here?
1116 mapResName
:= g_ExtractFileName(Res
);
1117 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1119 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1127 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1128 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1129 MapReader
:= TMapReader_1
.Create();
1131 if not MapReader
.LoadMap(Data
) then
1133 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1140 generateExternalResourcesList(MapReader
);
1141 // Çàãðóçêà òåêñòóð:
1142 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1143 _textures
:= MapReader
.GetTextures();
1146 // Äîáàâëåíèå òåêñòóð â Textures[]:
1147 if _textures
<> nil then
1149 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1150 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1151 SetLength(_texnummap
, length(_textures
));
1153 for a
:= 0 to High(_textures
) do
1156 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1157 for b
:= 1 to Length(s
) do
1163 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1164 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1165 // Àíèìèðîâàííàÿ òåêñòóðà:
1166 if ByteBool(_textures
[a
].Anim
) then
1168 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1171 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1172 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1175 else // Îáû÷íàÿ òåêñòóðà:
1176 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1179 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1180 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1183 _texnummap
[a
] := ntn
; // fix texture number
1184 g_Game_StepLoading();
1188 // Çàãðóçêà òðèããåðîâ:
1189 gTriggerClientID
:= 0;
1190 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1191 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1192 triggers
:= MapReader
.GetTriggers();
1194 // Çàãðóçêà ïàíåëåé:
1195 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1196 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1197 panels
:= MapReader
.GetPanels();
1199 // check texture numbers for panels
1200 for a
:= 0 to High(panels
) do
1202 if panels
[a
].TextureNum
> High(_textures
) then
1204 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1208 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1211 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1212 if triggers
<> nil then
1214 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1215 SetLength(TriggersTable
, Length(triggers
));
1216 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1218 for a
:= 0 to High(TriggersTable
) do
1220 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1221 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1223 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1224 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1226 TriggersTable
[a
].LiftPanel
:= -1;
1228 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1229 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1230 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1231 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1233 TriggersTable
[a
].DoorPanel
:= -1;
1235 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1236 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1238 TriggersTable
[a
].ShotPanel
:= -1;
1240 g_Game_StepLoading();
1245 if panels
<> nil then
1247 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1248 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1250 for a
:= 0 to High(panels
) do
1252 SetLength(AddTextures
, 0);
1255 if _textures
<> nil then
1257 texture
:= _textures
[panels
[a
].TextureNum
];
1265 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1266 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1268 if (TriggersTable
<> nil) and (_textures
<> nil) then
1269 for b
:= 0 to High(TriggersTable
) do
1270 if (TriggersTable
[b
].TexturePanel
= a
)
1271 or (TriggersTable
[b
].ShotPanel
= a
) then
1280 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1282 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1285 for c
:= Len
downto 1 do
1293 // Ñïåö-òåêñòóðû çàïðåùåíû:
1294 if g_Map_IsSpecialTexture(s
) then
1297 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1298 ok
:= g_Texture_NumNameFindStart(s
);
1300 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1301 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1304 k
:= NNF_NAME_BEFORE
;
1305 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1306 while ok
or (k
= NNF_NAME_BEFORE
) or
1307 (k
= NNF_NAME_EQUALS
) do
1309 k
:= g_Texture_NumNameFindNext(TexName
);
1311 if (k
= NNF_NAME_BEFORE
) or
1312 (k
= NNF_NAME_AFTER
) then
1314 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1315 if ByteBool(texture
.Anim
) then
1316 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1318 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1320 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1322 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1326 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1328 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1330 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1332 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1336 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1339 for c
:= 0 to High(Textures
) do
1340 if Textures
[c
].TextureName
= TexName
then
1342 SetLength(AddTextures
, Length(AddTextures
)+1);
1343 AddTextures
[High(AddTextures
)].Texture
:= c
;
1344 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1350 if k
= NNF_NAME_EQUALS
then
1352 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1353 SetLength(AddTextures
, Length(AddTextures
)+1);
1354 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1355 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1356 CurTex
:= High(AddTextures
);
1364 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1365 end; // if ok - ññûëàþòñÿ òðèããåðû
1369 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1370 SetLength(AddTextures
, 1);
1371 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1372 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1376 //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);
1378 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1379 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1381 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1382 if TriggersTable
<> nil then
1383 for b
:= 0 to High(TriggersTable
) do
1385 // Òðèããåð äâåðè/ëèôòà:
1386 if (TriggersTable
[b
].LiftPanel
= a
) or
1387 (TriggersTable
[b
].DoorPanel
= a
) then
1388 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1389 // Òðèããåð ñìåíû òåêñòóðû:
1390 if TriggersTable
[b
].TexturePanel
= a
then
1391 triggers
[b
].TexturePanel
:= PanelID
;
1392 // Òðèããåð "Òóðåëü":
1393 if TriggersTable
[b
].ShotPanel
= a
then
1394 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1397 g_Game_StepLoading();
1401 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1402 if (triggers
<> nil) and not gLoadGameMode
then
1404 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1405 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1406 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1407 for a
:= 0 to High(triggers
) do
1409 if triggers
[a
].TexturePanel
<> -1 then
1410 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1413 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1414 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1415 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1418 CreateTrigger(triggers
[a
], b
, c
);
1422 // Çàãðóçêà ïðåäìåòîâ:
1423 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1424 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1425 items
:= MapReader
.GetItems();
1427 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1428 if (items
<> nil) and not gLoadGameMode
then
1430 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1431 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1432 for a
:= 0 to High(items
) do
1433 CreateItem(Items
[a
]);
1436 // Çàãðóçêà îáëàñòåé:
1437 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1438 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1439 areas
:= MapReader
.GetAreas();
1441 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1442 if areas
<> nil then
1444 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1445 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1446 for a
:= 0 to High(areas
) do
1447 CreateArea(areas
[a
]);
1450 // Çàãðóçêà ìîíñòðîâ:
1451 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1452 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1453 monsters
:= MapReader
.GetMonsters();
1455 gTotalMonsters
:= 0;
1457 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1458 if (monsters
<> nil) and not gLoadGameMode
then
1460 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1461 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1462 for a
:= 0 to High(monsters
) do
1463 CreateMonster(monsters
[a
]);
1466 // Çàãðóçêà îïèñàíèÿ êàðòû:
1467 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1468 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1469 Header
:= MapReader
.GetMapHeader();
1475 Name
:= Header
.MapName
;
1476 Description
:= Header
.MapDescription
;
1477 Author
:= Header
.MapAuthor
;
1478 MusicName
:= Header
.MusicName
;
1479 SkyName
:= Header
.SkyName
;
1480 Height
:= Header
.Height
;
1481 Width
:= Header
.Width
;
1485 if gMapInfo
.SkyName
<> '' then
1487 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1488 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1489 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1491 if FileName
<> '' then
1492 FileName
:= GameDir
+'/wads/'+FileName
1495 FileName
:= g_ExtractWadName(Res
);
1498 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1499 if g_Texture_CreateWAD(BackID
, s
) then
1501 g_Game_SetupScreenSize();
1504 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1509 if gMapInfo
.MusicName
<> '' then
1511 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1512 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1513 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1515 if FileName
<> '' then
1516 FileName
:= GameDir
+'/wads/'+FileName
1519 FileName
:= g_ExtractWadName(Res
);
1522 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1523 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1526 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1529 // Îñòàëüíûå óñòàíâêè:
1537 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1538 if not gLoadGameMode
then
1541 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1547 TriggersTable
:= nil;
1550 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1551 if ok
and (not gLoadGameMode
) then
1553 gMusic
.SetByName(gMapInfo
.MusicName
);
1557 gMusic
.SetByName('');
1559 sfsGCEnable(); // enable releasing unused volumes
1562 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1565 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1569 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1572 MapReader
: TMapReader_1
;
1573 Header
: TMapHeaderRec_1
;
1578 FillChar(Result
, SizeOf(Result
), 0);
1579 FileName
:= g_ExtractWadName(Res
);
1581 WAD
:= TWADFile
.Create();
1582 if not WAD
.ReadFile(FileName
) then
1588 //k8: it ignores path again
1589 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1597 MapReader
:= TMapReader_1
.Create();
1599 if not MapReader
.LoadMap(Data
) then
1601 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1602 ZeroMemory(@Header
, SizeOf(Header
));
1603 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1604 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1608 Header
:= MapReader
.GetMapHeader();
1609 Result
.Name
:= Header
.MapName
;
1610 Result
.Description
:= Header
.MapDescription
;
1617 Result
.Author
:= Header
.MapAuthor
;
1618 Result
.Height
:= Header
.Height
;
1619 Result
.Width
:= Header
.Width
;
1622 function g_Map_GetMapsList(WADName
: string): SArray
;
1629 WAD
:= TWADFile
.Create();
1630 if not WAD
.ReadFile(WADName
) then
1635 ResList
:= WAD
.GetMapResources();
1636 if ResList
<> nil then
1638 for a
:= 0 to High(ResList
) do
1640 SetLength(Result
, Length(Result
)+1);
1641 Result
[High(Result
)] := ResList
[a
];
1647 function g_Map_Exist(Res
: string): Boolean;
1650 FileName
, mnn
: string;
1656 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1658 WAD
:= TWADFile
.Create
;
1659 if not WAD
.ReadFile(FileName
) then
1665 ResList
:= WAD
.GetMapResources();
1668 mnn
:= g_ExtractFileName(Res
);
1669 if ResList
<> nil then
1670 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1677 procedure g_Map_Free();
1681 procedure FreePanelArray(var panels
: TPanelArray
);
1686 if panels
<> nil then
1688 for i
:= 0 to High(panels
) do
1701 RespawnPoints
:= nil;
1702 if FlagPoints
[FLAG_RED
] <> nil then
1704 Dispose(FlagPoints
[FLAG_RED
]);
1705 FlagPoints
[FLAG_RED
] := nil;
1707 if FlagPoints
[FLAG_BLUE
] <> nil then
1709 Dispose(FlagPoints
[FLAG_BLUE
]);
1710 FlagPoints
[FLAG_BLUE
] := nil;
1712 //DOMFlagPoints := nil;
1716 if Textures
<> nil then
1718 for a
:= 0 to High(Textures
) do
1719 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1720 if Textures
[a
].Anim
then
1721 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1723 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1724 e_DeleteTexture(Textures
[a
].TextureID
);
1729 FreePanelArray(gWalls
);
1730 FreePanelArray(gRenderBackgrounds
);
1731 FreePanelArray(gRenderForegrounds
);
1732 FreePanelArray(gWater
);
1733 FreePanelArray(gAcid1
);
1734 FreePanelArray(gAcid2
);
1735 FreePanelArray(gSteps
);
1736 FreePanelArray(gLifts
);
1737 FreePanelArray(gBlockMon
);
1739 if BackID
<> DWORD(-1) then
1743 e_DeleteTexture(BackID
);
1744 BackID
:= DWORD(-1);
1747 g_Game_StopAllSounds(False);
1749 g_Sound_Delete(gMapInfo
.MusicName
);
1751 gMapInfo
.Name
:= '';
1752 gMapInfo
.Description
:= '';
1753 gMapInfo
.MusicName
:= '';
1754 gMapInfo
.Height
:= 0;
1755 gMapInfo
.Width
:= 0;
1763 procedure g_Map_Update();
1769 procedure UpdatePanelArray(var panels
: TPanelArray
);
1774 if panels
<> nil then
1775 for i
:= 0 to High(panels
) do
1780 UpdatePanelArray(gWalls
);
1781 UpdatePanelArray(gRenderBackgrounds
);
1782 UpdatePanelArray(gRenderForegrounds
);
1783 UpdatePanelArray(gWater
);
1784 UpdatePanelArray(gAcid1
);
1785 UpdatePanelArray(gAcid2
);
1786 UpdatePanelArray(gSteps
);
1788 if gGameSettings
.GameMode
= GM_CTF
then
1790 for a
:= FLAG_RED
to FLAG_BLUE
do
1791 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1794 if gFlags
[a
].Animation
<> nil then
1795 gFlags
[a
].Animation
.Update();
1797 m
:= g_Obj_Move(@Obj
, True, True);
1799 if gTime
mod (GAME_TICK
*2) <> 0 then
1802 // Ñîïðîòèâëåíèå âîçäóõà:
1803 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1805 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1806 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1809 gFlags
[a
].CaptureTime
:= 0;
1810 if a
= FLAG_RED
then
1811 s
:= _lc
[I_PLAYER_FLAG_RED
]
1813 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1814 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1816 if g_Game_IsNet
then
1817 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1824 // Èãðîê áåðåò ôëàã:
1825 if gPlayers
<> nil then
1827 j
:= Random(Length(gPlayers
)) - 1;
1829 for d
:= 0 to High(gPlayers
) do
1832 if j
> High(gPlayers
) then
1835 if gPlayers
[j
] <> nil then
1836 if gPlayers
[j
].Live
and
1837 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1839 if gPlayers
[j
].GetFlag(a
) then
1849 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1851 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1855 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1857 // alas, no visible set
1858 for idx
:= 0 to High(panels
) do
1860 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1867 PANEL_WALL
: DrawPanels(0, gWalls
);
1868 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1869 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1870 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1871 PANEL_WATER
: DrawPanels(3, gWater
);
1872 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1873 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1874 PANEL_STEP
: DrawPanels(6, gSteps
);
1880 gDrawPanelList
: TBinaryHeapObj
= nil;
1882 function dplLess (a
, b
: TObject
): Boolean;
1884 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1887 procedure dplClear ();
1889 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1892 procedure dplAddPanel (pan
: TPanel
);
1894 if pan
= nil then exit
;
1895 gDrawPanelList
.insert(pan
);
1899 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1903 function checker (obj
: TObject
; tag
: Integer): Boolean;
1907 result
:= false; // don't stop, ever
1908 //e_WriteLog(Format(' *body: tag:%d; ptag:%d; pantype=%d', [tag, ptag, PanelType]), MSG_NOTIFY);
1909 if (tag
<> ptag
) then exit
;
1911 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1912 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1913 //pan := (obj as TPanel);
1914 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1916 pan
:= (obj
as TPanel
);
1917 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1918 //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);
1922 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1927 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1929 // alas, no visible set
1930 for idx
:= 0 to High(panels
) do
1932 if not (drawDoors
xor panels
[idx
].Door
) then
1936 if (pan.Width < 1) or (pan.Height < 1) then continue;
1937 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1938 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1941 //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);
1948 //g_Map_DrawPanelsOld(PanelType); exit;
1949 //e_WriteLog('==================', MSG_NOTIFY);
1950 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1952 ptag
:= panelTypeToTag(PanelType
);
1954 if gdbg_map_use_accel_render
then
1956 if gdbg_map_use_tree_draw
then
1958 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, ptag
);
1962 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
, ptag
);
1964 // sort and draw the list (we need to sort it, or rendering is fucked)
1965 while gDrawPanelList
.count
> 0 do
1967 (gDrawPanelList
.front() as TPanel
).Draw();
1968 gDrawPanelList
.popFront();
1973 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1975 PANEL_WALL
: DrawPanels(0, gWalls
);
1976 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1977 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1978 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1979 PANEL_WATER
: DrawPanels(3, gWater
);
1980 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1981 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1982 PANEL_STEP
: DrawPanels(6, gSteps
);
1986 //e_WriteLog('==================', MSG_NOTIFY);
1990 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1991 function checker (obj
: TObject
; tag
: Integer): Boolean;
1995 result
:= false; // don't stop, ever
1996 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1997 pan
:= (obj
as TPanel
);
1998 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
2002 if gdbg_map_use_tree_draw
then
2004 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, GridTagWallDoor
);
2008 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, GridTagWallDoor
);
2013 procedure g_Map_DrawBack(dx
, dy
: Integer);
2015 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2016 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2018 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2021 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2022 PanelType
: Word; b1x3
: Boolean): Boolean;
2028 if WordBool(PanelType
and PANEL_WALL
) then
2029 if gWalls
<> nil then
2034 if gWalls
[a
].Enabled
and
2035 g_Collide(X
, Y
, Width
, Height
,
2036 gWalls
[a
].X
, gWalls
[a
].Y
,
2037 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2044 if WordBool(PanelType
and PANEL_WATER
) then
2045 if gWater
<> nil then
2050 if g_Collide(X
, Y
, Width
, Height
,
2051 gWater
[a
].X
, gWater
[a
].Y
,
2052 gWater
[a
].Width
, gWater
[a
].Height
) then
2059 if WordBool(PanelType
and PANEL_ACID1
) then
2060 if gAcid1
<> nil then
2065 if g_Collide(X
, Y
, Width
, Height
,
2066 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2067 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2074 if WordBool(PanelType
and PANEL_ACID2
) then
2075 if gAcid2
<> nil then
2080 if g_Collide(X
, Y
, Width
, Height
,
2081 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2082 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2089 if WordBool(PanelType
and PANEL_STEP
) then
2090 if gSteps
<> nil then
2095 if g_Collide(X
, Y
, Width
, Height
,
2096 gSteps
[a
].X
, gSteps
[a
].Y
,
2097 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2104 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2105 if gLifts
<> nil then
2110 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2111 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2112 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2113 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2114 g_Collide(X
, Y
, Width
, Height
,
2115 gLifts
[a
].X
, gLifts
[a
].Y
,
2116 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2123 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2124 if gBlockMon
<> nil then
2126 h
:= High(gBlockMon
);
2130 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2131 g_Collide(X
, Y
, Width
, Height
,
2132 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2133 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2141 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2145 function checkPanels (var panels
: TPanelArray
): Boolean;
2150 if panels
= nil then exit
;
2151 for a
:= 0 to High(panels
) do
2153 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2156 texid
:= panels
[a
].GetTextureID();
2163 texid
:= TEXTURE_NONE
;
2165 if not checkPanels(gWater
) then
2166 if not checkPanels(gAcid1
) then
2167 if not checkPanels(gAcid2
) then exit
;
2172 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2174 function checker (obj
: TObject
; tag
: Integer): Boolean;
2179 result
:= false; // don't stop, ever
2181 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2185 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2187 if not (obj
is TPanel
) then
2189 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2193 pan
:= (obj
as TPanel
);
2196 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2198 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2205 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2207 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2214 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2216 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2223 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2225 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2232 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2234 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2241 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2243 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2244 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2245 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2246 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2247 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2254 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2256 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2257 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2266 //TODO: detailed profile
2267 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2268 if gdbg_map_use_accel_coldet
then
2270 if gdbg_map_use_tree_coldet
then
2272 //e_WriteLog(Format('coldet query: x=%d; y=%d; w=%d; h=%d', [X, Y, Width, Height]), MSG_NOTIFY);
2273 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWallDoor
or GridTagWater
or GridTagAcid1
or GridTagAcid2
or GridTagStep
or GridTagLift
or GridTagBlockMon
)) <> nil);
2274 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2276 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2277 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2282 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWallDoor
or GridTagWater
or GridTagAcid1
or GridTagAcid2
or GridTagStep
or GridTagLift
or GridTagBlockMon
));
2287 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2289 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2293 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2295 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2298 // slightly different from the old code, but meh...
2299 function checker (obj
: TObject
; tag
: Integer): Boolean;
2304 result
:= false; // don't stop, ever
2305 if (tag
<> GridTagWater
) and (tag
<> GridTagAcid1
) and (tag
<> GridTagAcid2
) then exit
;
2306 pan
:= (obj
as TPanel
);
2309 if (tag
= GridTagWater
) then
2311 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2313 result
:= true; // water has highest priority, so stop right here
2314 texid
:= gWater
[a
].GetTextureID();
2319 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2321 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2324 texid
:= gAcid1
[a
].GetTextureID();
2329 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2331 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2334 texid
:= gAcid2
[a
].GetTextureID();
2341 //TODO: detailed profile?
2342 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2343 if gdbg_map_use_accel_coldet
then
2345 texid
:= TEXTURE_NONE
;
2346 if gdbg_map_use_tree_coldet
then
2348 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2352 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
, (GridTagWater
or GridTagAcid1
or GridTagAcid2
));
2358 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2360 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2363 procedure g_Map_EnableWall(ID
: DWORD
);
2368 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2370 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2374 procedure g_Map_DisableWall(ID
: DWORD
);
2379 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2381 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2385 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2390 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2393 tp
:= gRenderForegrounds
[ID
];
2395 tp
:= gRenderBackgrounds
[ID
];
2408 tp
.NextTexture(AnimLoop
);
2409 if g_Game_IsServer
and g_Game_IsNet
then
2410 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2413 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2415 if gLifts
[ID
].LiftType
= t
then
2422 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2424 if LiftType
= 0 then
2425 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2426 else if LiftType
= 1 then
2427 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2428 else if LiftType
= 2 then
2429 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2430 else if LiftType
= 3 then
2431 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2433 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2437 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2440 PointsArray
: Array of TRespawnPoint
;
2443 SetLength(PointsArray
, 0);
2445 if RespawnPoints
= nil then
2448 for a
:= 0 to High(RespawnPoints
) do
2449 if RespawnPoints
[a
].PointType
= PointType
then
2451 SetLength(PointsArray
, Length(PointsArray
)+1);
2452 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2455 if PointsArray
= nil then
2458 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2462 function g_Map_GetPointCount(PointType
: Byte): Word;
2468 if RespawnPoints
= nil then
2471 for a
:= 0 to High(RespawnPoints
) do
2472 if RespawnPoints
[a
].PointType
= PointType
then
2473 Result
:= Result
+ 1;
2476 function g_Map_HaveFlagPoints(): Boolean;
2478 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2481 procedure g_Map_ResetFlag(Flag
: Byte);
2483 with gFlags
[Flag
] do
2489 Direction
:= D_LEFT
;
2490 State
:= FLAG_STATE_NONE
;
2491 if FlagPoints
[Flag
] <> nil then
2493 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2494 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2495 Direction
:= FlagPoints
[Flag
]^.Direction
;
2496 State
:= FLAG_STATE_NORMAL
;
2502 procedure g_Map_DrawFlags();
2505 Mirror
: TMirrorType
;
2507 if gGameSettings
.GameMode
<> GM_CTF
then
2510 for i
:= FLAG_RED
to FLAG_BLUE
do
2512 if State
<> FLAG_STATE_CAPTURED
then
2514 if State
= FLAG_STATE_NONE
then
2517 if Direction
= D_LEFT
then
2519 Mirror
:= M_HORIZONTAL
;
2528 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2530 if g_debug_Frames
then
2532 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2534 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2535 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2541 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2548 procedure SavePanelArray(var panels
: TPanelArray
);
2550 PAMem
: TBinMemoryWriter
;
2553 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2554 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2557 while i
< Length(panels
) do
2559 if panels
[i
].SaveIt
then
2563 // Ñîõðàíÿåì ïàíåëü:
2564 panels
[i
].SaveState(PAMem
);
2569 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2570 PAMem
.SaveToMemory(Mem
);
2574 procedure SaveFlag(flag
: PFlag
);
2577 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2579 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2580 Mem
.WriteByte(flag
^.RespawnType
);
2582 Mem
.WriteByte(flag
^.State
);
2583 // Íàïðàâëåíèå ôëàãà:
2584 if flag
^.Direction
= D_LEFT
then
2590 Obj_SaveState(@flag
^.Obj
, Mem
);
2594 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2596 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2597 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2598 SavePanelArray(gWalls
);
2599 // Ñîõðàíÿåì ïàíåëè ôîíà:
2600 SavePanelArray(gRenderBackgrounds
);
2601 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2602 SavePanelArray(gRenderForegrounds
);
2603 // Ñîõðàíÿåì ïàíåëè âîäû:
2604 SavePanelArray(gWater
);
2605 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2606 SavePanelArray(gAcid1
);
2607 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2608 SavePanelArray(gAcid2
);
2609 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2610 SavePanelArray(gSteps
);
2611 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2612 SavePanelArray(gLifts
);
2615 ///// Ñîõðàíÿåì ìóçûêó: /////
2616 // Ñèãíàòóðà ìóçûêè:
2617 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2620 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2621 if gMusic
.NoMusic
then
2625 Mem
.WriteString(str
, 64);
2626 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2627 dw
:= gMusic
.GetPosition();
2629 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2630 boo
:= gMusic
.SpecPause
;
2631 Mem
.WriteBoolean(boo
);
2634 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2635 Mem
.WriteInt(gTotalMonsters
);
2638 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2639 if gGameSettings
.GameMode
= GM_CTF
then
2641 // Ôëàã Êðàñíîé êîìàíäû:
2642 SaveFlag(@gFlags
[FLAG_RED
]);
2643 // Ôëàã Ñèíåé êîìàíäû:
2644 SaveFlag(@gFlags
[FLAG_BLUE
]);
2648 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2649 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2651 // Î÷êè Êðàñíîé êîìàíäû:
2652 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2653 // Î÷êè Ñèíåé êîìàíäû:
2654 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2659 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2666 procedure LoadPanelArray(var panels
: TPanelArray
);
2668 PAMem
: TBinMemoryReader
;
2671 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2672 PAMem
:= TBinMemoryReader
.Create();
2673 PAMem
.LoadFromMemory(Mem
);
2675 for i
:= 0 to Length(panels
)-1 do
2676 if panels
[i
].SaveIt
then
2682 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2684 // Çàãðóæàåì ïàíåëü:
2685 panels
[i
].LoadState(PAMem
);
2688 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2692 procedure LoadFlag(flag
: PFlag
);
2696 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2698 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2700 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2701 Mem
.ReadByte(flag
^.RespawnType
);
2703 Mem
.ReadByte(flag
^.State
);
2704 // Íàïðàâëåíèå ôëàãà:
2707 flag
^.Direction
:= D_LEFT
2709 flag
^.Direction
:= D_RIGHT
;
2711 Obj_LoadState(@flag
^.Obj
, Mem
);
2718 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2719 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2720 LoadPanelArray(gWalls
);
2721 // Çàãðóæàåì ïàíåëè ôîíà:
2722 LoadPanelArray(gRenderBackgrounds
);
2723 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2724 LoadPanelArray(gRenderForegrounds
);
2725 // Çàãðóæàåì ïàíåëè âîäû:
2726 LoadPanelArray(gWater
);
2727 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2728 LoadPanelArray(gAcid1
);
2729 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2730 LoadPanelArray(gAcid2
);
2731 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2732 LoadPanelArray(gSteps
);
2733 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2734 LoadPanelArray(gLifts
);
2737 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2741 ///// Çàãðóæàåì ìóçûêó: /////
2742 // Ñèãíàòóðà ìóçûêè:
2744 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2746 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2749 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2750 Mem
.ReadString(str
);
2751 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2753 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2754 Mem
.ReadBoolean(boo
);
2755 // Çàïóñêàåì ýòó ìóçûêó:
2756 gMusic
.SetByName(str
);
2757 gMusic
.SpecPause
:= boo
;
2760 gMusic
.SetPosition(dw
);
2763 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2764 Mem
.ReadInt(gTotalMonsters
);
2767 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2768 if gGameSettings
.GameMode
= GM_CTF
then
2770 // Ôëàã Êðàñíîé êîìàíäû:
2771 LoadFlag(@gFlags
[FLAG_RED
]);
2772 // Ôëàã Ñèíåé êîìàíäû:
2773 LoadFlag(@gFlags
[FLAG_BLUE
]);
2777 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2778 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2780 // Î÷êè Êðàñíîé êîìàíäû:
2781 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2782 // Î÷êè Ñèíåé êîìàíäû:
2783 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2788 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2793 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2794 Arr
:= PanelByID
[PanelID
].PWhere
^;
2795 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2796 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);