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 // build "possibly lit panels" index, so we can avoid looping over all level panels again and again
93 function g_Map_BuildPLP (ltminx
, ltminy
, ltmaxx
, ltmaxy
: Integer): Boolean; // returns `false` if no patels lit
94 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
97 RESPAWNPOINT_PLAYER1
= 1;
98 RESPAWNPOINT_PLAYER2
= 2;
100 RESPAWNPOINT_RED
= 4;
101 RESPAWNPOINT_BLUE
= 5;
109 FLAG_STATE_NORMAL
= 1;
110 FLAG_STATE_DROPPED
= 2;
111 FLAG_STATE_CAPTURED
= 3;
112 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
115 FLAG_TIME
= 720; // 20 seconds
117 SKY_STRETCH
: Single = 1.5;
121 gRenderBackgrounds
: TPanelArray
;
122 gRenderForegrounds
: TPanelArray
;
123 gWater
, gAcid1
, gAcid2
: TPanelArray
;
126 gBlockMon
: TPanelArray
;
127 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
128 //gDOMFlags: array of TFlag;
131 gDoorMap
: array of array of DWORD
;
132 gLiftMap
: array of array of DWORD
;
133 gWADHash
: TMD5Digest
;
134 BackID
: DWORD
= DWORD(-1);
135 gExternalResources
: TStringList
;
136 gMapGrid
: TBodyGrid
= nil;
141 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
142 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
143 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
144 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
146 ImagingTypes
, Imaging
, ImagingUtility
,
147 ImagingGif
, ImagingNetworkGraphics
;
150 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
151 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
152 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
156 PWhere
: ^TPanelArray
;
161 PanelById
: array of TPanelID
;
162 Textures
: TLevelTextureArray
;
163 RespawnPoints
: Array of TRespawnPoint
;
164 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
165 //DOMFlagPoints: Array of TFlagPoint;
168 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
170 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
171 (Texture
= TEXTURE_NAME_ACID1
) or
172 (Texture
= TEXTURE_NAME_ACID2
);
175 procedure CreateDoorMap();
177 PanelArray
: Array of record
183 a
, b
, c
, m
, i
, len
: Integer;
191 SetLength(PanelArray
, len
);
193 for a
:= 0 to High(gWalls
) do
194 if gWalls
[a
].Door
then
196 PanelArray
[i
].X
:= gWalls
[a
].X
;
197 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
198 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
199 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
200 PanelArray
[i
].Active
:= True;
201 PanelArray
[i
].PanelID
:= a
;
207 SetLength(PanelArray
, len
);
218 SetLength(gDoorMap
, 0);
220 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
223 if PanelArray
[a
].Active
then
225 PanelArray
[a
].Active
:= False;
226 m
:= Length(gDoorMap
);
227 SetLength(gDoorMap
, m
+1);
228 SetLength(gDoorMap
[m
], 1);
229 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
237 if PanelArray
[b
].Active
then
238 for c
:= 0 to High(gDoorMap
[m
]) do
239 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
240 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
241 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
242 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
243 gWalls
[gDoorMap
[m
, c
]].X
,
244 gWalls
[gDoorMap
[m
, c
]].Y
,
245 gWalls
[gDoorMap
[m
, c
]].Width
,
246 gWalls
[gDoorMap
[m
, c
]].Height
) then
248 PanelArray
[b
].Active
:= False;
249 SetLength(gDoorMap
[m
],
250 Length(gDoorMap
[m
])+1);
251 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
257 g_Game_StepLoading();
263 procedure CreateLiftMap();
265 PanelArray
: Array of record
270 a
, b
, c
, len
, i
, j
: Integer;
276 len
:= Length(gLifts
);
277 SetLength(PanelArray
, len
);
279 for a
:= 0 to len
-1 do
281 PanelArray
[a
].X
:= gLifts
[a
].X
;
282 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
283 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
284 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
285 PanelArray
[a
].Active
:= True;
288 SetLength(gLiftMap
, len
);
291 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
293 for a
:= 0 to len
-1 do
294 if PanelArray
[a
].Active
then
296 PanelArray
[a
].Active
:= False;
297 SetLength(gLiftMap
[i
], 32);
305 for b
:= 0 to len
-1 do
306 if PanelArray
[b
].Active
then
308 if g_CollideAround(PanelArray
[b
].X
,
311 PanelArray
[b
].Height
,
312 PanelArray
[gLiftMap
[i
, c
]].X
,
313 PanelArray
[gLiftMap
[i
, c
]].Y
,
314 PanelArray
[gLiftMap
[i
, c
]].Width
,
315 PanelArray
[gLiftMap
[i
, c
]].Height
) then
317 PanelArray
[b
].Active
:= False;
319 if j
> High(gLiftMap
[i
]) then
320 SetLength(gLiftMap
[i
],
321 Length(gLiftMap
[i
])+32);
330 SetLength(gLiftMap
[i
], j
+1);
333 g_Game_StepLoading();
336 SetLength(gLiftMap
, i
);
341 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
342 CurTex
: Integer; sav
: Boolean): Integer;
345 panels
: ^TPanelArray
;
349 case PanelRec
.PanelType
of
350 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
353 panels
:= @gRenderBackgrounds
;
355 panels
:= @gRenderForegrounds
;
364 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
367 panels
:= @gBlockMon
;
372 len
:= Length(panels
^);
373 SetLength(panels
^, len
+ 1);
375 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
376 panels
^[len
].ArrIdx
:= len
;
378 panels
^[len
].SaveIt
:= True;
382 len
:= Length(PanelByID
);
383 SetLength(PanelByID
, len
+ 1);
384 PanelByID
[len
].PWhere
:= panels
;
385 PanelByID
[len
].PArrID
:= Result
;
388 function CreateNullTexture(RecName
: String): Integer;
390 SetLength(Textures
, Length(Textures
)+1);
391 result
:= High(Textures
);
393 with Textures
[High(Textures
)] do
395 TextureName
:= RecName
;
399 TextureID
:= TEXTURE_NONE
;
403 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
406 TextureData
: Pointer;
407 WADName
, txname
: String;
408 a
, ResLength
: Integer;
412 if Textures
<> nil then
413 for a
:= 0 to High(Textures
) do
414 if Textures
[a
].TextureName
= RecName
then
415 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
420 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
421 if (RecName
= TEXTURE_NAME_WATER
) or
422 (RecName
= TEXTURE_NAME_ACID1
) or
423 (RecName
= TEXTURE_NAME_ACID2
) then
425 SetLength(Textures
, Length(Textures
)+1);
427 with Textures
[High(Textures
)] do
429 TextureName
:= RecName
;
431 if TextureName
= TEXTURE_NAME_WATER
then
432 TextureID
:= TEXTURE_SPECIAL_WATER
434 if TextureName
= TEXTURE_NAME_ACID1
then
435 TextureID
:= TEXTURE_SPECIAL_ACID1
437 if TextureName
= TEXTURE_NAME_ACID2
then
438 TextureID
:= TEXTURE_SPECIAL_ACID2
;
443 result
:= High(Textures
);
447 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
448 WADName
:= g_ExtractWadName(RecName
);
450 WAD
:= TWADFile
.Create();
452 if WADName
<> '' then
453 WADName
:= GameDir
+'/wads/'+WADName
457 WAD
.ReadFile(WADName
);
461 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
463 FreeMem(TextureData);
464 RecName := 'COMMON\ALIEN';
468 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
470 SetLength(Textures
, Length(Textures
)+1);
471 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
473 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
474 @Textures
[High(Textures
)].Width
,
475 @Textures
[High(Textures
)].Height
);
476 FreeMem(TextureData
);
477 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
478 Textures
[High(Textures
)].Anim
:= False;
480 result
:= High(Textures
);
482 else // Íåò òàêîãî ðåóñðñà â WAD'å
484 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
487 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
488 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
495 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
498 TextureWAD
: PChar = nil;
499 TextData
: Pointer = nil;
500 TextureData
: Pointer = nil;
504 TextureResource
: String;
505 _width
, _height
, _framecount
, _speed
: Integer;
506 _backanimation
: Boolean;
508 ia
: TDynImageDataArray
= nil;
509 f
, c
, frdelay
, frloop
: Integer;
513 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
515 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
516 WADName
:= g_ExtractWadName(RecName
);
518 WAD
:= TWADFile
.Create();
520 if WADName
<> '' then
521 WADName
:= GameDir
+'/wads/'+WADName
525 WAD
.ReadFile(WADName
);
527 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
531 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
532 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
538 if WADName = Map then
540 //FreeMem(TextureWAD);
541 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
547 if ResLength
< 6 then
549 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
553 // ýòî ïòèöà? ýòî ñàìîë¸ò?
554 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
555 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
557 // íåò, ýòî ñóïåðìåí!
558 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
560 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
564 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
565 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
567 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
571 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
573 TextureResource
:= cfg
.ReadStr('', 'resource', '');
574 if TextureResource
= '' then
576 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
580 _width
:= cfg
.ReadInt('', 'framewidth', 0);
581 _height
:= cfg
.ReadInt('', 'frameheight', 0);
582 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
583 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
584 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
589 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
590 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
592 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
599 SetLength(Textures
, Length(Textures
)+1);
600 with Textures
[High(Textures
)] do
602 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
603 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
605 TextureName
:= RecName
;
609 FramesCount
:= _framecount
;
611 result
:= High(Textures
);
615 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
621 // try animated image
623 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
624 if length(imgfmt) = 0 then
626 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
630 GlobalMetadata
.ClearMetaItems();
631 GlobalMetadata
.ClearMetaItemsForSaving();
632 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
634 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
637 if length(ia
) = 0 then
639 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
646 _width
:= ia
[0].width
;
647 _height
:= ia
[0].height
;
648 _framecount
:= length(ia
);
650 _backanimation
:= false;
653 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
655 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
657 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
659 if f
< 0 then f
:= 0;
662 if c
< 13 then c
:= 0 else c
:= 1;
664 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
669 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
671 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
673 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
675 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
679 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
680 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
681 f
:= ord(_backanimation
);
682 e_WriteLog(Format('Animated texture file "%s": %d frames (delay:%d; back:%d; frdelay:%d; frloop:%d), %dx%d', [RecName
, length(ia
), _speed
, f
, frdelay
, frloop
, _width
, _height
]), MSG_NOTIFY
);
684 SetLength(Textures
, Length(Textures
)+1);
685 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
686 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
688 Textures
[High(Textures
)].TextureName
:= RecName
;
689 Textures
[High(Textures
)].Width
:= _width
;
690 Textures
[High(Textures
)].Height
:= _height
;
691 Textures
[High(Textures
)].Anim
:= True;
692 Textures
[High(Textures
)].FramesCount
:= length(ia
);
693 Textures
[High(Textures
)].Speed
:= _speed
;
694 result
:= High(Textures
);
695 //writeln(' CREATED!');
699 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
703 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
706 if TextureWAD
<> nil then FreeMem(TextureWAD
);
707 if TextData
<> nil then FreeMem(TextData
);
708 if TextureData
<> nil then FreeMem(TextureData
);
712 procedure CreateItem(Item
: TItemRec_1
);
714 if g_Game_IsClient
then Exit
;
716 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
717 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
720 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
721 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
724 procedure CreateArea(Area
: TAreaRec_1
);
729 case Area
.AreaType
of
730 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
731 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
733 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
734 with RespawnPoints
[High(RespawnPoints
)] do
738 Direction
:= TDirection(Area
.Direction
);
740 case Area
.AreaType
of
741 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
742 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
743 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
744 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
745 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
750 AREA_REDFLAG
, AREA_BLUEFLAG
:
752 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
754 if FlagPoints
[a
] <> nil then Exit
;
758 with FlagPoints
[a
]^ do
760 X
:= Area
.X
-FLAGRECT
.X
;
761 Y
:= Area
.Y
-FLAGRECT
.Y
;
762 Direction
:= TDirection(Area
.Direction
);
768 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
769 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
772 Animation
:= TAnimation
.Create(id
, True, 8);
773 Obj
.Rect
:= FLAGRECT
;
781 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
782 with DOMFlagPoints[High(DOMFlagPoints)] do
786 Direction := TDirection(Area.Direction);
789 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
794 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
798 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
804 Width
:= Trigger
.Width
;
805 Height
:= Trigger
.Height
;
806 Enabled
:= ByteBool(Trigger
.Enabled
);
807 TexturePanel
:= Trigger
.TexturePanel
;
808 TexturePanelType
:= fTexturePanel1Type
;
809 ShotPanelType
:= fTexturePanel2Type
;
810 TriggerType
:= Trigger
.TriggerType
;
811 ActivateType
:= Trigger
.ActivateType
;
812 Keys
:= Trigger
.Keys
;
813 Data
.Default
:= Trigger
.DATA
;
816 g_Triggers_Create(_trigger
);
819 procedure CreateMonster(monster
: TMonsterRec_1
);
823 if g_Game_IsClient
then Exit
;
825 if (gGameSettings
.GameType
= GT_SINGLE
)
826 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
828 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
829 TDirection(monster
.Direction
));
831 if gTriggers
<> nil then
832 for a
:= 0 to High(gTriggers
) do
833 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
834 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
835 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
836 gMonsters
[i
].AddTrigger(a
);
838 if monster
.MonsterType
<> MONSTER_BARREL
then
843 procedure g_Map_ReAdd_DieTriggers();
847 if g_Game_IsClient
then Exit
;
849 for i
:= 0 to High(gMonsters
) do
850 if gMonsters
[i
] <> nil then
852 gMonsters
[i
].ClearTriggers();
854 for a
:= 0 to High(gTriggers
) do
855 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
856 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
857 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
858 gMonsters
[i
].AddTrigger(a
);
862 function extractWadName(resourceName
: string): string;
866 posN
:= Pos(':', resourceName
);
868 Result
:= Copy(resourceName
, 0, posN
-1)
873 procedure addResToExternalResList(res
: string);
875 res
:= extractWadName(res
);
876 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
877 gExternalResources
.Add(res
);
880 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
882 textures
: TTexturesRec1Array
;
883 mapHeader
: TMapHeaderRec_1
;
885 resFile
: String = '';
887 if gExternalResources
= nil then
888 gExternalResources
:= TStringList
.Create
;
890 gExternalResources
.Clear
;
891 textures
:= mapReader
.GetTextures();
892 for i
:= 0 to High(textures
) do
894 addResToExternalResList(resFile
);
899 mapHeader
:= mapReader
.GetMapHeader
;
901 addResToExternalResList(mapHeader
.MusicName
);
902 addResToExternalResList(mapHeader
.SkyName
);
905 function g_Map_Load(Res
: String): Boolean;
907 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
908 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
911 MapReader
: TMapReader_1
;
912 Header
: TMapHeaderRec_1
;
913 _textures
: TTexturesRec1Array
;
914 _texnummap
: array of Integer; // `_textures` -> `Textures`
915 panels
: TPanelsRec1Array
;
916 items
: TItemsRec1Array
;
917 monsters
: TMonsterRec1Array
;
918 areas
: TAreasRec1Array
;
919 triggers
: TTriggersRec1Array
;
922 AddTextures
: TAddTextureArray
;
923 texture
: TTextureRec_1
;
924 TriggersTable
: Array of record
925 TexturePanel
: Integer;
930 FileName
, mapResName
, s
, TexName
: String;
933 ok
, isAnim
, trigRef
: Boolean;
934 CurTex
, ntn
: Integer;
936 mapX0
: Integer = $3fffffff;
937 mapY0
: Integer = $3fffffff;
938 mapX1
: Integer = -$3fffffff;
939 mapY1
: Integer = -$3fffffff;
941 procedure fixMinMax (var panels
: TPanelArray
);
945 for idx
:= 0 to High(panels
) do
947 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
948 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
949 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
950 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
951 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
955 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
959 for idx
:= High(panels
) downto 0 do
961 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
971 TriggersTable
:= nil;
972 FillChar(texture
, SizeOf(texture
), 0);
974 sfsGCDisable(); // temporary disable removing of temporary volumes
977 FileName
:= g_ExtractWadName(Res
);
978 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
979 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
981 WAD
:= TWADFile
.Create();
982 if not WAD
.ReadFile(FileName
) then
984 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
988 //k8: why loader ignores path here?
989 mapResName
:= g_ExtractFileName(Res
);
990 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
992 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1000 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1001 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1002 MapReader
:= TMapReader_1
.Create();
1004 if not MapReader
.LoadMap(Data
) then
1006 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1013 generateExternalResourcesList(MapReader
);
1014 // Çàãðóçêà òåêñòóð:
1015 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1016 _textures
:= MapReader
.GetTextures();
1019 // Äîáàâëåíèå òåêñòóð â Textures[]:
1020 if _textures
<> nil then
1022 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1023 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1024 SetLength(_texnummap
, length(_textures
));
1026 for a
:= 0 to High(_textures
) do
1029 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1030 for b
:= 1 to Length(s
) do
1036 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1037 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1038 // Àíèìèðîâàííàÿ òåêñòóðà:
1039 if ByteBool(_textures
[a
].Anim
) then
1041 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1044 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1045 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1048 else // Îáû÷íàÿ òåêñòóðà:
1049 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1052 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1053 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1056 _texnummap
[a
] := ntn
; // fix texture number
1057 g_Game_StepLoading();
1061 // Çàãðóçêà òðèããåðîâ:
1062 gTriggerClientID
:= 0;
1063 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1064 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1065 triggers
:= MapReader
.GetTriggers();
1067 // Çàãðóçêà ïàíåëåé:
1068 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1069 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1070 panels
:= MapReader
.GetPanels();
1072 // check texture numbers for panels
1073 for a
:= 0 to High(panels
) do
1075 if panels
[a
].TextureNum
> High(_textures
) then
1077 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1081 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1084 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1085 if triggers
<> nil then
1087 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1088 SetLength(TriggersTable
, Length(triggers
));
1089 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1091 for a
:= 0 to High(TriggersTable
) do
1093 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1094 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1096 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1097 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1099 TriggersTable
[a
].LiftPanel
:= -1;
1101 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1102 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1103 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1104 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1106 TriggersTable
[a
].DoorPanel
:= -1;
1108 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1109 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1111 TriggersTable
[a
].ShotPanel
:= -1;
1113 g_Game_StepLoading();
1118 if panels
<> nil then
1120 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1121 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1123 for a
:= 0 to High(panels
) do
1125 SetLength(AddTextures
, 0);
1128 if _textures
<> nil then
1130 texture
:= _textures
[panels
[a
].TextureNum
];
1138 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1139 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1141 if (TriggersTable
<> nil) and (_textures
<> nil) then
1142 for b
:= 0 to High(TriggersTable
) do
1143 if (TriggersTable
[b
].TexturePanel
= a
)
1144 or (TriggersTable
[b
].ShotPanel
= a
) then
1153 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1155 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1158 for c
:= Len
downto 1 do
1166 // Ñïåö-òåêñòóðû çàïðåùåíû:
1167 if g_Map_IsSpecialTexture(s
) then
1170 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1171 ok
:= g_Texture_NumNameFindStart(s
);
1173 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1174 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1177 k
:= NNF_NAME_BEFORE
;
1178 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1179 while ok
or (k
= NNF_NAME_BEFORE
) or
1180 (k
= NNF_NAME_EQUALS
) do
1182 k
:= g_Texture_NumNameFindNext(TexName
);
1184 if (k
= NNF_NAME_BEFORE
) or
1185 (k
= NNF_NAME_AFTER
) then
1187 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1188 if ByteBool(texture
.Anim
) then
1189 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1191 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1193 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1195 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1199 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1201 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1203 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1205 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1209 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1212 for c
:= 0 to High(Textures
) do
1213 if Textures
[c
].TextureName
= TexName
then
1215 SetLength(AddTextures
, Length(AddTextures
)+1);
1216 AddTextures
[High(AddTextures
)].Texture
:= c
;
1217 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1223 if k
= NNF_NAME_EQUALS
then
1225 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1226 SetLength(AddTextures
, Length(AddTextures
)+1);
1227 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1228 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1229 CurTex
:= High(AddTextures
);
1237 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1238 end; // if ok - ññûëàþòñÿ òðèããåðû
1242 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1243 SetLength(AddTextures
, 1);
1244 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1245 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1249 //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);
1251 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1252 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1254 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1255 if TriggersTable
<> nil then
1256 for b
:= 0 to High(TriggersTable
) do
1258 // Òðèããåð äâåðè/ëèôòà:
1259 if (TriggersTable
[b
].LiftPanel
= a
) or
1260 (TriggersTable
[b
].DoorPanel
= a
) then
1261 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1262 // Òðèããåð ñìåíû òåêñòóðû:
1263 if TriggersTable
[b
].TexturePanel
= a
then
1264 triggers
[b
].TexturePanel
:= PanelID
;
1265 // Òðèããåð "Òóðåëü":
1266 if TriggersTable
[b
].ShotPanel
= a
then
1267 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1270 g_Game_StepLoading();
1274 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1275 if (triggers
<> nil) and not gLoadGameMode
then
1277 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1278 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1279 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1280 for a
:= 0 to High(triggers
) do
1282 if triggers
[a
].TexturePanel
<> -1 then
1283 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1286 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1287 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1288 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1291 CreateTrigger(triggers
[a
], b
, c
);
1295 // Çàãðóçêà ïðåäìåòîâ:
1296 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1297 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1298 items
:= MapReader
.GetItems();
1300 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1301 if (items
<> nil) and not gLoadGameMode
then
1303 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1304 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1305 for a
:= 0 to High(items
) do
1306 CreateItem(Items
[a
]);
1309 // Çàãðóçêà îáëàñòåé:
1310 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1311 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1312 areas
:= MapReader
.GetAreas();
1314 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1315 if areas
<> nil then
1317 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1318 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1319 for a
:= 0 to High(areas
) do
1320 CreateArea(areas
[a
]);
1323 // Çàãðóçêà ìîíñòðîâ:
1324 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1325 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1326 monsters
:= MapReader
.GetMonsters();
1328 gTotalMonsters
:= 0;
1330 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1331 if (monsters
<> nil) and not gLoadGameMode
then
1333 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1334 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1335 for a
:= 0 to High(monsters
) do
1336 CreateMonster(monsters
[a
]);
1339 // Çàãðóçêà îïèñàíèÿ êàðòû:
1340 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1341 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1342 Header
:= MapReader
.GetMapHeader();
1348 Name
:= Header
.MapName
;
1349 Description
:= Header
.MapDescription
;
1350 Author
:= Header
.MapAuthor
;
1351 MusicName
:= Header
.MusicName
;
1352 SkyName
:= Header
.SkyName
;
1353 Height
:= Header
.Height
;
1354 Width
:= Header
.Width
;
1358 if gMapInfo
.SkyName
<> '' then
1360 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1361 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1362 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1364 if FileName
<> '' then
1365 FileName
:= GameDir
+'/wads/'+FileName
1368 FileName
:= g_ExtractWadName(Res
);
1371 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1372 if g_Texture_CreateWAD(BackID
, s
) then
1374 g_Game_SetupScreenSize();
1377 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1382 if gMapInfo
.MusicName
<> '' then
1384 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1385 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1386 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1388 if FileName
<> '' then
1389 FileName
:= GameDir
+'/wads/'+FileName
1392 FileName
:= g_ExtractWadName(Res
);
1395 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1396 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1399 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1402 // Îñòàëüíûå óñòàíâêè:
1410 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1411 if not gLoadGameMode
then
1414 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1420 TriggersTable
:= nil;
1423 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1424 if ok
and (not gLoadGameMode
) then
1426 gMusic
.SetByName(gMapInfo
.MusicName
);
1430 gMusic
.SetByName('');
1432 sfsGCEnable(); // enable releasing unused volumes
1435 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1438 fixMinMax(gRenderBackgrounds
);
1439 fixMinMax(gRenderForegrounds
);
1445 gMapGrid
:= TBodyGrid
.Create(mapX1
+1, mapY1
+1);
1447 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1448 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1449 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1450 addPanelsToGrid(gWater
, PANEL_WATER
);
1451 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1452 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1453 addPanelsToGrid(gSteps
, PANEL_STEP
);
1455 gMapGrid
.dumpStats();
1457 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1461 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1464 MapReader
: TMapReader_1
;
1465 Header
: TMapHeaderRec_1
;
1470 FillChar(Result
, SizeOf(Result
), 0);
1471 FileName
:= g_ExtractWadName(Res
);
1473 WAD
:= TWADFile
.Create();
1474 if not WAD
.ReadFile(FileName
) then
1480 //k8: it ignores path again
1481 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1489 MapReader
:= TMapReader_1
.Create();
1491 if not MapReader
.LoadMap(Data
) then
1493 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1494 ZeroMemory(@Header
, SizeOf(Header
));
1495 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1496 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1500 Header
:= MapReader
.GetMapHeader();
1501 Result
.Name
:= Header
.MapName
;
1502 Result
.Description
:= Header
.MapDescription
;
1509 Result
.Author
:= Header
.MapAuthor
;
1510 Result
.Height
:= Header
.Height
;
1511 Result
.Width
:= Header
.Width
;
1514 function g_Map_GetMapsList(WADName
: string): SArray
;
1521 WAD
:= TWADFile
.Create();
1522 if not WAD
.ReadFile(WADName
) then
1527 ResList
:= WAD
.GetMapResources();
1528 if ResList
<> nil then
1530 for a
:= 0 to High(ResList
) do
1532 SetLength(Result
, Length(Result
)+1);
1533 Result
[High(Result
)] := ResList
[a
];
1539 function g_Map_Exist(Res
: string): Boolean;
1542 FileName
, mnn
: string;
1548 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1550 WAD
:= TWADFile
.Create
;
1551 if not WAD
.ReadFile(FileName
) then
1557 ResList
:= WAD
.GetMapResources();
1560 mnn
:= g_ExtractFileName(Res
);
1561 if ResList
<> nil then
1562 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1569 procedure g_Map_Free();
1573 procedure FreePanelArray(var panels
: TPanelArray
);
1578 if panels
<> nil then
1580 for i
:= 0 to High(panels
) do
1593 RespawnPoints
:= nil;
1594 if FlagPoints
[FLAG_RED
] <> nil then
1596 Dispose(FlagPoints
[FLAG_RED
]);
1597 FlagPoints
[FLAG_RED
] := nil;
1599 if FlagPoints
[FLAG_BLUE
] <> nil then
1601 Dispose(FlagPoints
[FLAG_BLUE
]);
1602 FlagPoints
[FLAG_BLUE
] := nil;
1604 //DOMFlagPoints := nil;
1608 if Textures
<> nil then
1610 for a
:= 0 to High(Textures
) do
1611 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1612 if Textures
[a
].Anim
then
1613 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1615 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1616 e_DeleteTexture(Textures
[a
].TextureID
);
1621 FreePanelArray(gWalls
);
1622 FreePanelArray(gRenderBackgrounds
);
1623 FreePanelArray(gRenderForegrounds
);
1624 FreePanelArray(gWater
);
1625 FreePanelArray(gAcid1
);
1626 FreePanelArray(gAcid2
);
1627 FreePanelArray(gSteps
);
1628 FreePanelArray(gLifts
);
1629 FreePanelArray(gBlockMon
);
1631 if BackID
<> DWORD(-1) then
1635 e_DeleteTexture(BackID
);
1636 BackID
:= DWORD(-1);
1639 g_Game_StopAllSounds(False);
1641 g_Sound_Delete(gMapInfo
.MusicName
);
1643 gMapInfo
.Name
:= '';
1644 gMapInfo
.Description
:= '';
1645 gMapInfo
.MusicName
:= '';
1646 gMapInfo
.Height
:= 0;
1647 gMapInfo
.Width
:= 0;
1655 procedure g_Map_Update();
1661 procedure UpdatePanelArray(var panels
: TPanelArray
);
1666 if panels
<> nil then
1667 for i
:= 0 to High(panels
) do
1672 UpdatePanelArray(gWalls
);
1673 UpdatePanelArray(gRenderBackgrounds
);
1674 UpdatePanelArray(gRenderForegrounds
);
1675 UpdatePanelArray(gWater
);
1676 UpdatePanelArray(gAcid1
);
1677 UpdatePanelArray(gAcid2
);
1678 UpdatePanelArray(gSteps
);
1680 if gGameSettings
.GameMode
= GM_CTF
then
1682 for a
:= FLAG_RED
to FLAG_BLUE
do
1683 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1686 if gFlags
[a
].Animation
<> nil then
1687 gFlags
[a
].Animation
.Update();
1689 m
:= g_Obj_Move(@Obj
, True, True);
1691 if gTime
mod (GAME_TICK
*2) <> 0 then
1694 // Ñîïðîòèâëåíèå âîçäóõà:
1695 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1697 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1698 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1701 gFlags
[a
].CaptureTime
:= 0;
1702 if a
= FLAG_RED
then
1703 s
:= _lc
[I_PLAYER_FLAG_RED
]
1705 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1706 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1708 if g_Game_IsNet
then
1709 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1716 // Èãðîê áåðåò ôëàã:
1717 if gPlayers
<> nil then
1719 j
:= Random(Length(gPlayers
)) - 1;
1721 for d
:= 0 to High(gPlayers
) do
1724 if j
> High(gPlayers
) then
1727 if gPlayers
[j
] <> nil then
1728 if gPlayers
[j
].Live
and
1729 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1731 if gPlayers
[j
].GetFlag(a
) then
1742 function pvpType (panelType: Word): Integer;
1745 PANEL_WALL, PANEL_CLOSEDOOR: result := 0; // gWalls
1746 PANEL_BACK: result := 1; // gRenderBackgrounds
1747 PANEL_FORE: result := 2; // gRenderForegrounds
1748 PANEL_WATER: result := 3; // gWater
1749 PANEL_ACID1: result := 4; // gAcid1
1750 PANEL_ACID2: result := 5; // gAcid2
1751 PANEL_STEP: result := 6; // gSteps
1758 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1760 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1764 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1766 // alas, no visible set
1767 for idx
:= 0 to High(panels
) do
1769 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1776 PANEL_WALL
: DrawPanels(0, gWalls
);
1777 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1778 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1779 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1780 PANEL_WATER
: DrawPanels(3, gWater
);
1781 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1782 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1783 PANEL_STEP
: DrawPanels(6, gSteps
);
1789 gDrawPanelList
: TBinaryHeapObj
= nil;
1791 function dplLess (a
, b
: TObject
): Boolean;
1793 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1796 procedure dplClear ();
1798 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1801 procedure dplAddPanel (pan
: TPanel
);
1803 if pan
= nil then exit
;
1804 gDrawPanelList
.insert(pan
);
1808 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1810 function qq (obj
: TObject
; tag
: Integer): Boolean;
1814 result
:= false; // don't stop, ever
1816 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1820 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1822 if not (obj
is TPanel
) then
1824 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1827 //pan := (obj as TPanel);
1828 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1830 if (tag
= PANEL_WALL
) then
1832 if (PanelType
= PANEL_WALL
) then
1834 pan
:= (obj
as TPanel
);
1835 if not pan
.Door
then
1837 //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);
1841 else if (PanelType
= PANEL_CLOSEDOOR
) then
1843 pan
:= (obj
as TPanel
);
1846 //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);
1851 else if (PanelType
= tag
) then
1853 pan
:= (obj
as TPanel
);
1854 if not pan
.Door
then
1856 //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);
1862 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1867 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1869 // alas, no visible set
1870 for idx
:= 0 to High(panels
) do
1872 if not (drawDoors
xor panels
[idx
].Door
) then
1875 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1876 if (pan
.X
+pan
.Width
<= x0
) or (pan
.Y
+pan
.Height
<= y0
) then continue
;
1877 if (pan
.X
>= x0
+wdt
) or (pan
.Y
>= y0
+hgt
) then continue
;
1878 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
);
1885 //g_Map_DrawPanelsOld(PanelType); exit;
1886 //e_WriteLog('==================', MSG_NOTIFY);
1887 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1889 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, qq
);
1893 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1895 PANEL_WALL: DrawPanels(0, gWalls);
1896 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1897 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1898 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1899 PANEL_WATER: DrawPanels(3, gWater);
1900 PANEL_ACID1: DrawPanels(4, gAcid1);
1901 PANEL_ACID2: DrawPanels(5, gAcid2);
1902 PANEL_STEP: DrawPanels(6, gSteps);
1904 e_WriteLog('==================', MSG_NOTIFY);
1907 // sort and draw the list (we need to sort it, or rendering is fucked)
1908 while gDrawPanelList
.count
> 0 do
1910 (gDrawPanelList
.front() as TPanel
).Draw();
1911 gDrawPanelList
.popFront();
1916 plpset
: array of Integer = nil; // potentially lit panels
1917 plpcount
: Integer; // to avoid constant reallocations
1919 function g_Map_BuildPLP (ltminx
, ltminy
, ltmaxx
, ltmaxy
: Integer): Boolean;
1922 panels
: TPanelArray
;
1926 if (ltminx
< ltmaxx
) and (ltminy
< ltmaxy
) then
1928 if panels
<> nil then
1930 for idx
:= 0 to High(panels
) do
1932 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
1933 if (panels
[idx
].X
+panels
[idx
].Width
<= ltminx
) then continue
;
1934 if (panels
[idx
].Y
+panels
[idx
].Height
<= ltminy
) then continue
;
1935 if (panels
[idx
].X
> ltmaxx
) then continue
;
1936 if (panels
[idx
].Y
> ltmaxy
) then continue
;
1937 if plpcount
= length(plpset
) then SetLength(plpset
, plpcount
+32768);
1938 plpset
[plpcount
] := idx
;
1941 //e_WriteLog(Format('%d panels left out of %d', [plpcount, Length(panels)]), MSG_NOTIFY);
1944 result
:= (plpcount
> 0);
1947 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1950 procedure drawPanels (var panels: TPanelArray);
1954 if panels <> nil then
1956 for a := 0 to High(panels) do
1958 panels[a].DrawShadowVolume(lightX, lightY, radius);
1968 //drawPanels(gRenderForegrounds);
1970 for idx
:= 0 to plpcount
-1 do
1972 gWalls
[plpset
[idx
]].DrawShadowVolume(lightX
, lightY
, radius
);
1976 procedure g_Map_DrawBack(dx
, dy
: Integer);
1978 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1979 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1981 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1984 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1985 PanelType
: Word; b1x3
: Boolean): Boolean;
1991 if WordBool(PanelType
and PANEL_WALL
) then
1992 if gWalls
<> nil then
1997 if gWalls
[a
].Enabled
and
1998 g_Collide(X
, Y
, Width
, Height
,
1999 gWalls
[a
].X
, gWalls
[a
].Y
,
2000 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2007 if WordBool(PanelType
and PANEL_WATER
) then
2008 if gWater
<> nil then
2013 if g_Collide(X
, Y
, Width
, Height
,
2014 gWater
[a
].X
, gWater
[a
].Y
,
2015 gWater
[a
].Width
, gWater
[a
].Height
) then
2022 if WordBool(PanelType
and PANEL_ACID1
) then
2023 if gAcid1
<> nil then
2028 if g_Collide(X
, Y
, Width
, Height
,
2029 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2030 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2037 if WordBool(PanelType
and PANEL_ACID2
) then
2038 if gAcid2
<> nil then
2043 if g_Collide(X
, Y
, Width
, Height
,
2044 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2045 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2052 if WordBool(PanelType
and PANEL_STEP
) then
2053 if gSteps
<> nil then
2058 if g_Collide(X
, Y
, Width
, Height
,
2059 gSteps
[a
].X
, gSteps
[a
].Y
,
2060 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2067 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2068 if gLifts
<> nil then
2073 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2074 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2075 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2076 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2077 g_Collide(X
, Y
, Width
, Height
,
2078 gLifts
[a
].X
, gLifts
[a
].Y
,
2079 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2086 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2087 if gBlockMon
<> nil then
2089 h
:= High(gBlockMon
);
2093 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2094 g_Collide(X
, Y
, Width
, Height
,
2095 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2096 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2104 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2106 function qq (obj
: TObject
; tag
: Integer): Boolean;
2111 result
:= false; // don't stop, ever
2113 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2117 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2119 if not (obj
is TPanel
) then
2121 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2125 pan
:= (obj
as TPanel
);
2128 if WordBool(PanelType
and PANEL_WALL
) and WordBool(tag
and PANEL_WALL
) then
2130 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2137 if WordBool(PanelType
and PANEL_WATER
) and WordBool(tag
and PANEL_WATER
) then
2139 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2146 if WordBool(PanelType
and PANEL_ACID1
) and WordBool(tag
and PANEL_ACID1
) then
2148 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2155 if WordBool(PanelType
and PANEL_ACID2
) and WordBool(tag
and PANEL_ACID2
) then
2157 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2164 if WordBool(PanelType
and PANEL_STEP
) and WordBool(tag
and PANEL_STEP
) then
2166 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2177 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, qq
);
2180 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (gLifts
<> nil) then
2185 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2186 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2187 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2188 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2189 g_Collide(X
, Y
, Width
, Height
,
2190 gLifts
[a
].X
, gLifts
[a
].Y
,
2191 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2199 if WordBool(PanelType
and PANEL_BLOCKMON
) and (gBlockMon
<> nil) then
2201 h
:= High(gBlockMon
);
2205 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2206 g_Collide(X
, Y
, Width
, Height
,
2207 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2208 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2219 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2223 Result
:= TEXTURE_NONE
;
2225 if gWater
<> nil then
2230 if g_Collide(X
, Y
, Width
, Height
,
2231 gWater
[a
].X
, gWater
[a
].Y
,
2232 gWater
[a
].Width
, gWater
[a
].Height
) then
2234 Result
:= gWater
[a
].GetTextureID();
2239 if gAcid1
<> nil then
2244 if g_Collide(X
, Y
, Width
, Height
,
2245 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2246 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2248 Result
:= gAcid1
[a
].GetTextureID();
2253 if gAcid2
<> nil then
2258 if g_Collide(X
, Y
, Width
, Height
,
2259 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2260 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2262 Result
:= gAcid2
[a
].GetTextureID();
2268 procedure g_Map_EnableWall(ID
: DWORD
);
2273 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2275 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2279 procedure g_Map_DisableWall(ID
: DWORD
);
2284 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2286 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2290 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2295 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2298 tp
:= gRenderForegrounds
[ID
];
2300 tp
:= gRenderBackgrounds
[ID
];
2313 tp
.NextTexture(AnimLoop
);
2314 if g_Game_IsServer
and g_Game_IsNet
then
2315 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2318 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2320 if gLifts
[ID
].LiftType
= t
then
2327 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2329 if LiftType
= 0 then
2330 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2331 else if LiftType
= 1 then
2332 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2333 else if LiftType
= 2 then
2334 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2335 else if LiftType
= 3 then
2336 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2338 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2342 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2345 PointsArray
: Array of TRespawnPoint
;
2348 SetLength(PointsArray
, 0);
2350 if RespawnPoints
= nil then
2353 for a
:= 0 to High(RespawnPoints
) do
2354 if RespawnPoints
[a
].PointType
= PointType
then
2356 SetLength(PointsArray
, Length(PointsArray
)+1);
2357 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2360 if PointsArray
= nil then
2363 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2367 function g_Map_GetPointCount(PointType
: Byte): Word;
2373 if RespawnPoints
= nil then
2376 for a
:= 0 to High(RespawnPoints
) do
2377 if RespawnPoints
[a
].PointType
= PointType
then
2378 Result
:= Result
+ 1;
2381 function g_Map_HaveFlagPoints(): Boolean;
2383 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2386 procedure g_Map_ResetFlag(Flag
: Byte);
2388 with gFlags
[Flag
] do
2394 Direction
:= D_LEFT
;
2395 State
:= FLAG_STATE_NONE
;
2396 if FlagPoints
[Flag
] <> nil then
2398 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2399 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2400 Direction
:= FlagPoints
[Flag
]^.Direction
;
2401 State
:= FLAG_STATE_NORMAL
;
2407 procedure g_Map_DrawFlags();
2410 Mirror
: TMirrorType
;
2412 if gGameSettings
.GameMode
<> GM_CTF
then
2415 for i
:= FLAG_RED
to FLAG_BLUE
do
2417 if State
<> FLAG_STATE_CAPTURED
then
2419 if State
= FLAG_STATE_NONE
then
2422 if Direction
= D_LEFT
then
2424 Mirror
:= M_HORIZONTAL
;
2433 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2435 if g_debug_Frames
then
2437 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2439 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2440 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2446 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2453 procedure SavePanelArray(var panels
: TPanelArray
);
2455 PAMem
: TBinMemoryWriter
;
2458 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2459 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2462 while i
< Length(panels
) do
2464 if panels
[i
].SaveIt
then
2468 // Ñîõðàíÿåì ïàíåëü:
2469 panels
[i
].SaveState(PAMem
);
2474 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2475 PAMem
.SaveToMemory(Mem
);
2479 procedure SaveFlag(flag
: PFlag
);
2482 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2484 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2485 Mem
.WriteByte(flag
^.RespawnType
);
2487 Mem
.WriteByte(flag
^.State
);
2488 // Íàïðàâëåíèå ôëàãà:
2489 if flag
^.Direction
= D_LEFT
then
2495 Obj_SaveState(@flag
^.Obj
, Mem
);
2499 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2501 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2502 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2503 SavePanelArray(gWalls
);
2504 // Ñîõðàíÿåì ïàíåëè ôîíà:
2505 SavePanelArray(gRenderBackgrounds
);
2506 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2507 SavePanelArray(gRenderForegrounds
);
2508 // Ñîõðàíÿåì ïàíåëè âîäû:
2509 SavePanelArray(gWater
);
2510 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2511 SavePanelArray(gAcid1
);
2512 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2513 SavePanelArray(gAcid2
);
2514 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2515 SavePanelArray(gSteps
);
2516 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2517 SavePanelArray(gLifts
);
2520 ///// Ñîõðàíÿåì ìóçûêó: /////
2521 // Ñèãíàòóðà ìóçûêè:
2522 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2525 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2526 if gMusic
.NoMusic
then
2530 Mem
.WriteString(str
, 64);
2531 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2532 dw
:= gMusic
.GetPosition();
2534 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2535 boo
:= gMusic
.SpecPause
;
2536 Mem
.WriteBoolean(boo
);
2539 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2540 Mem
.WriteInt(gTotalMonsters
);
2543 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2544 if gGameSettings
.GameMode
= GM_CTF
then
2546 // Ôëàã Êðàñíîé êîìàíäû:
2547 SaveFlag(@gFlags
[FLAG_RED
]);
2548 // Ôëàã Ñèíåé êîìàíäû:
2549 SaveFlag(@gFlags
[FLAG_BLUE
]);
2553 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2554 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2556 // Î÷êè Êðàñíîé êîìàíäû:
2557 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2558 // Î÷êè Ñèíåé êîìàíäû:
2559 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2564 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2571 procedure LoadPanelArray(var panels
: TPanelArray
);
2573 PAMem
: TBinMemoryReader
;
2576 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2577 PAMem
:= TBinMemoryReader
.Create();
2578 PAMem
.LoadFromMemory(Mem
);
2580 for i
:= 0 to Length(panels
)-1 do
2581 if panels
[i
].SaveIt
then
2587 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2589 // Çàãðóæàåì ïàíåëü:
2590 panels
[i
].LoadState(PAMem
);
2593 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2597 procedure LoadFlag(flag
: PFlag
);
2601 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2603 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2605 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2606 Mem
.ReadByte(flag
^.RespawnType
);
2608 Mem
.ReadByte(flag
^.State
);
2609 // Íàïðàâëåíèå ôëàãà:
2612 flag
^.Direction
:= D_LEFT
2614 flag
^.Direction
:= D_RIGHT
;
2616 Obj_LoadState(@flag
^.Obj
, Mem
);
2623 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2624 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2625 LoadPanelArray(gWalls
);
2626 // Çàãðóæàåì ïàíåëè ôîíà:
2627 LoadPanelArray(gRenderBackgrounds
);
2628 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2629 LoadPanelArray(gRenderForegrounds
);
2630 // Çàãðóæàåì ïàíåëè âîäû:
2631 LoadPanelArray(gWater
);
2632 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2633 LoadPanelArray(gAcid1
);
2634 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2635 LoadPanelArray(gAcid2
);
2636 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2637 LoadPanelArray(gSteps
);
2638 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2639 LoadPanelArray(gLifts
);
2642 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2645 ///// Çàãðóæàåì ìóçûêó: /////
2646 // Ñèãíàòóðà ìóçûêè:
2648 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2650 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2653 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2654 Mem
.ReadString(str
);
2655 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2657 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2658 Mem
.ReadBoolean(boo
);
2659 // Çàïóñêàåì ýòó ìóçûêó:
2660 gMusic
.SetByName(str
);
2661 gMusic
.SpecPause
:= boo
;
2664 gMusic
.SetPosition(dw
);
2667 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2668 Mem
.ReadInt(gTotalMonsters
);
2671 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2672 if gGameSettings
.GameMode
= GM_CTF
then
2674 // Ôëàã Êðàñíîé êîìàíäû:
2675 LoadFlag(@gFlags
[FLAG_RED
]);
2676 // Ôëàã Ñèíåé êîìàíäû:
2677 LoadFlag(@gFlags
[FLAG_BLUE
]);
2681 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2682 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2684 // Î÷êè Êðàñíîé êîìàíäû:
2685 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2686 // Î÷êè Ñèíåé êîìàíäû:
2687 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2692 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2697 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2698 Arr
:= PanelByID
[PanelID
].PWhere
^;
2699 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2700 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);