home *** CD-ROM | disk | FTP | other *** search
/ FMI Superhry 1 / Superhry-I.bin / bonus / doom / programs / ktsdht10 / thingdef.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-09  |  4KB  |  157 lines

  1. {****************************************************************************
  2. *                      The DOOM Hacker's Tool Kit                           *
  3. *****************************************************************************
  4. * Unit:       THINGDEF                                                         *
  5. * Purpose: Thing Definitions, Identification, and Cross Referencing         *
  6. * Date:    5/06/94                                                          *
  7. * Author:  Joshua Jackson        Internet: joshjackson@delphi.com           *
  8. ****************************************************************************}
  9.  
  10. {$O+,F+}                                                {Allow for overlaying}
  11. unit ThingDef;
  12.  
  13. interface
  14.  
  15. uses WadDecl,Wad;
  16.  
  17. const    MaxThingDefs=829;                            {64k worth}
  18.  
  19. type    PThingDef=^TThingDef;
  20.         PThingDefArray=^TThingDefArray;
  21.         TThingDef=record
  22.             Num        :word;
  23.             PictID   :array[1..4] of char;
  24.             AnimSeq  :array[1..7] of char;
  25.             DefType  :byte;
  26.             Desc     :array[1..65] of char;
  27.         end;
  28.         TThingDefArray=array[1..MaxThingDefs] of TThingDef;
  29.  
  30. var    TotalThingDefs:word;                            {DO NOT modify!}
  31.         ThingDefs:PThingDefArray;
  32.  
  33. Procedure InitThingDefs;
  34. Function GetThingDefFromID(ThingID:word):word;
  35. Function CrossRefThingDef(ThingID:word;WDir:PWadDirectory):word;
  36. Function GetThingNumViews(ThingID:word;WDir:PWadDirectory):word;
  37. Function GetThingDefFromSpriteName(SpriteName:ObjNameStr):word;
  38. Procedure DoneThingDefs;
  39.  
  40. implementation
  41.  
  42. var    IsInitialized:boolean;
  43.  
  44. Procedure InitThingDefs;
  45.  
  46.     var    f:file;
  47.  
  48.     begin
  49.         assign(f,'thing.def');
  50.         reset(f,1);
  51.         TotalThingDefs:=FileSize(f) div SizeOf(TThingDef);
  52.         if TotalThingDefs > MaxThingDefs then
  53.             TotalThingDefs:=MaxThingDefs;
  54.         GetMem(ThingDefs,TotalThingDefs * SizeOf(TThingDef));
  55.         BlockRead(f,ThingDefs^[1],TotalThingDefs * SizeOf(TThingDef));
  56.         close(f);
  57.         IsInitialized:=True;
  58.     end;
  59.  
  60. Function GetThingDefFromID(ThingID:word):word;
  61.  
  62.     var    t:word;
  63.  
  64.     begin
  65.         for t:=1 to TotalThingDefs do begin
  66.             if ThingID=ThingDefs^[t].Num then begin
  67.                 GetThingDefFromID:=t;
  68.                 exit;
  69.             end;
  70.         end;
  71.         GetThingDefFromID:=0;
  72.     end;
  73.  
  74. Function GetThingDefFromSpriteName(SpriteName:ObjNameStr):word;
  75.  
  76.     var    t:word;
  77.             TempName:array[1..4] of char;
  78.  
  79.     begin
  80.         for t:=1 to 4 do
  81.             TempName[t]:=UpCase(SpriteName[t]);
  82.         for t:=1 to TotalThingDefs do begin
  83.             if SpriteName=ThingDefs^[t].PictID then begin
  84.                 GetThingDefFromSpriteName:=t;
  85.                 exit;
  86.             end;
  87.         end;
  88.         GetThingDefFromSpriteName:=0;
  89.     end;
  90.  
  91. Function CrossRefThingDef(ThingID:word;WDir:PWadDirectory):word;
  92.  
  93.     var     ThingDefNum:word;
  94.             SpriteStart:word;
  95.             SpriteEnd:word;
  96.             t:integer;
  97.             SpriteName:array[1..4] of char;
  98.  
  99.     begin
  100.         CrossRefThingDef:=0;
  101.         ThingDefNum:=GetThingDefFromID(ThingID);
  102.         if ThingDefNum=0 then
  103.             exit;
  104.         SpriteStart:=WDir^.FindObject('S_START ');
  105.         if SpriteStart=0 then
  106.             exit;
  107.         SpriteEnd:=WDir^.FindObject('S_END   ');
  108.         if SpriteEnd=0 then
  109.             SpriteEnd:=WDir^.DirEntries;
  110.         for t:=(SpriteStart + 1) to (SpriteEnd - 1) do begin
  111.             Move(WDir^.DirEntry^[t].ObjName[1],SpriteName[1],4);
  112.             if SpriteName=ThingDefs^[ThingDefNum].PictID then begin
  113.                 CrossRefThingDef:=t;
  114.                 exit
  115.             end;
  116.         end;
  117.     end;
  118.  
  119. Function GetThingNumViews(ThingID:word;WDir:PWadDirectory):word;
  120.  
  121.     var   SpriteName:Array[1..4] of char;
  122.             ThingDefNum:word;
  123.             ThingViewStart:word;
  124.             SpriteEnd:word;
  125.             NumViews:word;
  126.             t:word;
  127.  
  128.     begin
  129.         NumViews:=0;
  130.         GetThingNumViews:=0;
  131.         ThingDefNum:=GetThingDefFromID(ThingID);
  132.         if ThingDefNum=0 then
  133.             exit;
  134.         ThingViewStart:=CrossRefThingDef(ThingID,WDir);
  135.         if ThingViewStart=0 then
  136.             exit;
  137.         SpriteEnd:=WDir^.FindObject('S_END   ');
  138.         if SpriteEnd=0 then
  139.             SpriteEnd:=WDir^.DirEntries;
  140.         for t:=(ThingViewStart) to (SpriteEnd - 1) do begin
  141.             Move(WDir^.DirEntry^[t].ObjName[1],SpriteName[1],4);
  142.             if SpriteName=ThingDefs^[ThingDefNum].PictID then
  143.                 Inc(NumViews);
  144.         end;
  145.         GetThingNumViews:=NumViews;
  146.     end;
  147.  
  148. Procedure DoneThingDefs;
  149.  
  150.     begin
  151.         FreeMem(ThingDefs,TotalThingDefs * SizeOf(TThingDef));
  152.         IsInitialized:=False;
  153.     end;
  154.  
  155. begin
  156.     IsInitialized:=False;
  157. end.