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
);
96 RESPAWNPOINT_PLAYER1
= 1;
97 RESPAWNPOINT_PLAYER2
= 2;
100 RESPAWNPOINT_BLUE
= 5;
108 FLAG_STATE_NORMAL
= 1;
109 FLAG_STATE_DROPPED
= 2;
110 FLAG_STATE_CAPTURED
= 3;
111 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
112 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
114 FLAG_TIME
= 720; // 20 seconds
116 SKY_STRETCH
: Single = 1.5;
120 gRenderBackgrounds
: TPanelArray
;
121 gRenderForegrounds
: TPanelArray
;
122 gWater
, gAcid1
, gAcid2
: TPanelArray
;
125 gBlockMon
: TPanelArray
;
126 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
127 //gDOMFlags: array of TFlag;
130 gDoorMap
: array of array of DWORD
;
131 gLiftMap
: array of array of DWORD
;
132 gWADHash
: TMD5Digest
;
133 BackID
: DWORD
= DWORD(-1);
134 gExternalResources
: TStringList
;
139 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
140 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
141 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
142 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
144 ImagingTypes
, Imaging
, ImagingUtility
,
145 ImagingGif
, ImagingNetworkGraphics
;
148 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
149 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
150 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
154 PWhere
: ^TPanelArray
;
159 PanelById
: array of TPanelID
;
160 Textures
: TLevelTextureArray
;
161 RespawnPoints
: Array of TRespawnPoint
;
162 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
163 //DOMFlagPoints: Array of TFlagPoint;
166 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
168 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
169 (Texture
= TEXTURE_NAME_ACID1
) or
170 (Texture
= TEXTURE_NAME_ACID2
);
173 procedure CreateDoorMap();
175 PanelArray
: Array of record
181 a
, b
, c
, m
, i
, len
: Integer;
189 SetLength(PanelArray
, len
);
191 for a
:= 0 to High(gWalls
) do
192 if gWalls
[a
].Door
then
194 PanelArray
[i
].X
:= gWalls
[a
].X
;
195 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
196 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
197 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
198 PanelArray
[i
].Active
:= True;
199 PanelArray
[i
].PanelID
:= a
;
205 SetLength(PanelArray
, len
);
216 SetLength(gDoorMap
, 0);
218 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
221 if PanelArray
[a
].Active
then
223 PanelArray
[a
].Active
:= False;
224 m
:= Length(gDoorMap
);
225 SetLength(gDoorMap
, m
+1);
226 SetLength(gDoorMap
[m
], 1);
227 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
235 if PanelArray
[b
].Active
then
236 for c
:= 0 to High(gDoorMap
[m
]) do
237 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
238 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
239 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
240 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
241 gWalls
[gDoorMap
[m
, c
]].X
,
242 gWalls
[gDoorMap
[m
, c
]].Y
,
243 gWalls
[gDoorMap
[m
, c
]].Width
,
244 gWalls
[gDoorMap
[m
, c
]].Height
) then
246 PanelArray
[b
].Active
:= False;
247 SetLength(gDoorMap
[m
],
248 Length(gDoorMap
[m
])+1);
249 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
255 g_Game_StepLoading();
261 procedure CreateLiftMap();
263 PanelArray
: Array of record
268 a
, b
, c
, len
, i
, j
: Integer;
274 len
:= Length(gLifts
);
275 SetLength(PanelArray
, len
);
277 for a
:= 0 to len
-1 do
279 PanelArray
[a
].X
:= gLifts
[a
].X
;
280 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
281 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
282 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
283 PanelArray
[a
].Active
:= True;
286 SetLength(gLiftMap
, len
);
289 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
291 for a
:= 0 to len
-1 do
292 if PanelArray
[a
].Active
then
294 PanelArray
[a
].Active
:= False;
295 SetLength(gLiftMap
[i
], 32);
303 for b
:= 0 to len
-1 do
304 if PanelArray
[b
].Active
then
306 if g_CollideAround(PanelArray
[b
].X
,
309 PanelArray
[b
].Height
,
310 PanelArray
[gLiftMap
[i
, c
]].X
,
311 PanelArray
[gLiftMap
[i
, c
]].Y
,
312 PanelArray
[gLiftMap
[i
, c
]].Width
,
313 PanelArray
[gLiftMap
[i
, c
]].Height
) then
315 PanelArray
[b
].Active
:= False;
317 if j
> High(gLiftMap
[i
]) then
318 SetLength(gLiftMap
[i
],
319 Length(gLiftMap
[i
])+32);
328 SetLength(gLiftMap
[i
], j
+1);
331 g_Game_StepLoading();
334 SetLength(gLiftMap
, i
);
339 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
340 CurTex
: Integer; sav
: Boolean): Integer;
343 panels
: ^TPanelArray
;
347 case PanelRec
.PanelType
of
348 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
351 panels
:= @gRenderBackgrounds
;
353 panels
:= @gRenderForegrounds
;
362 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
365 panels
:= @gBlockMon
;
370 len
:= Length(panels
^);
371 SetLength(panels
^, len
+ 1);
373 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
,
376 panels
^[len
].SaveIt
:= True;
380 len
:= Length(PanelByID
);
381 SetLength(PanelByID
, len
+ 1);
382 PanelByID
[len
].PWhere
:= panels
;
383 PanelByID
[len
].PArrID
:= Result
;
386 function CreateNullTexture(RecName
: String): Integer;
388 SetLength(Textures
, Length(Textures
)+1);
389 result
:= High(Textures
);
391 with Textures
[High(Textures
)] do
393 TextureName
:= RecName
;
397 TextureID
:= TEXTURE_NONE
;
401 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
404 TextureData
: Pointer;
405 WADName
, txname
: String;
406 a
, ResLength
: Integer;
410 if Textures
<> nil then
411 for a
:= 0 to High(Textures
) do
412 if Textures
[a
].TextureName
= RecName
then
413 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
418 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
419 if (RecName
= TEXTURE_NAME_WATER
) or
420 (RecName
= TEXTURE_NAME_ACID1
) or
421 (RecName
= TEXTURE_NAME_ACID2
) then
423 SetLength(Textures
, Length(Textures
)+1);
425 with Textures
[High(Textures
)] do
427 TextureName
:= RecName
;
429 if TextureName
= TEXTURE_NAME_WATER
then
430 TextureID
:= TEXTURE_SPECIAL_WATER
432 if TextureName
= TEXTURE_NAME_ACID1
then
433 TextureID
:= TEXTURE_SPECIAL_ACID1
435 if TextureName
= TEXTURE_NAME_ACID2
then
436 TextureID
:= TEXTURE_SPECIAL_ACID2
;
441 result
:= High(Textures
);
445 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
446 WADName
:= g_ExtractWadName(RecName
);
448 WAD
:= TWADFile
.Create();
450 if WADName
<> '' then
451 WADName
:= GameDir
+'/wads/'+WADName
455 WAD
.ReadFile(WADName
);
459 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
461 FreeMem(TextureData);
462 RecName := 'COMMON\ALIEN';
466 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
468 SetLength(Textures
, Length(Textures
)+1);
469 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
471 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
472 @Textures
[High(Textures
)].Width
,
473 @Textures
[High(Textures
)].Height
);
474 FreeMem(TextureData
);
475 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
476 Textures
[High(Textures
)].Anim
:= False;
478 result
:= High(Textures
);
480 else // Íåò òàêîãî ðåóñðñà â WAD'å
482 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
485 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
486 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
493 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
496 TextureWAD
: PChar = nil;
497 TextData
: Pointer = nil;
498 TextureData
: Pointer = nil;
502 TextureResource
: String;
503 _width
, _height
, _framecount
, _speed
: Integer;
504 _backanimation
: Boolean;
506 ia
: TDynImageDataArray
= nil;
507 f
, c
, frdelay
, frloop
: Integer;
511 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
513 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
514 WADName
:= g_ExtractWadName(RecName
);
516 WAD
:= TWADFile
.Create();
518 if WADName
<> '' then
519 WADName
:= GameDir
+'/wads/'+WADName
523 WAD
.ReadFile(WADName
);
525 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
529 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
530 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
536 if WADName = Map then
538 //FreeMem(TextureWAD);
539 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
545 if ResLength
< 6 then
547 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
551 // ýòî ïòèöà? ýòî ñàìîë¸ò?
552 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
553 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
555 // íåò, ýòî ñóïåðìåí!
556 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
558 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
562 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
563 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
565 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
569 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
571 TextureResource
:= cfg
.ReadStr('', 'resource', '');
572 if TextureResource
= '' then
574 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
578 _width
:= cfg
.ReadInt('', 'framewidth', 0);
579 _height
:= cfg
.ReadInt('', 'frameheight', 0);
580 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
581 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
582 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
587 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
588 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
590 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
597 SetLength(Textures
, Length(Textures
)+1);
598 with Textures
[High(Textures
)] do
600 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
601 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
603 TextureName
:= RecName
;
607 FramesCount
:= _framecount
;
609 result
:= High(Textures
);
613 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
619 // try animated image
621 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
622 if length(imgfmt) = 0 then
624 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
628 GlobalMetadata
.ClearMetaItems();
629 GlobalMetadata
.ClearMetaItemsForSaving();
630 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
632 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
635 if length(ia
) = 0 then
637 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
644 _width
:= ia
[0].width
;
645 _height
:= ia
[0].height
;
646 _framecount
:= length(ia
);
648 _backanimation
:= false;
651 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
653 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
655 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
657 if f
< 0 then f
:= 0;
660 if c
< 13 then c
:= 0 else c
:= 1;
662 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
667 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
669 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
671 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
673 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
677 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
678 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
679 f
:= ord(_backanimation
);
680 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
);
682 SetLength(Textures
, Length(Textures
)+1);
683 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
684 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
686 Textures
[High(Textures
)].TextureName
:= RecName
;
687 Textures
[High(Textures
)].Width
:= _width
;
688 Textures
[High(Textures
)].Height
:= _height
;
689 Textures
[High(Textures
)].Anim
:= True;
690 Textures
[High(Textures
)].FramesCount
:= length(ia
);
691 Textures
[High(Textures
)].Speed
:= _speed
;
692 result
:= High(Textures
);
693 //writeln(' CREATED!');
697 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
701 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
704 if TextureWAD
<> nil then FreeMem(TextureWAD
);
705 if TextData
<> nil then FreeMem(TextData
);
706 if TextureData
<> nil then FreeMem(TextureData
);
710 procedure CreateItem(Item
: TItemRec_1
);
712 if g_Game_IsClient
then Exit
;
714 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
715 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
718 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
719 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
722 procedure CreateArea(Area
: TAreaRec_1
);
727 case Area
.AreaType
of
728 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
729 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
731 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
732 with RespawnPoints
[High(RespawnPoints
)] do
736 Direction
:= TDirection(Area
.Direction
);
738 case Area
.AreaType
of
739 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
740 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
741 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
742 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
743 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
748 AREA_REDFLAG
, AREA_BLUEFLAG
:
750 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
752 if FlagPoints
[a
] <> nil then Exit
;
756 with FlagPoints
[a
]^ do
758 X
:= Area
.X
-FLAGRECT
.X
;
759 Y
:= Area
.Y
-FLAGRECT
.Y
;
760 Direction
:= TDirection(Area
.Direction
);
766 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
767 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
770 Animation
:= TAnimation
.Create(id
, True, 8);
771 Obj
.Rect
:= FLAGRECT
;
779 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
780 with DOMFlagPoints[High(DOMFlagPoints)] do
784 Direction := TDirection(Area.Direction);
787 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
792 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
796 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
802 Width
:= Trigger
.Width
;
803 Height
:= Trigger
.Height
;
804 Enabled
:= ByteBool(Trigger
.Enabled
);
805 TexturePanel
:= Trigger
.TexturePanel
;
806 TexturePanelType
:= fTexturePanel1Type
;
807 ShotPanelType
:= fTexturePanel2Type
;
808 TriggerType
:= Trigger
.TriggerType
;
809 ActivateType
:= Trigger
.ActivateType
;
810 Keys
:= Trigger
.Keys
;
811 Data
.Default
:= Trigger
.DATA
;
814 g_Triggers_Create(_trigger
);
817 procedure CreateMonster(monster
: TMonsterRec_1
);
821 if g_Game_IsClient
then Exit
;
823 if (gGameSettings
.GameType
= GT_SINGLE
)
824 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
826 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
827 TDirection(monster
.Direction
));
829 if gTriggers
<> nil then
830 for a
:= 0 to High(gTriggers
) do
831 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
832 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
833 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
834 gMonsters
[i
].AddTrigger(a
);
836 if monster
.MonsterType
<> MONSTER_BARREL
then
841 procedure g_Map_ReAdd_DieTriggers();
845 if g_Game_IsClient
then Exit
;
847 for i
:= 0 to High(gMonsters
) do
848 if gMonsters
[i
] <> nil then
850 gMonsters
[i
].ClearTriggers();
852 for a
:= 0 to High(gTriggers
) do
853 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
854 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
855 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
856 gMonsters
[i
].AddTrigger(a
);
860 function extractWadName(resourceName
: string): string;
864 posN
:= Pos(':', resourceName
);
866 Result
:= Copy(resourceName
, 0, posN
-1)
871 procedure addResToExternalResList(res
: string);
873 res
:= extractWadName(res
);
874 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
875 gExternalResources
.Add(res
);
878 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
880 textures
: TTexturesRec1Array
;
881 mapHeader
: TMapHeaderRec_1
;
883 resFile
: String = '';
885 if gExternalResources
= nil then
886 gExternalResources
:= TStringList
.Create
;
888 gExternalResources
.Clear
;
889 textures
:= mapReader
.GetTextures();
890 for i
:= 0 to High(textures
) do
892 addResToExternalResList(resFile
);
897 mapHeader
:= mapReader
.GetMapHeader
;
899 addResToExternalResList(mapHeader
.MusicName
);
900 addResToExternalResList(mapHeader
.SkyName
);
903 function g_Map_Load(Res
: String): Boolean;
905 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
906 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
909 MapReader
: TMapReader_1
;
910 Header
: TMapHeaderRec_1
;
911 _textures
: TTexturesRec1Array
;
912 _texnummap
: array of Integer; // `_textures` -> `Textures`
913 panels
: TPanelsRec1Array
;
914 items
: TItemsRec1Array
;
915 monsters
: TMonsterRec1Array
;
916 areas
: TAreasRec1Array
;
917 triggers
: TTriggersRec1Array
;
920 AddTextures
: TAddTextureArray
;
921 texture
: TTextureRec_1
;
922 TriggersTable
: Array of record
923 TexturePanel
: Integer;
928 FileName
, mapResName
, s
, TexName
: String;
931 ok
, isAnim
, trigRef
: Boolean;
932 CurTex
, ntn
: Integer;
936 TriggersTable
:= nil;
937 FillChar(texture
, SizeOf(texture
), 0);
939 sfsGCDisable(); // temporary disable removing of temporary volumes
942 FileName
:= g_ExtractWadName(Res
);
943 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
944 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
946 WAD
:= TWADFile
.Create();
947 if not WAD
.ReadFile(FileName
) then
949 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
953 //k8: why loader ignores path here?
954 mapResName
:= g_ExtractFileName(Res
);
955 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
957 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
965 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
966 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
967 MapReader
:= TMapReader_1
.Create();
969 if not MapReader
.LoadMap(Data
) then
971 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
978 generateExternalResourcesList(MapReader
);
980 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
981 _textures
:= MapReader
.GetTextures();
984 // Äîáàâëåíèå òåêñòóð â Textures[]:
985 if _textures
<> nil then
987 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
988 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
989 SetLength(_texnummap
, length(_textures
));
991 for a
:= 0 to High(_textures
) do
994 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
995 for b
:= 1 to Length(s
) do
1001 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1002 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1003 // Àíèìèðîâàííàÿ òåêñòóðà:
1004 if ByteBool(_textures
[a
].Anim
) then
1006 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1009 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1010 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1013 else // Îáû÷íàÿ òåêñòóðà:
1014 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1017 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1018 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1021 _texnummap
[a
] := ntn
; // fix texture number
1022 g_Game_StepLoading();
1026 // Çàãðóçêà òðèããåðîâ:
1027 gTriggerClientID
:= 0;
1028 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1029 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1030 triggers
:= MapReader
.GetTriggers();
1032 // Çàãðóçêà ïàíåëåé:
1033 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1034 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1035 panels
:= MapReader
.GetPanels();
1037 // check texture numbers for panels
1038 for a
:= 0 to High(panels
) do
1040 if panels
[a
].TextureNum
> High(_textures
) then
1042 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1046 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1049 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1050 if triggers
<> nil then
1052 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1053 SetLength(TriggersTable
, Length(triggers
));
1054 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1056 for a
:= 0 to High(TriggersTable
) do
1058 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1059 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1061 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1062 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1064 TriggersTable
[a
].LiftPanel
:= -1;
1066 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1067 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1068 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1069 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1071 TriggersTable
[a
].DoorPanel
:= -1;
1073 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1074 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1076 TriggersTable
[a
].ShotPanel
:= -1;
1078 g_Game_StepLoading();
1083 if panels
<> nil then
1085 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1086 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1088 for a
:= 0 to High(panels
) do
1090 SetLength(AddTextures
, 0);
1093 if _textures
<> nil then
1095 texture
:= _textures
[panels
[a
].TextureNum
];
1103 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1104 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1106 if (TriggersTable
<> nil) and (_textures
<> nil) then
1107 for b
:= 0 to High(TriggersTable
) do
1108 if (TriggersTable
[b
].TexturePanel
= a
)
1109 or (TriggersTable
[b
].ShotPanel
= a
) then
1118 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1120 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1123 for c
:= Len
downto 1 do
1131 // Ñïåö-òåêñòóðû çàïðåùåíû:
1132 if g_Map_IsSpecialTexture(s
) then
1135 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1136 ok
:= g_Texture_NumNameFindStart(s
);
1138 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1139 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1142 k
:= NNF_NAME_BEFORE
;
1143 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1144 while ok
or (k
= NNF_NAME_BEFORE
) or
1145 (k
= NNF_NAME_EQUALS
) do
1147 k
:= g_Texture_NumNameFindNext(TexName
);
1149 if (k
= NNF_NAME_BEFORE
) or
1150 (k
= NNF_NAME_AFTER
) then
1152 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1153 if ByteBool(texture
.Anim
) then
1154 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1156 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1158 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1160 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1164 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1166 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1168 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1170 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1174 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1177 for c
:= 0 to High(Textures
) do
1178 if Textures
[c
].TextureName
= TexName
then
1180 SetLength(AddTextures
, Length(AddTextures
)+1);
1181 AddTextures
[High(AddTextures
)].Texture
:= c
;
1182 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1188 if k
= NNF_NAME_EQUALS
then
1190 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1191 SetLength(AddTextures
, Length(AddTextures
)+1);
1192 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1193 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1194 CurTex
:= High(AddTextures
);
1202 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1203 end; // if ok - ññûëàþòñÿ òðèããåðû
1207 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1208 SetLength(AddTextures
, 1);
1209 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1210 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1214 //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);
1216 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1217 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1219 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1220 if TriggersTable
<> nil then
1221 for b
:= 0 to High(TriggersTable
) do
1223 // Òðèããåð äâåðè/ëèôòà:
1224 if (TriggersTable
[b
].LiftPanel
= a
) or
1225 (TriggersTable
[b
].DoorPanel
= a
) then
1226 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1227 // Òðèããåð ñìåíû òåêñòóðû:
1228 if TriggersTable
[b
].TexturePanel
= a
then
1229 triggers
[b
].TexturePanel
:= PanelID
;
1230 // Òðèããåð "Òóðåëü":
1231 if TriggersTable
[b
].ShotPanel
= a
then
1232 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1235 g_Game_StepLoading();
1239 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1240 if (triggers
<> nil) and not gLoadGameMode
then
1242 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1243 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1244 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1245 for a
:= 0 to High(triggers
) do
1247 if triggers
[a
].TexturePanel
<> -1 then
1248 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1251 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1252 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1253 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1256 CreateTrigger(triggers
[a
], b
, c
);
1260 // Çàãðóçêà ïðåäìåòîâ:
1261 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1262 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1263 items
:= MapReader
.GetItems();
1265 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1266 if (items
<> nil) and not gLoadGameMode
then
1268 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1269 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1270 for a
:= 0 to High(items
) do
1271 CreateItem(Items
[a
]);
1274 // Çàãðóçêà îáëàñòåé:
1275 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1276 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1277 areas
:= MapReader
.GetAreas();
1279 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1280 if areas
<> nil then
1282 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1283 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1284 for a
:= 0 to High(areas
) do
1285 CreateArea(areas
[a
]);
1288 // Çàãðóçêà ìîíñòðîâ:
1289 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1290 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1291 monsters
:= MapReader
.GetMonsters();
1293 gTotalMonsters
:= 0;
1295 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1296 if (monsters
<> nil) and not gLoadGameMode
then
1298 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1299 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1300 for a
:= 0 to High(monsters
) do
1301 CreateMonster(monsters
[a
]);
1304 // Çàãðóçêà îïèñàíèÿ êàðòû:
1305 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1306 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1307 Header
:= MapReader
.GetMapHeader();
1313 Name
:= Header
.MapName
;
1314 Description
:= Header
.MapDescription
;
1315 Author
:= Header
.MapAuthor
;
1316 MusicName
:= Header
.MusicName
;
1317 SkyName
:= Header
.SkyName
;
1318 Height
:= Header
.Height
;
1319 Width
:= Header
.Width
;
1323 if gMapInfo
.SkyName
<> '' then
1325 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1326 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1327 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1329 if FileName
<> '' then
1330 FileName
:= GameDir
+'/wads/'+FileName
1333 FileName
:= g_ExtractWadName(Res
);
1336 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1337 if g_Texture_CreateWAD(BackID
, s
) then
1339 g_Game_SetupScreenSize();
1342 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1347 if gMapInfo
.MusicName
<> '' then
1349 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1350 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1351 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1353 if FileName
<> '' then
1354 FileName
:= GameDir
+'/wads/'+FileName
1357 FileName
:= g_ExtractWadName(Res
);
1360 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1361 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1364 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1367 // Îñòàëüíûå óñòàíâêè:
1375 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1376 if not gLoadGameMode
then
1379 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1385 TriggersTable
:= nil;
1388 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1389 if ok
and (not gLoadGameMode
) then
1391 gMusic
.SetByName(gMapInfo
.MusicName
);
1395 gMusic
.SetByName('');
1397 sfsGCEnable(); // enable releasing unused volumes
1400 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1404 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1407 MapReader
: TMapReader_1
;
1408 Header
: TMapHeaderRec_1
;
1413 FillChar(Result
, SizeOf(Result
), 0);
1414 FileName
:= g_ExtractWadName(Res
);
1416 WAD
:= TWADFile
.Create();
1417 if not WAD
.ReadFile(FileName
) then
1423 //k8: it ignores path again
1424 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1432 MapReader
:= TMapReader_1
.Create();
1434 if not MapReader
.LoadMap(Data
) then
1436 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1437 ZeroMemory(@Header
, SizeOf(Header
));
1438 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1439 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1443 Header
:= MapReader
.GetMapHeader();
1444 Result
.Name
:= Header
.MapName
;
1445 Result
.Description
:= Header
.MapDescription
;
1452 Result
.Author
:= Header
.MapAuthor
;
1453 Result
.Height
:= Header
.Height
;
1454 Result
.Width
:= Header
.Width
;
1457 function g_Map_GetMapsList(WADName
: string): SArray
;
1464 WAD
:= TWADFile
.Create();
1465 if not WAD
.ReadFile(WADName
) then
1470 ResList
:= WAD
.GetMapResources();
1471 if ResList
<> nil then
1473 for a
:= 0 to High(ResList
) do
1475 SetLength(Result
, Length(Result
)+1);
1476 Result
[High(Result
)] := ResList
[a
];
1482 function g_Map_Exist(Res
: string): Boolean;
1485 FileName
, mnn
: string;
1491 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1493 WAD
:= TWADFile
.Create
;
1494 if not WAD
.ReadFile(FileName
) then
1500 ResList
:= WAD
.GetMapResources();
1503 mnn
:= g_ExtractFileName(Res
);
1504 if ResList
<> nil then
1505 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1512 procedure g_Map_Free();
1516 procedure FreePanelArray(var panels
: TPanelArray
);
1521 if panels
<> nil then
1523 for i
:= 0 to High(panels
) do
1536 RespawnPoints
:= nil;
1537 if FlagPoints
[FLAG_RED
] <> nil then
1539 Dispose(FlagPoints
[FLAG_RED
]);
1540 FlagPoints
[FLAG_RED
] := nil;
1542 if FlagPoints
[FLAG_BLUE
] <> nil then
1544 Dispose(FlagPoints
[FLAG_BLUE
]);
1545 FlagPoints
[FLAG_BLUE
] := nil;
1547 //DOMFlagPoints := nil;
1551 if Textures
<> nil then
1553 for a
:= 0 to High(Textures
) do
1554 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1555 if Textures
[a
].Anim
then
1556 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1558 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1559 e_DeleteTexture(Textures
[a
].TextureID
);
1564 FreePanelArray(gWalls
);
1565 FreePanelArray(gRenderBackgrounds
);
1566 FreePanelArray(gRenderForegrounds
);
1567 FreePanelArray(gWater
);
1568 FreePanelArray(gAcid1
);
1569 FreePanelArray(gAcid2
);
1570 FreePanelArray(gSteps
);
1571 FreePanelArray(gLifts
);
1572 FreePanelArray(gBlockMon
);
1574 if BackID
<> DWORD(-1) then
1578 e_DeleteTexture(BackID
);
1579 BackID
:= DWORD(-1);
1582 g_Game_StopAllSounds(False);
1584 g_Sound_Delete(gMapInfo
.MusicName
);
1586 gMapInfo
.Name
:= '';
1587 gMapInfo
.Description
:= '';
1588 gMapInfo
.MusicName
:= '';
1589 gMapInfo
.Height
:= 0;
1590 gMapInfo
.Width
:= 0;
1598 procedure g_Map_Update();
1604 procedure UpdatePanelArray(var panels
: TPanelArray
);
1609 if panels
<> nil then
1610 for i
:= 0 to High(panels
) do
1615 UpdatePanelArray(gWalls
);
1616 UpdatePanelArray(gRenderBackgrounds
);
1617 UpdatePanelArray(gRenderForegrounds
);
1618 UpdatePanelArray(gWater
);
1619 UpdatePanelArray(gAcid1
);
1620 UpdatePanelArray(gAcid2
);
1621 UpdatePanelArray(gSteps
);
1623 if gGameSettings
.GameMode
= GM_CTF
then
1625 for a
:= FLAG_RED
to FLAG_BLUE
do
1626 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1629 if gFlags
[a
].Animation
<> nil then
1630 gFlags
[a
].Animation
.Update();
1632 m
:= g_Obj_Move(@Obj
, True, True);
1634 if gTime
mod (GAME_TICK
*2) <> 0 then
1637 // Ñîïðîòèâëåíèå âîçäóõà:
1638 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1640 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1641 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1644 gFlags
[a
].CaptureTime
:= 0;
1645 if a
= FLAG_RED
then
1646 s
:= _lc
[I_PLAYER_FLAG_RED
]
1648 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1649 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1651 if g_Game_IsNet
then
1652 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1659 // Èãðîê áåðåò ôëàã:
1660 if gPlayers
<> nil then
1662 j
:= Random(Length(gPlayers
)) - 1;
1664 for d
:= 0 to High(gPlayers
) do
1667 if j
> High(gPlayers
) then
1670 if gPlayers
[j
] <> nil then
1671 if gPlayers
[j
].Live
and
1672 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1674 if gPlayers
[j
].GetFlag(a
) then
1685 pvpset
: array of PPanel
= nil; // potentially lit panels
1686 pvpb
, pvpe
: array [0..7] of Integer; // start/end (inclusive) of the correspoinding type panels in pvpset
1687 pvpcount
: Integer = -1; // to avoid constant reallocations
1689 function pvpType (panelType
: Word): Integer;
1692 PANEL_WALL
, PANEL_CLOSEDOOR
: result
:= 0; // gWalls
1693 PANEL_BACK
: result
:= 1; // gRenderBackgrounds
1694 PANEL_FORE
: result
:= 2; // gRenderForegrounds
1695 PANEL_WATER
: result
:= 3; // gWater
1696 PANEL_ACID1
: result
:= 4; // gAcid1
1697 PANEL_ACID2
: result
:= 5; // gAcid2
1698 PANEL_STEP
: result
:= 6; // gSteps
1703 procedure g_Map_ResetPVP ();
1705 pvpcount
:= -1; // special
1708 procedure g_Map_BuildPVP (minx
, miny
, maxx
, maxy
: Integer);
1713 procedure checkPanels (var panels
: TPanelArray
; stp
: Integer);
1715 idx
, x
, y
, w
, h
: Integer;
1717 if panels
= nil then exit
;
1718 tpc
:= tpc
+Length(panels
);
1719 if (stp
< 0) or (stp
> 6) then exit
;
1720 pvpb
[stp
] := pvpcount
;
1721 for idx
:= 0 to High(panels
) do
1723 w
:= panels
[idx
].Width
;
1724 h
:= panels
[idx
].Height
;
1725 if (w
< 1) or (h
< 1) then continue
;
1728 if (x
> maxx
) or (y
> maxy
) then continue
;
1729 if (x
+w
<= minx
) or (y
+h
<= miny
) then continue
;
1730 if pvpcount
= length(pvpset
) then SetLength(pvpset
, pvpcount
+32768);
1731 pvpset
[pvpcount
] := @panels
[idx
];
1734 pvpe
[stp
] := pvpcount
-1;
1738 //e_WriteLog(Format('visible rect: (%d,%d)-(%d,%d)', [minx, miny, maxx, maxy]), MSG_NOTIFY);
1740 for idx
:= 0 to High(pvpb
) do begin pvpb
[idx
] := 0; pvpe
[idx
] := -1; end;
1742 checkPanels(gWalls
, 0);
1743 checkPanels(gRenderBackgrounds
, 1);
1744 checkPanels(gRenderForegrounds
, 2);
1745 checkPanels(gWater
, 3);
1746 checkPanels(gAcid1
, 4);
1747 checkPanels(gAcid2
, 5);
1748 checkPanels(gSteps
, 6);
1749 //e_WriteLog(Format('total panels: %d; visible panels: %d', [tpc, pvpcount]), MSG_NOTIFY);
1752 procedure g_Map_DrawPanels(PanelType
: Word);
1754 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1758 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1760 if pvpcount
< 0 then
1762 // alas, no visible set
1763 for idx
:= 0 to High(panels
) do
1765 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1770 // wow, use visible set
1771 if pvpb
[stp
] <= pvpe
[stp
] then
1773 for idx
:= pvpb
[stp
] to pvpe
[stp
] do
1775 if not (drawDoors
xor pvpset
[idx
].Door
) then pvpset
[idx
].Draw();
1784 PANEL_WALL
: DrawPanels(0, gWalls
);
1785 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1786 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1787 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1788 PANEL_WATER
: DrawPanels(3, gWater
);
1789 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1790 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1791 PANEL_STEP
: DrawPanels(6, gSteps
);
1795 procedure g_Map_DrawBack(dx
, dy
: Integer);
1797 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1798 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1800 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1803 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
1804 PanelType
: Word; b1x3
: Boolean): Boolean;
1810 if WordBool(PanelType
and PANEL_WALL
) then
1811 if gWalls
<> nil then
1816 if gWalls
[a
].Enabled
and
1817 g_Collide(X
, Y
, Width
, Height
,
1818 gWalls
[a
].X
, gWalls
[a
].Y
,
1819 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1826 if WordBool(PanelType
and PANEL_WATER
) then
1827 if gWater
<> nil then
1832 if g_Collide(X
, Y
, Width
, Height
,
1833 gWater
[a
].X
, gWater
[a
].Y
,
1834 gWater
[a
].Width
, gWater
[a
].Height
) then
1841 if WordBool(PanelType
and PANEL_ACID1
) then
1842 if gAcid1
<> nil then
1847 if g_Collide(X
, Y
, Width
, Height
,
1848 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1849 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1856 if WordBool(PanelType
and PANEL_ACID2
) then
1857 if gAcid2
<> nil then
1862 if g_Collide(X
, Y
, Width
, Height
,
1863 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1864 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1871 if WordBool(PanelType
and PANEL_STEP
) then
1872 if gSteps
<> nil then
1877 if g_Collide(X
, Y
, Width
, Height
,
1878 gSteps
[a
].X
, gSteps
[a
].Y
,
1879 gSteps
[a
].Width
, gSteps
[a
].Height
) then
1886 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
1887 if gLifts
<> nil then
1892 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
1893 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
1894 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
1895 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
1896 g_Collide(X
, Y
, Width
, Height
,
1897 gLifts
[a
].X
, gLifts
[a
].Y
,
1898 gLifts
[a
].Width
, gLifts
[a
].Height
) then
1905 if WordBool(PanelType
and PANEL_BLOCKMON
) then
1906 if gBlockMon
<> nil then
1908 h
:= High(gBlockMon
);
1912 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
1913 g_Collide(X
, Y
, Width
, Height
,
1914 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
1915 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
1923 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
1927 Result
:= TEXTURE_NONE
;
1929 if gWater
<> nil then
1934 if g_Collide(X
, Y
, Width
, Height
,
1935 gWater
[a
].X
, gWater
[a
].Y
,
1936 gWater
[a
].Width
, gWater
[a
].Height
) then
1938 Result
:= gWater
[a
].GetTextureID();
1943 if gAcid1
<> nil then
1948 if g_Collide(X
, Y
, Width
, Height
,
1949 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1950 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1952 Result
:= gAcid1
[a
].GetTextureID();
1957 if gAcid2
<> nil then
1962 if g_Collide(X
, Y
, Width
, Height
,
1963 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1964 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1966 Result
:= gAcid2
[a
].GetTextureID();
1972 procedure g_Map_EnableWall(ID
: DWORD
);
1977 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
1979 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1983 procedure g_Map_DisableWall(ID
: DWORD
);
1988 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
1990 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1994 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
1999 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2002 tp
:= gRenderForegrounds
[ID
];
2004 tp
:= gRenderBackgrounds
[ID
];
2017 tp
.NextTexture(AnimLoop
);
2018 if g_Game_IsServer
and g_Game_IsNet
then
2019 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2022 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2024 if gLifts
[ID
].LiftType
= t
then
2031 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2033 if LiftType
= 0 then
2034 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2035 else if LiftType
= 1 then
2036 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2037 else if LiftType
= 2 then
2038 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2039 else if LiftType
= 3 then
2040 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2042 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2046 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2049 PointsArray
: Array of TRespawnPoint
;
2052 SetLength(PointsArray
, 0);
2054 if RespawnPoints
= nil then
2057 for a
:= 0 to High(RespawnPoints
) do
2058 if RespawnPoints
[a
].PointType
= PointType
then
2060 SetLength(PointsArray
, Length(PointsArray
)+1);
2061 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2064 if PointsArray
= nil then
2067 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2071 function g_Map_GetPointCount(PointType
: Byte): Word;
2077 if RespawnPoints
= nil then
2080 for a
:= 0 to High(RespawnPoints
) do
2081 if RespawnPoints
[a
].PointType
= PointType
then
2082 Result
:= Result
+ 1;
2085 function g_Map_HaveFlagPoints(): Boolean;
2087 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2090 procedure g_Map_ResetFlag(Flag
: Byte);
2092 with gFlags
[Flag
] do
2098 Direction
:= D_LEFT
;
2099 State
:= FLAG_STATE_NONE
;
2100 if FlagPoints
[Flag
] <> nil then
2102 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2103 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2104 Direction
:= FlagPoints
[Flag
]^.Direction
;
2105 State
:= FLAG_STATE_NORMAL
;
2111 procedure g_Map_DrawFlags();
2114 Mirror
: TMirrorType
;
2116 if gGameSettings
.GameMode
<> GM_CTF
then
2119 for i
:= FLAG_RED
to FLAG_BLUE
do
2121 if State
<> FLAG_STATE_CAPTURED
then
2123 if State
= FLAG_STATE_NONE
then
2126 if Direction
= D_LEFT
then
2128 Mirror
:= M_HORIZONTAL
;
2137 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2139 if g_debug_Frames
then
2141 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2143 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2144 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2150 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2157 procedure SavePanelArray(var panels
: TPanelArray
);
2159 PAMem
: TBinMemoryWriter
;
2162 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2163 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2166 while i
< Length(panels
) do
2168 if panels
[i
].SaveIt
then
2172 // Ñîõðàíÿåì ïàíåëü:
2173 panels
[i
].SaveState(PAMem
);
2178 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2179 PAMem
.SaveToMemory(Mem
);
2183 procedure SaveFlag(flag
: PFlag
);
2186 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2188 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2189 Mem
.WriteByte(flag
^.RespawnType
);
2191 Mem
.WriteByte(flag
^.State
);
2192 // Íàïðàâëåíèå ôëàãà:
2193 if flag
^.Direction
= D_LEFT
then
2199 Obj_SaveState(@flag
^.Obj
, Mem
);
2203 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2205 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2206 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2207 SavePanelArray(gWalls
);
2208 // Ñîõðàíÿåì ïàíåëè ôîíà:
2209 SavePanelArray(gRenderBackgrounds
);
2210 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2211 SavePanelArray(gRenderForegrounds
);
2212 // Ñîõðàíÿåì ïàíåëè âîäû:
2213 SavePanelArray(gWater
);
2214 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2215 SavePanelArray(gAcid1
);
2216 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2217 SavePanelArray(gAcid2
);
2218 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2219 SavePanelArray(gSteps
);
2220 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2221 SavePanelArray(gLifts
);
2224 ///// Ñîõðàíÿåì ìóçûêó: /////
2225 // Ñèãíàòóðà ìóçûêè:
2226 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2229 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2230 if gMusic
.NoMusic
then
2234 Mem
.WriteString(str
, 64);
2235 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2236 dw
:= gMusic
.GetPosition();
2238 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2239 boo
:= gMusic
.SpecPause
;
2240 Mem
.WriteBoolean(boo
);
2243 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2244 Mem
.WriteInt(gTotalMonsters
);
2247 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2248 if gGameSettings
.GameMode
= GM_CTF
then
2250 // Ôëàã Êðàñíîé êîìàíäû:
2251 SaveFlag(@gFlags
[FLAG_RED
]);
2252 // Ôëàã Ñèíåé êîìàíäû:
2253 SaveFlag(@gFlags
[FLAG_BLUE
]);
2257 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2258 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2260 // Î÷êè Êðàñíîé êîìàíäû:
2261 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2262 // Î÷êè Ñèíåé êîìàíäû:
2263 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2268 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2275 procedure LoadPanelArray(var panels
: TPanelArray
);
2277 PAMem
: TBinMemoryReader
;
2280 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2281 PAMem
:= TBinMemoryReader
.Create();
2282 PAMem
.LoadFromMemory(Mem
);
2284 for i
:= 0 to Length(panels
)-1 do
2285 if panels
[i
].SaveIt
then
2291 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2293 // Çàãðóæàåì ïàíåëü:
2294 panels
[i
].LoadState(PAMem
);
2297 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2301 procedure LoadFlag(flag
: PFlag
);
2305 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2307 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2309 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2310 Mem
.ReadByte(flag
^.RespawnType
);
2312 Mem
.ReadByte(flag
^.State
);
2313 // Íàïðàâëåíèå ôëàãà:
2316 flag
^.Direction
:= D_LEFT
2318 flag
^.Direction
:= D_RIGHT
;
2320 Obj_LoadState(@flag
^.Obj
, Mem
);
2327 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2328 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2329 LoadPanelArray(gWalls
);
2330 // Çàãðóæàåì ïàíåëè ôîíà:
2331 LoadPanelArray(gRenderBackgrounds
);
2332 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2333 LoadPanelArray(gRenderForegrounds
);
2334 // Çàãðóæàåì ïàíåëè âîäû:
2335 LoadPanelArray(gWater
);
2336 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2337 LoadPanelArray(gAcid1
);
2338 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2339 LoadPanelArray(gAcid2
);
2340 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2341 LoadPanelArray(gSteps
);
2342 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2343 LoadPanelArray(gLifts
);
2346 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2349 ///// Çàãðóæàåì ìóçûêó: /////
2350 // Ñèãíàòóðà ìóçûêè:
2352 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2354 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2357 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2358 Mem
.ReadString(str
);
2359 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2361 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2362 Mem
.ReadBoolean(boo
);
2363 // Çàïóñêàåì ýòó ìóçûêó:
2364 gMusic
.SetByName(str
);
2365 gMusic
.SpecPause
:= boo
;
2368 gMusic
.SetPosition(dw
);
2371 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2372 Mem
.ReadInt(gTotalMonsters
);
2375 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2376 if gGameSettings
.GameMode
= GM_CTF
then
2378 // Ôëàã Êðàñíîé êîìàíäû:
2379 LoadFlag(@gFlags
[FLAG_RED
]);
2380 // Ôëàã Ñèíåé êîìàíäû:
2381 LoadFlag(@gFlags
[FLAG_BLUE
]);
2385 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2386 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2388 // Î÷êè Êðàñíîé êîìàíäû:
2389 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2390 // Î÷êè Ñèíåé êîìàíäû:
2391 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2396 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2401 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2402 Arr
:= PanelByID
[PanelID
].PWhere
^;
2403 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2404 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);