6b343b325fa8913fa7f3cae31a27e42418be4659
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'
152 function panelTypeToTag (panelType
: Word): Integer;
155 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= 0; // gWalls
156 PANEL_BACK
: result
:= 1; // gRenderBackgrounds
157 PANEL_FORE
: result
:= 2; // gRenderForegrounds
158 PANEL_WATER
: result
:= 3; // gWater
159 PANEL_ACID1
: result
:= 4; // gAcid1
160 PANEL_ACID2
: result
:= 5; // gAcid2
161 PANEL_STEP
: result
:= 6; // gSteps
162 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= 7; // gLifts -- this is for all lifts
163 PANEL_BLOCKMON
: result
:= 8; // gBlockMon -- this is for all blockmons
171 PWhere
: ^TPanelArray
;
176 PanelById
: array of TPanelID
;
177 Textures
: TLevelTextureArray
;
178 RespawnPoints
: Array of TRespawnPoint
;
179 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
180 //DOMFlagPoints: Array of TFlagPoint;
181 gMapGrid
: TBodyGrid
= nil;
184 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
186 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
187 (Texture
= TEXTURE_NAME_ACID1
) or
188 (Texture
= TEXTURE_NAME_ACID2
);
191 procedure CreateDoorMap();
193 PanelArray
: Array of record
199 a
, b
, c
, m
, i
, len
: Integer;
207 SetLength(PanelArray
, len
);
209 for a
:= 0 to High(gWalls
) do
210 if gWalls
[a
].Door
then
212 PanelArray
[i
].X
:= gWalls
[a
].X
;
213 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
214 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
215 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
216 PanelArray
[i
].Active
:= True;
217 PanelArray
[i
].PanelID
:= a
;
223 SetLength(PanelArray
, len
);
234 SetLength(gDoorMap
, 0);
236 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
239 if PanelArray
[a
].Active
then
241 PanelArray
[a
].Active
:= False;
242 m
:= Length(gDoorMap
);
243 SetLength(gDoorMap
, m
+1);
244 SetLength(gDoorMap
[m
], 1);
245 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
253 if PanelArray
[b
].Active
then
254 for c
:= 0 to High(gDoorMap
[m
]) do
255 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
256 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
257 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
258 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
259 gWalls
[gDoorMap
[m
, c
]].X
,
260 gWalls
[gDoorMap
[m
, c
]].Y
,
261 gWalls
[gDoorMap
[m
, c
]].Width
,
262 gWalls
[gDoorMap
[m
, c
]].Height
) then
264 PanelArray
[b
].Active
:= False;
265 SetLength(gDoorMap
[m
],
266 Length(gDoorMap
[m
])+1);
267 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
273 g_Game_StepLoading();
279 procedure CreateLiftMap();
281 PanelArray
: Array of record
286 a
, b
, c
, len
, i
, j
: Integer;
292 len
:= Length(gLifts
);
293 SetLength(PanelArray
, len
);
295 for a
:= 0 to len
-1 do
297 PanelArray
[a
].X
:= gLifts
[a
].X
;
298 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
299 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
300 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
301 PanelArray
[a
].Active
:= True;
304 SetLength(gLiftMap
, len
);
307 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
309 for a
:= 0 to len
-1 do
310 if PanelArray
[a
].Active
then
312 PanelArray
[a
].Active
:= False;
313 SetLength(gLiftMap
[i
], 32);
321 for b
:= 0 to len
-1 do
322 if PanelArray
[b
].Active
then
324 if g_CollideAround(PanelArray
[b
].X
,
327 PanelArray
[b
].Height
,
328 PanelArray
[gLiftMap
[i
, c
]].X
,
329 PanelArray
[gLiftMap
[i
, c
]].Y
,
330 PanelArray
[gLiftMap
[i
, c
]].Width
,
331 PanelArray
[gLiftMap
[i
, c
]].Height
) then
333 PanelArray
[b
].Active
:= False;
335 if j
> High(gLiftMap
[i
]) then
336 SetLength(gLiftMap
[i
],
337 Length(gLiftMap
[i
])+32);
346 SetLength(gLiftMap
[i
], j
+1);
349 g_Game_StepLoading();
352 SetLength(gLiftMap
, i
);
357 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
358 CurTex
: Integer; sav
: Boolean): Integer;
361 panels
: ^TPanelArray
;
365 case PanelRec
.PanelType
of
366 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
369 panels
:= @gRenderBackgrounds
;
371 panels
:= @gRenderForegrounds
;
380 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
383 panels
:= @gBlockMon
;
388 len
:= Length(panels
^);
389 SetLength(panels
^, len
+ 1);
391 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
392 panels
^[len
].ArrIdx
:= len
;
394 panels
^[len
].SaveIt
:= True;
398 len
:= Length(PanelByID
);
399 SetLength(PanelByID
, len
+ 1);
400 PanelByID
[len
].PWhere
:= panels
;
401 PanelByID
[len
].PArrID
:= Result
;
404 function CreateNullTexture(RecName
: String): Integer;
406 SetLength(Textures
, Length(Textures
)+1);
407 result
:= High(Textures
);
409 with Textures
[High(Textures
)] do
411 TextureName
:= RecName
;
415 TextureID
:= TEXTURE_NONE
;
419 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
422 TextureData
: Pointer;
423 WADName
, txname
: String;
424 a
, ResLength
: Integer;
428 if Textures
<> nil then
429 for a
:= 0 to High(Textures
) do
430 if Textures
[a
].TextureName
= RecName
then
431 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
436 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
437 if (RecName
= TEXTURE_NAME_WATER
) or
438 (RecName
= TEXTURE_NAME_ACID1
) or
439 (RecName
= TEXTURE_NAME_ACID2
) then
441 SetLength(Textures
, Length(Textures
)+1);
443 with Textures
[High(Textures
)] do
445 TextureName
:= RecName
;
447 if TextureName
= TEXTURE_NAME_WATER
then
448 TextureID
:= TEXTURE_SPECIAL_WATER
450 if TextureName
= TEXTURE_NAME_ACID1
then
451 TextureID
:= TEXTURE_SPECIAL_ACID1
453 if TextureName
= TEXTURE_NAME_ACID2
then
454 TextureID
:= TEXTURE_SPECIAL_ACID2
;
459 result
:= High(Textures
);
463 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
464 WADName
:= g_ExtractWadName(RecName
);
466 WAD
:= TWADFile
.Create();
468 if WADName
<> '' then
469 WADName
:= GameDir
+'/wads/'+WADName
473 WAD
.ReadFile(WADName
);
477 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
479 FreeMem(TextureData);
480 RecName := 'COMMON\ALIEN';
484 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
486 SetLength(Textures
, Length(Textures
)+1);
487 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
489 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
490 @Textures
[High(Textures
)].Width
,
491 @Textures
[High(Textures
)].Height
);
492 FreeMem(TextureData
);
493 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
494 Textures
[High(Textures
)].Anim
:= False;
496 result
:= High(Textures
);
498 else // Íåò òàêîãî ðåóñðñà â WAD'å
500 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
503 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
504 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
511 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
514 TextureWAD
: PChar = nil;
515 TextData
: Pointer = nil;
516 TextureData
: Pointer = nil;
520 TextureResource
: String;
521 _width
, _height
, _framecount
, _speed
: Integer;
522 _backanimation
: Boolean;
524 ia
: TDynImageDataArray
= nil;
525 f
, c
, frdelay
, frloop
: Integer;
529 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
531 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
532 WADName
:= g_ExtractWadName(RecName
);
534 WAD
:= TWADFile
.Create();
536 if WADName
<> '' then
537 WADName
:= GameDir
+'/wads/'+WADName
541 WAD
.ReadFile(WADName
);
543 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
547 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
548 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
554 if WADName = Map then
556 //FreeMem(TextureWAD);
557 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
563 if ResLength
< 6 then
565 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
569 // ýòî ïòèöà? ýòî ñàìîë¸ò?
570 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
571 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
573 // íåò, ýòî ñóïåðìåí!
574 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
576 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
580 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
581 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
583 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
587 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
589 TextureResource
:= cfg
.ReadStr('', 'resource', '');
590 if TextureResource
= '' then
592 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
596 _width
:= cfg
.ReadInt('', 'framewidth', 0);
597 _height
:= cfg
.ReadInt('', 'frameheight', 0);
598 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
599 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
600 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
605 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
606 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
608 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
615 SetLength(Textures
, Length(Textures
)+1);
616 with Textures
[High(Textures
)] do
618 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
619 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
621 TextureName
:= RecName
;
625 FramesCount
:= _framecount
;
627 result
:= High(Textures
);
631 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
637 // try animated image
639 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
640 if length(imgfmt) = 0 then
642 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
646 GlobalMetadata
.ClearMetaItems();
647 GlobalMetadata
.ClearMetaItemsForSaving();
648 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
650 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
653 if length(ia
) = 0 then
655 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
662 _width
:= ia
[0].width
;
663 _height
:= ia
[0].height
;
664 _framecount
:= length(ia
);
666 _backanimation
:= false;
669 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
671 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
673 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
675 if f
< 0 then f
:= 0;
678 if c
< 13 then c
:= 0 else c
:= 1;
680 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
685 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
687 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
689 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
691 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
695 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
696 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
697 f
:= ord(_backanimation
);
698 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
);
700 SetLength(Textures
, Length(Textures
)+1);
701 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
702 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
704 Textures
[High(Textures
)].TextureName
:= RecName
;
705 Textures
[High(Textures
)].Width
:= _width
;
706 Textures
[High(Textures
)].Height
:= _height
;
707 Textures
[High(Textures
)].Anim
:= True;
708 Textures
[High(Textures
)].FramesCount
:= length(ia
);
709 Textures
[High(Textures
)].Speed
:= _speed
;
710 result
:= High(Textures
);
711 //writeln(' CREATED!');
715 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
719 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
722 if TextureWAD
<> nil then FreeMem(TextureWAD
);
723 if TextData
<> nil then FreeMem(TextData
);
724 if TextureData
<> nil then FreeMem(TextureData
);
728 procedure CreateItem(Item
: TItemRec_1
);
730 if g_Game_IsClient
then Exit
;
732 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
733 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
736 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
737 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
740 procedure CreateArea(Area
: TAreaRec_1
);
745 case Area
.AreaType
of
746 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
747 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
749 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
750 with RespawnPoints
[High(RespawnPoints
)] do
754 Direction
:= TDirection(Area
.Direction
);
756 case Area
.AreaType
of
757 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
758 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
759 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
760 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
761 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
766 AREA_REDFLAG
, AREA_BLUEFLAG
:
768 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
770 if FlagPoints
[a
] <> nil then Exit
;
774 with FlagPoints
[a
]^ do
776 X
:= Area
.X
-FLAGRECT
.X
;
777 Y
:= Area
.Y
-FLAGRECT
.Y
;
778 Direction
:= TDirection(Area
.Direction
);
784 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
785 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
788 Animation
:= TAnimation
.Create(id
, True, 8);
789 Obj
.Rect
:= FLAGRECT
;
797 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
798 with DOMFlagPoints[High(DOMFlagPoints)] do
802 Direction := TDirection(Area.Direction);
805 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
810 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
814 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
820 Width
:= Trigger
.Width
;
821 Height
:= Trigger
.Height
;
822 Enabled
:= ByteBool(Trigger
.Enabled
);
823 TexturePanel
:= Trigger
.TexturePanel
;
824 TexturePanelType
:= fTexturePanel1Type
;
825 ShotPanelType
:= fTexturePanel2Type
;
826 TriggerType
:= Trigger
.TriggerType
;
827 ActivateType
:= Trigger
.ActivateType
;
828 Keys
:= Trigger
.Keys
;
829 Data
.Default
:= Trigger
.DATA
;
832 g_Triggers_Create(_trigger
);
835 procedure CreateMonster(monster
: TMonsterRec_1
);
839 if g_Game_IsClient
then Exit
;
841 if (gGameSettings
.GameType
= GT_SINGLE
)
842 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
844 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
845 TDirection(monster
.Direction
));
847 if gTriggers
<> nil then
848 for a
:= 0 to High(gTriggers
) do
849 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
850 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
851 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
852 gMonsters
[i
].AddTrigger(a
);
854 if monster
.MonsterType
<> MONSTER_BARREL
then
859 procedure g_Map_ReAdd_DieTriggers();
863 if g_Game_IsClient
then Exit
;
865 for i
:= 0 to High(gMonsters
) do
866 if gMonsters
[i
] <> nil then
868 gMonsters
[i
].ClearTriggers();
870 for a
:= 0 to High(gTriggers
) do
871 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
872 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
873 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
874 gMonsters
[i
].AddTrigger(a
);
878 function extractWadName(resourceName
: string): string;
882 posN
:= Pos(':', resourceName
);
884 Result
:= Copy(resourceName
, 0, posN
-1)
889 procedure addResToExternalResList(res
: string);
891 res
:= extractWadName(res
);
892 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
893 gExternalResources
.Add(res
);
896 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
898 textures
: TTexturesRec1Array
;
899 mapHeader
: TMapHeaderRec_1
;
901 resFile
: String = '';
903 if gExternalResources
= nil then
904 gExternalResources
:= TStringList
.Create
;
906 gExternalResources
.Clear
;
907 textures
:= mapReader
.GetTextures();
908 for i
:= 0 to High(textures
) do
910 addResToExternalResList(resFile
);
915 mapHeader
:= mapReader
.GetMapHeader
;
917 addResToExternalResList(mapHeader
.MusicName
);
918 addResToExternalResList(mapHeader
.SkyName
);
921 procedure mapCreateGrid ();
923 mapX0
: Integer = $3fffffff;
924 mapY0
: Integer = $3fffffff;
925 mapX1
: Integer = -$3fffffff;
926 mapY1
: Integer = -$3fffffff;
928 procedure fixMinMax (var panels
: TPanelArray
);
932 for idx
:= 0 to High(panels
) do
934 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
935 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
936 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
937 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
938 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
942 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
946 tag
:= panelTypeToTag(tag
);
947 for idx
:= High(panels
) downto 0 do
949 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
958 fixMinMax(gRenderBackgrounds
);
959 fixMinMax(gRenderForegrounds
);
965 fixMinMax(gBlockMon
);
967 if (mapX0
< 0) or (mapY0
< 0) then
969 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
970 //raise Exception.Create('we are fucked');
973 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
975 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
976 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
977 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
978 addPanelsToGrid(gWater
, PANEL_WATER
);
979 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
980 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
981 addPanelsToGrid(gSteps
, PANEL_STEP
);
982 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
983 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
985 gMapGrid
.dumpStats();
988 function g_Map_Load(Res
: String): Boolean;
990 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
991 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
994 MapReader
: TMapReader_1
;
995 Header
: TMapHeaderRec_1
;
996 _textures
: TTexturesRec1Array
;
997 _texnummap
: array of Integer; // `_textures` -> `Textures`
998 panels
: TPanelsRec1Array
;
999 items
: TItemsRec1Array
;
1000 monsters
: TMonsterRec1Array
;
1001 areas
: TAreasRec1Array
;
1002 triggers
: TTriggersRec1Array
;
1003 a
, b
, c
, k
: Integer;
1005 AddTextures
: TAddTextureArray
;
1006 texture
: TTextureRec_1
;
1007 TriggersTable
: Array of record
1008 TexturePanel
: Integer;
1013 FileName
, mapResName
, s
, TexName
: String;
1016 ok
, isAnim
, trigRef
: Boolean;
1017 CurTex
, ntn
: Integer;
1024 gMapInfo
.Map
:= Res
;
1025 TriggersTable
:= nil;
1026 FillChar(texture
, SizeOf(texture
), 0);
1028 sfsGCDisable(); // temporary disable removing of temporary volumes
1031 FileName
:= g_ExtractWadName(Res
);
1032 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1033 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1035 WAD
:= TWADFile
.Create();
1036 if not WAD
.ReadFile(FileName
) then
1038 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1042 //k8: why loader ignores path here?
1043 mapResName
:= g_ExtractFileName(Res
);
1044 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1046 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1054 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1055 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1056 MapReader
:= TMapReader_1
.Create();
1058 if not MapReader
.LoadMap(Data
) then
1060 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1067 generateExternalResourcesList(MapReader
);
1068 // Çàãðóçêà òåêñòóð:
1069 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1070 _textures
:= MapReader
.GetTextures();
1073 // Äîáàâëåíèå òåêñòóð â Textures[]:
1074 if _textures
<> nil then
1076 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1077 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1078 SetLength(_texnummap
, length(_textures
));
1080 for a
:= 0 to High(_textures
) do
1083 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1084 for b
:= 1 to Length(s
) do
1090 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1091 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1092 // Àíèìèðîâàííàÿ òåêñòóðà:
1093 if ByteBool(_textures
[a
].Anim
) then
1095 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1098 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1099 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1102 else // Îáû÷íàÿ òåêñòóðà:
1103 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1106 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1107 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1110 _texnummap
[a
] := ntn
; // fix texture number
1111 g_Game_StepLoading();
1115 // Çàãðóçêà òðèããåðîâ:
1116 gTriggerClientID
:= 0;
1117 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1118 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1119 triggers
:= MapReader
.GetTriggers();
1121 // Çàãðóçêà ïàíåëåé:
1122 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1123 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1124 panels
:= MapReader
.GetPanels();
1126 // check texture numbers for panels
1127 for a
:= 0 to High(panels
) do
1129 if panels
[a
].TextureNum
> High(_textures
) then
1131 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1135 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1138 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1139 if triggers
<> nil then
1141 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1142 SetLength(TriggersTable
, Length(triggers
));
1143 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1145 for a
:= 0 to High(TriggersTable
) do
1147 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1148 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1150 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1151 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1153 TriggersTable
[a
].LiftPanel
:= -1;
1155 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1156 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1157 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1158 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1160 TriggersTable
[a
].DoorPanel
:= -1;
1162 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1163 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1165 TriggersTable
[a
].ShotPanel
:= -1;
1167 g_Game_StepLoading();
1172 if panels
<> nil then
1174 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1175 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1177 for a
:= 0 to High(panels
) do
1179 SetLength(AddTextures
, 0);
1182 if _textures
<> nil then
1184 texture
:= _textures
[panels
[a
].TextureNum
];
1192 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1193 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1195 if (TriggersTable
<> nil) and (_textures
<> nil) then
1196 for b
:= 0 to High(TriggersTable
) do
1197 if (TriggersTable
[b
].TexturePanel
= a
)
1198 or (TriggersTable
[b
].ShotPanel
= a
) then
1207 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1209 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1212 for c
:= Len
downto 1 do
1220 // Ñïåö-òåêñòóðû çàïðåùåíû:
1221 if g_Map_IsSpecialTexture(s
) then
1224 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1225 ok
:= g_Texture_NumNameFindStart(s
);
1227 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1228 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1231 k
:= NNF_NAME_BEFORE
;
1232 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1233 while ok
or (k
= NNF_NAME_BEFORE
) or
1234 (k
= NNF_NAME_EQUALS
) do
1236 k
:= g_Texture_NumNameFindNext(TexName
);
1238 if (k
= NNF_NAME_BEFORE
) or
1239 (k
= NNF_NAME_AFTER
) then
1241 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1242 if ByteBool(texture
.Anim
) then
1243 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1245 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1247 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1249 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1253 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1255 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1257 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1259 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1263 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1266 for c
:= 0 to High(Textures
) do
1267 if Textures
[c
].TextureName
= TexName
then
1269 SetLength(AddTextures
, Length(AddTextures
)+1);
1270 AddTextures
[High(AddTextures
)].Texture
:= c
;
1271 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1277 if k
= NNF_NAME_EQUALS
then
1279 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1280 SetLength(AddTextures
, Length(AddTextures
)+1);
1281 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1282 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1283 CurTex
:= High(AddTextures
);
1291 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1292 end; // if ok - ññûëàþòñÿ òðèããåðû
1296 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1297 SetLength(AddTextures
, 1);
1298 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1299 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1303 //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);
1305 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1306 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1308 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1309 if TriggersTable
<> nil then
1310 for b
:= 0 to High(TriggersTable
) do
1312 // Òðèããåð äâåðè/ëèôòà:
1313 if (TriggersTable
[b
].LiftPanel
= a
) or
1314 (TriggersTable
[b
].DoorPanel
= a
) then
1315 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1316 // Òðèããåð ñìåíû òåêñòóðû:
1317 if TriggersTable
[b
].TexturePanel
= a
then
1318 triggers
[b
].TexturePanel
:= PanelID
;
1319 // Òðèããåð "Òóðåëü":
1320 if TriggersTable
[b
].ShotPanel
= a
then
1321 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1324 g_Game_StepLoading();
1328 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1329 if (triggers
<> nil) and not gLoadGameMode
then
1331 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1332 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1333 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1334 for a
:= 0 to High(triggers
) do
1336 if triggers
[a
].TexturePanel
<> -1 then
1337 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1340 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1341 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1342 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1345 CreateTrigger(triggers
[a
], b
, c
);
1349 // Çàãðóçêà ïðåäìåòîâ:
1350 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1351 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1352 items
:= MapReader
.GetItems();
1354 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1355 if (items
<> nil) and not gLoadGameMode
then
1357 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1358 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1359 for a
:= 0 to High(items
) do
1360 CreateItem(Items
[a
]);
1363 // Çàãðóçêà îáëàñòåé:
1364 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1365 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1366 areas
:= MapReader
.GetAreas();
1368 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1369 if areas
<> nil then
1371 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1372 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1373 for a
:= 0 to High(areas
) do
1374 CreateArea(areas
[a
]);
1377 // Çàãðóçêà ìîíñòðîâ:
1378 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1379 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1380 monsters
:= MapReader
.GetMonsters();
1382 gTotalMonsters
:= 0;
1384 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1385 if (monsters
<> nil) and not gLoadGameMode
then
1387 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1388 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1389 for a
:= 0 to High(monsters
) do
1390 CreateMonster(monsters
[a
]);
1393 // Çàãðóçêà îïèñàíèÿ êàðòû:
1394 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1395 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1396 Header
:= MapReader
.GetMapHeader();
1402 Name
:= Header
.MapName
;
1403 Description
:= Header
.MapDescription
;
1404 Author
:= Header
.MapAuthor
;
1405 MusicName
:= Header
.MusicName
;
1406 SkyName
:= Header
.SkyName
;
1407 Height
:= Header
.Height
;
1408 Width
:= Header
.Width
;
1412 if gMapInfo
.SkyName
<> '' then
1414 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1415 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1416 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1418 if FileName
<> '' then
1419 FileName
:= GameDir
+'/wads/'+FileName
1422 FileName
:= g_ExtractWadName(Res
);
1425 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1426 if g_Texture_CreateWAD(BackID
, s
) then
1428 g_Game_SetupScreenSize();
1431 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1436 if gMapInfo
.MusicName
<> '' then
1438 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1439 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1440 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1442 if FileName
<> '' then
1443 FileName
:= GameDir
+'/wads/'+FileName
1446 FileName
:= g_ExtractWadName(Res
);
1449 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1450 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1453 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1456 // Îñòàëüíûå óñòàíâêè:
1464 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1465 if not gLoadGameMode
then
1468 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1474 TriggersTable
:= nil;
1477 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1478 if ok
and (not gLoadGameMode
) then
1480 gMusic
.SetByName(gMapInfo
.MusicName
);
1484 gMusic
.SetByName('');
1486 sfsGCEnable(); // enable releasing unused volumes
1489 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1492 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1496 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1499 MapReader
: TMapReader_1
;
1500 Header
: TMapHeaderRec_1
;
1505 FillChar(Result
, SizeOf(Result
), 0);
1506 FileName
:= g_ExtractWadName(Res
);
1508 WAD
:= TWADFile
.Create();
1509 if not WAD
.ReadFile(FileName
) then
1515 //k8: it ignores path again
1516 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1524 MapReader
:= TMapReader_1
.Create();
1526 if not MapReader
.LoadMap(Data
) then
1528 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1529 ZeroMemory(@Header
, SizeOf(Header
));
1530 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1531 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1535 Header
:= MapReader
.GetMapHeader();
1536 Result
.Name
:= Header
.MapName
;
1537 Result
.Description
:= Header
.MapDescription
;
1544 Result
.Author
:= Header
.MapAuthor
;
1545 Result
.Height
:= Header
.Height
;
1546 Result
.Width
:= Header
.Width
;
1549 function g_Map_GetMapsList(WADName
: string): SArray
;
1556 WAD
:= TWADFile
.Create();
1557 if not WAD
.ReadFile(WADName
) then
1562 ResList
:= WAD
.GetMapResources();
1563 if ResList
<> nil then
1565 for a
:= 0 to High(ResList
) do
1567 SetLength(Result
, Length(Result
)+1);
1568 Result
[High(Result
)] := ResList
[a
];
1574 function g_Map_Exist(Res
: string): Boolean;
1577 FileName
, mnn
: string;
1583 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1585 WAD
:= TWADFile
.Create
;
1586 if not WAD
.ReadFile(FileName
) then
1592 ResList
:= WAD
.GetMapResources();
1595 mnn
:= g_ExtractFileName(Res
);
1596 if ResList
<> nil then
1597 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1604 procedure g_Map_Free();
1608 procedure FreePanelArray(var panels
: TPanelArray
);
1613 if panels
<> nil then
1615 for i
:= 0 to High(panels
) do
1628 RespawnPoints
:= nil;
1629 if FlagPoints
[FLAG_RED
] <> nil then
1631 Dispose(FlagPoints
[FLAG_RED
]);
1632 FlagPoints
[FLAG_RED
] := nil;
1634 if FlagPoints
[FLAG_BLUE
] <> nil then
1636 Dispose(FlagPoints
[FLAG_BLUE
]);
1637 FlagPoints
[FLAG_BLUE
] := nil;
1639 //DOMFlagPoints := nil;
1643 if Textures
<> nil then
1645 for a
:= 0 to High(Textures
) do
1646 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1647 if Textures
[a
].Anim
then
1648 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1650 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1651 e_DeleteTexture(Textures
[a
].TextureID
);
1656 FreePanelArray(gWalls
);
1657 FreePanelArray(gRenderBackgrounds
);
1658 FreePanelArray(gRenderForegrounds
);
1659 FreePanelArray(gWater
);
1660 FreePanelArray(gAcid1
);
1661 FreePanelArray(gAcid2
);
1662 FreePanelArray(gSteps
);
1663 FreePanelArray(gLifts
);
1664 FreePanelArray(gBlockMon
);
1666 if BackID
<> DWORD(-1) then
1670 e_DeleteTexture(BackID
);
1671 BackID
:= DWORD(-1);
1674 g_Game_StopAllSounds(False);
1676 g_Sound_Delete(gMapInfo
.MusicName
);
1678 gMapInfo
.Name
:= '';
1679 gMapInfo
.Description
:= '';
1680 gMapInfo
.MusicName
:= '';
1681 gMapInfo
.Height
:= 0;
1682 gMapInfo
.Width
:= 0;
1690 procedure g_Map_Update();
1696 procedure UpdatePanelArray(var panels
: TPanelArray
);
1701 if panels
<> nil then
1702 for i
:= 0 to High(panels
) do
1707 UpdatePanelArray(gWalls
);
1708 UpdatePanelArray(gRenderBackgrounds
);
1709 UpdatePanelArray(gRenderForegrounds
);
1710 UpdatePanelArray(gWater
);
1711 UpdatePanelArray(gAcid1
);
1712 UpdatePanelArray(gAcid2
);
1713 UpdatePanelArray(gSteps
);
1715 if gGameSettings
.GameMode
= GM_CTF
then
1717 for a
:= FLAG_RED
to FLAG_BLUE
do
1718 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1721 if gFlags
[a
].Animation
<> nil then
1722 gFlags
[a
].Animation
.Update();
1724 m
:= g_Obj_Move(@Obj
, True, True);
1726 if gTime
mod (GAME_TICK
*2) <> 0 then
1729 // Ñîïðîòèâëåíèå âîçäóõà:
1730 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1732 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1733 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1736 gFlags
[a
].CaptureTime
:= 0;
1737 if a
= FLAG_RED
then
1738 s
:= _lc
[I_PLAYER_FLAG_RED
]
1740 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1741 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1743 if g_Game_IsNet
then
1744 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1751 // Èãðîê áåðåò ôëàã:
1752 if gPlayers
<> nil then
1754 j
:= Random(Length(gPlayers
)) - 1;
1756 for d
:= 0 to High(gPlayers
) do
1759 if j
> High(gPlayers
) then
1762 if gPlayers
[j
] <> nil then
1763 if gPlayers
[j
].Live
and
1764 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1766 if gPlayers
[j
].GetFlag(a
) then
1776 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1778 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1782 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1784 // alas, no visible set
1785 for idx
:= 0 to High(panels
) do
1787 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1794 PANEL_WALL
: DrawPanels(0, gWalls
);
1795 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1796 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1797 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1798 PANEL_WATER
: DrawPanels(3, gWater
);
1799 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1800 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1801 PANEL_STEP
: DrawPanels(6, gSteps
);
1807 gDrawPanelList
: TBinaryHeapObj
= nil;
1809 function dplLess (a
, b
: TObject
): Boolean;
1811 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1814 procedure dplClear ();
1816 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1819 procedure dplAddPanel (pan
: TPanel
);
1821 if pan
= nil then exit
;
1822 gDrawPanelList
.insert(pan
);
1826 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1830 function qq (obj
: TObject
; tag
: Integer): Boolean;
1834 result
:= false; // don't stop, ever
1835 if (tag
<> ptag
) then exit
;
1836 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1838 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1839 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1840 //pan := (obj as TPanel);
1841 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1843 pan
:= (obj
as TPanel
);
1844 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1845 //e_WriteLog(Format(' body hit: (%d,%d)-(%dx%d) tag: %d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1849 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1854 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1856 // alas, no visible set
1857 for idx
:= 0 to High(panels
) do
1859 if not (drawDoors
xor panels
[idx
].Door
) then
1862 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1863 if (pan
.X
+pan
.Width
<= x0
) or (pan
.Y
+pan
.Height
<= y0
) then continue
;
1864 if (pan
.X
>= x0
+wdt
) or (pan
.Y
>= y0
+hgt
) then continue
;
1865 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
);
1872 //g_Map_DrawPanelsOld(PanelType); exit;
1873 //e_WriteLog('==================', MSG_NOTIFY);
1874 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1876 ptag
:= panelTypeToTag(PanelType
);
1877 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, qq
);
1881 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1883 PANEL_WALL: DrawPanels(0, gWalls);
1884 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1885 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1886 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1887 PANEL_WATER: DrawPanels(3, gWater);
1888 PANEL_ACID1: DrawPanels(4, gAcid1);
1889 PANEL_ACID2: DrawPanels(5, gAcid2);
1890 PANEL_STEP: DrawPanels(6, gSteps);
1892 e_WriteLog('==================', MSG_NOTIFY);
1895 // sort and draw the list (we need to sort it, or rendering is fucked)
1896 while gDrawPanelList
.count
> 0 do
1898 (gDrawPanelList
.front() as TPanel
).Draw();
1899 gDrawPanelList
.popFront();
1904 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1905 function qq (obj
: TObject
; tag
: Integer): Boolean;
1909 result
:= false; // don't stop, ever
1910 if (tag
<> 0 {panelTypeToTag(PANEL_WALL)}) then exit
; // only walls
1911 pan
:= (obj
as TPanel
);
1912 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1916 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, qq
);
1920 procedure g_Map_DrawBack(dx
, dy
: Integer);
1922 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1923 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1925 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1928 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
1929 PanelType
: Word; b1x3
: Boolean): Boolean;
1935 if WordBool(PanelType
and PANEL_WALL
) then
1936 if gWalls
<> nil then
1941 if gWalls
[a
].Enabled
and
1942 g_Collide(X
, Y
, Width
, Height
,
1943 gWalls
[a
].X
, gWalls
[a
].Y
,
1944 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1951 if WordBool(PanelType
and PANEL_WATER
) then
1952 if gWater
<> nil then
1957 if g_Collide(X
, Y
, Width
, Height
,
1958 gWater
[a
].X
, gWater
[a
].Y
,
1959 gWater
[a
].Width
, gWater
[a
].Height
) then
1966 if WordBool(PanelType
and PANEL_ACID1
) then
1967 if gAcid1
<> nil then
1972 if g_Collide(X
, Y
, Width
, Height
,
1973 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1974 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1981 if WordBool(PanelType
and PANEL_ACID2
) then
1982 if gAcid2
<> nil then
1987 if g_Collide(X
, Y
, Width
, Height
,
1988 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1989 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1996 if WordBool(PanelType
and PANEL_STEP
) then
1997 if gSteps
<> nil then
2002 if g_Collide(X
, Y
, Width
, Height
,
2003 gSteps
[a
].X
, gSteps
[a
].Y
,
2004 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2011 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2012 if gLifts
<> nil then
2017 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2018 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2019 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2020 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2021 g_Collide(X
, Y
, Width
, Height
,
2022 gLifts
[a
].X
, gLifts
[a
].Y
,
2023 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2030 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2031 if gBlockMon
<> nil then
2033 h
:= High(gBlockMon
);
2037 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2038 g_Collide(X
, Y
, Width
, Height
,
2039 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2040 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2048 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2050 function qq (obj
: TObject
; tag
: Integer): Boolean;
2055 result
:= false; // don't stop, ever
2057 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2061 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2063 if not (obj
is TPanel
) then
2065 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2069 pan
:= (obj
as TPanel
);
2072 if WordBool(PanelType
and PANEL_WALL
) and (tag
= panelTypeToTag(PANEL_WALL
)) then
2074 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2081 if WordBool(PanelType
and PANEL_WATER
) and (tag
= panelTypeToTag(PANEL_WATER
)) then
2083 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2090 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= panelTypeToTag(PANEL_ACID1
)) then
2092 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2099 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= panelTypeToTag(PANEL_ACID2
)) then
2101 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2108 if WordBool(PanelType
and PANEL_STEP
) and (tag
= panelTypeToTag(PANEL_STEP
)) then
2110 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2117 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= panelTypeToTag(PANEL_LIFTUP
)) then
2119 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2120 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2121 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2122 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2123 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2130 if WordBool(PanelType
and PANEL_BLOCKMON
)and (tag
= panelTypeToTag(PANEL_BLOCKMON
)) then
2132 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2133 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2142 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, qq
);
2146 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2150 Result
:= TEXTURE_NONE
;
2152 if gWater
<> nil then
2157 if g_Collide(X
, Y
, Width
, Height
,
2158 gWater
[a
].X
, gWater
[a
].Y
,
2159 gWater
[a
].Width
, gWater
[a
].Height
) then
2161 Result
:= gWater
[a
].GetTextureID();
2166 if gAcid1
<> nil then
2171 if g_Collide(X
, Y
, Width
, Height
,
2172 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2173 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2175 Result
:= gAcid1
[a
].GetTextureID();
2180 if gAcid2
<> nil then
2185 if g_Collide(X
, Y
, Width
, Height
,
2186 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2187 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2189 Result
:= gAcid2
[a
].GetTextureID();
2195 procedure g_Map_EnableWall(ID
: DWORD
);
2200 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2202 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2206 procedure g_Map_DisableWall(ID
: DWORD
);
2211 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2213 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2217 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2222 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2225 tp
:= gRenderForegrounds
[ID
];
2227 tp
:= gRenderBackgrounds
[ID
];
2240 tp
.NextTexture(AnimLoop
);
2241 if g_Game_IsServer
and g_Game_IsNet
then
2242 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2245 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2247 if gLifts
[ID
].LiftType
= t
then
2254 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2256 if LiftType
= 0 then
2257 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2258 else if LiftType
= 1 then
2259 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2260 else if LiftType
= 2 then
2261 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2262 else if LiftType
= 3 then
2263 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2265 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2269 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2272 PointsArray
: Array of TRespawnPoint
;
2275 SetLength(PointsArray
, 0);
2277 if RespawnPoints
= nil then
2280 for a
:= 0 to High(RespawnPoints
) do
2281 if RespawnPoints
[a
].PointType
= PointType
then
2283 SetLength(PointsArray
, Length(PointsArray
)+1);
2284 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2287 if PointsArray
= nil then
2290 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2294 function g_Map_GetPointCount(PointType
: Byte): Word;
2300 if RespawnPoints
= nil then
2303 for a
:= 0 to High(RespawnPoints
) do
2304 if RespawnPoints
[a
].PointType
= PointType
then
2305 Result
:= Result
+ 1;
2308 function g_Map_HaveFlagPoints(): Boolean;
2310 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2313 procedure g_Map_ResetFlag(Flag
: Byte);
2315 with gFlags
[Flag
] do
2321 Direction
:= D_LEFT
;
2322 State
:= FLAG_STATE_NONE
;
2323 if FlagPoints
[Flag
] <> nil then
2325 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2326 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2327 Direction
:= FlagPoints
[Flag
]^.Direction
;
2328 State
:= FLAG_STATE_NORMAL
;
2334 procedure g_Map_DrawFlags();
2337 Mirror
: TMirrorType
;
2339 if gGameSettings
.GameMode
<> GM_CTF
then
2342 for i
:= FLAG_RED
to FLAG_BLUE
do
2344 if State
<> FLAG_STATE_CAPTURED
then
2346 if State
= FLAG_STATE_NONE
then
2349 if Direction
= D_LEFT
then
2351 Mirror
:= M_HORIZONTAL
;
2360 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2362 if g_debug_Frames
then
2364 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2366 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2367 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2373 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2380 procedure SavePanelArray(var panels
: TPanelArray
);
2382 PAMem
: TBinMemoryWriter
;
2385 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2386 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2389 while i
< Length(panels
) do
2391 if panels
[i
].SaveIt
then
2395 // Ñîõðàíÿåì ïàíåëü:
2396 panels
[i
].SaveState(PAMem
);
2401 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2402 PAMem
.SaveToMemory(Mem
);
2406 procedure SaveFlag(flag
: PFlag
);
2409 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2411 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2412 Mem
.WriteByte(flag
^.RespawnType
);
2414 Mem
.WriteByte(flag
^.State
);
2415 // Íàïðàâëåíèå ôëàãà:
2416 if flag
^.Direction
= D_LEFT
then
2422 Obj_SaveState(@flag
^.Obj
, Mem
);
2426 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2428 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2429 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2430 SavePanelArray(gWalls
);
2431 // Ñîõðàíÿåì ïàíåëè ôîíà:
2432 SavePanelArray(gRenderBackgrounds
);
2433 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2434 SavePanelArray(gRenderForegrounds
);
2435 // Ñîõðàíÿåì ïàíåëè âîäû:
2436 SavePanelArray(gWater
);
2437 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2438 SavePanelArray(gAcid1
);
2439 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2440 SavePanelArray(gAcid2
);
2441 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2442 SavePanelArray(gSteps
);
2443 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2444 SavePanelArray(gLifts
);
2447 ///// Ñîõðàíÿåì ìóçûêó: /////
2448 // Ñèãíàòóðà ìóçûêè:
2449 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2452 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2453 if gMusic
.NoMusic
then
2457 Mem
.WriteString(str
, 64);
2458 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2459 dw
:= gMusic
.GetPosition();
2461 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2462 boo
:= gMusic
.SpecPause
;
2463 Mem
.WriteBoolean(boo
);
2466 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2467 Mem
.WriteInt(gTotalMonsters
);
2470 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2471 if gGameSettings
.GameMode
= GM_CTF
then
2473 // Ôëàã Êðàñíîé êîìàíäû:
2474 SaveFlag(@gFlags
[FLAG_RED
]);
2475 // Ôëàã Ñèíåé êîìàíäû:
2476 SaveFlag(@gFlags
[FLAG_BLUE
]);
2480 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2481 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2483 // Î÷êè Êðàñíîé êîìàíäû:
2484 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2485 // Î÷êè Ñèíåé êîìàíäû:
2486 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2491 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2498 procedure LoadPanelArray(var panels
: TPanelArray
);
2500 PAMem
: TBinMemoryReader
;
2503 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2504 PAMem
:= TBinMemoryReader
.Create();
2505 PAMem
.LoadFromMemory(Mem
);
2507 for i
:= 0 to Length(panels
)-1 do
2508 if panels
[i
].SaveIt
then
2514 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2516 // Çàãðóæàåì ïàíåëü:
2517 panels
[i
].LoadState(PAMem
);
2520 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2524 procedure LoadFlag(flag
: PFlag
);
2528 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2530 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2532 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2533 Mem
.ReadByte(flag
^.RespawnType
);
2535 Mem
.ReadByte(flag
^.State
);
2536 // Íàïðàâëåíèå ôëàãà:
2539 flag
^.Direction
:= D_LEFT
2541 flag
^.Direction
:= D_RIGHT
;
2543 Obj_LoadState(@flag
^.Obj
, Mem
);
2550 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2551 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2552 LoadPanelArray(gWalls
);
2553 // Çàãðóæàåì ïàíåëè ôîíà:
2554 LoadPanelArray(gRenderBackgrounds
);
2555 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2556 LoadPanelArray(gRenderForegrounds
);
2557 // Çàãðóæàåì ïàíåëè âîäû:
2558 LoadPanelArray(gWater
);
2559 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2560 LoadPanelArray(gAcid1
);
2561 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2562 LoadPanelArray(gAcid2
);
2563 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2564 LoadPanelArray(gSteps
);
2565 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2566 LoadPanelArray(gLifts
);
2569 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2573 ///// Çàãðóæàåì ìóçûêó: /////
2574 // Ñèãíàòóðà ìóçûêè:
2576 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2578 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2581 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2582 Mem
.ReadString(str
);
2583 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2585 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2586 Mem
.ReadBoolean(boo
);
2587 // Çàïóñêàåì ýòó ìóçûêó:
2588 gMusic
.SetByName(str
);
2589 gMusic
.SpecPause
:= boo
;
2592 gMusic
.SetPosition(dw
);
2595 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2596 Mem
.ReadInt(gTotalMonsters
);
2599 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2600 if gGameSettings
.GameMode
= GM_CTF
then
2602 // Ôëàã Êðàñíîé êîìàíäû:
2603 LoadFlag(@gFlags
[FLAG_RED
]);
2604 // Ôëàã Ñèíåé êîìàíäû:
2605 LoadFlag(@gFlags
[FLAG_BLUE
]);
2609 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2610 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2612 // Î÷êè Êðàñíîé êîìàíäû:
2613 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2614 // Î÷êè Ñèíåé êîìàíäû:
2615 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2620 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2625 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2626 Arr
:= PanelByID
[PanelID
].PWhere
^;
2627 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2628 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);