1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, z_aabbtree
, md5
, xprofiler
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
67 procedure g_Map_DrawBack(dx
, dy
: Integer);
68 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
69 PanelType
: Word; b1x3
: Boolean): Boolean;
70 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
71 procedure g_Map_EnableWall(ID
: DWORD
);
72 procedure g_Map_DisableWall(ID
: DWORD
);
73 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
74 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
75 procedure g_Map_ReAdd_DieTriggers();
76 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
78 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
79 function g_Map_GetPointCount(PointType
: Byte): Word;
81 function g_Map_HaveFlagPoints(): Boolean;
83 procedure g_Map_ResetFlag(Flag
: Byte);
84 procedure g_Map_DrawFlags();
86 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
88 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
89 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
91 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
93 procedure g_Map_ProfilersBegin ();
94 procedure g_Map_ProfilersEnd ();
97 RESPAWNPOINT_PLAYER1
= 1;
98 RESPAWNPOINT_PLAYER2
= 2;
100 RESPAWNPOINT_RED
= 4;
101 RESPAWNPOINT_BLUE
= 5;
109 FLAG_STATE_NORMAL
= 1;
110 FLAG_STATE_DROPPED
= 2;
111 FLAG_STATE_CAPTURED
= 3;
112 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
115 FLAG_TIME
= 720; // 20 seconds
117 SKY_STRETCH
: Single = 1.5;
121 gRenderBackgrounds
: TPanelArray
;
122 gRenderForegrounds
: TPanelArray
;
123 gWater
, gAcid1
, gAcid2
: TPanelArray
;
126 gBlockMon
: TPanelArray
;
127 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
128 //gDOMFlags: array of TFlag;
131 gDoorMap
: array of array of DWORD
;
132 gLiftMap
: array of array of DWORD
;
133 gWADHash
: TMD5Digest
;
134 BackID
: DWORD
= DWORD(-1);
135 gExternalResources
: TStringList
;
137 gdbg_map_use_grid_render
: Boolean = true;
138 gdbg_map_use_grid_coldet
: Boolean = true;
139 gdbg_map_use_tree_draw
: Boolean = true;
140 gdbg_map_use_tree_coldet
: Boolean = false;
141 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;
204 if (flesh
= nil) then begin result
:= false; exit
; end;
205 pan
:= (flesh
as TPanel
);
206 aabb
:= AABB2D
.Create(pan
.X
, pan
.Y
, pan
.X
+pan
.Width
, pan
.Y
+pan
.Height
);
207 //e_WriteLog(Format('getFleshAABB(%d;%d) AABB:(%f,%f)-(%f,%f); valid=%d; volume=%f; x=%d; y=%d; w=%d; h=%d', [pan.tag, pan.ArrIdx, aabb.minX, aabb.minY, aabb.maxX, aabb.maxY, Integer(aabb.valid), aabb.volume, pan.X, pan.Y, pan.Width, pan.Height]), MSG_NOTIFY);
208 result
:= aabb
.valid
;
212 PanelById
: array of TPanelID
;
213 Textures
: TLevelTextureArray
;
214 RespawnPoints
: Array of TRespawnPoint
;
215 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
216 //DOMFlagPoints: Array of TFlagPoint;
217 gMapGrid
: TBodyGrid
= nil;
218 mapTree
: TDynAABBTree
= nil;
221 procedure g_Map_ProfilersBegin ();
223 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
224 profMapCollision
.mainBegin(g_profile_collision
);
226 if g_profile_collision
then
228 profMapCollision
.sectionBegin('wall coldet');
229 profMapCollision
.sectionEnd();
230 profMapCollision
.sectionBegin('liquid coldet');
231 profMapCollision
.sectionEnd();
235 procedure g_Map_ProfilersEnd ();
237 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
241 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
243 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
244 (Texture
= TEXTURE_NAME_ACID1
) or
245 (Texture
= TEXTURE_NAME_ACID2
);
248 procedure CreateDoorMap();
250 PanelArray
: Array of record
256 a
, b
, c
, m
, i
, len
: Integer;
264 SetLength(PanelArray
, len
);
266 for a
:= 0 to High(gWalls
) do
267 if gWalls
[a
].Door
then
269 PanelArray
[i
].X
:= gWalls
[a
].X
;
270 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
271 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
272 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
273 PanelArray
[i
].Active
:= True;
274 PanelArray
[i
].PanelID
:= a
;
280 SetLength(PanelArray
, len
);
291 SetLength(gDoorMap
, 0);
293 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
296 if PanelArray
[a
].Active
then
298 PanelArray
[a
].Active
:= False;
299 m
:= Length(gDoorMap
);
300 SetLength(gDoorMap
, m
+1);
301 SetLength(gDoorMap
[m
], 1);
302 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
310 if PanelArray
[b
].Active
then
311 for c
:= 0 to High(gDoorMap
[m
]) do
312 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
313 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
314 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
315 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
316 gWalls
[gDoorMap
[m
, c
]].X
,
317 gWalls
[gDoorMap
[m
, c
]].Y
,
318 gWalls
[gDoorMap
[m
, c
]].Width
,
319 gWalls
[gDoorMap
[m
, c
]].Height
) then
321 PanelArray
[b
].Active
:= False;
322 SetLength(gDoorMap
[m
],
323 Length(gDoorMap
[m
])+1);
324 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
330 g_Game_StepLoading();
336 procedure CreateLiftMap();
338 PanelArray
: Array of record
343 a
, b
, c
, len
, i
, j
: Integer;
349 len
:= Length(gLifts
);
350 SetLength(PanelArray
, len
);
352 for a
:= 0 to len
-1 do
354 PanelArray
[a
].X
:= gLifts
[a
].X
;
355 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
356 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
357 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
358 PanelArray
[a
].Active
:= True;
361 SetLength(gLiftMap
, len
);
364 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
366 for a
:= 0 to len
-1 do
367 if PanelArray
[a
].Active
then
369 PanelArray
[a
].Active
:= False;
370 SetLength(gLiftMap
[i
], 32);
378 for b
:= 0 to len
-1 do
379 if PanelArray
[b
].Active
then
381 if g_CollideAround(PanelArray
[b
].X
,
384 PanelArray
[b
].Height
,
385 PanelArray
[gLiftMap
[i
, c
]].X
,
386 PanelArray
[gLiftMap
[i
, c
]].Y
,
387 PanelArray
[gLiftMap
[i
, c
]].Width
,
388 PanelArray
[gLiftMap
[i
, c
]].Height
) then
390 PanelArray
[b
].Active
:= False;
392 if j
> High(gLiftMap
[i
]) then
393 SetLength(gLiftMap
[i
],
394 Length(gLiftMap
[i
])+32);
403 SetLength(gLiftMap
[i
], j
+1);
406 g_Game_StepLoading();
409 SetLength(gLiftMap
, i
);
414 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
415 CurTex
: Integer; sav
: Boolean): Integer;
418 panels
: ^TPanelArray
;
422 case PanelRec
.PanelType
of
423 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
426 panels
:= @gRenderBackgrounds
;
428 panels
:= @gRenderForegrounds
;
437 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
440 panels
:= @gBlockMon
;
445 len
:= Length(panels
^);
446 SetLength(panels
^, len
+ 1);
448 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
449 panels
^[len
].ArrIdx
:= len
;
450 panels
^[len
].tag
:= panelTypeToTag(PanelRec
.PanelType
);
452 panels
^[len
].SaveIt
:= True;
456 len
:= Length(PanelByID
);
457 SetLength(PanelByID
, len
+ 1);
458 PanelByID
[len
].PWhere
:= panels
;
459 PanelByID
[len
].PArrID
:= Result
;
462 function CreateNullTexture(RecName
: String): Integer;
464 SetLength(Textures
, Length(Textures
)+1);
465 result
:= High(Textures
);
467 with Textures
[High(Textures
)] do
469 TextureName
:= RecName
;
473 TextureID
:= TEXTURE_NONE
;
477 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
480 TextureData
: Pointer;
481 WADName
, txname
: String;
482 a
, ResLength
: Integer;
486 if Textures
<> nil then
487 for a
:= 0 to High(Textures
) do
488 if Textures
[a
].TextureName
= RecName
then
489 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
494 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
495 if (RecName
= TEXTURE_NAME_WATER
) or
496 (RecName
= TEXTURE_NAME_ACID1
) or
497 (RecName
= TEXTURE_NAME_ACID2
) then
499 SetLength(Textures
, Length(Textures
)+1);
501 with Textures
[High(Textures
)] do
503 TextureName
:= RecName
;
505 if TextureName
= TEXTURE_NAME_WATER
then
506 TextureID
:= TEXTURE_SPECIAL_WATER
508 if TextureName
= TEXTURE_NAME_ACID1
then
509 TextureID
:= TEXTURE_SPECIAL_ACID1
511 if TextureName
= TEXTURE_NAME_ACID2
then
512 TextureID
:= TEXTURE_SPECIAL_ACID2
;
517 result
:= High(Textures
);
521 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
522 WADName
:= g_ExtractWadName(RecName
);
524 WAD
:= TWADFile
.Create();
526 if WADName
<> '' then
527 WADName
:= GameDir
+'/wads/'+WADName
531 WAD
.ReadFile(WADName
);
535 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
537 FreeMem(TextureData);
538 RecName := 'COMMON\ALIEN';
542 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
544 SetLength(Textures
, Length(Textures
)+1);
545 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
547 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
548 @Textures
[High(Textures
)].Width
,
549 @Textures
[High(Textures
)].Height
);
550 FreeMem(TextureData
);
551 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
552 Textures
[High(Textures
)].Anim
:= False;
554 result
:= High(Textures
);
556 else // Íåò òàêîãî ðåóñðñà â WAD'å
558 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
561 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
562 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
569 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
572 TextureWAD
: PChar = nil;
573 TextData
: Pointer = nil;
574 TextureData
: Pointer = nil;
578 TextureResource
: String;
579 _width
, _height
, _framecount
, _speed
: Integer;
580 _backanimation
: Boolean;
582 ia
: TDynImageDataArray
= nil;
583 f
, c
, frdelay
, frloop
: Integer;
587 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
589 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
590 WADName
:= g_ExtractWadName(RecName
);
592 WAD
:= TWADFile
.Create();
594 if WADName
<> '' then
595 WADName
:= GameDir
+'/wads/'+WADName
599 WAD
.ReadFile(WADName
);
601 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
605 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
606 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
612 if WADName = Map then
614 //FreeMem(TextureWAD);
615 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
621 if ResLength
< 6 then
623 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
627 // ýòî ïòèöà? ýòî ñàìîë¸ò?
628 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
629 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
631 // íåò, ýòî ñóïåðìåí!
632 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
634 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
638 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
639 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
641 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
645 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
647 TextureResource
:= cfg
.ReadStr('', 'resource', '');
648 if TextureResource
= '' then
650 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
654 _width
:= cfg
.ReadInt('', 'framewidth', 0);
655 _height
:= cfg
.ReadInt('', 'frameheight', 0);
656 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
657 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
658 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
663 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
664 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
666 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
673 SetLength(Textures
, Length(Textures
)+1);
674 with Textures
[High(Textures
)] do
676 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
677 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
679 TextureName
:= RecName
;
683 FramesCount
:= _framecount
;
685 result
:= High(Textures
);
689 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
695 // try animated image
697 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
698 if length(imgfmt) = 0 then
700 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
704 GlobalMetadata
.ClearMetaItems();
705 GlobalMetadata
.ClearMetaItemsForSaving();
706 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
708 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
711 if length(ia
) = 0 then
713 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
720 _width
:= ia
[0].width
;
721 _height
:= ia
[0].height
;
722 _framecount
:= length(ia
);
724 _backanimation
:= false;
727 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
729 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
731 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
733 if f
< 0 then f
:= 0;
736 if c
< 13 then c
:= 0 else c
:= 1;
738 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
743 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
745 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
747 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
749 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
753 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
754 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
755 f
:= ord(_backanimation
);
756 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
);
758 SetLength(Textures
, Length(Textures
)+1);
759 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
760 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
762 Textures
[High(Textures
)].TextureName
:= RecName
;
763 Textures
[High(Textures
)].Width
:= _width
;
764 Textures
[High(Textures
)].Height
:= _height
;
765 Textures
[High(Textures
)].Anim
:= True;
766 Textures
[High(Textures
)].FramesCount
:= length(ia
);
767 Textures
[High(Textures
)].Speed
:= _speed
;
768 result
:= High(Textures
);
769 //writeln(' CREATED!');
773 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
777 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
780 if TextureWAD
<> nil then FreeMem(TextureWAD
);
781 if TextData
<> nil then FreeMem(TextData
);
782 if TextureData
<> nil then FreeMem(TextureData
);
786 procedure CreateItem(Item
: TItemRec_1
);
788 if g_Game_IsClient
then Exit
;
790 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
791 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
794 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
795 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
798 procedure CreateArea(Area
: TAreaRec_1
);
803 case Area
.AreaType
of
804 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
805 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
807 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
808 with RespawnPoints
[High(RespawnPoints
)] do
812 Direction
:= TDirection(Area
.Direction
);
814 case Area
.AreaType
of
815 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
816 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
817 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
818 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
819 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
824 AREA_REDFLAG
, AREA_BLUEFLAG
:
826 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
828 if FlagPoints
[a
] <> nil then Exit
;
832 with FlagPoints
[a
]^ do
834 X
:= Area
.X
-FLAGRECT
.X
;
835 Y
:= Area
.Y
-FLAGRECT
.Y
;
836 Direction
:= TDirection(Area
.Direction
);
842 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
843 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
846 Animation
:= TAnimation
.Create(id
, True, 8);
847 Obj
.Rect
:= FLAGRECT
;
855 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
856 with DOMFlagPoints[High(DOMFlagPoints)] do
860 Direction := TDirection(Area.Direction);
863 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
868 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
872 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
878 Width
:= Trigger
.Width
;
879 Height
:= Trigger
.Height
;
880 Enabled
:= ByteBool(Trigger
.Enabled
);
881 TexturePanel
:= Trigger
.TexturePanel
;
882 TexturePanelType
:= fTexturePanel1Type
;
883 ShotPanelType
:= fTexturePanel2Type
;
884 TriggerType
:= Trigger
.TriggerType
;
885 ActivateType
:= Trigger
.ActivateType
;
886 Keys
:= Trigger
.Keys
;
887 Data
.Default
:= Trigger
.DATA
;
890 g_Triggers_Create(_trigger
);
893 procedure CreateMonster(monster
: TMonsterRec_1
);
897 if g_Game_IsClient
then Exit
;
899 if (gGameSettings
.GameType
= GT_SINGLE
)
900 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
902 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
903 TDirection(monster
.Direction
));
905 if gTriggers
<> nil then
906 for a
:= 0 to High(gTriggers
) do
907 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
908 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
909 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
910 gMonsters
[i
].AddTrigger(a
);
912 if monster
.MonsterType
<> MONSTER_BARREL
then
917 procedure g_Map_ReAdd_DieTriggers();
921 if g_Game_IsClient
then Exit
;
923 for i
:= 0 to High(gMonsters
) do
924 if gMonsters
[i
] <> nil then
926 gMonsters
[i
].ClearTriggers();
928 for a
:= 0 to High(gTriggers
) do
929 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
930 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
931 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
932 gMonsters
[i
].AddTrigger(a
);
936 function extractWadName(resourceName
: string): string;
940 posN
:= Pos(':', resourceName
);
942 Result
:= Copy(resourceName
, 0, posN
-1)
947 procedure addResToExternalResList(res
: string);
949 res
:= extractWadName(res
);
950 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
951 gExternalResources
.Add(res
);
954 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
956 textures
: TTexturesRec1Array
;
957 mapHeader
: TMapHeaderRec_1
;
959 resFile
: String = '';
961 if gExternalResources
= nil then
962 gExternalResources
:= TStringList
.Create
;
964 gExternalResources
.Clear
;
965 textures
:= mapReader
.GetTextures();
966 for i
:= 0 to High(textures
) do
968 addResToExternalResList(resFile
);
973 mapHeader
:= mapReader
.GetMapHeader
;
975 addResToExternalResList(mapHeader
.MusicName
);
976 addResToExternalResList(mapHeader
.SkyName
);
979 procedure mapCreateGrid ();
981 mapX0
: Integer = $3fffffff;
982 mapY0
: Integer = $3fffffff;
983 mapX1
: Integer = -$3fffffff;
984 mapY1
: Integer = -$3fffffff;
986 procedure fixMinMax (var panels
: TPanelArray
);
990 for idx
:= 0 to High(panels
) do
992 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
993 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
994 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
995 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
996 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
1000 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
1004 tag
:= panelTypeToTag(tag
);
1005 for idx
:= High(panels
) downto 0 do
1007 panels
[idx
].tag
:= tag
;
1008 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1009 mapTree
.insertObject(panels
[idx
], tag
, true); // as static object
1020 fixMinMax(gRenderBackgrounds
);
1021 fixMinMax(gRenderForegrounds
);
1027 fixMinMax(gBlockMon
);
1029 if (mapX0
< 0) or (mapY0
< 0) then
1031 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1032 //raise Exception.Create('we are fucked');
1035 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1036 mapTree
:= TDynAABBTreeMap
.Create();
1038 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1039 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1040 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1041 addPanelsToGrid(gWater
, PANEL_WATER
);
1042 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1043 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1044 addPanelsToGrid(gSteps
, PANEL_STEP
);
1045 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1046 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1048 gMapGrid
.dumpStats();
1049 e_WriteLog(Format('tree depth: %d; %d nodes used, %d nodes allocated', [mapTree
.computeTreeHeight
, mapTree
.nodeCount
, mapTree
.nodeAlloced
]), MSG_NOTIFY
);
1050 mapTree
.forEachLeaf(nil);
1053 function g_Map_Load(Res
: String): Boolean;
1055 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1056 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1059 MapReader
: TMapReader_1
;
1060 Header
: TMapHeaderRec_1
;
1061 _textures
: TTexturesRec1Array
;
1062 _texnummap
: array of Integer; // `_textures` -> `Textures`
1063 panels
: TPanelsRec1Array
;
1064 items
: TItemsRec1Array
;
1065 monsters
: TMonsterRec1Array
;
1066 areas
: TAreasRec1Array
;
1067 triggers
: TTriggersRec1Array
;
1068 a
, b
, c
, k
: Integer;
1070 AddTextures
: TAddTextureArray
;
1071 texture
: TTextureRec_1
;
1072 TriggersTable
: Array of record
1073 TexturePanel
: Integer;
1078 FileName
, mapResName
, s
, TexName
: String;
1081 ok
, isAnim
, trigRef
: Boolean;
1082 CurTex
, ntn
: Integer;
1091 gMapInfo
.Map
:= Res
;
1092 TriggersTable
:= nil;
1093 FillChar(texture
, SizeOf(texture
), 0);
1095 sfsGCDisable(); // temporary disable removing of temporary volumes
1098 FileName
:= g_ExtractWadName(Res
);
1099 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1100 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1102 WAD
:= TWADFile
.Create();
1103 if not WAD
.ReadFile(FileName
) then
1105 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1109 //k8: why loader ignores path here?
1110 mapResName
:= g_ExtractFileName(Res
);
1111 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1113 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1121 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1122 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1123 MapReader
:= TMapReader_1
.Create();
1125 if not MapReader
.LoadMap(Data
) then
1127 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1134 generateExternalResourcesList(MapReader
);
1135 // Çàãðóçêà òåêñòóð:
1136 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1137 _textures
:= MapReader
.GetTextures();
1140 // Äîáàâëåíèå òåêñòóð â Textures[]:
1141 if _textures
<> nil then
1143 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1144 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1145 SetLength(_texnummap
, length(_textures
));
1147 for a
:= 0 to High(_textures
) do
1150 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1151 for b
:= 1 to Length(s
) do
1157 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1158 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1159 // Àíèìèðîâàííàÿ òåêñòóðà:
1160 if ByteBool(_textures
[a
].Anim
) then
1162 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1165 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1166 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1169 else // Îáû÷íàÿ òåêñòóðà:
1170 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1173 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1174 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1177 _texnummap
[a
] := ntn
; // fix texture number
1178 g_Game_StepLoading();
1182 // Çàãðóçêà òðèããåðîâ:
1183 gTriggerClientID
:= 0;
1184 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1185 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1186 triggers
:= MapReader
.GetTriggers();
1188 // Çàãðóçêà ïàíåëåé:
1189 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1190 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1191 panels
:= MapReader
.GetPanels();
1193 // check texture numbers for panels
1194 for a
:= 0 to High(panels
) do
1196 if panels
[a
].TextureNum
> High(_textures
) then
1198 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1202 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1205 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1206 if triggers
<> nil then
1208 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1209 SetLength(TriggersTable
, Length(triggers
));
1210 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1212 for a
:= 0 to High(TriggersTable
) do
1214 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1215 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1217 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1218 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1220 TriggersTable
[a
].LiftPanel
:= -1;
1222 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1223 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1224 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1225 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1227 TriggersTable
[a
].DoorPanel
:= -1;
1229 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1230 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1232 TriggersTable
[a
].ShotPanel
:= -1;
1234 g_Game_StepLoading();
1239 if panels
<> nil then
1241 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1242 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1244 for a
:= 0 to High(panels
) do
1246 SetLength(AddTextures
, 0);
1249 if _textures
<> nil then
1251 texture
:= _textures
[panels
[a
].TextureNum
];
1259 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1260 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1262 if (TriggersTable
<> nil) and (_textures
<> nil) then
1263 for b
:= 0 to High(TriggersTable
) do
1264 if (TriggersTable
[b
].TexturePanel
= a
)
1265 or (TriggersTable
[b
].ShotPanel
= a
) then
1274 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1276 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1279 for c
:= Len
downto 1 do
1287 // Ñïåö-òåêñòóðû çàïðåùåíû:
1288 if g_Map_IsSpecialTexture(s
) then
1291 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1292 ok
:= g_Texture_NumNameFindStart(s
);
1294 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1295 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1298 k
:= NNF_NAME_BEFORE
;
1299 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1300 while ok
or (k
= NNF_NAME_BEFORE
) or
1301 (k
= NNF_NAME_EQUALS
) do
1303 k
:= g_Texture_NumNameFindNext(TexName
);
1305 if (k
= NNF_NAME_BEFORE
) or
1306 (k
= NNF_NAME_AFTER
) then
1308 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1309 if ByteBool(texture
.Anim
) then
1310 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1312 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1314 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1316 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1320 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1322 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1324 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1326 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1330 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1333 for c
:= 0 to High(Textures
) do
1334 if Textures
[c
].TextureName
= TexName
then
1336 SetLength(AddTextures
, Length(AddTextures
)+1);
1337 AddTextures
[High(AddTextures
)].Texture
:= c
;
1338 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1344 if k
= NNF_NAME_EQUALS
then
1346 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1347 SetLength(AddTextures
, Length(AddTextures
)+1);
1348 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1349 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1350 CurTex
:= High(AddTextures
);
1358 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1359 end; // if ok - ññûëàþòñÿ òðèããåðû
1363 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1364 SetLength(AddTextures
, 1);
1365 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1366 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1370 //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);
1372 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1373 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1375 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1376 if TriggersTable
<> nil then
1377 for b
:= 0 to High(TriggersTable
) do
1379 // Òðèããåð äâåðè/ëèôòà:
1380 if (TriggersTable
[b
].LiftPanel
= a
) or
1381 (TriggersTable
[b
].DoorPanel
= a
) then
1382 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1383 // Òðèããåð ñìåíû òåêñòóðû:
1384 if TriggersTable
[b
].TexturePanel
= a
then
1385 triggers
[b
].TexturePanel
:= PanelID
;
1386 // Òðèããåð "Òóðåëü":
1387 if TriggersTable
[b
].ShotPanel
= a
then
1388 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1391 g_Game_StepLoading();
1395 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1396 if (triggers
<> nil) and not gLoadGameMode
then
1398 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1399 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1400 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1401 for a
:= 0 to High(triggers
) do
1403 if triggers
[a
].TexturePanel
<> -1 then
1404 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1407 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1408 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1409 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1412 CreateTrigger(triggers
[a
], b
, c
);
1416 // Çàãðóçêà ïðåäìåòîâ:
1417 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1418 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1419 items
:= MapReader
.GetItems();
1421 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1422 if (items
<> nil) and not gLoadGameMode
then
1424 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1425 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1426 for a
:= 0 to High(items
) do
1427 CreateItem(Items
[a
]);
1430 // Çàãðóçêà îáëàñòåé:
1431 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1432 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1433 areas
:= MapReader
.GetAreas();
1435 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1436 if areas
<> nil then
1438 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1439 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1440 for a
:= 0 to High(areas
) do
1441 CreateArea(areas
[a
]);
1444 // Çàãðóçêà ìîíñòðîâ:
1445 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1446 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1447 monsters
:= MapReader
.GetMonsters();
1449 gTotalMonsters
:= 0;
1451 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1452 if (monsters
<> nil) and not gLoadGameMode
then
1454 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1455 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1456 for a
:= 0 to High(monsters
) do
1457 CreateMonster(monsters
[a
]);
1460 // Çàãðóçêà îïèñàíèÿ êàðòû:
1461 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1462 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1463 Header
:= MapReader
.GetMapHeader();
1469 Name
:= Header
.MapName
;
1470 Description
:= Header
.MapDescription
;
1471 Author
:= Header
.MapAuthor
;
1472 MusicName
:= Header
.MusicName
;
1473 SkyName
:= Header
.SkyName
;
1474 Height
:= Header
.Height
;
1475 Width
:= Header
.Width
;
1479 if gMapInfo
.SkyName
<> '' then
1481 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1482 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1483 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1485 if FileName
<> '' then
1486 FileName
:= GameDir
+'/wads/'+FileName
1489 FileName
:= g_ExtractWadName(Res
);
1492 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1493 if g_Texture_CreateWAD(BackID
, s
) then
1495 g_Game_SetupScreenSize();
1498 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1503 if gMapInfo
.MusicName
<> '' then
1505 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1506 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1507 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1509 if FileName
<> '' then
1510 FileName
:= GameDir
+'/wads/'+FileName
1513 FileName
:= g_ExtractWadName(Res
);
1516 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1517 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1520 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1523 // Îñòàëüíûå óñòàíâêè:
1531 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1532 if not gLoadGameMode
then
1535 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1541 TriggersTable
:= nil;
1544 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1545 if ok
and (not gLoadGameMode
) then
1547 gMusic
.SetByName(gMapInfo
.MusicName
);
1551 gMusic
.SetByName('');
1553 sfsGCEnable(); // enable releasing unused volumes
1556 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1559 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1563 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1566 MapReader
: TMapReader_1
;
1567 Header
: TMapHeaderRec_1
;
1572 FillChar(Result
, SizeOf(Result
), 0);
1573 FileName
:= g_ExtractWadName(Res
);
1575 WAD
:= TWADFile
.Create();
1576 if not WAD
.ReadFile(FileName
) then
1582 //k8: it ignores path again
1583 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1591 MapReader
:= TMapReader_1
.Create();
1593 if not MapReader
.LoadMap(Data
) then
1595 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1596 ZeroMemory(@Header
, SizeOf(Header
));
1597 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1598 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1602 Header
:= MapReader
.GetMapHeader();
1603 Result
.Name
:= Header
.MapName
;
1604 Result
.Description
:= Header
.MapDescription
;
1611 Result
.Author
:= Header
.MapAuthor
;
1612 Result
.Height
:= Header
.Height
;
1613 Result
.Width
:= Header
.Width
;
1616 function g_Map_GetMapsList(WADName
: string): SArray
;
1623 WAD
:= TWADFile
.Create();
1624 if not WAD
.ReadFile(WADName
) then
1629 ResList
:= WAD
.GetMapResources();
1630 if ResList
<> nil then
1632 for a
:= 0 to High(ResList
) do
1634 SetLength(Result
, Length(Result
)+1);
1635 Result
[High(Result
)] := ResList
[a
];
1641 function g_Map_Exist(Res
: string): Boolean;
1644 FileName
, mnn
: string;
1650 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1652 WAD
:= TWADFile
.Create
;
1653 if not WAD
.ReadFile(FileName
) then
1659 ResList
:= WAD
.GetMapResources();
1662 mnn
:= g_ExtractFileName(Res
);
1663 if ResList
<> nil then
1664 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1671 procedure g_Map_Free();
1675 procedure FreePanelArray(var panels
: TPanelArray
);
1680 if panels
<> nil then
1682 for i
:= 0 to High(panels
) do
1695 RespawnPoints
:= nil;
1696 if FlagPoints
[FLAG_RED
] <> nil then
1698 Dispose(FlagPoints
[FLAG_RED
]);
1699 FlagPoints
[FLAG_RED
] := nil;
1701 if FlagPoints
[FLAG_BLUE
] <> nil then
1703 Dispose(FlagPoints
[FLAG_BLUE
]);
1704 FlagPoints
[FLAG_BLUE
] := nil;
1706 //DOMFlagPoints := nil;
1710 if Textures
<> nil then
1712 for a
:= 0 to High(Textures
) do
1713 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1714 if Textures
[a
].Anim
then
1715 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1717 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1718 e_DeleteTexture(Textures
[a
].TextureID
);
1723 FreePanelArray(gWalls
);
1724 FreePanelArray(gRenderBackgrounds
);
1725 FreePanelArray(gRenderForegrounds
);
1726 FreePanelArray(gWater
);
1727 FreePanelArray(gAcid1
);
1728 FreePanelArray(gAcid2
);
1729 FreePanelArray(gSteps
);
1730 FreePanelArray(gLifts
);
1731 FreePanelArray(gBlockMon
);
1733 if BackID
<> DWORD(-1) then
1737 e_DeleteTexture(BackID
);
1738 BackID
:= DWORD(-1);
1741 g_Game_StopAllSounds(False);
1743 g_Sound_Delete(gMapInfo
.MusicName
);
1745 gMapInfo
.Name
:= '';
1746 gMapInfo
.Description
:= '';
1747 gMapInfo
.MusicName
:= '';
1748 gMapInfo
.Height
:= 0;
1749 gMapInfo
.Width
:= 0;
1757 procedure g_Map_Update();
1763 procedure UpdatePanelArray(var panels
: TPanelArray
);
1768 if panels
<> nil then
1769 for i
:= 0 to High(panels
) do
1774 UpdatePanelArray(gWalls
);
1775 UpdatePanelArray(gRenderBackgrounds
);
1776 UpdatePanelArray(gRenderForegrounds
);
1777 UpdatePanelArray(gWater
);
1778 UpdatePanelArray(gAcid1
);
1779 UpdatePanelArray(gAcid2
);
1780 UpdatePanelArray(gSteps
);
1782 if gGameSettings
.GameMode
= GM_CTF
then
1784 for a
:= FLAG_RED
to FLAG_BLUE
do
1785 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1788 if gFlags
[a
].Animation
<> nil then
1789 gFlags
[a
].Animation
.Update();
1791 m
:= g_Obj_Move(@Obj
, True, True);
1793 if gTime
mod (GAME_TICK
*2) <> 0 then
1796 // Ñîïðîòèâëåíèå âîçäóõà:
1797 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1799 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1800 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1803 gFlags
[a
].CaptureTime
:= 0;
1804 if a
= FLAG_RED
then
1805 s
:= _lc
[I_PLAYER_FLAG_RED
]
1807 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1808 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1810 if g_Game_IsNet
then
1811 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1818 // Èãðîê áåðåò ôëàã:
1819 if gPlayers
<> nil then
1821 j
:= Random(Length(gPlayers
)) - 1;
1823 for d
:= 0 to High(gPlayers
) do
1826 if j
> High(gPlayers
) then
1829 if gPlayers
[j
] <> nil then
1830 if gPlayers
[j
].Live
and
1831 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1833 if gPlayers
[j
].GetFlag(a
) then
1843 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1845 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1849 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1851 // alas, no visible set
1852 for idx
:= 0 to High(panels
) do
1854 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1861 PANEL_WALL
: DrawPanels(0, gWalls
);
1862 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1863 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1864 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1865 PANEL_WATER
: DrawPanels(3, gWater
);
1866 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1867 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1868 PANEL_STEP
: DrawPanels(6, gSteps
);
1874 gDrawPanelList
: TBinaryHeapObj
= nil;
1876 function dplLess (a
, b
: TObject
): Boolean;
1878 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1881 procedure dplClear ();
1883 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1886 procedure dplAddPanel (pan
: TPanel
);
1888 if pan
= nil then exit
;
1889 gDrawPanelList
.insert(pan
);
1893 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1897 function checker (obj
: TObject
; tag
: Integer): Boolean;
1901 result
:= false; // don't stop, ever
1902 //e_WriteLog(Format(' *body: tag:%d; ptag:%d; pantype=%d', [tag, ptag, PanelType]), MSG_NOTIFY);
1903 if (tag
<> ptag
) then exit
;
1905 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1906 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1907 //pan := (obj as TPanel);
1908 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1910 pan
:= (obj
as TPanel
);
1911 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1912 //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);
1916 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1921 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1923 // alas, no visible set
1924 for idx
:= 0 to High(panels
) do
1926 if not (drawDoors
xor panels
[idx
].Door
) then
1930 if (pan.Width < 1) or (pan.Height < 1) then continue;
1931 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1932 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1935 //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);
1942 //g_Map_DrawPanelsOld(PanelType); exit;
1943 //e_WriteLog('==================', MSG_NOTIFY);
1944 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1946 ptag
:= panelTypeToTag(PanelType
);
1948 if gdbg_map_use_grid_render
then
1950 if gdbg_map_use_tree_draw
then
1952 mapTree
.aabbQuery(x0
, y0
, wdt
, hgt
, checker
, ptag
);
1956 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1958 // sort and draw the list (we need to sort it, or rendering is fucked)
1959 while gDrawPanelList
.count
> 0 do
1961 (gDrawPanelList
.front() as TPanel
).Draw();
1962 gDrawPanelList
.popFront();
1967 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1969 PANEL_WALL
: DrawPanels(0, gWalls
);
1970 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1971 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1972 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1973 PANEL_WATER
: DrawPanels(3, gWater
);
1974 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1975 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1976 PANEL_STEP
: DrawPanels(6, gSteps
);
1980 //e_WriteLog('==================', MSG_NOTIFY);
1984 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1985 function checker (obj
: TObject
; tag
: Integer): Boolean;
1989 result
:= false; // don't stop, ever
1990 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1991 pan
:= (obj
as TPanel
);
1992 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1996 if gdbg_map_use_tree_draw
then
1998 mapTree
.aabbQuery(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
, GridTagWallDoor
);
2002 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
2007 procedure g_Map_DrawBack(dx
, dy
: Integer);
2009 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2010 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2012 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2015 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2016 PanelType
: Word; b1x3
: Boolean): Boolean;
2022 if WordBool(PanelType
and PANEL_WALL
) then
2023 if gWalls
<> nil then
2028 if gWalls
[a
].Enabled
and
2029 g_Collide(X
, Y
, Width
, Height
,
2030 gWalls
[a
].X
, gWalls
[a
].Y
,
2031 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2038 if WordBool(PanelType
and PANEL_WATER
) then
2039 if gWater
<> nil then
2044 if g_Collide(X
, Y
, Width
, Height
,
2045 gWater
[a
].X
, gWater
[a
].Y
,
2046 gWater
[a
].Width
, gWater
[a
].Height
) then
2053 if WordBool(PanelType
and PANEL_ACID1
) then
2054 if gAcid1
<> nil then
2059 if g_Collide(X
, Y
, Width
, Height
,
2060 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2061 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2068 if WordBool(PanelType
and PANEL_ACID2
) then
2069 if gAcid2
<> nil then
2074 if g_Collide(X
, Y
, Width
, Height
,
2075 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2076 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2083 if WordBool(PanelType
and PANEL_STEP
) then
2084 if gSteps
<> nil then
2089 if g_Collide(X
, Y
, Width
, Height
,
2090 gSteps
[a
].X
, gSteps
[a
].Y
,
2091 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2098 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2099 if gLifts
<> nil then
2104 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2105 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2106 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2107 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2108 g_Collide(X
, Y
, Width
, Height
,
2109 gLifts
[a
].X
, gLifts
[a
].Y
,
2110 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2117 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2118 if gBlockMon
<> nil then
2120 h
:= High(gBlockMon
);
2124 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2125 g_Collide(X
, Y
, Width
, Height
,
2126 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2127 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2135 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2139 function checkPanels (var panels
: TPanelArray
): Boolean;
2144 if panels
= nil then exit
;
2145 for a
:= 0 to High(panels
) do
2147 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2150 texid
:= panels
[a
].GetTextureID();
2157 texid
:= TEXTURE_NONE
;
2159 if not checkPanels(gWater
) then
2160 if not checkPanels(gAcid1
) then
2161 if not checkPanels(gAcid2
) then exit
;
2166 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2168 function checker (obj
: TObject
; tag
: Integer): Boolean;
2173 result
:= false; // don't stop, ever
2175 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2179 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2181 if not (obj
is TPanel
) then
2183 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2187 pan
:= (obj
as TPanel
);
2190 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2192 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2199 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2201 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2208 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2210 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2217 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2219 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2226 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2228 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2235 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2237 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2238 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2239 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2240 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2241 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2248 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2250 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2251 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2260 //TODO: detailed profile
2261 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2263 if gdbg_map_use_grid_coldet
then
2265 if gdbg_map_use_tree_coldet
then
2267 result
:= (mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
, (GridTagWallDoor
or GridTagWater
or GridTagAcid1
or GridTagAcid2
or GridTagStep
or GridTagLift
or GridTagBlockMon
)) <> nil);
2268 if (gdbg_map_dump_coldet_tree_queries
) and (mapTree
.nodesVisited
<> 0) then
2270 //e_WriteLog(Format('map collision: %d nodes visited (%d deep)', [mapTree.nodesVisited, mapTree.nodesDeepVisited]), MSG_NOTIFY);
2271 g_Console_Add(Format('map collision: %d nodes visited (%d deep)', [mapTree
.nodesVisited
, mapTree
.nodesDeepVisited
]));
2276 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2281 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2284 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2289 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2291 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2294 // slightly different from the old code, but meh...
2295 function checker (obj
: TObject
; tag
: Integer): Boolean;
2300 result
:= false; // don't stop, ever
2301 if (tag
<> GridTagWater
) and (tag
<> GridTagAcid1
) and (tag
<> GridTagAcid2
) then exit
;
2302 pan
:= (obj
as TPanel
);
2305 if (tag
= GridTagWater
) then
2307 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2309 result
:= true; // water has highest priority, so stop right here
2310 texid
:= gWater
[a
].GetTextureID();
2315 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2317 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2320 texid
:= gAcid1
[a
].GetTextureID();
2325 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2327 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2330 texid
:= gAcid2
[a
].GetTextureID();
2337 cctype1: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2340 //TODO: detailed profile?
2341 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2343 if gdbg_map_use_grid_coldet
then
2345 texid
:= TEXTURE_NONE
;
2346 if gdbg_map_use_tree_coldet
then
2348 mapTree
.aabbQuery(X
, Y
, Width
, Height
, checker
);
2353 texid := TEXTURE_NONE;
2354 gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
2355 if (cctype1 <> cctype) or (texid1 <> texid) then
2357 e_WriteLog(Format('g_Map_CollideLiquid_Texture(%d, %d, %u, %u): tree(cctype:%d;texid:%u); grid(cctype:%d;texid:%u)', [X, Y, Width, Height, cctype1, texid1, cctype, texid]), MSG_WARNING);
2362 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2368 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2371 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2375 procedure g_Map_EnableWall(ID
: DWORD
);
2380 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2382 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2386 procedure g_Map_DisableWall(ID
: DWORD
);
2391 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2393 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2397 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2402 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2405 tp
:= gRenderForegrounds
[ID
];
2407 tp
:= gRenderBackgrounds
[ID
];
2420 tp
.NextTexture(AnimLoop
);
2421 if g_Game_IsServer
and g_Game_IsNet
then
2422 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2425 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2427 if gLifts
[ID
].LiftType
= t
then
2434 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2436 if LiftType
= 0 then
2437 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2438 else if LiftType
= 1 then
2439 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2440 else if LiftType
= 2 then
2441 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2442 else if LiftType
= 3 then
2443 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2445 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2449 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2452 PointsArray
: Array of TRespawnPoint
;
2455 SetLength(PointsArray
, 0);
2457 if RespawnPoints
= nil then
2460 for a
:= 0 to High(RespawnPoints
) do
2461 if RespawnPoints
[a
].PointType
= PointType
then
2463 SetLength(PointsArray
, Length(PointsArray
)+1);
2464 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2467 if PointsArray
= nil then
2470 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2474 function g_Map_GetPointCount(PointType
: Byte): Word;
2480 if RespawnPoints
= nil then
2483 for a
:= 0 to High(RespawnPoints
) do
2484 if RespawnPoints
[a
].PointType
= PointType
then
2485 Result
:= Result
+ 1;
2488 function g_Map_HaveFlagPoints(): Boolean;
2490 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2493 procedure g_Map_ResetFlag(Flag
: Byte);
2495 with gFlags
[Flag
] do
2501 Direction
:= D_LEFT
;
2502 State
:= FLAG_STATE_NONE
;
2503 if FlagPoints
[Flag
] <> nil then
2505 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2506 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2507 Direction
:= FlagPoints
[Flag
]^.Direction
;
2508 State
:= FLAG_STATE_NORMAL
;
2514 procedure g_Map_DrawFlags();
2517 Mirror
: TMirrorType
;
2519 if gGameSettings
.GameMode
<> GM_CTF
then
2522 for i
:= FLAG_RED
to FLAG_BLUE
do
2524 if State
<> FLAG_STATE_CAPTURED
then
2526 if State
= FLAG_STATE_NONE
then
2529 if Direction
= D_LEFT
then
2531 Mirror
:= M_HORIZONTAL
;
2540 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2542 if g_debug_Frames
then
2544 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2546 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2547 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2553 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2560 procedure SavePanelArray(var panels
: TPanelArray
);
2562 PAMem
: TBinMemoryWriter
;
2565 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2566 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2569 while i
< Length(panels
) do
2571 if panels
[i
].SaveIt
then
2575 // Ñîõðàíÿåì ïàíåëü:
2576 panels
[i
].SaveState(PAMem
);
2581 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2582 PAMem
.SaveToMemory(Mem
);
2586 procedure SaveFlag(flag
: PFlag
);
2589 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2591 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2592 Mem
.WriteByte(flag
^.RespawnType
);
2594 Mem
.WriteByte(flag
^.State
);
2595 // Íàïðàâëåíèå ôëàãà:
2596 if flag
^.Direction
= D_LEFT
then
2602 Obj_SaveState(@flag
^.Obj
, Mem
);
2606 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2608 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2609 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2610 SavePanelArray(gWalls
);
2611 // Ñîõðàíÿåì ïàíåëè ôîíà:
2612 SavePanelArray(gRenderBackgrounds
);
2613 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2614 SavePanelArray(gRenderForegrounds
);
2615 // Ñîõðàíÿåì ïàíåëè âîäû:
2616 SavePanelArray(gWater
);
2617 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2618 SavePanelArray(gAcid1
);
2619 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2620 SavePanelArray(gAcid2
);
2621 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2622 SavePanelArray(gSteps
);
2623 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2624 SavePanelArray(gLifts
);
2627 ///// Ñîõðàíÿåì ìóçûêó: /////
2628 // Ñèãíàòóðà ìóçûêè:
2629 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2632 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2633 if gMusic
.NoMusic
then
2637 Mem
.WriteString(str
, 64);
2638 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2639 dw
:= gMusic
.GetPosition();
2641 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2642 boo
:= gMusic
.SpecPause
;
2643 Mem
.WriteBoolean(boo
);
2646 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2647 Mem
.WriteInt(gTotalMonsters
);
2650 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2651 if gGameSettings
.GameMode
= GM_CTF
then
2653 // Ôëàã Êðàñíîé êîìàíäû:
2654 SaveFlag(@gFlags
[FLAG_RED
]);
2655 // Ôëàã Ñèíåé êîìàíäû:
2656 SaveFlag(@gFlags
[FLAG_BLUE
]);
2660 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2661 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2663 // Î÷êè Êðàñíîé êîìàíäû:
2664 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2665 // Î÷êè Ñèíåé êîìàíäû:
2666 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2671 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2678 procedure LoadPanelArray(var panels
: TPanelArray
);
2680 PAMem
: TBinMemoryReader
;
2683 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2684 PAMem
:= TBinMemoryReader
.Create();
2685 PAMem
.LoadFromMemory(Mem
);
2687 for i
:= 0 to Length(panels
)-1 do
2688 if panels
[i
].SaveIt
then
2694 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2696 // Çàãðóæàåì ïàíåëü:
2697 panels
[i
].LoadState(PAMem
);
2700 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2704 procedure LoadFlag(flag
: PFlag
);
2708 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2710 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2712 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2713 Mem
.ReadByte(flag
^.RespawnType
);
2715 Mem
.ReadByte(flag
^.State
);
2716 // Íàïðàâëåíèå ôëàãà:
2719 flag
^.Direction
:= D_LEFT
2721 flag
^.Direction
:= D_RIGHT
;
2723 Obj_LoadState(@flag
^.Obj
, Mem
);
2730 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2731 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2732 LoadPanelArray(gWalls
);
2733 // Çàãðóæàåì ïàíåëè ôîíà:
2734 LoadPanelArray(gRenderBackgrounds
);
2735 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2736 LoadPanelArray(gRenderForegrounds
);
2737 // Çàãðóæàåì ïàíåëè âîäû:
2738 LoadPanelArray(gWater
);
2739 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2740 LoadPanelArray(gAcid1
);
2741 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2742 LoadPanelArray(gAcid2
);
2743 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2744 LoadPanelArray(gSteps
);
2745 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2746 LoadPanelArray(gLifts
);
2749 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2753 ///// Çàãðóæàåì ìóçûêó: /////
2754 // Ñèãíàòóðà ìóçûêè:
2756 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2758 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2761 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2762 Mem
.ReadString(str
);
2763 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2765 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2766 Mem
.ReadBoolean(boo
);
2767 // Çàïóñêàåì ýòó ìóçûêó:
2768 gMusic
.SetByName(str
);
2769 gMusic
.SpecPause
:= boo
;
2772 gMusic
.SetPosition(dw
);
2775 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2776 Mem
.ReadInt(gTotalMonsters
);
2779 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2780 if gGameSettings
.GameMode
= GM_CTF
then
2782 // Ôëàã Êðàñíîé êîìàíäû:
2783 LoadFlag(@gFlags
[FLAG_RED
]);
2784 // Ôëàã Ñèíåé êîìàíäû:
2785 LoadFlag(@gFlags
[FLAG_BLUE
]);
2789 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2790 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2792 // Î÷êè Êðàñíîé êîìàíäû:
2793 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2794 // Î÷êè Ñèíåé êîìàíäû:
2795 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2800 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2805 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2806 Arr
:= PanelByID
[PanelID
].PWhere
^;
2807 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2808 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);