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/>.
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, md5
;
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 // build "potentially visible panels" set, so we can avoid looping over all level panels again and again
66 procedure g_Map_BuildPVP (minx
, miny
, maxx
, maxy
: Integer);
67 procedure g_Map_ResetPVP ();
68 // do not call this without calling `g_Map_BuildPVP()` or `g_Map_ResetPVP()` first!
69 procedure g_Map_DrawPanels(PanelType
: Word);
71 procedure g_Map_DrawBack(dx
, dy
: Integer);
72 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
73 PanelType
: Word; b1x3
: Boolean): Boolean;
74 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
75 procedure g_Map_EnableWall(ID
: DWORD
);
76 procedure g_Map_DisableWall(ID
: DWORD
);
77 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
78 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
79 procedure g_Map_ReAdd_DieTriggers();
80 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
82 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
83 function g_Map_GetPointCount(PointType
: Byte): Word;
85 function g_Map_HaveFlagPoints(): Boolean;
87 procedure g_Map_ResetFlag(Flag
: Byte);
88 procedure g_Map_DrawFlags();
90 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
92 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
93 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
95 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
98 RESPAWNPOINT_PLAYER1
= 1;
99 RESPAWNPOINT_PLAYER2
= 2;
101 RESPAWNPOINT_RED
= 4;
102 RESPAWNPOINT_BLUE
= 5;
110 FLAG_STATE_NORMAL
= 1;
111 FLAG_STATE_DROPPED
= 2;
112 FLAG_STATE_CAPTURED
= 3;
113 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
114 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
116 FLAG_TIME
= 720; // 20 seconds
118 SKY_STRETCH
: Single = 1.5;
122 gRenderBackgrounds
: TPanelArray
;
123 gRenderForegrounds
: TPanelArray
;
124 gWater
, gAcid1
, gAcid2
: TPanelArray
;
127 gBlockMon
: TPanelArray
;
128 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
129 //gDOMFlags: array of TFlag;
132 gDoorMap
: array of array of DWORD
;
133 gLiftMap
: array of array of DWORD
;
134 gWADHash
: TMD5Digest
;
135 BackID
: DWORD
= DWORD(-1);
136 gExternalResources
: TStringList
;
141 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
142 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
143 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
144 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
146 ImagingTypes
, Imaging
, ImagingUtility
,
147 ImagingGif
, ImagingNetworkGraphics
;
150 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
151 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
152 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
156 PWhere
: ^TPanelArray
;
161 PanelById
: array of TPanelID
;
162 Textures
: TLevelTextureArray
;
163 RespawnPoints
: Array of TRespawnPoint
;
164 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
165 //DOMFlagPoints: Array of TFlagPoint;
168 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
170 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
171 (Texture
= TEXTURE_NAME_ACID1
) or
172 (Texture
= TEXTURE_NAME_ACID2
);
175 procedure CreateDoorMap();
177 PanelArray
: Array of record
183 a
, b
, c
, m
, i
, len
: Integer;
191 SetLength(PanelArray
, len
);
193 for a
:= 0 to High(gWalls
) do
194 if gWalls
[a
].Door
then
196 PanelArray
[i
].X
:= gWalls
[a
].X
;
197 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
198 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
199 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
200 PanelArray
[i
].Active
:= True;
201 PanelArray
[i
].PanelID
:= a
;
207 SetLength(PanelArray
, len
);
218 SetLength(gDoorMap
, 0);
220 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
223 if PanelArray
[a
].Active
then
225 PanelArray
[a
].Active
:= False;
226 m
:= Length(gDoorMap
);
227 SetLength(gDoorMap
, m
+1);
228 SetLength(gDoorMap
[m
], 1);
229 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
237 if PanelArray
[b
].Active
then
238 for c
:= 0 to High(gDoorMap
[m
]) do
239 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
240 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
241 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
242 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
243 gWalls
[gDoorMap
[m
, c
]].X
,
244 gWalls
[gDoorMap
[m
, c
]].Y
,
245 gWalls
[gDoorMap
[m
, c
]].Width
,
246 gWalls
[gDoorMap
[m
, c
]].Height
) then
248 PanelArray
[b
].Active
:= False;
249 SetLength(gDoorMap
[m
],
250 Length(gDoorMap
[m
])+1);
251 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
257 g_Game_StepLoading();
263 procedure CreateLiftMap();
265 PanelArray
: Array of record
270 a
, b
, c
, len
, i
, j
: Integer;
276 len
:= Length(gLifts
);
277 SetLength(PanelArray
, len
);
279 for a
:= 0 to len
-1 do
281 PanelArray
[a
].X
:= gLifts
[a
].X
;
282 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
283 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
284 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
285 PanelArray
[a
].Active
:= True;
288 SetLength(gLiftMap
, len
);
291 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
293 for a
:= 0 to len
-1 do
294 if PanelArray
[a
].Active
then
296 PanelArray
[a
].Active
:= False;
297 SetLength(gLiftMap
[i
], 32);
305 for b
:= 0 to len
-1 do
306 if PanelArray
[b
].Active
then
308 if g_CollideAround(PanelArray
[b
].X
,
311 PanelArray
[b
].Height
,
312 PanelArray
[gLiftMap
[i
, c
]].X
,
313 PanelArray
[gLiftMap
[i
, c
]].Y
,
314 PanelArray
[gLiftMap
[i
, c
]].Width
,
315 PanelArray
[gLiftMap
[i
, c
]].Height
) then
317 PanelArray
[b
].Active
:= False;
319 if j
> High(gLiftMap
[i
]) then
320 SetLength(gLiftMap
[i
],
321 Length(gLiftMap
[i
])+32);
330 SetLength(gLiftMap
[i
], j
+1);
333 g_Game_StepLoading();
336 SetLength(gLiftMap
, i
);
341 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
342 CurTex
: Integer; sav
: Boolean): Integer;
345 panels
: ^TPanelArray
;
349 case PanelRec
.PanelType
of
350 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
353 panels
:= @gRenderBackgrounds
;
355 panels
:= @gRenderForegrounds
;
364 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
367 panels
:= @gBlockMon
;
372 len
:= Length(panels
^);
373 SetLength(panels
^, len
+ 1);
375 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
,
378 panels
^[len
].SaveIt
:= True;
382 len
:= Length(PanelByID
);
383 SetLength(PanelByID
, len
+ 1);
384 PanelByID
[len
].PWhere
:= panels
;
385 PanelByID
[len
].PArrID
:= Result
;
388 function CreateNullTexture(RecName
: String): Integer;
390 SetLength(Textures
, Length(Textures
)+1);
391 result
:= High(Textures
);
393 with Textures
[High(Textures
)] do
395 TextureName
:= RecName
;
399 TextureID
:= TEXTURE_NONE
;
403 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
406 TextureData
: Pointer;
407 WADName
, txname
: String;
408 a
, ResLength
: Integer;
412 if Textures
<> nil then
413 for a
:= 0 to High(Textures
) do
414 if Textures
[a
].TextureName
= RecName
then
415 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
420 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
421 if (RecName
= TEXTURE_NAME_WATER
) or
422 (RecName
= TEXTURE_NAME_ACID1
) or
423 (RecName
= TEXTURE_NAME_ACID2
) then
425 SetLength(Textures
, Length(Textures
)+1);
427 with Textures
[High(Textures
)] do
429 TextureName
:= RecName
;
431 if TextureName
= TEXTURE_NAME_WATER
then
432 TextureID
:= TEXTURE_SPECIAL_WATER
434 if TextureName
= TEXTURE_NAME_ACID1
then
435 TextureID
:= TEXTURE_SPECIAL_ACID1
437 if TextureName
= TEXTURE_NAME_ACID2
then
438 TextureID
:= TEXTURE_SPECIAL_ACID2
;
443 result
:= High(Textures
);
447 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
448 WADName
:= g_ExtractWadName(RecName
);
450 WAD
:= TWADFile
.Create();
452 if WADName
<> '' then
453 WADName
:= GameDir
+'/wads/'+WADName
457 WAD
.ReadFile(WADName
);
461 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
463 FreeMem(TextureData);
464 RecName := 'COMMON\ALIEN';
468 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
470 SetLength(Textures
, Length(Textures
)+1);
471 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
473 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
474 @Textures
[High(Textures
)].Width
,
475 @Textures
[High(Textures
)].Height
);
476 FreeMem(TextureData
);
477 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
478 Textures
[High(Textures
)].Anim
:= False;
480 result
:= High(Textures
);
482 else // Íåò òàêîãî ðåóñðñà â WAD'å
484 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
487 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
488 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
495 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
498 TextureWAD
: PChar = nil;
499 TextData
: Pointer = nil;
500 TextureData
: Pointer = nil;
504 TextureResource
: String;
505 _width
, _height
, _framecount
, _speed
: Integer;
506 _backanimation
: Boolean;
508 ia
: TDynImageDataArray
= nil;
509 f
, c
, frdelay
, frloop
: Integer;
513 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
515 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
516 WADName
:= g_ExtractWadName(RecName
);
518 WAD
:= TWADFile
.Create();
520 if WADName
<> '' then
521 WADName
:= GameDir
+'/wads/'+WADName
525 WAD
.ReadFile(WADName
);
527 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
531 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
532 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
538 if WADName = Map then
540 //FreeMem(TextureWAD);
541 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
547 if ResLength
< 6 then
549 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
553 // ýòî ïòèöà? ýòî ñàìîë¸ò?
554 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
555 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
557 // íåò, ýòî ñóïåðìåí!
558 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
560 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
564 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
565 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
567 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
571 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
573 TextureResource
:= cfg
.ReadStr('', 'resource', '');
574 if TextureResource
= '' then
576 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
580 _width
:= cfg
.ReadInt('', 'framewidth', 0);
581 _height
:= cfg
.ReadInt('', 'frameheight', 0);
582 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
583 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
584 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
589 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
590 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
592 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
599 SetLength(Textures
, Length(Textures
)+1);
600 with Textures
[High(Textures
)] do
602 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
603 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
605 TextureName
:= RecName
;
609 FramesCount
:= _framecount
;
611 result
:= High(Textures
);
615 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
621 // try animated image
623 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
624 if length(imgfmt) = 0 then
626 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
630 GlobalMetadata
.ClearMetaItems();
631 GlobalMetadata
.ClearMetaItemsForSaving();
632 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
634 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
637 if length(ia
) = 0 then
639 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
646 _width
:= ia
[0].width
;
647 _height
:= ia
[0].height
;
648 _framecount
:= length(ia
);
650 _backanimation
:= false;
653 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
655 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
657 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
659 if f
< 0 then f
:= 0;
662 if c
< 13 then c
:= 0 else c
:= 1;
664 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
669 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
671 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
673 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
675 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
679 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
680 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
681 f
:= ord(_backanimation
);
682 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
);
684 SetLength(Textures
, Length(Textures
)+1);
685 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
686 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
688 Textures
[High(Textures
)].TextureName
:= RecName
;
689 Textures
[High(Textures
)].Width
:= _width
;
690 Textures
[High(Textures
)].Height
:= _height
;
691 Textures
[High(Textures
)].Anim
:= True;
692 Textures
[High(Textures
)].FramesCount
:= length(ia
);
693 Textures
[High(Textures
)].Speed
:= _speed
;
694 result
:= High(Textures
);
695 //writeln(' CREATED!');
699 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
703 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
706 if TextureWAD
<> nil then FreeMem(TextureWAD
);
707 if TextData
<> nil then FreeMem(TextData
);
708 if TextureData
<> nil then FreeMem(TextureData
);
712 procedure CreateItem(Item
: TItemRec_1
);
714 if g_Game_IsClient
then Exit
;
716 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
717 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
720 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
721 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
724 procedure CreateArea(Area
: TAreaRec_1
);
729 case Area
.AreaType
of
730 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
731 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
733 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
734 with RespawnPoints
[High(RespawnPoints
)] do
738 Direction
:= TDirection(Area
.Direction
);
740 case Area
.AreaType
of
741 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
742 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
743 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
744 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
745 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
750 AREA_REDFLAG
, AREA_BLUEFLAG
:
752 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
754 if FlagPoints
[a
] <> nil then Exit
;
758 with FlagPoints
[a
]^ do
760 X
:= Area
.X
-FLAGRECT
.X
;
761 Y
:= Area
.Y
-FLAGRECT
.Y
;
762 Direction
:= TDirection(Area
.Direction
);
768 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
769 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
772 Animation
:= TAnimation
.Create(id
, True, 8);
773 Obj
.Rect
:= FLAGRECT
;
781 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
782 with DOMFlagPoints[High(DOMFlagPoints)] do
786 Direction := TDirection(Area.Direction);
789 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
794 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
798 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
804 Width
:= Trigger
.Width
;
805 Height
:= Trigger
.Height
;
806 Enabled
:= ByteBool(Trigger
.Enabled
);
807 TexturePanel
:= Trigger
.TexturePanel
;
808 TexturePanelType
:= fTexturePanel1Type
;
809 ShotPanelType
:= fTexturePanel2Type
;
810 TriggerType
:= Trigger
.TriggerType
;
811 ActivateType
:= Trigger
.ActivateType
;
812 Keys
:= Trigger
.Keys
;
813 Data
.Default
:= Trigger
.DATA
;
816 g_Triggers_Create(_trigger
);
819 procedure CreateMonster(monster
: TMonsterRec_1
);
823 if g_Game_IsClient
then Exit
;
825 if (gGameSettings
.GameType
= GT_SINGLE
)
826 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
828 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
829 TDirection(monster
.Direction
));
831 if gTriggers
<> nil then
832 for a
:= 0 to High(gTriggers
) do
833 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
834 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
835 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
836 gMonsters
[i
].AddTrigger(a
);
838 if monster
.MonsterType
<> MONSTER_BARREL
then
843 procedure g_Map_ReAdd_DieTriggers();
847 if g_Game_IsClient
then Exit
;
849 for i
:= 0 to High(gMonsters
) do
850 if gMonsters
[i
] <> nil then
852 gMonsters
[i
].ClearTriggers();
854 for a
:= 0 to High(gTriggers
) do
855 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
856 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
857 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
858 gMonsters
[i
].AddTrigger(a
);
862 function extractWadName(resourceName
: string): string;
866 posN
:= Pos(':', resourceName
);
868 Result
:= Copy(resourceName
, 0, posN
-1)
873 procedure addResToExternalResList(res
: string);
875 res
:= extractWadName(res
);
876 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
877 gExternalResources
.Add(res
);
880 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
882 textures
: TTexturesRec1Array
;
883 mapHeader
: TMapHeaderRec_1
;
885 resFile
: String = '';
887 if gExternalResources
= nil then
888 gExternalResources
:= TStringList
.Create
;
890 gExternalResources
.Clear
;
891 textures
:= mapReader
.GetTextures();
892 for i
:= 0 to High(textures
) do
894 addResToExternalResList(resFile
);
899 mapHeader
:= mapReader
.GetMapHeader
;
901 addResToExternalResList(mapHeader
.MusicName
);
902 addResToExternalResList(mapHeader
.SkyName
);
905 function g_Map_Load(Res
: String): Boolean;
907 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
908 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
911 MapReader
: TMapReader_1
;
912 Header
: TMapHeaderRec_1
;
913 _textures
: TTexturesRec1Array
;
914 _texnummap
: array of Integer; // `_textures` -> `Textures`
915 panels
: TPanelsRec1Array
;
916 items
: TItemsRec1Array
;
917 monsters
: TMonsterRec1Array
;
918 areas
: TAreasRec1Array
;
919 triggers
: TTriggersRec1Array
;
922 AddTextures
: TAddTextureArray
;
923 texture
: TTextureRec_1
;
924 TriggersTable
: Array of record
925 TexturePanel
: Integer;
930 FileName
, mapResName
, s
, TexName
: String;
933 ok
, isAnim
, trigRef
: Boolean;
934 CurTex
, ntn
: Integer;
938 TriggersTable
:= nil;
939 FillChar(texture
, SizeOf(texture
), 0);
941 sfsGCDisable(); // temporary disable removing of temporary volumes
944 FileName
:= g_ExtractWadName(Res
);
945 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
946 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
948 WAD
:= TWADFile
.Create();
949 if not WAD
.ReadFile(FileName
) then
951 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
955 //k8: why loader ignores path here?
956 mapResName
:= g_ExtractFileName(Res
);
957 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
959 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
967 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
968 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
969 MapReader
:= TMapReader_1
.Create();
971 if not MapReader
.LoadMap(Data
) then
973 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
980 generateExternalResourcesList(MapReader
);
982 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
983 _textures
:= MapReader
.GetTextures();
986 // Äîáàâëåíèå òåêñòóð â Textures[]:
987 if _textures
<> nil then
989 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
990 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
991 SetLength(_texnummap
, length(_textures
));
993 for a
:= 0 to High(_textures
) do
996 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
997 for b
:= 1 to Length(s
) do
1003 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1004 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1005 // Àíèìèðîâàííàÿ òåêñòóðà:
1006 if ByteBool(_textures
[a
].Anim
) then
1008 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1011 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1012 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1015 else // Îáû÷íàÿ òåêñòóðà:
1016 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1019 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1020 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1023 _texnummap
[a
] := ntn
; // fix texture number
1024 g_Game_StepLoading();
1028 // Çàãðóçêà òðèããåðîâ:
1029 gTriggerClientID
:= 0;
1030 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1031 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1032 triggers
:= MapReader
.GetTriggers();
1034 // Çàãðóçêà ïàíåëåé:
1035 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1036 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1037 panels
:= MapReader
.GetPanels();
1039 // check texture numbers for panels
1040 for a
:= 0 to High(panels
) do
1042 if panels
[a
].TextureNum
> High(_textures
) then
1044 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1048 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1051 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1052 if triggers
<> nil then
1054 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1055 SetLength(TriggersTable
, Length(triggers
));
1056 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1058 for a
:= 0 to High(TriggersTable
) do
1060 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1061 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1063 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1064 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1066 TriggersTable
[a
].LiftPanel
:= -1;
1068 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1069 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1070 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1071 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1073 TriggersTable
[a
].DoorPanel
:= -1;
1075 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1076 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1078 TriggersTable
[a
].ShotPanel
:= -1;
1080 g_Game_StepLoading();
1085 if panels
<> nil then
1087 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1088 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1090 for a
:= 0 to High(panels
) do
1092 SetLength(AddTextures
, 0);
1095 if _textures
<> nil then
1097 texture
:= _textures
[panels
[a
].TextureNum
];
1105 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1106 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1108 if (TriggersTable
<> nil) and (_textures
<> nil) then
1109 for b
:= 0 to High(TriggersTable
) do
1110 if (TriggersTable
[b
].TexturePanel
= a
)
1111 or (TriggersTable
[b
].ShotPanel
= a
) then
1120 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1122 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1125 for c
:= Len
downto 1 do
1133 // Ñïåö-òåêñòóðû çàïðåùåíû:
1134 if g_Map_IsSpecialTexture(s
) then
1137 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1138 ok
:= g_Texture_NumNameFindStart(s
);
1140 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1141 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1144 k
:= NNF_NAME_BEFORE
;
1145 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1146 while ok
or (k
= NNF_NAME_BEFORE
) or
1147 (k
= NNF_NAME_EQUALS
) do
1149 k
:= g_Texture_NumNameFindNext(TexName
);
1151 if (k
= NNF_NAME_BEFORE
) or
1152 (k
= NNF_NAME_AFTER
) then
1154 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1155 if ByteBool(texture
.Anim
) then
1156 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1158 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1160 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1162 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1166 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1168 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1170 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1172 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1176 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1179 for c
:= 0 to High(Textures
) do
1180 if Textures
[c
].TextureName
= TexName
then
1182 SetLength(AddTextures
, Length(AddTextures
)+1);
1183 AddTextures
[High(AddTextures
)].Texture
:= c
;
1184 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1190 if k
= NNF_NAME_EQUALS
then
1192 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1193 SetLength(AddTextures
, Length(AddTextures
)+1);
1194 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1195 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1196 CurTex
:= High(AddTextures
);
1204 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1205 end; // if ok - ññûëàþòñÿ òðèããåðû
1209 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1210 SetLength(AddTextures
, 1);
1211 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1212 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1216 //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);
1218 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1219 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1221 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1222 if TriggersTable
<> nil then
1223 for b
:= 0 to High(TriggersTable
) do
1225 // Òðèããåð äâåðè/ëèôòà:
1226 if (TriggersTable
[b
].LiftPanel
= a
) or
1227 (TriggersTable
[b
].DoorPanel
= a
) then
1228 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1229 // Òðèããåð ñìåíû òåêñòóðû:
1230 if TriggersTable
[b
].TexturePanel
= a
then
1231 triggers
[b
].TexturePanel
:= PanelID
;
1232 // Òðèããåð "Òóðåëü":
1233 if TriggersTable
[b
].ShotPanel
= a
then
1234 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1237 g_Game_StepLoading();
1241 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1242 if (triggers
<> nil) and not gLoadGameMode
then
1244 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1245 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1246 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1247 for a
:= 0 to High(triggers
) do
1249 if triggers
[a
].TexturePanel
<> -1 then
1250 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1253 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1254 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1255 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1258 CreateTrigger(triggers
[a
], b
, c
);
1262 // Çàãðóçêà ïðåäìåòîâ:
1263 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1264 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1265 items
:= MapReader
.GetItems();
1267 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1268 if (items
<> nil) and not gLoadGameMode
then
1270 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1271 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1272 for a
:= 0 to High(items
) do
1273 CreateItem(Items
[a
]);
1276 // Çàãðóçêà îáëàñòåé:
1277 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1278 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1279 areas
:= MapReader
.GetAreas();
1281 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1282 if areas
<> nil then
1284 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1285 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1286 for a
:= 0 to High(areas
) do
1287 CreateArea(areas
[a
]);
1290 // Çàãðóçêà ìîíñòðîâ:
1291 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1292 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1293 monsters
:= MapReader
.GetMonsters();
1295 gTotalMonsters
:= 0;
1297 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1298 if (monsters
<> nil) and not gLoadGameMode
then
1300 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1301 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1302 for a
:= 0 to High(monsters
) do
1303 CreateMonster(monsters
[a
]);
1306 // Çàãðóçêà îïèñàíèÿ êàðòû:
1307 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1308 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1309 Header
:= MapReader
.GetMapHeader();
1315 Name
:= Header
.MapName
;
1316 Description
:= Header
.MapDescription
;
1317 Author
:= Header
.MapAuthor
;
1318 MusicName
:= Header
.MusicName
;
1319 SkyName
:= Header
.SkyName
;
1320 Height
:= Header
.Height
;
1321 Width
:= Header
.Width
;
1325 if gMapInfo
.SkyName
<> '' then
1327 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1328 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1329 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1331 if FileName
<> '' then
1332 FileName
:= GameDir
+'/wads/'+FileName
1335 FileName
:= g_ExtractWadName(Res
);
1338 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1339 if g_Texture_CreateWAD(BackID
, s
) then
1341 g_Game_SetupScreenSize();
1344 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1349 if gMapInfo
.MusicName
<> '' then
1351 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1352 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1353 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1355 if FileName
<> '' then
1356 FileName
:= GameDir
+'/wads/'+FileName
1359 FileName
:= g_ExtractWadName(Res
);
1362 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1363 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1366 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1369 // Îñòàëüíûå óñòàíâêè:
1377 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1378 if not gLoadGameMode
then
1381 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1387 TriggersTable
:= nil;
1390 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1391 if ok
and (not gLoadGameMode
) then
1393 gMusic
.SetByName(gMapInfo
.MusicName
);
1397 gMusic
.SetByName('');
1399 sfsGCEnable(); // enable releasing unused volumes
1402 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1406 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1409 MapReader
: TMapReader_1
;
1410 Header
: TMapHeaderRec_1
;
1415 FillChar(Result
, SizeOf(Result
), 0);
1416 FileName
:= g_ExtractWadName(Res
);
1418 WAD
:= TWADFile
.Create();
1419 if not WAD
.ReadFile(FileName
) then
1425 //k8: it ignores path again
1426 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1434 MapReader
:= TMapReader_1
.Create();
1436 if not MapReader
.LoadMap(Data
) then
1438 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1439 ZeroMemory(@Header
, SizeOf(Header
));
1440 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1441 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1445 Header
:= MapReader
.GetMapHeader();
1446 Result
.Name
:= Header
.MapName
;
1447 Result
.Description
:= Header
.MapDescription
;
1454 Result
.Author
:= Header
.MapAuthor
;
1455 Result
.Height
:= Header
.Height
;
1456 Result
.Width
:= Header
.Width
;
1459 function g_Map_GetMapsList(WADName
: string): SArray
;
1466 WAD
:= TWADFile
.Create();
1467 if not WAD
.ReadFile(WADName
) then
1472 ResList
:= WAD
.GetMapResources();
1473 if ResList
<> nil then
1475 for a
:= 0 to High(ResList
) do
1477 SetLength(Result
, Length(Result
)+1);
1478 Result
[High(Result
)] := ResList
[a
];
1484 function g_Map_Exist(Res
: string): Boolean;
1487 FileName
, mnn
: string;
1493 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1495 WAD
:= TWADFile
.Create
;
1496 if not WAD
.ReadFile(FileName
) then
1502 ResList
:= WAD
.GetMapResources();
1505 mnn
:= g_ExtractFileName(Res
);
1506 if ResList
<> nil then
1507 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1514 procedure g_Map_Free();
1518 procedure FreePanelArray(var panels
: TPanelArray
);
1523 if panels
<> nil then
1525 for i
:= 0 to High(panels
) do
1538 RespawnPoints
:= nil;
1539 if FlagPoints
[FLAG_RED
] <> nil then
1541 Dispose(FlagPoints
[FLAG_RED
]);
1542 FlagPoints
[FLAG_RED
] := nil;
1544 if FlagPoints
[FLAG_BLUE
] <> nil then
1546 Dispose(FlagPoints
[FLAG_BLUE
]);
1547 FlagPoints
[FLAG_BLUE
] := nil;
1549 //DOMFlagPoints := nil;
1553 if Textures
<> nil then
1555 for a
:= 0 to High(Textures
) do
1556 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1557 if Textures
[a
].Anim
then
1558 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1560 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1561 e_DeleteTexture(Textures
[a
].TextureID
);
1566 FreePanelArray(gWalls
);
1567 FreePanelArray(gRenderBackgrounds
);
1568 FreePanelArray(gRenderForegrounds
);
1569 FreePanelArray(gWater
);
1570 FreePanelArray(gAcid1
);
1571 FreePanelArray(gAcid2
);
1572 FreePanelArray(gSteps
);
1573 FreePanelArray(gLifts
);
1574 FreePanelArray(gBlockMon
);
1576 if BackID
<> DWORD(-1) then
1580 e_DeleteTexture(BackID
);
1581 BackID
:= DWORD(-1);
1584 g_Game_StopAllSounds(False);
1586 g_Sound_Delete(gMapInfo
.MusicName
);
1588 gMapInfo
.Name
:= '';
1589 gMapInfo
.Description
:= '';
1590 gMapInfo
.MusicName
:= '';
1591 gMapInfo
.Height
:= 0;
1592 gMapInfo
.Width
:= 0;
1600 procedure g_Map_Update();
1606 procedure UpdatePanelArray(var panels
: TPanelArray
);
1611 if panels
<> nil then
1612 for i
:= 0 to High(panels
) do
1617 UpdatePanelArray(gWalls
);
1618 UpdatePanelArray(gRenderBackgrounds
);
1619 UpdatePanelArray(gRenderForegrounds
);
1620 UpdatePanelArray(gWater
);
1621 UpdatePanelArray(gAcid1
);
1622 UpdatePanelArray(gAcid2
);
1623 UpdatePanelArray(gSteps
);
1625 if gGameSettings
.GameMode
= GM_CTF
then
1627 for a
:= FLAG_RED
to FLAG_BLUE
do
1628 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1631 if gFlags
[a
].Animation
<> nil then
1632 gFlags
[a
].Animation
.Update();
1634 m
:= g_Obj_Move(@Obj
, True, True);
1636 if gTime
mod (GAME_TICK
*2) <> 0 then
1639 // Ñîïðîòèâëåíèå âîçäóõà:
1640 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1642 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1643 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1646 gFlags
[a
].CaptureTime
:= 0;
1647 if a
= FLAG_RED
then
1648 s
:= _lc
[I_PLAYER_FLAG_RED
]
1650 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1651 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1653 if g_Game_IsNet
then
1654 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1661 // Èãðîê áåðåò ôëàã:
1662 if gPlayers
<> nil then
1664 j
:= Random(Length(gPlayers
)) - 1;
1666 for d
:= 0 to High(gPlayers
) do
1669 if j
> High(gPlayers
) then
1672 if gPlayers
[j
] <> nil then
1673 if gPlayers
[j
].Live
and
1674 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1676 if gPlayers
[j
].GetFlag(a
) then
1687 pvpset
: array of PPanel
= nil; // potentially lit panels
1688 pvpb
, pvpe
: array [0..7] of Integer; // start/end (inclusive) of the correspoinding type panels in pvpset
1689 pvpcount
: Integer = -1; // to avoid constant reallocations
1691 function pvpType (panelType
: Word): Integer;
1694 PANEL_WALL
, PANEL_CLOSEDOOR
: result
:= 0; // gWalls
1695 PANEL_BACK
: result
:= 1; // gRenderBackgrounds
1696 PANEL_FORE
: result
:= 2; // gRenderForegrounds
1697 PANEL_WATER
: result
:= 3; // gWater
1698 PANEL_ACID1
: result
:= 4; // gAcid1
1699 PANEL_ACID2
: result
:= 5; // gAcid2
1700 PANEL_STEP
: result
:= 6; // gSteps
1705 procedure g_Map_ResetPVP ();
1707 pvpcount
:= -1; // special
1710 procedure g_Map_BuildPVP (minx
, miny
, maxx
, maxy
: Integer);
1715 procedure checkPanels (var panels
: TPanelArray
; stp
: Integer);
1717 idx
, x
, y
, w
, h
: Integer;
1719 if panels
= nil then exit
;
1720 tpc
:= tpc
+Length(panels
);
1721 if (stp
< 0) or (stp
> 6) then exit
;
1722 pvpb
[stp
] := pvpcount
;
1723 for idx
:= 0 to High(panels
) do
1725 w
:= panels
[idx
].Width
;
1726 h
:= panels
[idx
].Height
;
1727 if (w
< 1) or (h
< 1) then continue
;
1730 if (x
> maxx
) or (y
> maxy
) then continue
;
1731 if (x
+w
<= minx
) or (y
+h
<= miny
) then continue
;
1732 if pvpcount
= length(pvpset
) then SetLength(pvpset
, pvpcount
+32768);
1733 pvpset
[pvpcount
] := @panels
[idx
];
1736 pvpe
[stp
] := pvpcount
-1;
1740 //e_WriteLog(Format('visible rect: (%d,%d)-(%d,%d)', [minx, miny, maxx, maxy]), MSG_NOTIFY);
1742 for idx
:= 0 to High(pvpb
) do begin pvpb
[idx
] := 0; pvpe
[idx
] := -1; end;
1744 checkPanels(gWalls
, 0);
1745 checkPanels(gRenderBackgrounds
, 1);
1746 checkPanels(gRenderForegrounds
, 2);
1747 checkPanels(gWater
, 3);
1748 checkPanels(gAcid1
, 4);
1749 checkPanels(gAcid2
, 5);
1750 checkPanels(gSteps
, 6);
1751 //e_WriteLog(Format('total panels: %d; visible panels: %d', [tpc, pvpcount]), MSG_NOTIFY);
1754 procedure g_Map_DrawPanels(PanelType
: Word);
1756 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1760 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1762 if pvpcount
< 0 then
1764 // alas, no visible set
1765 for idx
:= 0 to High(panels
) do
1767 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1772 // wow, use visible set
1773 if pvpb
[stp
] <= pvpe
[stp
] then
1775 for idx
:= pvpb
[stp
] to pvpe
[stp
] do
1777 if not (drawDoors
xor pvpset
[idx
].Door
) then pvpset
[idx
].Draw();
1786 PANEL_WALL
: DrawPanels(0, gWalls
);
1787 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1788 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1789 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1790 PANEL_WATER
: DrawPanels(3, gWater
);
1791 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1792 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1793 PANEL_STEP
: DrawPanels(6, gSteps
);
1797 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1799 procedure drawPanels (var panels
: TPanelArray
);
1803 if panels
<> nil then
1805 for a
:= 0 to High(panels
) do
1807 panels
[a
].DrawShadowVolume(lightX
, lightY
, radius
);
1814 //drawPanels(gRenderForegrounds);
1817 procedure g_Map_DrawBack(dx
, dy
: Integer);
1819 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1820 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1822 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1825 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
1826 PanelType
: Word; b1x3
: Boolean): Boolean;
1832 if WordBool(PanelType
and PANEL_WALL
) then
1833 if gWalls
<> nil then
1838 if gWalls
[a
].Enabled
and
1839 g_Collide(X
, Y
, Width
, Height
,
1840 gWalls
[a
].X
, gWalls
[a
].Y
,
1841 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1848 if WordBool(PanelType
and PANEL_WATER
) then
1849 if gWater
<> nil then
1854 if g_Collide(X
, Y
, Width
, Height
,
1855 gWater
[a
].X
, gWater
[a
].Y
,
1856 gWater
[a
].Width
, gWater
[a
].Height
) then
1863 if WordBool(PanelType
and PANEL_ACID1
) then
1864 if gAcid1
<> nil then
1869 if g_Collide(X
, Y
, Width
, Height
,
1870 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1871 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1878 if WordBool(PanelType
and PANEL_ACID2
) then
1879 if gAcid2
<> nil then
1884 if g_Collide(X
, Y
, Width
, Height
,
1885 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1886 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1893 if WordBool(PanelType
and PANEL_STEP
) then
1894 if gSteps
<> nil then
1899 if g_Collide(X
, Y
, Width
, Height
,
1900 gSteps
[a
].X
, gSteps
[a
].Y
,
1901 gSteps
[a
].Width
, gSteps
[a
].Height
) then
1908 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
1909 if gLifts
<> nil then
1914 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
1915 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
1916 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
1917 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
1918 g_Collide(X
, Y
, Width
, Height
,
1919 gLifts
[a
].X
, gLifts
[a
].Y
,
1920 gLifts
[a
].Width
, gLifts
[a
].Height
) then
1927 if WordBool(PanelType
and PANEL_BLOCKMON
) then
1928 if gBlockMon
<> nil then
1930 h
:= High(gBlockMon
);
1934 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
1935 g_Collide(X
, Y
, Width
, Height
,
1936 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
1937 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
1945 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
1949 Result
:= TEXTURE_NONE
;
1951 if gWater
<> nil then
1956 if g_Collide(X
, Y
, Width
, Height
,
1957 gWater
[a
].X
, gWater
[a
].Y
,
1958 gWater
[a
].Width
, gWater
[a
].Height
) then
1960 Result
:= gWater
[a
].GetTextureID();
1965 if gAcid1
<> nil then
1970 if g_Collide(X
, Y
, Width
, Height
,
1971 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1972 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1974 Result
:= gAcid1
[a
].GetTextureID();
1979 if gAcid2
<> nil then
1984 if g_Collide(X
, Y
, Width
, Height
,
1985 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1986 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1988 Result
:= gAcid2
[a
].GetTextureID();
1994 procedure g_Map_EnableWall(ID
: DWORD
);
1999 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2001 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2005 procedure g_Map_DisableWall(ID
: DWORD
);
2010 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2012 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2016 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2021 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2024 tp
:= gRenderForegrounds
[ID
];
2026 tp
:= gRenderBackgrounds
[ID
];
2039 tp
.NextTexture(AnimLoop
);
2040 if g_Game_IsServer
and g_Game_IsNet
then
2041 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2044 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2046 if gLifts
[ID
].LiftType
= t
then
2053 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2055 if LiftType
= 0 then
2056 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2057 else if LiftType
= 1 then
2058 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2059 else if LiftType
= 2 then
2060 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2061 else if LiftType
= 3 then
2062 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2064 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2068 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2071 PointsArray
: Array of TRespawnPoint
;
2074 SetLength(PointsArray
, 0);
2076 if RespawnPoints
= nil then
2079 for a
:= 0 to High(RespawnPoints
) do
2080 if RespawnPoints
[a
].PointType
= PointType
then
2082 SetLength(PointsArray
, Length(PointsArray
)+1);
2083 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2086 if PointsArray
= nil then
2089 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2093 function g_Map_GetPointCount(PointType
: Byte): Word;
2099 if RespawnPoints
= nil then
2102 for a
:= 0 to High(RespawnPoints
) do
2103 if RespawnPoints
[a
].PointType
= PointType
then
2104 Result
:= Result
+ 1;
2107 function g_Map_HaveFlagPoints(): Boolean;
2109 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2112 procedure g_Map_ResetFlag(Flag
: Byte);
2114 with gFlags
[Flag
] do
2120 Direction
:= D_LEFT
;
2121 State
:= FLAG_STATE_NONE
;
2122 if FlagPoints
[Flag
] <> nil then
2124 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2125 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2126 Direction
:= FlagPoints
[Flag
]^.Direction
;
2127 State
:= FLAG_STATE_NORMAL
;
2133 procedure g_Map_DrawFlags();
2136 Mirror
: TMirrorType
;
2138 if gGameSettings
.GameMode
<> GM_CTF
then
2141 for i
:= FLAG_RED
to FLAG_BLUE
do
2143 if State
<> FLAG_STATE_CAPTURED
then
2145 if State
= FLAG_STATE_NONE
then
2148 if Direction
= D_LEFT
then
2150 Mirror
:= M_HORIZONTAL
;
2159 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2161 if g_debug_Frames
then
2163 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2165 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2166 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2172 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2179 procedure SavePanelArray(var panels
: TPanelArray
);
2181 PAMem
: TBinMemoryWriter
;
2184 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2185 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2188 while i
< Length(panels
) do
2190 if panels
[i
].SaveIt
then
2194 // Ñîõðàíÿåì ïàíåëü:
2195 panels
[i
].SaveState(PAMem
);
2200 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2201 PAMem
.SaveToMemory(Mem
);
2205 procedure SaveFlag(flag
: PFlag
);
2208 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2210 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2211 Mem
.WriteByte(flag
^.RespawnType
);
2213 Mem
.WriteByte(flag
^.State
);
2214 // Íàïðàâëåíèå ôëàãà:
2215 if flag
^.Direction
= D_LEFT
then
2221 Obj_SaveState(@flag
^.Obj
, Mem
);
2225 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2227 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2228 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2229 SavePanelArray(gWalls
);
2230 // Ñîõðàíÿåì ïàíåëè ôîíà:
2231 SavePanelArray(gRenderBackgrounds
);
2232 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2233 SavePanelArray(gRenderForegrounds
);
2234 // Ñîõðàíÿåì ïàíåëè âîäû:
2235 SavePanelArray(gWater
);
2236 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2237 SavePanelArray(gAcid1
);
2238 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2239 SavePanelArray(gAcid2
);
2240 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2241 SavePanelArray(gSteps
);
2242 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2243 SavePanelArray(gLifts
);
2246 ///// Ñîõðàíÿåì ìóçûêó: /////
2247 // Ñèãíàòóðà ìóçûêè:
2248 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2251 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2252 if gMusic
.NoMusic
then
2256 Mem
.WriteString(str
, 64);
2257 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2258 dw
:= gMusic
.GetPosition();
2260 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2261 boo
:= gMusic
.SpecPause
;
2262 Mem
.WriteBoolean(boo
);
2265 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2266 Mem
.WriteInt(gTotalMonsters
);
2269 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2270 if gGameSettings
.GameMode
= GM_CTF
then
2272 // Ôëàã Êðàñíîé êîìàíäû:
2273 SaveFlag(@gFlags
[FLAG_RED
]);
2274 // Ôëàã Ñèíåé êîìàíäû:
2275 SaveFlag(@gFlags
[FLAG_BLUE
]);
2279 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2280 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2282 // Î÷êè Êðàñíîé êîìàíäû:
2283 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2284 // Î÷êè Ñèíåé êîìàíäû:
2285 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2290 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2297 procedure LoadPanelArray(var panels
: TPanelArray
);
2299 PAMem
: TBinMemoryReader
;
2302 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2303 PAMem
:= TBinMemoryReader
.Create();
2304 PAMem
.LoadFromMemory(Mem
);
2306 for i
:= 0 to Length(panels
)-1 do
2307 if panels
[i
].SaveIt
then
2313 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2315 // Çàãðóæàåì ïàíåëü:
2316 panels
[i
].LoadState(PAMem
);
2319 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2323 procedure LoadFlag(flag
: PFlag
);
2327 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2329 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2331 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2332 Mem
.ReadByte(flag
^.RespawnType
);
2334 Mem
.ReadByte(flag
^.State
);
2335 // Íàïðàâëåíèå ôëàãà:
2338 flag
^.Direction
:= D_LEFT
2340 flag
^.Direction
:= D_RIGHT
;
2342 Obj_LoadState(@flag
^.Obj
, Mem
);
2349 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2350 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2351 LoadPanelArray(gWalls
);
2352 // Çàãðóæàåì ïàíåëè ôîíà:
2353 LoadPanelArray(gRenderBackgrounds
);
2354 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2355 LoadPanelArray(gRenderForegrounds
);
2356 // Çàãðóæàåì ïàíåëè âîäû:
2357 LoadPanelArray(gWater
);
2358 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2359 LoadPanelArray(gAcid1
);
2360 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2361 LoadPanelArray(gAcid2
);
2362 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2363 LoadPanelArray(gSteps
);
2364 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2365 LoadPanelArray(gLifts
);
2368 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2371 ///// Çàãðóæàåì ìóçûêó: /////
2372 // Ñèãíàòóðà ìóçûêè:
2374 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2376 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2379 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2380 Mem
.ReadString(str
);
2381 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2383 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2384 Mem
.ReadBoolean(boo
);
2385 // Çàïóñêàåì ýòó ìóçûêó:
2386 gMusic
.SetByName(str
);
2387 gMusic
.SpecPause
:= boo
;
2390 gMusic
.SetPosition(dw
);
2393 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2394 Mem
.ReadInt(gTotalMonsters
);
2397 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2398 if gGameSettings
.GameMode
= GM_CTF
then
2400 // Ôëàã Êðàñíîé êîìàíäû:
2401 LoadFlag(@gFlags
[FLAG_RED
]);
2402 // Ôëàã Ñèíåé êîìàíäû:
2403 LoadFlag(@gFlags
[FLAG_BLUE
]);
2407 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2408 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2410 // Î÷êè Êðàñíîé êîìàíäû:
2411 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2412 // Î÷êè Ñèíåé êîìàíäû:
2413 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2418 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2423 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2424 Arr
:= PanelByID
[PanelID
].PWhere
^;
2425 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2426 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);