home *** CD-ROM | disk | FTP | other *** search
/ D!Zone (Collector's Edition) / D_ZONE_CD.ISO / programs / editors / dhtk100 / mapread.pas < prev    next >
Pascal/Delphi Source File  |  1994-12-06  |  9KB  |  323 lines

  1. {****************************************************************************
  2. *                      The DOOM Hacker's Tool Kit                           *
  3. *****************************************************************************
  4. * Unit:       MAPREAD                                                          *
  5. * Purpose: Map Viewer unit for DOOM Front End (DFE)                         *
  6. * Date:    4/28/94                                                          *
  7. * Author:  Joshua Jackson        Internet: joshjackson@delphi.com           *
  8. ****************************************************************************}
  9.  
  10. {$O+,F+}
  11. unit MAPREAD;
  12.  
  13. interface
  14.  
  15. uses Wad,WadDecl,Maps,Graph,Crt,Things,Dos,DOOMGui,Mouse,ThingDef,GUIObj,SpriteView;
  16.  
  17. Procedure ViewMap(WadName:PathStr;LevelName:ObjNameStr;ViewerMask,ThingMask:word);
  18.  
  19. implementation
  20.  
  21. var    WDir:PWadDirectory;
  22.         DoomDir:PWadDirectory;
  23.         WMap:PWadMap;
  24.         WMapViewer:PWadMapViewer;
  25.         SpViewer:PSpriteViewer;
  26.         SVGA256Driver:integer;
  27.         In256ColorMode:Boolean;
  28.  
  29. procedure EgaVgaDriverProc; external;
  30. {$L EGAVGA.OBJ }
  31.  
  32. Procedure BGI256Proc; external;
  33. {$L BGI256.obj}
  34.  
  35. function DetectVGA256 : Integer;
  36.  
  37.     begin
  38.         DetectVGA256:=2;
  39.     end;
  40.  
  41. Procedure InitVideo;
  42.  
  43.     var    gd,gm:integer;
  44.  
  45.     begin
  46.     {$IFDEF DPMI}
  47.       if    RegisterBGIDriver(@BGI256Proc) < 0 then begin
  48.             writeln('SysMapVideo_Init: ',GraphErrorMsg(GraphResult));
  49.             halt;
  50.         end;
  51.         if RegisterBGIDriver(@EGAVGADriverProc) < 0 then begin
  52.             writeln('SysMapVideo_Init: ',GraphErrorMsg(GraphResult));
  53.             halt;
  54.         end;
  55.     {$ENDIF}
  56.         gd:=SVGA256Driver;
  57.         gm:=2;
  58.         InitGraph(gd,gm,'');
  59.         gd:=GraphResult;
  60.         if gd=grOK then begin
  61.             FakeCursor:=True;
  62.             In256ColorMode:=True;
  63.             exit;
  64.         end;
  65.         gd:=Detect;
  66.         InitGraph(gd,gm,'');
  67.         gd:=GraphResult;
  68.         FakeCursor:=False;
  69.         if gd<>grOK then begin
  70.             writeln('MapView_InitVideo: ',GraphErrorMsg(gd));
  71.             halt(1);
  72.         end;
  73.         In256ColorMode:=False;
  74.     end;
  75.  
  76. Procedure ViewMap(WadName:PathStr;LevelName:ObjNameStr;ViewerMask,ThingMask:word);
  77.  
  78.     var     TempStr:string;
  79.             ch:char;
  80.             ScaleInc,XOfs,YOfs:word;
  81.             t,MouseX,MouseY,MouseButtons:integer;
  82.             x1,x2,y1,y2:word;
  83.             ThingNum,ThingDefNum:word;
  84.             SpriteID:ObjNameStr;
  85.             Sprite:PWadThing;
  86.             Buttons:PGraphGroup;
  87.             MButton,GButton,WButton,PButton:PGraphButton;
  88.             Lev1Button,Lev3Button,Lev5Button:PGraphButton;
  89.             R:TGraphRect;
  90.             ReDraw:boolean;
  91.  
  92.     begin
  93.         TextAttr:=7;
  94.         ClrScr;
  95.         writeln('Map Viewer v2.01');
  96.         writeln('By Jackson Software');
  97.         writeln;
  98.         delay(500);
  99.         writeln('ThingDef_Init');
  100.         InitThingDefs;
  101.         TempStr:=LevelName+'        ';
  102.         Move(TempStr[1],LevelName,8);
  103.         writeln('WAD_Init:  Initializing WAD file...');
  104.         WDir:=New(PWadDirectory, Init(WadName));
  105.         TempStr:='DOOM'+#00;
  106.         DOOMDir:=WDir;
  107.         for t:=1 to 4 do begin
  108.             If WDir^.WadName[t] <> TempStr[t] then begin
  109.                 if MaxAvail < 64000 then begin
  110.                     writeln('Insufficent Memory To Load DOOM.WAD Directory.');
  111.                     halt;
  112.                 end;
  113.                 writeln('WAD_Init:  Intializing Main WAD file...');
  114.                 DOOMDir:=New(PWadDirectory, Init('DOOM.WAD'));
  115.                 Break;
  116.             end;
  117.         end;
  118.         writeln('WadMap_Init: Initializing WAD file Map...');
  119.         WMap:=New(PWadMap, Init(WDir,LevelName));
  120.         WMap^.ViewerMask:=ViewerMask;
  121.         WMap^.ThingMask:=ThingMask;
  122.         In256ColorMode:=True;
  123.         ScaleInc:=1;
  124.         XOfs:=0;
  125.         YOfs:=0;
  126.         R.Assign(1,1,15,15);
  127.         MButton:=New(PGraphButton, Init(R,0,'M'));
  128.         R.Assign(17,1,32,15);
  129.         GButton:=New(PGraphButton, Init(R,0,'G'));
  130.         R.Assign(34,1,49,15);
  131.         WButton:=New(PGraphButton, Init(R,0,'W'));
  132.         R.Assign(51,1,65,15);
  133.         PButton:=New(PGraphButton, Init(R,0,'P'));
  134.         R.Assign(68,1,93,15);
  135.         Lev1Button:=New(PGraphButton, Init(R,0,'12'));
  136.         R.Assign(95,1,120,15);
  137.         Lev3Button:=New(PGraphButton, Init(R,0,'3'));
  138.         R.Assign(122,1,147,15);
  139.         Lev5Button:=New(PGraphButton, Init(R,0,'45'));
  140.         if (ViewerMask and 1) = 1 then
  141.             MButton^.IsPressed:=1;
  142.         if (ViewerMask and 2) = 2 then
  143.             GButton^.IsPressed:=1;
  144.         if (ViewerMask and 8) = 8 then begin
  145.             Lev3Button^.IsPressed:=0;
  146.             Lev5Button^.IsPressed:=0;
  147.             Lev1Button^.IsPressed:=1;
  148.          end
  149.         else if (ViewerMask and 16) = 16 then begin
  150.             Lev1Button^.IsPressed:=0;
  151.             Lev5Button^.IsPressed:=0;
  152.             Lev3Button^.IsPressed:=1;
  153.          end
  154.         else if (ViewerMask and 32) = 32 then begin
  155.             Lev1Button^.IsPressed:=0;
  156.             Lev3Button^.IsPressed:=0;
  157.             Lev5Button^.IsPressed:=1;
  158.         end;
  159.         R.Assign(1,1,640,480);
  160.         writeln('MapView_Init');
  161.         WMapViewer:=New(PWadMapViewer, Init(R));
  162.         WMapViewer^.Insert(WMap);
  163.         WMapViewer^.Insert(MButton);
  164.         WMapViewer^.Insert(GButton);
  165.         WMapViewer^.Insert(WButton);
  166.         WMapViewer^.Insert(PButton);
  167.         WMapViewer^.Insert(Lev1Button);
  168.         WMapViewer^.Insert(Lev3Button);
  169.         WMapViewer^.Insert(Lev5Button);
  170.         ReDraw:=True;
  171.         writeln('MapVideo_Init');
  172.         InitVideo;
  173.         InitMouse;
  174.         ShowMousePointer;
  175.         if In256ColorMode then
  176.             DOOMDir^.SetWadPalette(0);
  177.         repeat
  178.             if ReDraw then begin
  179.                 WMap^.ViewerMask:=ViewerMask;
  180.                 HideMousePointer;
  181.                 ClearDevice;
  182.                 WMapViewer^.Draw;
  183.                 ShowMousePointer;
  184.             end;
  185.             ReDraw:=True;
  186.             ch:='~';
  187.             if UseMouse then begin
  188.                 GetMouseCoords(MouseX,MouseY,MouseButtons);
  189.                 str(MouseX,Tempstr);
  190.                 if FakeCursor then
  191.                     DrawFakeCursor(MouseX,MouseY);
  192.                 if (MouseButtons and 1)=1 then begin
  193.                     if MButton^.InButton(MouseX,MouseY) then
  194.                         ch:='M'
  195.                     else if GButton^.InButton(MouseX,MouseY) then
  196.                         ch:='G'
  197.                     else if WButton^.InButton(MouseX,MouseY) then
  198.                         ch:='W'
  199.                     else if PButton^.InButton(MouseX,MouseY) then
  200.                         ch:='P'
  201.                     else if Lev1Button^.InButton(MouseX,MouseY) then
  202.                         ch:='1'
  203.                     else if Lev3Button^.InButton(MouseX,MouseY) then
  204.                         ch:='3'
  205.                     else if Lev5Button^.InButton(MouseX,MouseY) then
  206.                         ch:='5'
  207.                     else begin
  208.                         x1:=MouseX - WMap^.ScaleInc;
  209.                         x2:=MouseX + WMap^.ScaleInc;
  210.                         y1:=Mousey - WMap^.ScaleInc;
  211.                         y2:=Mousey + WMap^.ScaleInc;
  212.                         ThingNum:=WMap^.GetThingInArea(x1,y1,x2,y2);
  213.                         if ThingNum <> 0 then begin
  214.                             HideMousePointer;
  215.                             SpViewer:=New(PSpriteViewer, Init(ThingNum, DOOMDir));
  216.                             if In256ColorMode then begin
  217.                                 SpViewer^.Draw;
  218.                              end
  219.                             else begin
  220.                                 SetColor(15);
  221.                                 OutTextXy(335,450,'Sprite View Disabled...');
  222.                                 OutTextXY(335,465,'System is in 16 Color Mode.');
  223.                             end;
  224.                             SpViewer^.Done;
  225.                             Dispose(SpViewer);
  226.                             ShowMousePointer;
  227.                         end;
  228.                     end;
  229.                 end;
  230.             end;
  231.             if KeyPressed then begin
  232.                 ch:=ReadKey;
  233.                 ch:=UpCase(ch);
  234.             end;
  235.             case ch of
  236.                 '+':if WMap^.ScaleInc < 10 then
  237.                         Inc(WMap^.ScaleInc);
  238.                 '-':if WMap^.ScaleInc > 1 then
  239.                         Dec(WMap^.ScaleInc);
  240.                 'S':ViewerMask:=ViewerMask xor 128;
  241.                 'M':Begin
  242.                         ViewerMask:=ViewerMask xor 1;
  243.                         MButton^.IsPressed:=MButton^.IsPressed xor 1;
  244.                      end;
  245.                 'G':Begin
  246.                         ViewerMask:=ViewerMask xor 2;
  247.                         GButton^.IsPressed:=GButton^.IsPressed xor 1;
  248.                      end;
  249.                 'W':Begin
  250.                         ViewerMask:=ViewerMask xor 4;
  251.                         WButton^.IsPressed:=WButton^.IsPressed xor 1;
  252.                      end;
  253.                 'P':Begin
  254.                         ViewerMask:=ViewerMask xor 64;
  255.                         PButton^.IsPressed:=PButton^.IsPressed xor 1;
  256.                      end;
  257.                 '1','2':begin
  258.                                 ViewerMask:=(ViewerMask and 199) or 8;
  259.                                 Lev3Button^.IsPressed:=0;
  260.                                 Lev5Button^.IsPressed:=0;
  261.                                 Lev1Button^.IsPressed:=1;
  262.                             end;
  263.                 '3':begin
  264.                         ViewerMask:=(ViewerMask and 199) or 16;
  265.                         Lev1Button^.IsPressed:=0;
  266.                         Lev5Button^.IsPressed:=0;
  267.                         Lev3Button^.IsPressed:=1;
  268.                     end;
  269.                 '4','5':begin
  270.                                 ViewerMask:=(ViewerMask and 199) or 32;
  271.                                 Lev1Button^.IsPressed:=0;
  272.                                 Lev3Button^.IsPressed:=0;
  273.                                 Lev5Button^.IsPressed:=1;
  274.                             end;
  275.                 #0:begin
  276.                         ch:=ReadKey;
  277.                         case ch of
  278.                             'H':WMap^.YOffset:=WMap^.YOffset+10;
  279.                             'K':WMap^.XOffset:=WMap^.XOffset+10;
  280.                             'P':WMap^.YOffset:=WMap^.YOffset-10;
  281.                             'M':WMap^.XOffset:=WMap^.XOffset-10;
  282.                             'G':WMap^.SetScale(1,0,0);
  283.                         end;
  284.                     end;
  285.                 else
  286.                     ReDraw:=False;
  287.             end;
  288.         until ch=#27;
  289.         DoneMouse;
  290.         ClearDevice;
  291.         if In256ColorMode th