1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, g_sap
, md5
, xprofiler
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
67 procedure g_Map_DrawBack(dx
, dy
: Integer);
68 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
69 PanelType
: Word; b1x3
: Boolean): Boolean;
70 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
71 procedure g_Map_EnableWall(ID
: DWORD
);
72 procedure g_Map_DisableWall(ID
: DWORD
);
73 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
74 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
75 procedure g_Map_ReAdd_DieTriggers();
76 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
78 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
79 function g_Map_GetPointCount(PointType
: Byte): Word;
81 function g_Map_HaveFlagPoints(): Boolean;
83 procedure g_Map_ResetFlag(Flag
: Byte);
84 procedure g_Map_DrawFlags();
86 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
88 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
89 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
91 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
93 procedure g_Map_ProfilersBegin ();
94 procedure g_Map_ProfilersEnd ();
97 RESPAWNPOINT_PLAYER1
= 1;
98 RESPAWNPOINT_PLAYER2
= 2;
100 RESPAWNPOINT_RED
= 4;
101 RESPAWNPOINT_BLUE
= 5;
109 FLAG_STATE_NORMAL
= 1;
110 FLAG_STATE_DROPPED
= 2;
111 FLAG_STATE_CAPTURED
= 3;
112 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
115 FLAG_TIME
= 720; // 20 seconds
117 SKY_STRETCH
: Single = 1.5;
121 gRenderBackgrounds
: TPanelArray
;
122 gRenderForegrounds
: TPanelArray
;
123 gWater
, gAcid1
, gAcid2
: TPanelArray
;
126 gBlockMon
: TPanelArray
;
127 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
128 //gDOMFlags: array of TFlag;
131 gDoorMap
: array of array of DWORD
;
132 gLiftMap
: array of array of DWORD
;
133 gWADHash
: TMD5Digest
;
134 BackID
: DWORD
= DWORD(-1);
135 gExternalResources
: TStringList
;
137 gdbg_map_use_grid_render
: Boolean = true;
138 gdbg_map_use_grid_coldet
: Boolean = true;
139 gdbg_map_use_sap_draw
: Boolean = true;
140 gdbg_map_use_sap_coldet
: Boolean = false;
141 profMapCollision
: TProfiler
= nil; //WARNING: FOR DEBUGGING ONLY!
146 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
147 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
148 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
149 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
151 ImagingTypes
, Imaging
, ImagingUtility
,
152 ImagingGif
, ImagingNetworkGraphics
;
155 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
156 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
157 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
171 function panelTypeToTag (panelType
: Word): Integer;
174 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
175 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
176 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
177 PANEL_WATER
: result
:= GridTagWater
; // gWater
178 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
179 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
180 PANEL_STEP
: result
:= GridTagStep
; // gSteps
181 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
182 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
183 else result
:= GridTagInvalid
;
190 PWhere
: ^TPanelArray
;
195 PanelById
: array of TPanelID
;
196 Textures
: TLevelTextureArray
;
197 RespawnPoints
: Array of TRespawnPoint
;
198 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
199 //DOMFlagPoints: Array of TFlagPoint;
200 gMapGrid
: TBodyGrid
= nil;
201 gMapSAP
: TSweepAndPrune
= nil;
204 procedure g_Map_ProfilersBegin ();
206 if (profMapCollision
= nil) then profMapCollision
:= TProfiler
.Create('MAP COLLISION', g_profile_history_size
);
207 profMapCollision
.mainBegin(g_profile_collision
);
209 if g_profile_collision
then
211 profMapCollision
.sectionBegin('wall coldet');
212 profMapCollision
.sectionEnd();
213 profMapCollision
.sectionBegin('liquid coldet');
214 profMapCollision
.sectionEnd();
218 procedure g_Map_ProfilersEnd ();
220 if (profMapCollision
<> nil) then profMapCollision
.mainEnd();
224 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
226 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
227 (Texture
= TEXTURE_NAME_ACID1
) or
228 (Texture
= TEXTURE_NAME_ACID2
);
231 procedure CreateDoorMap();
233 PanelArray
: Array of record
239 a
, b
, c
, m
, i
, len
: Integer;
247 SetLength(PanelArray
, len
);
249 for a
:= 0 to High(gWalls
) do
250 if gWalls
[a
].Door
then
252 PanelArray
[i
].X
:= gWalls
[a
].X
;
253 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
254 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
255 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
256 PanelArray
[i
].Active
:= True;
257 PanelArray
[i
].PanelID
:= a
;
263 SetLength(PanelArray
, len
);
274 SetLength(gDoorMap
, 0);
276 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
279 if PanelArray
[a
].Active
then
281 PanelArray
[a
].Active
:= False;
282 m
:= Length(gDoorMap
);
283 SetLength(gDoorMap
, m
+1);
284 SetLength(gDoorMap
[m
], 1);
285 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
293 if PanelArray
[b
].Active
then
294 for c
:= 0 to High(gDoorMap
[m
]) do
295 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
296 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
297 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
298 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
299 gWalls
[gDoorMap
[m
, c
]].X
,
300 gWalls
[gDoorMap
[m
, c
]].Y
,
301 gWalls
[gDoorMap
[m
, c
]].Width
,
302 gWalls
[gDoorMap
[m
, c
]].Height
) then
304 PanelArray
[b
].Active
:= False;
305 SetLength(gDoorMap
[m
],
306 Length(gDoorMap
[m
])+1);
307 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
313 g_Game_StepLoading();
319 procedure CreateLiftMap();
321 PanelArray
: Array of record
326 a
, b
, c
, len
, i
, j
: Integer;
332 len
:= Length(gLifts
);
333 SetLength(PanelArray
, len
);
335 for a
:= 0 to len
-1 do
337 PanelArray
[a
].X
:= gLifts
[a
].X
;
338 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
339 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
340 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
341 PanelArray
[a
].Active
:= True;
344 SetLength(gLiftMap
, len
);
347 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
349 for a
:= 0 to len
-1 do
350 if PanelArray
[a
].Active
then
352 PanelArray
[a
].Active
:= False;
353 SetLength(gLiftMap
[i
], 32);
361 for b
:= 0 to len
-1 do
362 if PanelArray
[b
].Active
then
364 if g_CollideAround(PanelArray
[b
].X
,
367 PanelArray
[b
].Height
,
368 PanelArray
[gLiftMap
[i
, c
]].X
,
369 PanelArray
[gLiftMap
[i
, c
]].Y
,
370 PanelArray
[gLiftMap
[i
, c
]].Width
,
371 PanelArray
[gLiftMap
[i
, c
]].Height
) then
373 PanelArray
[b
].Active
:= False;
375 if j
> High(gLiftMap
[i
]) then
376 SetLength(gLiftMap
[i
],
377 Length(gLiftMap
[i
])+32);
386 SetLength(gLiftMap
[i
], j
+1);
389 g_Game_StepLoading();
392 SetLength(gLiftMap
, i
);
397 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
398 CurTex
: Integer; sav
: Boolean): Integer;
401 panels
: ^TPanelArray
;
405 case PanelRec
.PanelType
of
406 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
409 panels
:= @gRenderBackgrounds
;
411 panels
:= @gRenderForegrounds
;
420 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
423 panels
:= @gBlockMon
;
428 len
:= Length(panels
^);
429 SetLength(panels
^, len
+ 1);
431 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
432 panels
^[len
].ArrIdx
:= len
;
434 panels
^[len
].SaveIt
:= True;
438 len
:= Length(PanelByID
);
439 SetLength(PanelByID
, len
+ 1);
440 PanelByID
[len
].PWhere
:= panels
;
441 PanelByID
[len
].PArrID
:= Result
;
444 function CreateNullTexture(RecName
: String): Integer;
446 SetLength(Textures
, Length(Textures
)+1);
447 result
:= High(Textures
);
449 with Textures
[High(Textures
)] do
451 TextureName
:= RecName
;
455 TextureID
:= TEXTURE_NONE
;
459 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
462 TextureData
: Pointer;
463 WADName
, txname
: String;
464 a
, ResLength
: Integer;
468 if Textures
<> nil then
469 for a
:= 0 to High(Textures
) do
470 if Textures
[a
].TextureName
= RecName
then
471 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
476 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
477 if (RecName
= TEXTURE_NAME_WATER
) or
478 (RecName
= TEXTURE_NAME_ACID1
) or
479 (RecName
= TEXTURE_NAME_ACID2
) then
481 SetLength(Textures
, Length(Textures
)+1);
483 with Textures
[High(Textures
)] do
485 TextureName
:= RecName
;
487 if TextureName
= TEXTURE_NAME_WATER
then
488 TextureID
:= TEXTURE_SPECIAL_WATER
490 if TextureName
= TEXTURE_NAME_ACID1
then
491 TextureID
:= TEXTURE_SPECIAL_ACID1
493 if TextureName
= TEXTURE_NAME_ACID2
then
494 TextureID
:= TEXTURE_SPECIAL_ACID2
;
499 result
:= High(Textures
);
503 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
504 WADName
:= g_ExtractWadName(RecName
);
506 WAD
:= TWADFile
.Create();
508 if WADName
<> '' then
509 WADName
:= GameDir
+'/wads/'+WADName
513 WAD
.ReadFile(WADName
);
517 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
519 FreeMem(TextureData);
520 RecName := 'COMMON\ALIEN';
524 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
526 SetLength(Textures
, Length(Textures
)+1);
527 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
529 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
530 @Textures
[High(Textures
)].Width
,
531 @Textures
[High(Textures
)].Height
);
532 FreeMem(TextureData
);
533 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
534 Textures
[High(Textures
)].Anim
:= False;
536 result
:= High(Textures
);
538 else // Íåò òàêîãî ðåóñðñà â WAD'å
540 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
543 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
544 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
551 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
554 TextureWAD
: PChar = nil;
555 TextData
: Pointer = nil;
556 TextureData
: Pointer = nil;
560 TextureResource
: String;
561 _width
, _height
, _framecount
, _speed
: Integer;
562 _backanimation
: Boolean;
564 ia
: TDynImageDataArray
= nil;
565 f
, c
, frdelay
, frloop
: Integer;
569 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
571 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
572 WADName
:= g_ExtractWadName(RecName
);
574 WAD
:= TWADFile
.Create();
576 if WADName
<> '' then
577 WADName
:= GameDir
+'/wads/'+WADName
581 WAD
.ReadFile(WADName
);
583 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
587 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
588 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
594 if WADName = Map then
596 //FreeMem(TextureWAD);
597 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
603 if ResLength
< 6 then
605 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
609 // ýòî ïòèöà? ýòî ñàìîë¸ò?
610 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
611 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
613 // íåò, ýòî ñóïåðìåí!
614 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
616 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
620 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
621 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
623 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
627 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
629 TextureResource
:= cfg
.ReadStr('', 'resource', '');
630 if TextureResource
= '' then
632 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
636 _width
:= cfg
.ReadInt('', 'framewidth', 0);
637 _height
:= cfg
.ReadInt('', 'frameheight', 0);
638 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
639 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
640 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
645 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
646 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
648 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
655 SetLength(Textures
, Length(Textures
)+1);
656 with Textures
[High(Textures
)] do
658 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
659 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
661 TextureName
:= RecName
;
665 FramesCount
:= _framecount
;
667 result
:= High(Textures
);
671 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
677 // try animated image
679 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
680 if length(imgfmt) = 0 then
682 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
686 GlobalMetadata
.ClearMetaItems();
687 GlobalMetadata
.ClearMetaItemsForSaving();
688 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
690 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
693 if length(ia
) = 0 then
695 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
702 _width
:= ia
[0].width
;
703 _height
:= ia
[0].height
;
704 _framecount
:= length(ia
);
706 _backanimation
:= false;
709 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
711 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
713 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
715 if f
< 0 then f
:= 0;
718 if c
< 13 then c
:= 0 else c
:= 1;
720 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
725 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
727 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
729 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
731 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
735 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
736 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
737 f
:= ord(_backanimation
);
738 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
);
740 SetLength(Textures
, Length(Textures
)+1);
741 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
742 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
744 Textures
[High(Textures
)].TextureName
:= RecName
;
745 Textures
[High(Textures
)].Width
:= _width
;
746 Textures
[High(Textures
)].Height
:= _height
;
747 Textures
[High(Textures
)].Anim
:= True;
748 Textures
[High(Textures
)].FramesCount
:= length(ia
);
749 Textures
[High(Textures
)].Speed
:= _speed
;
750 result
:= High(Textures
);
751 //writeln(' CREATED!');
755 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
759 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
762 if TextureWAD
<> nil then FreeMem(TextureWAD
);
763 if TextData
<> nil then FreeMem(TextData
);
764 if TextureData
<> nil then FreeMem(TextureData
);
768 procedure CreateItem(Item
: TItemRec_1
);
770 if g_Game_IsClient
then Exit
;
772 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
773 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
776 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
777 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
780 procedure CreateArea(Area
: TAreaRec_1
);
785 case Area
.AreaType
of
786 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
787 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
789 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
790 with RespawnPoints
[High(RespawnPoints
)] do
794 Direction
:= TDirection(Area
.Direction
);
796 case Area
.AreaType
of
797 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
798 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
799 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
800 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
801 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
806 AREA_REDFLAG
, AREA_BLUEFLAG
:
808 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
810 if FlagPoints
[a
] <> nil then Exit
;
814 with FlagPoints
[a
]^ do
816 X
:= Area
.X
-FLAGRECT
.X
;
817 Y
:= Area
.Y
-FLAGRECT
.Y
;
818 Direction
:= TDirection(Area
.Direction
);
824 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
825 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
828 Animation
:= TAnimation
.Create(id
, True, 8);
829 Obj
.Rect
:= FLAGRECT
;
837 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
838 with DOMFlagPoints[High(DOMFlagPoints)] do
842 Direction := TDirection(Area.Direction);
845 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
850 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
854 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
860 Width
:= Trigger
.Width
;
861 Height
:= Trigger
.Height
;
862 Enabled
:= ByteBool(Trigger
.Enabled
);
863 TexturePanel
:= Trigger
.TexturePanel
;
864 TexturePanelType
:= fTexturePanel1Type
;
865 ShotPanelType
:= fTexturePanel2Type
;
866 TriggerType
:= Trigger
.TriggerType
;
867 ActivateType
:= Trigger
.ActivateType
;
868 Keys
:= Trigger
.Keys
;
869 Data
.Default
:= Trigger
.DATA
;
872 g_Triggers_Create(_trigger
);
875 procedure CreateMonster(monster
: TMonsterRec_1
);
879 if g_Game_IsClient
then Exit
;
881 if (gGameSettings
.GameType
= GT_SINGLE
)
882 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
884 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
885 TDirection(monster
.Direction
));
887 if gTriggers
<> nil then
888 for a
:= 0 to High(gTriggers
) do
889 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
890 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
891 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
892 gMonsters
[i
].AddTrigger(a
);
894 if monster
.MonsterType
<> MONSTER_BARREL
then
899 procedure g_Map_ReAdd_DieTriggers();
903 if g_Game_IsClient
then Exit
;
905 for i
:= 0 to High(gMonsters
) do
906 if gMonsters
[i
] <> nil then
908 gMonsters
[i
].ClearTriggers();
910 for a
:= 0 to High(gTriggers
) do
911 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
912 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
913 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
914 gMonsters
[i
].AddTrigger(a
);
918 function extractWadName(resourceName
: string): string;
922 posN
:= Pos(':', resourceName
);
924 Result
:= Copy(resourceName
, 0, posN
-1)
929 procedure addResToExternalResList(res
: string);
931 res
:= extractWadName(res
);
932 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
933 gExternalResources
.Add(res
);
936 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
938 textures
: TTexturesRec1Array
;
939 mapHeader
: TMapHeaderRec_1
;
941 resFile
: String = '';
943 if gExternalResources
= nil then
944 gExternalResources
:= TStringList
.Create
;
946 gExternalResources
.Clear
;
947 textures
:= mapReader
.GetTextures();
948 for i
:= 0 to High(textures
) do
950 addResToExternalResList(resFile
);
955 mapHeader
:= mapReader
.GetMapHeader
;
957 addResToExternalResList(mapHeader
.MusicName
);
958 addResToExternalResList(mapHeader
.SkyName
);
961 procedure mapCreateGrid ();
963 mapX0
: Integer = $3fffffff;
964 mapY0
: Integer = $3fffffff;
965 mapX1
: Integer = -$3fffffff;
966 mapY1
: Integer = -$3fffffff;
968 procedure fixMinMax (var panels
: TPanelArray
);
972 for idx
:= 0 to High(panels
) do
974 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
975 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
976 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
977 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
978 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
982 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
986 tag
:= panelTypeToTag(tag
);
987 for idx
:= High(panels
) downto 0 do
989 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
990 gMapSAP
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
1001 fixMinMax(gRenderBackgrounds
);
1002 fixMinMax(gRenderForegrounds
);
1008 fixMinMax(gBlockMon
);
1010 if (mapX0
< 0) or (mapY0
< 0) then
1012 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
1013 //raise Exception.Create('we are fucked');
1016 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
1017 gMapSAP
:= TSweepAndPrune
.Create();
1019 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1020 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1021 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1022 addPanelsToGrid(gWater
, PANEL_WATER
);
1023 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1024 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1025 addPanelsToGrid(gSteps
, PANEL_STEP
);
1026 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
1027 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
1029 gMapGrid
.dumpStats();
1030 gMapSAP
.dumpStats();
1033 function g_Map_Load(Res
: String): Boolean;
1035 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1036 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1039 MapReader
: TMapReader_1
;
1040 Header
: TMapHeaderRec_1
;
1041 _textures
: TTexturesRec1Array
;
1042 _texnummap
: array of Integer; // `_textures` -> `Textures`
1043 panels
: TPanelsRec1Array
;
1044 items
: TItemsRec1Array
;
1045 monsters
: TMonsterRec1Array
;
1046 areas
: TAreasRec1Array
;
1047 triggers
: TTriggersRec1Array
;
1048 a
, b
, c
, k
: Integer;
1050 AddTextures
: TAddTextureArray
;
1051 texture
: TTextureRec_1
;
1052 TriggersTable
: Array of record
1053 TexturePanel
: Integer;
1058 FileName
, mapResName
, s
, TexName
: String;
1061 ok
, isAnim
, trigRef
: Boolean;
1062 CurTex
, ntn
: Integer;
1071 gMapInfo
.Map
:= Res
;
1072 TriggersTable
:= nil;
1073 FillChar(texture
, SizeOf(texture
), 0);
1075 sfsGCDisable(); // temporary disable removing of temporary volumes
1078 FileName
:= g_ExtractWadName(Res
);
1079 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1080 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1082 WAD
:= TWADFile
.Create();
1083 if not WAD
.ReadFile(FileName
) then
1085 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1089 //k8: why loader ignores path here?
1090 mapResName
:= g_ExtractFileName(Res
);
1091 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1093 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1101 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1102 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1103 MapReader
:= TMapReader_1
.Create();
1105 if not MapReader
.LoadMap(Data
) then
1107 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1114 generateExternalResourcesList(MapReader
);
1115 // Çàãðóçêà òåêñòóð:
1116 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1117 _textures
:= MapReader
.GetTextures();
1120 // Äîáàâëåíèå òåêñòóð â Textures[]:
1121 if _textures
<> nil then
1123 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1124 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1125 SetLength(_texnummap
, length(_textures
));
1127 for a
:= 0 to High(_textures
) do
1130 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1131 for b
:= 1 to Length(s
) do
1137 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1138 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1139 // Àíèìèðîâàííàÿ òåêñòóðà:
1140 if ByteBool(_textures
[a
].Anim
) then
1142 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1145 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1146 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1149 else // Îáû÷íàÿ òåêñòóðà:
1150 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1153 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1154 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1157 _texnummap
[a
] := ntn
; // fix texture number
1158 g_Game_StepLoading();
1162 // Çàãðóçêà òðèããåðîâ:
1163 gTriggerClientID
:= 0;
1164 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1165 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1166 triggers
:= MapReader
.GetTriggers();
1168 // Çàãðóçêà ïàíåëåé:
1169 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1170 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1171 panels
:= MapReader
.GetPanels();
1173 // check texture numbers for panels
1174 for a
:= 0 to High(panels
) do
1176 if panels
[a
].TextureNum
> High(_textures
) then
1178 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1182 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1185 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1186 if triggers
<> nil then
1188 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1189 SetLength(TriggersTable
, Length(triggers
));
1190 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1192 for a
:= 0 to High(TriggersTable
) do
1194 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1195 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1197 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1198 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1200 TriggersTable
[a
].LiftPanel
:= -1;
1202 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1203 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1204 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1205 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1207 TriggersTable
[a
].DoorPanel
:= -1;
1209 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1210 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1212 TriggersTable
[a
].ShotPanel
:= -1;
1214 g_Game_StepLoading();
1219 if panels
<> nil then
1221 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1222 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1224 for a
:= 0 to High(panels
) do
1226 SetLength(AddTextures
, 0);
1229 if _textures
<> nil then
1231 texture
:= _textures
[panels
[a
].TextureNum
];
1239 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1240 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1242 if (TriggersTable
<> nil) and (_textures
<> nil) then
1243 for b
:= 0 to High(TriggersTable
) do
1244 if (TriggersTable
[b
].TexturePanel
= a
)
1245 or (TriggersTable
[b
].ShotPanel
= a
) then
1254 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1256 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1259 for c
:= Len
downto 1 do
1267 // Ñïåö-òåêñòóðû çàïðåùåíû:
1268 if g_Map_IsSpecialTexture(s
) then
1271 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1272 ok
:= g_Texture_NumNameFindStart(s
);
1274 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1275 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1278 k
:= NNF_NAME_BEFORE
;
1279 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1280 while ok
or (k
= NNF_NAME_BEFORE
) or
1281 (k
= NNF_NAME_EQUALS
) do
1283 k
:= g_Texture_NumNameFindNext(TexName
);
1285 if (k
= NNF_NAME_BEFORE
) or
1286 (k
= NNF_NAME_AFTER
) then
1288 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1289 if ByteBool(texture
.Anim
) then
1290 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1292 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1294 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1296 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1300 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1302 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1304 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1306 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1310 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1313 for c
:= 0 to High(Textures
) do
1314 if Textures
[c
].TextureName
= TexName
then
1316 SetLength(AddTextures
, Length(AddTextures
)+1);
1317 AddTextures
[High(AddTextures
)].Texture
:= c
;
1318 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1324 if k
= NNF_NAME_EQUALS
then
1326 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1327 SetLength(AddTextures
, Length(AddTextures
)+1);
1328 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1329 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1330 CurTex
:= High(AddTextures
);
1338 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1339 end; // if ok - ññûëàþòñÿ òðèããåðû
1343 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1344 SetLength(AddTextures
, 1);
1345 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1346 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1350 //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);
1352 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1353 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1355 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1356 if TriggersTable
<> nil then
1357 for b
:= 0 to High(TriggersTable
) do
1359 // Òðèããåð äâåðè/ëèôòà:
1360 if (TriggersTable
[b
].LiftPanel
= a
) or
1361 (TriggersTable
[b
].DoorPanel
= a
) then
1362 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1363 // Òðèããåð ñìåíû òåêñòóðû:
1364 if TriggersTable
[b
].TexturePanel
= a
then
1365 triggers
[b
].TexturePanel
:= PanelID
;
1366 // Òðèããåð "Òóðåëü":
1367 if TriggersTable
[b
].ShotPanel
= a
then
1368 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1371 g_Game_StepLoading();
1375 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1376 if (triggers
<> nil) and not gLoadGameMode
then
1378 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1379 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1380 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1381 for a
:= 0 to High(triggers
) do
1383 if triggers
[a
].TexturePanel
<> -1 then
1384 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1387 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1388 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1389 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1392 CreateTrigger(triggers
[a
], b
, c
);
1396 // Çàãðóçêà ïðåäìåòîâ:
1397 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1398 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1399 items
:= MapReader
.GetItems();
1401 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1402 if (items
<> nil) and not gLoadGameMode
then
1404 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1405 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1406 for a
:= 0 to High(items
) do
1407 CreateItem(Items
[a
]);
1410 // Çàãðóçêà îáëàñòåé:
1411 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1412 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1413 areas
:= MapReader
.GetAreas();
1415 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1416 if areas
<> nil then
1418 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1419 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1420 for a
:= 0 to High(areas
) do
1421 CreateArea(areas
[a
]);
1424 // Çàãðóçêà ìîíñòðîâ:
1425 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1426 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1427 monsters
:= MapReader
.GetMonsters();
1429 gTotalMonsters
:= 0;
1431 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1432 if (monsters
<> nil) and not gLoadGameMode
then
1434 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1435 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1436 for a
:= 0 to High(monsters
) do
1437 CreateMonster(monsters
[a
]);
1440 // Çàãðóçêà îïèñàíèÿ êàðòû:
1441 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1442 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1443 Header
:= MapReader
.GetMapHeader();
1449 Name
:= Header
.MapName
;
1450 Description
:= Header
.MapDescription
;
1451 Author
:= Header
.MapAuthor
;
1452 MusicName
:= Header
.MusicName
;
1453 SkyName
:= Header
.SkyName
;
1454 Height
:= Header
.Height
;
1455 Width
:= Header
.Width
;
1459 if gMapInfo
.SkyName
<> '' then
1461 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1462 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1463 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1465 if FileName
<> '' then
1466 FileName
:= GameDir
+'/wads/'+FileName
1469 FileName
:= g_ExtractWadName(Res
);
1472 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1473 if g_Texture_CreateWAD(BackID
, s
) then
1475 g_Game_SetupScreenSize();
1478 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1483 if gMapInfo
.MusicName
<> '' then
1485 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1486 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1487 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1489 if FileName
<> '' then
1490 FileName
:= GameDir
+'/wads/'+FileName
1493 FileName
:= g_ExtractWadName(Res
);
1496 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1497 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1500 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1503 // Îñòàëüíûå óñòàíâêè:
1511 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1512 if not gLoadGameMode
then
1515 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1521 TriggersTable
:= nil;
1524 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1525 if ok
and (not gLoadGameMode
) then
1527 gMusic
.SetByName(gMapInfo
.MusicName
);
1531 gMusic
.SetByName('');
1533 sfsGCEnable(); // enable releasing unused volumes
1536 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1539 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1543 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1546 MapReader
: TMapReader_1
;
1547 Header
: TMapHeaderRec_1
;
1552 FillChar(Result
, SizeOf(Result
), 0);
1553 FileName
:= g_ExtractWadName(Res
);
1555 WAD
:= TWADFile
.Create();
1556 if not WAD
.ReadFile(FileName
) then
1562 //k8: it ignores path again
1563 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1571 MapReader
:= TMapReader_1
.Create();
1573 if not MapReader
.LoadMap(Data
) then
1575 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1576 ZeroMemory(@Header
, SizeOf(Header
));
1577 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1578 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1582 Header
:= MapReader
.GetMapHeader();
1583 Result
.Name
:= Header
.MapName
;
1584 Result
.Description
:= Header
.MapDescription
;
1591 Result
.Author
:= Header
.MapAuthor
;
1592 Result
.Height
:= Header
.Height
;
1593 Result
.Width
:= Header
.Width
;
1596 function g_Map_GetMapsList(WADName
: string): SArray
;
1603 WAD
:= TWADFile
.Create();
1604 if not WAD
.ReadFile(WADName
) then
1609 ResList
:= WAD
.GetMapResources();
1610 if ResList
<> nil then
1612 for a
:= 0 to High(ResList
) do
1614 SetLength(Result
, Length(Result
)+1);
1615 Result
[High(Result
)] := ResList
[a
];
1621 function g_Map_Exist(Res
: string): Boolean;
1624 FileName
, mnn
: string;
1630 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1632 WAD
:= TWADFile
.Create
;
1633 if not WAD
.ReadFile(FileName
) then
1639 ResList
:= WAD
.GetMapResources();
1642 mnn
:= g_ExtractFileName(Res
);
1643 if ResList
<> nil then
1644 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1651 procedure g_Map_Free();
1655 procedure FreePanelArray(var panels
: TPanelArray
);
1660 if panels
<> nil then
1662 for i
:= 0 to High(panels
) do
1675 RespawnPoints
:= nil;
1676 if FlagPoints
[FLAG_RED
] <> nil then
1678 Dispose(FlagPoints
[FLAG_RED
]);
1679 FlagPoints
[FLAG_RED
] := nil;
1681 if FlagPoints
[FLAG_BLUE
] <> nil then
1683 Dispose(FlagPoints
[FLAG_BLUE
]);
1684 FlagPoints
[FLAG_BLUE
] := nil;
1686 //DOMFlagPoints := nil;
1690 if Textures
<> nil then
1692 for a
:= 0 to High(Textures
) do
1693 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1694 if Textures
[a
].Anim
then
1695 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1697 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1698 e_DeleteTexture(Textures
[a
].TextureID
);
1703 FreePanelArray(gWalls
);
1704 FreePanelArray(gRenderBackgrounds
);
1705 FreePanelArray(gRenderForegrounds
);
1706 FreePanelArray(gWater
);
1707 FreePanelArray(gAcid1
);
1708 FreePanelArray(gAcid2
);
1709 FreePanelArray(gSteps
);
1710 FreePanelArray(gLifts
);
1711 FreePanelArray(gBlockMon
);
1713 if BackID
<> DWORD(-1) then
1717 e_DeleteTexture(BackID
);
1718 BackID
:= DWORD(-1);
1721 g_Game_StopAllSounds(False);
1723 g_Sound_Delete(gMapInfo
.MusicName
);
1725 gMapInfo
.Name
:= '';
1726 gMapInfo
.Description
:= '';
1727 gMapInfo
.MusicName
:= '';
1728 gMapInfo
.Height
:= 0;
1729 gMapInfo
.Width
:= 0;
1737 procedure g_Map_Update();
1743 procedure UpdatePanelArray(var panels
: TPanelArray
);
1748 if panels
<> nil then
1749 for i
:= 0 to High(panels
) do
1754 UpdatePanelArray(gWalls
);
1755 UpdatePanelArray(gRenderBackgrounds
);
1756 UpdatePanelArray(gRenderForegrounds
);
1757 UpdatePanelArray(gWater
);
1758 UpdatePanelArray(gAcid1
);
1759 UpdatePanelArray(gAcid2
);
1760 UpdatePanelArray(gSteps
);
1762 if gGameSettings
.GameMode
= GM_CTF
then
1764 for a
:= FLAG_RED
to FLAG_BLUE
do
1765 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1768 if gFlags
[a
].Animation
<> nil then
1769 gFlags
[a
].Animation
.Update();
1771 m
:= g_Obj_Move(@Obj
, True, True);
1773 if gTime
mod (GAME_TICK
*2) <> 0 then
1776 // Ñîïðîòèâëåíèå âîçäóõà:
1777 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1779 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1780 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1783 gFlags
[a
].CaptureTime
:= 0;
1784 if a
= FLAG_RED
then
1785 s
:= _lc
[I_PLAYER_FLAG_RED
]
1787 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1788 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1790 if g_Game_IsNet
then
1791 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1798 // Èãðîê áåðåò ôëàã:
1799 if gPlayers
<> nil then
1801 j
:= Random(Length(gPlayers
)) - 1;
1803 for d
:= 0 to High(gPlayers
) do
1806 if j
> High(gPlayers
) then
1809 if gPlayers
[j
] <> nil then
1810 if gPlayers
[j
].Live
and
1811 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1813 if gPlayers
[j
].GetFlag(a
) then
1823 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1825 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1829 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1831 // alas, no visible set
1832 for idx
:= 0 to High(panels
) do
1834 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1841 PANEL_WALL
: DrawPanels(0, gWalls
);
1842 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1843 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1844 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1845 PANEL_WATER
: DrawPanels(3, gWater
);
1846 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1847 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1848 PANEL_STEP
: DrawPanels(6, gSteps
);
1854 gDrawPanelList
: TBinaryHeapObj
= nil;
1856 function dplLess (a
, b
: TObject
): Boolean;
1858 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1861 procedure dplClear ();
1863 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1866 procedure dplAddPanel (pan
: TPanel
);
1868 if pan
= nil then exit
;
1869 gDrawPanelList
.insert(pan
);
1873 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1877 function checker (obj
: TObject
; tag
: Integer): Boolean;
1881 result
:= false; // don't stop, ever
1882 if (tag
<> ptag
) then exit
;
1883 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1885 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1886 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1887 //pan := (obj as TPanel);
1888 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1890 pan
:= (obj
as TPanel
);
1891 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1892 //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);
1896 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1901 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1903 // alas, no visible set
1904 for idx
:= 0 to High(panels
) do
1906 if not (drawDoors
xor panels
[idx
].Door
) then
1910 if (pan.Width < 1) or (pan.Height < 1) then continue;
1911 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1912 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1915 //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);
1922 //g_Map_DrawPanelsOld(PanelType); exit;
1923 //e_WriteLog('==================', MSG_NOTIFY);
1924 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1926 ptag
:= panelTypeToTag(PanelType
);
1928 if gdbg_map_use_grid_render
then
1930 if gdbg_map_use_sap_draw
then
1932 gMapSAP
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1936 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1938 // sort and draw the list (we need to sort it, or rendering is fucked)
1939 while gDrawPanelList
.count
> 0 do
1941 (gDrawPanelList
.front() as TPanel
).Draw();
1942 gDrawPanelList
.popFront();
1947 //e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1949 PANEL_WALL
: DrawPanels(0, gWalls
);
1950 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1951 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1952 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1953 PANEL_WATER
: DrawPanels(3, gWater
);
1954 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1955 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1956 PANEL_STEP
: DrawPanels(6, gSteps
);
1960 //e_WriteLog('==================', MSG_NOTIFY);
1964 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1965 function checker (obj
: TObject
; tag
: Integer): Boolean;
1969 result
:= false; // don't stop, ever
1970 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1971 pan
:= (obj
as TPanel
);
1972 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1976 if gdbg_map_use_sap_draw
then
1978 gMapSAP
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1982 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1987 procedure g_Map_DrawBack(dx
, dy
: Integer);
1989 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1990 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1992 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1995 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1996 PanelType
: Word; b1x3
: Boolean): Boolean;
2002 if WordBool(PanelType
and PANEL_WALL
) then
2003 if gWalls
<> nil then
2008 if gWalls
[a
].Enabled
and
2009 g_Collide(X
, Y
, Width
, Height
,
2010 gWalls
[a
].X
, gWalls
[a
].Y
,
2011 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2018 if WordBool(PanelType
and PANEL_WATER
) then
2019 if gWater
<> nil then
2024 if g_Collide(X
, Y
, Width
, Height
,
2025 gWater
[a
].X
, gWater
[a
].Y
,
2026 gWater
[a
].Width
, gWater
[a
].Height
) then
2033 if WordBool(PanelType
and PANEL_ACID1
) then
2034 if gAcid1
<> nil then
2039 if g_Collide(X
, Y
, Width
, Height
,
2040 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2041 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2048 if WordBool(PanelType
and PANEL_ACID2
) then
2049 if gAcid2
<> nil then
2054 if g_Collide(X
, Y
, Width
, Height
,
2055 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2056 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2063 if WordBool(PanelType
and PANEL_STEP
) then
2064 if gSteps
<> nil then
2069 if g_Collide(X
, Y
, Width
, Height
,
2070 gSteps
[a
].X
, gSteps
[a
].Y
,
2071 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2078 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2079 if gLifts
<> nil then
2084 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2085 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2086 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2087 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2088 g_Collide(X
, Y
, Width
, Height
,
2089 gLifts
[a
].X
, gLifts
[a
].Y
,
2090 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2097 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2098 if gBlockMon
<> nil then
2100 h
:= High(gBlockMon
);
2104 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2105 g_Collide(X
, Y
, Width
, Height
,
2106 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2107 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2115 function g_Map_CollideLiquid_TextureOld(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2119 function checkPanels (var panels
: TPanelArray
): Boolean;
2124 if panels
= nil then exit
;
2125 for a
:= 0 to High(panels
) do
2127 if g_Collide(X
, Y
, Width
, Height
, panels
[a
].X
, panels
[a
].Y
, panels
[a
].Width
, panels
[a
].Height
) then
2130 texid
:= panels
[a
].GetTextureID();
2137 texid
:= TEXTURE_NONE
;
2139 if not checkPanels(gWater
) then
2140 if not checkPanels(gAcid1
) then
2141 if not checkPanels(gAcid2
) then exit
;
2146 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2148 function checker (obj
: TObject
; tag
: Integer): Boolean;
2153 result
:= false; // don't stop, ever
2155 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2159 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2161 if not (obj
is TPanel
) then
2163 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2167 pan
:= (obj
as TPanel
);
2170 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2172 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2179 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2181 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2188 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2190 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2197 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2199 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2206 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2208 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2215 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2217 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2218 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2219 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2220 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2221 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2228 if WordBool(PanelType
and PANEL_BLOCKMON
) and (tag
= GridTagBlockMon
) then
2230 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2231 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2240 //TODO: detailed profile
2241 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('wall coldet');
2243 if gdbg_map_use_grid_coldet
then
2245 if gdbg_map_use_sap_coldet
then
2247 gMapSAP
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2251 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2256 result
:= g_Map_CollidePanelOld(X
, Y
, Width
, Height
, PanelType
, b1x3
);
2259 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2264 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2266 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2269 // slightly different from the old code, but meh...
2270 function checker (obj
: TObject
; tag
: Integer): Boolean;
2275 result
:= false; // don't stop, ever
2276 pan
:= (obj
as TPanel
);
2279 if (tag
= GridTagWater
) then
2281 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2283 result
:= true; // water has highest priority, so stop right here
2284 texid
:= gWater
[a
].GetTextureID();
2289 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2291 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2294 texid
:= gAcid1
[a
].GetTextureID();
2299 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2301 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2304 texid
:= gAcid2
[a
].GetTextureID();
2311 //TODO: detailed profile?
2312 if (profMapCollision
<> nil) then profMapCollision
.sectionBeginAccum('liquid coldet');
2314 if gdbg_map_use_grid_coldet
then
2316 texid
:= TEXTURE_NONE
;
2317 if gdbg_map_use_sap_coldet
then
2319 gMapSAP
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2323 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2329 result
:= g_Map_CollideLiquid_TextureOld(X
, Y
, Width
, Height
);
2332 if (profMapCollision
<> nil) then profMapCollision
.sectionEnd();
2336 procedure g_Map_EnableWall(ID
: DWORD
);
2341 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2343 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2347 procedure g_Map_DisableWall(ID
: DWORD
);
2352 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2354 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2358 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2363 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2366 tp
:= gRenderForegrounds
[ID
];
2368 tp
:= gRenderBackgrounds
[ID
];
2381 tp
.NextTexture(AnimLoop
);
2382 if g_Game_IsServer
and g_Game_IsNet
then
2383 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2386 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2388 if gLifts
[ID
].LiftType
= t
then
2395 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2397 if LiftType
= 0 then
2398 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2399 else if LiftType
= 1 then
2400 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2401 else if LiftType
= 2 then
2402 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2403 else if LiftType
= 3 then
2404 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2406 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2410 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2413 PointsArray
: Array of TRespawnPoint
;
2416 SetLength(PointsArray
, 0);
2418 if RespawnPoints
= nil then
2421 for a
:= 0 to High(RespawnPoints
) do
2422 if RespawnPoints
[a
].PointType
= PointType
then
2424 SetLength(PointsArray
, Length(PointsArray
)+1);
2425 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2428 if PointsArray
= nil then
2431 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2435 function g_Map_GetPointCount(PointType
: Byte): Word;
2441 if RespawnPoints
= nil then
2444 for a
:= 0 to High(RespawnPoints
) do
2445 if RespawnPoints
[a
].PointType
= PointType
then
2446 Result
:= Result
+ 1;
2449 function g_Map_HaveFlagPoints(): Boolean;
2451 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2454 procedure g_Map_ResetFlag(Flag
: Byte);
2456 with gFlags
[Flag
] do
2462 Direction
:= D_LEFT
;
2463 State
:= FLAG_STATE_NONE
;
2464 if FlagPoints
[Flag
] <> nil then
2466 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2467 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2468 Direction
:= FlagPoints
[Flag
]^.Direction
;
2469 State
:= FLAG_STATE_NORMAL
;
2475 procedure g_Map_DrawFlags();
2478 Mirror
: TMirrorType
;
2480 if gGameSettings
.GameMode
<> GM_CTF
then
2483 for i
:= FLAG_RED
to FLAG_BLUE
do
2485 if State
<> FLAG_STATE_CAPTURED
then
2487 if State
= FLAG_STATE_NONE
then
2490 if Direction
= D_LEFT
then
2492 Mirror
:= M_HORIZONTAL
;
2501 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2503 if g_debug_Frames
then
2505 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2507 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2508 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2514 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2521 procedure SavePanelArray(var panels
: TPanelArray
);
2523 PAMem
: TBinMemoryWriter
;
2526 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2527 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2530 while i
< Length(panels
) do
2532 if panels
[i
].SaveIt
then
2536 // Ñîõðàíÿåì ïàíåëü:
2537 panels
[i
].SaveState(PAMem
);
2542 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2543 PAMem
.SaveToMemory(Mem
);
2547 procedure SaveFlag(flag
: PFlag
);
2550 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2552 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2553 Mem
.WriteByte(flag
^.RespawnType
);
2555 Mem
.WriteByte(flag
^.State
);
2556 // Íàïðàâëåíèå ôëàãà:
2557 if flag
^.Direction
= D_LEFT
then
2563 Obj_SaveState(@flag
^.Obj
, Mem
);
2567 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2569 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2570 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2571 SavePanelArray(gWalls
);
2572 // Ñîõðàíÿåì ïàíåëè ôîíà:
2573 SavePanelArray(gRenderBackgrounds
);
2574 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2575 SavePanelArray(gRenderForegrounds
);
2576 // Ñîõðàíÿåì ïàíåëè âîäû:
2577 SavePanelArray(gWater
);
2578 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2579 SavePanelArray(gAcid1
);
2580 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2581 SavePanelArray(gAcid2
);
2582 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2583 SavePanelArray(gSteps
);
2584 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2585 SavePanelArray(gLifts
);
2588 ///// Ñîõðàíÿåì ìóçûêó: /////
2589 // Ñèãíàòóðà ìóçûêè:
2590 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2593 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2594 if gMusic
.NoMusic
then
2598 Mem
.WriteString(str
, 64);
2599 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2600 dw
:= gMusic
.GetPosition();
2602 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2603 boo
:= gMusic
.SpecPause
;
2604 Mem
.WriteBoolean(boo
);
2607 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2608 Mem
.WriteInt(gTotalMonsters
);
2611 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2612 if gGameSettings
.GameMode
= GM_CTF
then
2614 // Ôëàã Êðàñíîé êîìàíäû:
2615 SaveFlag(@gFlags
[FLAG_RED
]);
2616 // Ôëàã Ñèíåé êîìàíäû:
2617 SaveFlag(@gFlags
[FLAG_BLUE
]);
2621 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2622 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2624 // Î÷êè Êðàñíîé êîìàíäû:
2625 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2626 // Î÷êè Ñèíåé êîìàíäû:
2627 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2632 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2639 procedure LoadPanelArray(var panels
: TPanelArray
);
2641 PAMem
: TBinMemoryReader
;
2644 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2645 PAMem
:= TBinMemoryReader
.Create();
2646 PAMem
.LoadFromMemory(Mem
);
2648 for i
:= 0 to Length(panels
)-1 do
2649 if panels
[i
].SaveIt
then
2655 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2657 // Çàãðóæàåì ïàíåëü:
2658 panels
[i
].LoadState(PAMem
);
2661 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2665 procedure LoadFlag(flag
: PFlag
);
2669 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2671 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2673 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2674 Mem
.ReadByte(flag
^.RespawnType
);
2676 Mem
.ReadByte(flag
^.State
);
2677 // Íàïðàâëåíèå ôëàãà:
2680 flag
^.Direction
:= D_LEFT
2682 flag
^.Direction
:= D_RIGHT
;
2684 Obj_LoadState(@flag
^.Obj
, Mem
);
2691 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2692 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2693 LoadPanelArray(gWalls
);
2694 // Çàãðóæàåì ïàíåëè ôîíà:
2695 LoadPanelArray(gRenderBackgrounds
);
2696 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2697 LoadPanelArray(gRenderForegrounds
);
2698 // Çàãðóæàåì ïàíåëè âîäû:
2699 LoadPanelArray(gWater
);
2700 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2701 LoadPanelArray(gAcid1
);
2702 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2703 LoadPanelArray(gAcid2
);
2704 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2705 LoadPanelArray(gSteps
);
2706 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2707 LoadPanelArray(gLifts
);
2710 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2714 ///// Çàãðóæàåì ìóçûêó: /////
2715 // Ñèãíàòóðà ìóçûêè:
2717 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2719 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2722 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2723 Mem
.ReadString(str
);
2724 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2726 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2727 Mem
.ReadBoolean(boo
);
2728 // Çàïóñêàåì ýòó ìóçûêó:
2729 gMusic
.SetByName(str
);
2730 gMusic
.SpecPause
:= boo
;
2733 gMusic
.SetPosition(dw
);
2736 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2737 Mem
.ReadInt(gTotalMonsters
);
2740 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2741 if gGameSettings
.GameMode
= GM_CTF
then
2743 // Ôëàã Êðàñíîé êîìàíäû:
2744 LoadFlag(@gFlags
[FLAG_RED
]);
2745 // Ôëàã Ñèíåé êîìàíäû:
2746 LoadFlag(@gFlags
[FLAG_BLUE
]);
2750 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2751 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2753 // Î÷êè Êðàñíîé êîìàíäû:
2754 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2755 // Î÷êè Ñèíåé êîìàíäû:
2756 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2761 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2766 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2767 Arr
:= PanelByID
[PanelID
].PWhere
^;
2768 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2769 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);