home *** CD-ROM | disk | FTP | other *** search
/ 1,001 Nights of Doom / 1001NightsOfDoom1995wickedSensations.iso / nodebild / idbsp10.zip / WAD_DWD.C < prev    next >
C/C++ Source or Header  |  1994-06-04  |  4KB  |  174 lines

  1. /*
  2.     WAD_DWD.C - version 1.0 (06/03/94)
  3.     (c) 1994 Ron Rossbach (ej070@cleveland.freenet.edu)
  4.  
  5.     This program converts an ordinary WAD file into a slightly extended version
  6.     of a DWD file.  The DWD file can then be used as input to IDBSP
  7.  
  8.     Use and distribution of this code permitted according to the terms of the GNU
  9.     General Public License.
  10. */
  11.  
  12. #include "wad_dwd.h"
  13.  
  14. /*
  15. ===============
  16. =
  17. = main
  18. =
  19. ===============
  20. */
  21. int main(int argc, char *argv[])
  22. {
  23.     char dwd_name[81];
  24.     char wad_name[81];
  25.     char tmp[9];
  26.     FILE *dwd,*wad;
  27.     int i;
  28.     long numthings, numvertexes, numlines, numsides, numsectors;
  29.     int episode, level;
  30.     mapvertex_t *vertexes = NULL;
  31.     mapsidedef_t *sidedefs = NULL;
  32.     maplinedef_t *linedefs = NULL;
  33.     mapsector_t *sectors = NULL;
  34.     mapthing_t *things = NULL;
  35.     lumpinfo_t *lumps = NULL;
  36.     wadinfo_t wadheader;
  37.  
  38.     printf("** WAD_DWD - a WAD->DWD converter for DOOM - version 1.0 **"
  39.     "\n(c) 1994 Ron Rossbach (ej070@cleveland.freenet.edu)"
  40.     "\n\nDOOM is a registered trademark of id Software, Inc."
  41.     "\n\nSee the accompanying README for terms of use, distribution, etc.");
  42.  
  43.     if (argc < 2 || argc > 3)
  44.         {
  45.         printf("\n\nUsage: \"wad_dwd wadfile [dwdfile]\""
  46.                      "\nTMP.DWD is the default if dwdfile is not specified.");
  47.         Error("\nExiting....");
  48.         }
  49.  
  50.     strcpy(wad_name,argv[1]);
  51.  
  52.     if (argc == 3)
  53.         strcpy(dwd_name, argv[2]);
  54.     else
  55.         strcpy(dwd_name,"tmp.dwd");
  56.  
  57.     if ((wad = fopen(wad_name,"rb"))==NULL)
  58.         Error("Cannot open WAD file");
  59.  
  60.     if ((dwd = fopen(dwd_name,"w"))==NULL)
  61.         {
  62.         fclose(wad);
  63.         Error("Cannot open DWD file");
  64.         }
  65.  
  66.     /*
  67.         Read the WAD header
  68.     */
  69.     fread(&wadheader,sizeof(wadinfo_t),1,wad);
  70.     fseek(wad, wadheader.infotableofs, SEEK_SET);
  71.  
  72.     printf("\n\nWAD file: %s\nDWD file: %s\n",wad_name,dwd_name);
  73.  
  74.     /*
  75.         Read the WAD directory
  76.     */
  77.     lumps = ReadWAD(wad, wadheader.numlumps, sizeof(lumpinfo_t));
  78.  
  79.     /*
  80.         Process directory entries
  81.     */
  82.     WriteHeader(dwd);
  83.     for (i=0; i<wadheader.numlumps; i++)
  84.         {
  85.         strncpy(tmp, lumps[i].name, 8);
  86.         tmp[8] = '\0';
  87.  
  88.                     /* Handle map levels */
  89.         if (sscanf(tmp,"E%dM%d",&episode,&level) == 2)
  90.             {
  91.             printf("\nWriting Level: %s",tmp);
  92.             things = (mapthing_t *)ReadStorage(wad, &lumps[++i], &numthings, sizeof(mapthing_t));
  93.             linedefs = (maplinedef_t *)ReadStorage(wad, &lumps[++i], &numlines, sizeof(maplinedef_t));
  94.             sidedefs = (mapsidedef_t *)ReadStorage(wad, &lumps[++i], &numsides, sizeof(mapsidedef_t));
  95.             vertexes = (mapvertex_t *)ReadStorage(wad, &lumps[++i], &numvertexes, sizeof(mapvertex_t));
  96.             i += 4;
  97.             sectors = (mapsector_t *)ReadStorage(wad, &lumps[i], &numsectors, sizeof(mapsector_t));
  98.             i += 2;
  99.             fprintf(dwd,"\nlevel:E%dM%d\n",episode,level);
  100.             WriteLines(dwd, numlines, linedefs, vertexes, sidedefs, sectors);
  101.             WriteThings(dwd, numthings, things);
  102.             free(vertexes);
  103.             free(sidedefs);
  104.             free(linedefs);
  105.             free(sectors);
  106.             }
  107.                     /* Other Resources */
  108.         else
  109.             {
  110.             printf("\nWriting Resource: %s",tmp);
  111.             fprintf(dwd, "\n%s :%d\n", tmp, lumps[i].size);
  112.             ExtractResource(wad, &lumps[i]);
  113.             }
  114.         }
  115.  
  116.     free(lumps);
  117.     fclose(wad);
  118.     fclose(dwd);
  119.  
  120.     return 0;
  121. }
  122.  
  123. /*
  124. ===============
  125. =
  126. = progress
  127. =
  128. = provides some visual feedback for the user....
  129. =
  130. ===============
  131. */
  132. void progress(void)
  133. {
  134.     char *s="/-\\|/-\\|";
  135.     static unsigned char pcnt=0;
  136.  
  137.     if((pcnt&15) == 0)
  138.         {
  139.         printf("%c\b",s[((pcnt)/16)&7]);
  140.         fflush(stdout);
  141.         }
  142.     pcnt++;
  143. }
  144.  
  145. /*
  146. ====================
  147. =
  148. = Error
  149. =
  150. = Displays an error message and exits program
  151. =
  152. ====================
  153. */
  154. void Error (char *error, ...)
  155. {
  156.     va_list argptr;
  157.     va_start (argptr,error);
  158.     vprintf (error,argptr);
  159.     va_end (argptr);
  160.     printf ("\n");
  161.     exit (1);
  162. }
  163.  
  164.  
  165. void *SafeCalloc(unsigned num, size_t size)
  166. {
  167.     void *ret = (void *)calloc(num,size);
  168.     if (!ret)
  169.         Error("\nSafeCalloc: Failed to allocate %u of %u bytes",num,size);
  170.  
  171.     return ret;
  172. }
  173.  
  174.