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
;
138 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
139 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
140 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
141 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
143 ImagingTypes
, Imaging
, ImagingUtility
,
144 ImagingGif
, ImagingNetworkGraphics
;
147 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
148 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
149 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
163 function panelTypeToTag (panelType
: Word): Integer;
166 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
167 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
168 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
169 PANEL_WATER
: result
:= GridTagWater
; // gWater
170 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
171 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
172 PANEL_STEP
: result
:= GridTagStep
; // gSteps
173 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
174 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
175 else result
:= GridTagInvalid
;
182 PWhere
: ^TPanelArray
;
187 PanelById
: array of TPanelID
;
188 Textures
: TLevelTextureArray
;
189 RespawnPoints
: Array of TRespawnPoint
;
190 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
191 //DOMFlagPoints: Array of TFlagPoint;
192 gMapGrid
: TBodyGrid
= nil;
195 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
197 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
198 (Texture
= TEXTURE_NAME_ACID1
) or
199 (Texture
= TEXTURE_NAME_ACID2
);
202 procedure CreateDoorMap();
204 PanelArray
: Array of record
210 a
, b
, c
, m
, i
, len
: Integer;
218 SetLength(PanelArray
, len
);
220 for a
:= 0 to High(gWalls
) do
221 if gWalls
[a
].Door
then
223 PanelArray
[i
].X
:= gWalls
[a
].X
;
224 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
225 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
226 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
227 PanelArray
[i
].Active
:= True;
228 PanelArray
[i
].PanelID
:= a
;
234 SetLength(PanelArray
, len
);
245 SetLength(gDoorMap
, 0);
247 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
250 if PanelArray
[a
].Active
then
252 PanelArray
[a
].Active
:= False;
253 m
:= Length(gDoorMap
);
254 SetLength(gDoorMap
, m
+1);
255 SetLength(gDoorMap
[m
], 1);
256 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
264 if PanelArray
[b
].Active
then
265 for c
:= 0 to High(gDoorMap
[m
]) do
266 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
267 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
268 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
269 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
270 gWalls
[gDoorMap
[m
, c
]].X
,
271 gWalls
[gDoorMap
[m
, c
]].Y
,
272 gWalls
[gDoorMap
[m
, c
]].Width
,
273 gWalls
[gDoorMap
[m
, c
]].Height
) then
275 PanelArray
[b
].Active
:= False;
276 SetLength(gDoorMap
[m
],
277 Length(gDoorMap
[m
])+1);
278 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
284 g_Game_StepLoading();
290 procedure CreateLiftMap();
292 PanelArray
: Array of record
297 a
, b
, c
, len
, i
, j
: Integer;
303 len
:= Length(gLifts
);
304 SetLength(PanelArray
, len
);
306 for a
:= 0 to len
-1 do
308 PanelArray
[a
].X
:= gLifts
[a
].X
;
309 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
310 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
311 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
312 PanelArray
[a
].Active
:= True;
315 SetLength(gLiftMap
, len
);
318 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
320 for a
:= 0 to len
-1 do
321 if PanelArray
[a
].Active
then
323 PanelArray
[a
].Active
:= False;
324 SetLength(gLiftMap
[i
], 32);
332 for b
:= 0 to len
-1 do
333 if PanelArray
[b
].Active
then
335 if g_CollideAround(PanelArray
[b
].X
,
338 PanelArray
[b
].Height
,
339 PanelArray
[gLiftMap
[i
, c
]].X
,
340 PanelArray
[gLiftMap
[i
, c
]].Y
,
341 PanelArray
[gLiftMap
[i
, c
]].Width
,
342 PanelArray
[gLiftMap
[i
, c
]].Height
) then
344 PanelArray
[b
].Active
:= False;
346 if j
> High(gLiftMap
[i
]) then
347 SetLength(gLiftMap
[i
],
348 Length(gLiftMap
[i
])+32);
357 SetLength(gLiftMap
[i
], j
+1);
360 g_Game_StepLoading();
363 SetLength(gLiftMap
, i
);
368 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
369 CurTex
: Integer; sav
: Boolean): Integer;
372 panels
: ^TPanelArray
;
376 case PanelRec
.PanelType
of
377 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
380 panels
:= @gRenderBackgrounds
;
382 panels
:= @gRenderForegrounds
;
391 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
394 panels
:= @gBlockMon
;
399 len
:= Length(panels
^);
400 SetLength(panels
^, len
+ 1);
402 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
403 panels
^[len
].ArrIdx
:= len
;
405 panels
^[len
].SaveIt
:= True;
409 len
:= Length(PanelByID
);
410 SetLength(PanelByID
, len
+ 1);
411 PanelByID
[len
].PWhere
:= panels
;
412 PanelByID
[len
].PArrID
:= Result
;
415 function CreateNullTexture(RecName
: String): Integer;
417 SetLength(Textures
, Length(Textures
)+1);
418 result
:= High(Textures
);
420 with Textures
[High(Textures
)] do
422 TextureName
:= RecName
;
426 TextureID
:= TEXTURE_NONE
;
430 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
433 TextureData
: Pointer;
434 WADName
, txname
: String;
435 a
, ResLength
: Integer;
439 if Textures
<> nil then
440 for a
:= 0 to High(Textures
) do
441 if Textures
[a
].TextureName
= RecName
then
442 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
447 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
448 if (RecName
= TEXTURE_NAME_WATER
) or
449 (RecName
= TEXTURE_NAME_ACID1
) or
450 (RecName
= TEXTURE_NAME_ACID2
) then
452 SetLength(Textures
, Length(Textures
)+1);
454 with Textures
[High(Textures
)] do
456 TextureName
:= RecName
;
458 if TextureName
= TEXTURE_NAME_WATER
then
459 TextureID
:= TEXTURE_SPECIAL_WATER
461 if TextureName
= TEXTURE_NAME_ACID1
then
462 TextureID
:= TEXTURE_SPECIAL_ACID1
464 if TextureName
= TEXTURE_NAME_ACID2
then
465 TextureID
:= TEXTURE_SPECIAL_ACID2
;
470 result
:= High(Textures
);
474 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
475 WADName
:= g_ExtractWadName(RecName
);
477 WAD
:= TWADFile
.Create();
479 if WADName
<> '' then
480 WADName
:= GameDir
+'/wads/'+WADName
484 WAD
.ReadFile(WADName
);
488 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
490 FreeMem(TextureData);
491 RecName := 'COMMON\ALIEN';
495 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
497 SetLength(Textures
, Length(Textures
)+1);
498 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
500 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
501 @Textures
[High(Textures
)].Width
,
502 @Textures
[High(Textures
)].Height
);
503 FreeMem(TextureData
);
504 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
505 Textures
[High(Textures
)].Anim
:= False;
507 result
:= High(Textures
);
509 else // Íåò òàêîãî ðåóñðñà â WAD'å
511 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
514 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
515 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
522 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
525 TextureWAD
: PChar = nil;
526 TextData
: Pointer = nil;
527 TextureData
: Pointer = nil;
531 TextureResource
: String;
532 _width
, _height
, _framecount
, _speed
: Integer;
533 _backanimation
: Boolean;
535 ia
: TDynImageDataArray
= nil;
536 f
, c
, frdelay
, frloop
: Integer;
540 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
542 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
543 WADName
:= g_ExtractWadName(RecName
);
545 WAD
:= TWADFile
.Create();
547 if WADName
<> '' then
548 WADName
:= GameDir
+'/wads/'+WADName
552 WAD
.ReadFile(WADName
);
554 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
558 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
559 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
565 if WADName = Map then
567 //FreeMem(TextureWAD);
568 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
574 if ResLength
< 6 then
576 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
580 // ýòî ïòèöà? ýòî ñàìîë¸ò?
581 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
582 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
584 // íåò, ýòî ñóïåðìåí!
585 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
587 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
591 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
592 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
594 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
598 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
600 TextureResource
:= cfg
.ReadStr('', 'resource', '');
601 if TextureResource
= '' then
603 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
607 _width
:= cfg
.ReadInt('', 'framewidth', 0);
608 _height
:= cfg
.ReadInt('', 'frameheight', 0);
609 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
610 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
611 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
616 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
617 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
619 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
626 SetLength(Textures
, Length(Textures
)+1);
627 with Textures
[High(Textures
)] do
629 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
630 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
632 TextureName
:= RecName
;
636 FramesCount
:= _framecount
;
638 result
:= High(Textures
);
642 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
648 // try animated image
650 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
651 if length(imgfmt) = 0 then
653 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
657 GlobalMetadata
.ClearMetaItems();
658 GlobalMetadata
.ClearMetaItemsForSaving();
659 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
661 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
664 if length(ia
) = 0 then
666 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
673 _width
:= ia
[0].width
;
674 _height
:= ia
[0].height
;
675 _framecount
:= length(ia
);
677 _backanimation
:= false;
680 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
682 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
684 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
686 if f
< 0 then f
:= 0;
689 if c
< 13 then c
:= 0 else c
:= 1;
691 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
696 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
698 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
700 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
702 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
706 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
707 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
708 f
:= ord(_backanimation
);
709 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
);
711 SetLength(Textures
, Length(Textures
)+1);
712 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
713 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
715 Textures
[High(Textures
)].TextureName
:= RecName
;
716 Textures
[High(Textures
)].Width
:= _width
;
717 Textures
[High(Textures
)].Height
:= _height
;
718 Textures
[High(Textures
)].Anim
:= True;
719 Textures
[High(Textures
)].FramesCount
:= length(ia
);
720 Textures
[High(Textures
)].Speed
:= _speed
;
721 result
:= High(Textures
);
722 //writeln(' CREATED!');
726 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
730 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
733 if TextureWAD
<> nil then FreeMem(TextureWAD
);
734 if TextData
<> nil then FreeMem(TextData
);
735 if TextureData
<> nil then FreeMem(TextureData
);
739 procedure CreateItem(Item
: TItemRec_1
);
741 if g_Game_IsClient
then Exit
;
743 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
744 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
747 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
748 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
751 procedure CreateArea(Area
: TAreaRec_1
);
756 case Area
.AreaType
of
757 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
758 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
760 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
761 with RespawnPoints
[High(RespawnPoints
)] do
765 Direction
:= TDirection(Area
.Direction
);
767 case Area
.AreaType
of
768 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
769 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
770 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
771 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
772 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
777 AREA_REDFLAG
, AREA_BLUEFLAG
:
779 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
781 if FlagPoints
[a
] <> nil then Exit
;
785 with FlagPoints
[a
]^ do
787 X
:= Area
.X
-FLAGRECT
.X
;
788 Y
:= Area
.Y
-FLAGRECT
.Y
;
789 Direction
:= TDirection(Area
.Direction
);
795 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
796 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
799 Animation
:= TAnimation
.Create(id
, True, 8);
800 Obj
.Rect
:= FLAGRECT
;
808 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
809 with DOMFlagPoints[High(DOMFlagPoints)] do
813 Direction := TDirection(Area.Direction);
816 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
821 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
825 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
831 Width
:= Trigger
.Width
;
832 Height
:= Trigger
.Height
;
833 Enabled
:= ByteBool(Trigger
.Enabled
);
834 TexturePanel
:= Trigger
.TexturePanel
;
835 TexturePanelType
:= fTexturePanel1Type
;
836 ShotPanelType
:= fTexturePanel2Type
;
837 TriggerType
:= Trigger
.TriggerType
;
838 ActivateType
:= Trigger
.ActivateType
;
839 Keys
:= Trigger
.Keys
;
840 Data
.Default
:= Trigger
.DATA
;
843 g_Triggers_Create(_trigger
);
846 procedure CreateMonster(monster
: TMonsterRec_1
);
850 if g_Game_IsClient
then Exit
;
852 if (gGameSettings
.GameType
= GT_SINGLE
)
853 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
855 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
856 TDirection(monster
.Direction
));
858 if gTriggers
<> nil then
859 for a
:= 0 to High(gTriggers
) do
860 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
861 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
862 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
863 gMonsters
[i
].AddTrigger(a
);
865 if monster
.MonsterType
<> MONSTER_BARREL
then
870 procedure g_Map_ReAdd_DieTriggers();
874 if g_Game_IsClient
then Exit
;
876 for i
:= 0 to High(gMonsters
) do
877 if gMonsters
[i
] <> nil then
879 gMonsters
[i
].ClearTriggers();
881 for a
:= 0 to High(gTriggers
) do
882 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
883 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
884 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
885 gMonsters
[i
].AddTrigger(a
);
889 function extractWadName(resourceName
: string): string;
893 posN
:= Pos(':', resourceName
);
895 Result
:= Copy(resourceName
, 0, posN
-1)
900 procedure addResToExternalResList(res
: string);
902 res
:= extractWadName(res
);
903 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
904 gExternalResources
.Add(res
);
907 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
909 textures
: TTexturesRec1Array
;
910 mapHeader
: TMapHeaderRec_1
;
912 resFile
: String = '';
914 if gExternalResources
= nil then
915 gExternalResources
:= TStringList
.Create
;
917 gExternalResources
.Clear
;
918 textures
:= mapReader
.GetTextures();
919 for i
:= 0 to High(textures
) do
921 addResToExternalResList(resFile
);
926 mapHeader
:= mapReader
.GetMapHeader
;
928 addResToExternalResList(mapHeader
.MusicName
);
929 addResToExternalResList(mapHeader
.SkyName
);
932 procedure mapCreateGrid ();
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 tag
:= panelTypeToTag(tag
);
958 for idx
:= High(panels
) downto 0 do
960 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
969 fixMinMax(gRenderBackgrounds
);
970 fixMinMax(gRenderForegrounds
);
976 fixMinMax(gBlockMon
);
978 if (mapX0
< 0) or (mapY0
< 0) then
980 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
981 //raise Exception.Create('we are fucked');
984 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
986 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
987 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
988 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
989 addPanelsToGrid(gWater
, PANEL_WATER
);
990 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
991 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
992 addPanelsToGrid(gSteps
, PANEL_STEP
);
993 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
994 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
996 gMapGrid
.dumpStats();
999 function g_Map_Load(Res
: String): Boolean;
1001 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1002 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1005 MapReader
: TMapReader_1
;
1006 Header
: TMapHeaderRec_1
;
1007 _textures
: TTexturesRec1Array
;
1008 _texnummap
: array of Integer; // `_textures` -> `Textures`
1009 panels
: TPanelsRec1Array
;
1010 items
: TItemsRec1Array
;
1011 monsters
: TMonsterRec1Array
;
1012 areas
: TAreasRec1Array
;
1013 triggers
: TTriggersRec1Array
;
1014 a
, b
, c
, k
: Integer;
1016 AddTextures
: TAddTextureArray
;
1017 texture
: TTextureRec_1
;
1018 TriggersTable
: Array of record
1019 TexturePanel
: Integer;
1024 FileName
, mapResName
, s
, TexName
: String;
1027 ok
, isAnim
, trigRef
: Boolean;
1028 CurTex
, ntn
: Integer;
1035 gMapInfo
.Map
:= Res
;
1036 TriggersTable
:= nil;
1037 FillChar(texture
, SizeOf(texture
), 0);
1039 sfsGCDisable(); // temporary disable removing of temporary volumes
1042 FileName
:= g_ExtractWadName(Res
);
1043 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1044 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1046 WAD
:= TWADFile
.Create();
1047 if not WAD
.ReadFile(FileName
) then
1049 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1053 //k8: why loader ignores path here?
1054 mapResName
:= g_ExtractFileName(Res
);
1055 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1057 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1065 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1066 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1067 MapReader
:= TMapReader_1
.Create();
1069 if not MapReader
.LoadMap(Data
) then
1071 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1078 generateExternalResourcesList(MapReader
);
1079 // Çàãðóçêà òåêñòóð:
1080 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1081 _textures
:= MapReader
.GetTextures();
1084 // Äîáàâëåíèå òåêñòóð â Textures[]:
1085 if _textures
<> nil then
1087 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1088 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1089 SetLength(_texnummap
, length(_textures
));
1091 for a
:= 0 to High(_textures
) do
1094 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1095 for b
:= 1 to Length(s
) do
1101 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1102 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1103 // Àíèìèðîâàííàÿ òåêñòóðà:
1104 if ByteBool(_textures
[a
].Anim
) then
1106 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1109 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1110 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1113 else // Îáû÷íàÿ òåêñòóðà:
1114 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1117 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1118 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1121 _texnummap
[a
] := ntn
; // fix texture number
1122 g_Game_StepLoading();
1126 // Çàãðóçêà òðèããåðîâ:
1127 gTriggerClientID
:= 0;
1128 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1129 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1130 triggers
:= MapReader
.GetTriggers();
1132 // Çàãðóçêà ïàíåëåé:
1133 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1134 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1135 panels
:= MapReader
.GetPanels();
1137 // check texture numbers for panels
1138 for a
:= 0 to High(panels
) do
1140 if panels
[a
].TextureNum
> High(_textures
) then
1142 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1146 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1149 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1150 if triggers
<> nil then
1152 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1153 SetLength(TriggersTable
, Length(triggers
));
1154 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1156 for a
:= 0 to High(TriggersTable
) do
1158 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1159 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1161 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1162 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1164 TriggersTable
[a
].LiftPanel
:= -1;
1166 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1167 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1168 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1169 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1171 TriggersTable
[a
].DoorPanel
:= -1;
1173 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1174 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1176 TriggersTable
[a
].ShotPanel
:= -1;
1178 g_Game_StepLoading();
1183 if panels
<> nil then
1185 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1186 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1188 for a
:= 0 to High(panels
) do
1190 SetLength(AddTextures
, 0);
1193 if _textures
<> nil then
1195 texture
:= _textures
[panels
[a
].TextureNum
];
1203 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1204 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1206 if (TriggersTable
<> nil) and (_textures
<> nil) then
1207 for b
:= 0 to High(TriggersTable
) do
1208 if (TriggersTable
[b
].TexturePanel
= a
)
1209 or (TriggersTable
[b
].ShotPanel
= a
) then
1218 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1220 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1223 for c
:= Len
downto 1 do
1231 // Ñïåö-òåêñòóðû çàïðåùåíû:
1232 if g_Map_IsSpecialTexture(s
) then
1235 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1236 ok
:= g_Texture_NumNameFindStart(s
);
1238 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1239 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1242 k
:= NNF_NAME_BEFORE
;
1243 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1244 while ok
or (k
= NNF_NAME_BEFORE
) or
1245 (k
= NNF_NAME_EQUALS
) do
1247 k
:= g_Texture_NumNameFindNext(TexName
);
1249 if (k
= NNF_NAME_BEFORE
) or
1250 (k
= NNF_NAME_AFTER
) then
1252 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1253 if ByteBool(texture
.Anim
) then
1254 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1256 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1258 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1260 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1264 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1266 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1268 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1270 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1274 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1277 for c
:= 0 to High(Textures
) do
1278 if Textures
[c
].TextureName
= TexName
then
1280 SetLength(AddTextures
, Length(AddTextures
)+1);
1281 AddTextures
[High(AddTextures
)].Texture
:= c
;
1282 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1288 if k
= NNF_NAME_EQUALS
then
1290 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1291 SetLength(AddTextures
, Length(AddTextures
)+1);
1292 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1293 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1294 CurTex
:= High(AddTextures
);
1302 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1303 end; // if ok - ññûëàþòñÿ òðèããåðû
1307 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1308 SetLength(AddTextures
, 1);
1309 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1310 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1314 //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);
1316 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1317 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1319 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1320 if TriggersTable
<> nil then
1321 for b
:= 0 to High(TriggersTable
) do
1323 // Òðèããåð äâåðè/ëèôòà:
1324 if (TriggersTable
[b
].LiftPanel
= a
) or
1325 (TriggersTable
[b
].DoorPanel
= a
) then
1326 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1327 // Òðèããåð ñìåíû òåêñòóðû:
1328 if TriggersTable
[b
].TexturePanel
= a
then
1329 triggers
[b
].TexturePanel
:= PanelID
;
1330 // Òðèããåð "Òóðåëü":
1331 if TriggersTable
[b
].ShotPanel
= a
then
1332 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1335 g_Game_StepLoading();
1339 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1340 if (triggers
<> nil) and not gLoadGameMode
then
1342 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1343 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1344 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1345 for a
:= 0 to High(triggers
) do
1347 if triggers
[a
].TexturePanel
<> -1 then
1348 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1351 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1352 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1353 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1356 CreateTrigger(triggers
[a
], b
, c
);
1360 // Çàãðóçêà ïðåäìåòîâ:
1361 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1362 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1363 items
:= MapReader
.GetItems();
1365 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1366 if (items
<> nil) and not gLoadGameMode
then
1368 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1369 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1370 for a
:= 0 to High(items
) do
1371 CreateItem(Items
[a
]);
1374 // Çàãðóçêà îáëàñòåé:
1375 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1376 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1377 areas
:= MapReader
.GetAreas();
1379 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1380 if areas
<> nil then
1382 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1383 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1384 for a
:= 0 to High(areas
) do
1385 CreateArea(areas
[a
]);
1388 // Çàãðóçêà ìîíñòðîâ:
1389 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1390 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1391 monsters
:= MapReader
.GetMonsters();
1393 gTotalMonsters
:= 0;
1395 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1396 if (monsters
<> nil) and not gLoadGameMode
then
1398 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1399 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1400 for a
:= 0 to High(monsters
) do
1401 CreateMonster(monsters
[a
]);
1404 // Çàãðóçêà îïèñàíèÿ êàðòû:
1405 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1406 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1407 Header
:= MapReader
.GetMapHeader();
1413 Name
:= Header
.MapName
;
1414 Description
:= Header
.MapDescription
;
1415 Author
:= Header
.MapAuthor
;
1416 MusicName
:= Header
.MusicName
;
1417 SkyName
:= Header
.SkyName
;
1418 Height
:= Header
.Height
;
1419 Width
:= Header
.Width
;
1423 if gMapInfo
.SkyName
<> '' then
1425 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1426 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1427 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1429 if FileName
<> '' then
1430 FileName
:= GameDir
+'/wads/'+FileName
1433 FileName
:= g_ExtractWadName(Res
);
1436 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1437 if g_Texture_CreateWAD(BackID
, s
) then
1439 g_Game_SetupScreenSize();
1442 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1447 if gMapInfo
.MusicName
<> '' then
1449 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1450 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1451 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1453 if FileName
<> '' then
1454 FileName
:= GameDir
+'/wads/'+FileName
1457 FileName
:= g_ExtractWadName(Res
);
1460 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1461 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1464 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1467 // Îñòàëüíûå óñòàíâêè:
1475 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1476 if not gLoadGameMode
then
1479 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1485 TriggersTable
:= nil;
1488 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1489 if ok
and (not gLoadGameMode
) then
1491 gMusic
.SetByName(gMapInfo
.MusicName
);
1495 gMusic
.SetByName('');
1497 sfsGCEnable(); // enable releasing unused volumes
1500 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1503 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1507 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1510 MapReader
: TMapReader_1
;
1511 Header
: TMapHeaderRec_1
;
1516 FillChar(Result
, SizeOf(Result
), 0);
1517 FileName
:= g_ExtractWadName(Res
);
1519 WAD
:= TWADFile
.Create();
1520 if not WAD
.ReadFile(FileName
) then
1526 //k8: it ignores path again
1527 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1535 MapReader
:= TMapReader_1
.Create();
1537 if not MapReader
.LoadMap(Data
) then
1539 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1540 ZeroMemory(@Header
, SizeOf(Header
));
1541 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1542 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1546 Header
:= MapReader
.GetMapHeader();
1547 Result
.Name
:= Header
.MapName
;
1548 Result
.Description
:= Header
.MapDescription
;
1555 Result
.Author
:= Header
.MapAuthor
;
1556 Result
.Height
:= Header
.Height
;
1557 Result
.Width
:= Header
.Width
;
1560 function g_Map_GetMapsList(WADName
: string): SArray
;
1567 WAD
:= TWADFile
.Create();
1568 if not WAD
.ReadFile(WADName
) then
1573 ResList
:= WAD
.GetMapResources();
1574 if ResList
<> nil then
1576 for a
:= 0 to High(ResList
) do
1578 SetLength(Result
, Length(Result
)+1);
1579 Result
[High(Result
)] := ResList
[a
];
1585 function g_Map_Exist(Res
: string): Boolean;
1588 FileName
, mnn
: string;
1594 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1596 WAD
:= TWADFile
.Create
;
1597 if not WAD
.ReadFile(FileName
) then
1603 ResList
:= WAD
.GetMapResources();
1606 mnn
:= g_ExtractFileName(Res
);
1607 if ResList
<> nil then
1608 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1615 procedure g_Map_Free();
1619 procedure FreePanelArray(var panels
: TPanelArray
);
1624 if panels
<> nil then
1626 for i
:= 0 to High(panels
) do
1639 RespawnPoints
:= nil;
1640 if FlagPoints
[FLAG_RED
] <> nil then
1642 Dispose(FlagPoints
[FLAG_RED
]);
1643 FlagPoints
[FLAG_RED
] := nil;
1645 if FlagPoints
[FLAG_BLUE
] <> nil then
1647 Dispose(FlagPoints
[FLAG_BLUE
]);
1648 FlagPoints
[FLAG_BLUE
] := nil;
1650 //DOMFlagPoints := nil;
1654 if Textures
<> nil then
1656 for a
:= 0 to High(Textures
) do
1657 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1658 if Textures
[a
].Anim
then
1659 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1661 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1662 e_DeleteTexture(Textures
[a
].TextureID
);
1667 FreePanelArray(gWalls
);
1668 FreePanelArray(gRenderBackgrounds
);
1669 FreePanelArray(gRenderForegrounds
);
1670 FreePanelArray(gWater
);
1671 FreePanelArray(gAcid1
);
1672 FreePanelArray(gAcid2
);
1673 FreePanelArray(gSteps
);
1674 FreePanelArray(gLifts
);
1675 FreePanelArray(gBlockMon
);
1677 if BackID
<> DWORD(-1) then
1681 e_DeleteTexture(BackID
);
1682 BackID
:= DWORD(-1);
1685 g_Game_StopAllSounds(False);
1687 g_Sound_Delete(gMapInfo
.MusicName
);
1689 gMapInfo
.Name
:= '';
1690 gMapInfo
.Description
:= '';
1691 gMapInfo
.MusicName
:= '';
1692 gMapInfo
.Height
:= 0;
1693 gMapInfo
.Width
:= 0;
1701 procedure g_Map_Update();
1707 procedure UpdatePanelArray(var panels
: TPanelArray
);
1712 if panels
<> nil then
1713 for i
:= 0 to High(panels
) do
1718 UpdatePanelArray(gWalls
);
1719 UpdatePanelArray(gRenderBackgrounds
);
1720 UpdatePanelArray(gRenderForegrounds
);
1721 UpdatePanelArray(gWater
);
1722 UpdatePanelArray(gAcid1
);
1723 UpdatePanelArray(gAcid2
);
1724 UpdatePanelArray(gSteps
);
1726 if gGameSettings
.GameMode
= GM_CTF
then
1728 for a
:= FLAG_RED
to FLAG_BLUE
do
1729 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1732 if gFlags
[a
].Animation
<> nil then
1733 gFlags
[a
].Animation
.Update();
1735 m
:= g_Obj_Move(@Obj
, True, True);
1737 if gTime
mod (GAME_TICK
*2) <> 0 then
1740 // Ñîïðîòèâëåíèå âîçäóõà:
1741 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1743 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1744 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1747 gFlags
[a
].CaptureTime
:= 0;
1748 if a
= FLAG_RED
then
1749 s
:= _lc
[I_PLAYER_FLAG_RED
]
1751 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1752 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1754 if g_Game_IsNet
then
1755 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1762 // Èãðîê áåðåò ôëàã:
1763 if gPlayers
<> nil then
1765 j
:= Random(Length(gPlayers
)) - 1;
1767 for d
:= 0 to High(gPlayers
) do
1770 if j
> High(gPlayers
) then
1773 if gPlayers
[j
] <> nil then
1774 if gPlayers
[j
].Live
and
1775 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1777 if gPlayers
[j
].GetFlag(a
) then
1787 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1789 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1793 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1795 // alas, no visible set
1796 for idx
:= 0 to High(panels
) do
1798 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1805 PANEL_WALL
: DrawPanels(0, gWalls
);
1806 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1807 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1808 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1809 PANEL_WATER
: DrawPanels(3, gWater
);
1810 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1811 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1812 PANEL_STEP
: DrawPanels(6, gSteps
);
1818 gDrawPanelList
: TBinaryHeapObj
= nil;
1820 function dplLess (a
, b
: TObject
): Boolean;
1822 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1825 procedure dplClear ();
1827 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1830 procedure dplAddPanel (pan
: TPanel
);
1832 if pan
= nil then exit
;
1833 gDrawPanelList
.insert(pan
);
1837 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1841 function checker (obj
: TObject
; tag
: Integer): Boolean;
1845 result
:= false; // don't stop, ever
1846 if (tag
<> ptag
) then exit
;
1847 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1849 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1850 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1851 //pan := (obj as TPanel);
1852 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1854 pan
:= (obj
as TPanel
);
1855 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
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);
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 ptag
:= panelTypeToTag(PanelType
);
1888 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1892 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1894 PANEL_WALL: DrawPanels(0, gWalls);
1895 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1896 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1897 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1898 PANEL_WATER: DrawPanels(3, gWater);
1899 PANEL_ACID1: DrawPanels(4, gAcid1);
1900 PANEL_ACID2: DrawPanels(5, gAcid2);
1901 PANEL_STEP: DrawPanels(6, gSteps);
1903 e_WriteLog('==================', MSG_NOTIFY);
1906 // sort and draw the list (we need to sort it, or rendering is fucked)
1907 while gDrawPanelList
.count
> 0 do
1909 (gDrawPanelList
.front() as TPanel
).Draw();
1910 gDrawPanelList
.popFront();
1915 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1916 function checker (obj
: TObject
; tag
: Integer): Boolean;
1920 result
:= false; // don't stop, ever
1921 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1922 pan
:= (obj
as TPanel
);
1923 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1927 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1931 procedure g_Map_DrawBack(dx
, dy
: Integer);
1933 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1934 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1936 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1940 function g_Map_CollidePanelOld(X, Y: Integer; Width, Height: Word;
1941 PanelType: Word; b1x3: Boolean): Boolean;
1947 if WordBool(PanelType and PANEL_WALL) then
1948 if gWalls <> nil then
1953 if gWalls[a].Enabled and
1954 g_Collide(X, Y, Width, Height,
1955 gWalls[a].X, gWalls[a].Y,
1956 gWalls[a].Width, gWalls[a].Height) then
1963 if WordBool(PanelType and PANEL_WATER) then
1964 if gWater <> nil then
1969 if g_Collide(X, Y, Width, Height,
1970 gWater[a].X, gWater[a].Y,
1971 gWater[a].Width, gWater[a].Height) then
1978 if WordBool(PanelType and PANEL_ACID1) then
1979 if gAcid1 <> nil then
1984 if g_Collide(X, Y, Width, Height,
1985 gAcid1[a].X, gAcid1[a].Y,
1986 gAcid1[a].Width, gAcid1[a].Height) then
1993 if WordBool(PanelType and PANEL_ACID2) then
1994 if gAcid2 <> nil then
1999 if g_Collide(X, Y, Width, Height,
2000 gAcid2[a].X, gAcid2[a].Y,
2001 gAcid2[a].Width, gAcid2[a].Height) then
2008 if WordBool(PanelType and PANEL_STEP) then
2009 if gSteps <> nil then
2014 if g_Collide(X, Y, Width, Height,
2015 gSteps[a].X, gSteps[a].Y,
2016 gSteps[a].Width, gSteps[a].Height) then
2023 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
2024 if gLifts <> nil then
2029 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2030 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2031 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2032 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2033 g_Collide(X, Y, Width, Height,
2034 gLifts[a].X, gLifts[a].Y,
2035 gLifts[a].Width, gLifts[a].Height) then
2042 if WordBool(PanelType and PANEL_BLOCKMON) then
2043 if gBlockMon <> nil then
2045 h := High(gBlockMon);
2049 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2050 g_Collide(X, Y, Width, Height,
2051 gBlockMon[a].X, gBlockMon[a].Y,
2052 gBlockMon[a].Width, gBlockMon[a].Height) then
2061 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2063 function checker (obj
: TObject
; tag
: Integer): Boolean;
2068 result
:= false; // don't stop, ever
2070 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2074 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2076 if not (obj
is TPanel
) then
2078 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2082 pan
:= (obj
as TPanel
);
2085 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2087 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2094 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2096 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2103 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2105 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2112 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2114 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2121 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2123 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2130 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2132 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2133 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2134 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2135 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2136 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2143 if WordBool(PanelType
and PANEL_BLOCKMON
)and (tag
= GridTagBlockMon
) then
2145 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2146 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2155 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2159 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2161 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2164 // slightly different from the old code, but meh...
2165 function checker (obj
: TObject
; tag
: Integer): Boolean;
2170 result
:= false; // don't stop, ever
2171 pan
:= (obj
as TPanel
);
2174 if (tag
= GridTagWater
) then
2176 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2178 result
:= true; // water has highest priority, so stop right here
2179 texid
:= gWater
[a
].GetTextureID();
2184 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2186 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2189 texid
:= gAcid1
[a
].GetTextureID();
2194 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2196 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2199 texid
:= gAcid2
[a
].GetTextureID();
2206 texid
:= TEXTURE_NONE
;
2207 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2211 procedure g_Map_EnableWall(ID
: DWORD
);
2216 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2218 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2222 procedure g_Map_DisableWall(ID
: DWORD
);
2227 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2229 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2233 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2238 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2241 tp
:= gRenderForegrounds
[ID
];
2243 tp
:= gRenderBackgrounds
[ID
];
2256 tp
.NextTexture(AnimLoop
);
2257 if g_Game_IsServer
and g_Game_IsNet
then
2258 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2261 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2263 if gLifts
[ID
].LiftType
= t
then
2270 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2272 if LiftType
= 0 then
2273 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2274 else if LiftType
= 1 then
2275 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2276 else if LiftType
= 2 then
2277 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2278 else if LiftType
= 3 then
2279 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2281 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2285 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2288 PointsArray
: Array of TRespawnPoint
;
2291 SetLength(PointsArray
, 0);
2293 if RespawnPoints
= nil then
2296 for a
:= 0 to High(RespawnPoints
) do
2297 if RespawnPoints
[a
].PointType
= PointType
then
2299 SetLength(PointsArray
, Length(PointsArray
)+1);
2300 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2303 if PointsArray
= nil then
2306 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2310 function g_Map_GetPointCount(PointType
: Byte): Word;
2316 if RespawnPoints
= nil then
2319 for a
:= 0 to High(RespawnPoints
) do
2320 if RespawnPoints
[a
].PointType
= PointType
then
2321 Result
:= Result
+ 1;
2324 function g_Map_HaveFlagPoints(): Boolean;
2326 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2329 procedure g_Map_ResetFlag(Flag
: Byte);
2331 with gFlags
[Flag
] do
2337 Direction
:= D_LEFT
;
2338 State
:= FLAG_STATE_NONE
;
2339 if FlagPoints
[Flag
] <> nil then
2341 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2342 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2343 Direction
:= FlagPoints
[Flag
]^.Direction
;
2344 State
:= FLAG_STATE_NORMAL
;
2350 procedure g_Map_DrawFlags();
2353 Mirror
: TMirrorType
;
2355 if gGameSettings
.GameMode
<> GM_CTF
then
2358 for i
:= FLAG_RED
to FLAG_BLUE
do
2360 if State
<> FLAG_STATE_CAPTURED
then
2362 if State
= FLAG_STATE_NONE
then
2365 if Direction
= D_LEFT
then
2367 Mirror
:= M_HORIZONTAL
;
2376 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2378 if g_debug_Frames
then
2380 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2382 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2383 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2389 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2396 procedure SavePanelArray(var panels
: TPanelArray
);
2398 PAMem
: TBinMemoryWriter
;
2401 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2402 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2405 while i
< Length(panels
) do
2407 if panels
[i
].SaveIt
then
2411 // Ñîõðàíÿåì ïàíåëü:
2412 panels
[i
].SaveState(PAMem
);
2417 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2418 PAMem
.SaveToMemory(Mem
);
2422 procedure SaveFlag(flag
: PFlag
);
2425 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2427 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2428 Mem
.WriteByte(flag
^.RespawnType
);
2430 Mem
.WriteByte(flag
^.State
);
2431 // Íàïðàâëåíèå ôëàãà:
2432 if flag
^.Direction
= D_LEFT
then
2438 Obj_SaveState(@flag
^.Obj
, Mem
);
2442 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2444 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2445 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2446 SavePanelArray(gWalls
);
2447 // Ñîõðàíÿåì ïàíåëè ôîíà:
2448 SavePanelArray(gRenderBackgrounds
);
2449 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2450 SavePanelArray(gRenderForegrounds
);
2451 // Ñîõðàíÿåì ïàíåëè âîäû:
2452 SavePanelArray(gWater
);
2453 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2454 SavePanelArray(gAcid1
);
2455 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2456 SavePanelArray(gAcid2
);
2457 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2458 SavePanelArray(gSteps
);
2459 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2460 SavePanelArray(gLifts
);
2463 ///// Ñîõðàíÿåì ìóçûêó: /////
2464 // Ñèãíàòóðà ìóçûêè:
2465 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2468 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2469 if gMusic
.NoMusic
then
2473 Mem
.WriteString(str
, 64);
2474 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2475 dw
:= gMusic
.GetPosition();
2477 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2478 boo
:= gMusic
.SpecPause
;
2479 Mem
.WriteBoolean(boo
);
2482 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2483 Mem
.WriteInt(gTotalMonsters
);
2486 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2487 if gGameSettings
.GameMode
= GM_CTF
then
2489 // Ôëàã Êðàñíîé êîìàíäû:
2490 SaveFlag(@gFlags
[FLAG_RED
]);
2491 // Ôëàã Ñèíåé êîìàíäû:
2492 SaveFlag(@gFlags
[FLAG_BLUE
]);
2496 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2497 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2499 // Î÷êè Êðàñíîé êîìàíäû:
2500 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2501 // Î÷êè Ñèíåé êîìàíäû:
2502 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2507 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2514 procedure LoadPanelArray(var panels
: TPanelArray
);
2516 PAMem
: TBinMemoryReader
;
2519 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2520 PAMem
:= TBinMemoryReader
.Create();
2521 PAMem
.LoadFromMemory(Mem
);
2523 for i
:= 0 to Length(panels
)-1 do
2524 if panels
[i
].SaveIt
then
2530 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2532 // Çàãðóæàåì ïàíåëü:
2533 panels
[i
].LoadState(PAMem
);
2536 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2540 procedure LoadFlag(flag
: PFlag
);
2544 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2546 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2548 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2549 Mem
.ReadByte(flag
^.RespawnType
);
2551 Mem
.ReadByte(flag
^.State
);
2552 // Íàïðàâëåíèå ôëàãà:
2555 flag
^.Direction
:= D_LEFT
2557 flag
^.Direction
:= D_RIGHT
;
2559 Obj_LoadState(@flag
^.Obj
, Mem
);
2566 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2567 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2568 LoadPanelArray(gWalls
);
2569 // Çàãðóæàåì ïàíåëè ôîíà:
2570 LoadPanelArray(gRenderBackgrounds
);
2571 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2572 LoadPanelArray(gRenderForegrounds
);
2573 // Çàãðóæàåì ïàíåëè âîäû:
2574 LoadPanelArray(gWater
);
2575 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2576 LoadPanelArray(gAcid1
);
2577 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2578 LoadPanelArray(gAcid2
);
2579 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2580 LoadPanelArray(gSteps
);
2581 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2582 LoadPanelArray(gLifts
);
2585 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2589 ///// Çàãðóæàåì ìóçûêó: /////
2590 // Ñèãíàòóðà ìóçûêè:
2592 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2594 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2597 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2598 Mem
.ReadString(str
);
2599 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2601 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2602 Mem
.ReadBoolean(boo
);
2603 // Çàïóñêàåì ýòó ìóçûêó:
2604 gMusic
.SetByName(str
);
2605 gMusic
.SpecPause
:= boo
;
2608 gMusic
.SetPosition(dw
);
2611 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2612 Mem
.ReadInt(gTotalMonsters
);
2615 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2616 if gGameSettings
.GameMode
= GM_CTF
then
2618 // Ôëàã Êðàñíîé êîìàíäû:
2619 LoadFlag(@gFlags
[FLAG_RED
]);
2620 // Ôëàã Ñèíåé êîìàíäû:
2621 LoadFlag(@gFlags
[FLAG_BLUE
]);
2625 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2626 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2628 // Î÷êè Êðàñíîé êîìàíäû:
2629 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2630 // Î÷êè Ñèíåé êîìàíäû:
2631 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2636 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2641 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2642 Arr
:= PanelByID
[PanelID
].PWhere
^;
2643 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2644 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);