DEADSOFTWARE

more map grid code
[d2df-sdl.git] / src / game / g_map.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
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.
7 *
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.
12 *
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/>.
15 *)
16 {$MODE DELPHI}
17 {$modeswitch nestedprocvars}
18 unit g_map;
20 interface
22 uses
23 e_graphics, g_basic, MAPSTRUCT, g_textures, Classes,
24 g_phys, wadreader, BinEditor, g_panel, g_grid, md5;
26 type
27 TMapInfo = record
28 Map: String;
29 Name: String;
30 Description: String;
31 Author: String;
32 MusicName: String;
33 SkyName: String;
34 Height: Word;
35 Width: Word;
36 end;
38 PRespawnPoint = ^TRespawnPoint;
39 TRespawnPoint = record
40 X, Y: Integer;
41 Direction: TDirection;
42 PointType: Byte;
43 end;
45 PFlagPoint = ^TFlagPoint;
46 TFlagPoint = TRespawnPoint;
48 PFlag = ^TFlag;
49 TFlag = record
50 Obj: TObj;
51 RespawnType: Byte;
52 State: Byte;
53 Count: Integer;
54 CaptureTime: LongWord;
55 Animation: TAnimation;
56 Direction: TDirection;
57 end;
59 function g_Map_Load(Res: String): Boolean;
60 function g_Map_GetMapInfo(Res: String): TMapInfo;
61 function g_Map_GetMapsList(WADName: String): SArray;
62 function g_Map_Exist(Res: String): Boolean;
63 procedure g_Map_Free();
64 procedure g_Map_Update();
66 procedure g_Map_DrawPanels(x0, y0, wdt, hgt: Integer; PanelType: Word);
68 procedure g_Map_DrawBack(dx, dy: Integer);
69 function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word;
70 PanelType: Word; b1x3: Boolean): Boolean;
71 function g_Map_CollideLiquid_Texture(X, Y: Integer; Width, Height: Word): DWORD;
72 procedure g_Map_EnableWall(ID: DWORD);
73 procedure g_Map_DisableWall(ID: DWORD);
74 procedure g_Map_SwitchTexture(PanelType: Word; ID: DWORD; AnimLoop: Byte = 0);
75 procedure g_Map_SetLift(ID: DWORD; t: Integer);
76 procedure g_Map_ReAdd_DieTriggers();
77 function g_Map_IsSpecialTexture(Texture: String): Boolean;
79 function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
80 function g_Map_GetPointCount(PointType: Byte): Word;
82 function g_Map_HaveFlagPoints(): Boolean;
84 procedure g_Map_ResetFlag(Flag: Byte);
85 procedure g_Map_DrawFlags();
87 function g_Map_PanelForPID(PanelID: Integer; var PanelArrayID: Integer): PPanel;
89 procedure g_Map_SaveState(Var Mem: TBinMemoryWriter);
90 procedure g_Map_LoadState(Var Mem: TBinMemoryReader);
92 procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
94 const
95 RESPAWNPOINT_PLAYER1 = 1;
96 RESPAWNPOINT_PLAYER2 = 2;
97 RESPAWNPOINT_DM = 3;
98 RESPAWNPOINT_RED = 4;
99 RESPAWNPOINT_BLUE = 5;
101 FLAG_NONE = 0;
102 FLAG_RED = 1;
103 FLAG_BLUE = 2;
104 FLAG_DOM = 3;
106 FLAG_STATE_NONE = 0;
107 FLAG_STATE_NORMAL = 1;
108 FLAG_STATE_DROPPED = 2;
109 FLAG_STATE_CAPTURED = 3;
110 FLAG_STATE_SCORED = 4; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
111 FLAG_STATE_RETURNED = 5; // Äëÿ ýâåíòîâ ÷åðåç ñåòêó.
113 FLAG_TIME = 720; // 20 seconds
115 SKY_STRETCH: Single = 1.5;
117 var
118 gWalls: TPanelArray;
119 gRenderBackgrounds: TPanelArray;
120 gRenderForegrounds: TPanelArray;
121 gWater, gAcid1, gAcid2: TPanelArray;
122 gSteps: TPanelArray;
123 gLifts: TPanelArray;
124 gBlockMon: TPanelArray;
125 gFlags: array [FLAG_RED..FLAG_BLUE] of TFlag;
126 //gDOMFlags: array of TFlag;
127 gMapInfo: TMapInfo;
128 gBackSize: TPoint;
129 gDoorMap: array of array of DWORD;
130 gLiftMap: array of array of DWORD;
131 gWADHash: TMD5Digest;
132 BackID: DWORD = DWORD(-1);
133 gExternalResources: TStringList;
135 implementation
137 uses
138 g_main, e_log, SysUtils, g_items, g_gfx, g_console,
139 GL, GLExt, g_weapons, g_game, g_sound, e_sound, CONFIG,
140 g_options, MAPREADER, g_triggers, g_player, MAPDEF,
141 Math, g_monsters, g_saveload, g_language, g_netmsg,
142 utils, sfs,
143 ImagingTypes, Imaging, ImagingUtility,
144 ImagingGif, ImagingNetworkGraphics;
146 const
147 FLAGRECT: TRectWH = (X:15; Y:12; Width:33; Height:52);
148 MUSIC_SIGNATURE = $4953554D; // 'MUSI'
149 FLAG_SIGNATURE = $47414C46; // 'FLAG'
151 GridTagInvalid = -1;
152 GridTagWallDoor = 0;
153 GridTagBack = 1;
154 GridTagFore = 2;
155 GridTagWater = 3;
156 GridTagAcid1 = 4;
157 GridTagAcid2 = 5;
158 GridTagStep = 6;
159 GridTagLift = 7;
160 GridTagBlockMon = 8;
163 function panelTypeToTag (panelType: Word): Integer;
164 begin
165 case panelType of
166 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: result := GridTagWallDoor; // gWalls
167 PANEL_BACK: result := GridTagBack; // gRenderBackgrounds
168 PANEL_FORE: result := GridTagFore; // gRenderForegrounds
169 PANEL_WATER: result := GridTagWater; // gWater
170 PANEL_ACID1: result := GridTagAcid1; // gAcid1
171 PANEL_ACID2: result := GridTagAcid2; // gAcid2
172 PANEL_STEP: result := GridTagStep; // gSteps
173 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT: result := GridTagLift; // gLifts -- this is for all lifts
174 PANEL_BLOCKMON: result := GridTagBlockMon; // gBlockMon -- this is for all blockmons
175 else result := GridTagInvalid;
176 end;
177 end;
180 type
181 TPanelID = record
182 PWhere: ^TPanelArray;
183 PArrID: Integer;
184 end;
186 var
187 PanelById: array of TPanelID;
188 Textures: TLevelTextureArray;
189 RespawnPoints: Array of TRespawnPoint;
190 FlagPoints: Array [FLAG_RED..FLAG_BLUE] of PFlagPoint;
191 //DOMFlagPoints: Array of TFlagPoint;
192 gMapGrid: TBodyGrid = nil;
195 function g_Map_IsSpecialTexture(Texture: String): Boolean;
196 begin
197 Result := (Texture = TEXTURE_NAME_WATER) or
198 (Texture = TEXTURE_NAME_ACID1) or
199 (Texture = TEXTURE_NAME_ACID2);
200 end;
202 procedure CreateDoorMap();
203 var
204 PanelArray: Array of record
205 X, Y: Integer;
206 Width, Height: Word;
207 Active: Boolean;
208 PanelID: DWORD;
209 end;
210 a, b, c, m, i, len: Integer;
211 ok: Boolean;
212 begin
213 if gWalls = nil then
214 Exit;
216 i := 0;
217 len := 128;
218 SetLength(PanelArray, len);
220 for a := 0 to High(gWalls) do
221 if gWalls[a].Door then
222 begin
223 PanelArray[i].X := gWalls[a].X;
224 PanelArray[i].Y := gWalls[a].Y;
225 PanelArray[i].Width := gWalls[a].Width;
226 PanelArray[i].Height := gWalls[a].Height;
227 PanelArray[i].Active := True;
228 PanelArray[i].PanelID := a;
230 i := i + 1;
231 if i = len then
232 begin
233 len := len + 128;
234 SetLength(PanelArray, len);
235 end;
236 end;
238 // Íåò äâåðåé:
239 if i = 0 then
240 begin
241 PanelArray := nil;
242 Exit;
243 end;
245 SetLength(gDoorMap, 0);
247 g_Game_SetLoadingText(_lc[I_LOAD_DOOR_MAP], i-1, False);
249 for a := 0 to i-1 do
250 if PanelArray[a].Active then
251 begin
252 PanelArray[a].Active := False;
253 m := Length(gDoorMap);
254 SetLength(gDoorMap, m+1);
255 SetLength(gDoorMap[m], 1);
256 gDoorMap[m, 0] := PanelArray[a].PanelID;
257 ok := True;
259 while ok do
260 begin
261 ok := False;
263 for b := 0 to i-1 do
264 if PanelArray[b].Active then
265 for c := 0 to High(gDoorMap[m]) do
266 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
267 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
268 g_CollideAround(PanelArray[b].X, PanelArray[b].Y,
269 PanelArray[b].Width, PanelArray[b].Height,
270 gWalls[gDoorMap[m, c]].X,
271 gWalls[gDoorMap[m, c]].Y,
272 gWalls[gDoorMap[m, c]].Width,
273 gWalls[gDoorMap[m, c]].Height) then
274 begin
275 PanelArray[b].Active := False;
276 SetLength(gDoorMap[m],
277 Length(gDoorMap[m])+1);
278 gDoorMap[m, High(gDoorMap[m])] := PanelArray[b].PanelID;
279 ok := True;
280 Break;
281 end;
282 end;
284 g_Game_StepLoading();
285 end;
287 PanelArray := nil;
288 end;
290 procedure CreateLiftMap();
291 var
292 PanelArray: Array of record
293 X, Y: Integer;
294 Width, Height: Word;
295 Active: Boolean;
296 end;
297 a, b, c, len, i, j: Integer;
298 ok: Boolean;
299 begin
300 if gLifts = nil then
301 Exit;
303 len := Length(gLifts);
304 SetLength(PanelArray, len);
306 for a := 0 to len-1 do
307 begin
308 PanelArray[a].X := gLifts[a].X;
309 PanelArray[a].Y := gLifts[a].Y;
310 PanelArray[a].Width := gLifts[a].Width;
311 PanelArray[a].Height := gLifts[a].Height;
312 PanelArray[a].Active := True;
313 end;
315 SetLength(gLiftMap, len);
316 i := 0;
318 g_Game_SetLoadingText(_lc[I_LOAD_LIFT_MAP], len-1, False);
320 for a := 0 to len-1 do
321 if PanelArray[a].Active then
322 begin
323 PanelArray[a].Active := False;
324 SetLength(gLiftMap[i], 32);
325 j := 0;
326 gLiftMap[i, j] := a;
327 ok := True;
329 while ok do
330 begin
331 ok := False;
332 for b := 0 to len-1 do
333 if PanelArray[b].Active then
334 for c := 0 to j do
335 if g_CollideAround(PanelArray[b].X,
336 PanelArray[b].Y,
337 PanelArray[b].Width,
338 PanelArray[b].Height,
339 PanelArray[gLiftMap[i, c]].X,
340 PanelArray[gLiftMap[i, c]].Y,
341 PanelArray[gLiftMap[i, c]].Width,
342 PanelArray[gLiftMap[i, c]].Height) then
343 begin
344 PanelArray[b].Active := False;
345 j := j+1;
346 if j > High(gLiftMap[i]) then
347 SetLength(gLiftMap[i],
348 Length(gLiftMap[i])+32);
350 gLiftMap[i, j] := b;
351 ok := True;
353 Break;
354 end;
355 end;
357 SetLength(gLiftMap[i], j+1);
358 i := i+1;
360 g_Game_StepLoading();
361 end;
363 SetLength(gLiftMap, i);
365 PanelArray := nil;
366 end;
368 function CreatePanel(PanelRec: TPanelRec_1; AddTextures: TAddTextureArray;
369 CurTex: Integer; sav: Boolean): Integer;
370 var
371 len: Integer;
372 panels: ^TPanelArray;
373 begin
374 Result := -1;
376 case PanelRec.PanelType of
377 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
378 panels := @gWalls;
379 PANEL_BACK:
380 panels := @gRenderBackgrounds;
381 PANEL_FORE:
382 panels := @gRenderForegrounds;
383 PANEL_WATER:
384 panels := @gWater;
385 PANEL_ACID1:
386 panels := @gAcid1;
387 PANEL_ACID2:
388 panels := @gAcid2;
389 PANEL_STEP:
390 panels := @gSteps;
391 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
392 panels := @gLifts;
393 PANEL_BLOCKMON:
394 panels := @gBlockMon;
395 else
396 Exit;
397 end;
399 len := Length(panels^);
400 SetLength(panels^, len + 1);
402 panels^[len] := TPanel.Create(PanelRec, AddTextures, CurTex, Textures);
403 panels^[len].ArrIdx := len;
404 if sav then
405 panels^[len].SaveIt := True;
407 Result := len;
409 len := Length(PanelByID);
410 SetLength(PanelByID, len + 1);
411 PanelByID[len].PWhere := panels;
412 PanelByID[len].PArrID := Result;
413 end;
415 function CreateNullTexture(RecName: String): Integer;
416 begin
417 SetLength(Textures, Length(Textures)+1);
418 result := High(Textures);
420 with Textures[High(Textures)] do
421 begin
422 TextureName := RecName;
423 Width := 1;
424 Height := 1;
425 Anim := False;
426 TextureID := TEXTURE_NONE;
427 end;
428 end;
430 function CreateTexture(RecName: String; Map: string; log: Boolean): Integer;
431 var
432 WAD: TWADFile;
433 TextureData: Pointer;
434 WADName, txname: String;
435 a, ResLength: Integer;
436 begin
437 Result := -1;
439 if Textures <> nil then
440 for a := 0 to High(Textures) do
441 if Textures[a].TextureName = RecName then
442 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
443 Result := a;
444 Exit;
445 end;
447 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
448 if (RecName = TEXTURE_NAME_WATER) or
449 (RecName = TEXTURE_NAME_ACID1) or
450 (RecName = TEXTURE_NAME_ACID2) then
451 begin
452 SetLength(Textures, Length(Textures)+1);
454 with Textures[High(Textures)] do
455 begin
456 TextureName := RecName;
458 if TextureName = TEXTURE_NAME_WATER then
459 TextureID := TEXTURE_SPECIAL_WATER
460 else
461 if TextureName = TEXTURE_NAME_ACID1 then
462 TextureID := TEXTURE_SPECIAL_ACID1
463 else
464 if TextureName = TEXTURE_NAME_ACID2 then
465 TextureID := TEXTURE_SPECIAL_ACID2;
467 Anim := False;
468 end;
470 result := High(Textures);
471 Exit;
472 end;
474 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
475 WADName := g_ExtractWadName(RecName);
477 WAD := TWADFile.Create();
479 if WADName <> '' then
480 WADName := GameDir+'/wads/'+WADName
481 else
482 WADName := Map;
484 WAD.ReadFile(WADName);
486 txname := RecName;
488 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
489 begin
490 FreeMem(TextureData);
491 RecName := 'COMMON\ALIEN';
492 end;
495 if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
496 begin
497 SetLength(Textures, Length(Textures)+1);
498 if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then
499 Exit;
500 e_GetTextureSize(Textures[High(Textures)].TextureID,
501 @Textures[High(Textures)].Width,
502 @Textures[High(Textures)].Height);
503 FreeMem(TextureData);
504 Textures[High(Textures)].TextureName := {RecName}txname;
505 Textures[High(Textures)].Anim := False;
507 result := High(Textures);
508 end
509 else // Íåò òàêîãî ðåóñðñà â WAD'å
510 begin
511 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
512 if log then
513 begin
514 e_WriteLog(Format('Error loading texture %s', [RecName]), MSG_WARNING);
515 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
516 end;
517 end;
519 WAD.Free();
520 end;
522 function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Integer;
523 var
524 WAD: TWADFile;
525 TextureWAD: PChar = nil;
526 TextData: Pointer = nil;
527 TextureData: Pointer = nil;
528 cfg: TConfig = nil;
529 WADName: String;
530 ResLength: Integer;
531 TextureResource: String;
532 _width, _height, _framecount, _speed: Integer;
533 _backanimation: Boolean;
534 //imgfmt: string;
535 ia: TDynImageDataArray = nil;
536 f, c, frdelay, frloop: Integer;
537 begin
538 result := -1;
540 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
542 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
543 WADName := g_ExtractWadName(RecName);
545 WAD := TWADFile.Create();
546 try
547 if WADName <> '' then
548 WADName := GameDir+'/wads/'+WADName
549 else
550 WADName := Map;
552 WAD.ReadFile(WADName);
554 if not WAD.GetResource(g_ExtractFilePathName(RecName), TextureWAD, ResLength) then
555 begin
556 if log then
557 begin
558 e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
559 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
560 end;
561 exit;
562 end;
564 {TEST
565 if WADName = Map then
566 begin
567 //FreeMem(TextureWAD);
568 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
569 end;
572 WAD.FreeWAD();
574 if ResLength < 6 then
575 begin
576 e_WriteLog(Format('Animated texture file "%s" too short', [RecName]), MSG_WARNING);
577 exit;
578 end;
580 // ýòî ïòèöà? ýòî ñàìîë¸ò?
581 if (TextureWAD[0] = 'D') and (TextureWAD[1] = 'F') and
582 (TextureWAD[2] = 'W') and (TextureWAD[3] = 'A') and (TextureWAD[4] = 'D') then
583 begin
584 // íåò, ýòî ñóïåðìåí!
585 if not WAD.ReadMemory(TextureWAD, ResLength) then
586 begin
587 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName]), MSG_WARNING);
588 exit;
589 end;
591 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
592 if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then
593 begin
594 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName]), MSG_WARNING);
595 exit;
596 end;
598 cfg := TConfig.CreateMem(TextData, ResLength);
600 TextureResource := cfg.ReadStr('', 'resource', '');
601 if TextureResource = '' then
602 begin
603 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName]), MSG_WARNING);
604 exit;
605 end;
607 _width := cfg.ReadInt('', 'framewidth', 0);
608 _height := cfg.ReadInt('', 'frameheight', 0);
609 _framecount := cfg.ReadInt('', 'framecount', 0);
610 _speed := cfg.ReadInt('', 'waitcount', 0);
611 _backanimation := cfg.ReadBool('', 'backanimation', False);
613 cfg.Free();
614 cfg := nil;
616 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
617 if not WAD.GetResource('TEXTURES/'+TextureResource, TextureData, ResLength) then
618 begin
619 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName, 'TEXTURES/'+TextureResource]), MSG_WARNING);
620 exit;
621 end;
623 WAD.Free();
624 WAD := nil;
626 SetLength(Textures, Length(Textures)+1);
627 with Textures[High(Textures)] do
628 begin
629 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
630 if g_Frames_CreateMemory(@FramesID, '', TextureData, ResLength, _width, _height, _framecount, _backanimation) then
631 begin
632 TextureName := RecName;
633 Width := _width;
634 Height := _height;
635 Anim := True;
636 FramesCount := _framecount;
637 Speed := _speed;
638 result := High(Textures);
639 end
640 else
641 begin
642 if log then e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
643 end;
644 end;
645 end
646 else
647 begin
648 // try animated image
650 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
651 if length(imgfmt) = 0 then
652 begin
653 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
654 exit;
655 end;
657 GlobalMetadata.ClearMetaItems();
658 GlobalMetadata.ClearMetaItemsForSaving();
659 if not LoadMultiImageFromMemory(TextureWAD, ResLength, ia) then
660 begin
661 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName]), MSG_WARNING);
662 exit;
663 end;
664 if length(ia) = 0 then
665 begin
666 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName]), MSG_WARNING);
667 exit;
668 end;
670 WAD.Free();
671 WAD := nil;
673 _width := ia[0].width;
674 _height := ia[0].height;
675 _framecount := length(ia);
676 _speed := 1;
677 _backanimation := false;
678 frdelay := -1;
679 frloop := -666;
680 if GlobalMetadata.HasMetaItem(SMetaFrameDelay) then
681 begin
682 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
683 try
684 f := GlobalMetadata.MetaItems[SMetaFrameDelay];
685 frdelay := f;
686 if f < 0 then f := 0;
687 // rounding ;-)
688 c := f mod 28;
689 if c < 13 then c := 0 else c := 1;
690 f := (f div 28)+c;
691 if f < 1 then f := 1 else if f > 255 then f := 255;
692 _speed := f;
693 except
694 end;
695 end;
696 if GlobalMetadata.HasMetaItem(SMetaAnimationLoops) then
697 begin
698 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
699 try
700 f := GlobalMetadata.MetaItems[SMetaAnimationLoops];
701 frloop := f;
702 if f <> 0 then _backanimation := true; // non-infinite looping == forth-and-back
703 except
704 end;
705 end;
706 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
707 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
708 f := ord(_backanimation);
709 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);
711 SetLength(Textures, Length(Textures)+1);
712 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
713 if g_CreateFramesImg(ia, @Textures[High(Textures)].FramesID, '', _backanimation) then
714 begin
715 Textures[High(Textures)].TextureName := RecName;
716 Textures[High(Textures)].Width := _width;
717 Textures[High(Textures)].Height := _height;
718 Textures[High(Textures)].Anim := True;
719 Textures[High(Textures)].FramesCount := length(ia);
720 Textures[High(Textures)].Speed := _speed;
721 result := High(Textures);
722 //writeln(' CREATED!');
723 end
724 else
725 begin
726 if log then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName]), MSG_WARNING);
727 end;
728 end;
729 finally
730 for f := 0 to High(ia) do FreeImage(ia[f]);
731 WAD.Free();
732 cfg.Free();
733 if TextureWAD <> nil then FreeMem(TextureWAD);
734 if TextData <> nil then FreeMem(TextData);
735 if TextureData <> nil then FreeMem(TextureData);
736 end;
737 end;
739 procedure CreateItem(Item: TItemRec_1);
740 begin
741 if g_Game_IsClient then Exit;
743 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) and
744 ByteBool(Item.Options and ITEM_OPTION_ONLYDM) then
745 Exit;
747 g_Items_Create(Item.X, Item.Y, Item.ItemType, ByteBool(Item.Options and ITEM_OPTION_FALL),
748 gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP]);
749 end;
751 procedure CreateArea(Area: TAreaRec_1);
752 var
753 a: Integer;
754 id: DWORD;
755 begin
756 case Area.AreaType of
757 AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2,
758 AREA_REDTEAMPOINT, AREA_BLUETEAMPOINT:
759 begin
760 SetLength(RespawnPoints, Length(RespawnPoints)+1);
761 with RespawnPoints[High(RespawnPoints)] do
762 begin
763 X := Area.X;
764 Y := Area.Y;
765 Direction := TDirection(Area.Direction);
767 case Area.AreaType of
768 AREA_DMPOINT: PointType := RESPAWNPOINT_DM;
769 AREA_PLAYERPOINT1: PointType := RESPAWNPOINT_PLAYER1;
770 AREA_PLAYERPOINT2: PointType := RESPAWNPOINT_PLAYER2;
771 AREA_REDTEAMPOINT: PointType := RESPAWNPOINT_RED;
772 AREA_BLUETEAMPOINT: PointType := RESPAWNPOINT_BLUE;
773 end;
774 end;
775 end;
777 AREA_REDFLAG, AREA_BLUEFLAG:
778 begin
779 if Area.AreaType = AREA_REDFLAG then a := FLAG_RED else a := FLAG_BLUE;
781 if FlagPoints[a] <> nil then Exit;
783 New(FlagPoints[a]);
785 with FlagPoints[a]^ do
786 begin
787 X := Area.X-FLAGRECT.X;
788 Y := Area.Y-FLAGRECT.Y;
789 Direction := TDirection(Area.Direction);
790 end;
792 with gFlags[a] do
793 begin
794 case a of
795 FLAG_RED: g_Frames_Get(id, 'FRAMES_FLAG_RED');
796 FLAG_BLUE: g_Frames_Get(id, 'FRAMES_FLAG_BLUE');
797 end;
799 Animation := TAnimation.Create(id, True, 8);
800 Obj.Rect := FLAGRECT;
802 g_Map_ResetFlag(a);
803 end;
804 end;
806 AREA_DOMFLAG:
807 begin
808 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
809 with DOMFlagPoints[High(DOMFlagPoints)] do
810 begin
811 X := Area.X;
812 Y := Area.Y;
813 Direction := TDirection(Area.Direction);
814 end;
816 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
817 end;
818 end;
819 end;
821 procedure CreateTrigger(Trigger: TTriggerRec_1; fTexturePanel1Type, fTexturePanel2Type: Word);
822 var
823 _trigger: TTrigger;
824 begin
825 if g_Game_IsClient and not (Trigger.TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) then Exit;
827 with _trigger do
828 begin
829 X := Trigger.X;
830 Y := Trigger.Y;
831 Width := Trigger.Width;
832 Height := Trigger.Height;
833 Enabled := ByteBool(Trigger.Enabled);
834 TexturePanel := Trigger.TexturePanel;
835 TexturePanelType := fTexturePanel1Type;
836 ShotPanelType := fTexturePanel2Type;
837 TriggerType := Trigger.TriggerType;
838 ActivateType := Trigger.ActivateType;
839 Keys := Trigger.Keys;
840 Data.Default := Trigger.DATA;
841 end;
843 g_Triggers_Create(_trigger);
844 end;
846 procedure CreateMonster(monster: TMonsterRec_1);
847 var
848 a, i: Integer;
849 begin
850 if g_Game_IsClient then Exit;
852 if (gGameSettings.GameType = GT_SINGLE)
853 or LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS) then
854 begin
855 i := g_Monsters_Create(monster.MonsterType, monster.X, monster.Y,
856 TDirection(monster.Direction));
858 if gTriggers <> nil then
859 for a := 0 to High(gTriggers) do
860 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
861 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
862 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
863 gMonsters[i].AddTrigger(a);
865 if monster.MonsterType <> MONSTER_BARREL then
866 Inc(gTotalMonsters);
867 end;
868 end;
870 procedure g_Map_ReAdd_DieTriggers();
871 var
872 i, a: Integer;
873 begin
874 if g_Game_IsClient then Exit;
876 for i := 0 to High(gMonsters) do
877 if gMonsters[i] <> nil then
878 begin
879 gMonsters[i].ClearTriggers();
881 for a := 0 to High(gTriggers) do
882 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
883 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
884 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
885 gMonsters[i].AddTrigger(a);
886 end;
887 end;
889 function extractWadName(resourceName: string): string;
890 var
891 posN: Integer;
892 begin
893 posN := Pos(':', resourceName);
894 if posN > 0 then
895 Result:= Copy(resourceName, 0, posN-1)
896 else
897 Result := '';
898 end;
900 procedure addResToExternalResList(res: string);
901 begin
902 res := extractWadName(res);
903 if (res <> '') and (gExternalResources.IndexOf(res) = -1) then
904 gExternalResources.Add(res);
905 end;
907 procedure generateExternalResourcesList(mapReader: TMapReader_1);
908 var
909 textures: TTexturesRec1Array;
910 mapHeader: TMapHeaderRec_1;
911 i: integer;
912 resFile: String = '';
913 begin
914 if gExternalResources = nil then
915 gExternalResources := TStringList.Create;
917 gExternalResources.Clear;
918 textures := mapReader.GetTextures();
919 for i := 0 to High(textures) do
920 begin
921 addResToExternalResList(resFile);
922 end;
924 textures := nil;
926 mapHeader := mapReader.GetMapHeader;
928 addResToExternalResList(mapHeader.MusicName);
929 addResToExternalResList(mapHeader.SkyName);
930 end;
932 procedure mapCreateGrid ();
933 var
934 mapX0: Integer = $3fffffff;
935 mapY0: Integer = $3fffffff;
936 mapX1: Integer = -$3fffffff;
937 mapY1: Integer = -$3fffffff;
939 procedure fixMinMax (var panels: TPanelArray);
940 var
941 idx: Integer;
942 begin
943 for idx := 0 to High(panels) do
944 begin
945 if (panels[idx].Width < 1) or (panels[idx].Height < 1) then continue;
946 if mapX0 > panels[idx].X then mapX0 := panels[idx].X;
947 if mapY0 > panels[idx].Y then mapY0 := panels[idx].Y;
948 if mapX1 < panels[idx].X+panels[idx].Width-1 then mapX1 := panels[idx].X+panels[idx].Width-1;
949 if mapY1 < panels[idx].Y+panels[idx].Height-1 then mapY1 := panels[idx].Y+panels[idx].Height-1;
950 end;
951 end;
953 procedure addPanelsToGrid (var panels: TPanelArray; tag: Integer);
954 var
955 idx: Integer;
956 begin
957 tag := panelTypeToTag(tag);
958 for idx := High(panels) downto 0 do
959 begin
960 gMapGrid.insertBody(panels[idx], panels[idx].X, panels[idx].Y, panels[idx].Width, panels[idx].Height, tag);
961 end;
962 end;
964 begin
965 gMapGrid.Free();
966 gMapGrid := nil;
968 fixMinMax(gWalls);
969 fixMinMax(gRenderBackgrounds);
970 fixMinMax(gRenderForegrounds);
971 fixMinMax(gWater);
972 fixMinMax(gAcid1);
973 fixMinMax(gAcid2);
974 fixMinMax(gSteps);
975 fixMinMax(gLifts);
976 fixMinMax(gBlockMon);
978 if (mapX0 < 0) or (mapY0 < 0) then
979 begin
980 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1]), MSG_WARNING);
981 //raise Exception.Create('we are fucked');
982 end;
984 gMapGrid := TBodyGrid.Create(mapX0, mapY0, mapX1-mapX0+1, mapY1-mapY0+1);
986 addPanelsToGrid(gWalls, PANEL_WALL); // and PANEL_CLOSEDOOR
987 addPanelsToGrid(gRenderBackgrounds, PANEL_BACK);
988 addPanelsToGrid(gRenderForegrounds, PANEL_FORE);
989 addPanelsToGrid(gWater, PANEL_WATER);
990 addPanelsToGrid(gAcid1, PANEL_ACID1);
991 addPanelsToGrid(gAcid2, PANEL_ACID2);
992 addPanelsToGrid(gSteps, PANEL_STEP);
993 addPanelsToGrid(gLifts, PANEL_LIFTUP); // it doesn't matter which LIFT type is used here
994 addPanelsToGrid(gBlockMon, PANEL_BLOCKMON);
996 gMapGrid.dumpStats();
997 end;
999 function g_Map_Load(Res: String): Boolean;
1000 const
1001 DefaultMusRes = 'Standart.wad:STDMUS\MUS1';
1002 DefaultSkyRes = 'Standart.wad:STDSKY\SKY0';
1003 var
1004 WAD: TWADFile;
1005 MapReader: TMapReader_1;
1006 Header: TMapHeaderRec_1;
1007 _textures: TTexturesRec1Array;
1008 _texnummap: array of Integer; // `_textures` -> `Textures`
1009 panels: TPanelsRec1Array;
1010 items: TItemsRec1Array;
1011 monsters: TMonsterRec1Array;
1012 areas: TAreasRec1Array;
1013 triggers: TTriggersRec1Array;
1014 a, b, c, k: Integer;
1015 PanelID: DWORD;
1016 AddTextures: TAddTextureArray;
1017 texture: TTextureRec_1;
1018 TriggersTable: Array of record
1019 TexturePanel: Integer;
1020 LiftPanel: Integer;
1021 DoorPanel: Integer;
1022 ShotPanel: Integer;
1023 end;
1024 FileName, mapResName, s, TexName: String;
1025 Data: Pointer;
1026 Len: Integer;
1027 ok, isAnim, trigRef: Boolean;
1028 CurTex, ntn: Integer;
1030 begin
1031 gMapGrid.Free();
1032 gMapGrid := nil;
1034 Result := False;
1035 gMapInfo.Map := Res;
1036 TriggersTable := nil;
1037 FillChar(texture, SizeOf(texture), 0);
1039 sfsGCDisable(); // temporary disable removing of temporary volumes
1040 try
1041 // Çàãðóçêà WAD:
1042 FileName := g_ExtractWadName(Res);
1043 e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY);
1044 g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False);
1046 WAD := TWADFile.Create();
1047 if not WAD.ReadFile(FileName) then
1048 begin
1049 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [FileName]));
1050 WAD.Free();
1051 Exit;
1052 end;
1053 //k8: why loader ignores path here?
1054 mapResName := g_ExtractFileName(Res);
1055 if not WAD.GetMapResource(mapResName, Data, Len) then
1056 begin
1057 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName]));
1058 WAD.Free();
1059 Exit;
1060 end;
1062 WAD.Free();
1064 // Çàãðóçêà êàðòû:
1065 e_WriteLog('Loading map: '+mapResName, MSG_NOTIFY);
1066 g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False);
1067 MapReader := TMapReader_1.Create();
1069 if not MapReader.LoadMap(Data) then
1070 begin
1071 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]));
1072 FreeMem(Data);
1073 MapReader.Free();
1074 Exit;
1075 end;
1077 FreeMem(Data);
1078 generateExternalResourcesList(MapReader);
1079 // Çàãðóçêà òåêñòóð:
1080 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], 0, False);
1081 _textures := MapReader.GetTextures();
1082 _texnummap := nil;
1084 // Äîáàâëåíèå òåêñòóð â Textures[]:
1085 if _textures <> nil then
1086 begin
1087 e_WriteLog(' Loading textures:', MSG_NOTIFY);
1088 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], High(_textures), False);
1089 SetLength(_texnummap, length(_textures));
1091 for a := 0 to High(_textures) do
1092 begin
1093 SetLength(s, 64);
1094 CopyMemory(@s[1], @_textures[a].Resource[0], 64);
1095 for b := 1 to Length(s) do
1096 if s[b] = #0 then
1097 begin
1098 SetLength(s, b-1);
1099 Break;
1100 end;
1101 e_WriteLog(Format(' Loading texture #%d: %s', [a, s]), MSG_NOTIFY);
1102 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1103 // Àíèìèðîâàííàÿ òåêñòóðà:
1104 if ByteBool(_textures[a].Anim) then
1105 begin
1106 ntn := CreateAnimTexture(_textures[a].Resource, FileName, True);
1107 if ntn < 0 then
1108 begin
1109 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_ANIM], [s]));
1110 ntn := CreateNullTexture(_textures[a].Resource);
1111 end;
1112 end
1113 else // Îáû÷íàÿ òåêñòóðà:
1114 ntn := CreateTexture(_textures[a].Resource, FileName, True);
1115 if ntn < 0 then
1116 begin
1117 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_SIMPLE], [s]));
1118 ntn := CreateNullTexture(_textures[a].Resource);
1119 end;
1121 _texnummap[a] := ntn; // fix texture number
1122 g_Game_StepLoading();
1123 end;
1124 end;
1126 // Çàãðóçêà òðèããåðîâ:
1127 gTriggerClientID := 0;
1128 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1129 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS], 0, False);
1130 triggers := MapReader.GetTriggers();
1132 // Çàãðóçêà ïàíåëåé:
1133 e_WriteLog(' Loading panels...', MSG_NOTIFY);
1134 g_Game_SetLoadingText(_lc[I_LOAD_PANELS], 0, False);
1135 panels := MapReader.GetPanels();
1137 // check texture numbers for panels
1138 for a := 0 to High(panels) do
1139 begin
1140 if panels[a].TextureNum > High(_textures) then
1141 begin
1142 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR);
1143 result := false;
1144 exit;
1145 end;
1146 panels[a].TextureNum := _texnummap[panels[a].TextureNum];
1147 end;
1149 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1150 if triggers <> nil then
1151 begin
1152 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY);
1153 SetLength(TriggersTable, Length(triggers));
1154 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS_TABLE], High(TriggersTable), False);
1156 for a := 0 to High(TriggersTable) do
1157 begin
1158 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1159 TriggersTable[a].TexturePanel := triggers[a].TexturePanel;
1160 // Ëèôòû:
1161 if triggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT] then
1162 TriggersTable[a].LiftPanel := TTriggerData(triggers[a].DATA).PanelID
1163 else
1164 TriggersTable[a].LiftPanel := -1;
1165 // Äâåðè:
1166 if triggers[a].TriggerType in [TRIGGER_OPENDOOR,
1167 TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
1168 TRIGGER_CLOSETRAP, TRIGGER_TRAP] then
1169 TriggersTable[a].DoorPanel := TTriggerData(triggers[a].DATA).PanelID
1170 else
1171 TriggersTable[a].DoorPanel := -1;
1172 // Òóðåëü:
1173 if triggers[a].TriggerType = TRIGGER_SHOT then
1174 TriggersTable[a].ShotPanel := TTriggerData(triggers[a].DATA).ShotPanelID
1175 else
1176 TriggersTable[a].ShotPanel := -1;
1178 g_Game_StepLoading();
1179 end;
1180 end;
1182 // Ñîçäàåì ïàíåëè:
1183 if panels <> nil then
1184 begin
1185 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY);
1186 g_Game_SetLoadingText(_lc[I_LOAD_LINK_TRIGGERS], High(panels), False);
1188 for a := 0 to High(panels) do
1189 begin
1190 SetLength(AddTextures, 0);
1191 trigRef := False;
1192 CurTex := -1;
1193 if _textures <> nil then
1194 begin
1195 texture := _textures[panels[a].TextureNum];
1196 ok := True;
1197 end
1198 else
1199 ok := False;
1201 if ok then
1202 begin
1203 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1204 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1205 ok := False;
1206 if (TriggersTable <> nil) and (_textures <> nil) then
1207 for b := 0 to High(TriggersTable) do
1208 if (TriggersTable[b].TexturePanel = a)
1209 or (TriggersTable[b].ShotPanel = a) then
1210 begin
1211 trigRef := True;
1212 ok := True;
1213 Break;
1214 end;
1215 end;
1217 if ok then
1218 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1219 SetLength(s, 64);
1220 CopyMemory(@s[1], @texture.Resource[0], 64);
1221 // Èçìåðÿåì äëèíó:
1222 Len := Length(s);
1223 for c := Len downto 1 do
1224 if s[c] <> #0 then
1225 begin
1226 Len := c;
1227 Break;
1228 end;
1229 SetLength(s, Len);
1231 // Ñïåö-òåêñòóðû çàïðåùåíû:
1232 if g_Map_IsSpecialTexture(s) then
1233 ok := False
1234 else
1235 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1236 ok := g_Texture_NumNameFindStart(s);
1238 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1239 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1240 if ok then
1241 begin
1242 k := NNF_NAME_BEFORE;
1243 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1244 while ok or (k = NNF_NAME_BEFORE) or
1245 (k = NNF_NAME_EQUALS) do
1246 begin
1247 k := g_Texture_NumNameFindNext(TexName);
1249 if (k = NNF_NAME_BEFORE) or
1250 (k = NNF_NAME_AFTER) then
1251 begin
1252 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1253 if ByteBool(texture.Anim) then
1254 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1255 isAnim := True;
1256 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1257 if not ok then
1258 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1259 isAnim := False;
1260 ok := CreateTexture(TexName, FileName, False) >= 0;
1261 end;
1262 end
1263 else
1264 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1265 isAnim := False;
1266 ok := CreateTexture(TexName, FileName, False) >= 0;
1267 if not ok then
1268 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1269 isAnim := True;
1270 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1271 end;
1272 end;
1274 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1275 if ok then
1276 begin
1277 for c := 0 to High(Textures) do
1278 if Textures[c].TextureName = TexName then
1279 begin
1280 SetLength(AddTextures, Length(AddTextures)+1);
1281 AddTextures[High(AddTextures)].Texture := c;
1282 AddTextures[High(AddTextures)].Anim := isAnim;
1283 Break;
1284 end;
1285 end;
1286 end
1287 else
1288 if k = NNF_NAME_EQUALS then
1289 begin
1290 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1291 SetLength(AddTextures, Length(AddTextures)+1);
1292 AddTextures[High(AddTextures)].Texture := panels[a].TextureNum;
1293 AddTextures[High(AddTextures)].Anim := ByteBool(texture.Anim);
1294 CurTex := High(AddTextures);
1295 ok := True;
1296 end
1297 else // NNF_NO_NAME
1298 ok := False;
1299 end; // while ok...
1301 ok := True;
1302 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1303 end; // if ok - ññûëàþòñÿ òðèããåðû
1305 if not ok then
1306 begin
1307 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1308 SetLength(AddTextures, 1);
1309 AddTextures[0].Texture := panels[a].TextureNum;
1310 AddTextures[0].Anim := ByteBool(texture.Anim);
1311 CurTex := 0;
1312 end;
1314 //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);
1316 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1317 PanelID := CreatePanel(panels[a], AddTextures, CurTex, trigRef);
1319 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1320 if TriggersTable <> nil then
1321 for b := 0 to High(TriggersTable) do
1322 begin
1323 // Òðèããåð äâåðè/ëèôòà:
1324 if (TriggersTable[b].LiftPanel = a) or
1325 (TriggersTable[b].DoorPanel = a) then
1326 TTriggerData(triggers[b].DATA).PanelID := PanelID;
1327 // Òðèããåð ñìåíû òåêñòóðû:
1328 if TriggersTable[b].TexturePanel = a then
1329 triggers[b].TexturePanel := PanelID;
1330 // Òðèããåð "Òóðåëü":
1331 if TriggersTable[b].ShotPanel = a then
1332 TTriggerData(triggers[b].DATA).ShotPanelID := PanelID;
1333 end;
1335 g_Game_StepLoading();
1336 end;
1337 end;
1339 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1340 if (triggers <> nil) and not gLoadGameMode then
1341 begin
1342 e_WriteLog(' Creating triggers...', MSG_NOTIFY);
1343 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_TRIGGERS], 0, False);
1344 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1345 for a := 0 to High(triggers) do
1346 begin
1347 if triggers[a].TexturePanel <> -1 then
1348 b := panels[TriggersTable[a].TexturePanel].PanelType
1349 else
1350 b := 0;
1351 if (triggers[a].TriggerType = TRIGGER_SHOT) and
1352 (TTriggerData(triggers[a].DATA).ShotPanelID <> -1) then
1353 c := panels[TriggersTable[a].ShotPanel].PanelType
1354 else
1355 c := 0;
1356 CreateTrigger(triggers[a], b, c);
1357 end;
1358 end;
1360 // Çàãðóçêà ïðåäìåòîâ:
1361 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1362 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS], 0, False);
1363 items := MapReader.GetItems();
1365 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1366 if (items <> nil) and not gLoadGameMode then
1367 begin
1368 e_WriteLog(' Spawning items...', MSG_NOTIFY);
1369 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_ITEMS], 0, False);
1370 for a := 0 to High(items) do
1371 CreateItem(Items[a]);
1372 end;
1374 // Çàãðóçêà îáëàñòåé:
1375 e_WriteLog(' Loading areas...', MSG_NOTIFY);
1376 g_Game_SetLoadingText(_lc[I_LOAD_AREAS], 0, False);
1377 areas := MapReader.GetAreas();
1379 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1380 if areas <> nil then
1381 begin
1382 e_WriteLog(' Creating areas...', MSG_NOTIFY);
1383 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_AREAS], 0, False);
1384 for a := 0 to High(areas) do
1385 CreateArea(areas[a]);
1386 end;
1388 // Çàãðóçêà ìîíñòðîâ:
1389 e_WriteLog(' Loading monsters...', MSG_NOTIFY);
1390 g_Game_SetLoadingText(_lc[I_LOAD_MONSTERS], 0, False);
1391 monsters := MapReader.GetMonsters();
1393 gTotalMonsters := 0;
1395 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1396 if (monsters <> nil) and not gLoadGameMode then
1397 begin
1398 e_WriteLog(' Spawning monsters...', MSG_NOTIFY);
1399 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_MONSTERS], 0, False);
1400 for a := 0 to High(monsters) do
1401 CreateMonster(monsters[a]);
1402 end;
1404 // Çàãðóçêà îïèñàíèÿ êàðòû:
1405 e_WriteLog(' Reading map info...', MSG_NOTIFY);
1406 g_Game_SetLoadingText(_lc[I_LOAD_MAP_HEADER], 0, False);
1407 Header := MapReader.GetMapHeader();
1409 MapReader.Free();
1411 with gMapInfo do
1412 begin
1413 Name := Header.MapName;
1414 Description := Header.MapDescription;
1415 Author := Header.MapAuthor;
1416 MusicName := Header.MusicName;
1417 SkyName := Header.SkyName;
1418 Height := Header.Height;
1419 Width := Header.Width;
1420 end;
1422 // Çàãðóçêà íåáà:
1423 if gMapInfo.SkyName <> '' then
1424 begin
1425 e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, MSG_NOTIFY);
1426 g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
1427 FileName := g_ExtractWadName(gMapInfo.SkyName);
1429 if FileName <> '' then
1430 FileName := GameDir+'/wads/'+FileName
1431 else
1432 begin
1433 FileName := g_ExtractWadName(Res);
1434 end;
1436 s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName);
1437 if g_Texture_CreateWAD(BackID, s) then
1438 begin
1439 g_Game_SetupScreenSize();
1440 end
1441 else
1442 g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]));
1443 end;
1445 // Çàãðóçêà ìóçûêè:
1446 ok := False;
1447 if gMapInfo.MusicName <> '' then
1448 begin
1449 e_WriteLog(' Loading music: ' + gMapInfo.MusicName, MSG_NOTIFY);
1450 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1451 FileName := g_ExtractWadName(gMapInfo.MusicName);
1453 if FileName <> '' then
1454 FileName := GameDir+'/wads/'+FileName
1455 else
1456 begin
1457 FileName := g_ExtractWadName(Res);
1458 end;
1460 s := FileName+':'+g_ExtractFilePathName(gMapInfo.MusicName);
1461 if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then
1462 ok := True
1463 else
1464 g_FatalError(Format(_lc[I_GAME_ERROR_MUSIC], [s]));
1465 end;
1467 // Îñòàëüíûå óñòàíâêè:
1468 CreateDoorMap();
1469 CreateLiftMap();
1471 g_Items_Init();
1472 g_Weapon_Init();
1473 g_Monsters_Init();
1475 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1476 if not gLoadGameMode then
1477 g_GFX_Init();
1479 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1480 _textures := nil;
1481 panels := nil;
1482 items := nil;
1483 areas := nil;
1484 triggers := nil;
1485 TriggersTable := nil;
1486 AddTextures := nil;
1488 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1489 if ok and (not gLoadGameMode) then
1490 begin
1491 gMusic.SetByName(gMapInfo.MusicName);
1492 gMusic.Play();
1493 end
1494 else
1495 gMusic.SetByName('');
1496 finally
1497 sfsGCEnable(); // enable releasing unused volumes
1498 end;
1500 e_WriteLog('Creating map grid', MSG_NOTIFY);
1501 mapCreateGrid();
1503 e_WriteLog('Done loading map.', MSG_NOTIFY);
1504 Result := True;
1505 end;
1507 function g_Map_GetMapInfo(Res: String): TMapInfo;
1508 var
1509 WAD: TWADFile;
1510 MapReader: TMapReader_1;
1511 Header: TMapHeaderRec_1;
1512 FileName: String;
1513 Data: Pointer;
1514 Len: Integer;
1515 begin
1516 FillChar(Result, SizeOf(Result), 0);
1517 FileName := g_ExtractWadName(Res);
1519 WAD := TWADFile.Create();
1520 if not WAD.ReadFile(FileName) then
1521 begin
1522 WAD.Free();
1523 Exit;
1524 end;
1526 //k8: it ignores path again
1527 if not WAD.GetMapResource(g_ExtractFileName(Res), Data, Len) then
1528 begin
1529 WAD.Free();
1530 Exit;
1531 end;
1533 WAD.Free();
1535 MapReader := TMapReader_1.Create();
1537 if not MapReader.LoadMap(Data) then
1538 begin
1539 g_Console_Add(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]), True);
1540 ZeroMemory(@Header, SizeOf(Header));
1541 Result.Name := _lc[I_GAME_ERROR_MAP_SELECT];
1542 Result.Description := _lc[I_GAME_ERROR_MAP_SELECT];
1543 end
1544 else
1545 begin
1546 Header := MapReader.GetMapHeader();
1547 Result.Name := Header.MapName;
1548 Result.Description := Header.MapDescription;
1549 end;
1551 FreeMem(Data);
1552 MapReader.Free();
1554 Result.Map := Res;
1555 Result.Author := Header.MapAuthor;
1556 Result.Height := Header.Height;
1557 Result.Width := Header.Width;
1558 end;
1560 function g_Map_GetMapsList(WADName: string): SArray;
1561 var
1562 WAD: TWADFile;
1563 a: Integer;
1564 ResList: SArray;
1565 begin
1566 Result := nil;
1567 WAD := TWADFile.Create();
1568 if not WAD.ReadFile(WADName) then
1569 begin
1570 WAD.Free();
1571 Exit;
1572 end;
1573 ResList := WAD.GetMapResources();
1574 if ResList <> nil then
1575 begin
1576 for a := 0 to High(ResList) do
1577 begin
1578 SetLength(Result, Length(Result)+1);
1579 Result[High(Result)] := ResList[a];
1580 end;
1581 end;
1582 WAD.Free();
1583 end;
1585 function g_Map_Exist(Res: string): Boolean;
1586 var
1587 WAD: TWADFile;
1588 FileName, mnn: string;
1589 ResList: SArray;
1590 a: Integer;
1591 begin
1592 Result := False;
1594 FileName := addWadExtension(g_ExtractWadName(Res));
1596 WAD := TWADFile.Create;
1597 if not WAD.ReadFile(FileName) then
1598 begin
1599 WAD.Free();
1600 Exit;
1601 end;
1603 ResList := WAD.GetMapResources();
1604 WAD.Free();
1606 mnn := g_ExtractFileName(Res);
1607 if ResList <> nil then
1608 for a := 0 to High(ResList) do if StrEquCI1251(ResList[a], mnn) then
1609 begin
1610 Result := True;
1611 Exit;
1612 end;
1613 end;
1615 procedure g_Map_Free();
1616 var
1617 a: Integer;
1619 procedure FreePanelArray(var panels: TPanelArray);
1620 var
1621 i: Integer;
1623 begin
1624 if panels <> nil then
1625 begin
1626 for i := 0 to High(panels) do
1627 panels[i].Free();
1628 panels := nil;
1629 end;
1630 end;
1632 begin
1633 g_GFX_Free();
1634 g_Weapon_Free();
1635 g_Items_Free();
1636 g_Triggers_Free();
1637 g_Monsters_Free();
1639 RespawnPoints := nil;
1640 if FlagPoints[FLAG_RED] <> nil then
1641 begin
1642 Dispose(FlagPoints[FLAG_RED]);
1643 FlagPoints[FLAG_RED] := nil;
1644 end;
1645 if FlagPoints[FLAG_BLUE] <> nil then
1646 begin
1647 Dispose(FlagPoints[FLAG_BLUE]);
1648 FlagPoints[FLAG_BLUE] := nil;
1649 end;
1650 //DOMFlagPoints := nil;
1652 //gDOMFlags := nil;
1654 if Textures <> nil then
1655 begin
1656 for a := 0 to High(Textures) do
1657 if not g_Map_IsSpecialTexture(Textures[a].TextureName) then
1658 if Textures[a].Anim then
1659 g_Frames_DeleteByID(Textures[a].FramesID)
1660 else
1661 if Textures[a].TextureID <> TEXTURE_NONE then
1662 e_DeleteTexture(Textures[a].TextureID);
1664 Textures := nil;
1665 end;
1667 FreePanelArray(gWalls);
1668 FreePanelArray(gRenderBackgrounds);
1669 FreePanelArray(gRenderForegrounds);
1670 FreePanelArray(gWater);
1671 FreePanelArray(gAcid1);
1672 FreePanelArray(gAcid2);
1673 FreePanelArray(gSteps);
1674 FreePanelArray(gLifts);
1675 FreePanelArray(gBlockMon);
1677 if BackID <> DWORD(-1) then
1678 begin
1679 gBackSize.X := 0;
1680 gBackSize.Y := 0;
1681 e_DeleteTexture(BackID);
1682 BackID := DWORD(-1);
1683 end;
1685 g_Game_StopAllSounds(False);
1686 gMusic.FreeSound();
1687 g_Sound_Delete(gMapInfo.MusicName);
1689 gMapInfo.Name := '';
1690 gMapInfo.Description := '';
1691 gMapInfo.MusicName := '';
1692 gMapInfo.Height := 0;
1693 gMapInfo.Width := 0;
1695 gDoorMap := nil;
1696 gLiftMap := nil;
1698 PanelByID := nil;
1699 end;
1701 procedure g_Map_Update();
1702 var
1703 a, d, j: Integer;
1704 m: Word;
1705 s: String;
1707 procedure UpdatePanelArray(var panels: TPanelArray);
1708 var
1709 i: Integer;
1711 begin
1712 if panels <> nil then
1713 for i := 0 to High(panels) do
1714 panels[i].Update();
1715 end;
1717 begin
1718 UpdatePanelArray(gWalls);
1719 UpdatePanelArray(gRenderBackgrounds);
1720 UpdatePanelArray(gRenderForegrounds);
1721 UpdatePanelArray(gWater);
1722 UpdatePanelArray(gAcid1);
1723 UpdatePanelArray(gAcid2);
1724 UpdatePanelArray(gSteps);
1726 if gGameSettings.GameMode = GM_CTF then
1727 begin
1728 for a := FLAG_RED to FLAG_BLUE do
1729 if not (gFlags[a].State in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1730 with gFlags[a] do
1731 begin
1732 if gFlags[a].Animation <> nil then
1733 gFlags[a].Animation.Update();
1735 m := g_Obj_Move(@Obj, True, True);
1737 if gTime mod (GAME_TICK*2) <> 0 then
1738 Continue;
1740 // Ñîïðîòèâëåíèå âîçäóõà:
1741 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1743 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1744 if ((Count = 0) or ByteBool(m and MOVE_FALLOUT)) and g_Game_IsServer then
1745 begin
1746 g_Map_ResetFlag(a);
1747 gFlags[a].CaptureTime := 0;
1748 if a = FLAG_RED then
1749 s := _lc[I_PLAYER_FLAG_RED]
1750 else
1751 s := _lc[I_PLAYER_FLAG_BLUE];
1752 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1754 if g_Game_IsNet then
1755 MH_SEND_FlagEvent(FLAG_STATE_RETURNED, a, 0);
1756 Continue;
1757 end;
1759 if Count > 0 then
1760 Count := Count - 1;
1762 // Èãðîê áåðåò ôëàã:
1763 if gPlayers <> nil then
1764 begin
1765 j := Random(Length(gPlayers)) - 1;
1767 for d := 0 to High(gPlayers) do
1768 begin
1769 Inc(j);
1770 if j > High(gPlayers) then
1771 j := 0;
1773 if gPlayers[j] <> nil then
1774 if gPlayers[j].Live and
1775 g_Obj_Collide(@Obj, @gPlayers[j].Obj) then
1776 begin
1777 if gPlayers[j].GetFlag(a) then
1778 Break;
1779 end;
1780 end;
1781 end;
1782 end;
1783 end;
1784 end;
1787 procedure g_Map_DrawPanelsOld(PanelType: Word);
1789 procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False);
1790 var
1791 idx: Integer;
1792 begin
1793 if (panels <> nil) and (stp >= 0) and (stp <= 6) then
1794 begin
1795 // alas, no visible set
1796 for idx := 0 to High(panels) do
1797 begin
1798 if not (drawDoors xor panels[idx].Door) then panels[idx].Draw();
1799 end;
1800 end;
1801 end;
1803 begin
1804 case PanelType of
1805 PANEL_WALL: DrawPanels(0, gWalls);
1806 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1807 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1808 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1809 PANEL_WATER: DrawPanels(3, gWater);
1810 PANEL_ACID1: DrawPanels(4, gAcid1);
1811 PANEL_ACID2: DrawPanels(5, gAcid2);
1812 PANEL_STEP: DrawPanels(6, gSteps);
1813 end;
1814 end;
1817 var
1818 gDrawPanelList: TBinaryHeapObj = nil;
1820 function dplLess (a, b: TObject): Boolean;
1821 begin
1822 result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
1823 end;
1825 procedure dplClear ();
1826 begin
1827 if gDrawPanelList = nil then gDrawPanelList := TBinaryHeapObj.Create(@dplLess) else gDrawPanelList.clear();
1828 end;
1830 procedure dplAddPanel (pan: TPanel);
1831 begin
1832 if pan = nil then exit;
1833 gDrawPanelList.insert(pan);
1834 end;
1837 procedure g_Map_DrawPanels(x0, y0, wdt, hgt: Integer; PanelType: Word);
1838 var
1839 ptag: Integer;
1841 function checker (obj: TObject; tag: Integer): Boolean;
1842 var
1843 pan: TPanel;
1844 begin
1845 result := false; // don't stop, ever
1846 if (tag <> ptag) then exit;
1847 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1849 if obj = nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end;
1850 if not (obj is TPanel) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end;
1851 //pan := (obj as TPanel);
1852 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1854 pan := (obj as TPanel);
1855 if (PanelType = PANEL_CLOSEDOOR) then begin if not pan.Door then exit; end else begin if pan.Door then exit; end;
1856 //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);
1857 dplAddPanel(pan);
1858 end;
1860 procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False);
1861 var
1862 idx: Integer;
1863 pan: TPanel;
1864 begin
1865 if (panels <> nil) and (stp >= 0) and (stp <= 6) then
1866 begin
1867 // alas, no visible set
1868 for idx := 0 to High(panels) do
1869 begin
1870 if not (drawDoors xor panels[idx].Door) then
1871 begin
1872 pan := panels[idx];
1873 if (pan.Width < 1) or (pan.Height < 1) then continue;
1874 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1875 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1876 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);
1877 end;
1878 end;
1879 end;
1880 end;
1882 begin
1883 //g_Map_DrawPanelsOld(PanelType); exit;
1884 //e_WriteLog('==================', MSG_NOTIFY);
1885 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1886 dplClear();
1887 ptag := panelTypeToTag(PanelType);
1888 gMapGrid.forEachInAABB(x0, y0, wdt, hgt, checker);
1890 // debug
1892 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1893 case PanelType of
1894 PANEL_WALL: DrawPanels(0, gWalls);
1895 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1896 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1897 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1898 PANEL_WATER: DrawPanels(3, gWater);
1899 PANEL_ACID1: DrawPanels(4, gAcid1);
1900 PANEL_ACID2: DrawPanels(5, gAcid2);
1901 PANEL_STEP: DrawPanels(6, gSteps);
1902 end;
1903 e_WriteLog('==================', MSG_NOTIFY);
1906 // sort and draw the list (we need to sort it, or rendering is fucked)
1907 while gDrawPanelList.count > 0 do
1908 begin
1909 (gDrawPanelList.front() as TPanel).Draw();
1910 gDrawPanelList.popFront();
1911 end;
1912 end;
1915 procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
1916 function checker (obj: TObject; tag: Integer): Boolean;
1917 var
1918 pan: TPanel;
1919 begin
1920 result := false; // don't stop, ever
1921 if (tag <> GridTagWallDoor) then exit; // only walls
1922 pan := (obj as TPanel);
1923 pan.DrawShadowVolume(lightX, lightY, radius);
1924 end;
1926 begin
1927 gMapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, checker);
1928 end;
1931 procedure g_Map_DrawBack(dx, dy: Integer);
1932 begin
1933 if gDrawBackGround and (BackID <> DWORD(-1)) then
1934 e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
1935 else
1936 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
1937 end;
1939 (*
1940 function g_Map_CollidePanelOld(X, Y: Integer; Width, Height: Word;
1941 PanelType: Word; b1x3: Boolean): Boolean;
1942 var
1943 a, h: Integer;
1944 begin
1945 Result := False;
1947 if WordBool(PanelType and PANEL_WALL) then
1948 if gWalls <> nil then
1949 begin
1950 h := High(gWalls);
1952 for a := 0 to h do
1953 if gWalls[a].Enabled and
1954 g_Collide(X, Y, Width, Height,
1955 gWalls[a].X, gWalls[a].Y,
1956 gWalls[a].Width, gWalls[a].Height) then
1957 begin
1958 Result := True;
1959 Exit;
1960 end;
1961 end;
1963 if WordBool(PanelType and PANEL_WATER) then
1964 if gWater <> nil then
1965 begin
1966 h := High(gWater);
1968 for a := 0 to h do
1969 if g_Collide(X, Y, Width, Height,
1970 gWater[a].X, gWater[a].Y,
1971 gWater[a].Width, gWater[a].Height) then
1972 begin
1973 Result := True;
1974 Exit;
1975 end;
1976 end;
1978 if WordBool(PanelType and PANEL_ACID1) then
1979 if gAcid1 <> nil then
1980 begin
1981 h := High(gAcid1);
1983 for a := 0 to h do
1984 if g_Collide(X, Y, Width, Height,
1985 gAcid1[a].X, gAcid1[a].Y,
1986 gAcid1[a].Width, gAcid1[a].Height) then
1987 begin
1988 Result := True;
1989 Exit;
1990 end;
1991 end;
1993 if WordBool(PanelType and PANEL_ACID2) then
1994 if gAcid2 <> nil then
1995 begin
1996 h := High(gAcid2);
1998 for a := 0 to h do
1999 if g_Collide(X, Y, Width, Height,
2000 gAcid2[a].X, gAcid2[a].Y,
2001 gAcid2[a].Width, gAcid2[a].Height) then
2002 begin
2003 Result := True;
2004 Exit;
2005 end;
2006 end;
2008 if WordBool(PanelType and PANEL_STEP) then
2009 if gSteps <> nil then
2010 begin
2011 h := High(gSteps);
2013 for a := 0 to h do
2014 if g_Collide(X, Y, Width, Height,
2015 gSteps[a].X, gSteps[a].Y,
2016 gSteps[a].Width, gSteps[a].Height) then
2017 begin
2018 Result := True;
2019 Exit;
2020 end;
2021 end;
2023 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
2024 if gLifts <> nil then
2025 begin
2026 h := High(gLifts);
2028 for a := 0 to h do
2029 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2030 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2031 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2032 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2033 g_Collide(X, Y, Width, Height,
2034 gLifts[a].X, gLifts[a].Y,
2035 gLifts[a].Width, gLifts[a].Height) then
2036 begin
2037 Result := True;
2038 Exit;
2039 end;
2040 end;
2042 if WordBool(PanelType and PANEL_BLOCKMON) then
2043 if gBlockMon <> nil then
2044 begin
2045 h := High(gBlockMon);
2047 for a := 0 to h do
2048 if ( (not b1x3) or
2049 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2050 g_Collide(X, Y, Width, Height,
2051 gBlockMon[a].X, gBlockMon[a].Y,
2052 gBlockMon[a].Width, gBlockMon[a].Height) then
2053 begin
2054 Result := True;
2055 Exit;
2056 end;
2057 end;
2058 end;
2059 *)
2061 function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean;
2063 function checker (obj: TObject; tag: Integer): Boolean;
2064 var
2065 pan: TPanel;
2066 a: Integer;
2067 begin
2068 result := false; // don't stop, ever
2070 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2072 if obj = nil then
2073 begin
2074 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2075 end;
2076 if not (obj is TPanel) then
2077 begin
2078 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2079 exit;
2080 end;
2082 pan := (obj as TPanel);
2083 a := pan.ArrIdx;
2085 if WordBool(PanelType and PANEL_WALL) and (tag = GridTagWallDoor) then
2086 begin
2087 if gWalls[a].Enabled and g_Collide(X, Y, Width, Height, gWalls[a].X, gWalls[a].Y, gWalls[a].Width, gWalls[a].Height) then
2088 begin
2089 result := true;
2090 exit;
2091 end;
2092 end;
2094 if WordBool(PanelType and PANEL_WATER) and (tag = GridTagWater) then
2095 begin
2096 if g_Collide(X, Y, Width, Height, gWater[a].X, gWater[a].Y, gWater[a].Width, gWater[a].Height) then
2097 begin
2098 result := True;
2099 exit;
2100 end;
2101 end;
2103 if WordBool(PanelType and PANEL_ACID1) and (tag = GridTagAcid1) then
2104 begin
2105 if g_Collide(X, Y, Width, Height, gAcid1[a].X, gAcid1[a].Y, gAcid1[a].Width, gAcid1[a].Height) then
2106 begin
2107 result := True;
2108 exit;
2109 end;
2110 end;
2112 if WordBool(PanelType and PANEL_ACID2) and (tag = GridTagAcid2) then
2113 begin
2114 if g_Collide(X, Y, Width, Height, gAcid2[a].X, gAcid2[a].Y, gAcid2[a].Width, gAcid2[a].Height) then
2115 begin
2116 result := True;
2117 exit;
2118 end;
2119 end;
2121 if WordBool(PanelType and PANEL_STEP) and (tag = GridTagStep) then
2122 begin
2123 if g_Collide(X, Y, Width, Height, gSteps[a].X, gSteps[a].Y, gSteps[a].Width, gSteps[a].Height) then
2124 begin
2125 result := True;
2126 exit;
2127 end;
2128 end;
2130 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) and (tag = GridTagLift) then
2131 begin
2132 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2133 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2134 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2135 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2136 g_Collide(X, Y, Width, Height, gLifts[a].X, gLifts[a].Y, gLifts[a].Width, gLifts[a].Height) then
2137 begin
2138 result := true;
2139 exit;
2140 end;
2141 end;
2143 if WordBool(PanelType and PANEL_BLOCKMON)and (tag = GridTagBlockMon) then
2144 begin
2145 if ((not b1x3) or ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64)) and
2146 g_Collide(X, Y, Width, Height, gBlockMon[a].X, gBlockMon[a].Y, gBlockMon[a].Width, gBlockMon[a].Height) then
2147 begin
2148 result := True;
2149 exit;
2150 end;
2151 end;
2152 end;
2154 begin
2155 result := gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
2156 end;
2159 function g_Map_CollideLiquid_Texture(X, Y: Integer; Width, Height: Word): DWORD;
2160 var
2161 cctype: Integer = 3; // priority: 0: water, 1: acid1, 2: acid2; 3: others (nothing)
2162 texid: DWORD;
2164 // slightly different from the old code, but meh...
2165 function checker (obj: TObject; tag: Integer): Boolean;
2166 var
2167 pan: TPanel;
2168 a: Integer;
2169 begin
2170 result := false; // don't stop, ever
2171 pan := (obj as TPanel);
2172 a := pan.ArrIdx;
2173 // water
2174 if (tag = GridTagWater) then
2175 begin
2176 if g_Collide(X, Y, Width, Height, gWater[a].X, gWater[a].Y, gWater[a].Width, gWater[a].Height) then
2177 begin
2178 result := true; // water has highest priority, so stop right here
2179 texid := gWater[a].GetTextureID();
2180 exit;
2181 end;
2182 end;
2183 // acid1
2184 if (cctype > 1) and (tag = GridTagAcid1) then
2185 begin
2186 if g_Collide(X, Y, Width, Height, gAcid1[a].X, gAcid1[a].Y, gAcid1[a].Width, gAcid1[a].Height) then
2187 begin
2188 cctype := 1;
2189 texid := gAcid1[a].GetTextureID();
2190 exit;
2191 end;
2192 end;
2193 // acid2
2194 if (cctype > 2) and (tag = GridTagAcid2) then
2195 begin
2196 if g_Collide(X, Y, Width, Height, gAcid2[a].X, gAcid2[a].Y, gAcid2[a].Width, gAcid2[a].Height) then
2197 begin
2198 cctype := 2;
2199 texid := gAcid2[a].GetTextureID();
2200 exit;
2201 end;
2202 end;
2203 end;
2205 begin
2206 texid := TEXTURE_NONE;
2207 gMapGrid.forEachInAABB(X, Y, Width, Height, checker);
2208 result := texid;
2209 end;
2211 procedure g_Map_EnableWall(ID: DWORD);
2212 begin
2213 with gWalls[ID] do
2214 begin
2215 Enabled := True;
2216 g_Mark(X, Y, Width, Height, MARK_DOOR, True);
2218 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2219 end;
2220 end;
2222 procedure g_Map_DisableWall(ID: DWORD);
2223 begin
2224 with gWalls[ID] do
2225 begin
2226 Enabled := False;
2227 g_Mark(X, Y, Width, Height, MARK_DOOR, False);
2229 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2230 end;
2231 end;
2233 procedure g_Map_SwitchTexture(PanelType: Word; ID: DWORD; AnimLoop: Byte = 0);
2234 var
2235 tp: TPanel;
2236 begin
2237 case PanelType of
2238 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2239 tp := gWalls[ID];
2240 PANEL_FORE:
2241 tp := gRenderForegrounds[ID];
2242 PANEL_BACK:
2243 tp := gRenderBackgrounds[ID];
2244 PANEL_WATER:
2245 tp := gWater[ID];
2246 PANEL_ACID1:
2247 tp := gAcid1[ID];
2248 PANEL_ACID2:
2249 tp := gAcid2[ID];
2250 PANEL_STEP:
2251 tp := gSteps[ID];
2252 else
2253 Exit;
2254 end;
2256 tp.NextTexture(AnimLoop);
2257 if g_Game_IsServer and g_Game_IsNet then
2258 MH_SEND_PanelTexture(PanelType, ID, AnimLoop);
2259 end;
2261 procedure g_Map_SetLift(ID: DWORD; t: Integer);
2262 begin
2263 if gLifts[ID].LiftType = t then
2264 Exit;
2266 with gLifts[ID] do
2267 begin
2268 LiftType := t;
2270 g_Mark(X, Y, Width, Height, MARK_LIFT, False);
2272 if LiftType = 0 then
2273 g_Mark(X, Y, Width, Height, MARK_LIFTUP, True)
2274 else if LiftType = 1 then
2275 g_Mark(X, Y, Width, Height, MARK_LIFTDOWN, True)
2276 else if LiftType = 2 then
2277 g_Mark(X, Y, Width, Height, MARK_LIFTLEFT, True)
2278 else if LiftType = 3 then
2279 g_Mark(X, Y, Width, Height, MARK_LIFTRIGHT, True);
2281 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2282 end;
2283 end;
2285 function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
2286 var
2287 a: Integer;
2288 PointsArray: Array of TRespawnPoint;
2289 begin
2290 Result := False;
2291 SetLength(PointsArray, 0);
2293 if RespawnPoints = nil then
2294 Exit;
2296 for a := 0 to High(RespawnPoints) do
2297 if RespawnPoints[a].PointType = PointType then
2298 begin
2299 SetLength(PointsArray, Length(PointsArray)+1);
2300 PointsArray[High(PointsArray)] := RespawnPoints[a];
2301 end;
2303 if PointsArray = nil then
2304 Exit;
2306 RespawnPoint := PointsArray[Random(Length(PointsArray))];
2307 Result := True;
2308 end;
2310 function g_Map_GetPointCount(PointType: Byte): Word;
2311 var
2312 a: Integer;
2313 begin
2314 Result := 0;
2316 if RespawnPoints = nil then
2317 Exit;
2319 for a := 0 to High(RespawnPoints) do
2320 if RespawnPoints[a].PointType = PointType then
2321 Result := Result + 1;
2322 end;
2324 function g_Map_HaveFlagPoints(): Boolean;
2325 begin
2326 Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil);
2327 end;
2329 procedure g_Map_ResetFlag(Flag: Byte);
2330 begin
2331 with gFlags[Flag] do
2332 begin
2333 Obj.X := -1000;
2334 Obj.Y := -1000;
2335 Obj.Vel.X := 0;
2336 Obj.Vel.Y := 0;
2337 Direction := D_LEFT;
2338 State := FLAG_STATE_NONE;
2339 if FlagPoints[Flag] <> nil then
2340 begin
2341 Obj.X := FlagPoints[Flag]^.X;
2342 Obj.Y := FlagPoints[Flag]^.Y;
2343 Direction := FlagPoints[Flag]^.Direction;
2344 State := FLAG_STATE_NORMAL;
2345 end;
2346 Count := -1;
2347 end;
2348 end;
2350 procedure g_Map_DrawFlags();
2351 var
2352 i, dx: Integer;
2353 Mirror: TMirrorType;
2354 begin
2355 if gGameSettings.GameMode <> GM_CTF then
2356 Exit;
2358 for i := FLAG_RED to FLAG_BLUE do
2359 with gFlags[i] do
2360 if State <> FLAG_STATE_CAPTURED then
2361 begin
2362 if State = FLAG_STATE_NONE then
2363 continue;
2365 if Direction = D_LEFT then
2366 begin
2367 Mirror := M_HORIZONTAL;
2368 dx := -1;
2369 end
2370 else
2371 begin
2372 Mirror := M_NONE;
2373 dx := 1;
2374 end;
2376 Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
2378 if g_debug_Frames then
2379 begin
2380 e_DrawQuad(Obj.X+Obj.Rect.X,
2381 Obj.Y+Obj.Rect.Y,
2382 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2383 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2384 0, 255, 0);
2385 end;
2386 end;
2387 end;
2389 procedure g_Map_SaveState(Var Mem: TBinMemoryWriter);
2390 var
2391 dw: DWORD;
2392 b: Byte;
2393 str: String;
2394 boo: Boolean;
2396 procedure SavePanelArray(var panels: TPanelArray);
2397 var
2398 PAMem: TBinMemoryWriter;
2399 i: Integer;
2400 begin
2401 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2402 PAMem := TBinMemoryWriter.Create((Length(panels)+1) * 40);
2404 i := 0;
2405 while i < Length(panels) do
2406 begin
2407 if panels[i].SaveIt then
2408 begin
2409 // ID ïàíåëè:
2410 PAMem.WriteInt(i);
2411 // Ñîõðàíÿåì ïàíåëü:
2412 panels[i].SaveState(PAMem);
2413 end;
2414 Inc(i);
2415 end;
2417 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2418 PAMem.SaveToMemory(Mem);
2419 PAMem.Free();
2420 end;
2422 procedure SaveFlag(flag: PFlag);
2423 begin
2424 // Ñèãíàòóðà ôëàãà:
2425 dw := FLAG_SIGNATURE; // 'FLAG'
2426 Mem.WriteDWORD(dw);
2427 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2428 Mem.WriteByte(flag^.RespawnType);
2429 // Ñîñòîÿíèå ôëàãà:
2430 Mem.WriteByte(flag^.State);
2431 // Íàïðàâëåíèå ôëàãà:
2432 if flag^.Direction = D_LEFT then
2433 b := 1
2434 else // D_RIGHT
2435 b := 2;
2436 Mem.WriteByte(b);
2437 // Îáúåêò ôëàãà:
2438 Obj_SaveState(@flag^.Obj, Mem);
2439 end;
2441 begin
2442 Mem := TBinMemoryWriter.Create(1024 * 1024); // 1 MB
2444 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2445 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2446 SavePanelArray(gWalls);
2447 // Ñîõðàíÿåì ïàíåëè ôîíà:
2448 SavePanelArray(gRenderBackgrounds);
2449 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2450 SavePanelArray(gRenderForegrounds);
2451 // Ñîõðàíÿåì ïàíåëè âîäû:
2452 SavePanelArray(gWater);
2453 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2454 SavePanelArray(gAcid1);
2455 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2456 SavePanelArray(gAcid2);
2457 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2458 SavePanelArray(gSteps);
2459 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2460 SavePanelArray(gLifts);
2461 ///// /////
2463 ///// Ñîõðàíÿåì ìóçûêó: /////
2464 // Ñèãíàòóðà ìóçûêè:
2465 dw := MUSIC_SIGNATURE; // 'MUSI'
2466 Mem.WriteDWORD(dw);
2467 // Íàçâàíèå ìóçûêè:
2468 Assert(gMusic <> nil, 'g_Map_SaveState: gMusic = nil');
2469 if gMusic.NoMusic then
2470 str := ''
2471 else
2472 str := gMusic.Name;
2473 Mem.WriteString(str, 64);
2474 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2475 dw := gMusic.GetPosition();
2476 Mem.WriteDWORD(dw);
2477 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2478 boo := gMusic.SpecPause;
2479 Mem.WriteBoolean(boo);
2480 ///// /////
2482 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2483 Mem.WriteInt(gTotalMonsters);
2484 ///// /////
2486 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2487 if gGameSettings.GameMode = GM_CTF then
2488 begin
2489 // Ôëàã Êðàñíîé êîìàíäû:
2490 SaveFlag(@gFlags[FLAG_RED]);
2491 // Ôëàã Ñèíåé êîìàíäû:
2492 SaveFlag(@gFlags[FLAG_BLUE]);
2493 end;
2494 ///// /////
2496 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2497 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2498 begin
2499 // Î÷êè Êðàñíîé êîìàíäû:
2500 Mem.WriteSmallInt(gTeamStat[TEAM_RED].Goals);
2501 // Î÷êè Ñèíåé êîìàíäû:
2502 Mem.WriteSmallInt(gTeamStat[TEAM_BLUE].Goals);
2503 end;
2504 ///// /////
2505 end;
2507 procedure g_Map_LoadState(Var Mem: TBinMemoryReader);
2508 var
2509 dw: DWORD;
2510 b: Byte;
2511 str: String;
2512 boo: Boolean;
2514 procedure LoadPanelArray(var panels: TPanelArray);
2515 var
2516 PAMem: TBinMemoryReader;
2517 i, id: Integer;
2518 begin
2519 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2520 PAMem := TBinMemoryReader.Create();
2521 PAMem.LoadFromMemory(Mem);
2523 for i := 0 to Length(panels)-1 do
2524 if panels[i].SaveIt then
2525 begin
2526 // ID ïàíåëè:
2527 PAMem.ReadInt(id);
2528 if id <> i then
2529 begin
2530 raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2531 end;
2532 // Çàãðóæàåì ïàíåëü:
2533 panels[i].LoadState(PAMem);
2534 end;
2536 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2537 PAMem.Free();
2538 end;
2540 procedure LoadFlag(flag: PFlag);
2541 begin
2542 // Ñèãíàòóðà ôëàãà:
2543 Mem.ReadDWORD(dw);
2544 if dw <> FLAG_SIGNATURE then // 'FLAG'
2545 begin
2546 raise EBinSizeError.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2547 end;
2548 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2549 Mem.ReadByte(flag^.RespawnType);
2550 // Ñîñòîÿíèå ôëàãà:
2551 Mem.ReadByte(flag^.State);
2552 // Íàïðàâëåíèå ôëàãà:
2553 Mem.ReadByte(b);
2554 if b = 1 then
2555 flag^.Direction := D_LEFT
2556 else // b = 2
2557 flag^.Direction := D_RIGHT;
2558 // Îáúåêò ôëàãà:
2559 Obj_LoadState(@flag^.Obj, Mem);
2560 end;
2562 begin
2563 if Mem = nil then
2564 Exit;
2566 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2567 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2568 LoadPanelArray(gWalls);
2569 // Çàãðóæàåì ïàíåëè ôîíà:
2570 LoadPanelArray(gRenderBackgrounds);
2571 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2572 LoadPanelArray(gRenderForegrounds);
2573 // Çàãðóæàåì ïàíåëè âîäû:
2574 LoadPanelArray(gWater);
2575 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2576 LoadPanelArray(gAcid1);
2577 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2578 LoadPanelArray(gAcid2);
2579 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2580 LoadPanelArray(gSteps);
2581 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2582 LoadPanelArray(gLifts);
2583 ///// /////
2585 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2586 g_GFX_Init();
2587 mapCreateGrid();
2589 ///// Çàãðóæàåì ìóçûêó: /////
2590 // Ñèãíàòóðà ìóçûêè:
2591 Mem.ReadDWORD(dw);
2592 if dw <> MUSIC_SIGNATURE then // 'MUSI'
2593 begin
2594 raise EBinSizeError.Create('g_Map_LoadState: Wrong Music Signature');
2595 end;
2596 // Íàçâàíèå ìóçûêè:
2597 Assert(gMusic <> nil, 'g_Map_LoadState: gMusic = nil');
2598 Mem.ReadString(str);
2599 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2600 Mem.ReadDWORD(dw);
2601 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2602 Mem.ReadBoolean(boo);
2603 // Çàïóñêàåì ýòó ìóçûêó:
2604 gMusic.SetByName(str);
2605 gMusic.SpecPause := boo;
2606 gMusic.Play();
2607 gMusic.Pause(True);
2608 gMusic.SetPosition(dw);
2609 ///// /////
2611 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2612 Mem.ReadInt(gTotalMonsters);
2613 ///// /////
2615 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2616 if gGameSettings.GameMode = GM_CTF then
2617 begin
2618 // Ôëàã Êðàñíîé êîìàíäû:
2619 LoadFlag(@gFlags[FLAG_RED]);
2620 // Ôëàã Ñèíåé êîìàíäû:
2621 LoadFlag(@gFlags[FLAG_BLUE]);
2622 end;
2623 ///// /////
2625 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2626 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2627 begin
2628 // Î÷êè Êðàñíîé êîìàíäû:
2629 Mem.ReadSmallInt(gTeamStat[TEAM_RED].Goals);
2630 // Î÷êè Ñèíåé êîìàíäû:
2631 Mem.ReadSmallInt(gTeamStat[TEAM_BLUE].Goals);
2632 end;
2633 ///// /////
2634 end;
2636 function g_Map_PanelForPID(PanelID: Integer; var PanelArrayID: Integer): PPanel;
2637 var
2638 Arr: TPanelArray;
2639 begin
2640 Result := nil;
2641 if (PanelID < 0) or (PanelID > High(PanelByID)) then Exit;
2642 Arr := PanelByID[PanelID].PWhere^;
2643 PanelArrayID := PanelByID[PanelID].PArrID;
2644 Result := Addr(Arr[PanelByID[PanelID].PArrID]);
2645 end;
2647 end.