b2e35c0eb0b3044abc5308cd98354f286651a9c8
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/>.
17 {$modeswitch nestedprocvars}
23 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
24 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
;
38 PRespawnPoint
= ^TRespawnPoint
;
39 TRespawnPoint
= record
41 Direction
: TDirection
;
45 PFlagPoint
= ^TFlagPoint
;
46 TFlagPoint
= TRespawnPoint
;
54 CaptureTime
: LongWord;
55 Animation
: TAnimation
;
56 Direction
: TDirection
;
59 function g_Map_Load(Res
: String): Boolean;
60 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
61 function g_Map_GetMapsList(WADName
: String): SArray
;
62 function g_Map_Exist(Res
: String): Boolean;
63 procedure g_Map_Free();
64 procedure g_Map_Update();
66 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
68 procedure g_Map_DrawBack(dx
, dy
: Integer);
69 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
70 PanelType
: Word; b1x3
: Boolean): Boolean;
71 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
72 procedure g_Map_EnableWall(ID
: DWORD
);
73 procedure g_Map_DisableWall(ID
: DWORD
);
74 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
75 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
76 procedure g_Map_ReAdd_DieTriggers();
77 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
79 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
80 function g_Map_GetPointCount(PointType
: Byte): Word;
82 function g_Map_HaveFlagPoints(): Boolean;
84 procedure g_Map_ResetFlag(Flag
: Byte);
85 procedure g_Map_DrawFlags();
87 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
89 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
90 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
92 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
95 RESPAWNPOINT_PLAYER1
= 1;
96 RESPAWNPOINT_PLAYER2
= 2;
99 RESPAWNPOINT_BLUE
= 5;
107 FLAG_STATE_NORMAL
= 1;
108 FLAG_STATE_DROPPED
= 2;
109 FLAG_STATE_CAPTURED
= 3;
110 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
111 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_TIME
= 720; // 20 seconds
115 SKY_STRETCH
: Single = 1.5;
119 gRenderBackgrounds
: TPanelArray
;
120 gRenderForegrounds
: TPanelArray
;
121 gWater
, gAcid1
, gAcid2
: TPanelArray
;
124 gBlockMon
: TPanelArray
;
125 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
126 //gDOMFlags: array of TFlag;
129 gDoorMap
: array of array of DWORD
;
130 gLiftMap
: array of array of DWORD
;
131 gWADHash
: TMD5Digest
;
132 BackID
: DWORD
= DWORD(-1);
133 gExternalResources
: TStringList
;
134 gMapGrid
: TBodyGrid
= nil;
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
, CurTex
, Textures
);
374 panels
^[len
].ArrIdx
:= len
;
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;
934 mapX0
: Integer = $3fffffff;
935 mapY0
: Integer = $3fffffff;
936 mapX1
: Integer = -$3fffffff;
937 mapY1
: Integer = -$3fffffff;
939 procedure fixMinMax (var panels
: TPanelArray
);
943 for idx
:= 0 to High(panels
) do
945 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
946 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
947 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
948 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
949 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
953 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
957 for idx
:= High(panels
) downto 0 do
959 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
969 TriggersTable
:= nil;
970 FillChar(texture
, SizeOf(texture
), 0);
972 sfsGCDisable(); // temporary disable removing of temporary volumes
975 FileName
:= g_ExtractWadName(Res
);
976 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
977 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
979 WAD
:= TWADFile
.Create();
980 if not WAD
.ReadFile(FileName
) then
982 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
986 //k8: why loader ignores path here?
987 mapResName
:= g_ExtractFileName(Res
);
988 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
990 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
998 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
999 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1000 MapReader
:= TMapReader_1
.Create();
1002 if not MapReader
.LoadMap(Data
) then
1004 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1011 generateExternalResourcesList(MapReader
);
1012 // Çàãðóçêà òåêñòóð:
1013 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1014 _textures
:= MapReader
.GetTextures();
1017 // Äîáàâëåíèå òåêñòóð â Textures[]:
1018 if _textures
<> nil then
1020 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1021 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1022 SetLength(_texnummap
, length(_textures
));
1024 for a
:= 0 to High(_textures
) do
1027 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1028 for b
:= 1 to Length(s
) do
1034 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1035 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1036 // Àíèìèðîâàííàÿ òåêñòóðà:
1037 if ByteBool(_textures
[a
].Anim
) then
1039 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1042 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1043 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1046 else // Îáû÷íàÿ òåêñòóðà:
1047 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1050 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1051 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1054 _texnummap
[a
] := ntn
; // fix texture number
1055 g_Game_StepLoading();
1059 // Çàãðóçêà òðèããåðîâ:
1060 gTriggerClientID
:= 0;
1061 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1062 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1063 triggers
:= MapReader
.GetTriggers();
1065 // Çàãðóçêà ïàíåëåé:
1066 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1067 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1068 panels
:= MapReader
.GetPanels();
1070 // check texture numbers for panels
1071 for a
:= 0 to High(panels
) do
1073 if panels
[a
].TextureNum
> High(_textures
) then
1075 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1079 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1082 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1083 if triggers
<> nil then
1085 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1086 SetLength(TriggersTable
, Length(triggers
));
1087 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1089 for a
:= 0 to High(TriggersTable
) do
1091 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1092 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1094 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1095 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1097 TriggersTable
[a
].LiftPanel
:= -1;
1099 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1100 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1101 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1102 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1104 TriggersTable
[a
].DoorPanel
:= -1;
1106 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1107 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1109 TriggersTable
[a
].ShotPanel
:= -1;
1111 g_Game_StepLoading();
1116 if panels
<> nil then
1118 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1119 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1121 for a
:= 0 to High(panels
) do
1123 SetLength(AddTextures
, 0);
1126 if _textures
<> nil then
1128 texture
:= _textures
[panels
[a
].TextureNum
];
1136 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1137 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1139 if (TriggersTable
<> nil) and (_textures
<> nil) then
1140 for b
:= 0 to High(TriggersTable
) do
1141 if (TriggersTable
[b
].TexturePanel
= a
)
1142 or (TriggersTable
[b
].ShotPanel
= a
) then
1151 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1153 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1156 for c
:= Len
downto 1 do
1164 // Ñïåö-òåêñòóðû çàïðåùåíû:
1165 if g_Map_IsSpecialTexture(s
) then
1168 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1169 ok
:= g_Texture_NumNameFindStart(s
);
1171 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1172 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1175 k
:= NNF_NAME_BEFORE
;
1176 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1177 while ok
or (k
= NNF_NAME_BEFORE
) or
1178 (k
= NNF_NAME_EQUALS
) do
1180 k
:= g_Texture_NumNameFindNext(TexName
);
1182 if (k
= NNF_NAME_BEFORE
) or
1183 (k
= NNF_NAME_AFTER
) then
1185 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1186 if ByteBool(texture
.Anim
) then
1187 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1189 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1191 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1193 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1197 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1199 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1201 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1203 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1207 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1210 for c
:= 0 to High(Textures
) do
1211 if Textures
[c
].TextureName
= TexName
then
1213 SetLength(AddTextures
, Length(AddTextures
)+1);
1214 AddTextures
[High(AddTextures
)].Texture
:= c
;
1215 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1221 if k
= NNF_NAME_EQUALS
then
1223 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1224 SetLength(AddTextures
, Length(AddTextures
)+1);
1225 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1226 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1227 CurTex
:= High(AddTextures
);
1235 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1236 end; // if ok - ññûëàþòñÿ òðèããåðû
1240 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1241 SetLength(AddTextures
, 1);
1242 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1243 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1247 //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);
1249 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1250 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1252 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1253 if TriggersTable
<> nil then
1254 for b
:= 0 to High(TriggersTable
) do
1256 // Òðèããåð äâåðè/ëèôòà:
1257 if (TriggersTable
[b
].LiftPanel
= a
) or
1258 (TriggersTable
[b
].DoorPanel
= a
) then
1259 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1260 // Òðèããåð ñìåíû òåêñòóðû:
1261 if TriggersTable
[b
].TexturePanel
= a
then
1262 triggers
[b
].TexturePanel
:= PanelID
;
1263 // Òðèããåð "Òóðåëü":
1264 if TriggersTable
[b
].ShotPanel
= a
then
1265 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1268 g_Game_StepLoading();
1272 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1273 if (triggers
<> nil) and not gLoadGameMode
then
1275 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1276 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1277 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1278 for a
:= 0 to High(triggers
) do
1280 if triggers
[a
].TexturePanel
<> -1 then
1281 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1284 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1285 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1286 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1289 CreateTrigger(triggers
[a
], b
, c
);
1293 // Çàãðóçêà ïðåäìåòîâ:
1294 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1295 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1296 items
:= MapReader
.GetItems();
1298 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1299 if (items
<> nil) and not gLoadGameMode
then
1301 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1302 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1303 for a
:= 0 to High(items
) do
1304 CreateItem(Items
[a
]);
1307 // Çàãðóçêà îáëàñòåé:
1308 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1309 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1310 areas
:= MapReader
.GetAreas();
1312 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1313 if areas
<> nil then
1315 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1316 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1317 for a
:= 0 to High(areas
) do
1318 CreateArea(areas
[a
]);
1321 // Çàãðóçêà ìîíñòðîâ:
1322 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1323 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1324 monsters
:= MapReader
.GetMonsters();
1326 gTotalMonsters
:= 0;
1328 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1329 if (monsters
<> nil) and not gLoadGameMode
then
1331 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1332 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1333 for a
:= 0 to High(monsters
) do
1334 CreateMonster(monsters
[a
]);
1337 // Çàãðóçêà îïèñàíèÿ êàðòû:
1338 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1339 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1340 Header
:= MapReader
.GetMapHeader();
1346 Name
:= Header
.MapName
;
1347 Description
:= Header
.MapDescription
;
1348 Author
:= Header
.MapAuthor
;
1349 MusicName
:= Header
.MusicName
;
1350 SkyName
:= Header
.SkyName
;
1351 Height
:= Header
.Height
;
1352 Width
:= Header
.Width
;
1356 if gMapInfo
.SkyName
<> '' then
1358 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1359 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1360 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1362 if FileName
<> '' then
1363 FileName
:= GameDir
+'/wads/'+FileName
1366 FileName
:= g_ExtractWadName(Res
);
1369 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1370 if g_Texture_CreateWAD(BackID
, s
) then
1372 g_Game_SetupScreenSize();
1375 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1380 if gMapInfo
.MusicName
<> '' then
1382 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1383 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1384 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1386 if FileName
<> '' then
1387 FileName
:= GameDir
+'/wads/'+FileName
1390 FileName
:= g_ExtractWadName(Res
);
1393 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1394 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1397 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1400 // Îñòàëüíûå óñòàíâêè:
1408 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1409 if not gLoadGameMode
then
1412 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1418 TriggersTable
:= nil;
1421 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1422 if ok
and (not gLoadGameMode
) then
1424 gMusic
.SetByName(gMapInfo
.MusicName
);
1428 gMusic
.SetByName('');
1430 sfsGCEnable(); // enable releasing unused volumes
1433 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1436 fixMinMax(gRenderBackgrounds
);
1437 fixMinMax(gRenderForegrounds
);
1443 gMapGrid
:= TBodyGrid
.Create(mapX1
+1, mapY1
+1);
1445 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1446 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1447 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1448 addPanelsToGrid(gWater
, PANEL_WATER
);
1449 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1450 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1451 addPanelsToGrid(gSteps
, PANEL_STEP
);
1453 gMapGrid
.dumpStats();
1455 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1459 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1462 MapReader
: TMapReader_1
;
1463 Header
: TMapHeaderRec_1
;
1468 FillChar(Result
, SizeOf(Result
), 0);
1469 FileName
:= g_ExtractWadName(Res
);
1471 WAD
:= TWADFile
.Create();
1472 if not WAD
.ReadFile(FileName
) then
1478 //k8: it ignores path again
1479 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1487 MapReader
:= TMapReader_1
.Create();
1489 if not MapReader
.LoadMap(Data
) then
1491 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1492 ZeroMemory(@Header
, SizeOf(Header
));
1493 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1494 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1498 Header
:= MapReader
.GetMapHeader();
1499 Result
.Name
:= Header
.MapName
;
1500 Result
.Description
:= Header
.MapDescription
;
1507 Result
.Author
:= Header
.MapAuthor
;
1508 Result
.Height
:= Header
.Height
;
1509 Result
.Width
:= Header
.Width
;
1512 function g_Map_GetMapsList(WADName
: string): SArray
;
1519 WAD
:= TWADFile
.Create();
1520 if not WAD
.ReadFile(WADName
) then
1525 ResList
:= WAD
.GetMapResources();
1526 if ResList
<> nil then
1528 for a
:= 0 to High(ResList
) do
1530 SetLength(Result
, Length(Result
)+1);
1531 Result
[High(Result
)] := ResList
[a
];
1537 function g_Map_Exist(Res
: string): Boolean;
1540 FileName
, mnn
: string;
1546 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1548 WAD
:= TWADFile
.Create
;
1549 if not WAD
.ReadFile(FileName
) then
1555 ResList
:= WAD
.GetMapResources();
1558 mnn
:= g_ExtractFileName(Res
);
1559 if ResList
<> nil then
1560 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1567 procedure g_Map_Free();
1571 procedure FreePanelArray(var panels
: TPanelArray
);
1576 if panels
<> nil then
1578 for i
:= 0 to High(panels
) do
1591 RespawnPoints
:= nil;
1592 if FlagPoints
[FLAG_RED
] <> nil then
1594 Dispose(FlagPoints
[FLAG_RED
]);
1595 FlagPoints
[FLAG_RED
] := nil;
1597 if FlagPoints
[FLAG_BLUE
] <> nil then
1599 Dispose(FlagPoints
[FLAG_BLUE
]);
1600 FlagPoints
[FLAG_BLUE
] := nil;
1602 //DOMFlagPoints := nil;
1606 if Textures
<> nil then
1608 for a
:= 0 to High(Textures
) do
1609 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1610 if Textures
[a
].Anim
then
1611 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1613 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1614 e_DeleteTexture(Textures
[a
].TextureID
);
1619 FreePanelArray(gWalls
);
1620 FreePanelArray(gRenderBackgrounds
);
1621 FreePanelArray(gRenderForegrounds
);
1622 FreePanelArray(gWater
);
1623 FreePanelArray(gAcid1
);
1624 FreePanelArray(gAcid2
);
1625 FreePanelArray(gSteps
);
1626 FreePanelArray(gLifts
);
1627 FreePanelArray(gBlockMon
);
1629 if BackID
<> DWORD(-1) then
1633 e_DeleteTexture(BackID
);
1634 BackID
:= DWORD(-1);
1637 g_Game_StopAllSounds(False);
1639 g_Sound_Delete(gMapInfo
.MusicName
);
1641 gMapInfo
.Name
:= '';
1642 gMapInfo
.Description
:= '';
1643 gMapInfo
.MusicName
:= '';
1644 gMapInfo
.Height
:= 0;
1645 gMapInfo
.Width
:= 0;
1653 procedure g_Map_Update();
1659 procedure UpdatePanelArray(var panels
: TPanelArray
);
1664 if panels
<> nil then
1665 for i
:= 0 to High(panels
) do
1670 UpdatePanelArray(gWalls
);
1671 UpdatePanelArray(gRenderBackgrounds
);
1672 UpdatePanelArray(gRenderForegrounds
);
1673 UpdatePanelArray(gWater
);
1674 UpdatePanelArray(gAcid1
);
1675 UpdatePanelArray(gAcid2
);
1676 UpdatePanelArray(gSteps
);
1678 if gGameSettings
.GameMode
= GM_CTF
then
1680 for a
:= FLAG_RED
to FLAG_BLUE
do
1681 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1684 if gFlags
[a
].Animation
<> nil then
1685 gFlags
[a
].Animation
.Update();
1687 m
:= g_Obj_Move(@Obj
, True, True);
1689 if gTime
mod (GAME_TICK
*2) <> 0 then
1692 // Ñîïðîòèâëåíèå âîçäóõà:
1693 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1695 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1696 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1699 gFlags
[a
].CaptureTime
:= 0;
1700 if a
= FLAG_RED
then
1701 s
:= _lc
[I_PLAYER_FLAG_RED
]
1703 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1704 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1706 if g_Game_IsNet
then
1707 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1714 // Èãðîê áåðåò ôëàã:
1715 if gPlayers
<> nil then
1717 j
:= Random(Length(gPlayers
)) - 1;
1719 for d
:= 0 to High(gPlayers
) do
1722 if j
> High(gPlayers
) then
1725 if gPlayers
[j
] <> nil then
1726 if gPlayers
[j
].Live
and
1727 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1729 if gPlayers
[j
].GetFlag(a
) then
1740 function pvpType (panelType: Word): Integer;
1743 PANEL_WALL, PANEL_CLOSEDOOR: result := 0; // gWalls
1744 PANEL_BACK: result := 1; // gRenderBackgrounds
1745 PANEL_FORE: result := 2; // gRenderForegrounds
1746 PANEL_WATER: result := 3; // gWater
1747 PANEL_ACID1: result := 4; // gAcid1
1748 PANEL_ACID2: result := 5; // gAcid2
1749 PANEL_STEP: result := 6; // gSteps
1756 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1758 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1762 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) 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();
1774 PANEL_WALL
: DrawPanels(0, gWalls
);
1775 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1776 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1777 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1778 PANEL_WATER
: DrawPanels(3, gWater
);
1779 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1780 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1781 PANEL_STEP
: DrawPanels(6, gSteps
);
1787 gDrawPanelList
: TBinaryHeapObj
= nil;
1789 function dplLess (a
, b
: TObject
): Boolean;
1791 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1794 procedure dplClear ();
1796 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1799 procedure dplAddPanel (pan
: TPanel
);
1801 if pan
= nil then exit
;
1802 gDrawPanelList
.insert(pan
);
1806 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1808 function qq (obj
: TObject
; tag
: Integer): Boolean;
1812 result
:= false; // don't stop, ever
1814 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1818 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1820 if not (obj
is TPanel
) then
1822 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1825 //pan := (obj as TPanel);
1826 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1828 if (tag
= PANEL_WALL
) then
1830 if (PanelType
= PANEL_WALL
) then
1832 pan
:= (obj
as TPanel
);
1833 if not pan
.Door
then
1835 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1839 else if (PanelType
= PANEL_CLOSEDOOR
) then
1841 pan
:= (obj
as TPanel
);
1844 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1849 else if (PanelType
= tag
) then
1851 pan
:= (obj
as TPanel
);
1852 if not pan
.Door
then
1854 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1860 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1865 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1867 // alas, no visible set
1868 for idx
:= 0 to High(panels
) do
1870 if not (drawDoors
xor panels
[idx
].Door
) then
1873 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1874 if (pan
.X
+pan
.Width
<= x0
) or (pan
.Y
+pan
.Height
<= y0
) then continue
;
1875 if (pan
.X
>= x0
+wdt
) or (pan
.Y
>= y0
+hgt
) then continue
;
1876 e_WriteLog(Format(' *body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan
.X
, pan
.Y
, pan
.Width
, pan
.Height
, PanelType
, PanelType
]), MSG_NOTIFY
);
1883 //g_Map_DrawPanelsOld(PanelType); exit;
1884 //e_WriteLog('==================', MSG_NOTIFY);
1885 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1887 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, qq
);
1891 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1893 PANEL_WALL: DrawPanels(0, gWalls);
1894 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1895 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1896 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1897 PANEL_WATER: DrawPanels(3, gWater);
1898 PANEL_ACID1: DrawPanels(4, gAcid1);
1899 PANEL_ACID2: DrawPanels(5, gAcid2);
1900 PANEL_STEP: DrawPanels(6, gSteps);
1902 e_WriteLog('==================', MSG_NOTIFY);
1905 // sort and draw the list (we need to sort it, or rendering is fucked)
1906 while gDrawPanelList
.count
> 0 do
1908 (gDrawPanelList
.front() as TPanel
).Draw();
1909 gDrawPanelList
.popFront();
1914 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1915 function qq (obj
: TObject
; tag
: Integer): Boolean;
1919 result
:= false; // don't stop, ever
1920 if (tag
<> PANEL_WALL
) then exit
; // only walls
1921 pan
:= (obj
as TPanel
);
1922 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1926 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, qq
);
1930 procedure g_Map_DrawBack(dx
, dy
: Integer);
1932 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1933 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1935 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1938 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1939 PanelType
: Word; b1x3
: Boolean): Boolean;
1945 if WordBool(PanelType
and PANEL_WALL
) then
1946 if gWalls
<> nil then
1951 if gWalls
[a
].Enabled
and
1952 g_Collide(X
, Y
, Width
, Height
,
1953 gWalls
[a
].X
, gWalls
[a
].Y
,
1954 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1961 if WordBool(PanelType
and PANEL_WATER
) then
1962 if gWater
<> nil then
1967 if g_Collide(X
, Y
, Width
, Height
,
1968 gWater
[a
].X
, gWater
[a
].Y
,
1969 gWater
[a
].Width
, gWater
[a
].Height
) then
1976 if WordBool(PanelType
and PANEL_ACID1
) then
1977 if gAcid1
<> nil then
1982 if g_Collide(X
, Y
, Width
, Height
,
1983 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1984 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1991 if WordBool(PanelType
and PANEL_ACID2
) then
1992 if gAcid2
<> nil then
1997 if g_Collide(X
, Y
, Width
, Height
,
1998 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1999 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2006 if WordBool(PanelType
and PANEL_STEP
) then
2007 if gSteps
<> nil then
2012 if g_Collide(X
, Y
, Width
, Height
,
2013 gSteps
[a
].X
, gSteps
[a
].Y
,
2014 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2021 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2022 if gLifts
<> nil then
2027 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2028 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2029 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2030 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2031 g_Collide(X
, Y
, Width
, Height
,
2032 gLifts
[a
].X
, gLifts
[a
].Y
,
2033 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2040 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2041 if gBlockMon
<> nil then
2043 h
:= High(gBlockMon
);
2047 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2048 g_Collide(X
, Y
, Width
, Height
,
2049 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2050 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2058 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2060 function qq (obj
: TObject
; tag
: Integer): Boolean;
2065 result
:= false; // don't stop, ever
2067 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2071 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2073 if not (obj
is TPanel
) then
2075 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2079 pan
:= (obj
as TPanel
);
2082 if WordBool(PanelType
and PANEL_WALL
) and WordBool(tag
and PANEL_WALL
) then
2084 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2091 if WordBool(PanelType
and PANEL_WATER
) and WordBool(tag
and PANEL_WATER
) then
2093 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2100 if WordBool(PanelType
and PANEL_ACID1
) and WordBool(tag
and PANEL_ACID1
) then
2102 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2109 if WordBool(PanelType
and PANEL_ACID2
) and WordBool(tag
and PANEL_ACID2
) then
2111 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2118 if WordBool(PanelType
and PANEL_STEP
) and WordBool(tag
and PANEL_STEP
) then
2120 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2131 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, qq
);
2134 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (gLifts
<> nil) then
2139 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2140 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2141 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2142 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2143 g_Collide(X
, Y
, Width
, Height
,
2144 gLifts
[a
].X
, gLifts
[a
].Y
,
2145 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2153 if WordBool(PanelType
and PANEL_BLOCKMON
) and (gBlockMon
<> nil) then
2155 h
:= High(gBlockMon
);
2159 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2160 g_Collide(X
, Y
, Width
, Height
,
2161 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2162 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2173 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2177 Result
:= TEXTURE_NONE
;
2179 if gWater
<> nil then
2184 if g_Collide(X
, Y
, Width
, Height
,
2185 gWater
[a
].X
, gWater
[a
].Y
,
2186 gWater
[a
].Width
, gWater
[a
].Height
) then
2188 Result
:= gWater
[a
].GetTextureID();
2193 if gAcid1
<> nil then
2198 if g_Collide(X
, Y
, Width
, Height
,
2199 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2200 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2202 Result
:= gAcid1
[a
].GetTextureID();
2207 if gAcid2
<> nil then
2212 if g_Collide(X
, Y
, Width
, Height
,
2213 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2214 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2216 Result
:= gAcid2
[a
].GetTextureID();
2222 procedure g_Map_EnableWall(ID
: DWORD
);
2227 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2229 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2233 procedure g_Map_DisableWall(ID
: DWORD
);
2238 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2240 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2244 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2249 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2252 tp
:= gRenderForegrounds
[ID
];
2254 tp
:= gRenderBackgrounds
[ID
];
2267 tp
.NextTexture(AnimLoop
);
2268 if g_Game_IsServer
and g_Game_IsNet
then
2269 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2272 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2274 if gLifts
[ID
].LiftType
= t
then
2281 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2283 if LiftType
= 0 then
2284 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2285 else if LiftType
= 1 then
2286 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2287 else if LiftType
= 2 then
2288 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2289 else if LiftType
= 3 then
2290 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2292 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2296 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2299 PointsArray
: Array of TRespawnPoint
;
2302 SetLength(PointsArray
, 0);
2304 if RespawnPoints
= nil then
2307 for a
:= 0 to High(RespawnPoints
) do
2308 if RespawnPoints
[a
].PointType
= PointType
then
2310 SetLength(PointsArray
, Length(PointsArray
)+1);
2311 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2314 if PointsArray
= nil then
2317 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2321 function g_Map_GetPointCount(PointType
: Byte): Word;
2327 if RespawnPoints
= nil then
2330 for a
:= 0 to High(RespawnPoints
) do
2331 if RespawnPoints
[a
].PointType
= PointType
then
2332 Result
:= Result
+ 1;
2335 function g_Map_HaveFlagPoints(): Boolean;
2337 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2340 procedure g_Map_ResetFlag(Flag
: Byte);
2342 with gFlags
[Flag
] do
2348 Direction
:= D_LEFT
;
2349 State
:= FLAG_STATE_NONE
;
2350 if FlagPoints
[Flag
] <> nil then
2352 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2353 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2354 Direction
:= FlagPoints
[Flag
]^.Direction
;
2355 State
:= FLAG_STATE_NORMAL
;
2361 procedure g_Map_DrawFlags();
2364 Mirror
: TMirrorType
;
2366 if gGameSettings
.GameMode
<> GM_CTF
then
2369 for i
:= FLAG_RED
to FLAG_BLUE
do
2371 if State
<> FLAG_STATE_CAPTURED
then
2373 if State
= FLAG_STATE_NONE
then
2376 if Direction
= D_LEFT
then
2378 Mirror
:= M_HORIZONTAL
;
2387 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2389 if g_debug_Frames
then
2391 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2393 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2394 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2400 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2407 procedure SavePanelArray(var panels
: TPanelArray
);
2409 PAMem
: TBinMemoryWriter
;
2412 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2413 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2416 while i
< Length(panels
) do
2418 if panels
[i
].SaveIt
then
2422 // Ñîõðàíÿåì ïàíåëü:
2423 panels
[i
].SaveState(PAMem
);
2428 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2429 PAMem
.SaveToMemory(Mem
);
2433 procedure SaveFlag(flag
: PFlag
);
2436 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2438 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2439 Mem
.WriteByte(flag
^.RespawnType
);
2441 Mem
.WriteByte(flag
^.State
);
2442 // Íàïðàâëåíèå ôëàãà:
2443 if flag
^.Direction
= D_LEFT
then
2449 Obj_SaveState(@flag
^.Obj
, Mem
);
2453 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2455 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2456 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2457 SavePanelArray(gWalls
);
2458 // Ñîõðàíÿåì ïàíåëè ôîíà:
2459 SavePanelArray(gRenderBackgrounds
);
2460 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2461 SavePanelArray(gRenderForegrounds
);
2462 // Ñîõðàíÿåì ïàíåëè âîäû:
2463 SavePanelArray(gWater
);
2464 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2465 SavePanelArray(gAcid1
);
2466 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2467 SavePanelArray(gAcid2
);
2468 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2469 SavePanelArray(gSteps
);
2470 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2471 SavePanelArray(gLifts
);
2474 ///// Ñîõðàíÿåì ìóçûêó: /////
2475 // Ñèãíàòóðà ìóçûêè:
2476 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2479 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2480 if gMusic
.NoMusic
then
2484 Mem
.WriteString(str
, 64);
2485 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2486 dw
:= gMusic
.GetPosition();
2488 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2489 boo
:= gMusic
.SpecPause
;
2490 Mem
.WriteBoolean(boo
);
2493 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2494 Mem
.WriteInt(gTotalMonsters
);
2497 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2498 if gGameSettings
.GameMode
= GM_CTF
then
2500 // Ôëàã Êðàñíîé êîìàíäû:
2501 SaveFlag(@gFlags
[FLAG_RED
]);
2502 // Ôëàã Ñèíåé êîìàíäû:
2503 SaveFlag(@gFlags
[FLAG_BLUE
]);
2507 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2508 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2510 // Î÷êè Êðàñíîé êîìàíäû:
2511 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2512 // Î÷êè Ñèíåé êîìàíäû:
2513 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2518 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2525 procedure LoadPanelArray(var panels
: TPanelArray
);
2527 PAMem
: TBinMemoryReader
;
2530 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2531 PAMem
:= TBinMemoryReader
.Create();
2532 PAMem
.LoadFromMemory(Mem
);
2534 for i
:= 0 to Length(panels
)-1 do
2535 if panels
[i
].SaveIt
then
2541 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2543 // Çàãðóæàåì ïàíåëü:
2544 panels
[i
].LoadState(PAMem
);
2547 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2551 procedure LoadFlag(flag
: PFlag
);
2555 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2557 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2559 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2560 Mem
.ReadByte(flag
^.RespawnType
);
2562 Mem
.ReadByte(flag
^.State
);
2563 // Íàïðàâëåíèå ôëàãà:
2566 flag
^.Direction
:= D_LEFT
2568 flag
^.Direction
:= D_RIGHT
;
2570 Obj_LoadState(@flag
^.Obj
, Mem
);
2577 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2578 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2579 LoadPanelArray(gWalls
);
2580 // Çàãðóæàåì ïàíåëè ôîíà:
2581 LoadPanelArray(gRenderBackgrounds
);
2582 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2583 LoadPanelArray(gRenderForegrounds
);
2584 // Çàãðóæàåì ïàíåëè âîäû:
2585 LoadPanelArray(gWater
);
2586 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2587 LoadPanelArray(gAcid1
);
2588 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2589 LoadPanelArray(gAcid2
);
2590 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2591 LoadPanelArray(gSteps
);
2592 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2593 LoadPanelArray(gLifts
);
2596 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2599 ///// Çàãðóæàåì ìóçûêó: /////
2600 // Ñèãíàòóðà ìóçûêè:
2602 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2604 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2607 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2608 Mem
.ReadString(str
);
2609 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2611 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2612 Mem
.ReadBoolean(boo
);
2613 // Çàïóñêàåì ýòó ìóçûêó:
2614 gMusic
.SetByName(str
);
2615 gMusic
.SpecPause
:= boo
;
2618 gMusic
.SetPosition(dw
);
2621 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2622 Mem
.ReadInt(gTotalMonsters
);
2625 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2626 if gGameSettings
.GameMode
= GM_CTF
then
2628 // Ôëàã Êðàñíîé êîìàíäû:
2629 LoadFlag(@gFlags
[FLAG_RED
]);
2630 // Ôëàã Ñèíåé êîìàíäû:
2631 LoadFlag(@gFlags
[FLAG_BLUE
]);
2635 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2636 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2638 // Î÷êè Êðàñíîé êîìàíäû:
2639 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2640 // Î÷êè Ñèíåé êîìàíäû:
2641 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2646 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2651 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2652 Arr
:= PanelByID
[PanelID
].PWhere
^;
2653 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2654 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);