DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

d_main.cpp (19707B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "Precompiled.h"
     30 #include "globaldata.h"
     31 
     32 
     33 
     34 #include <stdio.h>
     35 #include <stdlib.h>
     36 #include <sys/types.h>
     37 #include <sys/stat.h>
     38 #include <fcntl.h>
     39 
     40 #include "doomdef.h"
     41 #include "doomstat.h"
     42 
     43 #include "dstrings.h"
     44 #include "sounds.h"
     45 
     46 
     47 #include "z_zone.h"
     48 #include "w_wad.h"
     49 #include "s_sound.h"
     50 #include "v_video.h"
     51 
     52 #include "f_finale.h"
     53 #include "f_wipe.h"
     54 
     55 #include "m_argv.h"
     56 #include "m_misc.h"
     57 #include "m_menu.h"
     58 
     59 #include "i_system.h"
     60 #include "i_sound.h"
     61 #include "i_video.h"
     62 
     63 #include "g_game.h"
     64 
     65 #include "hu_stuff.h"
     66 #include "wi_stuff.h"
     67 #include "st_stuff.h"
     68 #include "am_map.h"
     69 
     70 #include "p_setup.h"
     71 #include "r_local.h"
     72 
     73 
     74 #include "d_main.h"
     75 
     76 //#include "../idLib/precompiled.h"
     77 //#include "../Main/PlayerProfile.h"
     78 //#include "../Main/PSN/PS3_Session.h"
     79 #include "d3xp/Game_local.h"
     80 
     81 //
     82 // D-DoomLoop()
     83 // Not a globally visible function,
     84 //  just included for source reference,
     85 //  called by D_DoomMain, never exits.
     86 // Manages timing and IO,
     87 //  calls all ?_Responder, ?_Ticker, and ?_Drawer,
     88 //  calls I_GetTime, I_StartFrame, and I_StartTic
     89 //
     90 void D_DoomLoop (void);
     91 
     92 void R_ExecuteSetViewSize (void);
     93 void D_CheckNetGame (void);
     94 bool D_PollNetworkStart();
     95 void D_ProcessEvents (void);
     96 void D_DoAdvanceDemo (void);
     97 
     98 const char*		wadfiles[MAXWADFILES] =
     99 {
    100 	0
    101 };
    102 
    103 const char*		extraWad = 0;
    104 
    105 //
    106 // EVENT HANDLING
    107 //
    108 // Events are asynchronous inputs generally generated by the game user.
    109 // Events can be discarded if no responder claims them
    110 //
    111 
    112 
    113 //
    114 // D_PostEvent
    115 // Called by the I/O functions when input is detected
    116 //
    117 void D_PostEvent (event_t* ev)
    118 {
    119 	::g->events[::g->eventhead] = *ev;
    120 	::g->eventhead = (++::g->eventhead)&(MAXEVENTS-1);
    121 }
    122 
    123 
    124 //
    125 // D_ProcessEvents
    126 // Send all the ::g->events of the given timestamp down the responder chain
    127 //
    128 void D_ProcessEvents (void)
    129 {
    130 	event_t*	ev;
    131 
    132 	// IF STORE DEMO, DO NOT ACCEPT INPUT
    133 	if ( ( ::g->gamemode == commercial )
    134 		&& (W_CheckNumForName("map01")<0) )
    135 		return;
    136 
    137 	for ( ; ::g->eventtail != ::g->eventhead ; ::g->eventtail = (++::g->eventtail)&(MAXEVENTS-1) )
    138 	{
    139 		ev = &::g->events[::g->eventtail];
    140 		if (M_Responder (ev))
    141 			continue;               // menu ate the event
    142 		G_Responder (ev);
    143 	}
    144 }
    145 
    146 
    147 
    148 
    149 //
    150 // D_Display
    151 //  draw current display, possibly wiping it from the previous
    152 //
    153 // ::g->wipegamestate can be set to -1 to force a ::g->wipe on the next draw
    154 extern bool waitingForWipe;
    155 
    156 void D_Wipe()
    157 {
    158 	int nowtime, tics;
    159 
    160 	nowtime = I_GetTime();
    161 	tics = nowtime - ::g->wipestart;
    162 
    163 	if (tics != 0)
    164 	{
    165 		::g->wipestart = nowtime;
    166 		::g->wipedone = wipe_ScreenWipe( 0, 0, SCREENWIDTH, SCREENHEIGHT, tics );
    167 
    168 		// DHM - Nerve :: Demo recording :: Stop large hitch on first frame after the wipe
    169 		if ( ::g->wipedone ) {
    170 			::g->oldtrt_entertics = nowtime / ::g->ticdup;
    171 			::g->gametime = nowtime;
    172 			::g->wipe = false;
    173 			waitingForWipe = false;
    174 		}
    175 	}
    176 }
    177 
    178 
    179 void D_Display (void)
    180 {
    181 	qboolean			redrawsbar;
    182 
    183 	if (::g->nodrawers)
    184 		return;                    // for comparative timing / profiling
    185 
    186 	redrawsbar = false;
    187 
    188 	// change the view size if needed
    189 	if (::g->setsizeneeded)
    190 	{
    191 		R_ExecuteSetViewSize();
    192 		::g->oldgamestate = (gamestate_t)-1;                      // force background redraw
    193 		::g->borderdrawcount = 3;
    194 	}
    195 
    196 	// save the current screen if about to ::g->wipe
    197 	if (::g->gamestate != ::g->wipegamestate)
    198 	{
    199 		::g->wipe = true;
    200 		wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
    201 	}
    202 	else
    203 		::g->wipe = false;
    204 
    205 	if (::g->gamestate == GS_LEVEL && ::g->gametic)
    206 		HU_Erase();
    207 
    208 	// do buffered drawing
    209 	switch (::g->gamestate)
    210 	{
    211 	case GS_LEVEL:
    212 		if (!::g->gametic)
    213 			break;
    214 		if (::g->automapactive)
    215 			AM_Drawer ();
    216 		if (::g->wipe || (::g->viewheight != 200 * GLOBAL_IMAGE_SCALER && ::g->fullscreen) )
    217 			redrawsbar = true;
    218 		if (::g->inhelpscreensstate && !::g->inhelpscreens)
    219 			redrawsbar = true;              // just put away the help screen
    220 		ST_Drawer ( ::g->viewheight == 200 * GLOBAL_IMAGE_SCALER, redrawsbar );
    221 		::g->fullscreen = ::g->viewheight == 200 * GLOBAL_IMAGE_SCALER;
    222 		break;
    223 
    224 	case GS_INTERMISSION:
    225 		WI_Drawer ();
    226 		break;
    227 
    228 	case GS_FINALE:
    229 		F_Drawer ();
    230 		break;
    231 
    232 	case GS_DEMOSCREEN:
    233 		D_PageDrawer ();
    234 		break;
    235 	}
    236 
    237 	// draw buffered stuff to screen
    238 	I_UpdateNoBlit ();
    239 
    240 	// draw the view directly
    241 	if (::g->gamestate == GS_LEVEL && !::g->automapactive && ::g->gametic)
    242 		R_RenderPlayerView (&::g->players[::g->displayplayer]);
    243 
    244 	if (::g->gamestate == GS_LEVEL && ::g->gametic)
    245 		HU_Drawer ();
    246 
    247 	// clean up border stuff
    248 	if (::g->gamestate != ::g->oldgamestate && ::g->gamestate != GS_LEVEL)
    249 		I_SetPalette ((byte*)W_CacheLumpName ("PLAYPAL",PU_CACHE_SHARED));
    250 
    251 	// see if the border needs to be initially drawn
    252 	if (::g->gamestate == GS_LEVEL && ::g->oldgamestate != GS_LEVEL)
    253 	{
    254 		::g->viewactivestate = false;        // view was not active
    255 		R_FillBackScreen ();    // draw the pattern into the back screen
    256 	}
    257 
    258 	// see if the border needs to be updated to the screen
    259 	if (::g->gamestate == GS_LEVEL && !::g->automapactive && ::g->scaledviewwidth != (320 * GLOBAL_IMAGE_SCALER) )
    260 	{
    261 		if (::g->menuactive || ::g->menuactivestate || !::g->viewactivestate)
    262 			::g->borderdrawcount = 3;
    263 		if (::g->borderdrawcount)
    264 		{
    265 			R_DrawViewBorder ();    // erase old menu stuff
    266 			::g->borderdrawcount--;
    267 		}
    268 
    269 	}
    270 
    271 	::g->menuactivestate = ::g->menuactive;
    272 	::g->viewactivestate = ::g->viewactive;
    273 	::g->inhelpscreensstate = ::g->inhelpscreens;
    274 	::g->oldgamestate = ::g->wipegamestate = ::g->gamestate;
    275 
    276 	// draw pause pic
    277 /*
    278 	if (::g->paused)
    279 	{
    280 		if (::g->automapactive)
    281 			y = 4;
    282 		else
    283 			y = ::g->viewwindowy+4;
    284 		V_DrawPatchDirect(::g->viewwindowx+(ORIGINAL_WIDTH-68)/2,
    285 			y,0,(patch_t*)W_CacheLumpName ("M_PAUSE", PU_CACHE_SHARED));
    286 	}
    287 */
    288 
    289 	// menus go directly to the screen
    290 	M_Drawer ();          // menu is drawn even on top of everything
    291 	NetUpdate ( NULL );         // send out any new accumulation
    292 	
    293 	// normal update
    294 	if (!::g->wipe)
    295 	{
    296 		I_FinishUpdate ();              // page flip or blit buffer
    297 		return;
    298 	}
    299 
    300 	// \ update
    301 	wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
    302 
    303 	::g->wipestart = I_GetTime () - 1;
    304 
    305 	D_Wipe(); // initialize g->wipedone
    306 }
    307 
    308 
    309 
    310 void D_RunFrame( bool Sounds )
    311 {
    312 	if (Sounds)	{
    313 		// move positional sounds
    314 		S_UpdateSounds (::g->players[::g->consoleplayer].mo);
    315 	}
    316 
    317 	// Update display, next frame, with current state.
    318 	D_Display ();
    319 
    320 	if (Sounds)	{
    321 		// Update sound output.
    322 		I_SubmitSound();
    323 	}
    324 }
    325 
    326 
    327 
    328 //
    329 //  D_DoomLoop
    330 //
    331 void D_DoomLoop (void)
    332 {
    333 	// DHM - Not used
    334 /*
    335 	if (M_CheckParm ("-debugfile"))
    336 	{
    337 		char    filename[20];
    338 		sprintf (filename,"debug%i.txt",::g->consoleplayer);
    339 		I_Printf ("debug output to: %s\n",filename);
    340 		::g->debugfile = f o p e n(filename,"w");
    341 	}
    342 
    343 	I_InitGraphics ();
    344 
    345 	while (1)
    346 	{
    347 		TryRunTics();
    348 		D_RunFrame( true );
    349 	}
    350 */
    351 }
    352 
    353 
    354 
    355 //
    356 //  DEMO LOOP
    357 //
    358 
    359 
    360 //
    361 // D_PageTicker
    362 // Handles timing for warped ::g->projection
    363 //
    364 void D_PageTicker (void)
    365 {
    366 	if (--::g->pagetic < 0)
    367 		D_AdvanceDemo ();
    368 }
    369 
    370 
    371 
    372 //
    373 // D_PageDrawer
    374 //
    375 void D_PageDrawer (void)
    376 {
    377 	V_DrawPatch (0,0, 0, (patch_t*)W_CacheLumpName(::g->pagename, PU_CACHE_SHARED));
    378 }
    379 
    380 
    381 //
    382 // D_AdvanceDemo
    383 // Called after each demo or intro ::g->demosequence finishes
    384 //
    385 void D_AdvanceDemo (void)
    386 {
    387 	::g->advancedemo = true;
    388 }
    389 
    390 
    391 //
    392 // This cycles through the demo sequences.
    393 // FIXME - version dependend demo numbers?
    394 //
    395 void D_DoAdvanceDemo (void)
    396 {
    397 	::g->players[::g->consoleplayer].playerstate = PST_LIVE;  // not reborn
    398 	::g->advancedemo = false;
    399 	::g->usergame = false;               // no save / end game here
    400 	::g->paused = false;
    401 	::g->gameaction = ga_nothing;
    402 
    403 	if ( ::g->gamemode == retail )
    404 		::g->demosequence = (::g->demosequence+1)%8;
    405 	else
    406 		::g->demosequence = (::g->demosequence+1)%6;
    407 
    408 	switch (::g->demosequence)
    409 	{
    410 	case 0:
    411 		if ( ::g->gamemode == commercial )
    412 			::g->pagetic = 35 * 11;
    413 		else
    414 			::g->pagetic = 8 * TICRATE;
    415 
    416 		::g->gamestate = GS_DEMOSCREEN;
    417 		::g->pagename = "INTERPIC";
    418 
    419 		if ( ::g->gamemode == commercial )
    420 			S_StartMusic(mus_dm2ttl);
    421 		else
    422 			S_StartMusic (mus_intro);
    423 
    424 		break;
    425 	case 1:
    426 		G_DeferedPlayDemo ("demo1");
    427 		break;
    428 	case 2:
    429 		::g->pagetic = 3 * TICRATE;
    430 		::g->gamestate = GS_DEMOSCREEN;
    431 		::g->pagename = "INTERPIC";
    432 		break;
    433 	case 3:
    434 		G_DeferedPlayDemo ("demo2");
    435 		break;
    436 	case 4:
    437 		::g->pagetic = 3 * TICRATE;
    438 		::g->gamestate = GS_DEMOSCREEN;
    439 		::g->pagename = "INTERPIC";
    440 		break;
    441 	case 5:
    442 		G_DeferedPlayDemo ("demo3");
    443 		break;
    444 		// THE DEFINITIVE DOOM Special Edition demo
    445 	case 6:
    446 		::g->pagetic = 3 * TICRATE;
    447 		::g->gamestate = GS_DEMOSCREEN;
    448 		::g->pagename = "INTERPIC";
    449 		break;
    450 	case 7:
    451 		G_DeferedPlayDemo ("demo4");
    452 		break;
    453 	}
    454 }
    455 
    456 
    457 
    458 //
    459 // D_StartTitle
    460 //
    461 void D_StartTitle (void)
    462 {
    463 	::g->gameaction = ga_nothing;
    464 	::g->demosequence = -1;
    465 	D_AdvanceDemo ();
    466 }
    467 
    468 
    469 
    470 
    471 //      print ::g->title for every printed line
    472 
    473 //
    474 // D_AddExtraWadFile
    475 //
    476 void D_SetExtraWadFile( const char *file ) {
    477 	extraWad = file;
    478 }
    479 
    480 //
    481 // D_AddFile
    482 //
    483 void D_AddFile (const char *file)
    484 {
    485 	int     numwadfiles;
    486 
    487 	for (numwadfiles = 0 ; wadfiles[numwadfiles] ; numwadfiles++)
    488 		if (file == wadfiles[numwadfiles])
    489 			return;
    490 		;
    491 	wadfiles[numwadfiles] = file;
    492 }
    493 
    494 //
    495 // IdentifyVersion
    496 // Checks availability of IWAD files by name,
    497 // to determine whether registered/commercial features
    498 // should be executed (notably loading PWAD's).
    499 //
    500 
    501 void IdentifyVersion (void)
    502 {
    503 	W_FreeWadFiles();
    504 
    505 	const ExpansionData * expansion =  DoomLib::GetCurrentExpansion();
    506 	::g->gamemode = expansion->gameMode;
    507 	::g->gamemission = expansion->pack_type;
    508 
    509 
    510 	if( expansion->type == ExpansionData::PWAD ) {
    511 		D_AddFile( expansion->iWadFilename );
    512 		D_AddFile( expansion->pWadFilename );
    513 
    514 	} else {
    515 		D_AddFile( expansion->iWadFilename );
    516 	}
    517 	
    518 }
    519 
    520 
    521 //
    522 // Find a Response File
    523 //
    524 void FindResponseFile (void)
    525 {
    526 }
    527 
    528 
    529 //
    530 // D_DoomMain
    531 //
    532 
    533 void D_DoomMain (void)
    534 {
    535 	int             p;
    536 	char                    file[256];
    537 
    538 
    539 	FindResponseFile ();
    540 
    541 	IdentifyVersion ();
    542 
    543 	setbuf (stdout, NULL);
    544 	::g->modifiedgame = false;
    545 
    546 	// TODO: Networking
    547 	//const bool isDeathmatch = gameLocal->GetMatchParms().GetGameType() == GAME_TYPE_PVP;
    548 	const bool isDeathmatch = false;
    549 
    550 	::g->nomonsters = M_CheckParm ("-nomonsters") || isDeathmatch;
    551 	::g->respawnparm = M_CheckParm ("-respawn");
    552 	::g->fastparm = M_CheckParm ("-fast");
    553 	::g->devparm = M_CheckParm ("-devparm");
    554 	if (M_CheckParm ("-altdeath") || isDeathmatch)
    555 		::g->deathmatch = 2;
    556 	else if (M_CheckParm ("-deathmatch"))
    557 		::g->deathmatch = 1;
    558 
    559 	switch ( ::g->gamemode )
    560 	{
    561 	case retail:
    562 		sprintf (::g->title,
    563 			"                         "
    564 			"The Ultimate DOOM Startup v%i.%i"
    565 			"                           ",
    566 			VERSION/100,VERSION%100);
    567 		break;
    568 	case shareware:
    569 		sprintf (::g->title,
    570 			"                            "
    571 			"DOOM Shareware Startup v%i.%i"
    572 			"                           ",
    573 			VERSION/100,VERSION%100);
    574 		break;
    575 	case registered:
    576 		sprintf (::g->title,
    577 			"                            "
    578 			"DOOM Registered Startup v%i.%i"
    579 			"                           ",
    580 			VERSION/100,VERSION%100);
    581 		break;
    582 	case commercial:
    583 		sprintf (::g->title,
    584 			"                         "
    585 			"DOOM 2: Hell on Earth v%i.%i"
    586 			"                           ",
    587 			VERSION/100,VERSION%100);
    588 		break;
    589 	default:
    590 		sprintf (::g->title,
    591 			"                     "
    592 			"Public DOOM - v%i.%i"
    593 			"                           ",
    594 			VERSION/100,VERSION%100);
    595 		break;
    596 	}
    597 
    598 	I_Printf ("%s\n",::g->title);
    599 
    600 	if (::g->devparm)
    601 		I_Printf(D_DEVSTR);
    602 
    603 	if (M_CheckParm("-cdrom"))
    604 	{
    605 		I_Printf(D_CDROM);
    606 //c++		mkdir("c:\\doomdata",0);
    607 		strcpy (::g->basedefault,"c:/doomdata/default.cfg");
    608 	}	
    609 
    610 	// add any files specified on the command line with -file ::g->wadfile
    611 	// to the wad list
    612 	//
    613 	p = M_CheckParm ("-file");
    614 	if (p)
    615 	{
    616 		// the parms after p are ::g->wadfile/lump names,
    617 		// until end of parms or another - preceded parm
    618 		::g->modifiedgame = true;            // homebrew levels
    619 		while (++p != ::g->myargc && ::g->myargv[p][0] != '-')
    620 			D_AddFile (::g->myargv[p]);
    621 	}
    622 
    623 	p = M_CheckParm ("-playdemo");
    624 
    625 	if (!p)
    626 		p = M_CheckParm ("-timedemo");
    627 
    628 	if (p && p < ::g->myargc-1)
    629 	{
    630 		sprintf (file,"d:\\%s.lmp", ::g->myargv[p+1]);
    631 		D_AddFile (file);
    632 		I_Printf("Playing demo %s.lmp.\n",::g->myargv[p+1]);
    633 	}
    634 
    635 	// get skill / episode / map from defaults
    636 	::g->startskill = sk_medium;
    637 	::g->startepisode = 1;
    638 	::g->startmap = 1;
    639 	::g->autostart = false;
    640 
    641 	if ( DoomLib::matchParms.gameEpisode != GAME_EPISODE_UNKNOWN ) {
    642 		::g->startepisode = DoomLib::matchParms.gameEpisode;
    643 		::g->autostart = 1;
    644 	}
    645 
    646 	if ( DoomLib::matchParms.gameMap != -1 ) {
    647 		::g->startmap = DoomLib::matchParms.gameMap;
    648 		::g->autostart = 1;
    649 	}
    650 
    651 	if ( DoomLib::matchParms.gameSkill != -1) {
    652 		::g->startskill = (skill_t)DoomLib::matchParms.gameSkill;
    653 	}
    654 
    655 	// get skill / episode / map from cmdline
    656 	p = M_CheckParm ("-skill");
    657 	if (p && p < ::g->myargc-1)
    658 	{
    659 		::g->startskill = (skill_t)(::g->myargv[p+1][0]-'1');
    660 		::g->autostart = true;
    661 	}
    662 
    663 	p = M_CheckParm ("-episode");
    664 	if (p && p < ::g->myargc-1)
    665 	{
    666 		::g->startepisode = ::g->myargv[p+1][0]-'0';
    667 		::g->startmap = 1;
    668 		::g->autostart = true;
    669 	}
    670 
    671 	/*p = M_CheckParm ("-timer");
    672 	if (p && p < ::g->myargc-1 && ::g->deathmatch)
    673 	{*/
    674 	// TODO: Networking
    675 	//const int timeLimit = gameLocal->GetMatchParms().GetTimeLimit();
    676 	const int timeLimit = 0;
    677 	if (timeLimit != 0 && ::g->deathmatch) 
    678 	{
    679 		int     time;
    680 		//time = atoi(::g->myargv[p+1]);
    681 		time = timeLimit;
    682 		I_Printf("Levels will end after %d minute",time);
    683 		if (time>1)
    684 			I_Printf("s");
    685 		I_Printf(".\n");
    686 	}
    687 
    688 	p = M_CheckParm ("-avg");
    689 	if (p && p < ::g->myargc-1 && ::g->deathmatch)
    690 		I_Printf("Austin Virtual Gaming: Levels will end after 20 minutes\n");
    691 
    692 	p = M_CheckParm ("-warp");
    693 	if (p && p < ::g->myargc-1)
    694 	{
    695 		if (::g->gamemode == commercial)
    696 			::g->startmap = atoi (::g->myargv[p+1]);
    697 		else
    698 		{
    699 			::g->startepisode = ::g->myargv[p+1][0]-'0';
    700 			::g->startmap = ::g->myargv[p+2][0]-'0';
    701 		}
    702 		::g->autostart = true;
    703 	}
    704 
    705 	I_Printf ("Z_Init: Init zone memory allocation daemon. \n");
    706 	Z_Init ();
    707 
    708 	// init subsystems
    709 	I_Printf ("V_Init: allocate ::g->screens.\n");
    710 	V_Init ();
    711 
    712 	I_Printf ("M_LoadDefaults: Load system defaults.\n");
    713 	M_LoadDefaults ();              // load before initing other systems
    714 
    715 	I_Printf ("W_Init: Init WADfiles.\n");
    716 	W_InitMultipleFiles (wadfiles);
    717 
    718 
    719 	// Check for -file in shareware
    720 	if (::g->modifiedgame)
    721 	{
    722 		// These are the lumps that will be checked in IWAD,
    723 		// if any one is not present, execution will be aborted.
    724 		char name[23][16]=
    725 		{
    726 			"e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
    727 				"e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",
    728 				"dphoof","bfgga0","heada1","cybra1","spida1d1"
    729 		};
    730 		int i;
    731 
    732 		if ( ::g->gamemode == shareware)
    733 			I_Error("\nYou cannot -file with the shareware "
    734 			"version. Register!");
    735 
    736 		// Check for fake IWAD with right name,
    737 		// but w/o all the lumps of the registered version. 
    738 		if (::g->gamemode == registered)
    739 			for (i = 0;i < 23; i++)
    740 				if (W_CheckNumForName(name[i])<0)
    741 					I_Error("\nThis is not the registered version.");
    742 	}
    743 
    744 	// Iff additonal PWAD files are used, print modified banner
    745 	if (::g->modifiedgame)
    746 	{
    747 		/*m*/I_Printf (
    748 		"===========================================================================\n"
    749 			"ATTENTION:  This version of DOOM has been modified.  If you would like to\n"
    750 			"get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n"
    751 			"        You will not receive technical support for modified games.\n"
    752 			"                      press enter to continue\n"
    753 			"===========================================================================\n"
    754 			);
    755 		getchar ();
    756 	}
    757 
    758 
    759 	// Check and print which version is executed.
    760 	switch ( ::g->gamemode )
    761 	{
    762 	case shareware:
    763 	case indetermined:
    764 		I_Printf (
    765 			"===========================================================================\n"
    766 			"                                Shareware!\n"
    767 			"===========================================================================\n"
    768 			);
    769 		break;
    770 	case registered:
    771 	case retail:
    772 	case commercial:
    773 		I_Printf (
    774 			"===========================================================================\n"
    775 			"                 Commercial product - do not distribute!\n"
    776 			"         Please report software piracy to the SPA: 1-800-388-PIR8\n"
    777 			"===========================================================================\n"
    778 			);
    779 		break;
    780 
    781 	default:
    782 		// Ouch.
    783 		break;
    784 	}
    785 
    786 	I_Printf ("M_Init: Init miscellaneous info.\n");
    787 	M_Init ();
    788 
    789 	I_Printf ("R_Init: Init DOOM refresh daemon - ");
    790 	R_Init ();
    791 
    792 	I_Printf ("\nP_Init: Init Playloop state.\n");
    793 	P_Init ();
    794 
    795 	I_Printf ("I_Init: Setting up machine state.\n");
    796 	I_Init ();
    797 
    798 	I_Printf ("D_CheckNetGame: Checking network game status.\n");
    799 	D_CheckNetGame ();
    800 }
    801 
    802 bool D_DoomMainPoll(void)
    803 {
    804 	int             p;
    805 	char                    file[256];
    806 
    807 	if (D_PollNetworkStart() == false)
    808 		return false;
    809 
    810 
    811 	I_Printf( "S_Init: Setting up sound.\n" );
    812 	S_Init( s_volume_sound.GetInteger(), s_volume_midi.GetInteger() );
    813 
    814 	I_Printf ("HU_Init: Setting up heads up display.\n");
    815 	HU_Init ();
    816 
    817 	I_Printf ("ST_Init: Init status bar.\n");
    818 	ST_Init ();
    819 
    820 	// start the apropriate game based on parms
    821 	p = M_CheckParm ("-record");
    822 
    823 	if (p && p < ::g->myargc-1)
    824 	{
    825 		G_RecordDemo (::g->myargv[p+1]);
    826 		::g->autostart = true;
    827 	}
    828 
    829 	p = M_CheckParm ("-playdemo");
    830 	if (p && p < ::g->myargc-1)
    831 	{
    832 		//::g->singledemo = true;              // quit after one demo
    833 		G_DeferedPlayDemo (::g->myargv[p+1]);
    834 		//D_DoomLoop ();  // never returns
    835 	}
    836 
    837 	p = M_CheckParm ("-timedemo");
    838 	if (p && p < ::g->myargc-1)
    839 	{
    840 		G_TimeDemo ("nukage1");//::g->myargv[p+1]);
    841 		D_DoomLoop ();  // never returns
    842 	}
    843 
    844 	p = M_CheckParm ("-loadgame");
    845 	if (p && p < ::g->myargc-1)
    846 	{
    847 		if (M_CheckParm("-cdrom"))
    848 			sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",::g->myargv[p+1][0]);
    849 		else
    850 			sprintf(file, SAVEGAMENAME"%c.dsg",::g->myargv[p+1][0]);
    851 		G_LoadGame (file);
    852 	}
    853 
    854 
    855 	if ( ::g->gameaction != ga_loadgame && ::g->gameaction != ga_playdemo )
    856 	{
    857 		if (::g->autostart || ::g->netgame ) {
    858 			G_InitNew (::g->startskill, ::g->startepisode, ::g->startmap );
    859 		} else if(  ::g->gameaction != ga_newgame) {
    860 			D_StartTitle ();                // start up intro loop
    861 		}
    862 	}
    863 	return true;
    864 }
    865 
    866