DEADSOFTWARE

grid now works for any map bounding box; collisions with lifts and blockmons are...
[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'
152 function panelTypeToTag (panelType: Word): Integer;
153 begin
154 case panelType of
155 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: result := 0; // gWalls
156 PANEL_BACK: result := 1; // gRenderBackgrounds
157 PANEL_FORE: result := 2; // gRenderForegrounds
158 PANEL_WATER: result := 3; // gWater
159 PANEL_ACID1: result := 4; // gAcid1
160 PANEL_ACID2: result := 5; // gAcid2
161 PANEL_STEP: result := 6; // gSteps
162 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT: result := 7; // gLifts -- this is for all lifts
163 PANEL_BLOCKMON: result := 8; // gBlockMon -- this is for all blockmons
164 else result := -1;
165 end;
166 end;
169 type
170 TPanelID = record
171 PWhere: ^TPanelArray;
172 PArrID: Integer;
173 end;
175 var
176 PanelById: array of TPanelID;
177 Textures: TLevelTextureArray;
178 RespawnPoints: Array of TRespawnPoint;
179 FlagPoints: Array [FLAG_RED..FLAG_BLUE] of PFlagPoint;
180 //DOMFlagPoints: Array of TFlagPoint;
181 gMapGrid: TBodyGrid = nil;
184 function g_Map_IsSpecialTexture(Texture: String): Boolean;
185 begin
186 Result := (Texture = TEXTURE_NAME_WATER) or
187 (Texture = TEXTURE_NAME_ACID1) or
188 (Texture = TEXTURE_NAME_ACID2);
189 end;
191 procedure CreateDoorMap();
192 var
193 PanelArray: Array of record
194 X, Y: Integer;
195 Width, Height: Word;
196 Active: Boolean;
197 PanelID: DWORD;
198 end;
199 a, b, c, m, i, len: Integer;
200 ok: Boolean;
201 begin
202 if gWalls = nil then
203 Exit;
205 i := 0;
206 len := 128;
207 SetLength(PanelArray, len);
209 for a := 0 to High(gWalls) do
210 if gWalls[a].Door then
211 begin
212 PanelArray[i].X := gWalls[a].X;
213 PanelArray[i].Y := gWalls[a].Y;
214 PanelArray[i].Width := gWalls[a].Width;
215 PanelArray[i].Height := gWalls[a].Height;
216 PanelArray[i].Active := True;
217 PanelArray[i].PanelID := a;
219 i := i + 1;
220 if i = len then
221 begin
222 len := len + 128;
223 SetLength(PanelArray, len);
224 end;
225 end;
227 // Íåò äâåðåé:
228 if i = 0 then
229 begin
230 PanelArray := nil;
231 Exit;
232 end;
234 SetLength(gDoorMap, 0);
236 g_Game_SetLoadingText(_lc[I_LOAD_DOOR_MAP], i-1, False);
238 for a := 0 to i-1 do
239 if PanelArray[a].Active then
240 begin
241 PanelArray[a].Active := False;
242 m := Length(gDoorMap);
243 SetLength(gDoorMap, m+1);
244 SetLength(gDoorMap[m], 1);
245 gDoorMap[m, 0] := PanelArray[a].PanelID;
246 ok := True;
248 while ok do
249 begin
250 ok := False;
252 for b := 0 to i-1 do
253 if PanelArray[b].Active then
254 for c := 0 to High(gDoorMap[m]) do
255 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
256 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
257 g_CollideAround(PanelArray[b].X, PanelArray[b].Y,
258 PanelArray[b].Width, PanelArray[b].Height,
259 gWalls[gDoorMap[m, c]].X,
260 gWalls[gDoorMap[m, c]].Y,
261 gWalls[gDoorMap[m, c]].Width,
262 gWalls[gDoorMap[m, c]].Height) then
263 begin
264 PanelArray[b].Active := False;
265 SetLength(gDoorMap[m],
266 Length(gDoorMap[m])+1);
267 gDoorMap[m, High(gDoorMap[m])] := PanelArray[b].PanelID;
268 ok := True;
269 Break;
270 end;
271 end;
273 g_Game_StepLoading();
274 end;
276 PanelArray := nil;
277 end;
279 procedure CreateLiftMap();
280 var
281 PanelArray: Array of record
282 X, Y: Integer;
283 Width, Height: Word;
284 Active: Boolean;
285 end;
286 a, b, c, len, i, j: Integer;
287 ok: Boolean;
288 begin
289 if gLifts = nil then
290 Exit;
292 len := Length(gLifts);
293 SetLength(PanelArray, len);
295 for a := 0 to len-1 do
296 begin
297 PanelArray[a].X := gLifts[a].X;
298 PanelArray[a].Y := gLifts[a].Y;
299 PanelArray[a].Width := gLifts[a].Width;
300 PanelArray[a].Height := gLifts[a].Height;
301 PanelArray[a].Active := True;
302 end;
304 SetLength(gLiftMap, len);
305 i := 0;
307 g_Game_SetLoadingText(_lc[I_LOAD_LIFT_MAP], len-1, False);
309 for a := 0 to len-1 do
310 if PanelArray[a].Active then
311 begin
312 PanelArray[a].Active := False;
313 SetLength(gLiftMap[i], 32);
314 j := 0;
315 gLiftMap[i, j] := a;
316 ok := True;
318 while ok do
319 begin
320 ok := False;
321 for b := 0 to len-1 do
322 if PanelArray[b].Active then
323 for c := 0 to j do
324 if g_CollideAround(PanelArray[b].X,
325 PanelArray[b].Y,
326 PanelArray[b].Width,
327 PanelArray[b].Height,
328 PanelArray[gLiftMap[i, c]].X,
329 PanelArray[gLiftMap[i, c]].Y,
330 PanelArray[gLiftMap[i, c]].Width,
331 PanelArray[gLiftMap[i, c]].Height) then
332 begin
333 PanelArray[b].Active := False;
334 j := j+1;
335 if j > High(gLiftMap[i]) then
336 SetLength(gLiftMap[i],
337 Length(gLiftMap[i])+32);
339 gLiftMap[i, j] := b;
340 ok := True;
342 Break;
343 end;
344 end;
346 SetLength(gLiftMap[i], j+1);
347 i := i+1;
349 g_Game_StepLoading();
350 end;
352 SetLength(gLiftMap, i);
354 PanelArray := nil;
355 end;
357 function CreatePanel(PanelRec: TPanelRec_1; AddTextures: TAddTextureArray;
358 CurTex: Integer; sav: Boolean): Integer;
359 var
360 len: Integer;
361 panels: ^TPanelArray;
362 begin
363 Result := -1;
365 case PanelRec.PanelType of
366 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
367 panels := @gWalls;
368 PANEL_BACK:
369 panels := @gRenderBackgrounds;
370 PANEL_FORE:
371 panels := @gRenderForegrounds;
372 PANEL_WATER:
373 panels := @gWater;
374 PANEL_ACID1:
375 panels := @gAcid1;
376 PANEL_ACID2:
377 panels := @gAcid2;
378 PANEL_STEP:
379 panels := @gSteps;
380 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
381 panels := @gLifts;
382 PANEL_BLOCKMON:
383 panels := @gBlockMon;
384 else
385 Exit;
386 end;
388 len := Length(panels^);
389 SetLength(panels^, len + 1);
391 panels^[len] := TPanel.Create(PanelRec, AddTextures, CurTex, Textures);
392 panels^[len].ArrIdx := len;
393 if sav then
394 panels^[len].SaveIt := True;
396 Result := len;
398 len := Length(PanelByID);
399 SetLength(PanelByID, len + 1);
400 PanelByID[len].PWhere := panels;
401 PanelByID[len].PArrID := Result;
402 end;
404 function CreateNullTexture(RecName: String): Integer;
405 begin
406 SetLength(Textures, Length(Textures)+1);
407 result := High(Textures);
409 with Textures[High(Textures)] do
410 begin
411 TextureName := RecName;
412 Width := 1;
413 Height := 1;
414 Anim := False;
415 TextureID := TEXTURE_NONE;
416 end;
417 end;
419 function CreateTexture(RecName: String; Map: string; log: Boolean): Integer;
420 var
421 WAD: TWADFile;
422 TextureData: Pointer;
423 WADName, txname: String;
424 a, ResLength: Integer;
425 begin
426 Result := -1;
428 if Textures <> nil then
429 for a := 0 to High(Textures) do
430 if Textures[a].TextureName = RecName then
431 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
432 Result := a;
433 Exit;
434 end;
436 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
437 if (RecName = TEXTURE_NAME_WATER) or
438 (RecName = TEXTURE_NAME_ACID1) or
439 (RecName = TEXTURE_NAME_ACID2) then
440 begin
441 SetLength(Textures, Length(Textures)+1);
443 with Textures[High(Textures)] do
444 begin
445 TextureName := RecName;
447 if TextureName = TEXTURE_NAME_WATER then
448 TextureID := TEXTURE_SPECIAL_WATER
449 else
450 if TextureName = TEXTURE_NAME_ACID1 then
451 TextureID := TEXTURE_SPECIAL_ACID1
452 else
453 if TextureName = TEXTURE_NAME_ACID2 then
454 TextureID := TEXTURE_SPECIAL_ACID2;
456 Anim := False;
457 end;
459 result := High(Textures);
460 Exit;
461 end;
463 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
464 WADName := g_ExtractWadName(RecName);
466 WAD := TWADFile.Create();
468 if WADName <> '' then
469 WADName := GameDir+'/wads/'+WADName
470 else
471 WADName := Map;
473 WAD.ReadFile(WADName);
475 txname := RecName;
477 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
478 begin
479 FreeMem(TextureData);
480 RecName := 'COMMON\ALIEN';
481 end;
484 if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
485 begin
486 SetLength(Textures, Length(Textures)+1);
487 if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then
488 Exit;
489 e_GetTextureSize(Textures[High(Textures)].TextureID,
490 @Textures[High(Textures)].Width,
491 @Textures[High(Textures)].Height);
492 FreeMem(TextureData);
493 Textures[High(Textures)].TextureName := {RecName}txname;
494 Textures[High(Textures)].Anim := False;
496 result := High(Textures);
497 end
498 else // Íåò òàêîãî ðåóñðñà â WAD'å
499 begin
500 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
501 if log then
502 begin
503 e_WriteLog(Format('Error loading texture %s', [RecName]), MSG_WARNING);
504 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
505 end;
506 end;
508 WAD.Free();
509 end;
511 function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Integer;
512 var
513 WAD: TWADFile;
514 TextureWAD: PChar = nil;
515 TextData: Pointer = nil;
516 TextureData: Pointer = nil;
517 cfg: TConfig = nil;
518 WADName: String;
519 ResLength: Integer;
520 TextureResource: String;
521 _width, _height, _framecount, _speed: Integer;
522 _backanimation: Boolean;
523 //imgfmt: string;
524 ia: TDynImageDataArray = nil;
525 f, c, frdelay, frloop: Integer;
526 begin
527 result := -1;
529 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
531 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
532 WADName := g_ExtractWadName(RecName);
534 WAD := TWADFile.Create();
535 try
536 if WADName <> '' then
537 WADName := GameDir+'/wads/'+WADName
538 else
539 WADName := Map;
541 WAD.ReadFile(WADName);
543 if not WAD.GetResource(g_ExtractFilePathName(RecName), TextureWAD, ResLength) then
544 begin
545 if log then
546 begin
547 e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
548 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
549 end;
550 exit;
551 end;
553 {TEST
554 if WADName = Map then
555 begin
556 //FreeMem(TextureWAD);
557 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
558 end;
561 WAD.FreeWAD();
563 if ResLength < 6 then
564 begin
565 e_WriteLog(Format('Animated texture file "%s" too short', [RecName]), MSG_WARNING);
566 exit;
567 end;
569 // ýòî ïòèöà? ýòî ñàìîë¸ò?
570 if (TextureWAD[0] = 'D') and (TextureWAD[1] = 'F') and
571 (TextureWAD[2] = 'W') and (TextureWAD[3] = 'A') and (TextureWAD[4] = 'D') then
572 begin
573 // íåò, ýòî ñóïåðìåí!
574 if not WAD.ReadMemory(TextureWAD, ResLength) then
575 begin
576 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName]), MSG_WARNING);
577 exit;
578 end;
580 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
581 if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then
582 begin
583 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName]), MSG_WARNING);
584 exit;
585 end;
587 cfg := TConfig.CreateMem(TextData, ResLength);
589 TextureResource := cfg.ReadStr('', 'resource', '');
590 if TextureResource = '' then
591 begin
592 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName]), MSG_WARNING);
593 exit;
594 end;
596 _width := cfg.ReadInt('', 'framewidth', 0);
597 _height := cfg.ReadInt('', 'frameheight', 0);
598 _framecount := cfg.ReadInt('', 'framecount', 0);
599 _speed := cfg.ReadInt('', 'waitcount', 0);
600 _backanimation := cfg.ReadBool('', 'backanimation', False);
602 cfg.Free();
603 cfg := nil;
605 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
606 if not WAD.GetResource('TEXTURES/'+TextureResource, TextureData, ResLength) then
607 begin
608 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName, 'TEXTURES/'+TextureResource]), MSG_WARNING);
609 exit;
610 end;
612 WAD.Free();
613 WAD := nil;
615 SetLength(Textures, Length(Textures)+1);
616 with Textures[High(Textures)] do
617 begin
618 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
619 if g_Frames_CreateMemory(@FramesID, '', TextureData, ResLength, _width, _height, _framecount, _backanimation) then
620 begin
621 TextureName := RecName;
622 Width := _width;
623 Height := _height;
624 Anim := True;
625 FramesCount := _framecount;
626 Speed := _speed;
627 result := High(Textures);
628 end
629 else
630 begin
631 if log then e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
632 end;
633 end;
634 end
635 else
636 begin
637 // try animated image
639 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
640 if length(imgfmt) = 0 then
641 begin
642 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
643 exit;
644 end;
646 GlobalMetadata.ClearMetaItems();
647 GlobalMetadata.ClearMetaItemsForSaving();
648 if not LoadMultiImageFromMemory(TextureWAD, ResLength, ia) then
649 begin
650 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName]), MSG_WARNING);
651 exit;
652 end;
653 if length(ia) = 0 then
654 begin
655 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName]), MSG_WARNING);
656 exit;
657 end;
659 WAD.Free();
660 WAD := nil;
662 _width := ia[0].width;
663 _height := ia[0].height;
664 _framecount := length(ia);
665 _speed := 1;
666 _backanimation := false;
667 frdelay := -1;
668 frloop := -666;
669 if GlobalMetadata.HasMetaItem(SMetaFrameDelay) then
670 begin
671 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
672 try
673 f := GlobalMetadata.MetaItems[SMetaFrameDelay];
674 frdelay := f;
675 if f < 0 then f := 0;
676 // rounding ;-)
677 c := f mod 28;
678 if c < 13 then c := 0 else c := 1;
679 f := (f div 28)+c;
680 if f < 1 then f := 1 else if f > 255 then f := 255;
681 _speed := f;
682 except
683 end;
684 end;
685 if GlobalMetadata.HasMetaItem(SMetaAnimationLoops) then
686 begin
687 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
688 try
689 f := GlobalMetadata.MetaItems[SMetaAnimationLoops];
690 frloop := f;
691 if f <> 0 then _backanimation := true; // non-infinite looping == forth-and-back
692 except
693 end;
694 end;
695 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
696 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
697 f := ord(_backanimation);
698 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);
700 SetLength(Textures, Length(Textures)+1);
701 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
702 if g_CreateFramesImg(ia, @Textures[High(Textures)].FramesID, '', _backanimation) then
703 begin
704 Textures[High(Textures)].TextureName := RecName;
705 Textures[High(Textures)].Width := _width;
706 Textures[High(Textures)].Height := _height;
707 Textures[High(Textures)].Anim := True;
708 Textures[High(Textures)].FramesCount := length(ia);
709 Textures[High(Textures)].Speed := _speed;
710 result := High(Textures);
711 //writeln(' CREATED!');
712 end
713 else
714 begin
715 if log then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName]), MSG_WARNING);
716 end;
717 end;
718 finally
719 for f := 0 to High(ia) do FreeImage(ia[f]);
720 WAD.Free();
721 cfg.Free();
722 if TextureWAD <> nil then FreeMem(TextureWAD);
723 if TextData <> nil then FreeMem(TextData);
724 if TextureData <> nil then FreeMem(TextureData);
725 end;
726 end;
728 procedure CreateItem(Item: TItemRec_1);
729 begin
730 if g_Game_IsClient then Exit;
732 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) and
733 ByteBool(Item.Options and ITEM_OPTION_ONLYDM) then
734 Exit;
736 g_Items_Create(Item.X, Item.Y, Item.ItemType, ByteBool(Item.Options and ITEM_OPTION_FALL),
737 gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP]);
738 end;
740 procedure CreateArea(Area: TAreaRec_1);
741 var
742 a: Integer;
743 id: DWORD;
744 begin
745 case Area.AreaType of
746 AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2,
747 AREA_REDTEAMPOINT, AREA_BLUETEAMPOINT:
748 begin
749 SetLength(RespawnPoints, Length(RespawnPoints)+1);
750 with RespawnPoints[High(RespawnPoints)] do
751 begin
752 X := Area.X;
753 Y := Area.Y;
754 Direction := TDirection(Area.Direction);
756 case Area.AreaType of
757 AREA_DMPOINT: PointType := RESPAWNPOINT_DM;
758 AREA_PLAYERPOINT1: PointType := RESPAWNPOINT_PLAYER1;
759 AREA_PLAYERPOINT2: PointType := RESPAWNPOINT_PLAYER2;
760 AREA_REDTEAMPOINT: PointType := RESPAWNPOINT_RED;
761 AREA_BLUETEAMPOINT: PointType := RESPAWNPOINT_BLUE;
762 end;
763 end;
764 end;
766 AREA_REDFLAG, AREA_BLUEFLAG:
767 begin
768 if Area.AreaType = AREA_REDFLAG then a := FLAG_RED else a := FLAG_BLUE;
770 if FlagPoints[a] <> nil then Exit;
772 New(FlagPoints[a]);
774 with FlagPoints[a]^ do
775 begin
776 X := Area.X-FLAGRECT.X;
777 Y := Area.Y-FLAGRECT.Y;
778 Direction := TDirection(Area.Direction);
779 end;
781 with gFlags[a] do
782 begin
783 case a of
784 FLAG_RED: g_Frames_Get(id, 'FRAMES_FLAG_RED');
785 FLAG_BLUE: g_Frames_Get(id, 'FRAMES_FLAG_BLUE');
786 end;
788 Animation := TAnimation.Create(id, True, 8);
789 Obj.Rect := FLAGRECT;
791 g_Map_ResetFlag(a);
792 end;
793 end;
795 AREA_DOMFLAG:
796 begin
797 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
798 with DOMFlagPoints[High(DOMFlagPoints)] do
799 begin
800 X := Area.X;
801 Y := Area.Y;
802 Direction := TDirection(Area.Direction);
803 end;
805 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
806 end;
807 end;
808 end;
810 procedure CreateTrigger(Trigger: TTriggerRec_1; fTexturePanel1Type, fTexturePanel2Type: Word);
811 var
812 _trigger: TTrigger;
813 begin
814 if g_Game_IsClient and not (Trigger.TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) then Exit;
816 with _trigger do
817 begin
818 X := Trigger.X;
819 Y := Trigger.Y;
820 Width := Trigger.Width;
821 Height := Trigger.Height;
822 Enabled := ByteBool(Trigger.Enabled);
823 TexturePanel := Trigger.TexturePanel;
824 TexturePanelType := fTexturePanel1Type;
825 ShotPanelType := fTexturePanel2Type;
826 TriggerType := Trigger.TriggerType;
827 ActivateType := Trigger.ActivateType;
828 Keys := Trigger.Keys;
829 Data.Default := Trigger.DATA;
830 end;
832 g_Triggers_Create(_trigger);
833 end;
835 procedure CreateMonster(monster: TMonsterRec_1);
836 var
837 a, i: Integer;
838 begin
839 if g_Game_IsClient then Exit;
841 if (gGameSettings.GameType = GT_SINGLE)
842 or LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS) then
843 begin
844 i := g_Monsters_Create(monster.MonsterType, monster.X, monster.Y,
845 TDirection(monster.Direction));
847 if gTriggers <> nil then
848 for a := 0 to High(gTriggers) do
849 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
850 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
851 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
852 gMonsters[i].AddTrigger(a);
854 if monster.MonsterType <> MONSTER_BARREL then
855 Inc(gTotalMonsters);
856 end;
857 end;
859 procedure g_Map_ReAdd_DieTriggers();
860 var
861 i, a: Integer;
862 begin
863 if g_Game_IsClient then Exit;
865 for i := 0 to High(gMonsters) do
866 if gMonsters[i] <> nil then
867 begin
868 gMonsters[i].ClearTriggers();
870 for a := 0 to High(gTriggers) do
871 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
872 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
873 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
874 gMonsters[i].AddTrigger(a);
875 end;
876 end;
878 function extractWadName(resourceName: string): string;
879 var
880 posN: Integer;
881 begin
882 posN := Pos(':', resourceName);
883 if posN > 0 then
884 Result:= Copy(resourceName, 0, posN-1)
885 else
886 Result := '';
887 end;
889 procedure addResToExternalResList(res: string);
890 begin
891 res := extractWadName(res);
892 if (res <> '') and (gExternalResources.IndexOf(res) = -1) then
893 gExternalResources.Add(res);
894 end;
896 procedure generateExternalResourcesList(mapReader: TMapReader_1);
897 var
898 textures: TTexturesRec1Array;
899 mapHeader: TMapHeaderRec_1;
900 i: integer;
901 resFile: String = '';
902 begin
903 if gExternalResources = nil then
904 gExternalResources := TStringList.Create;
906 gExternalResources.Clear;
907 textures := mapReader.GetTextures();
908 for i := 0 to High(textures) do
909 begin
910 addResToExternalResList(resFile);
911 end;
913 textures := nil;
915 mapHeader := mapReader.GetMapHeader;
917 addResToExternalResList(mapHeader.MusicName);
918 addResToExternalResList(mapHeader.SkyName);
919 end;
921 procedure mapCreateGrid ();
922 var
923 mapX0: Integer = $3fffffff;
924 mapY0: Integer = $3fffffff;
925 mapX1: Integer = -$3fffffff;
926 mapY1: Integer = -$3fffffff;
928 procedure fixMinMax (var panels: TPanelArray);
929 var
930 idx: Integer;
931 begin
932 for idx := 0 to High(panels) do
933 begin
934 if (panels[idx].Width < 1) or (panels[idx].Height < 1) then continue;
935 if mapX0 > panels[idx].X then mapX0 := panels[idx].X;
936 if mapY0 > panels[idx].Y then mapY0 := panels[idx].Y;
937 if mapX1 < panels[idx].X+panels[idx].Width-1 then mapX1 := panels[idx].X+panels[idx].Width-1;
938 if mapY1 < panels[idx].Y+panels[idx].Height-1 then mapY1 := panels[idx].Y+panels[idx].Height-1;
939 end;
940 end;
942 procedure addPanelsToGrid (var panels: TPanelArray; tag: Integer);
943 var
944 idx: Integer;
945 begin
946 tag := panelTypeToTag(tag);
947 for idx := High(panels) downto 0 do
948 begin
949 gMapGrid.insertBody(panels[idx], panels[idx].X, panels[idx].Y, panels[idx].Width, panels[idx].Height, tag);
950 end;
951 end;
953 begin
954 gMapGrid.Free();
955 gMapGrid := nil;
957 fixMinMax(gWalls);
958 fixMinMax(gRenderBackgrounds);
959 fixMinMax(gRenderForegrounds);
960 fixMinMax(gWater);
961 fixMinMax(gAcid1);
962 fixMinMax(gAcid2);
963 fixMinMax(gSteps);
964 fixMinMax(gLifts);
965 fixMinMax(gBlockMon);
967 if (mapX0 < 0) or (mapY0 < 0) then
968 begin
969 e_WriteLog(Format('funny map dimensions: (%d,%d)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1]), MSG_WARNING);
970 //raise Exception.Create('we are fucked');
971 end;
973 gMapGrid := TBodyGrid.Create(mapX0, mapY0, mapX1-mapX0+1, mapY1-mapY0+1);
975 addPanelsToGrid(gWalls, PANEL_WALL); // and PANEL_CLOSEDOOR
976 addPanelsToGrid(gRenderBackgrounds, PANEL_BACK);
977 addPanelsToGrid(gRenderForegrounds, PANEL_FORE);
978 addPanelsToGrid(gWater, PANEL_WATER);
979 addPanelsToGrid(gAcid1, PANEL_ACID1);
980 addPanelsToGrid(gAcid2, PANEL_ACID2);
981 addPanelsToGrid(gSteps, PANEL_STEP);
982 addPanelsToGrid(gLifts, PANEL_LIFTUP); // it doesn't matter which LIFT type is used here
983 addPanelsToGrid(gBlockMon, PANEL_BLOCKMON);
985 gMapGrid.dumpStats();
986 end;
988 function g_Map_Load(Res: String): Boolean;
989 const
990 DefaultMusRes = 'Standart.wad:STDMUS\MUS1';
991 DefaultSkyRes = 'Standart.wad:STDSKY\SKY0';
992 var
993 WAD: TWADFile;
994 MapReader: TMapReader_1;
995 Header: TMapHeaderRec_1;
996 _textures: TTexturesRec1Array;
997 _texnummap: array of Integer; // `_textures` -> `Textures`
998 panels: TPanelsRec1Array;
999 items: TItemsRec1Array;
1000 monsters: TMonsterRec1Array;
1001 areas: TAreasRec1Array;
1002 triggers: TTriggersRec1Array;
1003 a, b, c, k: Integer;
1004 PanelID: DWORD;
1005 AddTextures: TAddTextureArray;
1006 texture: TTextureRec_1;
1007 TriggersTable: Array of record
1008 TexturePanel: Integer;
1009 LiftPanel: Integer;
1010 DoorPanel: Integer;
1011 ShotPanel: Integer;
1012 end;
1013 FileName, mapResName, s, TexName: String;
1014 Data: Pointer;
1015 Len: Integer;
1016 ok, isAnim, trigRef: Boolean;
1017 CurTex, ntn: Integer;
1019 begin
1020 gMapGrid.Free();
1021 gMapGrid := nil;
1023 Result := False;
1024 gMapInfo.Map := Res;
1025 TriggersTable := nil;
1026 FillChar(texture, SizeOf(texture), 0);
1028 sfsGCDisable(); // temporary disable removing of temporary volumes
1029 try
1030 // Çàãðóçêà WAD:
1031 FileName := g_ExtractWadName(Res);
1032 e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY);
1033 g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False);
1035 WAD := TWADFile.Create();
1036 if not WAD.ReadFile(FileName) then
1037 begin
1038 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [FileName]));
1039 WAD.Free();
1040 Exit;
1041 end;
1042 //k8: why loader ignores path here?
1043 mapResName := g_ExtractFileName(Res);
1044 if not WAD.GetMapResource(mapResName, Data, Len) then
1045 begin
1046 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName]));
1047 WAD.Free();
1048 Exit;
1049 end;
1051 WAD.Free();
1053 // Çàãðóçêà êàðòû:
1054 e_WriteLog('Loading map: '+mapResName, MSG_NOTIFY);
1055 g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False);
1056 MapReader := TMapReader_1.Create();
1058 if not MapReader.LoadMap(Data) then
1059 begin
1060 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]));
1061 FreeMem(Data);
1062 MapReader.Free();
1063 Exit;
1064 end;
1066 FreeMem(Data);
1067 generateExternalResourcesList(MapReader);
1068 // Çàãðóçêà òåêñòóð:
1069 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], 0, False);
1070 _textures := MapReader.GetTextures();
1071 _texnummap := nil;
1073 // Äîáàâëåíèå òåêñòóð â Textures[]:
1074 if _textures <> nil then
1075 begin
1076 e_WriteLog(' Loading textures:', MSG_NOTIFY);
1077 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], High(_textures), False);
1078 SetLength(_texnummap, length(_textures));
1080 for a := 0 to High(_textures) do
1081 begin
1082 SetLength(s, 64);
1083 CopyMemory(@s[1], @_textures[a].Resource[0], 64);
1084 for b := 1 to Length(s) do
1085 if s[b] = #0 then
1086 begin
1087 SetLength(s, b-1);
1088 Break;
1089 end;
1090 e_WriteLog(Format(' Loading texture #%d: %s', [a, s]), MSG_NOTIFY);
1091 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1092 // Àíèìèðîâàííàÿ òåêñòóðà:
1093 if ByteBool(_textures[a].Anim) then
1094 begin
1095 ntn := CreateAnimTexture(_textures[a].Resource, FileName, True);
1096 if ntn < 0 then
1097 begin
1098 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_ANIM], [s]));
1099 ntn := CreateNullTexture(_textures[a].Resource);
1100 end;
1101 end
1102 else // Îáû÷íàÿ òåêñòóðà:
1103 ntn := CreateTexture(_textures[a].Resource, FileName, True);
1104 if ntn < 0 then
1105 begin
1106 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_SIMPLE], [s]));
1107 ntn := CreateNullTexture(_textures[a].Resource);
1108 end;
1110 _texnummap[a] := ntn; // fix texture number
1111 g_Game_StepLoading();
1112 end;
1113 end;
1115 // Çàãðóçêà òðèããåðîâ:
1116 gTriggerClientID := 0;
1117 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1118 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS], 0, False);
1119 triggers := MapReader.GetTriggers();
1121 // Çàãðóçêà ïàíåëåé:
1122 e_WriteLog(' Loading panels...', MSG_NOTIFY);
1123 g_Game_SetLoadingText(_lc[I_LOAD_PANELS], 0, False);
1124 panels := MapReader.GetPanels();
1126 // check texture numbers for panels
1127 for a := 0 to High(panels) do
1128 begin
1129 if panels[a].TextureNum > High(_textures) then
1130 begin
1131 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR);
1132 result := false;
1133 exit;
1134 end;
1135 panels[a].TextureNum := _texnummap[panels[a].TextureNum];
1136 end;
1138 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1139 if triggers <> nil then
1140 begin
1141 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY);
1142 SetLength(TriggersTable, Length(triggers));
1143 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS_TABLE], High(TriggersTable), False);
1145 for a := 0 to High(TriggersTable) do
1146 begin
1147 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1148 TriggersTable[a].TexturePanel := triggers[a].TexturePanel;
1149 // Ëèôòû:
1150 if triggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT] then
1151 TriggersTable[a].LiftPanel := TTriggerData(triggers[a].DATA).PanelID
1152 else
1153 TriggersTable[a].LiftPanel := -1;
1154 // Äâåðè:
1155 if triggers[a].TriggerType in [TRIGGER_OPENDOOR,
1156 TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
1157 TRIGGER_CLOSETRAP, TRIGGER_TRAP] then
1158 TriggersTable[a].DoorPanel := TTriggerData(triggers[a].DATA).PanelID
1159 else
1160 TriggersTable[a].DoorPanel := -1;
1161 // Òóðåëü:
1162 if triggers[a].TriggerType = TRIGGER_SHOT then
1163 TriggersTable[a].ShotPanel := TTriggerData(triggers[a].DATA).ShotPanelID
1164 else
1165 TriggersTable[a].ShotPanel := -1;
1167 g_Game_StepLoading();
1168 end;
1169 end;
1171 // Ñîçäàåì ïàíåëè:
1172 if panels <> nil then
1173 begin
1174 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY);
1175 g_Game_SetLoadingText(_lc[I_LOAD_LINK_TRIGGERS], High(panels), False);
1177 for a := 0 to High(panels) do
1178 begin
1179 SetLength(AddTextures, 0);
1180 trigRef := False;
1181 CurTex := -1;
1182 if _textures <> nil then
1183 begin
1184 texture := _textures[panels[a].TextureNum];
1185 ok := True;
1186 end
1187 else
1188 ok := False;
1190 if ok then
1191 begin
1192 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1193 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1194 ok := False;
1195 if (TriggersTable <> nil) and (_textures <> nil) then
1196 for b := 0 to High(TriggersTable) do
1197 if (TriggersTable[b].TexturePanel = a)
1198 or (TriggersTable[b].ShotPanel = a) then
1199 begin
1200 trigRef := True;
1201 ok := True;
1202 Break;
1203 end;
1204 end;
1206 if ok then
1207 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1208 SetLength(s, 64);
1209 CopyMemory(@s[1], @texture.Resource[0], 64);
1210 // Èçìåðÿåì äëèíó:
1211 Len := Length(s);
1212 for c := Len downto 1 do
1213 if s[c] <> #0 then
1214 begin
1215 Len := c;
1216 Break;
1217 end;
1218 SetLength(s, Len);
1220 // Ñïåö-òåêñòóðû çàïðåùåíû:
1221 if g_Map_IsSpecialTexture(s) then
1222 ok := False
1223 else
1224 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1225 ok := g_Texture_NumNameFindStart(s);
1227 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1228 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1229 if ok then
1230 begin
1231 k := NNF_NAME_BEFORE;
1232 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1233 while ok or (k = NNF_NAME_BEFORE) or
1234 (k = NNF_NAME_EQUALS) do
1235 begin
1236 k := g_Texture_NumNameFindNext(TexName);
1238 if (k = NNF_NAME_BEFORE) or
1239 (k = NNF_NAME_AFTER) then
1240 begin
1241 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1242 if ByteBool(texture.Anim) then
1243 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1244 isAnim := True;
1245 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1246 if not ok then
1247 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1248 isAnim := False;
1249 ok := CreateTexture(TexName, FileName, False) >= 0;
1250 end;
1251 end
1252 else
1253 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1254 isAnim := False;
1255 ok := CreateTexture(TexName, FileName, False) >= 0;
1256 if not ok then
1257 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1258 isAnim := True;
1259 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1260 end;
1261 end;
1263 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1264 if ok then
1265 begin
1266 for c := 0 to High(Textures) do
1267 if Textures[c].TextureName = TexName then
1268 begin
1269 SetLength(AddTextures, Length(AddTextures)+1);
1270 AddTextures[High(AddTextures)].Texture := c;
1271 AddTextures[High(AddTextures)].Anim := isAnim;
1272 Break;
1273 end;
1274 end;
1275 end
1276 else
1277 if k = NNF_NAME_EQUALS then
1278 begin
1279 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1280 SetLength(AddTextures, Length(AddTextures)+1);
1281 AddTextures[High(AddTextures)].Texture := panels[a].TextureNum;
1282 AddTextures[High(AddTextures)].Anim := ByteBool(texture.Anim);
1283 CurTex := High(AddTextures);
1284 ok := True;
1285 end
1286 else // NNF_NO_NAME
1287 ok := False;
1288 end; // while ok...
1290 ok := True;
1291 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1292 end; // if ok - ññûëàþòñÿ òðèããåðû
1294 if not ok then
1295 begin
1296 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1297 SetLength(AddTextures, 1);
1298 AddTextures[0].Texture := panels[a].TextureNum;
1299 AddTextures[0].Anim := ByteBool(texture.Anim);
1300 CurTex := 0;
1301 end;
1303 //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);
1305 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1306 PanelID := CreatePanel(panels[a], AddTextures, CurTex, trigRef);
1308 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1309 if TriggersTable <> nil then
1310 for b := 0 to High(TriggersTable) do
1311 begin
1312 // Òðèããåð äâåðè/ëèôòà:
1313 if (TriggersTable[b].LiftPanel = a) or
1314 (TriggersTable[b].DoorPanel = a) then
1315 TTriggerData(triggers[b].DATA).PanelID := PanelID;
1316 // Òðèããåð ñìåíû òåêñòóðû:
1317 if TriggersTable[b].TexturePanel = a then
1318 triggers[b].TexturePanel := PanelID;
1319 // Òðèããåð "Òóðåëü":
1320 if TriggersTable[b].ShotPanel = a then
1321 TTriggerData(triggers[b].DATA).ShotPanelID := PanelID;
1322 end;
1324 g_Game_StepLoading();
1325 end;
1326 end;
1328 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1329 if (triggers <> nil) and not gLoadGameMode then
1330 begin
1331 e_WriteLog(' Creating triggers...', MSG_NOTIFY);
1332 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_TRIGGERS], 0, False);
1333 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1334 for a := 0 to High(triggers) do
1335 begin
1336 if triggers[a].TexturePanel <> -1 then
1337 b := panels[TriggersTable[a].TexturePanel].PanelType
1338 else
1339 b := 0;
1340 if (triggers[a].TriggerType = TRIGGER_SHOT) and
1341 (TTriggerData(triggers[a].DATA).ShotPanelID <> -1) then
1342 c := panels[TriggersTable[a].ShotPanel].PanelType
1343 else
1344 c := 0;
1345 CreateTrigger(triggers[a], b, c);
1346 end;
1347 end;
1349 // Çàãðóçêà ïðåäìåòîâ:
1350 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1351 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS], 0, False);
1352 items := MapReader.GetItems();
1354 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1355 if (items <> nil) and not gLoadGameMode then
1356 begin
1357 e_WriteLog(' Spawning items...', MSG_NOTIFY);
1358 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_ITEMS], 0, False);
1359 for a := 0 to High(items) do
1360 CreateItem(Items[a]);
1361 end;
1363 // Çàãðóçêà îáëàñòåé:
1364 e_WriteLog(' Loading areas...', MSG_NOTIFY);
1365 g_Game_SetLoadingText(_lc[I_LOAD_AREAS], 0, False);
1366 areas := MapReader.GetAreas();
1368 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1369 if areas <> nil then
1370 begin
1371 e_WriteLog(' Creating areas...', MSG_NOTIFY);
1372 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_AREAS], 0, False);
1373 for a := 0 to High(areas) do
1374 CreateArea(areas[a]);
1375 end;
1377 // Çàãðóçêà ìîíñòðîâ:
1378 e_WriteLog(' Loading monsters...', MSG_NOTIFY);
1379 g_Game_SetLoadingText(_lc[I_LOAD_MONSTERS], 0, False);
1380 monsters := MapReader.GetMonsters();
1382 gTotalMonsters := 0;
1384 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1385 if (monsters <> nil) and not gLoadGameMode then
1386 begin
1387 e_WriteLog(' Spawning monsters...', MSG_NOTIFY);
1388 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_MONSTERS], 0, False);
1389 for a := 0 to High(monsters) do
1390 CreateMonster(monsters[a]);
1391 end;
1393 // Çàãðóçêà îïèñàíèÿ êàðòû:
1394 e_WriteLog(' Reading map info...', MSG_NOTIFY);
1395 g_Game_SetLoadingText(_lc[I_LOAD_MAP_HEADER], 0, False);
1396 Header := MapReader.GetMapHeader();
1398 MapReader.Free();
1400 with gMapInfo do
1401 begin
1402 Name := Header.MapName;
1403 Description := Header.MapDescription;
1404 Author := Header.MapAuthor;
1405 MusicName := Header.MusicName;
1406 SkyName := Header.SkyName;
1407 Height := Header.Height;
1408 Width := Header.Width;
1409 end;
1411 // Çàãðóçêà íåáà:
1412 if gMapInfo.SkyName <> '' then
1413 begin
1414 e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, MSG_NOTIFY);
1415 g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
1416 FileName := g_ExtractWadName(gMapInfo.SkyName);
1418 if FileName <> '' then
1419 FileName := GameDir+'/wads/'+FileName
1420 else
1421 begin
1422 FileName := g_ExtractWadName(Res);
1423 end;
1425 s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName);
1426 if g_Texture_CreateWAD(BackID, s) then
1427 begin
1428 g_Game_SetupScreenSize();
1429 end
1430 else
1431 g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]));
1432 end;
1434 // Çàãðóçêà ìóçûêè:
1435 ok := False;
1436 if gMapInfo.MusicName <> '' then
1437 begin
1438 e_WriteLog(' Loading music: ' + gMapInfo.MusicName, MSG_NOTIFY);
1439 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1440 FileName := g_ExtractWadName(gMapInfo.MusicName);
1442 if FileName <> '' then
1443 FileName := GameDir+'/wads/'+FileName
1444 else
1445 begin
1446 FileName := g_ExtractWadName(Res);
1447 end;
1449 s := FileName+':'+g_ExtractFilePathName(gMapInfo.MusicName);
1450 if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then
1451 ok := True
1452 else
1453 g_FatalError(Format(_lc[I_GAME_ERROR_MUSIC], [s]));
1454 end;
1456 // Îñòàëüíûå óñòàíâêè:
1457 CreateDoorMap();
1458 CreateLiftMap();
1460 g_Items_Init();
1461 g_Weapon_Init();
1462 g_Monsters_Init();
1464 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1465 if not gLoadGameMode then
1466 g_GFX_Init();
1468 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1469 _textures := nil;
1470 panels := nil;
1471 items := nil;
1472 areas := nil;
1473 triggers := nil;
1474 TriggersTable := nil;
1475 AddTextures := nil;
1477 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1478 if ok and (not gLoadGameMode) then
1479 begin
1480 gMusic.SetByName(gMapInfo.MusicName);
1481 gMusic.Play();
1482 end
1483 else
1484 gMusic.SetByName('');
1485 finally
1486 sfsGCEnable(); // enable releasing unused volumes
1487 end;
1489 e_WriteLog('Creating map grid', MSG_NOTIFY);
1490 mapCreateGrid();
1492 e_WriteLog('Done loading map.', MSG_NOTIFY);
1493 Result := True;
1494 end;
1496 function g_Map_GetMapInfo(Res: String): TMapInfo;
1497 var
1498 WAD: TWADFile;
1499 MapReader: TMapReader_1;
1500 Header: TMapHeaderRec_1;
1501 FileName: String;
1502 Data: Pointer;
1503 Len: Integer;
1504 begin
1505 FillChar(Result, SizeOf(Result), 0);
1506 FileName := g_ExtractWadName(Res);
1508 WAD := TWADFile.Create();
1509 if not WAD.ReadFile(FileName) then
1510 begin
1511 WAD.Free();
1512 Exit;
1513 end;
1515 //k8: it ignores path again
1516 if not WAD.GetMapResource(g_ExtractFileName(Res), Data, Len) then
1517 begin
1518 WAD.Free();
1519 Exit;
1520 end;
1522 WAD.Free();
1524 MapReader := TMapReader_1.Create();
1526 if not MapReader.LoadMap(Data) then
1527 begin
1528 g_Console_Add(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]), True);
1529 ZeroMemory(@Header, SizeOf(Header));
1530 Result.Name := _lc[I_GAME_ERROR_MAP_SELECT];
1531 Result.Description := _lc[I_GAME_ERROR_MAP_SELECT];
1532 end
1533 else
1534 begin
1535 Header := MapReader.GetMapHeader();
1536 Result.Name := Header.MapName;
1537 Result.Description := Header.MapDescription;
1538 end;
1540 FreeMem(Data);
1541 MapReader.Free();
1543 Result.Map := Res;
1544 Result.Author := Header.MapAuthor;
1545 Result.Height := Header.Height;
1546 Result.Width := Header.Width;
1547 end;
1549 function g_Map_GetMapsList(WADName: string): SArray;
1550 var
1551 WAD: TWADFile;
1552 a: Integer;
1553 ResList: SArray;
1554 begin
1555 Result := nil;
1556 WAD := TWADFile.Create();
1557 if not WAD.ReadFile(WADName) then
1558 begin
1559 WAD.Free();
1560 Exit;
1561 end;
1562 ResList := WAD.GetMapResources();
1563 if ResList <> nil then
1564 begin
1565 for a := 0 to High(ResList) do
1566 begin
1567 SetLength(Result, Length(Result)+1);
1568 Result[High(Result)] := ResList[a];
1569 end;
1570 end;
1571 WAD.Free();
1572 end;
1574 function g_Map_Exist(Res: string): Boolean;
1575 var
1576 WAD: TWADFile;
1577 FileName, mnn: string;
1578 ResList: SArray;
1579 a: Integer;
1580 begin
1581 Result := False;
1583 FileName := addWadExtension(g_ExtractWadName(Res));
1585 WAD := TWADFile.Create;
1586 if not WAD.ReadFile(FileName) then
1587 begin
1588 WAD.Free();
1589 Exit;
1590 end;
1592 ResList := WAD.GetMapResources();
1593 WAD.Free();
1595 mnn := g_ExtractFileName(Res);
1596 if ResList <> nil then
1597 for a := 0 to High(ResList) do if StrEquCI1251(ResList[a], mnn) then
1598 begin
1599 Result := True;
1600 Exit;
1601 end;
1602 end;
1604 procedure g_Map_Free();
1605 var
1606 a: Integer;
1608 procedure FreePanelArray(var panels: TPanelArray);
1609 var
1610 i: Integer;
1612 begin
1613 if panels <> nil then
1614 begin
1615 for i := 0 to High(panels) do
1616 panels[i].Free();
1617 panels := nil;
1618 end;
1619 end;
1621 begin
1622 g_GFX_Free();
1623 g_Weapon_Free();
1624 g_Items_Free();
1625 g_Triggers_Free();
1626 g_Monsters_Free();
1628 RespawnPoints := nil;
1629 if FlagPoints[FLAG_RED] <> nil then
1630 begin
1631 Dispose(FlagPoints[FLAG_RED]);
1632 FlagPoints[FLAG_RED] := nil;
1633 end;
1634 if FlagPoints[FLAG_BLUE] <> nil then
1635 begin
1636 Dispose(FlagPoints[FLAG_BLUE]);
1637 FlagPoints[FLAG_BLUE] := nil;
1638 end;
1639 //DOMFlagPoints := nil;
1641 //gDOMFlags := nil;
1643 if Textures <> nil then
1644 begin
1645 for a := 0 to High(Textures) do
1646 if not g_Map_IsSpecialTexture(Textures[a].TextureName) then
1647 if Textures[a].Anim then
1648 g_Frames_DeleteByID(Textures[a].FramesID)
1649 else
1650 if Textures[a].TextureID <> TEXTURE_NONE then
1651 e_DeleteTexture(Textures[a].TextureID);
1653 Textures := nil;
1654 end;
1656 FreePanelArray(gWalls);
1657 FreePanelArray(gRenderBackgrounds);
1658 FreePanelArray(gRenderForegrounds);
1659 FreePanelArray(gWater);
1660 FreePanelArray(gAcid1);
1661 FreePanelArray(gAcid2);
1662 FreePanelArray(gSteps);
1663 FreePanelArray(gLifts);
1664 FreePanelArray(gBlockMon);
1666 if BackID <> DWORD(-1) then
1667 begin
1668 gBackSize.X := 0;
1669 gBackSize.Y := 0;
1670 e_DeleteTexture(BackID);
1671 BackID := DWORD(-1);
1672 end;
1674 g_Game_StopAllSounds(False);
1675 gMusic.FreeSound();
1676 g_Sound_Delete(gMapInfo.MusicName);
1678 gMapInfo.Name := '';
1679 gMapInfo.Description := '';
1680 gMapInfo.MusicName := '';
1681 gMapInfo.Height := 0;
1682 gMapInfo.Width := 0;
1684 gDoorMap := nil;
1685 gLiftMap := nil;
1687 PanelByID := nil;
1688 end;
1690 procedure g_Map_Update();
1691 var
1692 a, d, j: Integer;
1693 m: Word;
1694 s: String;
1696 procedure UpdatePanelArray(var panels: TPanelArray);
1697 var
1698 i: Integer;
1700 begin
1701 if panels <> nil then
1702 for i := 0 to High(panels) do
1703 panels[i].Update();
1704 end;
1706 begin
1707 UpdatePanelArray(gWalls);
1708 UpdatePanelArray(gRenderBackgrounds);
1709 UpdatePanelArray(gRenderForegrounds);
1710 UpdatePanelArray(gWater);
1711 UpdatePanelArray(gAcid1);
1712 UpdatePanelArray(gAcid2);
1713 UpdatePanelArray(gSteps);
1715 if gGameSettings.GameMode = GM_CTF then
1716 begin
1717 for a := FLAG_RED to FLAG_BLUE do
1718 if not (gFlags[a].State in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1719 with gFlags[a] do
1720 begin
1721 if gFlags[a].Animation <> nil then
1722 gFlags[a].Animation.Update();
1724 m := g_Obj_Move(@Obj, True, True);
1726 if gTime mod (GAME_TICK*2) <> 0 then
1727 Continue;
1729 // Ñîïðîòèâëåíèå âîçäóõà:
1730 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1732 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1733 if ((Count = 0) or ByteBool(m and MOVE_FALLOUT)) and g_Game_IsServer then
1734 begin
1735 g_Map_ResetFlag(a);
1736 gFlags[a].CaptureTime := 0;
1737 if a = FLAG_RED then
1738 s := _lc[I_PLAYER_FLAG_RED]
1739 else
1740 s := _lc[I_PLAYER_FLAG_BLUE];
1741 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1743 if g_Game_IsNet then
1744 MH_SEND_FlagEvent(FLAG_STATE_RETURNED, a, 0);
1745 Continue;
1746 end;
1748 if Count > 0 then
1749 Count := Count - 1;
1751 // Èãðîê áåðåò ôëàã:
1752 if gPlayers <> nil then
1753 begin
1754 j := Random(Length(gPlayers)) - 1;
1756 for d := 0 to High(gPlayers) do
1757 begin
1758 Inc(j);
1759 if j > High(gPlayers) then
1760 j := 0;
1762 if gPlayers[j] <> nil then
1763 if gPlayers[j].Live and
1764 g_Obj_Collide(@Obj, @gPlayers[j].Obj) then
1765 begin
1766 if gPlayers[j].GetFlag(a) then
1767 Break;
1768 end;
1769 end;
1770 end;
1771 end;
1772 end;
1773 end;
1776 procedure g_Map_DrawPanelsOld(PanelType: Word);
1778 procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False);
1779 var
1780 idx: Integer;
1781 begin
1782 if (panels <> nil) and (stp >= 0) and (stp <= 6) then
1783 begin
1784 // alas, no visible set
1785 for idx := 0 to High(panels) do
1786 begin
1787 if not (drawDoors xor panels[idx].Door) then panels[idx].Draw();
1788 end;
1789 end;
1790 end;
1792 begin
1793 case PanelType of
1794 PANEL_WALL: DrawPanels(0, gWalls);
1795 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1796 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1797 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1798 PANEL_WATER: DrawPanels(3, gWater);
1799 PANEL_ACID1: DrawPanels(4, gAcid1);
1800 PANEL_ACID2: DrawPanels(5, gAcid2);
1801 PANEL_STEP: DrawPanels(6, gSteps);
1802 end;
1803 end;
1806 var
1807 gDrawPanelList: TBinaryHeapObj = nil;
1809 function dplLess (a, b: TObject): Boolean;
1810 begin
1811 result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
1812 end;
1814 procedure dplClear ();
1815 begin
1816 if gDrawPanelList = nil then gDrawPanelList := TBinaryHeapObj.Create(@dplLess) else gDrawPanelList.clear();
1817 end;
1819 procedure dplAddPanel (pan: TPanel);
1820 begin
1821 if pan = nil then exit;
1822 gDrawPanelList.insert(pan);
1823 end;
1826 procedure g_Map_DrawPanels(x0, y0, wdt, hgt: Integer; PanelType: Word);
1827 var
1828 ptag: Integer;
1830 function qq (obj: TObject; tag: Integer): Boolean;
1831 var
1832 pan: TPanel;
1833 begin
1834 result := false; // don't stop, ever
1835 if (tag <> ptag) then exit;
1836 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1838 if obj = nil then begin e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end;
1839 if not (obj is TPanel) then begin e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY); exit; end;
1840 //pan := (obj as TPanel);
1841 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1843 pan := (obj as TPanel);
1844 if (PanelType = PANEL_CLOSEDOOR) then begin if not pan.Door then exit; end else begin if pan.Door then exit; end;
1845 //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);
1846 dplAddPanel(pan);
1847 end;
1849 procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False);
1850 var
1851 idx: Integer;
1852 pan: TPanel;
1853 begin
1854 if (panels <> nil) and (stp >= 0) and (stp <= 6) then
1855 begin
1856 // alas, no visible set
1857 for idx := 0 to High(panels) do
1858 begin
1859 if not (drawDoors xor panels[idx].Door) then
1860 begin
1861 pan := panels[idx];
1862 if (pan.Width < 1) or (pan.Height < 1) then continue;
1863 if (pan.X+pan.Width <= x0) or (pan.Y+pan.Height <= y0) then continue;
1864 if (pan.X >= x0+wdt) or (pan.Y >= y0+hgt) then continue;
1865 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);
1866 end;
1867 end;
1868 end;
1869 end;
1871 begin
1872 //g_Map_DrawPanelsOld(PanelType); exit;
1873 //e_WriteLog('==================', MSG_NOTIFY);
1874 //e_WriteLog(Format('***QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1875 dplClear();
1876 ptag := panelTypeToTag(PanelType);
1877 gMapGrid.forEachInAABB(x0, y0, wdt, hgt, qq);
1879 // debug
1881 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1882 case PanelType of
1883 PANEL_WALL: DrawPanels(0, gWalls);
1884 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1885 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1886 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1887 PANEL_WATER: DrawPanels(3, gWater);
1888 PANEL_ACID1: DrawPanels(4, gAcid1);
1889 PANEL_ACID2: DrawPanels(5, gAcid2);
1890 PANEL_STEP: DrawPanels(6, gSteps);
1891 end;
1892 e_WriteLog('==================', MSG_NOTIFY);
1895 // sort and draw the list (we need to sort it, or rendering is fucked)
1896 while gDrawPanelList.count > 0 do
1897 begin
1898 (gDrawPanelList.front() as TPanel).Draw();
1899 gDrawPanelList.popFront();
1900 end;
1901 end;
1904 procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
1905 function qq (obj: TObject; tag: Integer): Boolean;
1906 var
1907 pan: TPanel;
1908 begin
1909 result := false; // don't stop, ever
1910 if (tag <> 0 {panelTypeToTag(PANEL_WALL)}) then exit; // only walls
1911 pan := (obj as TPanel);
1912 pan.DrawShadowVolume(lightX, lightY, radius);
1913 end;
1915 begin
1916 gMapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, qq);
1917 end;
1920 procedure g_Map_DrawBack(dx, dy: Integer);
1921 begin
1922 if gDrawBackGround and (BackID <> DWORD(-1)) then
1923 e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
1924 else
1925 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
1926 end;
1928 function g_Map_CollidePanelOld(X, Y: Integer; Width, Height: Word;
1929 PanelType: Word; b1x3: Boolean): Boolean;
1930 var
1931 a, h: Integer;
1932 begin
1933 Result := False;
1935 if WordBool(PanelType and PANEL_WALL) then
1936 if gWalls <> nil then
1937 begin
1938 h := High(gWalls);
1940 for a := 0 to h do
1941 if gWalls[a].Enabled and
1942 g_Collide(X, Y, Width, Height,
1943 gWalls[a].X, gWalls[a].Y,
1944 gWalls[a].Width, gWalls[a].Height) then
1945 begin
1946 Result := True;
1947 Exit;
1948 end;
1949 end;
1951 if WordBool(PanelType and PANEL_WATER) then
1952 if gWater <> nil then
1953 begin
1954 h := High(gWater);
1956 for a := 0 to h do
1957 if g_Collide(X, Y, Width, Height,
1958 gWater[a].X, gWater[a].Y,
1959 gWater[a].Width, gWater[a].Height) then
1960 begin
1961 Result := True;
1962 Exit;
1963 end;
1964 end;
1966 if WordBool(PanelType and PANEL_ACID1) then
1967 if gAcid1 <> nil then
1968 begin
1969 h := High(gAcid1);
1971 for a := 0 to h do
1972 if g_Collide(X, Y, Width, Height,
1973 gAcid1[a].X, gAcid1[a].Y,
1974 gAcid1[a].Width, gAcid1[a].Height) then
1975 begin
1976 Result := True;
1977 Exit;
1978 end;
1979 end;
1981 if WordBool(PanelType and PANEL_ACID2) then
1982 if gAcid2 <> nil then
1983 begin
1984 h := High(gAcid2);
1986 for a := 0 to h do
1987 if g_Collide(X, Y, Width, Height,
1988 gAcid2[a].X, gAcid2[a].Y,
1989 gAcid2[a].Width, gAcid2[a].Height) then
1990 begin
1991 Result := True;
1992 Exit;
1993 end;
1994 end;
1996 if WordBool(PanelType and PANEL_STEP) then
1997 if gSteps <> nil then
1998 begin
1999 h := High(gSteps);
2001 for a := 0 to h do
2002 if g_Collide(X, Y, Width, Height,
2003 gSteps[a].X, gSteps[a].Y,
2004 gSteps[a].Width, gSteps[a].Height) then
2005 begin
2006 Result := True;
2007 Exit;
2008 end;
2009 end;
2011 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
2012 if gLifts <> nil then
2013 begin
2014 h := High(gLifts);
2016 for a := 0 to h do
2017 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2018 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2019 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2020 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2021 g_Collide(X, Y, Width, Height,
2022 gLifts[a].X, gLifts[a].Y,
2023 gLifts[a].Width, gLifts[a].Height) then
2024 begin
2025 Result := True;
2026 Exit;
2027 end;
2028 end;
2030 if WordBool(PanelType and PANEL_BLOCKMON) then
2031 if gBlockMon <> nil then
2032 begin
2033 h := High(gBlockMon);
2035 for a := 0 to h do
2036 if ( (not b1x3) or
2037 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2038 g_Collide(X, Y, Width, Height,
2039 gBlockMon[a].X, gBlockMon[a].Y,
2040 gBlockMon[a].Width, gBlockMon[a].Height) then
2041 begin
2042 Result := True;
2043 Exit;
2044 end;
2045 end;
2046 end;
2048 function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean;
2050 function qq (obj: TObject; tag: Integer): Boolean;
2051 var
2052 pan: TPanel;
2053 a: Integer;
2054 begin
2055 result := false; // don't stop, ever
2057 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2059 if obj = nil then
2060 begin
2061 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2062 end;
2063 if not (obj is TPanel) then
2064 begin
2065 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2066 exit;
2067 end;
2069 pan := (obj as TPanel);
2070 a := pan.ArrIdx;
2072 if WordBool(PanelType and PANEL_WALL) and (tag = panelTypeToTag(PANEL_WALL)) then
2073 begin
2074 if gWalls[a].Enabled and g_Collide(X, Y, Width, Height, gWalls[a].X, gWalls[a].Y, gWalls[a].Width, gWalls[a].Height) then
2075 begin
2076 result := true;
2077 exit;
2078 end;
2079 end;
2081 if WordBool(PanelType and PANEL_WATER) and (tag = panelTypeToTag(PANEL_WATER)) then
2082 begin
2083 if g_Collide(X, Y, Width, Height, gWater[a].X, gWater[a].Y, gWater[a].Width, gWater[a].Height) then
2084 begin
2085 result := True;
2086 exit;
2087 end;
2088 end;
2090 if WordBool(PanelType and PANEL_ACID1) and (tag = panelTypeToTag(PANEL_ACID1)) then
2091 begin
2092 if g_Collide(X, Y, Width, Height, gAcid1[a].X, gAcid1[a].Y, gAcid1[a].Width, gAcid1[a].Height) then
2093 begin
2094 result := True;
2095 exit;
2096 end;
2097 end;
2099 if WordBool(PanelType and PANEL_ACID2) and (tag = panelTypeToTag(PANEL_ACID2)) then
2100 begin
2101 if g_Collide(X, Y, Width, Height, gAcid2[a].X, gAcid2[a].Y, gAcid2[a].Width, gAcid2[a].Height) then
2102 begin
2103 result := True;
2104 exit;
2105 end;
2106 end;
2108 if WordBool(PanelType and PANEL_STEP) and (tag = panelTypeToTag(PANEL_STEP)) then
2109 begin
2110 if g_Collide(X, Y, Width, Height, gSteps[a].X, gSteps[a].Y, gSteps[a].Width, gSteps[a].Height) then
2111 begin
2112 result := True;
2113 exit;
2114 end;
2115 end;
2117 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) and (tag = panelTypeToTag(PANEL_LIFTUP)) then
2118 begin
2119 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2120 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2121 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2122 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2123 g_Collide(X, Y, Width, Height, gLifts[a].X, gLifts[a].Y, gLifts[a].Width, gLifts[a].Height) then
2124 begin
2125 result := true;
2126 exit;
2127 end;
2128 end;
2130 if WordBool(PanelType and PANEL_BLOCKMON)and (tag = panelTypeToTag(PANEL_BLOCKMON)) then
2131 begin
2132 if ((not b1x3) or ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64)) and
2133 g_Collide(X, Y, Width, Height, gBlockMon[a].X, gBlockMon[a].Y, gBlockMon[a].Width, gBlockMon[a].Height) then
2134 begin
2135 result := True;
2136 exit;
2137 end;
2138 end;
2139 end;
2141 begin
2142 result := gMapGrid.forEachInAABB(X, Y, Width, Height, qq);
2143 end;
2146 function g_Map_CollideLiquid_Texture(X, Y: Integer; Width, Height: Word): DWORD;
2147 var
2148 a, h: Integer;
2149 begin
2150 Result := TEXTURE_NONE;
2152 if gWater <> nil then
2153 begin
2154 h := High(gWater);
2156 for a := 0 to h do
2157 if g_Collide(X, Y, Width, Height,
2158 gWater[a].X, gWater[a].Y,
2159 gWater[a].Width, gWater[a].Height) then
2160 begin
2161 Result := gWater[a].GetTextureID();
2162 Exit;
2163 end;
2164 end;
2166 if gAcid1 <> nil then
2167 begin
2168 h := High(gAcid1);
2170 for a := 0 to h do
2171 if g_Collide(X, Y, Width, Height,
2172 gAcid1[a].X, gAcid1[a].Y,
2173 gAcid1[a].Width, gAcid1[a].Height) then
2174 begin
2175 Result := gAcid1[a].GetTextureID();
2176 Exit;
2177 end;
2178 end;
2180 if gAcid2 <> nil then
2181 begin
2182 h := High(gAcid2);
2184 for a := 0 to h do
2185 if g_Collide(X, Y, Width, Height,
2186 gAcid2[a].X, gAcid2[a].Y,
2187 gAcid2[a].Width, gAcid2[a].Height) then
2188 begin
2189 Result := gAcid2[a].GetTextureID();
2190 Exit;
2191 end;
2192 end;
2193 end;
2195 procedure g_Map_EnableWall(ID: DWORD);
2196 begin
2197 with gWalls[ID] do
2198 begin
2199 Enabled := True;
2200 g_Mark(X, Y, Width, Height, MARK_DOOR, True);
2202 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2203 end;
2204 end;
2206 procedure g_Map_DisableWall(ID: DWORD);
2207 begin
2208 with gWalls[ID] do
2209 begin
2210 Enabled := False;
2211 g_Mark(X, Y, Width, Height, MARK_DOOR, False);
2213 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2214 end;
2215 end;
2217 procedure g_Map_SwitchTexture(PanelType: Word; ID: DWORD; AnimLoop: Byte = 0);
2218 var
2219 tp: TPanel;
2220 begin
2221 case PanelType of
2222 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2223 tp := gWalls[ID];
2224 PANEL_FORE:
2225 tp := gRenderForegrounds[ID];
2226 PANEL_BACK:
2227 tp := gRenderBackgrounds[ID];
2228 PANEL_WATER:
2229 tp := gWater[ID];
2230 PANEL_ACID1:
2231 tp := gAcid1[ID];
2232 PANEL_ACID2:
2233 tp := gAcid2[ID];
2234 PANEL_STEP:
2235 tp := gSteps[ID];
2236 else
2237 Exit;
2238 end;
2240 tp.NextTexture(AnimLoop);
2241 if g_Game_IsServer and g_Game_IsNet then
2242 MH_SEND_PanelTexture(PanelType, ID, AnimLoop);
2243 end;
2245 procedure g_Map_SetLift(ID: DWORD; t: Integer);
2246 begin
2247 if gLifts[ID].LiftType = t then
2248 Exit;
2250 with gLifts[ID] do
2251 begin
2252 LiftType := t;
2254 g_Mark(X, Y, Width, Height, MARK_LIFT, False);
2256 if LiftType = 0 then
2257 g_Mark(X, Y, Width, Height, MARK_LIFTUP, True)
2258 else if LiftType = 1 then
2259 g_Mark(X, Y, Width, Height, MARK_LIFTDOWN, True)
2260 else if LiftType = 2 then
2261 g_Mark(X, Y, Width, Height, MARK_LIFTLEFT, True)
2262 else if LiftType = 3 then
2263 g_Mark(X, Y, Width, Height, MARK_LIFTRIGHT, True);
2265 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2266 end;
2267 end;
2269 function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
2270 var
2271 a: Integer;
2272 PointsArray: Array of TRespawnPoint;
2273 begin
2274 Result := False;
2275 SetLength(PointsArray, 0);
2277 if RespawnPoints = nil then
2278 Exit;
2280 for a := 0 to High(RespawnPoints) do
2281 if RespawnPoints[a].PointType = PointType then
2282 begin
2283 SetLength(PointsArray, Length(PointsArray)+1);
2284 PointsArray[High(PointsArray)] := RespawnPoints[a];
2285 end;
2287 if PointsArray = nil then
2288 Exit;
2290 RespawnPoint := PointsArray[Random(Length(PointsArray))];
2291 Result := True;
2292 end;
2294 function g_Map_GetPointCount(PointType: Byte): Word;
2295 var
2296 a: Integer;
2297 begin
2298 Result := 0;
2300 if RespawnPoints = nil then
2301 Exit;
2303 for a := 0 to High(RespawnPoints) do
2304 if RespawnPoints[a].PointType = PointType then
2305 Result := Result + 1;
2306 end;
2308 function g_Map_HaveFlagPoints(): Boolean;
2309 begin
2310 Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil);
2311 end;
2313 procedure g_Map_ResetFlag(Flag: Byte);
2314 begin
2315 with gFlags[Flag] do
2316 begin
2317 Obj.X := -1000;
2318 Obj.Y := -1000;
2319 Obj.Vel.X := 0;
2320 Obj.Vel.Y := 0;
2321 Direction := D_LEFT;
2322 State := FLAG_STATE_NONE;
2323 if FlagPoints[Flag] <> nil then
2324 begin
2325 Obj.X := FlagPoints[Flag]^.X;
2326 Obj.Y := FlagPoints[Flag]^.Y;
2327 Direction := FlagPoints[Flag]^.Direction;
2328 State := FLAG_STATE_NORMAL;
2329 end;
2330 Count := -1;
2331 end;
2332 end;
2334 procedure g_Map_DrawFlags();
2335 var
2336 i, dx: Integer;
2337 Mirror: TMirrorType;
2338 begin
2339 if gGameSettings.GameMode <> GM_CTF then
2340 Exit;
2342 for i := FLAG_RED to FLAG_BLUE do
2343 with gFlags[i] do
2344 if State <> FLAG_STATE_CAPTURED then
2345 begin
2346 if State = FLAG_STATE_NONE then
2347 continue;
2349 if Direction = D_LEFT then
2350 begin
2351 Mirror := M_HORIZONTAL;
2352 dx := -1;
2353 end
2354 else
2355 begin
2356 Mirror := M_NONE;
2357 dx := 1;
2358 end;
2360 Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
2362 if g_debug_Frames then
2363 begin
2364 e_DrawQuad(Obj.X+Obj.Rect.X,
2365 Obj.Y+Obj.Rect.Y,
2366 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2367 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2368 0, 255, 0);
2369 end;
2370 end;
2371 end;
2373 procedure g_Map_SaveState(Var Mem: TBinMemoryWriter);
2374 var
2375 dw: DWORD;
2376 b: Byte;
2377 str: String;
2378 boo: Boolean;
2380 procedure SavePanelArray(var panels: TPanelArray);
2381 var
2382 PAMem: TBinMemoryWriter;
2383 i: Integer;
2384 begin
2385 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2386 PAMem := TBinMemoryWriter.Create((Length(panels)+1) * 40);
2388 i := 0;
2389 while i < Length(panels) do
2390 begin
2391 if panels[i].SaveIt then
2392 begin
2393 // ID ïàíåëè:
2394 PAMem.WriteInt(i);
2395 // Ñîõðàíÿåì ïàíåëü:
2396 panels[i].SaveState(PAMem);
2397 end;
2398 Inc(i);
2399 end;
2401 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2402 PAMem.SaveToMemory(Mem);
2403 PAMem.Free();
2404 end;
2406 procedure SaveFlag(flag: PFlag);
2407 begin
2408 // Ñèãíàòóðà ôëàãà:
2409 dw := FLAG_SIGNATURE; // 'FLAG'
2410 Mem.WriteDWORD(dw);
2411 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2412 Mem.WriteByte(flag^.RespawnType);
2413 // Ñîñòîÿíèå ôëàãà:
2414 Mem.WriteByte(flag^.State);
2415 // Íàïðàâëåíèå ôëàãà:
2416 if flag^.Direction = D_LEFT then
2417 b := 1
2418 else // D_RIGHT
2419 b := 2;
2420 Mem.WriteByte(b);
2421 // Îáúåêò ôëàãà:
2422 Obj_SaveState(@flag^.Obj, Mem);
2423 end;
2425 begin
2426 Mem := TBinMemoryWriter.Create(1024 * 1024); // 1 MB
2428 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2429 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2430 SavePanelArray(gWalls);
2431 // Ñîõðàíÿåì ïàíåëè ôîíà:
2432 SavePanelArray(gRenderBackgrounds);
2433 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2434 SavePanelArray(gRenderForegrounds);
2435 // Ñîõðàíÿåì ïàíåëè âîäû:
2436 SavePanelArray(gWater);
2437 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2438 SavePanelArray(gAcid1);
2439 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2440 SavePanelArray(gAcid2);
2441 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2442 SavePanelArray(gSteps);
2443 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2444 SavePanelArray(gLifts);
2445 ///// /////
2447 ///// Ñîõðàíÿåì ìóçûêó: /////
2448 // Ñèãíàòóðà ìóçûêè:
2449 dw := MUSIC_SIGNATURE; // 'MUSI'
2450 Mem.WriteDWORD(dw);
2451 // Íàçâàíèå ìóçûêè:
2452 Assert(gMusic <> nil, 'g_Map_SaveState: gMusic = nil');
2453 if gMusic.NoMusic then
2454 str := ''
2455 else
2456 str := gMusic.Name;
2457 Mem.WriteString(str, 64);
2458 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2459 dw := gMusic.GetPosition();
2460 Mem.WriteDWORD(dw);
2461 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2462 boo := gMusic.SpecPause;
2463 Mem.WriteBoolean(boo);
2464 ///// /////
2466 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2467 Mem.WriteInt(gTotalMonsters);
2468 ///// /////
2470 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2471 if gGameSettings.GameMode = GM_CTF then
2472 begin
2473 // Ôëàã Êðàñíîé êîìàíäû:
2474 SaveFlag(@gFlags[FLAG_RED]);
2475 // Ôëàã Ñèíåé êîìàíäû:
2476 SaveFlag(@gFlags[FLAG_BLUE]);
2477 end;
2478 ///// /////
2480 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2481 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2482 begin
2483 // Î÷êè Êðàñíîé êîìàíäû:
2484 Mem.WriteSmallInt(gTeamStat[TEAM_RED].Goals);
2485 // Î÷êè Ñèíåé êîìàíäû:
2486 Mem.WriteSmallInt(gTeamStat[TEAM_BLUE].Goals);
2487 end;
2488 ///// /////
2489 end;
2491 procedure g_Map_LoadState(Var Mem: TBinMemoryReader);
2492 var
2493 dw: DWORD;
2494 b: Byte;
2495 str: String;
2496 boo: Boolean;
2498 procedure LoadPanelArray(var panels: TPanelArray);
2499 var
2500 PAMem: TBinMemoryReader;
2501 i, id: Integer;
2502 begin
2503 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2504 PAMem := TBinMemoryReader.Create();
2505 PAMem.LoadFromMemory(Mem);
2507 for i := 0 to Length(panels)-1 do
2508 if panels[i].SaveIt then
2509 begin
2510 // ID ïàíåëè:
2511 PAMem.ReadInt(id);
2512 if id <> i then
2513 begin
2514 raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2515 end;
2516 // Çàãðóæàåì ïàíåëü:
2517 panels[i].LoadState(PAMem);
2518 end;
2520 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2521 PAMem.Free();
2522 end;
2524 procedure LoadFlag(flag: PFlag);
2525 begin
2526 // Ñèãíàòóðà ôëàãà:
2527 Mem.ReadDWORD(dw);
2528 if dw <> FLAG_SIGNATURE then // 'FLAG'
2529 begin
2530 raise EBinSizeError.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2531 end;
2532 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2533 Mem.ReadByte(flag^.RespawnType);
2534 // Ñîñòîÿíèå ôëàãà:
2535 Mem.ReadByte(flag^.State);
2536 // Íàïðàâëåíèå ôëàãà:
2537 Mem.ReadByte(b);
2538 if b = 1 then
2539 flag^.Direction := D_LEFT
2540 else // b = 2
2541 flag^.Direction := D_RIGHT;
2542 // Îáúåêò ôëàãà:
2543 Obj_LoadState(@flag^.Obj, Mem);
2544 end;
2546 begin
2547 if Mem = nil then
2548 Exit;
2550 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2551 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2552 LoadPanelArray(gWalls);
2553 // Çàãðóæàåì ïàíåëè ôîíà:
2554 LoadPanelArray(gRenderBackgrounds);
2555 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2556 LoadPanelArray(gRenderForegrounds);
2557 // Çàãðóæàåì ïàíåëè âîäû:
2558 LoadPanelArray(gWater);
2559 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2560 LoadPanelArray(gAcid1);
2561 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2562 LoadPanelArray(gAcid2);
2563 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2564 LoadPanelArray(gSteps);
2565 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2566 LoadPanelArray(gLifts);
2567 ///// /////
2569 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó:
2570 g_GFX_Init();
2571 mapCreateGrid();
2573 ///// Çàãðóæàåì ìóçûêó: /////
2574 // Ñèãíàòóðà ìóçûêè:
2575 Mem.ReadDWORD(dw);
2576 if dw <> MUSIC_SIGNATURE then // 'MUSI'
2577 begin
2578 raise EBinSizeError.Create('g_Map_LoadState: Wrong Music Signature');
2579 end;
2580 // Íàçâàíèå ìóçûêè:
2581 Assert(gMusic <> nil, 'g_Map_LoadState: gMusic = nil');
2582 Mem.ReadString(str);
2583 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2584 Mem.ReadDWORD(dw);
2585 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2586 Mem.ReadBoolean(boo);
2587 // Çàïóñêàåì ýòó ìóçûêó:
2588 gMusic.SetByName(str);
2589 gMusic.SpecPause := boo;
2590 gMusic.Play();
2591 gMusic.Pause(True);
2592 gMusic.SetPosition(dw);
2593 ///// /////
2595 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2596 Mem.ReadInt(gTotalMonsters);
2597 ///// /////
2599 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2600 if gGameSettings.GameMode = GM_CTF then
2601 begin
2602 // Ôëàã Êðàñíîé êîìàíäû:
2603 LoadFlag(@gFlags[FLAG_RED]);
2604 // Ôëàã Ñèíåé êîìàíäû:
2605 LoadFlag(@gFlags[FLAG_BLUE]);
2606 end;
2607 ///// /////
2609 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2610 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2611 begin
2612 // Î÷êè Êðàñíîé êîìàíäû:
2613 Mem.ReadSmallInt(gTeamStat[TEAM_RED].Goals);
2614 // Î÷êè Ñèíåé êîìàíäû:
2615 Mem.ReadSmallInt(gTeamStat[TEAM_BLUE].Goals);
2616 end;
2617 ///// /////
2618 end;
2620 function g_Map_PanelForPID(PanelID: Integer; var PanelArrayID: Integer): PPanel;
2621 var
2622 Arr: TPanelArray;
2623 begin
2624 Result := nil;
2625 if (PanelID < 0) or (PanelID > High(PanelByID)) then Exit;
2626 Arr := PanelByID[PanelID].PWhere^;
2627 PanelArrayID := PanelByID[PanelID].PArrID;
2628 Result := Addr(Arr[PanelByID[PanelID].PArrID]);
2629 end;
2631 end.