2c611442025585a94d1c42d998ff5c900c6d2f6d
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
,
124 FLAGRECT
: TRectWH
= (X
:15; Y
:12; Width
:33; Height
:52);
125 MUSIC_SIGNATURE
= $4953554D; // 'MUSI'
126 FLAG_SIGNATURE
= $47414C46; // 'FLAG'
129 Textures
: TLevelTextureArray
;
130 RespawnPoints
: Array of TRespawnPoint
;
131 FlagPoints
: Array [FLAG_RED
..FLAG_BLUE
] of PFlagPoint
;
132 //DOMFlagPoints: Array of TFlagPoint;
135 function g_Map_IsSpecialTexture(Texture
: String): Boolean;
137 Result
:= (Texture
= TEXTURE_NAME_WATER
) or
138 (Texture
= TEXTURE_NAME_ACID1
) or
139 (Texture
= TEXTURE_NAME_ACID2
);
142 procedure CreateDoorMap();
144 PanelArray
: Array of record
150 a
, b
, c
, m
, i
, len
: Integer;
158 SetLength(PanelArray
, len
);
160 for a
:= 0 to High(gWalls
) do
161 if gWalls
[a
].Door
then
163 PanelArray
[i
].X
:= gWalls
[a
].X
;
164 PanelArray
[i
].Y
:= gWalls
[a
].Y
;
165 PanelArray
[i
].Width
:= gWalls
[a
].Width
;
166 PanelArray
[i
].Height
:= gWalls
[a
].Height
;
167 PanelArray
[i
].Active
:= True;
168 PanelArray
[i
].PanelID
:= a
;
174 SetLength(PanelArray
, len
);
185 SetLength(gDoorMap
, 0);
187 g_Game_SetLoadingText(_lc
[I_LOAD_DOOR_MAP
], i
-1, False);
190 if PanelArray
[a
].Active
then
192 PanelArray
[a
].Active
:= False;
193 m
:= Length(gDoorMap
);
194 SetLength(gDoorMap
, m
+1);
195 SetLength(gDoorMap
[m
], 1);
196 gDoorMap
[m
, 0] := PanelArray
[a
].PanelID
;
204 if PanelArray
[b
].Active
then
205 for c
:= 0 to High(gDoorMap
[m
]) do
206 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
207 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
208 g_CollideAround(PanelArray
[b
].X
, PanelArray
[b
].Y
,
209 PanelArray
[b
].Width
, PanelArray
[b
].Height
,
210 gWalls
[gDoorMap
[m
, c
]].X
,
211 gWalls
[gDoorMap
[m
, c
]].Y
,
212 gWalls
[gDoorMap
[m
, c
]].Width
,
213 gWalls
[gDoorMap
[m
, c
]].Height
) then
215 PanelArray
[b
].Active
:= False;
216 SetLength(gDoorMap
[m
],
217 Length(gDoorMap
[m
])+1);
218 gDoorMap
[m
, High(gDoorMap
[m
])] := PanelArray
[b
].PanelID
;
224 g_Game_StepLoading();
230 procedure CreateLiftMap();
232 PanelArray
: Array of record
237 a
, b
, c
, len
, i
, j
: Integer;
243 len
:= Length(gLifts
);
244 SetLength(PanelArray
, len
);
246 for a
:= 0 to len
-1 do
248 PanelArray
[a
].X
:= gLifts
[a
].X
;
249 PanelArray
[a
].Y
:= gLifts
[a
].Y
;
250 PanelArray
[a
].Width
:= gLifts
[a
].Width
;
251 PanelArray
[a
].Height
:= gLifts
[a
].Height
;
252 PanelArray
[a
].Active
:= True;
255 SetLength(gLiftMap
, len
);
258 g_Game_SetLoadingText(_lc
[I_LOAD_LIFT_MAP
], len
-1, False);
260 for a
:= 0 to len
-1 do
261 if PanelArray
[a
].Active
then
263 PanelArray
[a
].Active
:= False;
264 SetLength(gLiftMap
[i
], 32);
272 for b
:= 0 to len
-1 do
273 if PanelArray
[b
].Active
then
275 if g_CollideAround(PanelArray
[b
].X
,
278 PanelArray
[b
].Height
,
279 PanelArray
[gLiftMap
[i
, c
]].X
,
280 PanelArray
[gLiftMap
[i
, c
]].Y
,
281 PanelArray
[gLiftMap
[i
, c
]].Width
,
282 PanelArray
[gLiftMap
[i
, c
]].Height
) then
284 PanelArray
[b
].Active
:= False;
286 if j
> High(gLiftMap
[i
]) then
287 SetLength(gLiftMap
[i
],
288 Length(gLiftMap
[i
])+32);
297 SetLength(gLiftMap
[i
], j
+1);
300 g_Game_StepLoading();
303 SetLength(gLiftMap
, i
);
308 function CreatePanel(PanelRec
: TPanelRec_1
; AddTextures
: TAddTextureArray
;
309 CurTex
: Integer; sav
: Boolean): Integer;
312 panels
: ^TPanelArray
;
316 case PanelRec
.PanelType
of
317 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
320 panels
:= @gRenderBackgrounds
;
322 panels
:= @gRenderForegrounds
;
331 PANEL_LIFTUP
, PANEL_LIFTDOWN
, PANEL_LIFTLEFT
, PANEL_LIFTRIGHT
:
334 panels
:= @gBlockMon
;
339 len
:= Length(panels
^);
340 SetLength(panels
^, len
+ 1);
342 panels
^[len
] := TPanel
.Create(PanelRec
, AddTextures
,
345 panels
^[len
].SaveIt
:= True;
350 function CreateNullTexture(RecName
: String): Integer;
352 SetLength(Textures
, Length(Textures
)+1);
353 result
:= High(Textures
);
355 with Textures
[High(Textures
)] do
357 TextureName
:= RecName
;
361 TextureID
:= TEXTURE_NONE
;
365 function CreateTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
368 TextureData
: Pointer;
370 a
, ResLength
: Integer;
374 if Textures
<> nil then
375 for a
:= 0 to High(Textures
) do
376 if Textures
[a
].TextureName
= RecName
then
377 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
382 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
383 if (RecName
= TEXTURE_NAME_WATER
) or
384 (RecName
= TEXTURE_NAME_ACID1
) or
385 (RecName
= TEXTURE_NAME_ACID2
) then
387 SetLength(Textures
, Length(Textures
)+1);
389 with Textures
[High(Textures
)] do
391 TextureName
:= RecName
;
393 if TextureName
= TEXTURE_NAME_WATER
then
394 TextureID
:= TEXTURE_SPECIAL_WATER
396 if TextureName
= TEXTURE_NAME_ACID1
then
397 TextureID
:= TEXTURE_SPECIAL_ACID1
399 if TextureName
= TEXTURE_NAME_ACID2
then
400 TextureID
:= TEXTURE_SPECIAL_ACID2
;
405 result
:= High(Textures
);
409 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
410 WADName
:= g_ExtractWadName(RecName
);
412 WAD
:= TWADFile
.Create();
414 if WADName
<> '' then
415 WADName
:= GameDir
+'/wads/'+WADName
419 WAD
.ReadFile(WADName
);
421 if WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureData
, ResLength
) then
423 SetLength(Textures
, Length(Textures
)+1);
424 if not e_CreateTextureMem(TextureData
, ResLength
, Textures
[High(Textures
)].TextureID
) then
426 e_GetTextureSize(Textures
[High(Textures
)].TextureID
,
427 @Textures
[High(Textures
)].Width
,
428 @Textures
[High(Textures
)].Height
);
429 FreeMem(TextureData
);
430 Textures
[High(Textures
)].TextureName
:= RecName
;
431 Textures
[High(Textures
)].Anim
:= False;
433 result
:= High(Textures
);
435 else // Íåò òàêîãî ðåóñðñà â WAD'å
438 e_WriteLog(Format('Error loading texture %s', [RecName
]), MSG_WARNING
);
439 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
445 function CreateAnimTexture(RecName
: String; Map
: string; log
: Boolean): Integer;
450 TextureData
: Pointer;
454 TextureResource
: String;
455 _width
, _height
, _framecount
, _speed
: Integer;
456 _backanimation
: Boolean;
460 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
461 WADName
:= g_ExtractWadName(RecName
);
463 WAD
:= TWADFile
.Create();
465 if WADName
<> '' then
466 WADName
:= GameDir
+'/wads/'+WADName
470 WAD
.ReadFile(WADName
);
472 if not WAD
.GetResource(g_ExtractFilePathName(RecName
), TextureWAD
, ResLength
) then
476 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
477 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
485 if not WAD
.ReadMemory(TextureWAD
, ResLength
) then
492 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
493 if not WAD
.GetResource('TEXT/ANIM', TextData
, ResLength
) then
500 cfg
:= TConfig
.CreateMem(TextData
, ResLength
);
502 TextureResource
:= cfg
.ReadStr('', 'resource', '');
504 if TextureResource
= '' then
513 _width
:= cfg
.ReadInt('', 'framewidth', 0);
514 _height
:= cfg
.ReadInt('', 'frameheight', 0);
515 _framecount
:= cfg
.ReadInt('', 'framecount', 0);
516 _speed
:= cfg
.ReadInt('', 'waitcount', 0);
517 _backanimation
:= cfg
.ReadBool('', 'backanimation', False);
521 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
522 if not WAD
.GetResource('TEXTURES/'+TextureResource
, TextureData
, ResLength
) then
532 SetLength(Textures
, Length(Textures
)+1);
533 with Textures
[High(Textures
)] do
535 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
536 if g_Frames_CreateMemory(@FramesID
, '', TextureData
, ResLength
,
537 _width
, _height
, _framecount
, _backanimation
) then
539 TextureName
:= RecName
;
543 FramesCount
:= _framecount
;
546 result
:= High(Textures
);
550 e_WriteLog(Format('Error loading animation texture %s', [RecName
]), MSG_WARNING
);
557 procedure CreateItem(Item
: TItemRec_1
);
559 if g_Game_IsClient
then Exit
;
561 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) and
562 ByteBool(Item
.Options
and ITEM_OPTION_ONLYDM
) then
565 g_Items_Create(Item
.X
, Item
.Y
, Item
.ItemType
, ByteBool(Item
.Options
and ITEM_OPTION_FALL
),
566 gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
]);
569 procedure CreateArea(Area
: TAreaRec_1
);
574 case Area
.AreaType
of
575 AREA_DMPOINT
, AREA_PLAYERPOINT1
, AREA_PLAYERPOINT2
,
576 AREA_REDTEAMPOINT
, AREA_BLUETEAMPOINT
:
578 SetLength(RespawnPoints
, Length(RespawnPoints
)+1);
579 with RespawnPoints
[High(RespawnPoints
)] do
583 Direction
:= TDirection(Area
.Direction
);
585 case Area
.AreaType
of
586 AREA_DMPOINT
: PointType
:= RESPAWNPOINT_DM
;
587 AREA_PLAYERPOINT1
: PointType
:= RESPAWNPOINT_PLAYER1
;
588 AREA_PLAYERPOINT2
: PointType
:= RESPAWNPOINT_PLAYER2
;
589 AREA_REDTEAMPOINT
: PointType
:= RESPAWNPOINT_RED
;
590 AREA_BLUETEAMPOINT
: PointType
:= RESPAWNPOINT_BLUE
;
595 AREA_REDFLAG
, AREA_BLUEFLAG
:
597 if Area
.AreaType
= AREA_REDFLAG
then a
:= FLAG_RED
else a
:= FLAG_BLUE
;
599 if FlagPoints
[a
] <> nil then Exit
;
603 with FlagPoints
[a
]^ do
605 X
:= Area
.X
-FLAGRECT
.X
;
606 Y
:= Area
.Y
-FLAGRECT
.Y
;
607 Direction
:= TDirection(Area
.Direction
);
613 FLAG_RED
: g_Frames_Get(id
, 'FRAMES_FLAG_RED');
614 FLAG_BLUE
: g_Frames_Get(id
, 'FRAMES_FLAG_BLUE');
617 Animation
:= TAnimation
.Create(id
, True, 8);
618 Obj
.Rect
:= FLAGRECT
;
626 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
627 with DOMFlagPoints[High(DOMFlagPoints)] do
631 Direction := TDirection(Area.Direction);
634 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
639 procedure CreateTrigger(Trigger
: TTriggerRec_1
; fTexturePanel1Type
, fTexturePanel2Type
: Word);
643 if g_Game_IsClient
and not (Trigger
.TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) then Exit
;
649 Width
:= Trigger
.Width
;
650 Height
:= Trigger
.Height
;
651 Enabled
:= ByteBool(Trigger
.Enabled
);
652 TexturePanel
:= Trigger
.TexturePanel
;
653 TexturePanelType
:= fTexturePanel1Type
;
654 ShotPanelType
:= fTexturePanel2Type
;
655 TriggerType
:= Trigger
.TriggerType
;
656 ActivateType
:= Trigger
.ActivateType
;
657 Keys
:= Trigger
.Keys
;
658 Data
.Default
:= Trigger
.DATA
;
661 g_Triggers_Create(_trigger
);
664 procedure CreateMonster(monster
: TMonsterRec_1
);
668 if g_Game_IsClient
then Exit
;
670 if (gGameSettings
.GameType
= GT_SINGLE
)
671 or LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
) then
673 i
:= g_Monsters_Create(monster
.MonsterType
, monster
.X
, monster
.Y
,
674 TDirection(monster
.Direction
));
676 if gTriggers
<> nil then
677 for a
:= 0 to High(gTriggers
) do
678 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
679 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
680 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
681 gMonsters
[i
].AddTrigger(a
);
683 if monster
.MonsterType
<> MONSTER_BARREL
then
688 procedure g_Map_ReAdd_DieTriggers();
692 if g_Game_IsClient
then Exit
;
694 for i
:= 0 to High(gMonsters
) do
695 if gMonsters
[i
] <> nil then
697 gMonsters
[i
].ClearTriggers();
699 for a
:= 0 to High(gTriggers
) do
700 if gTriggers
[a
].TriggerType
in [TRIGGER_PRESS
,
701 TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
] then
702 if (gTriggers
[a
].Data
.MonsterID
-1) = gMonsters
[i
].StartID
then
703 gMonsters
[i
].AddTrigger(a
);
707 function extractWadName(resourceName
: string): string;
711 posN
:= Pos(':', resourceName
);
713 Result
:= Copy(resourceName
, 0, posN
-1)
718 procedure addResToExternalResList(res
: string);
720 res
:= extractWadName(res
);
721 if (res
<> '') and (gExternalResources
.IndexOf(res
) = -1) then
722 gExternalResources
.Add(res
);
725 procedure generateExternalResourcesList(mapReader
: TMapReader_1
);
727 textures
: TTexturesRec1Array
;
728 mapHeader
: TMapHeaderRec_1
;
730 resFile
: String = '';
732 if gExternalResources
= nil then
733 gExternalResources
:= TStringList
.Create
;
735 gExternalResources
.Clear
;
736 textures
:= mapReader
.GetTextures();
737 for i
:= 0 to High(textures
) do
739 addResToExternalResList(resFile
);
744 mapHeader
:= mapReader
.GetMapHeader
;
746 addResToExternalResList(mapHeader
.MusicName
);
747 addResToExternalResList(mapHeader
.SkyName
);
750 function g_Map_Load(Res
: String): Boolean;
752 DefaultMusRes
= 'Standart.wad:STDMUS\MUS1';
753 DefaultSkyRes
= 'Standart.wad:STDSKY\SKY0';
756 MapReader
: TMapReader_1
;
757 Header
: TMapHeaderRec_1
;
758 _textures
: TTexturesRec1Array
;
759 _texnummap
: array of Integer; // `_textures` -> `Textures`
760 panels
: TPanelsRec1Array
;
761 items
: TItemsRec1Array
;
762 monsters
: TMonsterRec1Array
;
763 areas
: TAreasRec1Array
;
764 triggers
: TTriggersRec1Array
;
767 AddTextures
: TAddTextureArray
;
768 texture
: TTextureRec_1
;
769 TriggersTable
: Array of record
770 TexturePanel
: Integer;
775 FileName
, mapResName
, s
, TexName
: String;
778 ok
, isAnim
, trigRef
: Boolean;
779 CurTex
, ntn
: Integer;
783 TriggersTable
:= nil;
784 FillChar(texture
, SizeOf(texture
), 0);
786 sfsGCDisable(); // temporary disable removing of temporary volumes
789 FileName
:= g_ExtractWadName(Res
);
790 e_WriteLog('Loading map WAD: '+FileName
, MSG_NOTIFY
);
791 g_Game_SetLoadingText(_lc
[I_LOAD_WAD_FILE
], 0, False);
793 WAD
:= TWADFile
.Create();
794 if not WAD
.ReadFile(FileName
) then
796 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [FileName
]));
800 //k8: why loader ignores path here?
801 mapResName
:= g_ExtractFileName(Res
);
802 if not WAD
.GetMapResource(mapResName
, Data
, Len
) then
804 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_RES
], [mapResName
]));
811 e_WriteLog('Loading map: '+mapResName
, MSG_NOTIFY
);
812 g_Game_SetLoadingText(_lc
[I_LOAD_MAP
], 0, False);
813 MapReader
:= TMapReader_1
.Create();
815 if not MapReader
.LoadMap(Data
) then
817 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]));
824 generateExternalResourcesList(MapReader
);
826 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], 0, False);
827 _textures
:= MapReader
.GetTextures();
830 // Äîáàâëåíèå òåêñòóð â Textures[]:
831 if _textures
<> nil then
833 e_WriteLog(' Loading textures:', MSG_NOTIFY
);
834 g_Game_SetLoadingText(_lc
[I_LOAD_TEXTURES
], High(_textures
), False);
835 SetLength(_texnummap
, length(_textures
));
837 for a
:= 0 to High(_textures
) do
840 CopyMemory(@s
[1], @_textures
[a
].Resource
[0], 64);
841 for b
:= 1 to Length(s
) do
847 e_WriteLog(Format(' Loading texture #%d: %s', [a
, s
]), MSG_NOTIFY
);
848 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
849 // Àíèìèðîâàííàÿ òåêñòóðà:
850 if ByteBool(_textures
[a
].Anim
) then
852 ntn
:= CreateAnimTexture(_textures
[a
].Resource
, FileName
, True);
855 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_ANIM
], [s
]));
856 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
859 else // Îáû÷íàÿ òåêñòóðà:
860 ntn
:= CreateTexture(_textures
[a
].Resource
, FileName
, True);
863 g_SimpleError(Format(_lc
[I_GAME_ERROR_TEXTURE_SIMPLE
], [s
]));
864 ntn
:= CreateNullTexture(_textures
[a
].Resource
);
867 _texnummap
[a
] := ntn
; // fix texture number
868 g_Game_StepLoading();
872 // Çàãðóçêà òðèããåðîâ:
873 gTriggerClientID
:= 0;
874 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
875 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS
], 0, False);
876 triggers
:= MapReader
.GetTriggers();
879 e_WriteLog(' Loading panels...', MSG_NOTIFY
);
880 g_Game_SetLoadingText(_lc
[I_LOAD_PANELS
], 0, False);
881 panels
:= MapReader
.GetPanels();
883 // check texture numbers for panels
884 for a
:= 0 to High(panels
) do
886 if panels
[a
].TextureNum
> High(_textures
) then
888 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR
);
892 panels
[a
].TextureNum
:= _texnummap
[panels
[a
].TextureNum
];
895 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
896 if triggers
<> nil then
898 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY
);
899 SetLength(TriggersTable
, Length(triggers
));
900 g_Game_SetLoadingText(_lc
[I_LOAD_TRIGGERS_TABLE
], High(TriggersTable
), False);
902 for a
:= 0 to High(TriggersTable
) do
904 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
905 TriggersTable
[a
].TexturePanel
:= triggers
[a
].TexturePanel
;
907 if triggers
[a
].TriggerType
in [TRIGGER_LIFTUP
, TRIGGER_LIFTDOWN
, TRIGGER_LIFT
] then
908 TriggersTable
[a
].LiftPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
910 TriggersTable
[a
].LiftPanel
:= -1;
912 if triggers
[a
].TriggerType
in [TRIGGER_OPENDOOR
,
913 TRIGGER_CLOSEDOOR
, TRIGGER_DOOR
, TRIGGER_DOOR5
,
914 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
] then
915 TriggersTable
[a
].DoorPanel
:= TTriggerData(triggers
[a
].DATA
).PanelID
917 TriggersTable
[a
].DoorPanel
:= -1;
919 if triggers
[a
].TriggerType
= TRIGGER_SHOT
then
920 TriggersTable
[a
].ShotPanel
:= TTriggerData(triggers
[a
].DATA
).ShotPanelID
922 TriggersTable
[a
].ShotPanel
:= -1;
924 g_Game_StepLoading();
929 if panels
<> nil then
931 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY
);
932 g_Game_SetLoadingText(_lc
[I_LOAD_LINK_TRIGGERS
], High(panels
), False);
934 for a
:= 0 to High(panels
) do
936 SetLength(AddTextures
, 0);
939 if _textures
<> nil then
941 texture
:= _textures
[panels
[a
].TextureNum
];
949 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
950 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
952 if (TriggersTable
<> nil) and (_textures
<> nil) then
953 for b
:= 0 to High(TriggersTable
) do
954 if (TriggersTable
[b
].TexturePanel
= a
)
955 or (TriggersTable
[b
].ShotPanel
= a
) then
964 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
966 CopyMemory(@s
[1], @texture
.Resource
[0], 64);
969 for c
:= Len
downto 1 do
977 // Ñïåö-òåêñòóðû çàïðåùåíû:
978 if g_Map_IsSpecialTexture(s
) then
981 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
982 ok
:= g_Texture_NumNameFindStart(s
);
984 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
985 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
988 k
:= NNF_NAME_BEFORE
;
989 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
990 while ok
or (k
= NNF_NAME_BEFORE
) or
991 (k
= NNF_NAME_EQUALS
) do
993 k
:= g_Texture_NumNameFindNext(TexName
);
995 if (k
= NNF_NAME_BEFORE
) or
996 (k
= NNF_NAME_AFTER
) then
998 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
999 if ByteBool(texture
.Anim
) then
1000 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1002 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1004 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1006 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1010 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1012 ok
:= CreateTexture(TexName
, FileName
, False) >= 0;
1014 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1016 ok
:= CreateAnimTexture(TexName
, FileName
, False) >= 0;
1020 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1023 for c
:= 0 to High(Textures
) do
1024 if Textures
[c
].TextureName
= TexName
then
1026 SetLength(AddTextures
, Length(AddTextures
)+1);
1027 AddTextures
[High(AddTextures
)].Texture
:= c
;
1028 AddTextures
[High(AddTextures
)].Anim
:= isAnim
;
1034 if k
= NNF_NAME_EQUALS
then
1036 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1037 SetLength(AddTextures
, Length(AddTextures
)+1);
1038 AddTextures
[High(AddTextures
)].Texture
:= panels
[a
].TextureNum
;
1039 AddTextures
[High(AddTextures
)].Anim
:= ByteBool(texture
.Anim
);
1040 CurTex
:= High(AddTextures
);
1048 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1049 end; // if ok - ññûëàþòñÿ òðèããåðû
1053 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1054 SetLength(AddTextures
, 1);
1055 AddTextures
[0].Texture
:= panels
[a
].TextureNum
;
1056 AddTextures
[0].Anim
:= ByteBool(texture
.Anim
);
1060 //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);
1062 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1063 PanelID
:= CreatePanel(panels
[a
], AddTextures
, CurTex
, trigRef
);
1065 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1066 if TriggersTable
<> nil then
1067 for b
:= 0 to High(TriggersTable
) do
1069 // Òðèããåð äâåðè/ëèôòà:
1070 if (TriggersTable
[b
].LiftPanel
= a
) or
1071 (TriggersTable
[b
].DoorPanel
= a
) then
1072 TTriggerData(triggers
[b
].DATA
).PanelID
:= PanelID
;
1073 // Òðèããåð ñìåíû òåêñòóðû:
1074 if TriggersTable
[b
].TexturePanel
= a
then
1075 triggers
[b
].TexturePanel
:= PanelID
;
1076 // Òðèããåð "Òóðåëü":
1077 if TriggersTable
[b
].ShotPanel
= a
then
1078 TTriggerData(triggers
[b
].DATA
).ShotPanelID
:= PanelID
;
1081 g_Game_StepLoading();
1085 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1086 if (triggers
<> nil) and not gLoadGameMode
then
1088 e_WriteLog(' Creating triggers...', MSG_NOTIFY
);
1089 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_TRIGGERS
], 0, False);
1090 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1091 for a
:= 0 to High(triggers
) do
1093 if triggers
[a
].TexturePanel
<> -1 then
1094 b
:= panels
[TriggersTable
[a
].TexturePanel
].PanelType
1097 if (triggers
[a
].TriggerType
= TRIGGER_SHOT
) and
1098 (TTriggerData(triggers
[a
].DATA
).ShotPanelID
<> -1) then
1099 c
:= panels
[TriggersTable
[a
].ShotPanel
].PanelType
1102 CreateTrigger(triggers
[a
], b
, c
);
1106 // Çàãðóçêà ïðåäìåòîâ:
1107 e_WriteLog(' Loading triggers...', MSG_NOTIFY
);
1108 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS
], 0, False);
1109 items
:= MapReader
.GetItems();
1111 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1112 if (items
<> nil) and not gLoadGameMode
then
1114 e_WriteLog(' Spawning items...', MSG_NOTIFY
);
1115 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_ITEMS
], 0, False);
1116 for a
:= 0 to High(items
) do
1117 CreateItem(Items
[a
]);
1120 // Çàãðóçêà îáëàñòåé:
1121 e_WriteLog(' Loading areas...', MSG_NOTIFY
);
1122 g_Game_SetLoadingText(_lc
[I_LOAD_AREAS
], 0, False);
1123 areas
:= MapReader
.GetAreas();
1125 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1126 if areas
<> nil then
1128 e_WriteLog(' Creating areas...', MSG_NOTIFY
);
1129 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_AREAS
], 0, False);
1130 for a
:= 0 to High(areas
) do
1131 CreateArea(areas
[a
]);
1134 // Çàãðóçêà ìîíñòðîâ:
1135 e_WriteLog(' Loading monsters...', MSG_NOTIFY
);
1136 g_Game_SetLoadingText(_lc
[I_LOAD_MONSTERS
], 0, False);
1137 monsters
:= MapReader
.GetMonsters();
1139 gTotalMonsters
:= 0;
1141 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1142 if (monsters
<> nil) and not gLoadGameMode
then
1144 e_WriteLog(' Spawning monsters...', MSG_NOTIFY
);
1145 g_Game_SetLoadingText(_lc
[I_LOAD_CREATE_MONSTERS
], 0, False);
1146 for a
:= 0 to High(monsters
) do
1147 CreateMonster(monsters
[a
]);
1150 // Çàãðóçêà îïèñàíèÿ êàðòû:
1151 e_WriteLog(' Reading map info...', MSG_NOTIFY
);
1152 g_Game_SetLoadingText(_lc
[I_LOAD_MAP_HEADER
], 0, False);
1153 Header
:= MapReader
.GetMapHeader();
1159 Name
:= Header
.MapName
;
1160 Description
:= Header
.MapDescription
;
1161 Author
:= Header
.MapAuthor
;
1162 MusicName
:= Header
.MusicName
;
1163 SkyName
:= Header
.SkyName
;
1164 Height
:= Header
.Height
;
1165 Width
:= Header
.Width
;
1169 if gMapInfo
.SkyName
<> '' then
1171 e_WriteLog(' Loading sky: ' + gMapInfo
.SkyName
, MSG_NOTIFY
);
1172 g_Game_SetLoadingText(_lc
[I_LOAD_SKY
], 0, False);
1173 FileName
:= g_ExtractWadName(gMapInfo
.SkyName
);
1175 if FileName
<> '' then
1176 FileName
:= GameDir
+'/wads/'+FileName
1179 FileName
:= g_ExtractWadName(Res
);
1182 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.SkyName
);
1183 if g_Texture_CreateWAD(BackID
, s
) then
1185 g_Game_SetupScreenSize();
1188 g_FatalError(Format(_lc
[I_GAME_ERROR_SKY
], [s
]));
1193 if gMapInfo
.MusicName
<> '' then
1195 e_WriteLog(' Loading music: ' + gMapInfo
.MusicName
, MSG_NOTIFY
);
1196 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1197 FileName
:= g_ExtractWadName(gMapInfo
.MusicName
);
1199 if FileName
<> '' then
1200 FileName
:= GameDir
+'/wads/'+FileName
1203 FileName
:= g_ExtractWadName(Res
);
1206 s
:= FileName
+':'+g_ExtractFilePathName(gMapInfo
.MusicName
);
1207 if g_Sound_CreateWADEx(gMapInfo
.MusicName
, s
, True) then
1210 g_FatalError(Format(_lc
[I_GAME_ERROR_MUSIC
], [s
]));
1213 // Îñòàëüíûå óñòàíâêè:
1221 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1222 if not gLoadGameMode
then
1225 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1231 TriggersTable
:= nil;
1234 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1235 if ok
and (not gLoadGameMode
) then
1237 gMusic
.SetByName(gMapInfo
.MusicName
);
1241 gMusic
.SetByName('');
1243 sfsGCEnable(); // enable releasing unused volumes
1246 e_WriteLog('Done loading map.', MSG_NOTIFY
);
1250 function g_Map_GetMapInfo(Res
: String): TMapInfo
;
1253 MapReader
: TMapReader_1
;
1254 Header
: TMapHeaderRec_1
;
1259 FillChar(Result
, SizeOf(Result
), 0);
1260 FileName
:= g_ExtractWadName(Res
);
1262 WAD
:= TWADFile
.Create();
1263 if not WAD
.ReadFile(FileName
) then
1269 //k8: it ignores path again
1270 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
1278 MapReader
:= TMapReader_1
.Create();
1280 if not MapReader
.LoadMap(Data
) then
1282 g_Console_Add(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Res
]), True);
1283 ZeroMemory(@Header
, SizeOf(Header
));
1284 Result
.Name
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1285 Result
.Description
:= _lc
[I_GAME_ERROR_MAP_SELECT
];
1289 Header
:= MapReader
.GetMapHeader();
1290 Result
.Name
:= Header
.MapName
;
1291 Result
.Description
:= Header
.MapDescription
;
1298 Result
.Author
:= Header
.MapAuthor
;
1299 Result
.Height
:= Header
.Height
;
1300 Result
.Width
:= Header
.Width
;
1303 function g_Map_GetMapsList(WADName
: string): SArray
;
1310 WAD
:= TWADFile
.Create();
1311 if not WAD
.ReadFile(WADName
) then
1316 ResList
:= WAD
.GetMapResources();
1317 if ResList
<> nil then
1319 for a
:= 0 to High(ResList
) do
1321 SetLength(Result
, Length(Result
)+1);
1322 Result
[High(Result
)] := ResList
[a
];
1328 function g_Map_Exist(Res
: string): Boolean;
1331 FileName
, mnn
: string;
1337 FileName
:= addWadExtension(g_ExtractWadName(Res
));
1339 WAD
:= TWADFile
.Create
;
1340 if not WAD
.ReadFile(FileName
) then
1346 ResList
:= WAD
.GetMapResources();
1349 mnn
:= g_ExtractFileName(Res
);
1350 if ResList
<> nil then
1351 for a
:= 0 to High(ResList
) do if StrEquCI1251(ResList
[a
], mnn
) then
1358 procedure g_Map_Free();
1362 procedure FreePanelArray(var panels
: TPanelArray
);
1367 if panels
<> nil then
1369 for i
:= 0 to High(panels
) do
1382 RespawnPoints
:= nil;
1383 if FlagPoints
[FLAG_RED
] <> nil then
1385 Dispose(FlagPoints
[FLAG_RED
]);
1386 FlagPoints
[FLAG_RED
] := nil;
1388 if FlagPoints
[FLAG_BLUE
] <> nil then
1390 Dispose(FlagPoints
[FLAG_BLUE
]);
1391 FlagPoints
[FLAG_BLUE
] := nil;
1393 //DOMFlagPoints := nil;
1397 if Textures
<> nil then
1399 for a
:= 0 to High(Textures
) do
1400 if not g_Map_IsSpecialTexture(Textures
[a
].TextureName
) then
1401 if Textures
[a
].Anim
then
1402 g_Frames_DeleteByID(Textures
[a
].FramesID
)
1404 if Textures
[a
].TextureID
<> TEXTURE_NONE
then
1405 e_DeleteTexture(Textures
[a
].TextureID
);
1410 FreePanelArray(gWalls
);
1411 FreePanelArray(gRenderBackgrounds
);
1412 FreePanelArray(gRenderForegrounds
);
1413 FreePanelArray(gWater
);
1414 FreePanelArray(gAcid1
);
1415 FreePanelArray(gAcid2
);
1416 FreePanelArray(gSteps
);
1417 FreePanelArray(gLifts
);
1418 FreePanelArray(gBlockMon
);
1420 if BackID
<> DWORD(-1) then
1424 e_DeleteTexture(BackID
);
1425 BackID
:= DWORD(-1);
1428 g_Game_StopAllSounds(False);
1430 g_Sound_Delete(gMapInfo
.MusicName
);
1432 gMapInfo
.Name
:= '';
1433 gMapInfo
.Description
:= '';
1434 gMapInfo
.MusicName
:= '';
1435 gMapInfo
.Height
:= 0;
1436 gMapInfo
.Width
:= 0;
1442 procedure g_Map_Update();
1448 procedure UpdatePanelArray(var panels
: TPanelArray
);
1453 if panels
<> nil then
1454 for i
:= 0 to High(panels
) do
1459 UpdatePanelArray(gWalls
);
1460 UpdatePanelArray(gRenderBackgrounds
);
1461 UpdatePanelArray(gRenderForegrounds
);
1462 UpdatePanelArray(gWater
);
1463 UpdatePanelArray(gAcid1
);
1464 UpdatePanelArray(gAcid2
);
1465 UpdatePanelArray(gSteps
);
1467 if gGameSettings
.GameMode
= GM_CTF
then
1469 for a
:= FLAG_RED
to FLAG_BLUE
do
1470 if not (gFlags
[a
].State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
1473 if gFlags
[a
].Animation
<> nil then
1474 gFlags
[a
].Animation
.Update();
1476 m
:= g_Obj_Move(@Obj
, True, True);
1478 if gTime
mod (GAME_TICK
*2) <> 0 then
1481 // Ñîïðîòèâëåíèå âîçäóõà:
1482 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1484 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1485 if ((Count
= 0) or ByteBool(m
and MOVE_FALLOUT
)) and g_Game_IsServer
then
1488 gFlags
[a
].CaptureTime
:= 0;
1489 if a
= FLAG_RED
then
1490 s
:= _lc
[I_PLAYER_FLAG_RED
]
1492 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
1493 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
1495 if g_Game_IsNet
then
1496 MH_SEND_FlagEvent(FLAG_STATE_RETURNED
, a
, 0);
1503 // Èãðîê áåðåò ôëàã:
1504 if gPlayers
<> nil then
1506 j
:= Random(Length(gPlayers
)) - 1;
1508 for d
:= 0 to High(gPlayers
) do
1511 if j
> High(gPlayers
) then
1514 if gPlayers
[j
] <> nil then
1515 if gPlayers
[j
].Live
and
1516 g_Obj_Collide(@Obj
, @gPlayers
[j
].Obj
) then
1518 if gPlayers
[j
].GetFlag(a
) then
1527 procedure g_Map_DrawPanels(PanelType
: Word);
1529 procedure DrawPanels(var panels
: TPanelArray
;
1530 drawDoors
: Boolean = False);
1535 if panels
<> nil then
1536 for a
:= 0 to High(panels
) do
1537 if not (drawDoors
xor panels
[a
].Door
) then
1543 PANEL_WALL
: DrawPanels(gWalls
);
1544 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
1545 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
1546 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
1547 PANEL_WATER
: DrawPanels(gWater
);
1548 PANEL_ACID1
: DrawPanels(gAcid1
);
1549 PANEL_ACID2
: DrawPanels(gAcid2
);
1550 PANEL_STEP
: DrawPanels(gSteps
);
1554 procedure g_Map_DrawBack(dx
, dy
: Integer);
1556 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
1557 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
1559 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
1562 function g_Map_CollidePanel(X
, Y
: Integer; Width
, Height
: Word;
1563 PanelType
: Word; b1x3
: Boolean): Boolean;
1569 if WordBool(PanelType
and PANEL_WALL
) then
1570 if gWalls
<> nil then
1575 if gWalls
[a
].Enabled
and
1576 g_Collide(X
, Y
, Width
, Height
,
1577 gWalls
[a
].X
, gWalls
[a
].Y
,
1578 gWalls
[a
].Width
, gWalls
[a
].Height
) then
1585 if WordBool(PanelType
and PANEL_WATER
) then
1586 if gWater
<> nil then
1591 if g_Collide(X
, Y
, Width
, Height
,
1592 gWater
[a
].X
, gWater
[a
].Y
,
1593 gWater
[a
].Width
, gWater
[a
].Height
) then
1600 if WordBool(PanelType
and PANEL_ACID1
) then
1601 if gAcid1
<> nil then
1606 if g_Collide(X
, Y
, Width
, Height
,
1607 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1608 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1615 if WordBool(PanelType
and PANEL_ACID2
) then
1616 if gAcid2
<> nil then
1621 if g_Collide(X
, Y
, Width
, Height
,
1622 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1623 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1630 if WordBool(PanelType
and PANEL_STEP
) then
1631 if gSteps
<> nil then
1636 if g_Collide(X
, Y
, Width
, Height
,
1637 gSteps
[a
].X
, gSteps
[a
].Y
,
1638 gSteps
[a
].Width
, gSteps
[a
].Height
) then
1645 if WordBool(PanelType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
1646 if gLifts
<> nil then
1651 if ((WordBool(PanelType
and (PANEL_LIFTUP
)) and (gLifts
[a
].LiftType
= 0)) or
1652 (WordBool(PanelType
and (PANEL_LIFTDOWN
)) and (gLifts
[a
].LiftType
= 1)) or
1653 (WordBool(PanelType
and (PANEL_LIFTLEFT
)) and (gLifts
[a
].LiftType
= 2)) or
1654 (WordBool(PanelType
and (PANEL_LIFTRIGHT
)) and (gLifts
[a
].LiftType
= 3))) and
1655 g_Collide(X
, Y
, Width
, Height
,
1656 gLifts
[a
].X
, gLifts
[a
].Y
,
1657 gLifts
[a
].Width
, gLifts
[a
].Height
) then
1664 if WordBool(PanelType
and PANEL_BLOCKMON
) then
1665 if gBlockMon
<> nil then
1667 h
:= High(gBlockMon
);
1671 ((gBlockMon
[a
].Width
+ gBlockMon
[a
].Height
) >= 64) ) and
1672 g_Collide(X
, Y
, Width
, Height
,
1673 gBlockMon
[a
].X
, gBlockMon
[a
].Y
,
1674 gBlockMon
[a
].Width
, gBlockMon
[a
].Height
) then
1682 function g_Map_CollideLiquid_Texture(X
, Y
: Integer; Width
, Height
: Word): DWORD
;
1686 Result
:= TEXTURE_NONE
;
1688 if gWater
<> nil then
1693 if g_Collide(X
, Y
, Width
, Height
,
1694 gWater
[a
].X
, gWater
[a
].Y
,
1695 gWater
[a
].Width
, gWater
[a
].Height
) then
1697 Result
:= gWater
[a
].GetTextureID();
1702 if gAcid1
<> nil then
1707 if g_Collide(X
, Y
, Width
, Height
,
1708 gAcid1
[a
].X
, gAcid1
[a
].Y
,
1709 gAcid1
[a
].Width
, gAcid1
[a
].Height
) then
1711 Result
:= gAcid1
[a
].GetTextureID();
1716 if gAcid2
<> nil then
1721 if g_Collide(X
, Y
, Width
, Height
,
1722 gAcid2
[a
].X
, gAcid2
[a
].Y
,
1723 gAcid2
[a
].Width
, gAcid2
[a
].Height
) then
1725 Result
:= gAcid2
[a
].GetTextureID();
1731 procedure g_Map_EnableWall(ID
: DWORD
);
1736 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, True);
1738 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1742 procedure g_Map_DisableWall(ID
: DWORD
);
1747 g_Mark(X
, Y
, Width
, Height
, MARK_DOOR
, False);
1749 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1753 procedure g_Map_SwitchTexture(PanelType
: Word; ID
: DWORD
; AnimLoop
: Byte = 0);
1758 PANEL_WALL
, PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
1761 tp
:= gRenderForegrounds
[ID
];
1763 tp
:= gRenderBackgrounds
[ID
];
1776 tp
.NextTexture(AnimLoop
);
1777 if g_Game_IsServer
and g_Game_IsNet
then
1778 MH_SEND_PanelTexture(PanelType
, ID
, AnimLoop
);
1781 procedure g_Map_SetLift(ID
: DWORD
; t
: Integer);
1783 if gLifts
[ID
].LiftType
= t
then
1790 g_Mark(X
, Y
, Width
, Height
, MARK_LIFT
, False);
1792 if LiftType
= 0 then
1793 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTUP
, True)
1794 else if LiftType
= 1 then
1795 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTDOWN
, True)
1796 else if LiftType
= 2 then
1797 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTLEFT
, True)
1798 else if LiftType
= 3 then
1799 g_Mark(X
, Y
, Width
, Height
, MARK_LIFTRIGHT
, True);
1801 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_PanelState(PanelType
, ID
);
1805 function g_Map_GetPoint(PointType
: Byte; var RespawnPoint
: TRespawnPoint
): Boolean;
1808 PointsArray
: Array of TRespawnPoint
;
1811 SetLength(PointsArray
, 0);
1813 if RespawnPoints
= nil then
1816 for a
:= 0 to High(RespawnPoints
) do
1817 if RespawnPoints
[a
].PointType
= PointType
then
1819 SetLength(PointsArray
, Length(PointsArray
)+1);
1820 PointsArray
[High(PointsArray
)] := RespawnPoints
[a
];
1823 if PointsArray
= nil then
1826 RespawnPoint
:= PointsArray
[Random(Length(PointsArray
))];
1830 function g_Map_GetPointCount(PointType
: Byte): Word;
1836 if RespawnPoints
= nil then
1839 for a
:= 0 to High(RespawnPoints
) do
1840 if RespawnPoints
[a
].PointType
= PointType
then
1841 Result
:= Result
+ 1;
1844 function g_Map_HaveFlagPoints(): Boolean;
1846 Result
:= (FlagPoints
[FLAG_RED
] <> nil) and (FlagPoints
[FLAG_BLUE
] <> nil);
1849 procedure g_Map_ResetFlag(Flag
: Byte);
1851 with gFlags
[Flag
] do
1857 Direction
:= D_LEFT
;
1858 State
:= FLAG_STATE_NONE
;
1859 if FlagPoints
[Flag
] <> nil then
1861 Obj
.X
:= FlagPoints
[Flag
]^.X
;
1862 Obj
.Y
:= FlagPoints
[Flag
]^.Y
;
1863 Direction
:= FlagPoints
[Flag
]^.Direction
;
1864 State
:= FLAG_STATE_NORMAL
;
1870 procedure g_Map_DrawFlags();
1873 Mirror
: TMirrorType
;
1875 if gGameSettings
.GameMode
<> GM_CTF
then
1878 for i
:= FLAG_RED
to FLAG_BLUE
do
1880 if State
<> FLAG_STATE_CAPTURED
then
1882 if State
= FLAG_STATE_NONE
then
1885 if Direction
= D_LEFT
then
1887 Mirror
:= M_HORIZONTAL
;
1896 Animation
.Draw(Obj
.X
+dx
, Obj
.Y
+1, Mirror
);
1898 if g_debug_Frames
then
1900 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
1902 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
1903 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
1909 procedure g_Map_SaveState(Var Mem
: TBinMemoryWriter
);
1916 procedure SavePanelArray(var panels
: TPanelArray
);
1918 PAMem
: TBinMemoryWriter
;
1921 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
1922 PAMem
:= TBinMemoryWriter
.Create((Length(panels
)+1) * 40);
1925 while i
< Length(panels
) do
1927 if panels
[i
].SaveIt
then
1931 // Ñîõðàíÿåì ïàíåëü:
1932 panels
[i
].SaveState(PAMem
);
1937 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
1938 PAMem
.SaveToMemory(Mem
);
1942 procedure SaveFlag(flag
: PFlag
);
1945 dw
:= FLAG_SIGNATURE
; // 'FLAG'
1947 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
1948 Mem
.WriteByte(flag
^.RespawnType
);
1950 Mem
.WriteByte(flag
^.State
);
1951 // Íàïðàâëåíèå ôëàãà:
1952 if flag
^.Direction
= D_LEFT
then
1958 Obj_SaveState(@flag
^.Obj
, Mem
);
1962 Mem
:= TBinMemoryWriter
.Create(1024 * 1024); // 1 MB
1964 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
1965 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
1966 SavePanelArray(gWalls
);
1967 // Ñîõðàíÿåì ïàíåëè ôîíà:
1968 SavePanelArray(gRenderBackgrounds
);
1969 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
1970 SavePanelArray(gRenderForegrounds
);
1971 // Ñîõðàíÿåì ïàíåëè âîäû:
1972 SavePanelArray(gWater
);
1973 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
1974 SavePanelArray(gAcid1
);
1975 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
1976 SavePanelArray(gAcid2
);
1977 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
1978 SavePanelArray(gSteps
);
1979 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
1980 SavePanelArray(gLifts
);
1983 ///// Ñîõðàíÿåì ìóçûêó: /////
1984 // Ñèãíàòóðà ìóçûêè:
1985 dw
:= MUSIC_SIGNATURE
; // 'MUSI'
1988 Assert(gMusic
<> nil, 'g_Map_SaveState: gMusic = nil');
1989 if gMusic
.NoMusic
then
1993 Mem
.WriteString(str
, 64);
1994 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
1995 dw
:= gMusic
.GetPosition();
1997 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
1998 boo
:= gMusic
.SpecPause
;
1999 Mem
.WriteBoolean(boo
);
2002 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2003 Mem
.WriteInt(gTotalMonsters
);
2006 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2007 if gGameSettings
.GameMode
= GM_CTF
then
2009 // Ôëàã Êðàñíîé êîìàíäû:
2010 SaveFlag(@gFlags
[FLAG_RED
]);
2011 // Ôëàã Ñèíåé êîìàíäû:
2012 SaveFlag(@gFlags
[FLAG_BLUE
]);
2016 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2017 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2019 // Î÷êè Êðàñíîé êîìàíäû:
2020 Mem
.WriteSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2021 // Î÷êè Ñèíåé êîìàíäû:
2022 Mem
.WriteSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);
2027 procedure g_Map_LoadState(Var Mem
: TBinMemoryReader
);
2034 procedure LoadPanelArray(var panels
: TPanelArray
);
2036 PAMem
: TBinMemoryReader
;
2039 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2040 PAMem
:= TBinMemoryReader
.Create();
2041 PAMem
.LoadFromMemory(Mem
);
2043 for i
:= 0 to Length(panels
)-1 do
2044 if panels
[i
].SaveIt
then
2050 raise EBinSizeError
.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2052 // Çàãðóæàåì ïàíåëü:
2053 panels
[i
].LoadState(PAMem
);
2056 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2060 procedure LoadFlag(flag
: PFlag
);
2064 if dw
<> FLAG_SIGNATURE
then // 'FLAG'
2066 raise EBinSizeError
.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2068 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2069 Mem
.ReadByte(flag
^.RespawnType
);
2071 Mem
.ReadByte(flag
^.State
);
2072 // Íàïðàâëåíèå ôëàãà:
2075 flag
^.Direction
:= D_LEFT
2077 flag
^.Direction
:= D_RIGHT
;
2079 Obj_LoadState(@flag
^.Obj
, Mem
);
2086 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2087 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2088 LoadPanelArray(gWalls
);
2089 // Çàãðóæàåì ïàíåëè ôîíà:
2090 LoadPanelArray(gRenderBackgrounds
);
2091 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2092 LoadPanelArray(gRenderForegrounds
);
2093 // Çàãðóæàåì ïàíåëè âîäû:
2094 LoadPanelArray(gWater
);
2095 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2096 LoadPanelArray(gAcid1
);
2097 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2098 LoadPanelArray(gAcid2
);
2099 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2100 LoadPanelArray(gSteps
);
2101 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2102 LoadPanelArray(gLifts
);
2105 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2108 ///// Çàãðóæàåì ìóçûêó: /////
2109 // Ñèãíàòóðà ìóçûêè:
2111 if dw
<> MUSIC_SIGNATURE
then // 'MUSI'
2113 raise EBinSizeError
.Create('g_Map_LoadState: Wrong Music Signature');
2116 Assert(gMusic
<> nil, 'g_Map_LoadState: gMusic = nil');
2117 Mem
.ReadString(str
);
2118 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2120 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2121 Mem
.ReadBoolean(boo
);
2122 // Çàïóñêàåì ýòó ìóçûêó:
2123 gMusic
.SetByName(str
);
2124 gMusic
.SpecPause
:= boo
;
2127 gMusic
.SetPosition(dw
);
2130 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2131 Mem
.ReadInt(gTotalMonsters
);
2134 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2135 if gGameSettings
.GameMode
= GM_CTF
then
2137 // Ôëàã Êðàñíîé êîìàíäû:
2138 LoadFlag(@gFlags
[FLAG_RED
]);
2139 // Ôëàã Ñèíåé êîìàíäû:
2140 LoadFlag(@gFlags
[FLAG_BLUE
]);
2144 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2145 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2147 // Î÷êè Êðàñíîé êîìàíäû:
2148 Mem
.ReadSmallInt(gTeamStat
[TEAM_RED
].Goals
);
2149 // Î÷êè Ñèíåé êîìàíäû:
2150 Mem
.ReadSmallInt(gTeamStat
[TEAM_BLUE
].Goals
);