DEADSOFTWARE

b2e35c0eb0b3044abc5308cd98354f286651a9c8
[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;
134 gMapGrid: TBodyGrid = nil;
136 implementation
138 uses
139 g_main, e_log, SysUtils, g_items, g_gfx, g_console,
140 GL, GLExt, g_weapons, g_game, g_sound, e_sound, CONFIG,
141 g_options, MAPREADER, g_triggers, g_player, MAPDEF,
142 Math, g_monsters, g_saveload, g_language, g_netmsg,
143 utils, sfs,
144 ImagingTypes, Imaging, ImagingUtility,
145 ImagingGif, ImagingNetworkGraphics;
147 const
148 FLAGRECT: TRectWH = (X:15; Y:12; Width:33; Height:52);
149 MUSIC_SIGNATURE = $4953554D; // 'MUSI'
150 FLAG_SIGNATURE = $47414C46; // 'FLAG'
152 type
153 TPanelID = record
154 PWhere: ^TPanelArray;
155 PArrID: Integer;
156 end;
158 var
159 PanelById: array of TPanelID;
160 Textures: TLevelTextureArray;
161 RespawnPoints: Array of TRespawnPoint;
162 FlagPoints: Array [FLAG_RED..FLAG_BLUE] of PFlagPoint;
163 //DOMFlagPoints: Array of TFlagPoint;
166 function g_Map_IsSpecialTexture(Texture: String): Boolean;
167 begin
168 Result := (Texture = TEXTURE_NAME_WATER) or
169 (Texture = TEXTURE_NAME_ACID1) or
170 (Texture = TEXTURE_NAME_ACID2);
171 end;
173 procedure CreateDoorMap();
174 var
175 PanelArray: Array of record
176 X, Y: Integer;
177 Width, Height: Word;
178 Active: Boolean;
179 PanelID: DWORD;
180 end;
181 a, b, c, m, i, len: Integer;
182 ok: Boolean;
183 begin
184 if gWalls = nil then
185 Exit;
187 i := 0;
188 len := 128;
189 SetLength(PanelArray, len);
191 for a := 0 to High(gWalls) do
192 if gWalls[a].Door then
193 begin
194 PanelArray[i].X := gWalls[a].X;
195 PanelArray[i].Y := gWalls[a].Y;
196 PanelArray[i].Width := gWalls[a].Width;
197 PanelArray[i].Height := gWalls[a].Height;
198 PanelArray[i].Active := True;
199 PanelArray[i].PanelID := a;
201 i := i + 1;
202 if i = len then
203 begin
204 len := len + 128;
205 SetLength(PanelArray, len);
206 end;
207 end;
209 // Íåò äâåðåé:
210 if i = 0 then
211 begin
212 PanelArray := nil;
213 Exit;
214 end;
216 SetLength(gDoorMap, 0);
218 g_Game_SetLoadingText(_lc[I_LOAD_DOOR_MAP], i-1, False);
220 for a := 0 to i-1 do
221 if PanelArray[a].Active then
222 begin
223 PanelArray[a].Active := False;
224 m := Length(gDoorMap);
225 SetLength(gDoorMap, m+1);
226 SetLength(gDoorMap[m], 1);
227 gDoorMap[m, 0] := PanelArray[a].PanelID;
228 ok := True;
230 while ok do
231 begin
232 ok := False;
234 for b := 0 to i-1 do
235 if PanelArray[b].Active then
236 for c := 0 to High(gDoorMap[m]) do
237 if {((gRenderWalls[PanelArray[b].RenderPanelID].TextureID = gRenderWalls[gDoorMap[m, c]].TextureID) or
238 gRenderWalls[PanelArray[b].RenderPanelID].Hide or gRenderWalls[gDoorMap[m, c]].Hide) and}
239 g_CollideAround(PanelArray[b].X, PanelArray[b].Y,
240 PanelArray[b].Width, PanelArray[b].Height,
241 gWalls[gDoorMap[m, c]].X,
242 gWalls[gDoorMap[m, c]].Y,
243 gWalls[gDoorMap[m, c]].Width,
244 gWalls[gDoorMap[m, c]].Height) then
245 begin
246 PanelArray[b].Active := False;
247 SetLength(gDoorMap[m],
248 Length(gDoorMap[m])+1);
249 gDoorMap[m, High(gDoorMap[m])] := PanelArray[b].PanelID;
250 ok := True;
251 Break;
252 end;
253 end;
255 g_Game_StepLoading();
256 end;
258 PanelArray := nil;
259 end;
261 procedure CreateLiftMap();
262 var
263 PanelArray: Array of record
264 X, Y: Integer;
265 Width, Height: Word;
266 Active: Boolean;
267 end;
268 a, b, c, len, i, j: Integer;
269 ok: Boolean;
270 begin
271 if gLifts = nil then
272 Exit;
274 len := Length(gLifts);
275 SetLength(PanelArray, len);
277 for a := 0 to len-1 do
278 begin
279 PanelArray[a].X := gLifts[a].X;
280 PanelArray[a].Y := gLifts[a].Y;
281 PanelArray[a].Width := gLifts[a].Width;
282 PanelArray[a].Height := gLifts[a].Height;
283 PanelArray[a].Active := True;
284 end;
286 SetLength(gLiftMap, len);
287 i := 0;
289 g_Game_SetLoadingText(_lc[I_LOAD_LIFT_MAP], len-1, False);
291 for a := 0 to len-1 do
292 if PanelArray[a].Active then
293 begin
294 PanelArray[a].Active := False;
295 SetLength(gLiftMap[i], 32);
296 j := 0;
297 gLiftMap[i, j] := a;
298 ok := True;
300 while ok do
301 begin
302 ok := False;
303 for b := 0 to len-1 do
304 if PanelArray[b].Active then
305 for c := 0 to j do
306 if g_CollideAround(PanelArray[b].X,
307 PanelArray[b].Y,
308 PanelArray[b].Width,
309 PanelArray[b].Height,
310 PanelArray[gLiftMap[i, c]].X,
311 PanelArray[gLiftMap[i, c]].Y,
312 PanelArray[gLiftMap[i, c]].Width,
313 PanelArray[gLiftMap[i, c]].Height) then
314 begin
315 PanelArray[b].Active := False;
316 j := j+1;
317 if j > High(gLiftMap[i]) then
318 SetLength(gLiftMap[i],
319 Length(gLiftMap[i])+32);
321 gLiftMap[i, j] := b;
322 ok := True;
324 Break;
325 end;
326 end;
328 SetLength(gLiftMap[i], j+1);
329 i := i+1;
331 g_Game_StepLoading();
332 end;
334 SetLength(gLiftMap, i);
336 PanelArray := nil;
337 end;
339 function CreatePanel(PanelRec: TPanelRec_1; AddTextures: TAddTextureArray;
340 CurTex: Integer; sav: Boolean): Integer;
341 var
342 len: Integer;
343 panels: ^TPanelArray;
344 begin
345 Result := -1;
347 case PanelRec.PanelType of
348 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
349 panels := @gWalls;
350 PANEL_BACK:
351 panels := @gRenderBackgrounds;
352 PANEL_FORE:
353 panels := @gRenderForegrounds;
354 PANEL_WATER:
355 panels := @gWater;
356 PANEL_ACID1:
357 panels := @gAcid1;
358 PANEL_ACID2:
359 panels := @gAcid2;
360 PANEL_STEP:
361 panels := @gSteps;
362 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
363 panels := @gLifts;
364 PANEL_BLOCKMON:
365 panels := @gBlockMon;
366 else
367 Exit;
368 end;
370 len := Length(panels^);
371 SetLength(panels^, len + 1);
373 panels^[len] := TPanel.Create(PanelRec, AddTextures, CurTex, Textures);
374 panels^[len].ArrIdx := len;
375 if sav then
376 panels^[len].SaveIt := True;
378 Result := len;
380 len := Length(PanelByID);
381 SetLength(PanelByID, len + 1);
382 PanelByID[len].PWhere := panels;
383 PanelByID[len].PArrID := Result;
384 end;
386 function CreateNullTexture(RecName: String): Integer;
387 begin
388 SetLength(Textures, Length(Textures)+1);
389 result := High(Textures);
391 with Textures[High(Textures)] do
392 begin
393 TextureName := RecName;
394 Width := 1;
395 Height := 1;
396 Anim := False;
397 TextureID := TEXTURE_NONE;
398 end;
399 end;
401 function CreateTexture(RecName: String; Map: string; log: Boolean): Integer;
402 var
403 WAD: TWADFile;
404 TextureData: Pointer;
405 WADName, txname: String;
406 a, ResLength: Integer;
407 begin
408 Result := -1;
410 if Textures <> nil then
411 for a := 0 to High(Textures) do
412 if Textures[a].TextureName = RecName then
413 begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
414 Result := a;
415 Exit;
416 end;
418 // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
419 if (RecName = TEXTURE_NAME_WATER) or
420 (RecName = TEXTURE_NAME_ACID1) or
421 (RecName = TEXTURE_NAME_ACID2) then
422 begin
423 SetLength(Textures, Length(Textures)+1);
425 with Textures[High(Textures)] do
426 begin
427 TextureName := RecName;
429 if TextureName = TEXTURE_NAME_WATER then
430 TextureID := TEXTURE_SPECIAL_WATER
431 else
432 if TextureName = TEXTURE_NAME_ACID1 then
433 TextureID := TEXTURE_SPECIAL_ACID1
434 else
435 if TextureName = TEXTURE_NAME_ACID2 then
436 TextureID := TEXTURE_SPECIAL_ACID2;
438 Anim := False;
439 end;
441 result := High(Textures);
442 Exit;
443 end;
445 // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
446 WADName := g_ExtractWadName(RecName);
448 WAD := TWADFile.Create();
450 if WADName <> '' then
451 WADName := GameDir+'/wads/'+WADName
452 else
453 WADName := Map;
455 WAD.ReadFile(WADName);
457 txname := RecName;
459 if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
460 begin
461 FreeMem(TextureData);
462 RecName := 'COMMON\ALIEN';
463 end;
466 if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
467 begin
468 SetLength(Textures, Length(Textures)+1);
469 if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then
470 Exit;
471 e_GetTextureSize(Textures[High(Textures)].TextureID,
472 @Textures[High(Textures)].Width,
473 @Textures[High(Textures)].Height);
474 FreeMem(TextureData);
475 Textures[High(Textures)].TextureName := {RecName}txname;
476 Textures[High(Textures)].Anim := False;
478 result := High(Textures);
479 end
480 else // Íåò òàêîãî ðåóñðñà â WAD'å
481 begin
482 //e_WriteLog(Format('SHIT! Error loading texture %s : %s : %s', [RecName, txname, g_ExtractFilePathName(RecName)]), MSG_WARNING);
483 if log then
484 begin
485 e_WriteLog(Format('Error loading texture %s', [RecName]), MSG_WARNING);
486 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
487 end;
488 end;
490 WAD.Free();
491 end;
493 function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Integer;
494 var
495 WAD: TWADFile;
496 TextureWAD: PChar = nil;
497 TextData: Pointer = nil;
498 TextureData: Pointer = nil;
499 cfg: TConfig = nil;
500 WADName: String;
501 ResLength: Integer;
502 TextureResource: String;
503 _width, _height, _framecount, _speed: Integer;
504 _backanimation: Boolean;
505 //imgfmt: string;
506 ia: TDynImageDataArray = nil;
507 f, c, frdelay, frloop: Integer;
508 begin
509 result := -1;
511 //e_WriteLog(Format('*** Loading animated texture "%s"', [RecName]), MSG_NOTIFY);
513 // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
514 WADName := g_ExtractWadName(RecName);
516 WAD := TWADFile.Create();
517 try
518 if WADName <> '' then
519 WADName := GameDir+'/wads/'+WADName
520 else
521 WADName := Map;
523 WAD.ReadFile(WADName);
525 if not WAD.GetResource(g_ExtractFilePathName(RecName), TextureWAD, ResLength) then
526 begin
527 if log then
528 begin
529 e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
530 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
531 end;
532 exit;
533 end;
535 {TEST
536 if WADName = Map then
537 begin
538 //FreeMem(TextureWAD);
539 if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
540 end;
543 WAD.FreeWAD();
545 if ResLength < 6 then
546 begin
547 e_WriteLog(Format('Animated texture file "%s" too short', [RecName]), MSG_WARNING);
548 exit;
549 end;
551 // ýòî ïòèöà? ýòî ñàìîë¸ò?
552 if (TextureWAD[0] = 'D') and (TextureWAD[1] = 'F') and
553 (TextureWAD[2] = 'W') and (TextureWAD[3] = 'A') and (TextureWAD[4] = 'D') then
554 begin
555 // íåò, ýòî ñóïåðìåí!
556 if not WAD.ReadMemory(TextureWAD, ResLength) then
557 begin
558 e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName]), MSG_WARNING);
559 exit;
560 end;
562 // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
563 if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then
564 begin
565 e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName]), MSG_WARNING);
566 exit;
567 end;
569 cfg := TConfig.CreateMem(TextData, ResLength);
571 TextureResource := cfg.ReadStr('', 'resource', '');
572 if TextureResource = '' then
573 begin
574 e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName]), MSG_WARNING);
575 exit;
576 end;
578 _width := cfg.ReadInt('', 'framewidth', 0);
579 _height := cfg.ReadInt('', 'frameheight', 0);
580 _framecount := cfg.ReadInt('', 'framecount', 0);
581 _speed := cfg.ReadInt('', 'waitcount', 0);
582 _backanimation := cfg.ReadBool('', 'backanimation', False);
584 cfg.Free();
585 cfg := nil;
587 // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
588 if not WAD.GetResource('TEXTURES/'+TextureResource, TextureData, ResLength) then
589 begin
590 e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName, 'TEXTURES/'+TextureResource]), MSG_WARNING);
591 exit;
592 end;
594 WAD.Free();
595 WAD := nil;
597 SetLength(Textures, Length(Textures)+1);
598 with Textures[High(Textures)] do
599 begin
600 // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
601 if g_Frames_CreateMemory(@FramesID, '', TextureData, ResLength, _width, _height, _framecount, _backanimation) then
602 begin
603 TextureName := RecName;
604 Width := _width;
605 Height := _height;
606 Anim := True;
607 FramesCount := _framecount;
608 Speed := _speed;
609 result := High(Textures);
610 end
611 else
612 begin
613 if log then e_WriteLog(Format('Error loading animation texture %s', [RecName]), MSG_WARNING);
614 end;
615 end;
616 end
617 else
618 begin
619 // try animated image
621 imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
622 if length(imgfmt) = 0 then
623 begin
624 e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
625 exit;
626 end;
628 GlobalMetadata.ClearMetaItems();
629 GlobalMetadata.ClearMetaItemsForSaving();
630 if not LoadMultiImageFromMemory(TextureWAD, ResLength, ia) then
631 begin
632 e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName]), MSG_WARNING);
633 exit;
634 end;
635 if length(ia) = 0 then
636 begin
637 e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName]), MSG_WARNING);
638 exit;
639 end;
641 WAD.Free();
642 WAD := nil;
644 _width := ia[0].width;
645 _height := ia[0].height;
646 _framecount := length(ia);
647 _speed := 1;
648 _backanimation := false;
649 frdelay := -1;
650 frloop := -666;
651 if GlobalMetadata.HasMetaItem(SMetaFrameDelay) then
652 begin
653 //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
654 try
655 f := GlobalMetadata.MetaItems[SMetaFrameDelay];
656 frdelay := f;
657 if f < 0 then f := 0;
658 // rounding ;-)
659 c := f mod 28;
660 if c < 13 then c := 0 else c := 1;
661 f := (f div 28)+c;
662 if f < 1 then f := 1 else if f > 255 then f := 255;
663 _speed := f;
664 except
665 end;
666 end;
667 if GlobalMetadata.HasMetaItem(SMetaAnimationLoops) then
668 begin
669 //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
670 try
671 f := GlobalMetadata.MetaItems[SMetaAnimationLoops];
672 frloop := f;
673 if f <> 0 then _backanimation := true; // non-infinite looping == forth-and-back
674 except
675 end;
676 end;
677 //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
678 //for f := 0 to high(ia) do writeln(' frame #', f, ': ', ia[f].width, 'x', ia[f].height);
679 f := ord(_backanimation);
680 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);
682 SetLength(Textures, Length(Textures)+1);
683 // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
684 if g_CreateFramesImg(ia, @Textures[High(Textures)].FramesID, '', _backanimation) then
685 begin
686 Textures[High(Textures)].TextureName := RecName;
687 Textures[High(Textures)].Width := _width;
688 Textures[High(Textures)].Height := _height;
689 Textures[High(Textures)].Anim := True;
690 Textures[High(Textures)].FramesCount := length(ia);
691 Textures[High(Textures)].Speed := _speed;
692 result := High(Textures);
693 //writeln(' CREATED!');
694 end
695 else
696 begin
697 if log then e_WriteLog(Format('Error loading animation texture "%s" images', [RecName]), MSG_WARNING);
698 end;
699 end;
700 finally
701 for f := 0 to High(ia) do FreeImage(ia[f]);
702 WAD.Free();
703 cfg.Free();
704 if TextureWAD <> nil then FreeMem(TextureWAD);
705 if TextData <> nil then FreeMem(TextData);
706 if TextureData <> nil then FreeMem(TextureData);
707 end;
708 end;
710 procedure CreateItem(Item: TItemRec_1);
711 begin
712 if g_Game_IsClient then Exit;
714 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) and
715 ByteBool(Item.Options and ITEM_OPTION_ONLYDM) then
716 Exit;
718 g_Items_Create(Item.X, Item.Y, Item.ItemType, ByteBool(Item.Options and ITEM_OPTION_FALL),
719 gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP]);
720 end;
722 procedure CreateArea(Area: TAreaRec_1);
723 var
724 a: Integer;
725 id: DWORD;
726 begin
727 case Area.AreaType of
728 AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2,
729 AREA_REDTEAMPOINT, AREA_BLUETEAMPOINT:
730 begin
731 SetLength(RespawnPoints, Length(RespawnPoints)+1);
732 with RespawnPoints[High(RespawnPoints)] do
733 begin
734 X := Area.X;
735 Y := Area.Y;
736 Direction := TDirection(Area.Direction);
738 case Area.AreaType of
739 AREA_DMPOINT: PointType := RESPAWNPOINT_DM;
740 AREA_PLAYERPOINT1: PointType := RESPAWNPOINT_PLAYER1;
741 AREA_PLAYERPOINT2: PointType := RESPAWNPOINT_PLAYER2;
742 AREA_REDTEAMPOINT: PointType := RESPAWNPOINT_RED;
743 AREA_BLUETEAMPOINT: PointType := RESPAWNPOINT_BLUE;
744 end;
745 end;
746 end;
748 AREA_REDFLAG, AREA_BLUEFLAG:
749 begin
750 if Area.AreaType = AREA_REDFLAG then a := FLAG_RED else a := FLAG_BLUE;
752 if FlagPoints[a] <> nil then Exit;
754 New(FlagPoints[a]);
756 with FlagPoints[a]^ do
757 begin
758 X := Area.X-FLAGRECT.X;
759 Y := Area.Y-FLAGRECT.Y;
760 Direction := TDirection(Area.Direction);
761 end;
763 with gFlags[a] do
764 begin
765 case a of
766 FLAG_RED: g_Frames_Get(id, 'FRAMES_FLAG_RED');
767 FLAG_BLUE: g_Frames_Get(id, 'FRAMES_FLAG_BLUE');
768 end;
770 Animation := TAnimation.Create(id, True, 8);
771 Obj.Rect := FLAGRECT;
773 g_Map_ResetFlag(a);
774 end;
775 end;
777 AREA_DOMFLAG:
778 begin
779 {SetLength(DOMFlagPoints, Length(DOMFlagPoints)+1);
780 with DOMFlagPoints[High(DOMFlagPoints)] do
781 begin
782 X := Area.X;
783 Y := Area.Y;
784 Direction := TDirection(Area.Direction);
785 end;
787 g_Map_CreateFlag(DOMFlagPoints[High(DOMFlagPoints)], FLAG_DOM, FLAG_STATE_NORMAL);}
788 end;
789 end;
790 end;
792 procedure CreateTrigger(Trigger: TTriggerRec_1; fTexturePanel1Type, fTexturePanel2Type: Word);
793 var
794 _trigger: TTrigger;
795 begin
796 if g_Game_IsClient and not (Trigger.TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) then Exit;
798 with _trigger do
799 begin
800 X := Trigger.X;
801 Y := Trigger.Y;
802 Width := Trigger.Width;
803 Height := Trigger.Height;
804 Enabled := ByteBool(Trigger.Enabled);
805 TexturePanel := Trigger.TexturePanel;
806 TexturePanelType := fTexturePanel1Type;
807 ShotPanelType := fTexturePanel2Type;
808 TriggerType := Trigger.TriggerType;
809 ActivateType := Trigger.ActivateType;
810 Keys := Trigger.Keys;
811 Data.Default := Trigger.DATA;
812 end;
814 g_Triggers_Create(_trigger);
815 end;
817 procedure CreateMonster(monster: TMonsterRec_1);
818 var
819 a, i: Integer;
820 begin
821 if g_Game_IsClient then Exit;
823 if (gGameSettings.GameType = GT_SINGLE)
824 or LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS) then
825 begin
826 i := g_Monsters_Create(monster.MonsterType, monster.X, monster.Y,
827 TDirection(monster.Direction));
829 if gTriggers <> nil then
830 for a := 0 to High(gTriggers) do
831 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
832 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
833 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
834 gMonsters[i].AddTrigger(a);
836 if monster.MonsterType <> MONSTER_BARREL then
837 Inc(gTotalMonsters);
838 end;
839 end;
841 procedure g_Map_ReAdd_DieTriggers();
842 var
843 i, a: Integer;
844 begin
845 if g_Game_IsClient then Exit;
847 for i := 0 to High(gMonsters) do
848 if gMonsters[i] <> nil then
849 begin
850 gMonsters[i].ClearTriggers();
852 for a := 0 to High(gTriggers) do
853 if gTriggers[a].TriggerType in [TRIGGER_PRESS,
854 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then
855 if (gTriggers[a].Data.MonsterID-1) = gMonsters[i].StartID then
856 gMonsters[i].AddTrigger(a);
857 end;
858 end;
860 function extractWadName(resourceName: string): string;
861 var
862 posN: Integer;
863 begin
864 posN := Pos(':', resourceName);
865 if posN > 0 then
866 Result:= Copy(resourceName, 0, posN-1)
867 else
868 Result := '';
869 end;
871 procedure addResToExternalResList(res: string);
872 begin
873 res := extractWadName(res);
874 if (res <> '') and (gExternalResources.IndexOf(res) = -1) then
875 gExternalResources.Add(res);
876 end;
878 procedure generateExternalResourcesList(mapReader: TMapReader_1);
879 var
880 textures: TTexturesRec1Array;
881 mapHeader: TMapHeaderRec_1;
882 i: integer;
883 resFile: String = '';
884 begin
885 if gExternalResources = nil then
886 gExternalResources := TStringList.Create;
888 gExternalResources.Clear;
889 textures := mapReader.GetTextures();
890 for i := 0 to High(textures) do
891 begin
892 addResToExternalResList(resFile);
893 end;
895 textures := nil;
897 mapHeader := mapReader.GetMapHeader;
899 addResToExternalResList(mapHeader.MusicName);
900 addResToExternalResList(mapHeader.SkyName);
901 end;
903 function g_Map_Load(Res: String): Boolean;
904 const
905 DefaultMusRes = 'Standart.wad:STDMUS\MUS1';
906 DefaultSkyRes = 'Standart.wad:STDSKY\SKY0';
907 var
908 WAD: TWADFile;
909 MapReader: TMapReader_1;
910 Header: TMapHeaderRec_1;
911 _textures: TTexturesRec1Array;
912 _texnummap: array of Integer; // `_textures` -> `Textures`
913 panels: TPanelsRec1Array;
914 items: TItemsRec1Array;
915 monsters: TMonsterRec1Array;
916 areas: TAreasRec1Array;
917 triggers: TTriggersRec1Array;
918 a, b, c, k: Integer;
919 PanelID: DWORD;
920 AddTextures: TAddTextureArray;
921 texture: TTextureRec_1;
922 TriggersTable: Array of record
923 TexturePanel: Integer;
924 LiftPanel: Integer;
925 DoorPanel: Integer;
926 ShotPanel: Integer;
927 end;
928 FileName, mapResName, s, TexName: String;
929 Data: Pointer;
930 Len: Integer;
931 ok, isAnim, trigRef: Boolean;
932 CurTex, ntn: Integer;
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 for idx := High(panels) downto 0 do
958 begin
959 gMapGrid.insertBody(panels[idx], panels[idx].X, panels[idx].Y, panels[idx].Width, panels[idx].Height, tag);
960 end;
961 end;
963 begin
964 gMapGrid.Free();
965 gMapGrid := nil;
967 Result := False;
968 gMapInfo.Map := Res;
969 TriggersTable := nil;
970 FillChar(texture, SizeOf(texture), 0);
972 sfsGCDisable(); // temporary disable removing of temporary volumes
973 try
974 // Çàãðóçêà WAD:
975 FileName := g_ExtractWadName(Res);
976 e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY);
977 g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False);
979 WAD := TWADFile.Create();
980 if not WAD.ReadFile(FileName) then
981 begin
982 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [FileName]));
983 WAD.Free();
984 Exit;
985 end;
986 //k8: why loader ignores path here?
987 mapResName := g_ExtractFileName(Res);
988 if not WAD.GetMapResource(mapResName, Data, Len) then
989 begin
990 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName]));
991 WAD.Free();
992 Exit;
993 end;
995 WAD.Free();
997 // Çàãðóçêà êàðòû:
998 e_WriteLog('Loading map: '+mapResName, MSG_NOTIFY);
999 g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False);
1000 MapReader := TMapReader_1.Create();
1002 if not MapReader.LoadMap(Data) then
1003 begin
1004 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]));
1005 FreeMem(Data);
1006 MapReader.Free();
1007 Exit;
1008 end;
1010 FreeMem(Data);
1011 generateExternalResourcesList(MapReader);
1012 // Çàãðóçêà òåêñòóð:
1013 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], 0, False);
1014 _textures := MapReader.GetTextures();
1015 _texnummap := nil;
1017 // Äîáàâëåíèå òåêñòóð â Textures[]:
1018 if _textures <> nil then
1019 begin
1020 e_WriteLog(' Loading textures:', MSG_NOTIFY);
1021 g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], High(_textures), False);
1022 SetLength(_texnummap, length(_textures));
1024 for a := 0 to High(_textures) do
1025 begin
1026 SetLength(s, 64);
1027 CopyMemory(@s[1], @_textures[a].Resource[0], 64);
1028 for b := 1 to Length(s) do
1029 if s[b] = #0 then
1030 begin
1031 SetLength(s, b-1);
1032 Break;
1033 end;
1034 e_WriteLog(Format(' Loading texture #%d: %s', [a, s]), MSG_NOTIFY);
1035 //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY);
1036 // Àíèìèðîâàííàÿ òåêñòóðà:
1037 if ByteBool(_textures[a].Anim) then
1038 begin
1039 ntn := CreateAnimTexture(_textures[a].Resource, FileName, True);
1040 if ntn < 0 then
1041 begin
1042 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_ANIM], [s]));
1043 ntn := CreateNullTexture(_textures[a].Resource);
1044 end;
1045 end
1046 else // Îáû÷íàÿ òåêñòóðà:
1047 ntn := CreateTexture(_textures[a].Resource, FileName, True);
1048 if ntn < 0 then
1049 begin
1050 g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_SIMPLE], [s]));
1051 ntn := CreateNullTexture(_textures[a].Resource);
1052 end;
1054 _texnummap[a] := ntn; // fix texture number
1055 g_Game_StepLoading();
1056 end;
1057 end;
1059 // Çàãðóçêà òðèããåðîâ:
1060 gTriggerClientID := 0;
1061 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1062 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS], 0, False);
1063 triggers := MapReader.GetTriggers();
1065 // Çàãðóçêà ïàíåëåé:
1066 e_WriteLog(' Loading panels...', MSG_NOTIFY);
1067 g_Game_SetLoadingText(_lc[I_LOAD_PANELS], 0, False);
1068 panels := MapReader.GetPanels();
1070 // check texture numbers for panels
1071 for a := 0 to High(panels) do
1072 begin
1073 if panels[a].TextureNum > High(_textures) then
1074 begin
1075 e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR);
1076 result := false;
1077 exit;
1078 end;
1079 panels[a].TextureNum := _texnummap[panels[a].TextureNum];
1080 end;
1082 // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì):
1083 if triggers <> nil then
1084 begin
1085 e_WriteLog(' Setting up trigger table...', MSG_NOTIFY);
1086 SetLength(TriggersTable, Length(triggers));
1087 g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS_TABLE], High(TriggersTable), False);
1089 for a := 0 to High(TriggersTable) do
1090 begin
1091 // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè):
1092 TriggersTable[a].TexturePanel := triggers[a].TexturePanel;
1093 // Ëèôòû:
1094 if triggers[a].TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT] then
1095 TriggersTable[a].LiftPanel := TTriggerData(triggers[a].DATA).PanelID
1096 else
1097 TriggersTable[a].LiftPanel := -1;
1098 // Äâåðè:
1099 if triggers[a].TriggerType in [TRIGGER_OPENDOOR,
1100 TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
1101 TRIGGER_CLOSETRAP, TRIGGER_TRAP] then
1102 TriggersTable[a].DoorPanel := TTriggerData(triggers[a].DATA).PanelID
1103 else
1104 TriggersTable[a].DoorPanel := -1;
1105 // Òóðåëü:
1106 if triggers[a].TriggerType = TRIGGER_SHOT then
1107 TriggersTable[a].ShotPanel := TTriggerData(triggers[a].DATA).ShotPanelID
1108 else
1109 TriggersTable[a].ShotPanel := -1;
1111 g_Game_StepLoading();
1112 end;
1113 end;
1115 // Ñîçäàåì ïàíåëè:
1116 if panels <> nil then
1117 begin
1118 e_WriteLog(' Setting up trigger links...', MSG_NOTIFY);
1119 g_Game_SetLoadingText(_lc[I_LOAD_LINK_TRIGGERS], High(panels), False);
1121 for a := 0 to High(panels) do
1122 begin
1123 SetLength(AddTextures, 0);
1124 trigRef := False;
1125 CurTex := -1;
1126 if _textures <> nil then
1127 begin
1128 texture := _textures[panels[a].TextureNum];
1129 ok := True;
1130 end
1131 else
1132 ok := False;
1134 if ok then
1135 begin
1136 // Ñìîòðèì, ññûëàþòñÿ ëè íà ýòó ïàíåëü òðèããåðû.
1137 // Åñëè äà - òî íàäî ñîçäàòü åùå òåêñòóð:
1138 ok := False;
1139 if (TriggersTable <> nil) and (_textures <> nil) then
1140 for b := 0 to High(TriggersTable) do
1141 if (TriggersTable[b].TexturePanel = a)
1142 or (TriggersTable[b].ShotPanel = a) then
1143 begin
1144 trigRef := True;
1145 ok := True;
1146 Break;
1147 end;
1148 end;
1150 if ok then
1151 begin // Åñòü ññûëêè òðèããåðîâ íà ýòó ïàíåëü
1152 SetLength(s, 64);
1153 CopyMemory(@s[1], @texture.Resource[0], 64);
1154 // Èçìåðÿåì äëèíó:
1155 Len := Length(s);
1156 for c := Len downto 1 do
1157 if s[c] <> #0 then
1158 begin
1159 Len := c;
1160 Break;
1161 end;
1162 SetLength(s, Len);
1164 // Ñïåö-òåêñòóðû çàïðåùåíû:
1165 if g_Map_IsSpecialTexture(s) then
1166 ok := False
1167 else
1168 // Îïðåäåëÿåì íàëè÷èå è ïîëîæåíèå öèôð â êîíöå ñòðîêè:
1169 ok := g_Texture_NumNameFindStart(s);
1171 // Åñëè ok, çíà÷èò åñòü öèôðû â êîíöå.
1172 // Çàãðóæàåì òåêñòóðû ñ îñòàëüíûìè #:
1173 if ok then
1174 begin
1175 k := NNF_NAME_BEFORE;
1176 // Öèêë ïî èçìåíåíèþ èìåíè òåêñòóðû:
1177 while ok or (k = NNF_NAME_BEFORE) or
1178 (k = NNF_NAME_EQUALS) do
1179 begin
1180 k := g_Texture_NumNameFindNext(TexName);
1182 if (k = NNF_NAME_BEFORE) or
1183 (k = NNF_NAME_AFTER) then
1184 begin
1185 // Ïðîáóåì äîáàâèòü íîâóþ òåêñòóðó:
1186 if ByteBool(texture.Anim) then
1187 begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ
1188 isAnim := True;
1189 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1190 if not ok then
1191 begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ
1192 isAnim := False;
1193 ok := CreateTexture(TexName, FileName, False) >= 0;
1194 end;
1195 end
1196 else
1197 begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ
1198 isAnim := False;
1199 ok := CreateTexture(TexName, FileName, False) >= 0;
1200 if not ok then
1201 begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ
1202 isAnim := True;
1203 ok := CreateAnimTexture(TexName, FileName, False) >= 0;
1204 end;
1205 end;
1207 // Îíà ñóùåñòâóåò. Çàíîñèì åå ID â ñïèñîê ïàíåëè:
1208 if ok then
1209 begin
1210 for c := 0 to High(Textures) do
1211 if Textures[c].TextureName = TexName then
1212 begin
1213 SetLength(AddTextures, Length(AddTextures)+1);
1214 AddTextures[High(AddTextures)].Texture := c;
1215 AddTextures[High(AddTextures)].Anim := isAnim;
1216 Break;
1217 end;
1218 end;
1219 end
1220 else
1221 if k = NNF_NAME_EQUALS then
1222 begin
1223 // Çàíîñèì òåêóùóþ òåêñòóðó íà ñâîå ìåñòî:
1224 SetLength(AddTextures, Length(AddTextures)+1);
1225 AddTextures[High(AddTextures)].Texture := panels[a].TextureNum;
1226 AddTextures[High(AddTextures)].Anim := ByteBool(texture.Anim);
1227 CurTex := High(AddTextures);
1228 ok := True;
1229 end
1230 else // NNF_NO_NAME
1231 ok := False;
1232 end; // while ok...
1234 ok := True;
1235 end; // if ok - åñòü ñìåæíûå òåêñòóðû
1236 end; // if ok - ññûëàþòñÿ òðèããåðû
1238 if not ok then
1239 begin
1240 // Çàíîñèì òîëüêî òåêóùóþ òåêñòóðó:
1241 SetLength(AddTextures, 1);
1242 AddTextures[0].Texture := panels[a].TextureNum;
1243 AddTextures[0].Anim := ByteBool(texture.Anim);
1244 CurTex := 0;
1245 end;
1247 //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);
1249 // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð:
1250 PanelID := CreatePanel(panels[a], AddTextures, CurTex, trigRef);
1252 // Åñëè èñïîëüçóåòñÿ â òðèããåðàõ, òî ñòàâèì òî÷íûé ID:
1253 if TriggersTable <> nil then
1254 for b := 0 to High(TriggersTable) do
1255 begin
1256 // Òðèããåð äâåðè/ëèôòà:
1257 if (TriggersTable[b].LiftPanel = a) or
1258 (TriggersTable[b].DoorPanel = a) then
1259 TTriggerData(triggers[b].DATA).PanelID := PanelID;
1260 // Òðèããåð ñìåíû òåêñòóðû:
1261 if TriggersTable[b].TexturePanel = a then
1262 triggers[b].TexturePanel := PanelID;
1263 // Òðèããåð "Òóðåëü":
1264 if TriggersTable[b].ShotPanel = a then
1265 TTriggerData(triggers[b].DATA).ShotPanelID := PanelID;
1266 end;
1268 g_Game_StepLoading();
1269 end;
1270 end;
1272 // Åñëè íå LoadState, òî ñîçäàåì òðèããåðû:
1273 if (triggers <> nil) and not gLoadGameMode then
1274 begin
1275 e_WriteLog(' Creating triggers...', MSG_NOTIFY);
1276 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_TRIGGERS], 0, False);
1277 // Óêàçûâàåì òèï ïàíåëè, åñëè åñòü:
1278 for a := 0 to High(triggers) do
1279 begin
1280 if triggers[a].TexturePanel <> -1 then
1281 b := panels[TriggersTable[a].TexturePanel].PanelType
1282 else
1283 b := 0;
1284 if (triggers[a].TriggerType = TRIGGER_SHOT) and
1285 (TTriggerData(triggers[a].DATA).ShotPanelID <> -1) then
1286 c := panels[TriggersTable[a].ShotPanel].PanelType
1287 else
1288 c := 0;
1289 CreateTrigger(triggers[a], b, c);
1290 end;
1291 end;
1293 // Çàãðóçêà ïðåäìåòîâ:
1294 e_WriteLog(' Loading triggers...', MSG_NOTIFY);
1295 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS], 0, False);
1296 items := MapReader.GetItems();
1298 // Åñëè íå LoadState, òî ñîçäàåì ïðåäìåòû:
1299 if (items <> nil) and not gLoadGameMode then
1300 begin
1301 e_WriteLog(' Spawning items...', MSG_NOTIFY);
1302 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_ITEMS], 0, False);
1303 for a := 0 to High(items) do
1304 CreateItem(Items[a]);
1305 end;
1307 // Çàãðóçêà îáëàñòåé:
1308 e_WriteLog(' Loading areas...', MSG_NOTIFY);
1309 g_Game_SetLoadingText(_lc[I_LOAD_AREAS], 0, False);
1310 areas := MapReader.GetAreas();
1312 // Åñëè íå LoadState, òî ñîçäàåì îáëàñòè:
1313 if areas <> nil then
1314 begin
1315 e_WriteLog(' Creating areas...', MSG_NOTIFY);
1316 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_AREAS], 0, False);
1317 for a := 0 to High(areas) do
1318 CreateArea(areas[a]);
1319 end;
1321 // Çàãðóçêà ìîíñòðîâ:
1322 e_WriteLog(' Loading monsters...', MSG_NOTIFY);
1323 g_Game_SetLoadingText(_lc[I_LOAD_MONSTERS], 0, False);
1324 monsters := MapReader.GetMonsters();
1326 gTotalMonsters := 0;
1328 // Åñëè íå LoadState, òî ñîçäàåì ìîíñòðîâ:
1329 if (monsters <> nil) and not gLoadGameMode then
1330 begin
1331 e_WriteLog(' Spawning monsters...', MSG_NOTIFY);
1332 g_Game_SetLoadingText(_lc[I_LOAD_CREATE_MONSTERS], 0, False);
1333 for a := 0 to High(monsters) do
1334 CreateMonster(monsters[a]);
1335 end;
1337 // Çàãðóçêà îïèñàíèÿ êàðòû:
1338 e_WriteLog(' Reading map info...', MSG_NOTIFY);
1339 g_Game_SetLoadingText(_lc[I_LOAD_MAP_HEADER], 0, False);
1340 Header := MapReader.GetMapHeader();
1342 MapReader.Free();
1344 with gMapInfo do
1345 begin
1346 Name := Header.MapName;
1347 Description := Header.MapDescription;
1348 Author := Header.MapAuthor;
1349 MusicName := Header.MusicName;
1350 SkyName := Header.SkyName;
1351 Height := Header.Height;
1352 Width := Header.Width;
1353 end;
1355 // Çàãðóçêà íåáà:
1356 if gMapInfo.SkyName <> '' then
1357 begin
1358 e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, MSG_NOTIFY);
1359 g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
1360 FileName := g_ExtractWadName(gMapInfo.SkyName);
1362 if FileName <> '' then
1363 FileName := GameDir+'/wads/'+FileName
1364 else
1365 begin
1366 FileName := g_ExtractWadName(Res);
1367 end;
1369 s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName);
1370 if g_Texture_CreateWAD(BackID, s) then
1371 begin
1372 g_Game_SetupScreenSize();
1373 end
1374 else
1375 g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]));
1376 end;
1378 // Çàãðóçêà ìóçûêè:
1379 ok := False;
1380 if gMapInfo.MusicName <> '' then
1381 begin
1382 e_WriteLog(' Loading music: ' + gMapInfo.MusicName, MSG_NOTIFY);
1383 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1384 FileName := g_ExtractWadName(gMapInfo.MusicName);
1386 if FileName <> '' then
1387 FileName := GameDir+'/wads/'+FileName
1388 else
1389 begin
1390 FileName := g_ExtractWadName(Res);
1391 end;
1393 s := FileName+':'+g_ExtractFilePathName(gMapInfo.MusicName);
1394 if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then
1395 ok := True
1396 else
1397 g_FatalError(Format(_lc[I_GAME_ERROR_MUSIC], [s]));
1398 end;
1400 // Îñòàëüíûå óñòàíâêè:
1401 CreateDoorMap();
1402 CreateLiftMap();
1404 g_Items_Init();
1405 g_Weapon_Init();
1406 g_Monsters_Init();
1408 // Åñëè íå LoadState, òî ñîçäàåì êàðòó ñòîëêíîâåíèé:
1409 if not gLoadGameMode then
1410 g_GFX_Init();
1412 // Ñáðîñ ëîêàëüíûõ ìàññèâîâ:
1413 _textures := nil;
1414 panels := nil;
1415 items := nil;
1416 areas := nil;
1417 triggers := nil;
1418 TriggersTable := nil;
1419 AddTextures := nil;
1421 // Âêëþ÷àåì ìóçûêó, åñëè ýòî íå çàãðóçêà:
1422 if ok and (not gLoadGameMode) then
1423 begin
1424 gMusic.SetByName(gMapInfo.MusicName);
1425 gMusic.Play();
1426 end
1427 else
1428 gMusic.SetByName('');
1429 finally
1430 sfsGCEnable(); // enable releasing unused volumes
1431 end;
1433 e_WriteLog('Creating map grid', MSG_NOTIFY);
1435 fixMinMax(gWalls);
1436 fixMinMax(gRenderBackgrounds);
1437 fixMinMax(gRenderForegrounds);
1438 fixMinMax(gWater);
1439 fixMinMax(gAcid1);
1440 fixMinMax(gAcid2);
1441 fixMinMax(gSteps);
1443 gMapGrid := TBodyGrid.Create(mapX1+1, mapY1+1);
1445 addPanelsToGrid(gWalls, PANEL_WALL); // and PANEL_CLOSEDOOR
1446 addPanelsToGrid(gRenderBackgrounds, PANEL_BACK);
1447 addPanelsToGrid(gRenderForegrounds, PANEL_FORE);
1448 addPanelsToGrid(gWater, PANEL_WATER);
1449 addPanelsToGrid(gAcid1, PANEL_ACID1);
1450 addPanelsToGrid(gAcid2, PANEL_ACID2);
1451 addPanelsToGrid(gSteps, PANEL_STEP);
1453 gMapGrid.dumpStats();
1455 e_WriteLog('Done loading map.', MSG_NOTIFY);
1456 Result := True;
1457 end;
1459 function g_Map_GetMapInfo(Res: String): TMapInfo;
1460 var
1461 WAD: TWADFile;
1462 MapReader: TMapReader_1;
1463 Header: TMapHeaderRec_1;
1464 FileName: String;
1465 Data: Pointer;
1466 Len: Integer;
1467 begin
1468 FillChar(Result, SizeOf(Result), 0);
1469 FileName := g_ExtractWadName(Res);
1471 WAD := TWADFile.Create();
1472 if not WAD.ReadFile(FileName) then
1473 begin
1474 WAD.Free();
1475 Exit;
1476 end;
1478 //k8: it ignores path again
1479 if not WAD.GetMapResource(g_ExtractFileName(Res), Data, Len) then
1480 begin
1481 WAD.Free();
1482 Exit;
1483 end;
1485 WAD.Free();
1487 MapReader := TMapReader_1.Create();
1489 if not MapReader.LoadMap(Data) then
1490 begin
1491 g_Console_Add(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res]), True);
1492 ZeroMemory(@Header, SizeOf(Header));
1493 Result.Name := _lc[I_GAME_ERROR_MAP_SELECT];
1494 Result.Description := _lc[I_GAME_ERROR_MAP_SELECT];
1495 end
1496 else
1497 begin
1498 Header := MapReader.GetMapHeader();
1499 Result.Name := Header.MapName;
1500 Result.Description := Header.MapDescription;
1501 end;
1503 FreeMem(Data);
1504 MapReader.Free();
1506 Result.Map := Res;
1507 Result.Author := Header.MapAuthor;
1508 Result.Height := Header.Height;
1509 Result.Width := Header.Width;
1510 end;
1512 function g_Map_GetMapsList(WADName: string): SArray;
1513 var
1514 WAD: TWADFile;
1515 a: Integer;
1516 ResList: SArray;
1517 begin
1518 Result := nil;
1519 WAD := TWADFile.Create();
1520 if not WAD.ReadFile(WADName) then
1521 begin
1522 WAD.Free();
1523 Exit;
1524 end;
1525 ResList := WAD.GetMapResources();
1526 if ResList <> nil then
1527 begin
1528 for a := 0 to High(ResList) do
1529 begin
1530 SetLength(Result, Length(Result)+1);
1531 Result[High(Result)] := ResList[a];
1532 end;
1533 end;
1534 WAD.Free();
1535 end;
1537 function g_Map_Exist(Res: string): Boolean;
1538 var
1539 WAD: TWADFile;
1540 FileName, mnn: string;
1541 ResList: SArray;
1542 a: Integer;
1543 begin
1544 Result := False;
1546 FileName := addWadExtension(g_ExtractWadName(Res));
1548 WAD := TWADFile.Create;
1549 if not WAD.ReadFile(FileName) then
1550 begin
1551 WAD.Free();
1552 Exit;
1553 end;
1555 ResList := WAD.GetMapResources();
1556 WAD.Free();
1558 mnn := g_ExtractFileName(Res);
1559 if ResList <> nil then
1560 for a := 0 to High(ResList) do if StrEquCI1251(ResList[a], mnn) then
1561 begin
1562 Result := True;
1563 Exit;
1564 end;
1565 end;
1567 procedure g_Map_Free();
1568 var
1569 a: Integer;
1571 procedure FreePanelArray(var panels: TPanelArray);
1572 var
1573 i: Integer;
1575 begin
1576 if panels <> nil then
1577 begin
1578 for i := 0 to High(panels) do
1579 panels[i].Free();
1580 panels := nil;
1581 end;
1582 end;
1584 begin
1585 g_GFX_Free();
1586 g_Weapon_Free();
1587 g_Items_Free();
1588 g_Triggers_Free();
1589 g_Monsters_Free();
1591 RespawnPoints := nil;
1592 if FlagPoints[FLAG_RED] <> nil then
1593 begin
1594 Dispose(FlagPoints[FLAG_RED]);
1595 FlagPoints[FLAG_RED] := nil;
1596 end;
1597 if FlagPoints[FLAG_BLUE] <> nil then
1598 begin
1599 Dispose(FlagPoints[FLAG_BLUE]);
1600 FlagPoints[FLAG_BLUE] := nil;
1601 end;
1602 //DOMFlagPoints := nil;
1604 //gDOMFlags := nil;
1606 if Textures <> nil then
1607 begin
1608 for a := 0 to High(Textures) do
1609 if not g_Map_IsSpecialTexture(Textures[a].TextureName) then
1610 if Textures[a].Anim then
1611 g_Frames_DeleteByID(Textures[a].FramesID)
1612 else
1613 if Textures[a].TextureID <> TEXTURE_NONE then
1614 e_DeleteTexture(Textures[a].TextureID);
1616 Textures := nil;
1617 end;
1619 FreePanelArray(gWalls);
1620 FreePanelArray(gRenderBackgrounds);
1621 FreePanelArray(gRenderForegrounds);
1622 FreePanelArray(gWater);
1623 FreePanelArray(gAcid1);
1624 FreePanelArray(gAcid2);
1625 FreePanelArray(gSteps);
1626 FreePanelArray(gLifts);
1627 FreePanelArray(gBlockMon);
1629 if BackID <> DWORD(-1) then
1630 begin
1631 gBackSize.X := 0;
1632 gBackSize.Y := 0;
1633 e_DeleteTexture(BackID);
1634 BackID := DWORD(-1);
1635 end;
1637 g_Game_StopAllSounds(False);
1638 gMusic.FreeSound();
1639 g_Sound_Delete(gMapInfo.MusicName);
1641 gMapInfo.Name := '';
1642 gMapInfo.Description := '';
1643 gMapInfo.MusicName := '';
1644 gMapInfo.Height := 0;
1645 gMapInfo.Width := 0;
1647 gDoorMap := nil;
1648 gLiftMap := nil;
1650 PanelByID := nil;
1651 end;
1653 procedure g_Map_Update();
1654 var
1655 a, d, j: Integer;
1656 m: Word;
1657 s: String;
1659 procedure UpdatePanelArray(var panels: TPanelArray);
1660 var
1661 i: Integer;
1663 begin
1664 if panels <> nil then
1665 for i := 0 to High(panels) do
1666 panels[i].Update();
1667 end;
1669 begin
1670 UpdatePanelArray(gWalls);
1671 UpdatePanelArray(gRenderBackgrounds);
1672 UpdatePanelArray(gRenderForegrounds);
1673 UpdatePanelArray(gWater);
1674 UpdatePanelArray(gAcid1);
1675 UpdatePanelArray(gAcid2);
1676 UpdatePanelArray(gSteps);
1678 if gGameSettings.GameMode = GM_CTF then
1679 begin
1680 for a := FLAG_RED to FLAG_BLUE do
1681 if not (gFlags[a].State in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1682 with gFlags[a] do
1683 begin
1684 if gFlags[a].Animation <> nil then
1685 gFlags[a].Animation.Update();
1687 m := g_Obj_Move(@Obj, True, True);
1689 if gTime mod (GAME_TICK*2) <> 0 then
1690 Continue;
1692 // Ñîïðîòèâëåíèå âîçäóõà:
1693 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1695 // Òàéìàóò ïîòåðÿííîãî ôëàãà, ëèáî îí âûïàë çà êàðòó:
1696 if ((Count = 0) or ByteBool(m and MOVE_FALLOUT)) and g_Game_IsServer then
1697 begin
1698 g_Map_ResetFlag(a);
1699 gFlags[a].CaptureTime := 0;
1700 if a = FLAG_RED then
1701 s := _lc[I_PLAYER_FLAG_RED]
1702 else
1703 s := _lc[I_PLAYER_FLAG_BLUE];
1704 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1706 if g_Game_IsNet then
1707 MH_SEND_FlagEvent(FLAG_STATE_RETURNED, a, 0);
1708 Continue;
1709 end;
1711 if Count > 0 then
1712 Count := Count - 1;
1714 // Èãðîê áåðåò ôëàã:
1715 if gPlayers <> nil then
1716 begin
1717 j := Random(Length(gPlayers)) - 1;
1719 for d := 0 to High(gPlayers) do
1720 begin
1721 Inc(j);
1722 if j > High(gPlayers) then
1723 j := 0;
1725 if gPlayers[j] <> nil then
1726 if gPlayers[j].Live and
1727 g_Obj_Collide(@Obj, @gPlayers[j].Obj) then
1728 begin
1729 if gPlayers[j].GetFlag(a) then
1730 Break;
1731 end;
1732 end;
1733 end;
1734 end;
1735 end;
1736 end;
1740 function pvpType (panelType: Word): Integer;
1741 begin
1742 case panelType of
1743 PANEL_WALL, PANEL_CLOSEDOOR: result := 0; // gWalls
1744 PANEL_BACK: result := 1; // gRenderBackgrounds
1745 PANEL_FORE: result := 2; // gRenderForegrounds
1746 PANEL_WATER: result := 3; // gWater
1747 PANEL_ACID1: result := 4; // gAcid1
1748 PANEL_ACID2: result := 5; // gAcid2
1749 PANEL_STEP: result := 6; // gSteps
1750 else result := -1;
1751 end;
1752 end;
1756 procedure g_Map_DrawPanelsOld(PanelType: Word);
1758 procedure DrawPanels (stp: Integer; var panels: TPanelArray; drawDoors: Boolean=False);
1759 var
1760 idx: Integer;
1761 begin
1762 if (panels <> nil) and (stp >= 0) and (stp <= 6) then
1763 begin
1764 // alas, no visible set
1765 for idx := 0 to High(panels) do
1766 begin
1767 if not (drawDoors xor panels[idx].Door) then panels[idx].Draw();
1768 end;
1769 end;
1770 end;
1772 begin
1773 case PanelType of
1774 PANEL_WALL: DrawPanels(0, gWalls);
1775 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1776 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1777 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1778 PANEL_WATER: DrawPanels(3, gWater);
1779 PANEL_ACID1: DrawPanels(4, gAcid1);
1780 PANEL_ACID2: DrawPanels(5, gAcid2);
1781 PANEL_STEP: DrawPanels(6, gSteps);
1782 end;
1783 end;
1786 var
1787 gDrawPanelList: TBinaryHeapObj = nil;
1789 function dplLess (a, b: TObject): Boolean;
1790 begin
1791 result := ((a as TPanel).ArrIdx < (b as TPanel).ArrIdx);
1792 end;
1794 procedure dplClear ();
1795 begin
1796 if gDrawPanelList = nil then gDrawPanelList := TBinaryHeapObj.Create(@dplLess) else gDrawPanelList.clear();
1797 end;
1799 procedure dplAddPanel (pan: TPanel);
1800 begin
1801 if pan = nil then exit;
1802 gDrawPanelList.insert(pan);
1803 end;
1806 procedure g_Map_DrawPanels(x0, y0, wdt, hgt: Integer; PanelType: Word);
1808 function qq (obj: TObject; tag: Integer): Boolean;
1809 var
1810 pan: TPanel;
1811 begin
1812 result := false; // don't stop, ever
1814 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1816 if obj = nil then
1817 begin
1818 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1819 end;
1820 if not (obj is TPanel) then
1821 begin
1822 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
1823 exit;
1824 end;
1825 //pan := (obj as TPanel);
1826 //e_WriteLog(Format(' !body: (%d,%d)-(%dx%d) tag:%d; qtag:%d', [pan.X, pan.Y, pan.Width, pan.Height, tag, PanelType]), MSG_NOTIFY);
1828 if (tag = PANEL_WALL) then
1829 begin
1830 if (PanelType = PANEL_WALL) then
1831 begin
1832 pan := (obj as TPanel);
1833 if not pan.Door then
1834 begin
1835 //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);
1836 dplAddPanel(pan);
1837 end;
1838 end
1839 else if (PanelType = PANEL_CLOSEDOOR) then
1840 begin
1841 pan := (obj as TPanel);
1842 if pan.Door then
1843 begin
1844 //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);
1845 dplAddPanel(pan);
1846 end;
1847 end
1848 end
1849 else if (PanelType = tag) then
1850 begin
1851 pan := (obj as TPanel);
1852 if not pan.Door then
1853 begin
1854 //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);
1855 dplAddPanel(pan);
1856 end;
1857 end;
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 gMapGrid.forEachInAABB(x0, y0, wdt, hgt, qq);
1889 // debug
1891 e_WriteLog(Format('+++QQQ: qtag:%d', [PanelType]), MSG_NOTIFY);
1892 case PanelType of
1893 PANEL_WALL: DrawPanels(0, gWalls);
1894 PANEL_CLOSEDOOR: DrawPanels(0, gWalls, True);
1895 PANEL_BACK: DrawPanels(1, gRenderBackgrounds);
1896 PANEL_FORE: DrawPanels(2, gRenderForegrounds);
1897 PANEL_WATER: DrawPanels(3, gWater);
1898 PANEL_ACID1: DrawPanels(4, gAcid1);
1899 PANEL_ACID2: DrawPanels(5, gAcid2);
1900 PANEL_STEP: DrawPanels(6, gSteps);
1901 end;
1902 e_WriteLog('==================', MSG_NOTIFY);
1905 // sort and draw the list (we need to sort it, or rendering is fucked)
1906 while gDrawPanelList.count > 0 do
1907 begin
1908 (gDrawPanelList.front() as TPanel).Draw();
1909 gDrawPanelList.popFront();
1910 end;
1911 end;
1914 procedure g_Map_DrawPanelShadowVolumes(lightX: Integer; lightY: Integer; radius: Integer);
1915 function qq (obj: TObject; tag: Integer): Boolean;
1916 var
1917 pan: TPanel;
1918 begin
1919 result := false; // don't stop, ever
1920 if (tag <> PANEL_WALL) then exit; // only walls
1921 pan := (obj as TPanel);
1922 pan.DrawShadowVolume(lightX, lightY, radius);
1923 end;
1925 begin
1926 gMapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, qq);
1927 end;
1930 procedure g_Map_DrawBack(dx, dy: Integer);
1931 begin
1932 if gDrawBackGround and (BackID <> DWORD(-1)) then
1933 e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
1934 else
1935 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
1936 end;
1938 function g_Map_CollidePanelOld(X, Y: Integer; Width, Height: Word;
1939 PanelType: Word; b1x3: Boolean): Boolean;
1940 var
1941 a, h: Integer;
1942 begin
1943 Result := False;
1945 if WordBool(PanelType and PANEL_WALL) then
1946 if gWalls <> nil then
1947 begin
1948 h := High(gWalls);
1950 for a := 0 to h do
1951 if gWalls[a].Enabled and
1952 g_Collide(X, Y, Width, Height,
1953 gWalls[a].X, gWalls[a].Y,
1954 gWalls[a].Width, gWalls[a].Height) then
1955 begin
1956 Result := True;
1957 Exit;
1958 end;
1959 end;
1961 if WordBool(PanelType and PANEL_WATER) then
1962 if gWater <> nil then
1963 begin
1964 h := High(gWater);
1966 for a := 0 to h do
1967 if g_Collide(X, Y, Width, Height,
1968 gWater[a].X, gWater[a].Y,
1969 gWater[a].Width, gWater[a].Height) then
1970 begin
1971 Result := True;
1972 Exit;
1973 end;
1974 end;
1976 if WordBool(PanelType and PANEL_ACID1) then
1977 if gAcid1 <> nil then
1978 begin
1979 h := High(gAcid1);
1981 for a := 0 to h do
1982 if g_Collide(X, Y, Width, Height,
1983 gAcid1[a].X, gAcid1[a].Y,
1984 gAcid1[a].Width, gAcid1[a].Height) then
1985 begin
1986 Result := True;
1987 Exit;
1988 end;
1989 end;
1991 if WordBool(PanelType and PANEL_ACID2) then
1992 if gAcid2 <> nil then
1993 begin
1994 h := High(gAcid2);
1996 for a := 0 to h do
1997 if g_Collide(X, Y, Width, Height,
1998 gAcid2[a].X, gAcid2[a].Y,
1999 gAcid2[a].Width, gAcid2[a].Height) then
2000 begin
2001 Result := True;
2002 Exit;
2003 end;
2004 end;
2006 if WordBool(PanelType and PANEL_STEP) then
2007 if gSteps <> nil then
2008 begin
2009 h := High(gSteps);
2011 for a := 0 to h do
2012 if g_Collide(X, Y, Width, Height,
2013 gSteps[a].X, gSteps[a].Y,
2014 gSteps[a].Width, gSteps[a].Height) then
2015 begin
2016 Result := True;
2017 Exit;
2018 end;
2019 end;
2021 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) then
2022 if gLifts <> nil then
2023 begin
2024 h := High(gLifts);
2026 for a := 0 to h do
2027 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2028 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2029 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2030 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2031 g_Collide(X, Y, Width, Height,
2032 gLifts[a].X, gLifts[a].Y,
2033 gLifts[a].Width, gLifts[a].Height) then
2034 begin
2035 Result := True;
2036 Exit;
2037 end;
2038 end;
2040 if WordBool(PanelType and PANEL_BLOCKMON) then
2041 if gBlockMon <> nil then
2042 begin
2043 h := High(gBlockMon);
2045 for a := 0 to h do
2046 if ( (not b1x3) or
2047 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2048 g_Collide(X, Y, Width, Height,
2049 gBlockMon[a].X, gBlockMon[a].Y,
2050 gBlockMon[a].Width, gBlockMon[a].Height) then
2051 begin
2052 Result := True;
2053 Exit;
2054 end;
2055 end;
2056 end;
2058 function g_Map_CollidePanel(X, Y: Integer; Width, Height: Word; PanelType: Word; b1x3: Boolean): Boolean;
2060 function qq (obj: TObject; tag: Integer): Boolean;
2061 var
2062 pan: TPanel;
2063 a: Integer;
2064 begin
2065 result := false; // don't stop, ever
2067 //e_WriteLog(Format(' *body: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2069 if obj = nil then
2070 begin
2071 e_WriteLog(Format(' !bodyFUUUUU0: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2072 end;
2073 if not (obj is TPanel) then
2074 begin
2075 e_WriteLog(Format(' !bodyFUUUUU1: tag:%d; qtag:%d', [tag, PanelType]), MSG_NOTIFY);
2076 exit;
2077 end;
2079 pan := (obj as TPanel);
2080 a := pan.ArrIdx;
2082 if WordBool(PanelType and PANEL_WALL) and WordBool(tag and PANEL_WALL) then
2083 begin
2084 if gWalls[a].Enabled and g_Collide(X, Y, Width, Height, gWalls[a].X, gWalls[a].Y, gWalls[a].Width, gWalls[a].Height) then
2085 begin
2086 result := true;
2087 exit;
2088 end;
2089 end;
2091 if WordBool(PanelType and PANEL_WATER) and WordBool(tag and PANEL_WATER) then
2092 begin
2093 if g_Collide(X, Y, Width, Height, gWater[a].X, gWater[a].Y, gWater[a].Width, gWater[a].Height) then
2094 begin
2095 result := True;
2096 exit;
2097 end;
2098 end;
2100 if WordBool(PanelType and PANEL_ACID1) and WordBool(tag and PANEL_ACID1) then
2101 begin
2102 if g_Collide(X, Y, Width, Height, gAcid1[a].X, gAcid1[a].Y, gAcid1[a].Width, gAcid1[a].Height) then
2103 begin
2104 result := True;
2105 exit;
2106 end;
2107 end;
2109 if WordBool(PanelType and PANEL_ACID2) and WordBool(tag and PANEL_ACID2) then
2110 begin
2111 if g_Collide(X, Y, Width, Height, gAcid2[a].X, gAcid2[a].Y, gAcid2[a].Width, gAcid2[a].Height) then
2112 begin
2113 result := True;
2114 exit;
2115 end;
2116 end;
2118 if WordBool(PanelType and PANEL_STEP) and WordBool(tag and PANEL_STEP) then
2119 begin
2120 if g_Collide(X, Y, Width, Height, gSteps[a].X, gSteps[a].Y, gSteps[a].Width, gSteps[a].Height) then
2121 begin
2122 result := True;
2123 exit;
2124 end;
2125 end;
2126 end;
2128 var
2129 a, h: Integer;
2130 begin
2131 result := gMapGrid.forEachInAABB(X, Y, Width, Height, qq);
2132 if not result then
2133 begin
2134 if WordBool(PanelType and (PANEL_LIFTUP or PANEL_LIFTDOWN or PANEL_LIFTLEFT or PANEL_LIFTRIGHT)) and (gLifts <> nil) then
2135 begin
2136 h := High(gLifts);
2137 for a := 0 to h do
2138 begin
2139 if ((WordBool(PanelType and (PANEL_LIFTUP)) and (gLifts[a].LiftType = 0)) or
2140 (WordBool(PanelType and (PANEL_LIFTDOWN)) and (gLifts[a].LiftType = 1)) or
2141 (WordBool(PanelType and (PANEL_LIFTLEFT)) and (gLifts[a].LiftType = 2)) or
2142 (WordBool(PanelType and (PANEL_LIFTRIGHT)) and (gLifts[a].LiftType = 3))) and
2143 g_Collide(X, Y, Width, Height,
2144 gLifts[a].X, gLifts[a].Y,
2145 gLifts[a].Width, gLifts[a].Height) then
2146 begin
2147 Result := True;
2148 Exit;
2149 end;
2150 end;
2151 end;
2153 if WordBool(PanelType and PANEL_BLOCKMON) and (gBlockMon <> nil) then
2154 begin
2155 h := High(gBlockMon);
2156 for a := 0 to h do
2157 begin
2158 if ( (not b1x3) or
2159 ((gBlockMon[a].Width + gBlockMon[a].Height) >= 64) ) and
2160 g_Collide(X, Y, Width, Height,
2161 gBlockMon[a].X, gBlockMon[a].Y,
2162 gBlockMon[a].Width, gBlockMon[a].Height) then
2163 begin
2164 Result := True;
2165 Exit;
2166 end;
2167 end;
2168 end;
2169 end;
2170 end;
2173 function g_Map_CollideLiquid_Texture(X, Y: Integer; Width, Height: Word): DWORD;
2174 var
2175 a, h: Integer;
2176 begin
2177 Result := TEXTURE_NONE;
2179 if gWater <> nil then
2180 begin
2181 h := High(gWater);
2183 for a := 0 to h do
2184 if g_Collide(X, Y, Width, Height,
2185 gWater[a].X, gWater[a].Y,
2186 gWater[a].Width, gWater[a].Height) then
2187 begin
2188 Result := gWater[a].GetTextureID();
2189 Exit;
2190 end;
2191 end;
2193 if gAcid1 <> nil then
2194 begin
2195 h := High(gAcid1);
2197 for a := 0 to h do
2198 if g_Collide(X, Y, Width, Height,
2199 gAcid1[a].X, gAcid1[a].Y,
2200 gAcid1[a].Width, gAcid1[a].Height) then
2201 begin
2202 Result := gAcid1[a].GetTextureID();
2203 Exit;
2204 end;
2205 end;
2207 if gAcid2 <> nil then
2208 begin
2209 h := High(gAcid2);
2211 for a := 0 to h do
2212 if g_Collide(X, Y, Width, Height,
2213 gAcid2[a].X, gAcid2[a].Y,
2214 gAcid2[a].Width, gAcid2[a].Height) then
2215 begin
2216 Result := gAcid2[a].GetTextureID();
2217 Exit;
2218 end;
2219 end;
2220 end;
2222 procedure g_Map_EnableWall(ID: DWORD);
2223 begin
2224 with gWalls[ID] do
2225 begin
2226 Enabled := True;
2227 g_Mark(X, Y, Width, Height, MARK_DOOR, True);
2229 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2230 end;
2231 end;
2233 procedure g_Map_DisableWall(ID: DWORD);
2234 begin
2235 with gWalls[ID] do
2236 begin
2237 Enabled := False;
2238 g_Mark(X, Y, Width, Height, MARK_DOOR, False);
2240 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2241 end;
2242 end;
2244 procedure g_Map_SwitchTexture(PanelType: Word; ID: DWORD; AnimLoop: Byte = 0);
2245 var
2246 tp: TPanel;
2247 begin
2248 case PanelType of
2249 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2250 tp := gWalls[ID];
2251 PANEL_FORE:
2252 tp := gRenderForegrounds[ID];
2253 PANEL_BACK:
2254 tp := gRenderBackgrounds[ID];
2255 PANEL_WATER:
2256 tp := gWater[ID];
2257 PANEL_ACID1:
2258 tp := gAcid1[ID];
2259 PANEL_ACID2:
2260 tp := gAcid2[ID];
2261 PANEL_STEP:
2262 tp := gSteps[ID];
2263 else
2264 Exit;
2265 end;
2267 tp.NextTexture(AnimLoop);
2268 if g_Game_IsServer and g_Game_IsNet then
2269 MH_SEND_PanelTexture(PanelType, ID, AnimLoop);
2270 end;
2272 procedure g_Map_SetLift(ID: DWORD; t: Integer);
2273 begin
2274 if gLifts[ID].LiftType = t then
2275 Exit;
2277 with gLifts[ID] do
2278 begin
2279 LiftType := t;
2281 g_Mark(X, Y, Width, Height, MARK_LIFT, False);
2283 if LiftType = 0 then
2284 g_Mark(X, Y, Width, Height, MARK_LIFTUP, True)
2285 else if LiftType = 1 then
2286 g_Mark(X, Y, Width, Height, MARK_LIFTDOWN, True)
2287 else if LiftType = 2 then
2288 g_Mark(X, Y, Width, Height, MARK_LIFTLEFT, True)
2289 else if LiftType = 3 then
2290 g_Mark(X, Y, Width, Height, MARK_LIFTRIGHT, True);
2292 if g_Game_IsServer and g_Game_IsNet then MH_SEND_PanelState(PanelType, ID);
2293 end;
2294 end;
2296 function g_Map_GetPoint(PointType: Byte; var RespawnPoint: TRespawnPoint): Boolean;
2297 var
2298 a: Integer;
2299 PointsArray: Array of TRespawnPoint;
2300 begin
2301 Result := False;
2302 SetLength(PointsArray, 0);
2304 if RespawnPoints = nil then
2305 Exit;
2307 for a := 0 to High(RespawnPoints) do
2308 if RespawnPoints[a].PointType = PointType then
2309 begin
2310 SetLength(PointsArray, Length(PointsArray)+1);
2311 PointsArray[High(PointsArray)] := RespawnPoints[a];
2312 end;
2314 if PointsArray = nil then
2315 Exit;
2317 RespawnPoint := PointsArray[Random(Length(PointsArray))];
2318 Result := True;
2319 end;
2321 function g_Map_GetPointCount(PointType: Byte): Word;
2322 var
2323 a: Integer;
2324 begin
2325 Result := 0;
2327 if RespawnPoints = nil then
2328 Exit;
2330 for a := 0 to High(RespawnPoints) do
2331 if RespawnPoints[a].PointType = PointType then
2332 Result := Result + 1;
2333 end;
2335 function g_Map_HaveFlagPoints(): Boolean;
2336 begin
2337 Result := (FlagPoints[FLAG_RED] <> nil) and (FlagPoints[FLAG_BLUE] <> nil);
2338 end;
2340 procedure g_Map_ResetFlag(Flag: Byte);
2341 begin
2342 with gFlags[Flag] do
2343 begin
2344 Obj.X := -1000;
2345 Obj.Y := -1000;
2346 Obj.Vel.X := 0;
2347 Obj.Vel.Y := 0;
2348 Direction := D_LEFT;
2349 State := FLAG_STATE_NONE;
2350 if FlagPoints[Flag] <> nil then
2351 begin
2352 Obj.X := FlagPoints[Flag]^.X;
2353 Obj.Y := FlagPoints[Flag]^.Y;
2354 Direction := FlagPoints[Flag]^.Direction;
2355 State := FLAG_STATE_NORMAL;
2356 end;
2357 Count := -1;
2358 end;
2359 end;
2361 procedure g_Map_DrawFlags();
2362 var
2363 i, dx: Integer;
2364 Mirror: TMirrorType;
2365 begin
2366 if gGameSettings.GameMode <> GM_CTF then
2367 Exit;
2369 for i := FLAG_RED to FLAG_BLUE do
2370 with gFlags[i] do
2371 if State <> FLAG_STATE_CAPTURED then
2372 begin
2373 if State = FLAG_STATE_NONE then
2374 continue;
2376 if Direction = D_LEFT then
2377 begin
2378 Mirror := M_HORIZONTAL;
2379 dx := -1;
2380 end
2381 else
2382 begin
2383 Mirror := M_NONE;
2384 dx := 1;
2385 end;
2387 Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
2389 if g_debug_Frames then
2390 begin
2391 e_DrawQuad(Obj.X+Obj.Rect.X,
2392 Obj.Y+Obj.Rect.Y,
2393 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
2394 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
2395 0, 255, 0);
2396 end;
2397 end;
2398 end;
2400 procedure g_Map_SaveState(Var Mem: TBinMemoryWriter);
2401 var
2402 dw: DWORD;
2403 b: Byte;
2404 str: String;
2405 boo: Boolean;
2407 procedure SavePanelArray(var panels: TPanelArray);
2408 var
2409 PAMem: TBinMemoryWriter;
2410 i: Integer;
2411 begin
2412 // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé:
2413 PAMem := TBinMemoryWriter.Create((Length(panels)+1) * 40);
2415 i := 0;
2416 while i < Length(panels) do
2417 begin
2418 if panels[i].SaveIt then
2419 begin
2420 // ID ïàíåëè:
2421 PAMem.WriteInt(i);
2422 // Ñîõðàíÿåì ïàíåëü:
2423 panels[i].SaveState(PAMem);
2424 end;
2425 Inc(i);
2426 end;
2428 // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé:
2429 PAMem.SaveToMemory(Mem);
2430 PAMem.Free();
2431 end;
2433 procedure SaveFlag(flag: PFlag);
2434 begin
2435 // Ñèãíàòóðà ôëàãà:
2436 dw := FLAG_SIGNATURE; // 'FLAG'
2437 Mem.WriteDWORD(dw);
2438 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2439 Mem.WriteByte(flag^.RespawnType);
2440 // Ñîñòîÿíèå ôëàãà:
2441 Mem.WriteByte(flag^.State);
2442 // Íàïðàâëåíèå ôëàãà:
2443 if flag^.Direction = D_LEFT then
2444 b := 1
2445 else // D_RIGHT
2446 b := 2;
2447 Mem.WriteByte(b);
2448 // Îáúåêò ôëàãà:
2449 Obj_SaveState(@flag^.Obj, Mem);
2450 end;
2452 begin
2453 Mem := TBinMemoryWriter.Create(1024 * 1024); // 1 MB
2455 ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: /////
2456 // Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé:
2457 SavePanelArray(gWalls);
2458 // Ñîõðàíÿåì ïàíåëè ôîíà:
2459 SavePanelArray(gRenderBackgrounds);
2460 // Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà:
2461 SavePanelArray(gRenderForegrounds);
2462 // Ñîõðàíÿåì ïàíåëè âîäû:
2463 SavePanelArray(gWater);
2464 // Ñîõðàíÿåì ïàíåëè êèñëîòû-1:
2465 SavePanelArray(gAcid1);
2466 // Ñîõðàíÿåì ïàíåëè êèñëîòû-2:
2467 SavePanelArray(gAcid2);
2468 // Ñîõðàíÿåì ïàíåëè ñòóïåíåé:
2469 SavePanelArray(gSteps);
2470 // Ñîõðàíÿåì ïàíåëè ëèôòîâ:
2471 SavePanelArray(gLifts);
2472 ///// /////
2474 ///// Ñîõðàíÿåì ìóçûêó: /////
2475 // Ñèãíàòóðà ìóçûêè:
2476 dw := MUSIC_SIGNATURE; // 'MUSI'
2477 Mem.WriteDWORD(dw);
2478 // Íàçâàíèå ìóçûêè:
2479 Assert(gMusic <> nil, 'g_Map_SaveState: gMusic = nil');
2480 if gMusic.NoMusic then
2481 str := ''
2482 else
2483 str := gMusic.Name;
2484 Mem.WriteString(str, 64);
2485 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2486 dw := gMusic.GetPosition();
2487 Mem.WriteDWORD(dw);
2488 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2489 boo := gMusic.SpecPause;
2490 Mem.WriteBoolean(boo);
2491 ///// /////
2493 ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: /////
2494 Mem.WriteInt(gTotalMonsters);
2495 ///// /////
2497 //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: /////
2498 if gGameSettings.GameMode = GM_CTF then
2499 begin
2500 // Ôëàã Êðàñíîé êîìàíäû:
2501 SaveFlag(@gFlags[FLAG_RED]);
2502 // Ôëàã Ñèíåé êîìàíäû:
2503 SaveFlag(@gFlags[FLAG_BLUE]);
2504 end;
2505 ///// /////
2507 ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2508 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2509 begin
2510 // Î÷êè Êðàñíîé êîìàíäû:
2511 Mem.WriteSmallInt(gTeamStat[TEAM_RED].Goals);
2512 // Î÷êè Ñèíåé êîìàíäû:
2513 Mem.WriteSmallInt(gTeamStat[TEAM_BLUE].Goals);
2514 end;
2515 ///// /////
2516 end;
2518 procedure g_Map_LoadState(Var Mem: TBinMemoryReader);
2519 var
2520 dw: DWORD;
2521 b: Byte;
2522 str: String;
2523 boo: Boolean;
2525 procedure LoadPanelArray(var panels: TPanelArray);
2526 var
2527 PAMem: TBinMemoryReader;
2528 i, id: Integer;
2529 begin
2530 // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé:
2531 PAMem := TBinMemoryReader.Create();
2532 PAMem.LoadFromMemory(Mem);
2534 for i := 0 to Length(panels)-1 do
2535 if panels[i].SaveIt then
2536 begin
2537 // ID ïàíåëè:
2538 PAMem.ReadInt(id);
2539 if id <> i then
2540 begin
2541 raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID');
2542 end;
2543 // Çàãðóæàåì ïàíåëü:
2544 panels[i].LoadState(PAMem);
2545 end;
2547 // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí:
2548 PAMem.Free();
2549 end;
2551 procedure LoadFlag(flag: PFlag);
2552 begin
2553 // Ñèãíàòóðà ôëàãà:
2554 Mem.ReadDWORD(dw);
2555 if dw <> FLAG_SIGNATURE then // 'FLAG'
2556 begin
2557 raise EBinSizeError.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature');
2558 end;
2559 // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà:
2560 Mem.ReadByte(flag^.RespawnType);
2561 // Ñîñòîÿíèå ôëàãà:
2562 Mem.ReadByte(flag^.State);
2563 // Íàïðàâëåíèå ôëàãà:
2564 Mem.ReadByte(b);
2565 if b = 1 then
2566 flag^.Direction := D_LEFT
2567 else // b = 2
2568 flag^.Direction := D_RIGHT;
2569 // Îáúåêò ôëàãà:
2570 Obj_LoadState(@flag^.Obj, Mem);
2571 end;
2573 begin
2574 if Mem = nil then
2575 Exit;
2577 ///// Çàãðóæàåì ñïèñêè ïàíåëåé: /////
2578 // Çàãðóæàåì ïàíåëè ñòåí è äâåðåé:
2579 LoadPanelArray(gWalls);
2580 // Çàãðóæàåì ïàíåëè ôîíà:
2581 LoadPanelArray(gRenderBackgrounds);
2582 // Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà:
2583 LoadPanelArray(gRenderForegrounds);
2584 // Çàãðóæàåì ïàíåëè âîäû:
2585 LoadPanelArray(gWater);
2586 // Çàãðóæàåì ïàíåëè êèñëîòû-1:
2587 LoadPanelArray(gAcid1);
2588 // Çàãðóæàåì ïàíåëè êèñëîòû-2:
2589 LoadPanelArray(gAcid2);
2590 // Çàãðóæàåì ïàíåëè ñòóïåíåé:
2591 LoadPanelArray(gSteps);
2592 // Çàãðóæàåì ïàíåëè ëèôòîâ:
2593 LoadPanelArray(gLifts);
2594 ///// /////
2596 // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé:
2597 g_GFX_Init();
2599 ///// Çàãðóæàåì ìóçûêó: /////
2600 // Ñèãíàòóðà ìóçûêè:
2601 Mem.ReadDWORD(dw);
2602 if dw <> MUSIC_SIGNATURE then // 'MUSI'
2603 begin
2604 raise EBinSizeError.Create('g_Map_LoadState: Wrong Music Signature');
2605 end;
2606 // Íàçâàíèå ìóçûêè:
2607 Assert(gMusic <> nil, 'g_Map_LoadState: gMusic = nil');
2608 Mem.ReadString(str);
2609 // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè:
2610 Mem.ReadDWORD(dw);
2611 // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå:
2612 Mem.ReadBoolean(boo);
2613 // Çàïóñêàåì ýòó ìóçûêó:
2614 gMusic.SetByName(str);
2615 gMusic.SpecPause := boo;
2616 gMusic.Play();
2617 gMusic.Pause(True);
2618 gMusic.SetPosition(dw);
2619 ///// /////
2621 ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: /////
2622 Mem.ReadInt(gTotalMonsters);
2623 ///// /////
2625 //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: /////
2626 if gGameSettings.GameMode = GM_CTF then
2627 begin
2628 // Ôëàã Êðàñíîé êîìàíäû:
2629 LoadFlag(@gFlags[FLAG_RED]);
2630 // Ôëàã Ñèíåé êîìàíäû:
2631 LoadFlag(@gFlags[FLAG_BLUE]);
2632 end;
2633 ///// /////
2635 ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: /////
2636 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2637 begin
2638 // Î÷êè Êðàñíîé êîìàíäû:
2639 Mem.ReadSmallInt(gTeamStat[TEAM_RED].Goals);
2640 // Î÷êè Ñèíåé êîìàíäû:
2641 Mem.ReadSmallInt(gTeamStat[TEAM_BLUE].Goals);
2642 end;
2643 ///// /////
2644 end;
2646 function g_Map_PanelForPID(PanelID: Integer; var PanelArrayID: Integer): PPanel;
2647 var
2648 Arr: TPanelArray;
2649 begin
2650 Result := nil;
2651 if (PanelID < 0) or (PanelID > High(PanelByID)) then Exit;
2652 Arr := PanelByID[PanelID].PWhere^;
2653 PanelArrayID := PanelByID[PanelID].PArrID;
2654 Result := Addr(Arr[PanelByID[PanelID].PArrID]);
2655 end;
2657 end.