7 e_graphics
, g_basic
, MAPSTRUCT
, g_textures
, Classes
,
8 g_phys
, wadreader
, BinEditor
, g_panel
, md5
;
22 PRespawnPoint
= ^TRespawnPoint
;
23 TRespawnPoint
= record
25 Direction
: TDirection
;
29 PFlagPoint
= ^TFlagPoint
;
30 TFlagPoint
= TRespawnPoint
;
38 CaptureTime
: LongWord;
39 Animation
: TAnimation
;
40 Direction
: TDirection
;
44 function g_Map_Load(Res
: String): Boolean;
45 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
46 function g_Map_GetMapsList(WADName
: String): SArray
;
47 function g_Map_Exist(Res
: String): Boolean;
48 procedure g_Map_Free();
49 procedure g_Map_Update();
50 procedure g_Map_DrawPanels(PanelType
: Word);
51 procedure g_Map_DrawBack(dx
, dy
: Integer);
52 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
53 PanelType
: Word; b1x3
: Boolean): Boolean;
54 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
55 procedure g_Map_EnableWall(ID
: DWORD
);
56 procedure g_Map_DisableWall(ID
: DWORD
);
57 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
58 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
59 procedure g_Map_ReAdd_DieTriggers();
60 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
62 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
63 function g_Map_GetPointCount(PointType
: Byte): Word;
65 function g_Map_HaveFlagPoints(): Boolean;
67 procedure g_Map_ResetFlag(Flag
: Byte);
68 procedure g_Map_DrawFlags();
70 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
71 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
74 RESPAWNPOINT_PLAYER1
= 1;
75 RESPAWNPOINT_PLAYER2
= 2;
78 RESPAWNPOINT_BLUE
= 5;
86 FLAG_STATE_NORMAL
= 1;
87 FLAG_STATE_DROPPED
= 2;
88 FLAG_STATE_CAPTURED
= 3;
89 FLAG_STATE_SCORED
= 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
90 FLAG_STATE_RETURNED
= 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
92 FLAG_TIME
= 720; // 20 seconds
94 SKY_STRETCH
: Single = 1.5;
98 gRenderBackgrounds
: TPanelArray
;
99 gRenderForegrounds
: TPanelArray
;
100 gWater
, gAcid1
, gAcid2
: TPanelArray
;
103 gBlockMon
: TPanelArray
;
104 gFlags
: array [FLAG_RED
..FLAG_BLUE
] of TFlag
;
105 //gDOMFlags: array of TFlag;
108 gDoorMap
: array of array of DWORD
;
109 gLiftMap
: array of array of DWORD
;
110 gWADHash
: TMD5Digest
;
111 BackID
: DWORD
= DWORD(-1);
112 gExternalResources
: TStringList
;
117 g_main
, e_log
, SysUtils
, g_items
, g_gfx
, g_console
,
118 GL
, GLExt
, g_weapons
, g_game
, g_sound
, e_sound
, CONFIG
,
119 g_options
, MAPREADER
, g_triggers
, g_player
, MAPDEF
,
120 Math
, g_monsters
, g_saveload
, g_language
, g_netmsg
,
122 ImagingTypes
, Imaging
, ImagingUtility
,
123 ImagingGif
, ImagingNetworkGraphics
;
126 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
127 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
128 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
131 Textures
: TLevelTextureArray
;
132 RespawnPoints
: Array of TRespawnPoint
;
133 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
134 //DOMFlagPoints: Array of TFlagPoint;
137 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
139 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
140 (Texture
= TEXTURE_NAME_ACID1
) or
141 (Texture
= TEXTURE_NAME_ACID2
);
144 procedure CreateDoorMap();
146 PanelArray
: Array of record
152 a
, b
, c
, m
, i
, len
: Integer;
160 SetLength(PanelArray
, len
);
162 for a
:= 0 to High(gWalls
) do
163 if gWalls
[a
].Door
then
165 PanelArray
[i
].X
:= gWalls
[a
].X
;
166 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
167 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
168 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
169 PanelArray
[i
].Active
:= True;
170 PanelArray
[i
].PanelID
:= a
;
176 SetLength(PanelArray
, len
);
187 SetLength(gDoorMap
, 0);
189 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
192 if PanelArray
[a
].Active
then
194 PanelArray
[a
].Active
:= False;
195 m
:= Length(gDoorMap
);
196 SetLength(gDoorMap
, m
+1);
197 SetLength(gDoorMap
[m
], 1);
198 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
206 if PanelArray
[b
].Active
then
207 for c
:= 0 to High(gDoorMap
[m
]) do
208 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
209 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
210 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
211 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
212 gWalls
[gDoorMap
[m
, c
]].X
,
213 gWalls
[gDoorMap
[m
, c
]].Y
,
214 gWalls
[gDoorMap
[m
, c
]].Width
,
215 gWalls
[gDoorMap
[m
, c
]].Height
) then
217 PanelArray
[b
].Active
:= False;
218 SetLength(gDoorMap
[m
],
219 Length(gDoorMap
[m
])+1);
220 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
226 g_Game_StepLoading();
232 procedure CreateLiftMap();
234 PanelArray
: Array of record
239 a
, b
, c
, len
, i
, j
: Integer;
245 len
:= Length(gLifts
);
246 SetLength(PanelArray
, len
);
248 for a
:= 0 to len
-1 do
250 PanelArray
[a
].X
:= gLifts
[a
].X
;
251 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
252 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
253 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
254 PanelArray
[a
].Active
:= True;
257 SetLength(gLiftMap
, len
);
260 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
262 for a
:= 0 to len
-1 do
263 if PanelArray
[a
].Active
then
265 PanelArray
[a
].Active
:= False;
266 SetLength(gLiftMap
[i
], 32);
274 for b
:= 0 to len
-1 do
275 if PanelArray
[b
].Active
then
277 if g_CollideAround(PanelArray
[b
].X
,
280 PanelArray
[b
].Height
,
281 PanelArray
[gLiftMap
[i
, c
]].X
,
282 PanelArray
[gLiftMap
[i
, c
]].Y
,
283 PanelArray
[gLiftMap
[i
, c
]].Width
,
284 PanelArray
[gLiftMap
[i
, c
]].Height
) then
286 PanelArray
[b
].Active
:= False;
288 if j
> High(gLiftMap
[i
]) then
289 SetLength(gLiftMap
[i
],
290 Length(gLiftMap
[i
])+32);
299 SetLength(gLiftMap
[i
], j
+1);
302 g_Game_StepLoading();
305 SetLength(gLiftMap
, i
);
310 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
311 CurTex
: Integer; sav
: Boolean): Integer;
314 panels
: ^TPanelArray
;
318 case PanelRec
.PanelType
of
319 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
322 panels
:= @gRenderBackgrounds
;
324 panels
:= @gRenderForegrounds
;
333 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
336 panels
:= @gBlockMon
;
341 len
:= Length(panels
^);
342 SetLength(panels
^, len
+ 1);
344 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
,
347 panels
^[len
].SaveIt
:= True;
352 function CreateNullTexture(RecName
: String): Integer;
354 SetLength(Textures
, Length(Textures
)+1);
355 result
:= High(Textures
);
357 with Textures
[High(Textures
)] do
359 TextureName
:= RecName
;
363 TextureID
:= TEXTURE_NONE
;
367 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
370 TextureData
: Pointer;
371 WADName
, txname
: String;
372 a
, ResLength
: Integer;
376 if Textures
<> nil then
377 for a
:= 0 to High(Textures
) do
378 if Textures
[a
].TextureName
= RecName
then
379 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
384 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
385 if (RecName
= TEXTURE_NAME_WATER
) or
386 (RecName
= TEXTURE_NAME_ACID1
) or
387 (RecName
= TEXTURE_NAME_ACID2
) then
389 SetLength(Textures
, Length(Textures
)+1);
391 with Textures
[High(Textures
)] do
393 TextureName
:= RecName
;
395 if TextureName
= TEXTURE_NAME_WATER
then
396 TextureID
:= TEXTURE_SPECIAL_WATER
398 if TextureName
= TEXTURE_NAME_ACID1
then
399 TextureID
:= TEXTURE_SPECIAL_ACID1
401 if TextureName
= TEXTURE_NAME_ACID2
then
402 TextureID
:= TEXTURE_SPECIAL_ACID2
;
407 result
:= High(Textures
);
411 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
412 WADName
:= g_ExtractWadName(RecName
);
414 WAD
:= TWADFile
.Create();
416 if WADName
<> '' then
417 WADName
:= GameDir
+'/wads/'+WADName
421 WAD
.ReadFile(WADName
);
425 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
427 FreeMem(TextureData);
428 RecName := 'COMMON\ALIEN';
432 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
434 SetLength(Textures
, Length(Textures
)+1);
435 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
437 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
438 @Textures
[High(Textures
)].Width
,
439 @Textures
[High(Textures
)].Height
);
440 FreeMem(TextureData
);
441 Textures
[High(Textures
)].TextureName
:= {RecName}txname
;
442 Textures
[High(Textures
)].Anim
:= False;
444 result
:= High(Textures
);
446 else // Íåò òàêîãî ðåóñðñà â WAD'å
448 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
451 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
452 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
459 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
462 TextureWAD
: PChar = nil;
464 TextData
: Pointer = nil;
465 TextureData
: Pointer = nil;
468 ResLength
, rrl
: Integer;
469 TextureResource
: String;
470 _width
, _height
, _framecount
, _speed
: Integer;
471 _backanimation
: Boolean;
473 ia
: TDynImageDataArray
= nil;
474 f
, c
, frdelay
, frloop
: Integer;
478 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
480 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
481 WADName
:= g_ExtractWadName(RecName
);
483 WAD
:= TWADFile
.Create();
485 if WADName
<> '' then
486 WADName
:= GameDir
+'/wads/'+WADName
490 WAD
.ReadFile(WADName
);
492 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
496 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
497 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
503 if WADName = Map then
505 //FreeMem(TextureWAD);
506 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
512 if ResLength
< 6 then
514 e_WriteLog(Format('Animated texture file "%s" too short', [RecName
]), MSG_WARNING
);
518 // ýòî ïòèöà? ýòî ñàìîë¸ò?
519 if (TextureWAD
[0] = 'D') and (TextureWAD
[1] = 'F') and
520 (TextureWAD
[2] = 'W') and (TextureWAD
[3] = 'A') and (TextureWAD
[4] = 'D') then
522 // íåò, ýòî ñóïåðìåí!
523 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
525 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName
]), MSG_WARNING
);
529 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
530 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
532 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName
]), MSG_WARNING
);
536 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
538 TextureResource
:= cfg
.ReadStr('', 'resource', '');
539 if TextureResource
= '' then
541 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName
]), MSG_WARNING
);
545 _width
:= cfg
.ReadInt('', 'framewidth', 0);
546 _height
:= cfg
.ReadInt('', 'frameheight', 0);
547 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
548 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
549 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
554 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
555 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
557 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName
, 'TEXTURES/'+TextureResource
]), MSG_WARNING
);
564 SetLength(Textures
, Length(Textures
)+1);
565 with Textures
[High(Textures
)] do
567 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
568 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
, _width
, _height
, _framecount
, _backanimation
) then
570 TextureName
:= RecName
;
574 FramesCount
:= _framecount
;
576 result
:= High(Textures
);
580 if log
then e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
586 // try animated image
588 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
589 if length(imgfmt) = 0 then
591 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
595 GlobalMetadata
.ClearMetaItems();
596 GlobalMetadata
.ClearMetaItemsForSaving();
597 if not LoadMultiImageFromMemory(TextureWAD
, ResLength
, ia
) then
599 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName
]), MSG_WARNING
);
602 if length(ia
) = 0 then
604 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName
]), MSG_WARNING
);
611 _width
:= ia
[0].width
;
612 _height
:= ia
[0].height
;
613 _framecount
:= length(ia
);
615 _backanimation
:= false;
618 if GlobalMetadata
.HasMetaItem(SMetaFrameDelay
) then
620 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
622 f
:= GlobalMetadata
.MetaItems
[SMetaFrameDelay
];
624 if f
< 0 then f
:= 0;
627 if c
< 13 then c
:= 0 else c
:= 1;
629 if f
< 1 then f
:= 1 else if f
> 255 then f
:= 255;
634 if GlobalMetadata
.HasMetaItem(SMetaAnimationLoops
) then
636 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
638 f
:= GlobalMetadata
.MetaItems
[SMetaAnimationLoops
];
640 if f
<> 0 then _backanimation
:= true; // non-infinite looping == forth-and-back
644 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
645 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
646 f
:= ord(_backanimation
);
647 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
);
649 SetLength(Textures
, Length(Textures
)+1);
650 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
651 if g_CreateFramesImg(ia
, @Textures
[High(Textures
)].FramesID
, '', _backanimation
) then
653 Textures
[High(Textures
)].TextureName
:= RecName
;
654 Textures
[High(Textures
)].Width
:= _width
;
655 Textures
[High(Textures
)].Height
:= _height
;
656 Textures
[High(Textures
)].Anim
:= True;
657 Textures
[High(Textures
)].FramesCount
:= length(ia
);
658 Textures
[High(Textures
)].Speed
:= _speed
;
659 result
:= High(Textures
);
660 //writeln(' CREATED!');
664 if log
then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName
]), MSG_WARNING
);
668 for f
:= 0 to High(ia
) do FreeImage(ia
[f
]);
671 if TextureWAD
<> nil then FreeMem(TextureWAD
);
672 if TextData
<> nil then FreeMem(TextData
);
673 if TextureData
<> nil then FreeMem(TextureData
);
677 procedure CreateItem(Item
: TItemRec_1
);
679 if g_Game_IsClient
then Exit
;
681 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
682 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
685 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
686 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
689 procedure CreateArea(Area
: TAreaRec_1
);
694 case Area
.AreaType
of
695 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
696 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
698 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
699 with RespawnPoints
[High(RespawnPoints
)] do
703 Direction
:= TDirection(Area
.Direction
);
705 case Area
.AreaType
of
706 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
707 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
708 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
709 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
710 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
715 AREA_REDFLAG
, AREA_BLUEFLAG
:
717 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
719 if FlagPoints
[a
] <> nil then Exit
;
723 with FlagPoints
[a
]^ do
725 X
:= Area
.X
-FLAGRECT
.X
;
726 Y
:= Area
.Y
-FLAGRECT
.Y
;
727 Direction
:= TDirection(Area
.Direction
);
733 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
734 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
737 Animation
:= TAnimation
.Create(id
, True, 8);
738 Obj
.Rect
:= FLAGRECT
;
746 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
747 with DOMFlagPoints[High(DOMFlagPoints)] do
751 Direction := TDirection(Area.Direction);
754 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
759 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
763 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
769 Width
:= Trigger
.Width
;
770 Height
:= Trigger
.Height
;
771 Enabled
:= ByteBool(Trigger
.Enabled
);
772 TexturePanel
:= Trigger
.TexturePanel
;
773 TexturePanelType
:= fTexturePanel1Type
;
774 ShotPanelType
:= fTexturePanel2Type
;
775 TriggerType
:= Trigger
.TriggerType
;
776 ActivateType
:= Trigger
.ActivateType
;
777 Keys
:= Trigger
.Keys
;
778 Data
.Default
:= Trigger
.DATA
;
781 g_Triggers_Create(_trigger
);
784 procedure CreateMonster(monster
: TMonsterRec_1
);
788 if g_Game_IsClient
then Exit
;
790 if (gGameSettings
.GameType
= GT_SINGLE
)
791 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
793 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
794 TDirection(monster
.Direction
));
796 if gTriggers
<> nil then
797 for a
:= 0 to High(gTriggers
) do
798 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
799 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
800 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
801 gMonsters
[i
].AddTrigger(a
);
803 if monster
.MonsterType
<> MONSTER_BARREL
then
808 procedure g_Map_ReAdd_DieTriggers();
812 if g_Game_IsClient
then Exit
;
814 for i
:= 0 to High(gMonsters
) do
815 if gMonsters
[i
] <> nil then
817 gMonsters
[i
].ClearTriggers();
819 for a
:= 0 to High(gTriggers
) do
820 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
821 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
822 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
823 gMonsters
[i
].AddTrigger(a
);
827 function extractWadName(resourceName
: string): string;
831 posN
:= Pos(':', resourceName
);
833 Result
:= Copy(resourceName
, 0, posN
-1)
838 procedure addResToExternalResList(res
: string);
840 res
:= extractWadName(res
);
841 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
842 gExternalResources
.Add(res
);
845 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
847 textures
: TTexturesRec1Array
;
848 mapHeader
: TMapHeaderRec_1
;
850 resFile
: String = '';
852 if gExternalResources
= nil then
853 gExternalResources
:= TStringList
.Create
;
855 gExternalResources
.Clear
;
856 textures
:= mapReader
.GetTextures();
857 for i
:= 0 to High(textures
) do
859 addResToExternalResList(resFile
);
864 mapHeader
:= mapReader
.GetMapHeader
;
866 addResToExternalResList(mapHeader
.MusicName
);
867 addResToExternalResList(mapHeader
.SkyName
);
870 function g_Map_Load(Res
: String): Boolean;
872 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
873 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
876 MapReader
: TMapReader_1
;
877 Header
: TMapHeaderRec_1
;
878 _textures
: TTexturesRec1Array
;
879 _texnummap
: array of Integer; // `_textures` -> `Textures`
880 panels
: TPanelsRec1Array
;
881 items
: TItemsRec1Array
;
882 monsters
: TMonsterRec1Array
;
883 areas
: TAreasRec1Array
;
884 triggers
: TTriggersRec1Array
;
887 AddTextures
: TAddTextureArray
;
888 texture
: TTextureRec_1
;
889 TriggersTable
: Array of record
890 TexturePanel
: Integer;
895 FileName
, mapResName
, s
, TexName
: String;
898 ok
, isAnim
, trigRef
: Boolean;
899 CurTex
, ntn
: Integer;
903 TriggersTable
:= nil;
904 FillChar(texture
, SizeOf(texture
), 0);
906 sfsGCDisable(); // temporary disable removing of temporary volumes
909 FileName
:= g_ExtractWadName(Res
);
910 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
911 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
913 WAD
:= TWADFile
.Create();
914 if not WAD
.ReadFile(FileName
) then
916 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
920 //k8: why loader ignores path here?
921 mapResName
:= g_ExtractFileName(Res
);
922 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
924 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
931 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
932 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
933 MapReader
:= TMapReader_1
.Create();
935 if not MapReader
.LoadMap(Data
) then
937 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
944 generateExternalResourcesList(MapReader
);
946 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
947 _textures
:= MapReader
.GetTextures();
950 // Äîáàâëåíèå òåêñòóð â Textures[]:
951 if _textures
<> nil then
953 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
954 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
955 SetLength(_texnummap
, length(_textures
));
957 for a
:= 0 to High(_textures
) do
960 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
961 for b
:= 1 to Length(s
) do
967 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
968 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
969 // Àíèìèðîâàííàÿ òåêñòóðà:
970 if ByteBool(_textures
[a
].Anim
) then
972 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
975 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
976 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
979 else // Îáû÷íàÿ òåêñòóðà:
980 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
983 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
984 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
987 _texnummap
[a
] := ntn
; // fix texture number
988 g_Game_StepLoading();
992 // Çàãðóçêà òðèããåðîâ:
993 gTriggerClientID
:= 0;
994 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
995 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
996 triggers
:= MapReader
.GetTriggers();
999 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
1000 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
1001 panels
:= MapReader
.GetPanels();
1003 // check texture numbers for panels
1004 for a
:= 0 to High(panels
) do
1006 if panels
[a
].TextureNum
> High(_textures
) then
1008 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
1012 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
1015 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1016 if triggers
<> nil then
1018 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
1019 SetLength(TriggersTable
, Length(triggers
));
1020 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
1022 for a
:= 0 to High(TriggersTable
) do
1024 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1025 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
1027 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
1028 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1030 TriggersTable
[a
].LiftPanel
:= -1;
1032 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
1033 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
1034 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
1035 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
1037 TriggersTable
[a
].DoorPanel
:= -1;
1039 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
1040 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
1042 TriggersTable
[a
].ShotPanel
:= -1;
1044 g_Game_StepLoading();
1049 if panels
<> nil then
1051 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
1052 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
1054 for a
:= 0 to High(panels
) do
1056 SetLength(AddTextures
, 0);
1059 if _textures
<> nil then
1061 texture
:= _textures
[panels
[a
].TextureNum
];
1069 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1070 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1072 if (TriggersTable
<> nil) and (_textures
<> nil) then
1073 for b
:= 0 to High(TriggersTable
) do
1074 if (TriggersTable
[b
].TexturePanel
= a
)
1075 or (TriggersTable
[b
].ShotPanel
= a
) then
1084 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1086 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
1089 for c
:= Len
downto 1 do
1097 // Ñïåö-òåêñòóðû çàïðåùåíû:
1098 if g_Map_IsSpecialTexture(s
) then
1101 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1102 ok
:= g_Texture_NumNameFindStart(s
);
1104 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1105 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1108 k
:= NNF_NAME_BEFORE
;
1109 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1110 while ok
or (k
= NNF_NAME_BEFORE
) or
1111 (k
= NNF_NAME_EQUALS
) do
1113 k
:= g_Texture_NumNameFindNext(TexName
);
1115 if (k
= NNF_NAME_BEFORE
) or
1116 (k
= NNF_NAME_AFTER
) then
1118 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1119 if ByteBool(texture
.Anim
) then
1120 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1122 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1124 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1126 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1130 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1132 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1134 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1136 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1140 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1143 for c
:= 0 to High(Textures
) do
1144 if Textures
[c
].TextureName
= TexName
then
1146 SetLength(AddTextures
, Length(AddTextures
)+1);
1147 AddTextures
[High(AddTextures
)].Texture
:= c
;
1148 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1154 if k
= NNF_NAME_EQUALS
then
1156 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1157 SetLength(AddTextures
, Length(AddTextures
)+1);
1158 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1159 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1160 CurTex
:= High(AddTextures
);
1168 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1169 end; // if ok - ññûëàþòñÿ òðèããåðû
1173 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1174 SetLength(AddTextures
, 1);
1175 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1176 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1180 //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);
1182 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1183 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1185 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1186 if TriggersTable
<> nil then
1187 for b
:= 0 to High(TriggersTable
) do
1189 // Òðèããåð äâåðè/ëèôòà:
1190 if (TriggersTable
[b
].LiftPanel
= a
) or
1191 (TriggersTable
[b
].DoorPanel
= a
) then
1192 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1193 // Òðèããåð ñìåíû òåêñòóðû:
1194 if TriggersTable
[b
].TexturePanel
= a
then
1195 triggers
[b
].TexturePanel
:= PanelID
;
1196 // Òðèããåð "Òóðåëü":
1197 if TriggersTable
[b
].ShotPanel
= a
then
1198 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1201 g_Game_StepLoading();
1205 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1206 if (triggers
<> nil) and not gLoadGameMode
then
1208 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1209 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1210 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1211 for a
:= 0 to High(triggers
) do
1213 if triggers
[a
].TexturePanel
<> -1 then
1214 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1217 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1218 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1219 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1222 CreateTrigger(triggers
[a
], b
, c
);
1226 // Çàãðóçêà ïðåäìåòîâ:
1227 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1228 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1229 items
:= MapReader
.GetItems();
1231 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1232 if (items
<> nil) and not gLoadGameMode
then
1234 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1235 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1236 for a
:= 0 to High(items
) do
1237 CreateItem(Items
[a
]);
1240 // Çàãðóçêà îáëàñòåé:
1241 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1242 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1243 areas
:= MapReader
.GetAreas();
1245 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1246 if areas
<> nil then
1248 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1249 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1250 for a
:= 0 to High(areas
) do
1251 CreateArea(areas
[a
]);
1254 // Çàãðóçêà ìîíñòðîâ:
1255 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1256 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1257 monsters
:= MapReader
.GetMonsters();
1259 gTotalMonsters
:= 0;
1261 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1262 if (monsters
<> nil) and not gLoadGameMode
then
1264 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1265 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1266 for a
:= 0 to High(monsters
) do
1267 CreateMonster(monsters
[a
]);
1270 // Çàãðóçêà îïèñàíèÿ êàðòû:
1271 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1272 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1273 Header
:= MapReader
.GetMapHeader();
1279 Name
:= Header
.MapName
;
1280 Description
:= Header
.MapDescription
;
1281 Author
:= Header
.MapAuthor
;
1282 MusicName
:= Header
.MusicName
;
1283 SkyName
:= Header
.SkyName
;
1284 Height
:= Header
.Height
;
1285 Width
:= Header
.Width
;
1289 if gMapInfo
.SkyName
<> '' then
1291 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1292 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1293 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1295 if FileName
<> '' then
1296 FileName
:= GameDir
+'/wads/'+FileName
1299 FileName
:= g_ExtractWadName(Res
);
1302 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1303 if g_Texture_CreateWAD(BackID
, s
) then
1305 g_Game_SetupScreenSize();
1308 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1313 if gMapInfo
.MusicName
<> '' then
1315 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1316 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1317 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1319 if FileName
<> '' then
1320 FileName
:= GameDir
+'/wads/'+FileName
1323 FileName
:= g_ExtractWadName(Res
);
1326 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1327 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1330 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1333 // Îñòàëüíûå óñòàíâêè:
1341 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1342 if not gLoadGameMode
then
1345 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1351 TriggersTable
:= nil;
1354 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1355 if ok
and (not gLoadGameMode
) then
1357 gMusic
.SetByName(gMapInfo
.MusicName
);
1361 gMusic
.SetByName('');
1363 sfsGCEnable(); // enable releasing unused volumes
1366 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1370 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1373 MapReader
: TMapReader_1
;
1374 Header
: TMapHeaderRec_1
;
1379 FillChar(Result
, SizeOf(Result
), 0);
1380 FileName
:= g_ExtractWadName(Res
);
1382 WAD
:= TWADFile
.Create();
1383 if not WAD
.ReadFile(FileName
) then
1389 //k8: it ignores path again
1390 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1398 MapReader
:= TMapReader_1
.Create();
1400 if not MapReader
.LoadMap(Data
) then
1402 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1403 ZeroMemory(@Header
, SizeOf(Header
));
1404 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1405 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1409 Header
:= MapReader
.GetMapHeader();
1410 Result
.Name
:= Header
.MapName
;
1411 Result
.Description
:= Header
.MapDescription
;
1418 Result
.Author
:= Header
.MapAuthor
;
1419 Result
.Height
:= Header
.Height
;
1420 Result
.Width
:= Header
.Width
;
1423 function g_Map_GetMapsList(WADName
: string): SArray
;
1430 WAD
:= TWADFile
.Create();
1431 if not WAD
.ReadFile(WADName
) then
1436 ResList
:= WAD
.GetMapResources();
1437 if ResList
<> nil then
1439 for a
:= 0 to High(ResList
) do
1441 SetLength(Result
, Length(Result
)+1);
1442 Result
[High(Result
)] := ResList
[a
];
1448 function g_Map_Exist(Res
: string): Boolean;
1451 FileName
, mnn
: string;
1457 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1459 WAD
:= TWADFile
.Create
;
1460 if not WAD
.ReadFile(FileName
) then
1466 ResList
:= WAD
.GetMapResources();
1469 mnn
:= g_ExtractFileName(Res
);
1470 if ResList
<> nil then
1471 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1478 procedure g_Map_Free();
1482 procedure FreePanelArray(var panels
: TPanelArray
);
1487 if panels
<> nil then
1489 for i
:= 0 to High(panels
) do
1502 RespawnPoints
:= nil;
1503 if FlagPoints
[FLAG_RED
] <> nil then
1505 Dispose(FlagPoints
[FLAG_RED
]);
1506 FlagPoints
[FLAG_RED
] := nil;
1508 if FlagPoints
[FLAG_BLUE
] <> nil then
1510 Dispose(FlagPoints
[FLAG_BLUE
]);
1511 FlagPoints
[FLAG_BLUE
] := nil;
1513 //DOMFlagPoints := nil;
1517 if Textures
<> nil then
1519 for a
:= 0 to High(Textures
) do
1520 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1521 if Textures
[a
].Anim
then
1522 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1524 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1525 e_DeleteTexture(Textures
[a
].TextureID
);
1530 FreePanelArray(gWalls
);
1531 FreePanelArray(gRenderBackgrounds
);
1532 FreePanelArray(gRenderForegrounds
);
1533 FreePanelArray(gWater
);
1534 FreePanelArray(gAcid1
);
1535 FreePanelArray(gAcid2
);
1536 FreePanelArray(gSteps
);
1537 FreePanelArray(gLifts
);
1538 FreePanelArray(gBlockMon
);
1540 if BackID
<> DWORD(-1) then
1544 e_DeleteTexture(BackID
);
1545 BackID
:= DWORD(-1);
1548 g_Game_StopAllSounds(False);
1550 g_Sound_Delete(gMapInfo
.MusicName
);
1552 gMapInfo
.Name
:= '';
1553 gMapInfo
.Description
:= '';
1554 gMapInfo
.MusicName
:= '';
1555 gMapInfo
.Height
:= 0;
1556 gMapInfo
.Width
:= 0;
1562 procedure g_Map_Update();
1568 procedure UpdatePanelArray(var panels
: TPanelArray
);
1573 if panels
<> nil then
1574 for i
:= 0 to High(panels
) do
1579 UpdatePanelArray(gWalls
);
1580 UpdatePanelArray(gRenderBackgrounds
);
1581 UpdatePanelArray(gRenderForegrounds
);
1582 UpdatePanelArray(gWater
);
1583 UpdatePanelArray(gAcid1
);
1584 UpdatePanelArray(gAcid2
);
1585 UpdatePanelArray(gSteps
);
1587 if gGameSettings
.GameMode
= GM_CTF
then
1589 for a
:= FLAG_RED
to FLAG_BLUE
do
1590 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1593 if gFlags
[a
].Animation
<> nil then
1594 gFlags
[a
].Animation
.Update();
1596 m
:= g_Obj_Move(@Obj
, True, True);
1598 if gTime
mod (GAME_TICK
*2) <> 0 then
1601 // Ñîïðîòèâëåíèå âîçäóõà:
1602 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1604 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1605 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1608 gFlags
[a
].CaptureTime
:= 0;
1609 if a
= FLAG_RED
then
1610 s
:= _lc
[I_PLAYER_FLAG_RED
]
1612 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1613 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1615 if g_Game_IsNet
then
1616 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1623 // Èãðîê áåðåò ôëàã:
1624 if gPlayers
<> nil then
1626 j
:= Random(Length(gPlayers
)) - 1;
1628 for d
:= 0 to High(gPlayers
) do
1631 if j
> High(gPlayers
) then
1634 if gPlayers
[j
] <> nil then
1635 if gPlayers
[j
].Live
and
1636 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1638 if gPlayers
[j
].GetFlag(a
) then
1647 procedure g_Map_DrawPanels(PanelType
: Word);
1649 procedure DrawPanels(var panels
: TPanelArray
;
1650 drawDoors
: Boolean = False);
1655 if panels
<> nil then
1656 for a
:= 0 to High(panels
) do
1657 if not (drawDoors
xor panels
[a
].Door
) then
1663 PANEL_WALL
: DrawPanels(gWalls
);
1664 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1665 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1666 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1667 PANEL_WATER
: DrawPanels(gWater
);
1668 PANEL_ACID1
: DrawPanels(gAcid1
);
1669 PANEL_ACID2
: DrawPanels(gAcid2
);
1670 PANEL_STEP
: DrawPanels(gSteps
);
1674 procedure g_Map_DrawBack(dx
, dy
: Integer);
1676 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1677 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1679 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1682 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
1683 PanelType
: Word; b1x3
: Boolean): Boolean;
1689 if WordBool(PanelType
and PANEL_WALL
) then
1690 if gWalls
<> nil then
1695 if gWalls
[a
].Enabled
and
1696 g_Collide(X
, Y
, Width
, Height
,
1697 gWalls
[a
].X
, gWalls
[a
].Y
,
1698 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1705 if WordBool(PanelType
and PANEL_WATER
) then
1706 if gWater
<> nil then
1711 if g_Collide(X
, Y
, Width
, Height
,
1712 gWater
[a
].X
, gWater
[a
].Y
,
1713 gWater
[a
].Width
, gWater
[a
].Height
) then
1720 if WordBool(PanelType
and PANEL_ACID1
) then
1721 if gAcid1
<> nil then
1726 if g_Collide(X
, Y
, Width
, Height
,
1727 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1728 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1735 if WordBool(PanelType
and PANEL_ACID2
) then
1736 if gAcid2
<> nil then
1741 if g_Collide(X
, Y
, Width
, Height
,
1742 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1743 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1750 if WordBool(PanelType
and PANEL_STEP
) then
1751 if gSteps
<> nil then
1756 if g_Collide(X
, Y
, Width
, Height
,
1757 gSteps
[a
].X
, gSteps
[a
].Y
,
1758 gSteps
[a
].Width
, gSteps
[a
].Height
) then
1765 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
1766 if gLifts
<> nil then
1771 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
1772 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
1773 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
1774 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
1775 g_Collide(X
, Y
, Width
, Height
,
1776 gLifts
[a
].X
, gLifts
[a
].Y
,
1777 gLifts
[a
].Width
, gLifts
[a
].Height
) then
1784 if WordBool(PanelType
and PANEL_BLOCKMON
) then
1785 if gBlockMon
<> nil then
1787 h
:= High(gBlockMon
);
1791 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
1792 g_Collide(X
, Y
, Width
, Height
,
1793 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
1794 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
1802 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
1806 Result
:= TEXTURE_NONE
;
1808 if gWater
<> nil then
1813 if g_Collide(X
, Y
, Width
, Height
,
1814 gWater
[a
].X
, gWater
[a
].Y
,
1815 gWater
[a
].Width
, gWater
[a
].Height
) then
1817 Result
:= gWater
[a
].GetTextureID();
1822 if gAcid1
<> nil then
1827 if g_Collide(X
, Y
, Width
, Height
,
1828 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1829 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1831 Result
:= gAcid1
[a
].GetTextureID();
1836 if gAcid2
<> nil then
1841 if g_Collide(X
, Y
, Width
, Height
,
1842 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1843 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1845 Result
:= gAcid2
[a
].GetTextureID();
1851 procedure g_Map_EnableWall(ID
: DWORD
);
1856 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
1858 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1862 procedure g_Map_DisableWall(ID
: DWORD
);
1867 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
1869 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1873 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
1878 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1881 tp
:= gRenderForegrounds
[ID
];
1883 tp
:= gRenderBackgrounds
[ID
];
1896 tp
.NextTexture(AnimLoop
);
1897 if g_Game_IsServer
and g_Game_IsNet
then
1898 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
1901 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
1903 if gLifts
[ID
].LiftType
= t
then
1910 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
1912 if LiftType
= 0 then
1913 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
1914 else if LiftType
= 1 then
1915 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
1916 else if LiftType
= 2 then
1917 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
1918 else if LiftType
= 3 then
1919 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
1921 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1925 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
1928 PointsArray
: Array of TRespawnPoint
;
1931 SetLength(PointsArray
, 0);
1933 if RespawnPoints
= nil then
1936 for a
:= 0 to High(RespawnPoints
) do
1937 if RespawnPoints
[a
].PointType
= PointType
then
1939 SetLength(PointsArray
, Length(PointsArray
)+1);
1940 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
1943 if PointsArray
= nil then
1946 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
1950 function g_Map_GetPointCount(PointType
: Byte): Word;
1956 if RespawnPoints
= nil then
1959 for a
:= 0 to High(RespawnPoints
) do
1960 if RespawnPoints
[a
].PointType
= PointType
then
1961 Result
:= Result
+ 1;
1964 function g_Map_HaveFlagPoints(): Boolean;
1966 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
1969 procedure g_Map_ResetFlag(Flag
: Byte);
1971 with gFlags
[Flag
] do
1977 Direction
:= D_LEFT
;
1978 State
:= FLAG_STATE_NONE
;
1979 if FlagPoints
[Flag
] <> nil then
1981 Obj
.X
:= FlagPoints
[Flag
]^.X
;
1982 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
1983 Direction
:= FlagPoints
[Flag
]^.Direction
;
1984 State
:= FLAG_STATE_NORMAL
;
1990 procedure g_Map_DrawFlags();
1993 Mirror
: TMirrorType
;
1995 if gGameSettings
.GameMode
<> GM_CTF
then
1998 for i
:= FLAG_RED
to FLAG_BLUE
do
2000 if State
<> FLAG_STATE_CAPTURED
then
2002 if State
= FLAG_STATE_NONE
then
2005 if Direction
= D_LEFT
then
2007 Mirror
:= M_HORIZONTAL
;
2016 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
2018 if g_debug_Frames
then
2020 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
2022 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
2023 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
2029 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
2036 procedure SavePanelArray(var panels
: TPanelArray
);
2038 PAMem
: TBinMemoryWriter
;
2041 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2042 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
2045 while i
< Length(panels
) do
2047 if panels
[i
].SaveIt
then
2051 // Ñîõðàíÿåì ïàíåëü:
2052 panels
[i
].SaveState(PAMem
);
2057 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2058 PAMem
.SaveToMemory(Mem
);
2062 procedure SaveFlag(flag
: PFlag
);
2065 dw
:= FLAG_SIGNATURE
; // 'FLAG'
2067 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2068 Mem
.WriteByte(flag
^.RespawnType
);
2070 Mem
.WriteByte(flag
^.State
);
2071 // Íàïðàâëåíèå ôëàãà:
2072 if flag
^.Direction
= D_LEFT
then
2078 Obj_SaveState(@flag
^.Obj
, Mem
);
2082 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
2084 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2085 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2086 SavePanelArray(gWalls
);
2087 // Ñîõðàíÿåì ïàíåëè ôîíà:
2088 SavePanelArray(gRenderBackgrounds
);
2089 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2090 SavePanelArray(gRenderForegrounds
);
2091 // Ñîõðàíÿåì ïàíåëè âîäû:
2092 SavePanelArray(gWater
);
2093 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2094 SavePanelArray(gAcid1
);
2095 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2096 SavePanelArray(gAcid2
);
2097 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2098 SavePanelArray(gSteps
);
2099 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2100 SavePanelArray(gLifts
);
2103 ///// Ñîõðàíÿåì ìóçûêó: /////
2104 // Ñèãíàòóðà ìóçûêè:
2105 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
2108 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
2109 if gMusic
.NoMusic
then
2113 Mem
.WriteString(str
, 64);
2114 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2115 dw
:= gMusic
.GetPosition();
2117 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2118 boo
:= gMusic
.SpecPause
;
2119 Mem
.WriteBoolean(boo
);
2122 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2123 Mem
.WriteInt(gTotalMonsters
);
2126 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2127 if gGameSettings
.GameMode
= GM_CTF
then
2129 // Ôëàã Êðàñíîé êîìàíäû:
2130 SaveFlag(@gFlags
[FLAG_RED
]);
2131 // Ôëàã Ñèíåé êîìàíäû:
2132 SaveFlag(@gFlags
[FLAG_BLUE
]);
2136 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2137 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2139 // Î÷êè Êðàñíîé êîìàíäû:
2140 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2141 // Î÷êè Ñèíåé êîìàíäû:
2142 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2147 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2154 procedure LoadPanelArray(var panels
: TPanelArray
);
2156 PAMem
: TBinMemoryReader
;
2159 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2160 PAMem
:= TBinMemoryReader
.Create();
2161 PAMem
.LoadFromMemory(Mem
);
2163 for i
:= 0 to Length(panels
)-1 do
2164 if panels
[i
].SaveIt
then
2170 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2172 // Çàãðóæàåì ïàíåëü:
2173 panels
[i
].LoadState(PAMem
);
2176 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2180 procedure LoadFlag(flag
: PFlag
);
2184 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2186 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2188 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2189 Mem
.ReadByte(flag
^.RespawnType
);
2191 Mem
.ReadByte(flag
^.State
);
2192 // Íàïðàâëåíèå ôëàãà:
2195 flag
^.Direction
:= D_LEFT
2197 flag
^.Direction
:= D_RIGHT
;
2199 Obj_LoadState(@flag
^.Obj
, Mem
);
2206 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2207 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2208 LoadPanelArray(gWalls
);
2209 // Çàãðóæàåì ïàíåëè ôîíà:
2210 LoadPanelArray(gRenderBackgrounds
);
2211 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2212 LoadPanelArray(gRenderForegrounds
);
2213 // Çàãðóæàåì ïàíåëè âîäû:
2214 LoadPanelArray(gWater
);
2215 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2216 LoadPanelArray(gAcid1
);
2217 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2218 LoadPanelArray(gAcid2
);
2219 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2220 LoadPanelArray(gSteps
);
2221 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2222 LoadPanelArray(gLifts
);
2225 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2228 ///// Çàãðóæàåì ìóçûêó: /////
2229 // Ñèãíàòóðà ìóçûêè:
2231 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2233 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2236 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2237 Mem
.ReadString(str
);
2238 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2240 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2241 Mem
.ReadBoolean(boo
);
2242 // Çàïóñêàåì ýòó ìóçûêó:
2243 gMusic
.SetByName(str
);
2244 gMusic
.SpecPause
:= boo
;
2247 gMusic
.SetPosition(dw
);
2250 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2251 Mem
.ReadInt(gTotalMonsters
);
2254 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2255 if gGameSettings
.GameMode
= GM_CTF
then
2257 // Ôëàã Êðàñíîé êîìàíäû:
2258 LoadFlag(@gFlags
[FLAG_RED
]);
2259 // Ôëàã Ñèíåé êîìàíäû:
2260 LoadFlag(@gFlags
[FLAG_BLUE
]);
2264 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2265 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2267 // Î÷êè Êðàñíîé êîìàíäû:
2268 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2269 // Î÷êè Ñèíåé êîìàíäû:
2270 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);