home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / games / doom / source / linuxdoom-1.10 / d_main.c < prev    next >
C/C++ Source or Header  |  1997-12-22  |  26KB  |  1,172 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    DOOM main program (D_DoomMain) and game loop (D_DoomLoop),
  21. //    plus functions to determine game mode (shareware, registered),
  22. //    parse command line parameters, configure game parameters (turbo),
  23. //    and call the startup functions.
  24. //
  25. //-----------------------------------------------------------------------------
  26.  
  27.  
  28. static const char rcsid[] = "$Id: d_main.c,v 1.8 1997/02/03 22:45:09 b1 Exp $";
  29.  
  30. #define    BGCOLOR        7
  31. #define    FGCOLOR        8
  32.  
  33.  
  34. #ifdef NORMALUNIX
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <unistd.h>
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <fcntl.h>
  41. #endif
  42.  
  43.  
  44. #include "doomdef.h"
  45. #include "doomstat.h"
  46.  
  47. #include "dstrings.h"
  48. #include "sounds.h"
  49.  
  50.  
  51. #include "z_zone.h"
  52. #include "w_wad.h"
  53. #include "s_sound.h"
  54. #include "v_video.h"
  55.  
  56. #include "f_finale.h"
  57. #include "f_wipe.h"
  58.  
  59. #include "m_argv.h"
  60. #include "m_misc.h"
  61. #include "m_menu.h"
  62.  
  63. #include "i_system.h"
  64. #include "i_sound.h"
  65. #include "i_video.h"
  66.  
  67. #include "g_game.h"
  68.  
  69. #include "hu_stuff.h"
  70. #include "wi_stuff.h"
  71. #include "st_stuff.h"
  72. #include "am_map.h"
  73.  
  74. #include "p_setup.h"
  75. #include "r_local.h"
  76.  
  77.  
  78. #include "d_main.h"
  79.  
  80. //
  81. // D-DoomLoop()
  82. // Not a globally visible function,
  83. //  just included for source reference,
  84. //  called by D_DoomMain, never exits.
  85. // Manages timing and IO,
  86. //  calls all ?_Responder, ?_Ticker, and ?_Drawer,
  87. //  calls I_GetTime, I_StartFrame, and I_StartTic
  88. //
  89. void D_DoomLoop (void);
  90.  
  91.  
  92. char*        wadfiles[MAXWADFILES];
  93.  
  94.  
  95. boolean        devparm;    // started game with -devparm
  96. boolean         nomonsters;    // checkparm of -nomonsters
  97. boolean         respawnparm;    // checkparm of -respawn
  98. boolean         fastparm;    // checkparm of -fast
  99.  
  100. boolean         drone;
  101.  
  102. boolean        singletics = false; // debug flag to cancel adaptiveness
  103.  
  104.  
  105.  
  106. //extern int soundVolume;
  107. //extern  int    sfxVolume;
  108. //extern  int    musicVolume;
  109.  
  110. extern  boolean    inhelpscreens;
  111.  
  112. skill_t        startskill;
  113. int             startepisode;
  114. int        startmap;
  115. boolean        autostart;
  116.  
  117. FILE*        debugfile;
  118.  
  119. boolean        advancedemo;
  120.  
  121.  
  122.  
  123.  
  124. char        wadfile[1024];        // primary wad file
  125. char        mapdir[1024];           // directory of development maps
  126. char        basedefault[1024];      // default file
  127.  
  128.  
  129. void D_CheckNetGame (void);
  130. void D_ProcessEvents (void);
  131. void G_BuildTiccmd (ticcmd_t* cmd);
  132. void D_DoAdvanceDemo (void);
  133.  
  134.  
  135. //
  136. // EVENT HANDLING
  137. //
  138. // Events are asynchronous inputs generally generated by the game user.
  139. // Events can be discarded if no responder claims them
  140. //
  141. event_t         events[MAXEVENTS];
  142. int             eventhead;
  143. int         eventtail;
  144.  
  145.  
  146. //
  147. // D_PostEvent
  148. // Called by the I/O functions when input is detected
  149. //
  150. void D_PostEvent (event_t* ev)
  151. {
  152.     events[eventhead] = *ev;
  153.     eventhead = (++eventhead)&(MAXEVENTS-1);
  154. }
  155.  
  156.  
  157. //
  158. // D_ProcessEvents
  159. // Send all the events of the given timestamp down the responder chain
  160. //
  161. void D_ProcessEvents (void)
  162. {
  163.     event_t*    ev;
  164.     
  165.     // IF STORE DEMO, DO NOT ACCEPT INPUT
  166.     if ( ( gamemode == commercial )
  167.      && (W_CheckNumForName("map01")<0) )
  168.       return;
  169.     
  170.     for ( ; eventtail != eventhead ; eventtail = (++eventtail)&(MAXEVENTS-1) )
  171.     {
  172.     ev = &events[eventtail];
  173.     if (M_Responder (ev))
  174.         continue;               // menu ate the event
  175.     G_Responder (ev);
  176.     }
  177. }
  178.  
  179.  
  180.  
  181.  
  182. //
  183. // D_Display
  184. //  draw current display, possibly wiping it from the previous
  185. //
  186.  
  187. // wipegamestate can be set to -1 to force a wipe on the next draw
  188. gamestate_t     wipegamestate = GS_DEMOSCREEN;
  189. extern  boolean setsizeneeded;
  190. extern  int             showMessages;
  191. void R_ExecuteSetViewSize (void);
  192.  
  193. void D_Display (void)
  194. {
  195.     static  boolean        viewactivestate = false;
  196.     static  boolean        menuactivestate = false;
  197.     static  boolean        inhelpscreensstate = false;
  198.     static  boolean        fullscreen = false;
  199.     static  gamestate_t        oldgamestate = -1;
  200.     static  int            borderdrawcount;
  201.     int                nowtime;
  202.     int                tics;
  203.     int                wipestart;
  204.     int                y;
  205.     boolean            done;
  206.     boolean            wipe;
  207.     boolean            redrawsbar;
  208.  
  209.     if (nodrawers)
  210.     return;                    // for comparative timing / profiling
  211.         
  212.     redrawsbar = false;
  213.     
  214.     // change the view size if needed
  215.     if (setsizeneeded)
  216.     {
  217.     R_ExecuteSetViewSize ();
  218.     oldgamestate = -1;                      // force background redraw
  219.     borderdrawcount = 3;
  220.     }
  221.  
  222.     // save the current screen if about to wipe
  223.     if (gamestate != wipegamestate)
  224.     {
  225.     wipe = true;
  226.     wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
  227.     }
  228.     else
  229.     wipe = false;
  230.  
  231.     if (gamestate == GS_LEVEL && gametic)
  232.     HU_Erase();
  233.     
  234.     // do buffered drawing
  235.     switch (gamestate)
  236.     {
  237.       case GS_LEVEL:
  238.     if (!gametic)
  239.         break;
  240.     if (automapactive)
  241.         AM_Drawer ();
  242.     if (wipe || (viewheight != 200 && fullscreen) )
  243.         redrawsbar = true;
  244.     if (inhelpscreensstate && !inhelpscreens)
  245.         redrawsbar = true;              // just put away the help screen
  246.     ST_Drawer (viewheight == 200, redrawsbar );
  247.     fullscreen = viewheight == 200;
  248.     break;
  249.  
  250.       case GS_INTERMISSION:
  251.     WI_Drawer ();
  252.     break;
  253.  
  254.       case GS_FINALE:
  255.     F_Drawer ();
  256.     break;
  257.  
  258.       case GS_DEMOSCREEN:
  259.     D_PageDrawer ();
  260.     break;
  261.     }
  262.     
  263.     // draw buffered stuff to screen
  264.     I_UpdateNoBlit ();
  265.     
  266.     // draw the view directly
  267.     if (gamestate == GS_LEVEL && !automapactive && gametic)
  268.     R_RenderPlayerView (&players[displayplayer]);
  269.  
  270.     if (gamestate == GS_LEVEL && gametic)
  271.     HU_Drawer ();
  272.     
  273.     // clean up border stuff
  274.     if (gamestate != oldgamestate && gamestate != GS_LEVEL)
  275.     I_SetPalette (W_CacheLumpName ("PLAYPAL",PU_CACHE));
  276.  
  277.     // see if the border needs to be initially drawn
  278.     if (gamestate == GS_LEVEL && oldgamestate != GS_LEVEL)
  279.     {
  280.     viewactivestate = false;        // view was not active
  281.     R_FillBackScreen ();    // draw the pattern into the back screen
  282.     }
  283.  
  284.     // see if the border needs to be updated to the screen
  285.     if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320)
  286.     {
  287.     if (menuactive || menuactivestate || !viewactivestate)
  288.         borderdrawcount = 3;
  289.     if (borderdrawcount)
  290.     {
  291.         R_DrawViewBorder ();    // erase old menu stuff
  292.         borderdrawcount--;
  293.     }
  294.  
  295.     }
  296.  
  297.     menuactivestate = menuactive;
  298.     viewactivestate = viewactive;
  299.     inhelpscreensstate = inhelpscreens;
  300.     oldgamestate = wipegamestate = gamestate;
  301.     
  302.     // draw pause pic
  303.     if (paused)
  304.     {
  305.     if (automapactive)
  306.         y = 4;
  307.     else
  308.         y = viewwindowy+4;
  309.     V_DrawPatchDirect(viewwindowx+(scaledviewwidth-68)/2,
  310.               y,0,W_CacheLumpName ("M_PAUSE", PU_CACHE));
  311.     }
  312.  
  313.  
  314.     // menus go directly to the screen
  315.     M_Drawer ();          // menu is drawn even on top of everything
  316.     NetUpdate ();         // send out any new accumulation
  317.  
  318.  
  319.     // normal update
  320.     if (!wipe)
  321.     {
  322.     I_FinishUpdate ();              // page flip or blit buffer
  323.     return;
  324.     }
  325.     
  326.     // wipe update
  327.     wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
  328.  
  329.     wipestart = I_GetTime () - 1;
  330.  
  331.     do
  332.     {
  333.     do
  334.     {
  335.         nowtime = I_GetTime ();
  336.         tics = nowtime - wipestart;
  337.     } while (!tics);
  338.     wipestart = nowtime;
  339.     done = wipe_ScreenWipe(wipe_Melt
  340.                    , 0, 0, SCREENWIDTH, SCREENHEIGHT, tics);
  341.     I_UpdateNoBlit ();
  342.     M_Drawer ();                            // menu is drawn even on top of wipes
  343.     I_FinishUpdate ();                      // page flip or blit buffer
  344.     } while (!done);
  345. }
  346.  
  347.  
  348.  
  349. //
  350. //  D_DoomLoop
  351. //
  352. extern  boolean         demorecording;
  353.  
  354. void D_DoomLoop (void)
  355. {
  356.     if (demorecording)
  357.     G_BeginRecording ();
  358.         
  359.     if (M_CheckParm ("-debugfile"))
  360.     {
  361.     char    filename[20];
  362.     sprintf (filename,"debug%i.txt",consoleplayer);
  363.     printf ("debug output to: %s\n",filename);
  364.     debugfile = fopen (filename,"w");
  365.     }
  366.     
  367.     I_InitGraphics ();
  368.  
  369.     while (1)
  370.     {
  371.     // frame syncronous IO operations
  372.     I_StartFrame ();                
  373.     
  374.     // process one or more tics
  375.     if (singletics)
  376.     {
  377.         I_StartTic ();
  378.         D_ProcessEvents ();
  379.         G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
  380.         if (advancedemo)
  381.         D_DoAdvanceDemo ();
  382.         M_Ticker ();
  383.         G_Ticker ();
  384.         gametic++;
  385.         maketic++;
  386.     }
  387.     else
  388.     {
  389.         TryRunTics (); // will run at least one tic
  390.     }
  391.         
  392.     S_UpdateSounds (players[consoleplayer].mo);// move positional sounds
  393.  
  394.     // Update display, next frame, with current state.
  395.     D_Display ();
  396.  
  397. #ifndef SNDSERV
  398.     // Sound mixing for the buffer is snychronous.
  399.     I_UpdateSound();
  400. #endif    
  401.     // Synchronous sound output is explicitly called.
  402. #ifndef SNDINTR
  403.     // Update sound output.
  404.     I_SubmitSound();
  405. #endif
  406.     }
  407. }
  408.  
  409.  
  410.  
  411. //
  412. //  DEMO LOOP
  413. //
  414. int             demosequence;
  415. int             pagetic;
  416. char                    *pagename;
  417.  
  418.  
  419. //
  420. // D_PageTicker
  421. // Handles timing for warped projection
  422. //
  423. void D_PageTicker (void)
  424. {
  425.     if (--pagetic < 0)
  426.     D_AdvanceDemo ();
  427. }
  428.  
  429.  
  430.  
  431. //
  432. // D_PageDrawer
  433. //
  434. void D_PageDrawer (void)
  435. {
  436.     V_DrawPatch (0,0, 0, W_CacheLumpName(pagename, PU_CACHE));
  437. }
  438.  
  439.  
  440. //
  441. // D_AdvanceDemo
  442. // Called after each demo or intro demosequence finishes
  443. //
  444. void D_AdvanceDemo (void)
  445. {
  446.     advancedemo = true;
  447. }
  448.  
  449.  
  450. //
  451. // This cycles through the demo sequences.
  452. // FIXME - version dependend demo numbers?
  453. //
  454.  void D_DoAdvanceDemo (void)
  455. {
  456.     players[consoleplayer].playerstate = PST_LIVE;  // not reborn
  457.     advancedemo = false;
  458.     usergame = false;               // no save / end game here
  459.     paused = false;
  460.     gameaction = ga_nothing;
  461.  
  462.     if ( gamemode == retail )
  463.       demosequence = (demosequence+1)%7;
  464.     else
  465.       demosequence = (demosequence+1)%6;
  466.     
  467.     switch (demosequence)
  468.     {
  469.       case 0:
  470.     if ( gamemode == commercial )
  471.         pagetic = 35 * 11;
  472.     else
  473.         pagetic = 170;
  474.     gamestate = GS_DEMOSCREEN;
  475.     pagename = "TITLEPIC";
  476.     if ( gamemode == commercial )
  477.       S_StartMusic(mus_dm2ttl);
  478.     else
  479.       S_StartMusic (mus_intro);
  480.     break;
  481.       case 1:
  482.     G_DeferedPlayDemo ("demo1");
  483.     break;
  484.       case 2:
  485.     pagetic = 200;
  486.     gamestate = GS_DEMOSCREEN;
  487.     pagename = "CREDIT";
  488.     break;
  489.       case 3:
  490.     G_DeferedPlayDemo ("demo2");
  491.     break;
  492.       case 4:
  493.     gamestate = GS_DEMOSCREEN;
  494.     if ( gamemode == commercial)
  495.     {
  496.         pagetic = 35 * 11;
  497.         pagename = "TITLEPIC";
  498.         S_StartMusic(mus_dm2ttl);
  499.     }
  500.     else
  501.     {
  502.         pagetic = 200;
  503.  
  504.         if ( gamemode == retail )
  505.           pagename = "CREDIT";
  506.         else
  507.           pagename = "HELP2";
  508.     }
  509.     break;
  510.       case 5:
  511.     G_DeferedPlayDemo ("demo3");
  512.     break;
  513.         // THE DEFINITIVE DOOM Special Edition demo
  514.       case 6:
  515.     G_DeferedPlayDemo ("demo4");
  516.     break;
  517.     }
  518. }
  519.  
  520.  
  521.  
  522. //
  523. // D_StartTitle
  524. //
  525. void D_StartTitle (void)
  526. {
  527.     gameaction = ga_nothing;
  528.     demosequence = -1;
  529.     D_AdvanceDemo ();
  530. }
  531.  
  532.  
  533.  
  534.  
  535. //      print title for every printed line
  536. char            title[128];
  537.  
  538.  
  539.  
  540. //
  541. // D_AddFile
  542. //
  543. void D_AddFile (char *file)
  544. {
  545.     int     numwadfiles;
  546.     char    *newfile;
  547.     
  548.     for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++)
  549.     ;
  550.  
  551.     newfile = malloc (strlen(file)+1);
  552.     strcpy (newfile, file);
  553.     
  554.     wadfiles[numwadfiles] = newfile;
  555. }
  556.  
  557. //
  558. // IdentifyVersion
  559. // Checks availability of IWAD files by name,
  560. // to determine whether registered/commercial features
  561. // should be executed (notably loading PWAD's).
  562. //
  563. void IdentifyVersion (void)
  564. {
  565.  
  566.     char*    doom1wad;
  567.     char*    doomwad;
  568.     char*    doomuwad;
  569.     char*    doom2wad;
  570.  
  571.     char*    doom2fwad;
  572.     char*    plutoniawad;
  573.     char*    tntwad;
  574.  
  575. #ifdef NORMALUNIX
  576.     char *home;
  577.     char *doomwaddir;
  578.     doomwaddir = getenv("DOOMWADDIR");
  579.     if (!doomwaddir)
  580.     doomwaddir = ".";
  581.  
  582.     // Commercial.
  583.     doom2wad = malloc(strlen(doomwaddir)+1+9+1);
  584.     sprintf(doom2wad, "%s/doom2.wad", doomwaddir);
  585.  
  586.     // Retail.
  587.     doomuwad = malloc(strlen(doomwaddir)+1+8+1);
  588.     sprintf(doomuwad, "%s/doomu.wad", doomwaddir);
  589.     
  590.     // Registered.
  591.     doomwad = malloc(strlen(doomwaddir)+1+8+1);
  592.     sprintf(doomwad, "%s/doom.wad", doomwaddir);
  593.     
  594.     // Shareware.
  595.     doom1wad = malloc(strlen(doomwaddir)+1+9+1);
  596.     sprintf(doom1wad, "%s/doom1.wad", doomwaddir);
  597.  
  598.      // Bug, dear Shawn.
  599.     // Insufficient malloc, caused spurious realloc errors.
  600.     plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1);
  601.     sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir);
  602.  
  603.     tntwad = malloc(strlen(doomwaddir)+1+9+1);
  604.     sprintf(tntwad, "%s/tnt.wad", doomwaddir);
  605.  
  606.  
  607.     // French stuff.
  608.     doom2fwad = malloc(strlen(doomwaddir)+1+10+1);
  609.     sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir);
  610.  
  611.     home = getenv("HOME");
  612.     if (!home)
  613.       I_Error("Please set $HOME to your home directory");
  614.     sprintf(basedefault, "%s/.doomrc", home);
  615. #endif
  616.  
  617.     if (M_CheckParm ("-shdev"))
  618.     {
  619.     gamemode = shareware;
  620.     devparm = true;
  621.     D_AddFile (DEVDATA"doom1.wad");
  622.     D_AddFile (DEVMAPS"data_se/texture1.lmp");
  623.     D_AddFile (DEVMAPS"data_se/pnames.lmp");
  624.     strcpy (basedefault,DEVDATA"default.cfg");
  625.     return;
  626.     }
  627.  
  628.     if (M_CheckParm ("-regdev"))
  629.     {
  630.     gamemode = registered;
  631.     devparm = true;
  632.     D_AddFile (DEVDATA"doom.wad");
  633.     D_AddFile (DEVMAPS"data_se/texture1.lmp");
  634.     D_AddFile (DEVMAPS"data_se/texture2.lmp");
  635.     D_AddFile (DEVMAPS"data_se/pnames.lmp");
  636.     strcpy (basedefault,DEVDATA"default.cfg");
  637.     return;
  638.     }
  639.  
  640.     if (M_CheckParm ("-comdev"))
  641.     {
  642.     gamemode = commercial;
  643.     devparm = true;
  644.     /* I don't bother
  645.     if(plutonia)
  646.         D_AddFile (DEVDATA"plutonia.wad");
  647.     else if(tnt)
  648.         D_AddFile (DEVDATA"tnt.wad");
  649.     else*/
  650.         D_AddFile (DEVDATA"doom2.wad");
  651.         
  652.     D_AddFile (DEVMAPS"cdata/texture1.lmp");
  653.     D_AddFile (DEVMAPS"cdata/pnames.lmp");
  654.     strcpy (basedefault,DEVDATA"default.cfg");
  655.     return;
  656.     }
  657.  
  658.     if ( !access (doom2fwad,R_OK) )
  659.     {
  660.     gamemode = commercial;
  661.     // C'est ridicule!
  662.     // Let's handle languages in config files, okay?
  663.     language = french;
  664.     printf("French version\n");
  665.     D_AddFile (doom2fwad);
  666.     return;
  667.     }
  668.  
  669.     if ( !access (doom2wad,R_OK) )
  670.     {
  671.     gamemode = commercial;
  672.     D_AddFile (doom2wad);
  673.     return;
  674.     }
  675.  
  676.     if ( !access (plutoniawad, R_OK ) )
  677.     {
  678.       gamemode = commercial;
  679.       D_AddFile (plutoniawad);
  680.       return;
  681.     }
  682.  
  683.     if ( !access ( tntwad, R_OK ) )
  684.     {
  685.       gamemode = commercial;
  686.       D_AddFile (tntwad);
  687.       return;
  688.     }
  689.  
  690.     if ( !access (doomuwad,R_OK) )
  691.     {
  692.       gamemode = retail;
  693.       D_AddFile (doomuwad);
  694.       return;
  695.     }
  696.  
  697.     if ( !access (doomwad,R_OK) )
  698.     {
  699.       gamemode = registered;
  700.       D_AddFile (doomwad);
  701.       return;
  702.     }
  703.  
  704.     if ( !access (doom1wad,R_OK) )
  705.     {
  706.       gamemode = shareware;
  707.       D_AddFile (doom1wad);
  708.       return;
  709.     }
  710.  
  711.     printf("Game mode indeterminate.\n");
  712.     gamemode = indetermined;
  713.  
  714.     // We don't abort. Let's see what the PWAD contains.
  715.     //exit(1);
  716.     //I_Error ("Game mode indeterminate\n");
  717. }
  718.  
  719. //
  720. // Find a Response File
  721. //
  722. void FindResponseFile (void)
  723. {
  724.     int             i;
  725. #define MAXARGVS        100
  726.     
  727.     for (i = 1;i < myargc;i++)
  728.     if (myargv[i][0] == '@')
  729.     {
  730.         FILE *          handle;
  731.         int             size;
  732.         int             k;
  733.         int             index;
  734.         int             indexinfile;
  735.         char    *infile;
  736.         char    *file;
  737.         char    *moreargs[20];
  738.         char    *firstargv;
  739.             
  740.         // READ THE RESPONSE FILE INTO MEMORY
  741.         handle = fopen (&myargv[i][1],"rb");
  742.         if (!handle)
  743.         {
  744.         printf ("\nNo such response file!");
  745.         exit(1);
  746.         }
  747.         printf("Found response file %s!\n",&myargv[i][1]);
  748.         fseek (handle,0,SEEK_END);
  749.         size = ftell(handle);
  750.         fseek (handle,0,SEEK_SET);
  751.         file = malloc (size);
  752.         fread (file,size,1,handle);
  753.         fclose (handle);
  754.             
  755.         // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
  756.         for (index = 0,k = i+1; k < myargc; k++)
  757.         moreargs[index++] = myargv[k];
  758.             
  759.         firstargv = myargv[0];
  760.         myargv = malloc(sizeof(char *)*MAXARGVS);
  761.         memset(myargv,0,sizeof(char *)*MAXARGVS);
  762.         myargv[0] = firstargv;
  763.             
  764.         infile = file;
  765.         indexinfile = k = 0;
  766.         indexinfile++;  // SKIP PAST ARGV[0] (KEEP IT)
  767.         do
  768.         {
  769.         myargv[indexinfile++] = infile+k;
  770.         while(k < size &&
  771.               ((*(infile+k)>= ' '+1) && (*(infile+k)<='z')))
  772.             k++;
  773.         *(infile+k) = 0;
  774.         while(k < size &&
  775.               ((*(infile+k)<= ' ') || (*(infile+k)>'z')))
  776.             k++;
  777.         } while(k < size);
  778.             
  779.         for (k = 0;k < index;k++)
  780.         myargv[indexinfile++] = moreargs[k];
  781.         myargc = indexinfile;
  782.     
  783.         // DISPLAY ARGS
  784.         printf("%d command-line args:\n",myargc);
  785.         for (k=1;k<myargc;k++)
  786.         printf("%s\n",myargv[k]);
  787.  
  788.         break;
  789.     }
  790. }
  791.  
  792.  
  793. //
  794. // D_DoomMain
  795. //
  796. void D_DoomMain (void)
  797. {
  798.     int             p;
  799.     char                    file[256];
  800.  
  801.     FindResponseFile ();
  802.     
  803.     IdentifyVersion ();
  804.     
  805.     setbuf (stdout, NULL);
  806.     modifiedgame = false;
  807.     
  808.     nomonsters = M_CheckParm ("-nomonsters");
  809.     respawnparm = M_CheckParm ("-respawn");
  810.     fastparm = M_CheckParm ("-fast");
  811.     devparm = M_CheckParm ("-devparm");
  812.     if (M_CheckParm ("-altdeath"))
  813.     deathmatch = 2;
  814.     else if (M_CheckParm ("-deathmatch"))
  815.     deathmatch = 1;
  816.  
  817.     switch ( gamemode )
  818.     {
  819.       case retail:
  820.     sprintf (title,
  821.          "                         "
  822.          "The Ultimate DOOM Startup v%i.%i"
  823.          "                           ",
  824.          VERSION/100,VERSION%100);
  825.     break;
  826.       case shareware:
  827.     sprintf (title,
  828.          "                            "
  829.          "DOOM Shareware Startup v%i.%i"
  830.          "                           ",
  831.          VERSION/100,VERSION%100);
  832.     break;
  833.       case registered:
  834.     sprintf (title,
  835.          "                            "
  836.          "DOOM Registered Startup v%i.%i"
  837.          "                           ",
  838.          VERSION/100,VERSION%100);
  839.     break;
  840.       case commercial:
  841.     sprintf (title,
  842.          "                         "
  843.          "DOOM 2: Hell on Earth v%i.%i"
  844.          "                           ",
  845.          VERSION/100,VERSION%100);
  846.     break;
  847. /*FIXME
  848.        case pack_plut:
  849.     sprintf (title,
  850.          "                   "
  851.          "DOOM 2: Plutonia Experiment v%i.%i"
  852.          "                           ",
  853.          VERSION/100,VERSION%100);
  854.     break;
  855.       case pack_tnt:
  856.     sprintf (title,
  857.          "                     "
  858.          "DOOM 2: TNT - Evilution v%i.%i"
  859.          "                           ",
  860.          VERSION/100,VERSION%100);
  861.     break;
  862. */
  863.       default:
  864.     sprintf (title,
  865.          "                     "
  866.          "Public DOOM - v%i.%i"
  867.          "                           ",
  868.          VERSION/100,VERSION%100);
  869.     break;
  870.     }
  871.     
  872.     printf ("%s\n",title);
  873.  
  874.     if (devparm)
  875.     printf(D_DEVSTR);
  876.     
  877.     if (M_CheckParm("-cdrom"))
  878.     {
  879.     printf(D_CDROM);
  880.     mkdir("c:\\doomdata",0);
  881.     strcpy (basedefault,"c:/doomdata/default.cfg");
  882.     }    
  883.     
  884.     // turbo option
  885.     if ( (p=M_CheckParm ("-turbo")) )
  886.     {
  887.     int     scale = 200;
  888.     extern int forwardmove[2];
  889.     extern int sidemove[2];
  890.     
  891.     if (p<myargc-1)
  892.         scale = atoi (myargv[p+1]);
  893.     if (scale < 10)
  894.         scale = 10;
  895.     if (scale > 400)
  896.         scale = 400;
  897.     printf ("turbo scale: %i%%\n",scale);
  898.     forwardmove[0] = forwardmove[0]*scale/100;
  899.     forwardmove[1] = forwardmove[1]*scale/100;
  900.     sidemove[0] = sidemove[0]*scale/100;
  901.     sidemove[1] = sidemove[1]*scale/100;
  902.     }
  903.     
  904.     // add any files specified on the command line with -file wadfile
  905.     // to the wad list
  906.     //
  907.     // convenience hack to allow -wart e m to add a wad file
  908.     // prepend a tilde to the filename so wadfile will be reloadable
  909.     p = M_CheckParm ("-wart");
  910.     if (p)
  911.     {
  912.     myargv[p][4] = 'p';     // big hack, change to -warp
  913.  
  914.     // Map name handling.
  915.     switch (gamemode )
  916.     {
  917.       case shareware:
  918.       case retail:
  919.       case registered:
  920.         sprintf (file,"~"DEVMAPS"E%cM%c.wad",
  921.              myargv[p+1][0], myargv[p+2][0]);
  922.         printf("Warping to Episode %s, Map %s.\n",
  923.            myargv[p+1],myargv[p+2]);
  924.         break;
  925.         
  926.       case commercial:
  927.       default:
  928.         p = atoi (myargv[p+1]);
  929.         if (p<10)
  930.           sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p);
  931.         else
  932.           sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p);
  933.         break;
  934.     }
  935.     D_AddFile (file);
  936.     }
  937.     
  938.     p = M_CheckParm ("-file");
  939.     if (p)
  940.     {
  941.     // the parms after p are wadfile/lump names,
  942.     // until end of parms or another - preceded parm
  943.     modifiedgame = true;            // homebrew levels
  944.     while (++p != myargc && myargv[p][0] != '-')
  945.         D_AddFile (myargv[p]);
  946.     }
  947.  
  948.     p = M_CheckParm ("-playdemo");
  949.  
  950.     if (!p)
  951.     p = M_CheckParm ("-timedemo");
  952.  
  953.     if (p && p < myargc-1)
  954.     {
  955.     sprintf (file,"%s.lmp", myargv[p+1]);
  956.     D_AddFile (file);
  957.     printf("Playing demo %s.lmp.\n",myargv[p+1]);
  958.     }
  959.     
  960.     // get skill / episode / map from parms
  961.     startskill = sk_medium;
  962.     startepisode = 1;
  963.     startmap = 1;
  964.     autostart = false;
  965.  
  966.         
  967.     p = M_CheckParm ("-skill");
  968.     if (p && p < myargc-1)
  969.     {
  970.     startskill = myargv[p+1][0]-'1';
  971.     autostart = true;
  972.     }
  973.  
  974.     p = M_CheckParm ("-episode");
  975.     if (p && p < myargc-1)
  976.     {
  977.     startepisode = myargv[p+1][0]-'0';
  978.     startmap = 1;
  979.     autostart = true;
  980.     }
  981.     
  982.     p = M_CheckParm ("-timer");
  983.     if (p && p < myargc-1 && deathmatch)
  984.     {
  985.     int     time;
  986.     time = atoi(myargv[p+1]);
  987.     printf("Levels will end after %d minute",time);
  988.     if (time>1)
  989.         printf("s");
  990.     printf(".\n");
  991.     }
  992.  
  993.     p = M_CheckParm ("-avg");
  994.     if (p && p < myargc-1 && deathmatch)
  995.     printf("Austin Virtual Gaming: Levels will end after 20 minutes\n");
  996.  
  997.     p = M_CheckParm ("-warp");
  998.     if (p && p < myargc-1)
  999.     {
  1000.     if (gamemode == commercial)
  1001.         startmap = atoi (myargv[p+1]);
  1002.     else
  1003.     {
  1004.         startepisode = myargv[p+1][0]-'0';
  1005.         startmap = myargv[p+2][0]-'0';
  1006.     }
  1007.     autostart = true;
  1008.     }
  1009.     
  1010.     // init subsystems
  1011.     printf ("V_Init: allocate screens.\n");
  1012.     V_Init ();
  1013.  
  1014.     printf ("M_LoadDefaults: Load system defaults.\n");
  1015.     M_LoadDefaults ();              // load before initing other systems
  1016.  
  1017.     printf ("Z_Init: Init zone memory allocation daemon. \n");
  1018.     Z_Init ();
  1019.  
  1020.     printf ("W_Init: Init WADfiles.\n");
  1021.     W_InitMultipleFiles (wadfiles);
  1022.     
  1023.  
  1024.     // Check for -file in shareware
  1025.     if (modifiedgame)
  1026.     {
  1027.     // These are the lumps that will be checked in IWAD,
  1028.     // if any one is not present, execution will be aborted.
  1029.     char name[23][8]=
  1030.     {
  1031.         "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
  1032.         "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",
  1033.         "dphoof","bfgga0","heada1","cybra1","spida1d1"
  1034.     };
  1035.     int i;
  1036.     
  1037.     if ( gamemode == shareware)
  1038.         I_Error("\nYou cannot -file with the shareware "
  1039.             "version. Register!");
  1040.  
  1041.     // Check for fake IWAD with right name,
  1042.     // but w/o all the lumps of the registered version. 
  1043.     if (gamemode == registered)
  1044.         for (i = 0;i < 23; i++)
  1045.         if (W_CheckNumForName(name[i])<0)
  1046.             I_Error("\nThis is not the registered version.");
  1047.     }
  1048.     
  1049.     // Iff additonal PWAD files are used, print modified banner
  1050.     if (modifiedgame)
  1051.     {
  1052.     /*m*/printf (
  1053.         "===========================================================================\n"
  1054.         "ATTENTION:  This version of DOOM has been modified.  If you would like to\n"
  1055.         "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n"
  1056.         "        You will not receive technical support for modified games.\n"
  1057.         "                      press enter to continue\n"
  1058.         "===========================================================================\n"
  1059.         );
  1060.     getchar ();
  1061.     }
  1062.     
  1063.  
  1064.     // Check and print which version is executed.
  1065.     switch ( gamemode )
  1066.     {
  1067.       case shareware:
  1068.       case indetermined:
  1069.     printf (
  1070.         "===========================================================================\n"
  1071.         "                                Shareware!\n"
  1072.         "===========================================================================\n"
  1073.     );
  1074.     break;
  1075.       case registered:
  1076.       case retail:
  1077.       case commercial:
  1078.     printf (
  1079.         "===========================================================================\n"
  1080.         "                 Commercial product - do not distribute!\n"
  1081.         "         Please report software piracy to the SPA: 1-800-388-PIR8\n"
  1082.         "===========================================================================\n"
  1083.     );
  1084.     break;
  1085.     
  1086.       default:
  1087.     // Ouch.
  1088.     break;
  1089.     }
  1090.  
  1091.     printf ("M_Init: Init miscellaneous info.\n");
  1092.     M_Init ();
  1093.  
  1094.     printf ("R_Init: Init DOOM refresh daemon - ");
  1095.     R_Init ();
  1096.  
  1097.     printf ("\nP_Init: Init Playloop state.\n");
  1098.     P_Init ();
  1099.  
  1100.     printf ("I_Init: Setting up machine state.\n");
  1101.     I_Init ();
  1102.  
  1103.     printf ("D_CheckNetGame: Checking network game status.\n");
  1104.     D_CheckNetGame ();
  1105.  
  1106.     printf ("S_Init: Setting up sound.\n");
  1107.     S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ );
  1108.  
  1109.     printf ("HU_Init: Setting up heads up display.\n");
  1110.     HU_Init ();
  1111.  
  1112.     printf ("ST_Init: Init status bar.\n");
  1113.     ST_Init ();
  1114.  
  1115.     // check for a driver that wants intermission stats
  1116.     p = M_CheckParm ("-statcopy");
  1117.     if (p && p<myargc-1)
  1118.     {
  1119.     // for statistics driver
  1120.     extern  void*    statcopy;                            
  1121.  
  1122.     statcopy = (void*)atoi(myargv[p+1]);
  1123.     printf ("External statistics registered.\n");
  1124.     }
  1125.     
  1126.     // start the apropriate game based on parms
  1127.     p = M_CheckParm ("-record");
  1128.  
  1129.     if (p && p < myargc-1)
  1130.     {
  1131.     G_RecordDemo (myargv[p+1]);
  1132.     autostart = true;
  1133.     }
  1134.     
  1135.     p = M_CheckParm ("-playdemo");
  1136.     if (p && p < myargc-1)
  1137.     {
  1138.     singledemo = true;              // quit after one demo
  1139.     G_DeferedPlayDemo (myargv[p+1]);
  1140.     D_DoomLoop ();  // never returns
  1141.     }
  1142.     
  1143.     p = M_CheckParm ("-timedemo");
  1144.     if (p && p < myargc-1)
  1145.     {
  1146.     G_TimeDemo (myargv[p+1]);
  1147.     D_DoomLoop ();  // never returns
  1148.     }
  1149.     
  1150.     p = M_CheckParm ("-loadgame");
  1151.     if (p && p < myargc-1)
  1152.     {
  1153.     if (M_CheckParm("-cdrom"))
  1154.         sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
  1155.     else
  1156.         sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
  1157.     G_LoadGame (file);
  1158.     }
  1159.     
  1160.  
  1161.     if ( gameaction != ga_loadgame )
  1162.     {
  1163.     if (autostart || netgame)
  1164.         G_InitNew (startskill, startepisode, startmap);
  1165.     else
  1166.         D_StartTitle ();                // start up intro loop
  1167.  
  1168.     }
  1169.  
  1170.     D_DoomLoop ();  // never returns
  1171. }
  1172.