d56ed47860c43d1fa441a35bac8c1cbeec964ad9
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/>.
16 {$INCLUDE g_amodes.inc}
22 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
23 g_phys
, wadreader
, BinEditor
, g_panel
, g_grid
, md5
;
37 PRespawnPoint
= ^TRespawnPoint
;
38 TRespawnPoint
= record
40 Direction
: TDirection
;
44 PFlagPoint
= ^TFlagPoint
;
45 TFlagPoint
= TRespawnPoint
;
53 CaptureTime
: LongWord;
54 Animation
: TAnimation
;
55 Direction
: TDirection
;
58 function g_Map_Load(Res
: String): Boolean;
59 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
60 function g_Map_GetMapsList(WADName
: String): SArray
;
61 function g_Map_Exist(Res
: String): Boolean;
62 procedure g_Map_Free();
63 procedure g_Map_Update();
65 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
67 procedure g_Map_DrawBack(dx
, dy
: Integer);
68 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
69 PanelType
: Word; b1x3
: Boolean): Boolean;
70 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
71 procedure g_Map_EnableWall(ID
: DWORD
);
72 procedure g_Map_DisableWall(ID
: DWORD
);
73 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
74 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
75 procedure g_Map_ReAdd_DieTriggers();
76 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
78 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
79 function g_Map_GetPointCount(PointType
: Byte): Word;
81 function g_Map_HaveFlagPoints(): Boolean;
83 procedure g_Map_ResetFlag(Flag
: Byte);
84 procedure g_Map_DrawFlags();
86 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
88 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
89 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
91 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
94 RESPAWNPOINT_PLAYER1
= 1;
95 RESPAWNPOINT_PLAYER2
= 2;
98 RESPAWNPOINT_BLUE
= 5;
106 FLAG_STATE_NORMAL
= 1;
107 FLAG_STATE_DROPPED
= 2;
108 FLAG_STATE_CAPTURED
= 3;
109 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
110 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
112 FLAG_TIME
= 720; // 20 seconds
114 SKY_STRETCH
: Single = 1.5;
118 gRenderBackgrounds
: TPanelArray
;
119 gRenderForegrounds
: TPanelArray
;
120 gWater
, gAcid1
, gAcid2
: TPanelArray
;
123 gBlockMon
: TPanelArray
;
124 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
125 //gDOMFlags: array of TFlag;
128 gDoorMap
: array of array of DWORD
;
129 gLiftMap
: array of array of DWORD
;
130 gWADHash
: TMD5Digest
;
131 BackID
: DWORD
= DWORD(-1);
132 gExternalResources
: TStringList
;
137 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
138 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
139 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
140 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
142 ImagingTypes
, Imaging
, ImagingUtility
,
143 ImagingGif
, ImagingNetworkGraphics
;
146 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
147 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
148 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
162 function panelTypeToTag (panelType
: Word): Integer;
165 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
: result
:= GridTagWallDoor
; // gWalls
166 PANEL_BACK
: result
:= GridTagBack
; // gRenderBackgrounds
167 PANEL_FORE
: result
:= GridTagFore
; // gRenderForegrounds
168 PANEL_WATER
: result
:= GridTagWater
; // gWater
169 PANEL_ACID1
: result
:= GridTagAcid1
; // gAcid1
170 PANEL_ACID2
: result
:= GridTagAcid2
; // gAcid2
171 PANEL_STEP
: result
:= GridTagStep
; // gSteps
172 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
: result
:= GridTagLift
; // gLifts -- this is for all lifts
173 PANEL_BLOCKMON
: result
:= GridTagBlockMon
; // gBlockMon -- this is for all blockmons
174 else result
:= GridTagInvalid
;
181 PWhere
: ^TPanelArray
;
186 PanelById
: array of TPanelID
;
187 Textures
: TLevelTextureArray
;
188 RespawnPoints
: Array of TRespawnPoint
;
189 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
190 //DOMFlagPoints: Array of TFlagPoint;
191 gMapGrid
: TBodyGrid
= nil;
194 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
196 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
197 (Texture
= TEXTURE_NAME_ACID1
) or
198 (Texture
= TEXTURE_NAME_ACID2
);
201 procedure CreateDoorMap();
203 PanelArray
: Array of record
209 a
, b
, c
, m
, i
, len
: Integer;
217 SetLength(PanelArray
, len
);
219 for a
:= 0 to High(gWalls
) do
220 if gWalls
[a
].Door
then
222 PanelArray
[i
].X
:= gWalls
[a
].X
;
223 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
224 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
225 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
226 PanelArray
[i
].Active
:= True;
227 PanelArray
[i
].PanelID
:= a
;
233 SetLength(PanelArray
, len
);
244 SetLength(gDoorMap
, 0);
246 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
249 if PanelArray
[a
].Active
then
251 PanelArray
[a
].Active
:= False;
252 m
:= Length(gDoorMap
);
253 SetLength(gDoorMap
, m
+1);
254 SetLength(gDoorMap
[m
], 1);
255 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
263 if PanelArray
[b
].Active
then
264 for c
:= 0 to High(gDoorMap
[m
]) do
265 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
266 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
267 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
268 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
269 gWalls
[gDoorMap
[m
, c
]].X
,
270 gWalls
[gDoorMap
[m
, c
]].Y
,
271 gWalls
[gDoorMap
[m
, c
]].Width
,
272 gWalls
[gDoorMap
[m
, c
]].Height
) then
274 PanelArray
[b
].Active
:= False;
275 SetLength(gDoorMap
[m
],
276 Length(gDoorMap
[m
])+1);
277 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
283 g_Game_StepLoading();
289 procedure CreateLiftMap();
291 PanelArray
: Array of record
296 a
, b
, c
, len
, i
, j
: Integer;
302 len
:= Length(gLifts
);
303 SetLength(PanelArray
, len
);
305 for a
:= 0 to len
-1 do
307 PanelArray
[a
].X
:= gLifts
[a
].X
;
308 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
309 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
310 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
311 PanelArray
[a
].Active
:= True;
314 SetLength(gLiftMap
, len
);
317 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
319 for a
:= 0 to len
-1 do
320 if PanelArray
[a
].Active
then
322 PanelArray
[a
].Active
:= False;
323 SetLength(gLiftMap
[i
], 32);
331 for b
:= 0 to len
-1 do
332 if PanelArray
[b
].Active
then
334 if g_CollideAround(PanelArray
[b
].X
,
337 PanelArray
[b
].Height
,
338 PanelArray
[gLiftMap
[i
, c
]].X
,
339 PanelArray
[gLiftMap
[i
, c
]].Y
,
340 PanelArray
[gLiftMap
[i
, c
]].Width
,
341 PanelArray
[gLiftMap
[i
, c
]].Height
) then
343 PanelArray
[b
].Active
:= False;
345 if j
> High(gLiftMap
[i
]) then
346 SetLength(gLiftMap
[i
],
347 Length(gLiftMap
[i
])+32);
356 SetLength(gLiftMap
[i
], j
+1);
359 g_Game_StepLoading();
362 SetLength(gLiftMap
, i
);
367 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
368 CurTex
: Integer; sav
: Boolean): Integer;
371 panels
: ^TPanelArray
;
375 case PanelRec
.PanelType
of
376 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
379 panels
:= @gRenderBackgrounds
;
381 panels
:= @gRenderForegrounds
;
390 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
393 panels
:= @gBlockMon
;
398 len
:= Length(panels
^);
399 SetLength(panels
^, len
+ 1);
401 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
402 panels
^[len
].ArrIdx
:= len
;
404 panels
^[len
].SaveIt
:= True;
408 len
:= Length(PanelByID
);
409 SetLength(PanelByID
, len
+ 1);
410 PanelByID
[len
].PWhere
:= panels
;
411 PanelByID
[len
].PArrID
:= Result
;
414 function CreateNullTexture(RecName
: String): Integer;
416 SetLength(Textures
, Length(Textures
)+1);
417 result
:= High(Textures
);
419 with Textures
[High(Textures
)] do
421 TextureName
:= RecName
;
425 TextureID
:= TEXTURE_NONE
;
429 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
432 TextureData
: Pointer;
433 WADName
, txname
: String;
434 a
, ResLength
: Integer;
438 if Textures
<> nil then
439 for a
:= 0 to High(Textures
) do
440 if Textures
[a
].TextureName
= RecName
then
441 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
446 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
447 if (RecName
= TEXTURE_NAME_WATER
) or
448 (RecName
= TEXTURE_NAME_ACID1
) or
449 (RecName
= TEXTURE_NAME_ACID2
) then
451 SetLength(Textures
, Length(Textures
)+1);
453 with Textures
[High(Textures
)] do
455 TextureName
:= RecName
;
457 if TextureName
= TEXTURE_NAME_WATER
then
458 TextureID
:= TEXTURE_SPECIAL_WATER
460 if TextureName
= TEXTURE_NAME_ACID1
then
461 TextureID
:= TEXTURE_SPECIAL_ACID1
463 if TextureName
= TEXTURE_NAME_ACID2
then
464 TextureID
:= TEXTURE_SPECIAL_ACID2
;
469 result
:= High(Textures
);
473 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
474 WADName
:= g_ExtractWadName(RecName
);
476 WAD
:= TWADFile
.Create();
478 if WADName
<> '' then
479 WADName
:= GameDir
+'/wads/'+WADName
483 WAD
.ReadFile(WADName
);
487 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
489 FreeMem(TextureData);
490 RecName := 'COMMON\ALIEN';
494 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
496 SetLength(Textures
, Length(Textures
)+1);
497 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
499 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
500 @Textures
[High(Textures
)].Width
,
501 @Textures
[High(Textures
)].Height
);
502 FreeMem(TextureData
);
503 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
504 Textures
[High(Textures
)].Anim
:= False;
506 result
:= High(Textures
);
508 else // Íåò òàêîãî ðåóñðñà â WAD'å
510 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
513 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
514 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
521 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
524 TextureWAD
: PChar = nil;
525 TextData
: Pointer = nil;
526 TextureData
: Pointer = nil;
530 TextureResource
: String;
531 _width
, _height
, _framecount
, _speed
: Integer;
532 _backanimation
: Boolean;
534 ia
: TDynImageDataArray
= nil;
535 f
, c
, frdelay
, frloop
: Integer;
539 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
541 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
542 WADName
:= g_ExtractWadName(RecName
);
544 WAD
:= TWADFile
.Create();
546 if WADName
<> '' then
547 WADName
:= GameDir
+'/wads/'+WADName
551 WAD
.ReadFile(WADName
);
553 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
557 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
558 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
564 if WADName = Map then
566 //FreeMem(TextureWAD);
567 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
573 if ResLength
< 6 then
575 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
579 // ýòî ïòèöà? ýòî ñàìîë¸ò?
580 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
581 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
583 // íåò, ýòî ñóïåðìåí!
584 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
586 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
590 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
591 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
593 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
597 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
599 TextureResource
:= cfg
.ReadStr('', 'resource', '');
600 if TextureResource
= '' then
602 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
606 _width
:= cfg
.ReadInt('', 'framewidth', 0);
607 _height
:= cfg
.ReadInt('', 'frameheight', 0);
608 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
609 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
610 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
615 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
616 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
618 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
625 SetLength(Textures
, Length(Textures
)+1);
626 with Textures
[High(Textures
)] do
628 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
629 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
631 TextureName
:= RecName
;
635 FramesCount
:= _framecount
;
637 result
:= High(Textures
);
641 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
647 // try animated image
649 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
650 if length(imgfmt) = 0 then
652 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
656 GlobalMetadata
.ClearMetaItems();
657 GlobalMetadata
.ClearMetaItemsForSaving();
658 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
660 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
663 if length(ia
) = 0 then
665 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
672 _width
:= ia
[0].width
;
673 _height
:= ia
[0].height
;
674 _framecount
:= length(ia
);
676 _backanimation
:= false;
679 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
681 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
683 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
685 if f
< 0 then f
:= 0;
688 if c
< 13 then c
:= 0 else c
:= 1;
690 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
695 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
697 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
699 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
701 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
705 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
706 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
707 f
:= ord(_backanimation
);
708 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
);
710 SetLength(Textures
, Length(Textures
)+1);
711 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
712 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
714 Textures
[High(Textures
)].TextureName
:= RecName
;
715 Textures
[High(Textures
)].Width
:= _width
;
716 Textures
[High(Textures
)].Height
:= _height
;
717 Textures
[High(Textures
)].Anim
:= True;
718 Textures
[High(Textures
)].FramesCount
:= length(ia
);
719 Textures
[High(Textures
)].Speed
:= _speed
;
720 result
:= High(Textures
);
721 //writeln(' CREATED!');
725 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
729 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
732 if TextureWAD
<> nil then FreeMem(TextureWAD
);
733 if TextData
<> nil then FreeMem(TextData
);
734 if TextureData
<> nil then FreeMem(TextureData
);
738 procedure CreateItem(Item
: TItemRec_1
);
740 if g_Game_IsClient
then Exit
;
742 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
743 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
746 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
747 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
750 procedure CreateArea(Area
: TAreaRec_1
);
755 case Area
.AreaType
of
756 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
757 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
759 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
760 with RespawnPoints
[High(RespawnPoints
)] do
764 Direction
:= TDirection(Area
.Direction
);
766 case Area
.AreaType
of
767 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
768 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
769 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
770 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
771 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
776 AREA_REDFLAG
, AREA_BLUEFLAG
:
778 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
780 if FlagPoints
[a
] <> nil then Exit
;
784 with FlagPoints
[a
]^ do
786 X
:= Area
.X
-FLAGRECT
.X
;
787 Y
:= Area
.Y
-FLAGRECT
.Y
;
788 Direction
:= TDirection(Area
.Direction
);
794 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
795 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
798 Animation
:= TAnimation
.Create(id
, True, 8);
799 Obj
.Rect
:= FLAGRECT
;
807 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
808 with DOMFlagPoints[High(DOMFlagPoints)] do
812 Direction := TDirection(Area.Direction);
815 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
820 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
824 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
830 Width
:= Trigger
.Width
;
831 Height
:= Trigger
.Height
;
832 Enabled
:= ByteBool(Trigger
.Enabled
);
833 TexturePanel
:= Trigger
.TexturePanel
;
834 TexturePanelType
:= fTexturePanel1Type
;
835 ShotPanelType
:= fTexturePanel2Type
;
836 TriggerType
:= Trigger
.TriggerType
;
837 ActivateType
:= Trigger
.ActivateType
;
838 Keys
:= Trigger
.Keys
;
839 Data
.Default
:= Trigger
.DATA
;
842 g_Triggers_Create(_trigger
);
845 procedure CreateMonster(monster
: TMonsterRec_1
);
849 if g_Game_IsClient
then Exit
;
851 if (gGameSettings
.GameType
= GT_SINGLE
)
852 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
854 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
855 TDirection(monster
.Direction
));
857 if gTriggers
<> nil then
858 for a
:= 0 to High(gTriggers
) do
859 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
860 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
861 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
862 gMonsters
[i
].AddTrigger(a
);
864 if monster
.MonsterType
<> MONSTER_BARREL
then
869 procedure g_Map_ReAdd_DieTriggers();
873 if g_Game_IsClient
then Exit
;
875 for i
:= 0 to High(gMonsters
) do
876 if gMonsters
[i
] <> nil then
878 gMonsters
[i
].ClearTriggers();
880 for a
:= 0 to High(gTriggers
) do
881 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
882 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
883 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
884 gMonsters
[i
].AddTrigger(a
);
888 function extractWadName(resourceName
: string): string;
892 posN
:= Pos(':', resourceName
);
894 Result
:= Copy(resourceName
, 0, posN
-1)
899 procedure addResToExternalResList(res
: string);
901 res
:= extractWadName(res
);
902 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
903 gExternalResources
.Add(res
);
906 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
908 textures
: TTexturesRec1Array
;
909 mapHeader
: TMapHeaderRec_1
;
911 resFile
: String = '';
913 if gExternalResources
= nil then
914 gExternalResources
:= TStringList
.Create
;
916 gExternalResources
.Clear
;
917 textures
:= mapReader
.GetTextures();
918 for i
:= 0 to High(textures
) do
920 addResToExternalResList(resFile
);
925 mapHeader
:= mapReader
.GetMapHeader
;
927 addResToExternalResList(mapHeader
.MusicName
);
928 addResToExternalResList(mapHeader
.SkyName
);
931 procedure mapCreateGrid ();
933 mapX0
: Integer = $3fffffff;
934 mapY0
: Integer = $3fffffff;
935 mapX1
: Integer = -$3fffffff;
936 mapY1
: Integer = -$3fffffff;
938 procedure fixMinMax (var panels
: TPanelArray
);
942 for idx
:= 0 to High(panels
) do
944 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
945 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
946 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
947 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
948 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
952 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
956 tag
:= panelTypeToTag(tag
);
957 for idx
:= High(panels
) downto 0 do
959 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
968 fixMinMax(gRenderBackgrounds
);
969 fixMinMax(gRenderForegrounds
);
975 fixMinMax(gBlockMon
);
977 if (mapX0
< 0) or (mapY0
< 0) then
979 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0
, mapY0
, mapX1
, mapY1
]), MSG_WARNING
);
980 //raise Exception.Create('we are fucked');
983 gMapGrid
:= TBodyGrid
.Create(mapX0
, mapY0
, mapX1
-mapX0
+1, mapY1
-mapY0
+1);
985 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
986 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
987 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
988 addPanelsToGrid(gWater
, PANEL_WATER
);
989 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
990 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
991 addPanelsToGrid(gSteps
, PANEL_STEP
);
992 addPanelsToGrid(gLifts
, PANEL_LIFTUP
); // it doesn't matter which LIFT type is used here
993 addPanelsToGrid(gBlockMon
, PANEL_BLOCKMON
);
995 gMapGrid
.dumpStats();
998 function g_Map_Load(Res
: String): Boolean;
1000 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
1001 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
1004 MapReader
: TMapReader_1
;
1005 Header
: TMapHeaderRec_1
;
1006 _textures
: TTexturesRec1Array
;
1007 _texnummap
: array of Integer; // `_textures` -> `Textures`
1008 panels
: TPanelsRec1Array
;
1009 items
: TItemsRec1Array
;
1010 monsters
: TMonsterRec1Array
;
1011 areas
: TAreasRec1Array
;
1012 triggers
: TTriggersRec1Array
;
1013 a
, b
, c
, k
: Integer;
1015 AddTextures
: TAddTextureArray
;
1016 texture
: TTextureRec_1
;
1017 TriggersTable
: Array of record
1018 TexturePanel
: Integer;
1023 FileName
, mapResName
, s
, TexName
: String;
1026 ok
, isAnim
, trigRef
: Boolean;
1027 CurTex
, ntn
: Integer;
1034 gMapInfo
.Map
:= Res
;
1035 TriggersTable
:= nil;
1036 FillChar(texture
, SizeOf(texture
), 0);
1038 sfsGCDisable(); // temporary disable removing of temporary volumes
1041 FileName
:= g_ExtractWadName(Res
);
1042 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
1043 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
1045 WAD
:= TWADFile
.Create();
1046 if not WAD
.ReadFile(FileName
) then
1048 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
1052 //k8: why loader ignores path here?
1053 mapResName
:= g_ExtractFileName(Res
);
1054 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
1056 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1064 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1065 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1066 MapReader
:= TMapReader_1
.Create();
1068 if not MapReader
.LoadMap(Data
) then
1070 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1077 generateExternalResourcesList(MapReader
);
1078 // Çàãðóçêà òåêñòóð:
1079 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1080 _textures
:= MapReader
.GetTextures();
1083 // Äîáàâëåíèå òåêñòóð â Textures[]:
1084 if _textures
<> nil then
1086 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1087 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1088 SetLength(_texnummap
, length(_textures
));
1090 for a
:= 0 to High(_textures
) do
1093 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1094 for b
:= 1 to Length(s
) do
1100 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1101 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1102 // Àíèìèðîâàííàÿ òåêñòóðà:
1103 if ByteBool(_textures
[a
].Anim
) then
1105 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1108 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1109 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1112 else // Îáû÷íàÿ òåêñòóðà:
1113 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1116 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1117 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1120 _texnummap
[a
] := ntn
; // fix texture number
1121 g_Game_StepLoading();
1125 // Çàãðóçêà òðèããåðîâ:
1126 gTriggerClientID
:= 0;
1127 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1128 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1129 triggers
:= MapReader
.GetTriggers();
1131 // Çàãðóçêà ïàíåëåé:
1132 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1133 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1134 panels
:= MapReader
.GetPanels();
1136 // check texture numbers for panels
1137 for a
:= 0 to High(panels
) do
1139 if panels
[a
].TextureNum
> High(_textures
) then
1141 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1145 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1148 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1149 if triggers
<> nil then
1151 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1152 SetLength(TriggersTable
, Length(triggers
));
1153 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1155 for a
:= 0 to High(TriggersTable
) do
1157 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1158 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1160 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1161 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1163 TriggersTable
[a
].LiftPanel
:= -1;
1165 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1166 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1167 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1168 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1170 TriggersTable
[a
].DoorPanel
:= -1;
1172 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1173 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1175 TriggersTable
[a
].ShotPanel
:= -1;
1177 g_Game_StepLoading();
1182 if panels
<> nil then
1184 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1185 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1187 for a
:= 0 to High(panels
) do
1189 SetLength(AddTextures
, 0);
1192 if _textures
<> nil then
1194 texture
:= _textures
[panels
[a
].TextureNum
];
1202 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1203 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1205 if (TriggersTable
<> nil) and (_textures
<> nil) then
1206 for b
:= 0 to High(TriggersTable
) do
1207 if (TriggersTable
[b
].TexturePanel
= a
)
1208 or (TriggersTable
[b
].ShotPanel
= a
) then
1217 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1219 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1222 for c
:= Len
downto 1 do
1230 // Ñïåö-òåêñòóðû çàïðåùåíû:
1231 if g_Map_IsSpecialTexture(s
) then
1234 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1235 ok
:= g_Texture_NumNameFindStart(s
);
1237 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1238 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1241 k
:= NNF_NAME_BEFORE
;
1242 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1243 while ok
or (k
= NNF_NAME_BEFORE
) or
1244 (k
= NNF_NAME_EQUALS
) do
1246 k
:= g_Texture_NumNameFindNext(TexName
);
1248 if (k
= NNF_NAME_BEFORE
) or
1249 (k
= NNF_NAME_AFTER
) then
1251 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1252 if ByteBool(texture
.Anim
) then
1253 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1255 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1257 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1259 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1263 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1265 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1267 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1269 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1273 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1276 for c
:= 0 to High(Textures
) do
1277 if Textures
[c
].TextureName
= TexName
then
1279 SetLength(AddTextures
, Length(AddTextures
)+1);
1280 AddTextures
[High(AddTextures
)].Texture
:= c
;
1281 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1287 if k
= NNF_NAME_EQUALS
then
1289 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1290 SetLength(AddTextures
, Length(AddTextures
)+1);
1291 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1292 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1293 CurTex
:= High(AddTextures
);
1301 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1302 end; // if ok - ññûëàþòñÿ òðèããåðû
1306 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1307 SetLength(AddTextures
, 1);
1308 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1309 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1313 //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);
1315 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1316 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1318 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1319 if TriggersTable
<> nil then
1320 for b
:= 0 to High(TriggersTable
) do
1322 // Òðèããåð äâåðè/ëèôòà:
1323 if (TriggersTable
[b
].LiftPanel
= a
) or
1324 (TriggersTable
[b
].DoorPanel
= a
) then
1325 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1326 // Òðèããåð ñìåíû òåêñòóðû:
1327 if TriggersTable
[b
].TexturePanel
= a
then
1328 triggers
[b
].TexturePanel
:= PanelID
;
1329 // Òðèããåð "Òóðåëü":
1330 if TriggersTable
[b
].ShotPanel
= a
then
1331 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1334 g_Game_StepLoading();
1338 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1339 if (triggers
<> nil) and not gLoadGameMode
then
1341 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1342 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1343 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1344 for a
:= 0 to High(triggers
) do
1346 if triggers
[a
].TexturePanel
<> -1 then
1347 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1350 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1351 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1352 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1355 CreateTrigger(triggers
[a
], b
, c
);
1359 // Çàãðóçêà ïðåäìåòîâ:
1360 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1361 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1362 items
:= MapReader
.GetItems();
1364 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1365 if (items
<> nil) and not gLoadGameMode
then
1367 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1368 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1369 for a
:= 0 to High(items
) do
1370 CreateItem(Items
[a
]);
1373 // Çàãðóçêà îáëàñòåé:
1374 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1375 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1376 areas
:= MapReader
.GetAreas();
1378 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1379 if areas
<> nil then
1381 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1382 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1383 for a
:= 0 to High(areas
) do
1384 CreateArea(areas
[a
]);
1387 // Çàãðóçêà ìîíñòðîâ:
1388 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1389 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1390 monsters
:= MapReader
.GetMonsters();
1392 gTotalMonsters
:= 0;
1394 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1395 if (monsters
<> nil) and not gLoadGameMode
then
1397 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1398 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1399 for a
:= 0 to High(monsters
) do
1400 CreateMonster(monsters
[a
]);
1403 // Çàãðóçêà îïèñàíèÿ êàðòû:
1404 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1405 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1406 Header
:= MapReader
.GetMapHeader();
1412 Name
:= Header
.MapName
;
1413 Description
:= Header
.MapDescription
;
1414 Author
:= Header
.MapAuthor
;
1415 MusicName
:= Header
.MusicName
;
1416 SkyName
:= Header
.SkyName
;
1417 Height
:= Header
.Height
;
1418 Width
:= Header
.Width
;
1422 if gMapInfo
.SkyName
<> '' then
1424 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1425 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1426 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1428 if FileName
<> '' then
1429 FileName
:= GameDir
+'/wads/'+FileName
1432 FileName
:= g_ExtractWadName(Res
);
1435 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1436 if g_Texture_CreateWAD(BackID
, s
) then
1438 g_Game_SetupScreenSize();
1441 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1446 if gMapInfo
.MusicName
<> '' then
1448 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1449 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1450 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1452 if FileName
<> '' then
1453 FileName
:= GameDir
+'/wads/'+FileName
1456 FileName
:= g_ExtractWadName(Res
);
1459 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1460 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1463 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1466 // Îñòàëüíûå óñòàíâêè:
1474 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1475 if not gLoadGameMode
then
1478 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1484 TriggersTable
:= nil;
1487 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1488 if ok
and (not gLoadGameMode
) then
1490 gMusic
.SetByName(gMapInfo
.MusicName
);
1494 gMusic
.SetByName('');
1496 sfsGCEnable(); // enable releasing unused volumes
1499 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1502 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1506 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1509 MapReader
: TMapReader_1
;
1510 Header
: TMapHeaderRec_1
;
1515 FillChar(Result
, SizeOf(Result
), 0);
1516 FileName
:= g_ExtractWadName(Res
);
1518 WAD
:= TWADFile
.Create();
1519 if not WAD
.ReadFile(FileName
) then
1525 //k8: it ignores path again
1526 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1534 MapReader
:= TMapReader_1
.Create();
1536 if not MapReader
.LoadMap(Data
) then
1538 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1539 ZeroMemory(@Header
, SizeOf(Header
));
1540 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1541 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1545 Header
:= MapReader
.GetMapHeader();
1546 Result
.Name
:= Header
.MapName
;
1547 Result
.Description
:= Header
.MapDescription
;
1554 Result
.Author
:= Header
.MapAuthor
;
1555 Result
.Height
:= Header
.Height
;
1556 Result
.Width
:= Header
.Width
;
1559 function g_Map_GetMapsList(WADName
: string): SArray
;
1566 WAD
:= TWADFile
.Create();
1567 if not WAD
.ReadFile(WADName
) then
1572 ResList
:= WAD
.GetMapResources();
1573 if ResList
<> nil then
1575 for a
:= 0 to High(ResList
) do
1577 SetLength(Result
, Length(Result
)+1);
1578 Result
[High(Result
)] := ResList
[a
];
1584 function g_Map_Exist(Res
: string): Boolean;
1587 FileName
, mnn
: string;
1593 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1595 WAD
:= TWADFile
.Create
;
1596 if not WAD
.ReadFile(FileName
) then
1602 ResList
:= WAD
.GetMapResources();
1605 mnn
:= g_ExtractFileName(Res
);
1606 if ResList
<> nil then
1607 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1614 procedure g_Map_Free();
1618 procedure FreePanelArray(var panels
: TPanelArray
);
1623 if panels
<> nil then
1625 for i
:= 0 to High(panels
) do
1638 RespawnPoints
:= nil;
1639 if FlagPoints
[FLAG_RED
] <> nil then
1641 Dispose(FlagPoints
[FLAG_RED
]);
1642 FlagPoints
[FLAG_RED
] := nil;
1644 if FlagPoints
[FLAG_BLUE
] <> nil then
1646 Dispose(FlagPoints
[FLAG_BLUE
]);
1647 FlagPoints
[FLAG_BLUE
] := nil;
1649 //DOMFlagPoints := nil;
1653 if Textures
<> nil then
1655 for a
:= 0 to High(Textures
) do
1656 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1657 if Textures
[a
].Anim
then
1658 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1660 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1661 e_DeleteTexture(Textures
[a
].TextureID
);
1666 FreePanelArray(gWalls
);
1667 FreePanelArray(gRenderBackgrounds
);
1668 FreePanelArray(gRenderForegrounds
);
1669 FreePanelArray(gWater
);
1670 FreePanelArray(gAcid1
);
1671 FreePanelArray(gAcid2
);
1672 FreePanelArray(gSteps
);
1673 FreePanelArray(gLifts
);
1674 FreePanelArray(gBlockMon
);
1676 if BackID
<> DWORD(-1) then
1680 e_DeleteTexture(BackID
);
1681 BackID
:= DWORD(-1);
1684 g_Game_StopAllSounds(False);
1686 g_Sound_Delete(gMapInfo
.MusicName
);
1688 gMapInfo
.Name
:= '';
1689 gMapInfo
.Description
:= '';
1690 gMapInfo
.MusicName
:= '';
1691 gMapInfo
.Height
:= 0;
1692 gMapInfo
.Width
:= 0;
1700 procedure g_Map_Update();
1706 procedure UpdatePanelArray(var panels
: TPanelArray
);
1711 if panels
<> nil then
1712 for i
:= 0 to High(panels
) do
1717 UpdatePanelArray(gWalls
);
1718 UpdatePanelArray(gRenderBackgrounds
);
1719 UpdatePanelArray(gRenderForegrounds
);
1720 UpdatePanelArray(gWater
);
1721 UpdatePanelArray(gAcid1
);
1722 UpdatePanelArray(gAcid2
);
1723 UpdatePanelArray(gSteps
);
1725 if gGameSettings
.GameMode
= GM_CTF
then
1727 for a
:= FLAG_RED
to FLAG_BLUE
do
1728 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1731 if gFlags
[a
].Animation
<> nil then
1732 gFlags
[a
].Animation
.Update();
1734 m
:= g_Obj_Move(@Obj
, True, True);
1736 if gTime
mod (GAME_TICK
*2) <> 0 then
1739 // Ñîïðîòèâëåíèå âîçäóõà:
1740 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1742 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1743 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1746 gFlags
[a
].CaptureTime
:= 0;
1747 if a
= FLAG_RED
then
1748 s
:= _lc
[I_PLAYER_FLAG_RED
]
1750 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1751 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1753 if g_Game_IsNet
then
1754 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1761 // Èãðîê áåðåò ôëàã:
1762 if gPlayers
<> nil then
1764 j
:= Random(Length(gPlayers
)) - 1;
1766 for d
:= 0 to High(gPlayers
) do
1769 if j
> High(gPlayers
) then
1772 if gPlayers
[j
] <> nil then
1773 if gPlayers
[j
].Live
and
1774 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1776 if gPlayers
[j
].GetFlag(a
) then
1786 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1788 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1792 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1794 // alas, no visible set
1795 for idx
:= 0 to High(panels
) do
1797 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1804 PANEL_WALL
: DrawPanels(0, gWalls
);
1805 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1806 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1807 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1808 PANEL_WATER
: DrawPanels(3, gWater
);
1809 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1810 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1811 PANEL_STEP
: DrawPanels(6, gSteps
);
1817 gDrawPanelList
: TBinaryHeapObj
= nil;
1819 function dplLess (a
, b
: TObject
): Boolean;
1821 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1824 procedure dplClear ();
1826 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1829 procedure dplAddPanel (pan
: TPanel
);
1831 if pan
= nil then exit
;
1832 gDrawPanelList
.insert(pan
);
1836 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1840 function checker (obj
: TObject
; tag
: Integer): Boolean;
1844 result
:= false; // don't stop, ever
1845 if (tag
<> ptag
) then exit
;
1846 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1848 if obj
= nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1849 if not (obj
is TPanel
) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
); exit
; end;
1850 //pan := (obj as TPanel);
1851 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1853 pan
:= (obj
as TPanel
);
1854 if (PanelType
= PANEL_CLOSEDOOR
) then begin if not pan
.Door
then exit
; end else begin if pan
.Door
then exit
; end;
1855 //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);
1859 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1864 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1866 // alas, no visible set
1867 for idx
:= 0 to High(panels
) do
1869 if not (drawDoors
xor panels
[idx
].Door
) then
1872 if (pan
.Width
< 1) or (pan
.Height
< 1) then continue
;
1873 if (pan
.X
+pan
.Width
<= x0
) or (pan
.Y
+pan
.Height
<= y0
) then continue
;
1874 if (pan
.X
>= x0
+wdt
) or (pan
.Y
>= y0
+hgt
) then continue
;
1875 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
);
1882 //g_Map_DrawPanelsOld(PanelType); exit;
1883 //e_WriteLog('==================', MSG_NOTIFY);
1884 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1886 ptag
:= panelTypeToTag(PanelType
);
1887 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, checker
);
1891 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1893 PANEL_WALL: DrawPanels(0, gWalls);
1894 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1895 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1896 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1897 PANEL_WATER: DrawPanels(3, gWater);
1898 PANEL_ACID1: DrawPanels(4, gAcid1);
1899 PANEL_ACID2: DrawPanels(5, gAcid2);
1900 PANEL_STEP: DrawPanels(6, gSteps);
1902 e_WriteLog('==================', MSG_NOTIFY);
1905 // sort and draw the list (we need to sort it, or rendering is fucked)
1906 while gDrawPanelList
.count
> 0 do
1908 (gDrawPanelList
.front() as TPanel
).Draw();
1909 gDrawPanelList
.popFront();
1914 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
1915 function checker (obj
: TObject
; tag
: Integer): Boolean;
1919 result
:= false; // don't stop, ever
1920 if (tag
<> GridTagWallDoor
) then exit
; // only walls
1921 pan
:= (obj
as TPanel
);
1922 pan
.DrawShadowVolume(lightX
, lightY
, radius
);
1926 gMapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, checker
);
1930 procedure g_Map_DrawBack(dx
, dy
: Integer);
1932 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1933 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1935 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1939 function g_Map_CollidePanelOld(X, Y: Integer; Width, Height: Word;
1940 PanelType: Word; b1x3: Boolean): Boolean;
1946 if WordBool(PanelType and PANEL_WALL) then
1947 if gWalls <> nil then
1952 if gWalls[a].Enabled and
1953 g_Collide(X, Y, Width, Height,
1954 gWalls[a].X, gWalls[a].Y,
1955 gWalls[a].Width, gWalls[a].Height) then
1962 if WordBool(PanelType and PANEL_WATER) then
1963 if gWater <> nil then
1968 if g_Collide(X, Y, Width, Height,
1969 gWater[a].X, gWater[a].Y,
1970 gWater[a].Width, gWater[a].Height) then
1977 if WordBool(PanelType and PANEL_ACID1) then
1978 if gAcid1 <> nil then
1983 if g_Collide(X, Y, Width, Height,
1984 gAcid1[a].X, gAcid1[a].Y,
1985 gAcid1[a].Width, gAcid1[a].Height) then
1992 if WordBool(PanelType and PANEL_ACID2) then
1993 if gAcid2 <> nil then
1998 if g_Collide(X, Y, Width, Height,
1999 gAcid2[a].X, gAcid2[a].Y,
2000 gAcid2[a].Width, gAcid2[a].Height) then
2007 if WordBool(PanelType and PANEL_STEP) then
2008 if gSteps <> nil then
2013 if g_Collide(X, Y, Width, Height,
2014 gSteps[a].X, gSteps[a].Y,
2015 gSteps[a].Width, gSteps[a].Height) then
2022 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
2023 if gLifts <> nil then
2028 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2029 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2030 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2031 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2032 g_Collide(X, Y, Width, Height,
2033 gLifts[a].X, gLifts[a].Y,
2034 gLifts[a].Width, gLifts[a].Height) then
2041 if WordBool(PanelType and PANEL_BLOCKMON) then
2042 if gBlockMon <> nil then
2044 h := High(gBlockMon);
2048 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2049 g_Collide(X, Y, Width, Height,
2050 gBlockMon[a].X, gBlockMon[a].Y,
2051 gBlockMon[a].Width, gBlockMon[a].Height) then
2060 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2062 function checker (obj
: TObject
; tag
: Integer): Boolean;
2067 result
:= false; // don't stop, ever
2069 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2073 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2075 if not (obj
is TPanel
) then
2077 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2081 pan
:= (obj
as TPanel
);
2084 if WordBool(PanelType
and PANEL_WALL
) and (tag
= GridTagWallDoor
) then
2086 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2093 if WordBool(PanelType
and PANEL_WATER
) and (tag
= GridTagWater
) then
2095 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2102 if WordBool(PanelType
and PANEL_ACID1
) and (tag
= GridTagAcid1
) then
2104 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2111 if WordBool(PanelType
and PANEL_ACID2
) and (tag
= GridTagAcid2
) then
2113 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2120 if WordBool(PanelType
and PANEL_STEP
) and (tag
= GridTagStep
) then
2122 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2129 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (tag
= GridTagLift
) then
2131 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2132 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2133 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2134 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2135 g_Collide(X
, Y
, Width
, Height
, gLifts
[a
].X
, gLifts
[a
].Y
, gLifts
[a
].Width
, gLifts
[a
].Height
) then
2142 if WordBool(PanelType
and PANEL_BLOCKMON
)and (tag
= GridTagBlockMon
) then
2144 if ((not b1x3
) or ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64)) and
2145 g_Collide(X
, Y
, Width
, Height
, gBlockMon
[a
].X
, gBlockMon
[a
].Y
, gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2154 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2158 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2160 cctype
: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2163 // slightly different from the old code, but meh...
2164 function checker (obj
: TObject
; tag
: Integer): Boolean;
2169 result
:= false; // don't stop, ever
2170 pan
:= (obj
as TPanel
);
2173 if (tag
= GridTagWater
) then
2175 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2177 result
:= true; // water has highest priority, so stop right here
2178 texid
:= gWater
[a
].GetTextureID();
2183 if (cctype
> 1) and (tag
= GridTagAcid1
) then
2185 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2188 texid
:= gAcid1
[a
].GetTextureID();
2193 if (cctype
> 2) and (tag
= GridTagAcid2
) then
2195 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2198 texid
:= gAcid2
[a
].GetTextureID();
2205 texid
:= TEXTURE_NONE
;
2206 gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, checker
);
2210 procedure g_Map_EnableWall(ID
: DWORD
);
2215 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2217 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2221 procedure g_Map_DisableWall(ID
: DWORD
);
2226 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2228 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2232 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2237 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2240 tp
:= gRenderForegrounds
[ID
];
2242 tp
:= gRenderBackgrounds
[ID
];
2255 tp
.NextTexture(AnimLoop
);
2256 if g_Game_IsServer
and g_Game_IsNet
then
2257 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2260 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2262 if gLifts
[ID
].LiftType
= t
then
2269 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2271 if LiftType
= 0 then
2272 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2273 else if LiftType
= 1 then
2274 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2275 else if LiftType
= 2 then
2276 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2277 else if LiftType
= 3 then
2278 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2280 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2284 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2287 PointsArray
: Array of TRespawnPoint
;
2290 SetLength(PointsArray
, 0);
2292 if RespawnPoints
= nil then
2295 for a
:= 0 to High(RespawnPoints
) do
2296 if RespawnPoints
[a
].PointType
= PointType
then
2298 SetLength(PointsArray
, Length(PointsArray
)+1);
2299 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2302 if PointsArray
= nil then
2305 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2309 function g_Map_GetPointCount(PointType
: Byte): Word;
2315 if RespawnPoints
= nil then
2318 for a
:= 0 to High(RespawnPoints
) do
2319 if RespawnPoints
[a
].PointType
= PointType
then
2320 Result
:= Result
+ 1;
2323 function g_Map_HaveFlagPoints(): Boolean;
2325 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2328 procedure g_Map_ResetFlag(Flag
: Byte);
2330 with gFlags
[Flag
] do
2336 Direction
:= D_LEFT
;
2337 State
:= FLAG_STATE_NONE
;
2338 if FlagPoints
[Flag
] <> nil then
2340 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2341 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2342 Direction
:= FlagPoints
[Flag
]^.Direction
;
2343 State
:= FLAG_STATE_NORMAL
;
2349 procedure g_Map_DrawFlags();
2352 Mirror
: TMirrorType
;
2354 if gGameSettings
.GameMode
<> GM_CTF
then
2357 for i
:= FLAG_RED
to FLAG_BLUE
do
2359 if State
<> FLAG_STATE_CAPTURED
then
2361 if State
= FLAG_STATE_NONE
then
2364 if Direction
= D_LEFT
then
2366 Mirror
:= M_HORIZONTAL
;
2375 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2377 if g_debug_Frames
then
2379 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2381 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2382 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2388 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2395 procedure SavePanelArray(var panels
: TPanelArray
);
2397 PAMem
: TBinMemoryWriter
;
2400 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2401 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2404 while i
< Length(panels
) do
2406 if panels
[i
].SaveIt
then
2410 // Ñîõðàíÿåì ïàíåëü:
2411 panels
[i
].SaveState(PAMem
);
2416 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2417 PAMem
.SaveToMemory(Mem
);
2421 procedure SaveFlag(flag
: PFlag
);
2424 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2426 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2427 Mem
.WriteByte(flag
^.RespawnType
);
2429 Mem
.WriteByte(flag
^.State
);
2430 // Íàïðàâëåíèå ôëàãà:
2431 if flag
^.Direction
= D_LEFT
then
2437 Obj_SaveState(@flag
^.Obj
, Mem
);
2441 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2443 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2444 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2445 SavePanelArray(gWalls
);
2446 // Ñîõðàíÿåì ïàíåëè ôîíà:
2447 SavePanelArray(gRenderBackgrounds
);
2448 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2449 SavePanelArray(gRenderForegrounds
);
2450 // Ñîõðàíÿåì ïàíåëè âîäû:
2451 SavePanelArray(gWater
);
2452 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2453 SavePanelArray(gAcid1
);
2454 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2455 SavePanelArray(gAcid2
);
2456 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2457 SavePanelArray(gSteps
);
2458 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2459 SavePanelArray(gLifts
);
2462 ///// Ñîõðàíÿåì ìóçûêó: /////
2463 // Ñèãíàòóðà ìóçûêè:
2464 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2467 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2468 if gMusic
.NoMusic
then
2472 Mem
.WriteString(str
, 64);
2473 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2474 dw
:= gMusic
.GetPosition();
2476 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2477 boo
:= gMusic
.SpecPause
;
2478 Mem
.WriteBoolean(boo
);
2481 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2482 Mem
.WriteInt(gTotalMonsters
);
2485 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2486 if gGameSettings
.GameMode
= GM_CTF
then
2488 // Ôëàã Êðàñíîé êîìàíäû:
2489 SaveFlag(@gFlags
[FLAG_RED
]);
2490 // Ôëàã Ñèíåé êîìàíäû:
2491 SaveFlag(@gFlags
[FLAG_BLUE
]);
2495 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2496 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2498 // Î÷êè Êðàñíîé êîìàíäû:
2499 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2500 // Î÷êè Ñèíåé êîìàíäû:
2501 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2506 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2513 procedure LoadPanelArray(var panels
: TPanelArray
);
2515 PAMem
: TBinMemoryReader
;
2518 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2519 PAMem
:= TBinMemoryReader
.Create();
2520 PAMem
.LoadFromMemory(Mem
);
2522 for i
:= 0 to Length(panels
)-1 do
2523 if panels
[i
].SaveIt
then
2529 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2531 // Çàãðóæàåì ïàíåëü:
2532 panels
[i
].LoadState(PAMem
);
2535 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2539 procedure LoadFlag(flag
: PFlag
);
2543 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2545 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2547 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2548 Mem
.ReadByte(flag
^.RespawnType
);
2550 Mem
.ReadByte(flag
^.State
);
2551 // Íàïðàâëåíèå ôëàãà:
2554 flag
^.Direction
:= D_LEFT
2556 flag
^.Direction
:= D_RIGHT
;
2558 Obj_LoadState(@flag
^.Obj
, Mem
);
2565 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2566 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2567 LoadPanelArray(gWalls
);
2568 // Çàãðóæàåì ïàíåëè ôîíà:
2569 LoadPanelArray(gRenderBackgrounds
);
2570 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2571 LoadPanelArray(gRenderForegrounds
);
2572 // Çàãðóæàåì ïàíåëè âîäû:
2573 LoadPanelArray(gWater
);
2574 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2575 LoadPanelArray(gAcid1
);
2576 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2577 LoadPanelArray(gAcid2
);
2578 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2579 LoadPanelArray(gSteps
);
2580 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2581 LoadPanelArray(gLifts
);
2584 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2588 ///// Çàãðóæàåì ìóçûêó: /////
2589 // Ñèãíàòóðà ìóçûêè:
2591 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2593 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2596 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2597 Mem
.ReadString(str
);
2598 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2600 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2601 Mem
.ReadBoolean(boo
);
2602 // Çàïóñêàåì ýòó ìóçûêó:
2603 gMusic
.SetByName(str
);
2604 gMusic
.SpecPause
:= boo
;
2607 gMusic
.SetPosition(dw
);
2610 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2611 Mem
.ReadInt(gTotalMonsters
);
2614 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2615 if gGameSettings
.GameMode
= GM_CTF
then
2617 // Ôëàã Êðàñíîé êîìàíäû:
2618 LoadFlag(@gFlags
[FLAG_RED
]);
2619 // Ôëàã Ñèíåé êîìàíäû:
2620 LoadFlag(@gFlags
[FLAG_BLUE
]);
2624 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2625 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2627 // Î÷êè Êðàñíîé êîìàíäû:
2628 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2629 // Î÷êè Ñèíåé êîìàíäû:
2630 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2635 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2640 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2641 Arr
:= PanelByID
[PanelID
].PWhere
^;
2642 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2643 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);