home *** CD-ROM | disk | FTP | other *** search
/ Deathday Collection / dday.bin / edit / dfe / maps.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-26  |  9KB  |  273 lines

  1. {****************************************************************************
  2. *                      The DOOM Hacker's Tool Kit                           *
  3. *****************************************************************************
  4. * Unit:       MAPS                                                             *
  5. * Purpose: Loading and displaying the Maps from the WAD File                *
  6. * Date:    4/28/94                                                          *
  7. * Author:  Joshua Jackson        Internet: joshjackson@delphi.com           *
  8. ****************************************************************************}
  9.  
  10. {$O+,F+}
  11. unit Maps;
  12.  
  13. interface
  14.  
  15. uses Wad,WadDecl,DOOMGUI,GUIObj;
  16.  
  17. type  PWadMapViewer=^TWadMapViewer;
  18.         TWadMapViewer=TGraphGroup;
  19.         PWadMap=^TWadMap;
  20.         TWadMap=Object(TGraphView)
  21.             LevelEntries:PLevelEntries;
  22.             ThingList    :PThingList;
  23.             VertexList    :PVertexList;
  24.             LineDefList    :PLineDefList;
  25.             ViewerMask    :word;
  26.             ThingMask    :word;
  27.             ScaleInc,XOffset,YOffset:word;
  28.             Constructor Init(WDir:PWadDirectory;LevelName:ObjNameStr);
  29.             Procedure Draw; virtual;
  30.             Procedure SetScale(NewScaleInc,NewXOffset,NewYOffset:word);
  31.             Function GetThingInArea(x1,y1,x2,y2:word):word;
  32.             Destructor Done; virtual;
  33.         end;
  34.  
  35. implementation
  36.  
  37. uses crt,graph;
  38.  
  39. Function OnSkillLevel(Attr,ViewerMask:word):boolean;
  40.  
  41.     var TempAttr:word;
  42.  
  43.     begin
  44.         TempAttr:=(ViewerMask and 64);
  45.         if (TempAttr=0) and ((Attr and 16) = 16) then begin
  46.             OnSkillLevel:=False;
  47.             exit;
  48.         end;
  49.         TempAttr:=(ViewerMask and 56) shr 3;
  50.         if (TempAttr and (Attr and 7)) = TempAttr then
  51.             OnSkillLevel:=True
  52.         else
  53.             OnSkillLevel:=False;
  54.     end;
  55.  
  56. Constructor TWadMap.Init(WDir:PWadDirectory;LevelName:ObjNameStr);
  57.  
  58.     var    Entry,LevelPos:word;
  59.             R:TGraphRect;
  60.  
  61.     begin
  62.         Owner:=Nil;
  63.         Next:=Nil;
  64.         ScaleInc:=1;
  65.         XOffset:=0;
  66.         YOffset:=0;
  67.         R.Assign(0,0,639,479);
  68.         Bounds:=R;
  69.         New(LevelEntries);
  70.         LevelPos:=WDir^.FindObject(LevelName);
  71.         if LevelPos=0 then begin
  72.             writeln('TWapMap_Init: Invalid Level Name ',LevelName);
  73.             halt;
  74.         end;
  75.         LevelEntries^.MapID:=WDir^.DirEntry^[LevelPos];
  76.         LevelEntries^.Things:=WDir^.DirEntry^[LevelPos+1];
  77.         LevelEntries^.LineDefs:=WDir^.DirEntry^[LevelPos+2];
  78.         LevelEntries^.SideDefs:=WDir^.DirEntry^[LevelPos+3];
  79.         LevelEntries^.Vertexes:=WDir^.DirEntry^[LevelPos+4];
  80.         LevelEntries^.Segs:=WDir^.DirEntry^[LevelPos+5];
  81.         LevelEntries^.SSectors:=WDir^.DirEntry^[LevelPos+6];
  82.         LevelEntries^.Nodes:=WDir^.DirEntry^[LevelPos+7];
  83.         LevelEntries^.Sectors:=WDir^.DirEntry^[LevelPos+8];
  84.         LevelEntries^.Reject:=WDir^.DirEntry^[LevelPos+9];
  85.         LevelEntries^.BlockMap:=WDir^.DirEntry^[LevelPos+10];
  86.         GetMem(ThingList,LevelEntries^.Things.ObjLength);
  87.         Seek(WDir^.WadFile,LevelEntries^.Things.ObjStart);
  88.         BlockRead(WDir^.WadFile,ThingList^,LevelEntries^.Things.ObjLength);
  89.         GetMem(VertexList,LevelEntries^.Vertexes.ObjLength);
  90.         Seek(WDir^.WadFile,LevelEntries^.Vertexes.ObjStart);
  91.         BlockRead(WDir^.WadFile,VertexList^,LevelEntries^.Vertexes.ObjLength);
  92.         GetMem(LineDefList,LevelEntries^.LineDefs.ObjLength);
  93.         Seek(WDir^.WadFile,LevelEntries^.LineDefs.ObjStart);
  94.         BlockRead(WDir^.WadFile,LineDefList^,LevelEntries^.LineDefs.ObjLength);
  95.     end;
  96.  
  97. Procedure TWadMap.Draw;
  98.  
  99.     var    MidX,MidY,MaxX,MaxY,MinX,MinY:integer;
  100.             ScaleX,ScaleY,Scale:real;
  101.             IntScale:Longint;
  102.             x,y,NumThings,NumLines,gd,gm,t:integer;
  103.             ch,SkillLevel:Char;
  104.             TempStr:String;
  105.             TT:word;
  106.             SubView:PGraphView;
  107.  
  108.     begin
  109.         MinX:=32000;
  110.         MinY:=32000;
  111.         MaxX:=-32000;
  112.         MaxY:=-32000;
  113.         for t:=0 to ((LevelEntries^.Vertexes.ObjLength div 4) -1) do begin
  114.             if VertexList^[t].x < MinX then
  115.                 MinX:=VertexList^[t].x;
  116.             if VertexList^[t].x > MaxX then
  117.                 MaxX:=VertexList^[t].x;
  118.             if VertexList^[t].y < MinY then
  119.                 MinY:=VertexList^[t].y;
  120.             if VertexList^[t].y > Maxy then
  121.                 MaxY:=VertexList^[t].y;
  122.         end;
  123.         MidX:=(MinX+MaxX) div 2;
  124.         MidY:=(MinY+MaxY) div 2;
  125.         SkillLevel:=' ';
  126.         ScaleX:=(320 / (MaxX - MidX)) * 0.90;
  127.         ScaleY:=(240 / (MaxY - MidY)) * 0.90;
  128.         if ScaleX < ScaleY then
  129.             Scale:=ScaleX
  130.         else
  131.             Scale:=ScaleY;
  132.         Scale:=Scale * ScaleInc;
  133.         IntScale:=Round(Scale * 65536);
  134.         NumLines:=((LevelEntries^.LineDefs.ObjLength div 14) - 1);
  135.         for t:=0 to NumLines do begin
  136.             SetColor(wcBlue);
  137.             case LineDefList^[t].LineDefType of
  138.                 1,26..28,31..34:SetColor(wcLtBlue);   {Doors}
  139.             end;
  140.             if ((LineDefList^[t].Attributes and 32) = 32) and ((ViewerMask and 128)=128) then
  141.                 SetColor(wcLtGrey);
  142.             x:=(((VertexList^[LineDefList^[t].StartVertex].x-MidX) * IntScale div 65536) + 320)+(XOffset * ScaleInc);
  143.             y:=(((VertexList^[LineDefList^[t].StartVertex].Y-MidY) * (-IntScale) div 65536) + 240)+(YOffset * ScaleInc);
  144.             MoveTo(x,y);
  145.             x:=(((VertexList^[LineDefList^[t].EndVertex].x-MidX) * IntScale div 65536) + 320)+(XOffset * ScaleInc);
  146.             y:=(((VertexList^[LineDefList^[t].EndVertex].Y-MidY) * (-IntScale) div 65536) + 240)+(YOffset * ScaleInc);
  147.             LineTo(x,y);
  148.         end;
  149.         NumThings:=((LevelEntries^.Things.ObjLength div 10) -1);
  150.         for t:=0 to NumThings do begin
  151.             x:=(((ThingList^[t].x-MidX) * IntScale div 65536)+320)+(XOffset * ScaleInc);
  152.             y:=(((ThingList^[t].y-MidY) * (-IntScale) div 65536)+240)+(YOffset * ScaleInc);
  153.             SetColor(wcRed);
  154.             TT:=ThingList^[t].ThingType;
  155.             if (ThingMask=0) or (TT=ThingMask) then begin
  156.                 if OnSkillLevel(ThingList^[t].Attributes,ViewerMask) then begin
  157.                     if (ViewerMask and 1) = 1 then {Monsters}
  158.                         if (TT=$7) or (TT=$9) or (TT=$10) or (TT=$3A) or ((TT > $BB8) and (TT<$BBF)) then begin
  159.                             SetColor(wcRed);
  160.                             Circle(x,y,ScaleInc);
  161.                         end;
  162.                     if (ViewerMask and 2) = 2 then begin {Goodies}
  163.                         if (TT=$5) or (TT=$6) or (TT=$8) or (TT=$d) or (TT=$26) or (TT=$27) then begin
  164.                             SetColor(wcLtGreen);
  165.                             Circle(x,y,ScaleInc);
  166.                         end;
  167.                         if ((TT>$7D6) and (TT<$7EB)) or ((TT>$7FC) and (TT<$802)) then begin
  168.                             SetColor(wcLtGreen);
  169.                             Circle(x,y,ScaleInc);
  170.                         end;
  171.                     end;
  172.                     if (ViewerMask and 4) = 4 then {Weapons}
  173.                         if (TT > $7D0) and (TT<$7D7) then begin
  174.                             SetColor(wcYellow);
  175.                             Circle(x,y,ScaleInc);
  176.                         end;
  177.                 end;
  178.             end;
  179.         end;
  180.         OutTextXY(560,1,LevelEntries^.MapID.ObjName);
  181.         str(ScaleInc,TempStr);
  182.         OutTextXY(1,465,'Scale: '+TempStr+'x');
  183.     end;
  184.  
  185. Procedure TWadMap.SetScale(NewScaleInc,NewXOffset,NewYOffset:word);
  186.  
  187.     begin
  188.         ScaleInc:=NewScaleInc;
  189.         XOffset:=NewXOffset;
  190.         YOffset:=NewYOffset;
  191.     end;
  192.  
  193. Function TWadMap.GetThingInArea(x1,y1,x2,y2:word):word;
  194.  
  195.     var    MidX,MidY,MaxX,MaxY,MinX,MinY:integer;
  196.             ScaleX,ScaleY,Scale:real;
  197.             IntScale:Longint;
  198.             x,y,NumThings,NumLines,gd,gm,t:integer;
  199.             ch,SkillLevel:Char;
  200.             TT:word;
  201.  
  202.     begin
  203.         MinX:=32000;
  204.         MinY:=32000;
  205.         MaxX:=-32000;
  206.         MaxY:=-32000;
  207.         for t:=0 to ((LevelEntries^.Vertexes.ObjLength div 4) -1) do begin
  208.             if VertexList^[t].x < MinX then
  209.                 MinX:=VertexList^[t].x;
  210.             if VertexList^[t].x > MaxX then
  211.                 MaxX:=VertexList^[t].x;
  212.             if VertexList^[t].y < MinY then
  213.                 MinY:=VertexList^[t].y;
  214.             if VertexList^[t].y > Maxy then
  215.                 MaxY:=VertexList^[t].y;
  216.         end;
  217.         MidX:=(MinX+MaxX) div 2;
  218.         MidY:=(MinY+MaxY) div 2;
  219.         SkillLevel:=' ';
  220.         ScaleX:=(320 / (MaxX - MidX)) * 0.90;
  221.         ScaleY:=(240 / (MaxY - MidY)) * 0.90;
  222.         if ScaleX < ScaleY then
  223.             Scale:=ScaleX
  224.         else
  225.             Scale:=ScaleY;
  226.         Scale:=Scale * ScaleInc;
  227.         IntScale:=Round(Scale * 65536);
  228.         NumThings:=((LevelEntries^.Things.ObjLength div 10) -1);
  229.         for t:=0 to NumThings do begin
  230.             x:=(((ThingList^[t].x-MidX) * IntScale div 65536)+320)+(XOffset * ScaleInc);
  231.             y:=(((ThingList^[t].y-MidY) * (-IntScale) div 65536)+240)+(YOffset * ScaleInc);
  232.             if ((x >= x1) and (x <= x2)) and ((y >= y1) and (y <= y2)) then begin
  233.                 TT:=ThingList^[t].ThingType;
  234.                 if (ThingMask=0) or (TT=ThingMask) then begin
  235.                     if (ViewerMask and 1) = 1 then {Monsters}
  236.                         if (TT=$7) or (TT=$9) or (TT=$10) or (TT=$3A) or ((TT > $BB8) and (TT<$BBF)) then begin
  237.                             GetThingInArea:=TT;
  238.                             exit;
  239.                         end;
  240.                     if (ViewerMask and 2) = 2 then begin {Goodies}
  241.                         if (TT=$5) or (TT=$6) or (TT=$8) or (TT=$d) or (TT=$26) or (TT=$27) then begin
  242.                             GetThingInArea:=TT;
  243.                             exit;
  244.                         end;
  245.                         if ((TT>$7D6) and (TT<$7EB)) or ((TT>$7FC) and (TT<$802)) then begin
  246.                             GetThingInArea:=TT;
  247.                             exit;
  248.                         end;
  249.                     end;
  250.                     if (ViewerMask and 4) = 4 then {Weapons}
  251.                         if (TT > $7D0) and (TT<$7D7) then begin
  252.                             GetThingInArea:=TT;
  253.                             exit;
  254.                         end;
  255.                 end;
  256.             end;
  257.         end;
  258.         GetThingInArea:=0;
  259.     end;
  260.  
  261. Destructor TWadMap.Done;
  262.  
  263.     var    TempView,SubView:PGraphView;
  264.  
  265.     begin
  266.         FreeMem(ThingList,LevelEntries^.Things.ObjLength);
  267.         FreeMem(VertexList,LevelEntries^.Vertexes.ObjLength);
  268.         FreeMem(LineDefList,LevelEntries^.LineDefs.ObjLength);
  269.         Dispose(LevelEntries);
  270.     end;
  271.  
  272. end.
  273.