53b4ae2d40986595ee8f6d9e8a6e221c3f3fa8bc
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 // build "potentially visible panels" set, so we can avoid looping over all level panels again and again
67 procedure g_Map_BuildPVP (minx
, miny
, maxx
, maxy
: Integer);
68 procedure g_Map_ResetPVP ();
69 // do not call this without calling `g_Map_BuildPVP()` or `g_Map_ResetPVP()` first!
70 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
72 procedure g_Map_DrawBack(dx
, dy
: Integer);
73 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
74 PanelType
: Word; b1x3
: Boolean): Boolean;
75 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
76 procedure g_Map_EnableWall(ID
: DWORD
);
77 procedure g_Map_DisableWall(ID
: DWORD
);
78 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
79 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
80 procedure g_Map_ReAdd_DieTriggers();
81 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
83 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
84 function g_Map_GetPointCount(PointType
: Byte): Word;
86 function g_Map_HaveFlagPoints(): Boolean;
88 procedure g_Map_ResetFlag(Flag
: Byte);
89 procedure g_Map_DrawFlags();
91 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
93 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
94 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
96 // build "possibly lit panels" index, so we can avoid looping over all level panels again and again
97 function g_Map_BuildPLP (ltminx
, ltminy
, ltmaxx
, ltmaxy
: Integer): Boolean; // returns `false` if no patels lit
98 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
101 RESPAWNPOINT_PLAYER1
= 1;
102 RESPAWNPOINT_PLAYER2
= 2;
104 RESPAWNPOINT_RED
= 4;
105 RESPAWNPOINT_BLUE
= 5;
113 FLAG_STATE_NORMAL
= 1;
114 FLAG_STATE_DROPPED
= 2;
115 FLAG_STATE_CAPTURED
= 3;
116 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
117 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
119 FLAG_TIME
= 720; // 20 seconds
121 SKY_STRETCH
: Single = 1.5;
125 gRenderBackgrounds
: TPanelArray
;
126 gRenderForegrounds
: TPanelArray
;
127 gWater
, gAcid1
, gAcid2
: TPanelArray
;
130 gBlockMon
: TPanelArray
;
131 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
132 //gDOMFlags: array of TFlag;
135 gDoorMap
: array of array of DWORD
;
136 gLiftMap
: array of array of DWORD
;
137 gWADHash
: TMD5Digest
;
138 BackID
: DWORD
= DWORD(-1);
139 gExternalResources
: TStringList
;
140 gMapGrid
: TBodyGrid
= nil;
145 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
146 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
147 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
148 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
150 ImagingTypes
, Imaging
, ImagingUtility
,
151 ImagingGif
, ImagingNetworkGraphics
;
154 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
155 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
156 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
160 PWhere
: ^TPanelArray
;
165 PanelById
: array of TPanelID
;
166 Textures
: TLevelTextureArray
;
167 RespawnPoints
: Array of TRespawnPoint
;
168 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
169 //DOMFlagPoints: Array of TFlagPoint;
172 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
174 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
175 (Texture
= TEXTURE_NAME_ACID1
) or
176 (Texture
= TEXTURE_NAME_ACID2
);
179 procedure CreateDoorMap();
181 PanelArray
: Array of record
187 a
, b
, c
, m
, i
, len
: Integer;
195 SetLength(PanelArray
, len
);
197 for a
:= 0 to High(gWalls
) do
198 if gWalls
[a
].Door
then
200 PanelArray
[i
].X
:= gWalls
[a
].X
;
201 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
202 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
203 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
204 PanelArray
[i
].Active
:= True;
205 PanelArray
[i
].PanelID
:= a
;
211 SetLength(PanelArray
, len
);
222 SetLength(gDoorMap
, 0);
224 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
227 if PanelArray
[a
].Active
then
229 PanelArray
[a
].Active
:= False;
230 m
:= Length(gDoorMap
);
231 SetLength(gDoorMap
, m
+1);
232 SetLength(gDoorMap
[m
], 1);
233 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
241 if PanelArray
[b
].Active
then
242 for c
:= 0 to High(gDoorMap
[m
]) do
243 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
244 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
245 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
246 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
247 gWalls
[gDoorMap
[m
, c
]].X
,
248 gWalls
[gDoorMap
[m
, c
]].Y
,
249 gWalls
[gDoorMap
[m
, c
]].Width
,
250 gWalls
[gDoorMap
[m
, c
]].Height
) then
252 PanelArray
[b
].Active
:= False;
253 SetLength(gDoorMap
[m
],
254 Length(gDoorMap
[m
])+1);
255 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
261 g_Game_StepLoading();
267 procedure CreateLiftMap();
269 PanelArray
: Array of record
274 a
, b
, c
, len
, i
, j
: Integer;
280 len
:= Length(gLifts
);
281 SetLength(PanelArray
, len
);
283 for a
:= 0 to len
-1 do
285 PanelArray
[a
].X
:= gLifts
[a
].X
;
286 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
287 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
288 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
289 PanelArray
[a
].Active
:= True;
292 SetLength(gLiftMap
, len
);
295 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
297 for a
:= 0 to len
-1 do
298 if PanelArray
[a
].Active
then
300 PanelArray
[a
].Active
:= False;
301 SetLength(gLiftMap
[i
], 32);
309 for b
:= 0 to len
-1 do
310 if PanelArray
[b
].Active
then
312 if g_CollideAround(PanelArray
[b
].X
,
315 PanelArray
[b
].Height
,
316 PanelArray
[gLiftMap
[i
, c
]].X
,
317 PanelArray
[gLiftMap
[i
, c
]].Y
,
318 PanelArray
[gLiftMap
[i
, c
]].Width
,
319 PanelArray
[gLiftMap
[i
, c
]].Height
) then
321 PanelArray
[b
].Active
:= False;
323 if j
> High(gLiftMap
[i
]) then
324 SetLength(gLiftMap
[i
],
325 Length(gLiftMap
[i
])+32);
334 SetLength(gLiftMap
[i
], j
+1);
337 g_Game_StepLoading();
340 SetLength(gLiftMap
, i
);
345 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
346 CurTex
: Integer; sav
: Boolean): Integer;
349 panels
: ^TPanelArray
;
353 case PanelRec
.PanelType
of
354 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
357 panels
:= @gRenderBackgrounds
;
359 panels
:= @gRenderForegrounds
;
368 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
371 panels
:= @gBlockMon
;
376 len
:= Length(panels
^);
377 SetLength(panels
^, len
+ 1);
379 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
, CurTex
, Textures
);
380 panels
^[len
].ArrIdx
:= len
;
382 panels
^[len
].SaveIt
:= True;
386 len
:= Length(PanelByID
);
387 SetLength(PanelByID
, len
+ 1);
388 PanelByID
[len
].PWhere
:= panels
;
389 PanelByID
[len
].PArrID
:= Result
;
392 function CreateNullTexture(RecName
: String): Integer;
394 SetLength(Textures
, Length(Textures
)+1);
395 result
:= High(Textures
);
397 with Textures
[High(Textures
)] do
399 TextureName
:= RecName
;
403 TextureID
:= TEXTURE_NONE
;
407 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
410 TextureData
: Pointer;
411 WADName
, txname
: String;
412 a
, ResLength
: Integer;
416 if Textures
<> nil then
417 for a
:= 0 to High(Textures
) do
418 if Textures
[a
].TextureName
= RecName
then
419 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
424 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
425 if (RecName
= TEXTURE_NAME_WATER
) or
426 (RecName
= TEXTURE_NAME_ACID1
) or
427 (RecName
= TEXTURE_NAME_ACID2
) then
429 SetLength(Textures
, Length(Textures
)+1);
431 with Textures
[High(Textures
)] do
433 TextureName
:= RecName
;
435 if TextureName
= TEXTURE_NAME_WATER
then
436 TextureID
:= TEXTURE_SPECIAL_WATER
438 if TextureName
= TEXTURE_NAME_ACID1
then
439 TextureID
:= TEXTURE_SPECIAL_ACID1
441 if TextureName
= TEXTURE_NAME_ACID2
then
442 TextureID
:= TEXTURE_SPECIAL_ACID2
;
447 result
:= High(Textures
);
451 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
452 WADName
:= g_ExtractWadName(RecName
);
454 WAD
:= TWADFile
.Create();
456 if WADName
<> '' then
457 WADName
:= GameDir
+'/wads/'+WADName
461 WAD
.ReadFile(WADName
);
465 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
467 FreeMem(TextureData);
468 RecName := 'COMMON\ALIEN';
472 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
474 SetLength(Textures
, Length(Textures
)+1);
475 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
477 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
478 @Textures
[High(Textures
)].Width
,
479 @Textures
[High(Textures
)].Height
);
480 FreeMem(TextureData
);
481 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
482 Textures
[High(Textures
)].Anim
:= False;
484 result
:= High(Textures
);
486 else // Íåò òàêîãî ðåóñðñà â WAD'å
488 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
491 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
492 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
499 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
502 TextureWAD
: PChar = nil;
503 TextData
: Pointer = nil;
504 TextureData
: Pointer = nil;
508 TextureResource
: String;
509 _width
, _height
, _framecount
, _speed
: Integer;
510 _backanimation
: Boolean;
512 ia
: TDynImageDataArray
= nil;
513 f
, c
, frdelay
, frloop
: Integer;
517 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
519 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
520 WADName
:= g_ExtractWadName(RecName
);
522 WAD
:= TWADFile
.Create();
524 if WADName
<> '' then
525 WADName
:= GameDir
+'/wads/'+WADName
529 WAD
.ReadFile(WADName
);
531 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
535 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
536 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
542 if WADName = Map then
544 //FreeMem(TextureWAD);
545 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
551 if ResLength
< 6 then
553 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
557 // ýòî ïòèöà? ýòî ñàìîë¸ò?
558 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
559 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
561 // íåò, ýòî ñóïåðìåí!
562 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
564 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
568 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
569 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
571 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
575 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
577 TextureResource
:= cfg
.ReadStr('', 'resource', '');
578 if TextureResource
= '' then
580 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
584 _width
:= cfg
.ReadInt('', 'framewidth', 0);
585 _height
:= cfg
.ReadInt('', 'frameheight', 0);
586 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
587 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
588 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
593 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
594 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
596 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
603 SetLength(Textures
, Length(Textures
)+1);
604 with Textures
[High(Textures
)] do
606 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
607 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
609 TextureName
:= RecName
;
613 FramesCount
:= _framecount
;
615 result
:= High(Textures
);
619 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
625 // try animated image
627 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
628 if length(imgfmt) = 0 then
630 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
634 GlobalMetadata
.ClearMetaItems();
635 GlobalMetadata
.ClearMetaItemsForSaving();
636 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
638 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
641 if length(ia
) = 0 then
643 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
650 _width
:= ia
[0].width
;
651 _height
:= ia
[0].height
;
652 _framecount
:= length(ia
);
654 _backanimation
:= false;
657 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
659 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
661 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
663 if f
< 0 then f
:= 0;
666 if c
< 13 then c
:= 0 else c
:= 1;
668 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
673 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
675 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
677 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
679 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
683 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
684 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
685 f
:= ord(_backanimation
);
686 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
);
688 SetLength(Textures
, Length(Textures
)+1);
689 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
690 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
692 Textures
[High(Textures
)].TextureName
:= RecName
;
693 Textures
[High(Textures
)].Width
:= _width
;
694 Textures
[High(Textures
)].Height
:= _height
;
695 Textures
[High(Textures
)].Anim
:= True;
696 Textures
[High(Textures
)].FramesCount
:= length(ia
);
697 Textures
[High(Textures
)].Speed
:= _speed
;
698 result
:= High(Textures
);
699 //writeln(' CREATED!');
703 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
707 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
710 if TextureWAD
<> nil then FreeMem(TextureWAD
);
711 if TextData
<> nil then FreeMem(TextData
);
712 if TextureData
<> nil then FreeMem(TextureData
);
716 procedure CreateItem(Item
: TItemRec_1
);
718 if g_Game_IsClient
then Exit
;
720 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
721 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
724 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
725 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
728 procedure CreateArea(Area
: TAreaRec_1
);
733 case Area
.AreaType
of
734 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
735 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
737 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
738 with RespawnPoints
[High(RespawnPoints
)] do
742 Direction
:= TDirection(Area
.Direction
);
744 case Area
.AreaType
of
745 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
746 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
747 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
748 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
749 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
754 AREA_REDFLAG
, AREA_BLUEFLAG
:
756 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
758 if FlagPoints
[a
] <> nil then Exit
;
762 with FlagPoints
[a
]^ do
764 X
:= Area
.X
-FLAGRECT
.X
;
765 Y
:= Area
.Y
-FLAGRECT
.Y
;
766 Direction
:= TDirection(Area
.Direction
);
772 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
773 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
776 Animation
:= TAnimation
.Create(id
, True, 8);
777 Obj
.Rect
:= FLAGRECT
;
785 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
786 with DOMFlagPoints[High(DOMFlagPoints)] do
790 Direction := TDirection(Area.Direction);
793 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
798 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
802 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
808 Width
:= Trigger
.Width
;
809 Height
:= Trigger
.Height
;
810 Enabled
:= ByteBool(Trigger
.Enabled
);
811 TexturePanel
:= Trigger
.TexturePanel
;
812 TexturePanelType
:= fTexturePanel1Type
;
813 ShotPanelType
:= fTexturePanel2Type
;
814 TriggerType
:= Trigger
.TriggerType
;
815 ActivateType
:= Trigger
.ActivateType
;
816 Keys
:= Trigger
.Keys
;
817 Data
.Default
:= Trigger
.DATA
;
820 g_Triggers_Create(_trigger
);
823 procedure CreateMonster(monster
: TMonsterRec_1
);
827 if g_Game_IsClient
then Exit
;
829 if (gGameSettings
.GameType
= GT_SINGLE
)
830 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
832 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
833 TDirection(monster
.Direction
));
835 if gTriggers
<> nil then
836 for a
:= 0 to High(gTriggers
) do
837 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
838 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
839 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
840 gMonsters
[i
].AddTrigger(a
);
842 if monster
.MonsterType
<> MONSTER_BARREL
then
847 procedure g_Map_ReAdd_DieTriggers();
851 if g_Game_IsClient
then Exit
;
853 for i
:= 0 to High(gMonsters
) do
854 if gMonsters
[i
] <> nil then
856 gMonsters
[i
].ClearTriggers();
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
);
866 function extractWadName(resourceName
: string): string;
870 posN
:= Pos(':', resourceName
);
872 Result
:= Copy(resourceName
, 0, posN
-1)
877 procedure addResToExternalResList(res
: string);
879 res
:= extractWadName(res
);
880 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
881 gExternalResources
.Add(res
);
884 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
886 textures
: TTexturesRec1Array
;
887 mapHeader
: TMapHeaderRec_1
;
889 resFile
: String = '';
891 if gExternalResources
= nil then
892 gExternalResources
:= TStringList
.Create
;
894 gExternalResources
.Clear
;
895 textures
:= mapReader
.GetTextures();
896 for i
:= 0 to High(textures
) do
898 addResToExternalResList(resFile
);
903 mapHeader
:= mapReader
.GetMapHeader
;
905 addResToExternalResList(mapHeader
.MusicName
);
906 addResToExternalResList(mapHeader
.SkyName
);
909 function g_Map_Load(Res
: String): Boolean;
911 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
912 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
915 MapReader
: TMapReader_1
;
916 Header
: TMapHeaderRec_1
;
917 _textures
: TTexturesRec1Array
;
918 _texnummap
: array of Integer; // `_textures` -> `Textures`
919 panels
: TPanelsRec1Array
;
920 items
: TItemsRec1Array
;
921 monsters
: TMonsterRec1Array
;
922 areas
: TAreasRec1Array
;
923 triggers
: TTriggersRec1Array
;
926 AddTextures
: TAddTextureArray
;
927 texture
: TTextureRec_1
;
928 TriggersTable
: Array of record
929 TexturePanel
: Integer;
934 FileName
, mapResName
, s
, TexName
: String;
937 ok
, isAnim
, trigRef
: Boolean;
938 CurTex
, ntn
: Integer;
940 mapX0
: Integer = $3fffffff;
941 mapY0
: Integer = $3fffffff;
942 mapX1
: Integer = -$3fffffff;
943 mapY1
: Integer = -$3fffffff;
945 procedure fixMinMax (var panels
: TPanelArray
);
949 for idx
:= 0 to High(panels
) do
951 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
952 if mapX0
> panels
[idx
].X
then mapX0
:= panels
[idx
].X
;
953 if mapY0
> panels
[idx
].Y
then mapY0
:= panels
[idx
].Y
;
954 if mapX1
< panels
[idx
].X
+panels
[idx
].Width
-1 then mapX1
:= panels
[idx
].X
+panels
[idx
].Width
-1;
955 if mapY1
< panels
[idx
].Y
+panels
[idx
].Height
-1 then mapY1
:= panels
[idx
].Y
+panels
[idx
].Height
-1;
959 procedure addPanelsToGrid (var panels
: TPanelArray
; tag
: Integer);
963 for idx
:= High(panels
) downto 0 do
965 gMapGrid
.insertBody(panels
[idx
], panels
[idx
].X
, panels
[idx
].Y
, panels
[idx
].Width
, panels
[idx
].Height
, tag
);
975 TriggersTable
:= nil;
976 FillChar(texture
, SizeOf(texture
), 0);
978 sfsGCDisable(); // temporary disable removing of temporary volumes
981 FileName
:= g_ExtractWadName(Res
);
982 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
983 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
985 WAD
:= TWADFile
.Create();
986 if not WAD
.ReadFile(FileName
) then
988 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
992 //k8: why loader ignores path here?
993 mapResName
:= g_ExtractFileName(Res
);
994 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
996 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
1004 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
1005 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
1006 MapReader
:= TMapReader_1
.Create();
1008 if not MapReader
.LoadMap(Data
) then
1010 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
1017 generateExternalResourcesList(MapReader
);
1018 // Çàãðóçêà òåêñòóð:
1019 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
1020 _textures
:= MapReader
.GetTextures();
1023 // Äîáàâëåíèå òåêñòóð â Textures[]:
1024 if _textures
<> nil then
1026 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
1027 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
1028 SetLength(_texnummap
, length(_textures
));
1030 for a
:= 0 to High(_textures
) do
1033 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
1034 for b
:= 1 to Length(s
) do
1040 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
1041 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1042 // Àíèìèðîâàííàÿ òåêñòóðà:
1043 if ByteBool(_textures
[a
].Anim
) then
1045 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
1048 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
1049 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1052 else // Îáû÷íàÿ òåêñòóðà:
1053 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
1056 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
1057 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
1060 _texnummap
[a
] := ntn
; // fix texture number
1061 g_Game_StepLoading();
1065 // Çàãðóçêà òðèããåðîâ:
1066 gTriggerClientID
:= 0;
1067 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1068 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
1069 triggers
:= MapReader
.GetTriggers();
1071 // Çàãðóçêà ïàíåëåé:
1072 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1073 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1074 panels
:= MapReader
.GetPanels();
1076 // check texture numbers for panels
1077 for a
:= 0 to High(panels
) do
1079 if panels
[a
].TextureNum
> High(_textures
) then
1081 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1085 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1088 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1089 if triggers
<> nil then
1091 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1092 SetLength(TriggersTable
, Length(triggers
));
1093 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1095 for a
:= 0 to High(TriggersTable
) do
1097 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1098 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1100 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1101 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1103 TriggersTable
[a
].LiftPanel
:= -1;
1105 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1106 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1107 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1108 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1110 TriggersTable
[a
].DoorPanel
:= -1;
1112 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1113 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1115 TriggersTable
[a
].ShotPanel
:= -1;
1117 g_Game_StepLoading();
1122 if panels
<> nil then
1124 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1125 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1127 for a
:= 0 to High(panels
) do
1129 SetLength(AddTextures
, 0);
1132 if _textures
<> nil then
1134 texture
:= _textures
[panels
[a
].TextureNum
];
1142 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1143 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1145 if (TriggersTable
<> nil) and (_textures
<> nil) then
1146 for b
:= 0 to High(TriggersTable
) do
1147 if (TriggersTable
[b
].TexturePanel
= a
)
1148 or (TriggersTable
[b
].ShotPanel
= a
) then
1157 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1159 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1162 for c
:= Len
downto 1 do
1170 // Ñïåö-òåêñòóðû çàïðåùåíû:
1171 if g_Map_IsSpecialTexture(s
) then
1174 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1175 ok
:= g_Texture_NumNameFindStart(s
);
1177 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1178 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1181 k
:= NNF_NAME_BEFORE
;
1182 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1183 while ok
or (k
= NNF_NAME_BEFORE
) or
1184 (k
= NNF_NAME_EQUALS
) do
1186 k
:= g_Texture_NumNameFindNext(TexName
);
1188 if (k
= NNF_NAME_BEFORE
) or
1189 (k
= NNF_NAME_AFTER
) then
1191 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1192 if ByteBool(texture
.Anim
) then
1193 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1195 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1197 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1199 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1203 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1205 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1207 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1209 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1213 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1216 for c
:= 0 to High(Textures
) do
1217 if Textures
[c
].TextureName
= TexName
then
1219 SetLength(AddTextures
, Length(AddTextures
)+1);
1220 AddTextures
[High(AddTextures
)].Texture
:= c
;
1221 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1227 if k
= NNF_NAME_EQUALS
then
1229 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1230 SetLength(AddTextures
, Length(AddTextures
)+1);
1231 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1232 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1233 CurTex
:= High(AddTextures
);
1241 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1242 end; // if ok - ññûëàþòñÿ òðèããåðû
1246 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1247 SetLength(AddTextures
, 1);
1248 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1249 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1253 //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);
1255 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1256 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1258 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1259 if TriggersTable
<> nil then
1260 for b
:= 0 to High(TriggersTable
) do
1262 // Òðèããåð äâåðè/ëèôòà:
1263 if (TriggersTable
[b
].LiftPanel
= a
) or
1264 (TriggersTable
[b
].DoorPanel
= a
) then
1265 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1266 // Òðèããåð ñìåíû òåêñòóðû:
1267 if TriggersTable
[b
].TexturePanel
= a
then
1268 triggers
[b
].TexturePanel
:= PanelID
;
1269 // Òðèããåð "Òóðåëü":
1270 if TriggersTable
[b
].ShotPanel
= a
then
1271 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1274 g_Game_StepLoading();
1278 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1279 if (triggers
<> nil) and not gLoadGameMode
then
1281 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1282 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1283 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1284 for a
:= 0 to High(triggers
) do
1286 if triggers
[a
].TexturePanel
<> -1 then
1287 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1290 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1291 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1292 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1295 CreateTrigger(triggers
[a
], b
, c
);
1299 // Çàãðóçêà ïðåäìåòîâ:
1300 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1301 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1302 items
:= MapReader
.GetItems();
1304 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1305 if (items
<> nil) and not gLoadGameMode
then
1307 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1308 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1309 for a
:= 0 to High(items
) do
1310 CreateItem(Items
[a
]);
1313 // Çàãðóçêà îáëàñòåé:
1314 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1315 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1316 areas
:= MapReader
.GetAreas();
1318 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1319 if areas
<> nil then
1321 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1322 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1323 for a
:= 0 to High(areas
) do
1324 CreateArea(areas
[a
]);
1327 // Çàãðóçêà ìîíñòðîâ:
1328 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1329 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1330 monsters
:= MapReader
.GetMonsters();
1332 gTotalMonsters
:= 0;
1334 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1335 if (monsters
<> nil) and not gLoadGameMode
then
1337 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1338 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1339 for a
:= 0 to High(monsters
) do
1340 CreateMonster(monsters
[a
]);
1343 // Çàãðóçêà îïèñàíèÿ êàðòû:
1344 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1345 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1346 Header
:= MapReader
.GetMapHeader();
1352 Name
:= Header
.MapName
;
1353 Description
:= Header
.MapDescription
;
1354 Author
:= Header
.MapAuthor
;
1355 MusicName
:= Header
.MusicName
;
1356 SkyName
:= Header
.SkyName
;
1357 Height
:= Header
.Height
;
1358 Width
:= Header
.Width
;
1362 if gMapInfo
.SkyName
<> '' then
1364 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1365 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1366 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1368 if FileName
<> '' then
1369 FileName
:= GameDir
+'/wads/'+FileName
1372 FileName
:= g_ExtractWadName(Res
);
1375 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1376 if g_Texture_CreateWAD(BackID
, s
) then
1378 g_Game_SetupScreenSize();
1381 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1386 if gMapInfo
.MusicName
<> '' then
1388 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1389 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1390 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1392 if FileName
<> '' then
1393 FileName
:= GameDir
+'/wads/'+FileName
1396 FileName
:= g_ExtractWadName(Res
);
1399 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1400 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1403 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1406 // Îñòàëüíûå óñòàíâêè:
1414 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1415 if not gLoadGameMode
then
1418 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1424 TriggersTable
:= nil;
1427 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1428 if ok
and (not gLoadGameMode
) then
1430 gMusic
.SetByName(gMapInfo
.MusicName
);
1434 gMusic
.SetByName('');
1436 sfsGCEnable(); // enable releasing unused volumes
1439 e_WriteLog('Creating map grid', MSG_NOTIFY
);
1442 fixMinMax(gRenderBackgrounds
);
1443 fixMinMax(gRenderForegrounds
);
1449 gMapGrid
:= TBodyGrid
.Create(mapX1
+1, mapY1
+1);
1451 addPanelsToGrid(gWalls
, PANEL_WALL
); // and PANEL_CLOSEDOOR
1452 addPanelsToGrid(gRenderBackgrounds
, PANEL_BACK
);
1453 addPanelsToGrid(gRenderForegrounds
, PANEL_FORE
);
1454 addPanelsToGrid(gWater
, PANEL_WATER
);
1455 addPanelsToGrid(gAcid1
, PANEL_ACID1
);
1456 addPanelsToGrid(gAcid2
, PANEL_ACID2
);
1457 addPanelsToGrid(gSteps
, PANEL_STEP
);
1459 gMapGrid
.dumpStats();
1461 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1465 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1468 MapReader
: TMapReader_1
;
1469 Header
: TMapHeaderRec_1
;
1474 FillChar(Result
, SizeOf(Result
), 0);
1475 FileName
:= g_ExtractWadName(Res
);
1477 WAD
:= TWADFile
.Create();
1478 if not WAD
.ReadFile(FileName
) then
1484 //k8: it ignores path again
1485 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1493 MapReader
:= TMapReader_1
.Create();
1495 if not MapReader
.LoadMap(Data
) then
1497 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1498 ZeroMemory(@Header
, SizeOf(Header
));
1499 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1500 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1504 Header
:= MapReader
.GetMapHeader();
1505 Result
.Name
:= Header
.MapName
;
1506 Result
.Description
:= Header
.MapDescription
;
1513 Result
.Author
:= Header
.MapAuthor
;
1514 Result
.Height
:= Header
.Height
;
1515 Result
.Width
:= Header
.Width
;
1518 function g_Map_GetMapsList(WADName
: string): SArray
;
1525 WAD
:= TWADFile
.Create();
1526 if not WAD
.ReadFile(WADName
) then
1531 ResList
:= WAD
.GetMapResources();
1532 if ResList
<> nil then
1534 for a
:= 0 to High(ResList
) do
1536 SetLength(Result
, Length(Result
)+1);
1537 Result
[High(Result
)] := ResList
[a
];
1543 function g_Map_Exist(Res
: string): Boolean;
1546 FileName
, mnn
: string;
1552 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1554 WAD
:= TWADFile
.Create
;
1555 if not WAD
.ReadFile(FileName
) then
1561 ResList
:= WAD
.GetMapResources();
1564 mnn
:= g_ExtractFileName(Res
);
1565 if ResList
<> nil then
1566 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1573 procedure g_Map_Free();
1577 procedure FreePanelArray(var panels
: TPanelArray
);
1582 if panels
<> nil then
1584 for i
:= 0 to High(panels
) do
1597 RespawnPoints
:= nil;
1598 if FlagPoints
[FLAG_RED
] <> nil then
1600 Dispose(FlagPoints
[FLAG_RED
]);
1601 FlagPoints
[FLAG_RED
] := nil;
1603 if FlagPoints
[FLAG_BLUE
] <> nil then
1605 Dispose(FlagPoints
[FLAG_BLUE
]);
1606 FlagPoints
[FLAG_BLUE
] := nil;
1608 //DOMFlagPoints := nil;
1612 if Textures
<> nil then
1614 for a
:= 0 to High(Textures
) do
1615 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1616 if Textures
[a
].Anim
then
1617 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1619 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1620 e_DeleteTexture(Textures
[a
].TextureID
);
1625 FreePanelArray(gWalls
);
1626 FreePanelArray(gRenderBackgrounds
);
1627 FreePanelArray(gRenderForegrounds
);
1628 FreePanelArray(gWater
);
1629 FreePanelArray(gAcid1
);
1630 FreePanelArray(gAcid2
);
1631 FreePanelArray(gSteps
);
1632 FreePanelArray(gLifts
);
1633 FreePanelArray(gBlockMon
);
1635 if BackID
<> DWORD(-1) then
1639 e_DeleteTexture(BackID
);
1640 BackID
:= DWORD(-1);
1643 g_Game_StopAllSounds(False);
1645 g_Sound_Delete(gMapInfo
.MusicName
);
1647 gMapInfo
.Name
:= '';
1648 gMapInfo
.Description
:= '';
1649 gMapInfo
.MusicName
:= '';
1650 gMapInfo
.Height
:= 0;
1651 gMapInfo
.Width
:= 0;
1659 procedure g_Map_Update();
1665 procedure UpdatePanelArray(var panels
: TPanelArray
);
1670 if panels
<> nil then
1671 for i
:= 0 to High(panels
) do
1676 UpdatePanelArray(gWalls
);
1677 UpdatePanelArray(gRenderBackgrounds
);
1678 UpdatePanelArray(gRenderForegrounds
);
1679 UpdatePanelArray(gWater
);
1680 UpdatePanelArray(gAcid1
);
1681 UpdatePanelArray(gAcid2
);
1682 UpdatePanelArray(gSteps
);
1684 if gGameSettings
.GameMode
= GM_CTF
then
1686 for a
:= FLAG_RED
to FLAG_BLUE
do
1687 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1690 if gFlags
[a
].Animation
<> nil then
1691 gFlags
[a
].Animation
.Update();
1693 m
:= g_Obj_Move(@Obj
, True, True);
1695 if gTime
mod (GAME_TICK
*2) <> 0 then
1698 // Ñîïðîòèâëåíèå âîçäóõà:
1699 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1701 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1702 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1705 gFlags
[a
].CaptureTime
:= 0;
1706 if a
= FLAG_RED
then
1707 s
:= _lc
[I_PLAYER_FLAG_RED
]
1709 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1710 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1712 if g_Game_IsNet
then
1713 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1720 // Èãðîê áåðåò ôëàã:
1721 if gPlayers
<> nil then
1723 j
:= Random(Length(gPlayers
)) - 1;
1725 for d
:= 0 to High(gPlayers
) do
1728 if j
> High(gPlayers
) then
1731 if gPlayers
[j
] <> nil then
1732 if gPlayers
[j
].Live
and
1733 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1735 if gPlayers
[j
].GetFlag(a
) then
1746 pvpset
: array of TPanel
= nil; // potentially lit panels
1747 pvpb
, pvpe
: array [0..7] of Integer; // start/end (inclusive) of the correspoinding type panels in pvpset
1748 pvpcount
: Integer = -1; // to avoid constant reallocations
1750 function pvpType (panelType
: Word): Integer;
1753 PANEL_WALL
, PANEL_CLOSEDOOR
: result
:= 0; // gWalls
1754 PANEL_BACK
: result
:= 1; // gRenderBackgrounds
1755 PANEL_FORE
: result
:= 2; // gRenderForegrounds
1756 PANEL_WATER
: result
:= 3; // gWater
1757 PANEL_ACID1
: result
:= 4; // gAcid1
1758 PANEL_ACID2
: result
:= 5; // gAcid2
1759 PANEL_STEP
: result
:= 6; // gSteps
1764 procedure g_Map_ResetPVP ();
1766 pvpcount
:= -1; // special
1769 procedure g_Map_BuildPVP (minx
, miny
, maxx
, maxy
: Integer);
1774 procedure checkPanels (var panels
: TPanelArray
; stp
: Integer);
1776 idx
, x
, y
, w
, h
: Integer;
1778 if panels
= nil then exit
;
1779 tpc
:= tpc
+Length(panels
);
1780 if (stp
< 0) or (stp
> 6) then exit
;
1781 pvpb
[stp
] := pvpcount
;
1782 for idx
:= 0 to High(panels
) do
1784 w
:= panels
[idx
].Width
;
1785 h
:= panels
[idx
].Height
;
1786 if (w
< 1) or (h
< 1) then continue
;
1789 if (x
> maxx
) or (y
> maxy
) then continue
;
1790 if (x
+w
<= minx
) or (y
+h
<= miny
) then continue
;
1791 if pvpcount
= length(pvpset
) then SetLength(pvpset
, pvpcount
+32768);
1792 pvpset
[pvpcount
] := panels
[idx
];
1795 pvpe
[stp
] := pvpcount
-1;
1799 //e_WriteLog(Format('visible rect: (%d,%d)-(%d,%d)', [minx, miny, maxx, maxy]), MSG_NOTIFY);
1801 for idx
:= 0 to High(pvpb
) do begin pvpb
[idx
] := 0; pvpe
[idx
] := -1; end;
1803 checkPanels(gWalls
, 0);
1804 checkPanels(gRenderBackgrounds
, 1);
1805 checkPanels(gRenderForegrounds
, 2);
1806 checkPanels(gWater
, 3);
1807 checkPanels(gAcid1
, 4);
1808 checkPanels(gAcid2
, 5);
1809 checkPanels(gSteps
, 6);
1810 //e_WriteLog(Format('total panels: %d; visible panels: %d', [tpc, pvpcount]), MSG_NOTIFY);
1813 procedure g_Map_DrawPanelsOld(PanelType
: Word);
1815 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1819 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1821 if pvpcount
< 0 then
1823 // alas, no visible set
1824 for idx
:= 0 to High(panels
) do
1826 if not (drawDoors
xor panels
[idx
].Door
) then panels
[idx
].Draw();
1831 // wow, use visible set
1832 if pvpb
[stp
] <= pvpe
[stp
] then
1834 for idx
:= pvpb
[stp
] to pvpe
[stp
] do
1836 if not (drawDoors
xor pvpset
[idx
].Door
) then pvpset
[idx
].Draw();
1845 PANEL_WALL
: DrawPanels(0, gWalls
);
1846 PANEL_CLOSEDOOR
: DrawPanels(0, gWalls
, True);
1847 PANEL_BACK
: DrawPanels(1, gRenderBackgrounds
);
1848 PANEL_FORE
: DrawPanels(2, gRenderForegrounds
);
1849 PANEL_WATER
: DrawPanels(3, gWater
);
1850 PANEL_ACID1
: DrawPanels(4, gAcid1
);
1851 PANEL_ACID2
: DrawPanels(5, gAcid2
);
1852 PANEL_STEP
: DrawPanels(6, gSteps
);
1858 gDrawPanelList
: TBinaryHeapObj
= nil;
1860 function dplLess (a
, b
: TObject
): Boolean;
1862 result
:= ((a
as TPanel
).ArrIdx
< (b
as TPanel
).ArrIdx
);
1865 procedure dplClear ();
1867 if gDrawPanelList
= nil then gDrawPanelList
:= TBinaryHeapObj
.Create(@dplLess
) else gDrawPanelList
.clear();
1870 procedure dplAddPanel (pan
: TPanel
);
1872 if pan
= nil then exit
;
1873 gDrawPanelList
.insert(pan
);
1877 procedure g_Map_DrawPanels(x0
, y0
, wdt
, hgt
: Integer; PanelType
: Word);
1879 function qq (obj
: TObject
; tag
: Integer): Boolean;
1883 result
:= false; // don't stop, ever
1885 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1889 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1891 if not (obj
is TPanel
) then
1893 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
1896 //pan := (obj as TPanel);
1897 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1899 if (tag
= PANEL_WALL
) then
1901 if (PanelType
= PANEL_WALL
) then
1903 pan
:= (obj
as TPanel
);
1904 if not pan
.Door
then
1906 //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);
1910 else if (PanelType
= PANEL_CLOSEDOOR
) then
1912 pan
:= (obj
as TPanel
);
1915 //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);
1920 else if (PanelType
= tag
) then
1922 pan
:= (obj
as TPanel
);
1923 if not pan
.Door
then
1925 //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);
1931 procedure DrawPanels (stp
: Integer; var panels
: TPanelArray
; drawDoors
: Boolean=False);
1936 if (panels
<> nil) and (stp
>= 0) and (stp
<= 6) then
1938 if pvpcount
< 0 then
1940 // alas, no visible set
1941 for idx
:= 0 to High(panels
) do
1943 if not (drawDoors
xor panels
[idx
].Door
) then
1946 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
);
1952 // wow, use visible set
1953 if pvpb
[stp
] <= pvpe
[stp
] then
1955 for idx
:= pvpb
[stp
] to pvpe
[stp
] do
1957 if not (drawDoors
xor pvpset
[idx
].Door
) then
1960 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
);
1969 //g_Map_DrawPanelsOld(PanelType); exit;
1970 //e_WriteLog('==================', MSG_NOTIFY);
1971 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1973 gMapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, qq
);
1977 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1979 PANEL_WALL: DrawPanels(0, gWalls);
1980 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1981 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1982 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1983 PANEL_WATER: DrawPanels(3, gWater);
1984 PANEL_ACID1: DrawPanels(4, gAcid1);
1985 PANEL_ACID2: DrawPanels(5, gAcid2);
1986 PANEL_STEP: DrawPanels(6, gSteps);
1988 e_WriteLog('==================', MSG_NOTIFY);
1991 // sort and draw the list (we need to sort it, or rendering is fucked)
1992 while gDrawPanelList
.count
> 0 do
1994 (gDrawPanelList
.front() as TPanel
).Draw();
1995 gDrawPanelList
.popFront();
2000 plpset
: array of Integer = nil; // potentially lit panels
2001 plpcount
: Integer; // to avoid constant reallocations
2003 function g_Map_BuildPLP (ltminx
, ltminy
, ltmaxx
, ltmaxy
: Integer): Boolean;
2006 panels
: TPanelArray
;
2010 if (ltminx
< ltmaxx
) and (ltminy
< ltmaxy
) then
2012 if panels
<> nil then
2014 for idx
:= 0 to High(panels
) do
2016 if (panels
[idx
].Width
< 1) or (panels
[idx
].Height
< 1) then continue
;
2017 if (panels
[idx
].X
+panels
[idx
].Width
<= ltminx
) then continue
;
2018 if (panels
[idx
].Y
+panels
[idx
].Height
<= ltminy
) then continue
;
2019 if (panels
[idx
].X
> ltmaxx
) then continue
;
2020 if (panels
[idx
].Y
> ltmaxy
) then continue
;
2021 if plpcount
= length(plpset
) then SetLength(plpset
, plpcount
+32768);
2022 plpset
[plpcount
] := idx
;
2025 //e_WriteLog(Format('%d panels left out of %d', [plpcount, Length(panels)]), MSG_NOTIFY);
2028 result
:= (plpcount
> 0);
2031 procedure g_Map_DrawPanelShadowVolumes(lightX
: Integer; lightY
: Integer; radius
: Integer);
2034 procedure drawPanels (var panels: TPanelArray);
2038 if panels <> nil then
2040 for a := 0 to High(panels) do
2042 panels[a].DrawShadowVolume(lightX, lightY, radius);
2052 //drawPanels(gRenderForegrounds);
2054 for idx
:= 0 to plpcount
-1 do
2056 gWalls
[plpset
[idx
]].DrawShadowVolume(lightX
, lightY
, radius
);
2060 procedure g_Map_DrawBack(dx
, dy
: Integer);
2062 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
2063 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
2065 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
2068 function g_Map_CollidePanelOld(X
, Y
: Integer; Width
, Height
: Word;
2069 PanelType
: Word; b1x3
: Boolean): Boolean;
2075 if WordBool(PanelType
and PANEL_WALL
) then
2076 if gWalls
<> nil then
2081 if gWalls
[a
].Enabled
and
2082 g_Collide(X
, Y
, Width
, Height
,
2083 gWalls
[a
].X
, gWalls
[a
].Y
,
2084 gWalls
[a
].Width
, gWalls
[a
].Height
) then
2091 if WordBool(PanelType
and PANEL_WATER
) then
2092 if gWater
<> nil then
2097 if g_Collide(X
, Y
, Width
, Height
,
2098 gWater
[a
].X
, gWater
[a
].Y
,
2099 gWater
[a
].Width
, gWater
[a
].Height
) then
2106 if WordBool(PanelType
and PANEL_ACID1
) then
2107 if gAcid1
<> nil then
2112 if g_Collide(X
, Y
, Width
, Height
,
2113 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2114 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2121 if WordBool(PanelType
and PANEL_ACID2
) then
2122 if gAcid2
<> nil then
2127 if g_Collide(X
, Y
, Width
, Height
,
2128 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2129 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2136 if WordBool(PanelType
and PANEL_STEP
) then
2137 if gSteps
<> nil then
2142 if g_Collide(X
, Y
, Width
, Height
,
2143 gSteps
[a
].X
, gSteps
[a
].Y
,
2144 gSteps
[a
].Width
, gSteps
[a
].Height
) then
2151 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
2152 if gLifts
<> nil then
2157 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2158 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2159 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2160 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2161 g_Collide(X
, Y
, Width
, Height
,
2162 gLifts
[a
].X
, gLifts
[a
].Y
,
2163 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2170 if WordBool(PanelType
and PANEL_BLOCKMON
) then
2171 if gBlockMon
<> nil then
2173 h
:= High(gBlockMon
);
2177 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2178 g_Collide(X
, Y
, Width
, Height
,
2179 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2180 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2188 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word; PanelType
: Word; b1x3
: Boolean): Boolean;
2190 function qq (obj
: TObject
; tag
: Integer): Boolean;
2195 result
:= false; // don't stop, ever
2197 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2201 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2203 if not (obj
is TPanel
) then
2205 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag
, PanelType
]), MSG_NOTIFY
);
2209 pan
:= (obj
as TPanel
);
2212 if WordBool(PanelType
and PANEL_WALL
) and WordBool(tag
and PANEL_WALL
) then
2214 if gWalls
[a
].Enabled
and g_Collide(X
, Y
, Width
, Height
, gWalls
[a
].X
, gWalls
[a
].Y
, gWalls
[a
].Width
, gWalls
[a
].Height
) then
2221 if WordBool(PanelType
and PANEL_WATER
) and WordBool(tag
and PANEL_WATER
) then
2223 if g_Collide(X
, Y
, Width
, Height
, gWater
[a
].X
, gWater
[a
].Y
, gWater
[a
].Width
, gWater
[a
].Height
) then
2230 if WordBool(PanelType
and PANEL_ACID1
) and WordBool(tag
and PANEL_ACID1
) then
2232 if g_Collide(X
, Y
, Width
, Height
, gAcid1
[a
].X
, gAcid1
[a
].Y
, gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2239 if WordBool(PanelType
and PANEL_ACID2
) and WordBool(tag
and PANEL_ACID2
) then
2241 if g_Collide(X
, Y
, Width
, Height
, gAcid2
[a
].X
, gAcid2
[a
].Y
, gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2248 if WordBool(PanelType
and PANEL_STEP
) and WordBool(tag
and PANEL_STEP
) then
2250 if g_Collide(X
, Y
, Width
, Height
, gSteps
[a
].X
, gSteps
[a
].Y
, gSteps
[a
].Width
, gSteps
[a
].Height
) then
2261 result
:= gMapGrid
.forEachInAABB(X
, Y
, Width
, Height
, qq
);
2264 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) and (gLifts
<> nil) then
2269 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
2270 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
2271 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
2272 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
2273 g_Collide(X
, Y
, Width
, Height
,
2274 gLifts
[a
].X
, gLifts
[a
].Y
,
2275 gLifts
[a
].Width
, gLifts
[a
].Height
) then
2283 if WordBool(PanelType
and PANEL_BLOCKMON
) and (gBlockMon
<> nil) then
2285 h
:= High(gBlockMon
);
2289 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
2290 g_Collide(X
, Y
, Width
, Height
,
2291 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
2292 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
2303 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
2307 Result
:= TEXTURE_NONE
;
2309 if gWater
<> nil then
2314 if g_Collide(X
, Y
, Width
, Height
,
2315 gWater
[a
].X
, gWater
[a
].Y
,
2316 gWater
[a
].Width
, gWater
[a
].Height
) then
2318 Result
:= gWater
[a
].GetTextureID();
2323 if gAcid1
<> nil then
2328 if g_Collide(X
, Y
, Width
, Height
,
2329 gAcid1
[a
].X
, gAcid1
[a
].Y
,
2330 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
2332 Result
:= gAcid1
[a
].GetTextureID();
2337 if gAcid2
<> nil then
2342 if g_Collide(X
, Y
, Width
, Height
,
2343 gAcid2
[a
].X
, gAcid2
[a
].Y
,
2344 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
2346 Result
:= gAcid2
[a
].GetTextureID();
2352 procedure g_Map_EnableWall(ID
: DWORD
);
2357 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
2359 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2363 procedure g_Map_DisableWall(ID
: DWORD
);
2368 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
2370 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2374 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
2379 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2382 tp
:= gRenderForegrounds
[ID
];
2384 tp
:= gRenderBackgrounds
[ID
];
2397 tp
.NextTexture(AnimLoop
);
2398 if g_Game_IsServer
and g_Game_IsNet
then
2399 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
2402 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
2404 if gLifts
[ID
].LiftType
= t
then
2411 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
2413 if LiftType
= 0 then
2414 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
2415 else if LiftType
= 1 then
2416 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
2417 else if LiftType
= 2 then
2418 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
2419 else if LiftType
= 3 then
2420 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
2422 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
2426 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
2429 PointsArray
: Array of TRespawnPoint
;
2432 SetLength(PointsArray
, 0);
2434 if RespawnPoints
= nil then
2437 for a
:= 0 to High(RespawnPoints
) do
2438 if RespawnPoints
[a
].PointType
= PointType
then
2440 SetLength(PointsArray
, Length(PointsArray
)+1);
2441 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
2444 if PointsArray
= nil then
2447 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
2451 function g_Map_GetPointCount(PointType
: Byte): Word;
2457 if RespawnPoints
= nil then
2460 for a
:= 0 to High(RespawnPoints
) do
2461 if RespawnPoints
[a
].PointType
= PointType
then
2462 Result
:= Result
+ 1;
2465 function g_Map_HaveFlagPoints(): Boolean;
2467 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
2470 procedure g_Map_ResetFlag(Flag
: Byte);
2472 with gFlags
[Flag
] do
2478 Direction
:= D_LEFT
;
2479 State
:= FLAG_STATE_NONE
;
2480 if FlagPoints
[Flag
] <> nil then
2482 Obj
.X
:= FlagPoints
[Flag
]^.X
;
2483 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
2484 Direction
:= FlagPoints
[Flag
]^.Direction
;
2485 State
:= FLAG_STATE_NORMAL
;
2491 procedure g_Map_DrawFlags();
2494 Mirror
: TMirrorType
;
2496 if gGameSettings
.GameMode
<> GM_CTF
then
2499 for i
:= FLAG_RED
to FLAG_BLUE
do
2501 if State
<> FLAG_STATE_CAPTURED
then
2503 if State
= FLAG_STATE_NONE
then
2506 if Direction
= D_LEFT
then
2508 Mirror
:= M_HORIZONTAL
;
2517 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2519 if g_debug_Frames
then
2521 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2523 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2524 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2530 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2537 procedure SavePanelArray(var panels
: TPanelArray
);
2539 PAMem
: TBinMemoryWriter
;
2542 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2543 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2546 while i
< Length(panels
) do
2548 if panels
[i
].SaveIt
then
2552 // Ñîõðàíÿåì ïàíåëü:
2553 panels
[i
].SaveState(PAMem
);
2558 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2559 PAMem
.SaveToMemory(Mem
);
2563 procedure SaveFlag(flag
: PFlag
);
2566 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2568 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2569 Mem
.WriteByte(flag
^.RespawnType
);
2571 Mem
.WriteByte(flag
^.State
);
2572 // Íàïðàâëåíèå ôëàãà:
2573 if flag
^.Direction
= D_LEFT
then
2579 Obj_SaveState(@flag
^.Obj
, Mem
);
2583 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2585 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2586 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2587 SavePanelArray(gWalls
);
2588 // Ñîõðàíÿåì ïàíåëè ôîíà:
2589 SavePanelArray(gRenderBackgrounds
);
2590 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2591 SavePanelArray(gRenderForegrounds
);
2592 // Ñîõðàíÿåì ïàíåëè âîäû:
2593 SavePanelArray(gWater
);
2594 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2595 SavePanelArray(gAcid1
);
2596 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2597 SavePanelArray(gAcid2
);
2598 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2599 SavePanelArray(gSteps
);
2600 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2601 SavePanelArray(gLifts
);
2604 ///// Ñîõðàíÿåì ìóçûêó: /////
2605 // Ñèãíàòóðà ìóçûêè:
2606 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2609 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2610 if gMusic
.NoMusic
then
2614 Mem
.WriteString(str
, 64);
2615 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2616 dw
:= gMusic
.GetPosition();
2618 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2619 boo
:= gMusic
.SpecPause
;
2620 Mem
.WriteBoolean(boo
);
2623 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2624 Mem
.WriteInt(gTotalMonsters
);
2627 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2628 if gGameSettings
.GameMode
= GM_CTF
then
2630 // Ôëàã Êðàñíîé êîìàíäû:
2631 SaveFlag(@gFlags
[FLAG_RED
]);
2632 // Ôëàã Ñèíåé êîìàíäû:
2633 SaveFlag(@gFlags
[FLAG_BLUE
]);
2637 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2638 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2640 // Î÷êè Êðàñíîé êîìàíäû:
2641 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2642 // Î÷êè Ñèíåé êîìàíäû:
2643 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2648 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2655 procedure LoadPanelArray(var panels
: TPanelArray
);
2657 PAMem
: TBinMemoryReader
;
2660 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2661 PAMem
:= TBinMemoryReader
.Create();
2662 PAMem
.LoadFromMemory(Mem
);
2664 for i
:= 0 to Length(panels
)-1 do
2665 if panels
[i
].SaveIt
then
2671 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2673 // Çàãðóæàåì ïàíåëü:
2674 panels
[i
].LoadState(PAMem
);
2677 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2681 procedure LoadFlag(flag
: PFlag
);
2685 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2687 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2689 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2690 Mem
.ReadByte(flag
^.RespawnType
);
2692 Mem
.ReadByte(flag
^.State
);
2693 // Íàïðàâëåíèå ôëàãà:
2696 flag
^.Direction
:= D_LEFT
2698 flag
^.Direction
:= D_RIGHT
;
2700 Obj_LoadState(@flag
^.Obj
, Mem
);
2707 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2708 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2709 LoadPanelArray(gWalls
);
2710 // Çàãðóæàåì ïàíåëè ôîíà:
2711 LoadPanelArray(gRenderBackgrounds
);
2712 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2713 LoadPanelArray(gRenderForegrounds
);
2714 // Çàãðóæàåì ïàíåëè âîäû:
2715 LoadPanelArray(gWater
);
2716 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2717 LoadPanelArray(gAcid1
);
2718 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2719 LoadPanelArray(gAcid2
);
2720 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2721 LoadPanelArray(gSteps
);
2722 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2723 LoadPanelArray(gLifts
);
2726 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2729 ///// Çàãðóæàåì ìóçûêó: /////
2730 // Ñèãíàòóðà ìóçûêè:
2732 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2734 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2737 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2738 Mem
.ReadString(str
);
2739 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2741 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2742 Mem
.ReadBoolean(boo
);
2743 // Çàïóñêàåì ýòó ìóçûêó:
2744 gMusic
.SetByName(str
);
2745 gMusic
.SpecPause
:= boo
;
2748 gMusic
.SetPosition(dw
);
2751 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2752 Mem
.ReadInt(gTotalMonsters
);
2755 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2756 if gGameSettings
.GameMode
= GM_CTF
then
2758 // Ôëàã Êðàñíîé êîìàíäû:
2759 LoadFlag(@gFlags
[FLAG_RED
]);
2760 // Ôëàã Ñèíåé êîìàíäû:
2761 LoadFlag(@gFlags
[FLAG_BLUE
]);
2765 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2766 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2768 // Î÷êè Êðàñíîé êîìàíäû:
2769 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2770 // Î÷êè Ñèíåé êîìàíäû:
2771 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2776 function g_Map_PanelForPID(PanelID
: Integer; var PanelArrayID
: Integer): PPanel
;
2781 if (PanelID
< 0) or (PanelID
> High(PanelByID
)) then Exit
;
2782 Arr
:= PanelByID
[PanelID
].PWhere
^;
2783 PanelArrayID
:= PanelByID
[PanelID
].PArrID
;
2784 Result
:= Addr(Arr
[PanelByID
[PanelID
].PArrID
]);